]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.2.2-3.1.8-201201101724.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-3.1.8-201201101724.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index dfa6fc6..0095943 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -5,6 +5,7 @@
6 *.cis
7 *.cpio
8 *.csp
9 +*.dbg
10 *.dsp
11 *.dvi
12 *.elf
13 @@ -14,6 +15,7 @@
14 *.gcov
15 *.gen.S
16 *.gif
17 +*.gmo
18 *.grep
19 *.grp
20 *.gz
21 @@ -48,9 +50,11 @@
22 *.tab.h
23 *.tex
24 *.ver
25 +*.vim
26 *.xml
27 *.xz
28 *_MODULES
29 +*_reg_safe.h
30 *_vga16.c
31 *~
32 \#*#
33 @@ -70,6 +74,7 @@ Kerntypes
34 Module.markers
35 Module.symvers
36 PENDING
37 +PERF*
38 SCCS
39 System.map*
40 TAGS
41 @@ -93,19 +98,24 @@ bounds.h
42 bsetup
43 btfixupprep
44 build
45 +builtin-policy.h
46 bvmlinux
47 bzImage*
48 capability_names.h
49 capflags.c
50 classlist.h*
51 +clut_vga16.c
52 +common-cmds.h
53 comp*.log
54 compile.h*
55 conf
56 config
57 config-*
58 config_data.h*
59 +config.c
60 config.mak
61 config.mak.autogen
62 +config.tmp
63 conmakehash
64 consolemap_deftbl.c*
65 cpustr.h
66 @@ -119,6 +129,7 @@ dslm
67 elf2ecoff
68 elfconfig.h*
69 evergreen_reg_safe.h
70 +exception_policy.conf
71 fixdep
72 flask.h
73 fore200e_mkfirm
74 @@ -126,12 +137,15 @@ fore200e_pca_fw.c*
75 gconf
76 gconf.glade.h
77 gen-devlist
78 +gen-kdb_cmds.c
79 gen_crc32table
80 gen_init_cpio
81 generated
82 genheaders
83 genksyms
84 *_gray256.c
85 +hash
86 +hid-example
87 hpet_example
88 hugepage-mmap
89 hugepage-shm
90 @@ -146,7 +160,7 @@ int32.c
91 int4.c
92 int8.c
93 kallsyms
94 -kconfig
95 +kern_constants.h
96 keywords.c
97 ksym.c*
98 ksym.h*
99 @@ -154,7 +168,6 @@ kxgettext
100 lkc_defs.h
101 lex.c
102 lex.*.c
103 -linux
104 logo_*.c
105 logo_*_clut224.c
106 logo_*_mono.c
107 @@ -166,14 +179,15 @@ machtypes.h
108 map
109 map_hugetlb
110 maui_boot.h
111 -media
112 mconf
113 +mdp
114 miboot*
115 mk_elfconfig
116 mkboot
117 mkbugboot
118 mkcpustr
119 mkdep
120 +mkpiggy
121 mkprep
122 mkregtable
123 mktables
124 @@ -209,6 +223,7 @@ r300_reg_safe.h
125 r420_reg_safe.h
126 r600_reg_safe.h
127 recordmcount
128 +regdb.c
129 relocs
130 rlim_names.h
131 rn50_reg_safe.h
132 @@ -219,6 +234,7 @@ setup
133 setup.bin
134 setup.elf
135 sImage
136 +slabinfo
137 sm_tbl*
138 split-include
139 syscalltab.h
140 @@ -229,6 +245,7 @@ tftpboot.img
141 timeconst.h
142 times.h*
143 trix_boot.h
144 +user_constants.h
145 utsrelease.h*
146 vdso-syms.lds
147 vdso.lds
148 @@ -246,7 +263,9 @@ vmlinux
149 vmlinux-*
150 vmlinux.aout
151 vmlinux.bin.all
152 +vmlinux.bin.bz2
153 vmlinux.lds
154 +vmlinux.relocs
155 vmlinuz
156 voffset.h
157 vsyscall.lds
158 @@ -254,9 +273,11 @@ vsyscall_32.lds
159 wanxlfw.inc
160 uImage
161 unifdef
162 +utsrelease.h
163 wakeup.bin
164 wakeup.elf
165 wakeup.lds
166 zImage*
167 zconf.hash.c
168 +zconf.lex.c
169 zoffset.h
170 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
171 index d6e6724..a024ce8 100644
172 --- a/Documentation/kernel-parameters.txt
173 +++ b/Documentation/kernel-parameters.txt
174 @@ -1898,6 +1898,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
175 the specified number of seconds. This is to be used if
176 your oopses keep scrolling off the screen.
177
178 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
179 + virtualization environments that don't cope well with the
180 + expand down segment used by UDEREF on X86-32 or the frequent
181 + page table updates on X86-64.
182 +
183 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
184 +
185 pcbit= [HW,ISDN]
186
187 pcd. [PARIDE]
188 diff --git a/Makefile b/Makefile
189 index 64a2e76..5b86280 100644
190 --- a/Makefile
191 +++ b/Makefile
192 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
193
194 HOSTCC = gcc
195 HOSTCXX = g++
196 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
197 -HOSTCXXFLAGS = -O2
198 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
199 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
200 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
201
202 # Decide whether to build built-in, modular, or both.
203 # Normally, just do built-in.
204 @@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
205 # Rules shared between *config targets and build targets
206
207 # Basic helpers built in scripts/
208 -PHONY += scripts_basic
209 -scripts_basic:
210 +PHONY += scripts_basic gcc-plugins
211 +scripts_basic: gcc-plugins
212 $(Q)$(MAKE) $(build)=scripts/basic
213 $(Q)rm -f .tmp_quiet_recordmcount
214
215 @@ -564,6 +565,46 @@ else
216 KBUILD_CFLAGS += -O2
217 endif
218
219 +ifndef DISABLE_PAX_PLUGINS
220 +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
221 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
222 +CONSTIFY_PLUGIN := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
223 +endif
224 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
225 +STACKLEAK_PLUGIN := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
226 +STACKLEAK_PLUGIN += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
227 +endif
228 +ifdef CONFIG_KALLOCSTAT_PLUGIN
229 +KALLOCSTAT_PLUGIN := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
230 +endif
231 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
232 +KERNEXEC_PLUGIN := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
233 +KERNEXEC_PLUGIN += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD)
234 +endif
235 +ifdef CONFIG_CHECKER_PLUGIN
236 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
237 +CHECKER_PLUGIN := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
238 +endif
239 +endif
240 +GCC_PLUGINS := $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN) $(KALLOCSTAT_PLUGIN) $(KERNEXEC_PLUGIN) $(CHECKER_PLUGIN)
241 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN
242 +ifeq ($(KBUILD_EXTMOD),)
243 +gcc-plugins:
244 + $(Q)$(MAKE) $(build)=tools/gcc
245 +else
246 +gcc-plugins: ;
247 +endif
248 +else
249 +gcc-plugins:
250 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
251 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
252 +else
253 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
254 +endif
255 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
256 +endif
257 +endif
258 +
259 include $(srctree)/arch/$(SRCARCH)/Makefile
260
261 ifneq ($(CONFIG_FRAME_WARN),0)
262 @@ -708,7 +749,7 @@ export mod_strip_cmd
263
264
265 ifeq ($(KBUILD_EXTMOD),)
266 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
267 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
268
269 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
270 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
271 @@ -932,6 +973,7 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
272
273 # The actual objects are generated when descending,
274 # make sure no implicit rule kicks in
275 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS)
276 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
277
278 # Handle descending into subdirectories listed in $(vmlinux-dirs)
279 @@ -941,7 +983,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
280 # Error messages still appears in the original language
281
282 PHONY += $(vmlinux-dirs)
283 -$(vmlinux-dirs): prepare scripts
284 +$(vmlinux-dirs): gcc-plugins prepare scripts
285 $(Q)$(MAKE) $(build)=$@
286
287 # Store (new) KERNELRELASE string in include/config/kernel.release
288 @@ -986,6 +1028,7 @@ prepare0: archprepare FORCE
289 $(Q)$(MAKE) $(build)=. missing-syscalls
290
291 # All the preparing..
292 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS),$(KBUILD_CFLAGS))
293 prepare: prepare0
294
295 # Generate some files
296 @@ -1087,6 +1130,7 @@ all: modules
297 # using awk while concatenating to the final file.
298
299 PHONY += modules
300 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
301 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
302 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
303 @$(kecho) ' Building modules, stage 2.';
304 @@ -1102,7 +1146,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
305
306 # Target to prepare building external modules
307 PHONY += modules_prepare
308 -modules_prepare: prepare scripts
309 +modules_prepare: gcc-plugins prepare scripts
310
311 # Target to install modules
312 PHONY += modules_install
313 @@ -1198,7 +1242,7 @@ distclean: mrproper
314 @find $(srctree) $(RCS_FIND_IGNORE) \
315 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
316 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
317 - -o -name '.*.rej' -o -size 0 \
318 + -o -name '.*.rej' -o -name '*.so' -o -size 0 \
319 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
320 -type f -print | xargs rm -f
321
322 @@ -1360,6 +1404,7 @@ PHONY += $(module-dirs) modules
323 $(module-dirs): crmodverdir $(objtree)/Module.symvers
324 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
325
326 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
327 modules: $(module-dirs)
328 @$(kecho) ' Building modules, stage 2.';
329 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
330 @@ -1486,17 +1531,19 @@ else
331 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
332 endif
333
334 -%.s: %.c prepare scripts FORCE
335 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS)
336 +%.s: %.c gcc-plugins prepare scripts FORCE
337 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
338 %.i: %.c prepare scripts FORCE
339 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
340 -%.o: %.c prepare scripts FORCE
341 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS)
342 +%.o: %.c gcc-plugins prepare scripts FORCE
343 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
344 %.lst: %.c prepare scripts FORCE
345 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
346 -%.s: %.S prepare scripts FORCE
347 +%.s: %.S gcc-plugins prepare scripts FORCE
348 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
349 -%.o: %.S prepare scripts FORCE
350 +%.o: %.S gcc-plugins prepare scripts FORCE
351 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
352 %.symtypes: %.c prepare scripts FORCE
353 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
354 @@ -1506,11 +1553,13 @@ endif
355 $(cmd_crmodverdir)
356 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
357 $(build)=$(build-dir)
358 -%/: prepare scripts FORCE
359 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS)
360 +%/: gcc-plugins prepare scripts FORCE
361 $(cmd_crmodverdir)
362 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
363 $(build)=$(build-dir)
364 -%.ko: prepare scripts FORCE
365 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS)
366 +%.ko: gcc-plugins prepare scripts FORCE
367 $(cmd_crmodverdir)
368 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
369 $(build)=$(build-dir) $(@:.ko=.o)
370 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
371 index da5449e..7418343 100644
372 --- a/arch/alpha/include/asm/elf.h
373 +++ b/arch/alpha/include/asm/elf.h
374 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
375
376 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
377
378 +#ifdef CONFIG_PAX_ASLR
379 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
380 +
381 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
382 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
383 +#endif
384 +
385 /* $0 is set by ld.so to a pointer to a function which might be
386 registered using atexit. This provides a mean for the dynamic
387 linker to call DT_FINI functions for shared libraries that have
388 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
389 index de98a73..bd4f1f8 100644
390 --- a/arch/alpha/include/asm/pgtable.h
391 +++ b/arch/alpha/include/asm/pgtable.h
392 @@ -101,6 +101,17 @@ struct vm_area_struct;
393 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
394 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
395 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
396 +
397 +#ifdef CONFIG_PAX_PAGEEXEC
398 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
399 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
400 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
401 +#else
402 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
403 +# define PAGE_COPY_NOEXEC PAGE_COPY
404 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
405 +#endif
406 +
407 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
408
409 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
410 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
411 index 2fd00b7..cfd5069 100644
412 --- a/arch/alpha/kernel/module.c
413 +++ b/arch/alpha/kernel/module.c
414 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
415
416 /* The small sections were sorted to the end of the segment.
417 The following should definitely cover them. */
418 - gp = (u64)me->module_core + me->core_size - 0x8000;
419 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
420 got = sechdrs[me->arch.gotsecindex].sh_addr;
421
422 for (i = 0; i < n; i++) {
423 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
424 index 01e8715..be0e80f 100644
425 --- a/arch/alpha/kernel/osf_sys.c
426 +++ b/arch/alpha/kernel/osf_sys.c
427 @@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
428 /* At this point: (!vma || addr < vma->vm_end). */
429 if (limit - len < addr)
430 return -ENOMEM;
431 - if (!vma || addr + len <= vma->vm_start)
432 + if (check_heap_stack_gap(vma, addr, len))
433 return addr;
434 addr = vma->vm_end;
435 vma = vma->vm_next;
436 @@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
437 merely specific addresses, but regions of memory -- perhaps
438 this feature should be incorporated into all ports? */
439
440 +#ifdef CONFIG_PAX_RANDMMAP
441 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
442 +#endif
443 +
444 if (addr) {
445 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
446 if (addr != (unsigned long) -ENOMEM)
447 @@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
448 }
449
450 /* Next, try allocating at TASK_UNMAPPED_BASE. */
451 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
452 - len, limit);
453 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
454 +
455 if (addr != (unsigned long) -ENOMEM)
456 return addr;
457
458 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
459 index fadd5f8..904e73a 100644
460 --- a/arch/alpha/mm/fault.c
461 +++ b/arch/alpha/mm/fault.c
462 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
463 __reload_thread(pcb);
464 }
465
466 +#ifdef CONFIG_PAX_PAGEEXEC
467 +/*
468 + * PaX: decide what to do with offenders (regs->pc = fault address)
469 + *
470 + * returns 1 when task should be killed
471 + * 2 when patched PLT trampoline was detected
472 + * 3 when unpatched PLT trampoline was detected
473 + */
474 +static int pax_handle_fetch_fault(struct pt_regs *regs)
475 +{
476 +
477 +#ifdef CONFIG_PAX_EMUPLT
478 + int err;
479 +
480 + do { /* PaX: patched PLT emulation #1 */
481 + unsigned int ldah, ldq, jmp;
482 +
483 + err = get_user(ldah, (unsigned int *)regs->pc);
484 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
485 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
486 +
487 + if (err)
488 + break;
489 +
490 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
491 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
492 + jmp == 0x6BFB0000U)
493 + {
494 + unsigned long r27, addr;
495 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
496 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
497 +
498 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
499 + err = get_user(r27, (unsigned long *)addr);
500 + if (err)
501 + break;
502 +
503 + regs->r27 = r27;
504 + regs->pc = r27;
505 + return 2;
506 + }
507 + } while (0);
508 +
509 + do { /* PaX: patched PLT emulation #2 */
510 + unsigned int ldah, lda, br;
511 +
512 + err = get_user(ldah, (unsigned int *)regs->pc);
513 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
514 + err |= get_user(br, (unsigned int *)(regs->pc+8));
515 +
516 + if (err)
517 + break;
518 +
519 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
520 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
521 + (br & 0xFFE00000U) == 0xC3E00000U)
522 + {
523 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
524 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
525 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
526 +
527 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
528 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
529 + return 2;
530 + }
531 + } while (0);
532 +
533 + do { /* PaX: unpatched PLT emulation */
534 + unsigned int br;
535 +
536 + err = get_user(br, (unsigned int *)regs->pc);
537 +
538 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
539 + unsigned int br2, ldq, nop, jmp;
540 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
541 +
542 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
543 + err = get_user(br2, (unsigned int *)addr);
544 + err |= get_user(ldq, (unsigned int *)(addr+4));
545 + err |= get_user(nop, (unsigned int *)(addr+8));
546 + err |= get_user(jmp, (unsigned int *)(addr+12));
547 + err |= get_user(resolver, (unsigned long *)(addr+16));
548 +
549 + if (err)
550 + break;
551 +
552 + if (br2 == 0xC3600000U &&
553 + ldq == 0xA77B000CU &&
554 + nop == 0x47FF041FU &&
555 + jmp == 0x6B7B0000U)
556 + {
557 + regs->r28 = regs->pc+4;
558 + regs->r27 = addr+16;
559 + regs->pc = resolver;
560 + return 3;
561 + }
562 + }
563 + } while (0);
564 +#endif
565 +
566 + return 1;
567 +}
568 +
569 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
570 +{
571 + unsigned long i;
572 +
573 + printk(KERN_ERR "PAX: bytes at PC: ");
574 + for (i = 0; i < 5; i++) {
575 + unsigned int c;
576 + if (get_user(c, (unsigned int *)pc+i))
577 + printk(KERN_CONT "???????? ");
578 + else
579 + printk(KERN_CONT "%08x ", c);
580 + }
581 + printk("\n");
582 +}
583 +#endif
584
585 /*
586 * This routine handles page faults. It determines the address,
587 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
588 good_area:
589 si_code = SEGV_ACCERR;
590 if (cause < 0) {
591 - if (!(vma->vm_flags & VM_EXEC))
592 + if (!(vma->vm_flags & VM_EXEC)) {
593 +
594 +#ifdef CONFIG_PAX_PAGEEXEC
595 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
596 + goto bad_area;
597 +
598 + up_read(&mm->mmap_sem);
599 + switch (pax_handle_fetch_fault(regs)) {
600 +
601 +#ifdef CONFIG_PAX_EMUPLT
602 + case 2:
603 + case 3:
604 + return;
605 +#endif
606 +
607 + }
608 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
609 + do_group_exit(SIGKILL);
610 +#else
611 goto bad_area;
612 +#endif
613 +
614 + }
615 } else if (!cause) {
616 /* Allow reads even for write-only mappings */
617 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
618 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
619 index 86976d0..8a57797 100644
620 --- a/arch/arm/include/asm/atomic.h
621 +++ b/arch/arm/include/asm/atomic.h
622 @@ -239,6 +239,14 @@ typedef struct {
623 u64 __aligned(8) counter;
624 } atomic64_t;
625
626 +#ifdef CONFIG_PAX_REFCOUNT
627 +typedef struct {
628 + u64 __aligned(8) counter;
629 +} atomic64_unchecked_t;
630 +#else
631 +typedef atomic64_t atomic64_unchecked_t;
632 +#endif
633 +
634 #define ATOMIC64_INIT(i) { (i) }
635
636 static inline u64 atomic64_read(atomic64_t *v)
637 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
638 index 0e9ce8d..6ef1e03 100644
639 --- a/arch/arm/include/asm/elf.h
640 +++ b/arch/arm/include/asm/elf.h
641 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
642 the loader. We need to make sure that it is out of the way of the program
643 that it will "exec", and that there is sufficient room for the brk. */
644
645 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
646 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
647 +
648 +#ifdef CONFIG_PAX_ASLR
649 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
650 +
651 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
652 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
653 +#endif
654
655 /* When the program starts, a1 contains a pointer to a function to be
656 registered with atexit, as per the SVR4 ABI. A value of 0 means we
657 @@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
658 extern void elf_set_personality(const struct elf32_hdr *);
659 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
660
661 -struct mm_struct;
662 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
663 -#define arch_randomize_brk arch_randomize_brk
664 -
665 extern int vectors_user_mapping(void);
666 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
667 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
668 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
669 index e51b1e8..32a3113 100644
670 --- a/arch/arm/include/asm/kmap_types.h
671 +++ b/arch/arm/include/asm/kmap_types.h
672 @@ -21,6 +21,7 @@ enum km_type {
673 KM_L1_CACHE,
674 KM_L2_CACHE,
675 KM_KDB,
676 + KM_CLEARPAGE,
677 KM_TYPE_NR
678 };
679
680 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
681 index b293616..96310e5 100644
682 --- a/arch/arm/include/asm/uaccess.h
683 +++ b/arch/arm/include/asm/uaccess.h
684 @@ -22,6 +22,8 @@
685 #define VERIFY_READ 0
686 #define VERIFY_WRITE 1
687
688 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
689 +
690 /*
691 * The exception table consists of pairs of addresses: the first is the
692 * address of an instruction that is allowed to fault, and the second is
693 @@ -387,8 +389,23 @@ do { \
694
695
696 #ifdef CONFIG_MMU
697 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
698 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
699 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
700 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
701 +
702 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
703 +{
704 + if (!__builtin_constant_p(n))
705 + check_object_size(to, n, false);
706 + return ___copy_from_user(to, from, n);
707 +}
708 +
709 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
710 +{
711 + if (!__builtin_constant_p(n))
712 + check_object_size(from, n, true);
713 + return ___copy_to_user(to, from, n);
714 +}
715 +
716 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
717 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
718 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
719 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
720
721 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
722 {
723 + if ((long)n < 0)
724 + return n;
725 +
726 if (access_ok(VERIFY_READ, from, n))
727 n = __copy_from_user(to, from, n);
728 else /* security hole - plug it */
729 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
730
731 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
732 {
733 + if ((long)n < 0)
734 + return n;
735 +
736 if (access_ok(VERIFY_WRITE, to, n))
737 n = __copy_to_user(to, from, n);
738 return n;
739 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
740 index aeef960..2966009 100644
741 --- a/arch/arm/kernel/armksyms.c
742 +++ b/arch/arm/kernel/armksyms.c
743 @@ -98,8 +98,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
744 #ifdef CONFIG_MMU
745 EXPORT_SYMBOL(copy_page);
746
747 -EXPORT_SYMBOL(__copy_from_user);
748 -EXPORT_SYMBOL(__copy_to_user);
749 +EXPORT_SYMBOL(___copy_from_user);
750 +EXPORT_SYMBOL(___copy_to_user);
751 EXPORT_SYMBOL(__clear_user);
752
753 EXPORT_SYMBOL(__get_user_1);
754 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
755 index c9d11ea..5078081 100644
756 --- a/arch/arm/kernel/process.c
757 +++ b/arch/arm/kernel/process.c
758 @@ -28,7 +28,6 @@
759 #include <linux/tick.h>
760 #include <linux/utsname.h>
761 #include <linux/uaccess.h>
762 -#include <linux/random.h>
763 #include <linux/hw_breakpoint.h>
764 #include <linux/cpuidle.h>
765
766 @@ -484,12 +483,6 @@ unsigned long get_wchan(struct task_struct *p)
767 return 0;
768 }
769
770 -unsigned long arch_randomize_brk(struct mm_struct *mm)
771 -{
772 - unsigned long range_end = mm->brk + 0x02000000;
773 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
774 -}
775 -
776 #ifdef CONFIG_MMU
777 /*
778 * The vectors page is always readable from user space for the
779 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
780 index bc9f9da..c75d826 100644
781 --- a/arch/arm/kernel/traps.c
782 +++ b/arch/arm/kernel/traps.c
783 @@ -257,6 +257,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
784
785 static DEFINE_SPINLOCK(die_lock);
786
787 +extern void gr_handle_kernel_exploit(void);
788 +
789 /*
790 * This function is protected against re-entrancy.
791 */
792 @@ -284,6 +286,9 @@ void die(const char *str, struct pt_regs *regs, int err)
793 panic("Fatal exception in interrupt");
794 if (panic_on_oops)
795 panic("Fatal exception");
796 +
797 + gr_handle_kernel_exploit();
798 +
799 if (ret != NOTIFY_STOP)
800 do_exit(SIGSEGV);
801 }
802 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
803 index 66a477a..bee61d3 100644
804 --- a/arch/arm/lib/copy_from_user.S
805 +++ b/arch/arm/lib/copy_from_user.S
806 @@ -16,7 +16,7 @@
807 /*
808 * Prototype:
809 *
810 - * size_t __copy_from_user(void *to, const void *from, size_t n)
811 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
812 *
813 * Purpose:
814 *
815 @@ -84,11 +84,11 @@
816
817 .text
818
819 -ENTRY(__copy_from_user)
820 +ENTRY(___copy_from_user)
821
822 #include "copy_template.S"
823
824 -ENDPROC(__copy_from_user)
825 +ENDPROC(___copy_from_user)
826
827 .pushsection .fixup,"ax"
828 .align 0
829 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
830 index d066df6..df28194 100644
831 --- a/arch/arm/lib/copy_to_user.S
832 +++ b/arch/arm/lib/copy_to_user.S
833 @@ -16,7 +16,7 @@
834 /*
835 * Prototype:
836 *
837 - * size_t __copy_to_user(void *to, const void *from, size_t n)
838 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
839 *
840 * Purpose:
841 *
842 @@ -88,11 +88,11 @@
843 .text
844
845 ENTRY(__copy_to_user_std)
846 -WEAK(__copy_to_user)
847 +WEAK(___copy_to_user)
848
849 #include "copy_template.S"
850
851 -ENDPROC(__copy_to_user)
852 +ENDPROC(___copy_to_user)
853 ENDPROC(__copy_to_user_std)
854
855 .pushsection .fixup,"ax"
856 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
857 index d0ece2a..5ae2f39 100644
858 --- a/arch/arm/lib/uaccess.S
859 +++ b/arch/arm/lib/uaccess.S
860 @@ -20,7 +20,7 @@
861
862 #define PAGE_SHIFT 12
863
864 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
865 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
866 * Purpose : copy a block to user memory from kernel memory
867 * Params : to - user memory
868 * : from - kernel memory
869 @@ -40,7 +40,7 @@ USER( T(strgtb) r3, [r0], #1) @ May fault
870 sub r2, r2, ip
871 b .Lc2u_dest_aligned
872
873 -ENTRY(__copy_to_user)
874 +ENTRY(___copy_to_user)
875 stmfd sp!, {r2, r4 - r7, lr}
876 cmp r2, #4
877 blt .Lc2u_not_enough
878 @@ -278,14 +278,14 @@ USER( T(strgeb) r3, [r0], #1) @ May fault
879 ldrgtb r3, [r1], #0
880 USER( T(strgtb) r3, [r0], #1) @ May fault
881 b .Lc2u_finished
882 -ENDPROC(__copy_to_user)
883 +ENDPROC(___copy_to_user)
884
885 .pushsection .fixup,"ax"
886 .align 0
887 9001: ldmfd sp!, {r0, r4 - r7, pc}
888 .popsection
889
890 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
891 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
892 * Purpose : copy a block from user memory to kernel memory
893 * Params : to - kernel memory
894 * : from - user memory
895 @@ -304,7 +304,7 @@ USER( T(ldrgtb) r3, [r1], #1) @ May fault
896 sub r2, r2, ip
897 b .Lcfu_dest_aligned
898
899 -ENTRY(__copy_from_user)
900 +ENTRY(___copy_from_user)
901 stmfd sp!, {r0, r2, r4 - r7, lr}
902 cmp r2, #4
903 blt .Lcfu_not_enough
904 @@ -544,7 +544,7 @@ USER( T(ldrgeb) r3, [r1], #1) @ May fault
905 USER( T(ldrgtb) r3, [r1], #1) @ May fault
906 strgtb r3, [r0], #1
907 b .Lcfu_finished
908 -ENDPROC(__copy_from_user)
909 +ENDPROC(___copy_from_user)
910
911 .pushsection .fixup,"ax"
912 .align 0
913 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
914 index 8b9b136..70d5100 100644
915 --- a/arch/arm/lib/uaccess_with_memcpy.c
916 +++ b/arch/arm/lib/uaccess_with_memcpy.c
917 @@ -103,7 +103,7 @@ out:
918 }
919
920 unsigned long
921 -__copy_to_user(void __user *to, const void *from, unsigned long n)
922 +___copy_to_user(void __user *to, const void *from, unsigned long n)
923 {
924 /*
925 * This test is stubbed out of the main function above to keep
926 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
927 index 2b2d51c..0127490 100644
928 --- a/arch/arm/mach-ux500/mbox-db5500.c
929 +++ b/arch/arm/mach-ux500/mbox-db5500.c
930 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
931 return sprintf(buf, "0x%X\n", mbox_value);
932 }
933
934 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
935 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
936
937 static int mbox_show(struct seq_file *s, void *data)
938 {
939 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
940 index 3b5ea68..42fc9af 100644
941 --- a/arch/arm/mm/fault.c
942 +++ b/arch/arm/mm/fault.c
943 @@ -182,6 +182,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
944 }
945 #endif
946
947 +#ifdef CONFIG_PAX_PAGEEXEC
948 + if (fsr & FSR_LNX_PF) {
949 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
950 + do_group_exit(SIGKILL);
951 + }
952 +#endif
953 +
954 tsk->thread.address = addr;
955 tsk->thread.error_code = fsr;
956 tsk->thread.trap_no = 14;
957 @@ -383,6 +390,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
958 }
959 #endif /* CONFIG_MMU */
960
961 +#ifdef CONFIG_PAX_PAGEEXEC
962 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
963 +{
964 + long i;
965 +
966 + printk(KERN_ERR "PAX: bytes at PC: ");
967 + for (i = 0; i < 20; i++) {
968 + unsigned char c;
969 + if (get_user(c, (__force unsigned char __user *)pc+i))
970 + printk(KERN_CONT "?? ");
971 + else
972 + printk(KERN_CONT "%02x ", c);
973 + }
974 + printk("\n");
975 +
976 + printk(KERN_ERR "PAX: bytes at SP-4: ");
977 + for (i = -1; i < 20; i++) {
978 + unsigned long c;
979 + if (get_user(c, (__force unsigned long __user *)sp+i))
980 + printk(KERN_CONT "???????? ");
981 + else
982 + printk(KERN_CONT "%08lx ", c);
983 + }
984 + printk("\n");
985 +}
986 +#endif
987 +
988 /*
989 * First Level Translation Fault Handler
990 *
991 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
992 index 74be05f..f605b8c 100644
993 --- a/arch/arm/mm/mmap.c
994 +++ b/arch/arm/mm/mmap.c
995 @@ -65,6 +65,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
996 if (len > TASK_SIZE)
997 return -ENOMEM;
998
999 +#ifdef CONFIG_PAX_RANDMMAP
1000 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1001 +#endif
1002 +
1003 if (addr) {
1004 if (do_align)
1005 addr = COLOUR_ALIGN(addr, pgoff);
1006 @@ -72,15 +76,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1007 addr = PAGE_ALIGN(addr);
1008
1009 vma = find_vma(mm, addr);
1010 - if (TASK_SIZE - len >= addr &&
1011 - (!vma || addr + len <= vma->vm_start))
1012 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1013 return addr;
1014 }
1015 if (len > mm->cached_hole_size) {
1016 - start_addr = addr = mm->free_area_cache;
1017 + start_addr = addr = mm->free_area_cache;
1018 } else {
1019 - start_addr = addr = TASK_UNMAPPED_BASE;
1020 - mm->cached_hole_size = 0;
1021 + start_addr = addr = mm->mmap_base;
1022 + mm->cached_hole_size = 0;
1023 }
1024 /* 8 bits of randomness in 20 address space bits */
1025 if ((current->flags & PF_RANDOMIZE) &&
1026 @@ -100,14 +103,14 @@ full_search:
1027 * Start a new search - just in case we missed
1028 * some holes.
1029 */
1030 - if (start_addr != TASK_UNMAPPED_BASE) {
1031 - start_addr = addr = TASK_UNMAPPED_BASE;
1032 + if (start_addr != mm->mmap_base) {
1033 + start_addr = addr = mm->mmap_base;
1034 mm->cached_hole_size = 0;
1035 goto full_search;
1036 }
1037 return -ENOMEM;
1038 }
1039 - if (!vma || addr + len <= vma->vm_start) {
1040 + if (check_heap_stack_gap(vma, addr, len)) {
1041 /*
1042 * Remember the place where we stopped the search:
1043 */
1044 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1045 index 3b3159b..425ea94 100644
1046 --- a/arch/avr32/include/asm/elf.h
1047 +++ b/arch/avr32/include/asm/elf.h
1048 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1049 the loader. We need to make sure that it is out of the way of the program
1050 that it will "exec", and that there is sufficient room for the brk. */
1051
1052 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1053 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1054
1055 +#ifdef CONFIG_PAX_ASLR
1056 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1057 +
1058 +#define PAX_DELTA_MMAP_LEN 15
1059 +#define PAX_DELTA_STACK_LEN 15
1060 +#endif
1061
1062 /* This yields a mask that user programs can use to figure out what
1063 instruction set this CPU supports. This could be done in user space,
1064 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1065 index b7f5c68..556135c 100644
1066 --- a/arch/avr32/include/asm/kmap_types.h
1067 +++ b/arch/avr32/include/asm/kmap_types.h
1068 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1069 D(11) KM_IRQ1,
1070 D(12) KM_SOFTIRQ0,
1071 D(13) KM_SOFTIRQ1,
1072 -D(14) KM_TYPE_NR
1073 +D(14) KM_CLEARPAGE,
1074 +D(15) KM_TYPE_NR
1075 };
1076
1077 #undef D
1078 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1079 index f7040a1..db9f300 100644
1080 --- a/arch/avr32/mm/fault.c
1081 +++ b/arch/avr32/mm/fault.c
1082 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1083
1084 int exception_trace = 1;
1085
1086 +#ifdef CONFIG_PAX_PAGEEXEC
1087 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1088 +{
1089 + unsigned long i;
1090 +
1091 + printk(KERN_ERR "PAX: bytes at PC: ");
1092 + for (i = 0; i < 20; i++) {
1093 + unsigned char c;
1094 + if (get_user(c, (unsigned char *)pc+i))
1095 + printk(KERN_CONT "???????? ");
1096 + else
1097 + printk(KERN_CONT "%02x ", c);
1098 + }
1099 + printk("\n");
1100 +}
1101 +#endif
1102 +
1103 /*
1104 * This routine handles page faults. It determines the address and the
1105 * problem, and then passes it off to one of the appropriate routines.
1106 @@ -156,6 +173,16 @@ bad_area:
1107 up_read(&mm->mmap_sem);
1108
1109 if (user_mode(regs)) {
1110 +
1111 +#ifdef CONFIG_PAX_PAGEEXEC
1112 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1113 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1114 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1115 + do_group_exit(SIGKILL);
1116 + }
1117 + }
1118 +#endif
1119 +
1120 if (exception_trace && printk_ratelimit())
1121 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1122 "sp %08lx ecr %lu\n",
1123 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
1124 index f8e16b2..c73ff79 100644
1125 --- a/arch/frv/include/asm/kmap_types.h
1126 +++ b/arch/frv/include/asm/kmap_types.h
1127 @@ -23,6 +23,7 @@ enum km_type {
1128 KM_IRQ1,
1129 KM_SOFTIRQ0,
1130 KM_SOFTIRQ1,
1131 + KM_CLEARPAGE,
1132 KM_TYPE_NR
1133 };
1134
1135 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
1136 index 385fd30..6c3d97e 100644
1137 --- a/arch/frv/mm/elf-fdpic.c
1138 +++ b/arch/frv/mm/elf-fdpic.c
1139 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1140 if (addr) {
1141 addr = PAGE_ALIGN(addr);
1142 vma = find_vma(current->mm, addr);
1143 - if (TASK_SIZE - len >= addr &&
1144 - (!vma || addr + len <= vma->vm_start))
1145 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1146 goto success;
1147 }
1148
1149 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1150 for (; vma; vma = vma->vm_next) {
1151 if (addr > limit)
1152 break;
1153 - if (addr + len <= vma->vm_start)
1154 + if (check_heap_stack_gap(vma, addr, len))
1155 goto success;
1156 addr = vma->vm_end;
1157 }
1158 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1159 for (; vma; vma = vma->vm_next) {
1160 if (addr > limit)
1161 break;
1162 - if (addr + len <= vma->vm_start)
1163 + if (check_heap_stack_gap(vma, addr, len))
1164 goto success;
1165 addr = vma->vm_end;
1166 }
1167 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
1168 index b5298eb..67c6e62 100644
1169 --- a/arch/ia64/include/asm/elf.h
1170 +++ b/arch/ia64/include/asm/elf.h
1171 @@ -42,6 +42,13 @@
1172 */
1173 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1174
1175 +#ifdef CONFIG_PAX_ASLR
1176 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1177 +
1178 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1179 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1180 +#endif
1181 +
1182 #define PT_IA_64_UNWIND 0x70000001
1183
1184 /* IA-64 relocations: */
1185 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
1186 index 1a97af3..7529d31 100644
1187 --- a/arch/ia64/include/asm/pgtable.h
1188 +++ b/arch/ia64/include/asm/pgtable.h
1189 @@ -12,7 +12,7 @@
1190 * David Mosberger-Tang <davidm@hpl.hp.com>
1191 */
1192
1193 -
1194 +#include <linux/const.h>
1195 #include <asm/mman.h>
1196 #include <asm/page.h>
1197 #include <asm/processor.h>
1198 @@ -143,6 +143,17 @@
1199 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1200 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1201 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1202 +
1203 +#ifdef CONFIG_PAX_PAGEEXEC
1204 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1205 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1206 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1207 +#else
1208 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1209 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1210 +# define PAGE_COPY_NOEXEC PAGE_COPY
1211 +#endif
1212 +
1213 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1214 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1215 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1216 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
1217 index b77768d..e0795eb 100644
1218 --- a/arch/ia64/include/asm/spinlock.h
1219 +++ b/arch/ia64/include/asm/spinlock.h
1220 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
1221 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1222
1223 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1224 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1225 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1226 }
1227
1228 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
1229 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
1230 index 449c8c0..432a3d2 100644
1231 --- a/arch/ia64/include/asm/uaccess.h
1232 +++ b/arch/ia64/include/asm/uaccess.h
1233 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1234 const void *__cu_from = (from); \
1235 long __cu_len = (n); \
1236 \
1237 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
1238 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1239 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1240 __cu_len; \
1241 })
1242 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1243 long __cu_len = (n); \
1244 \
1245 __chk_user_ptr(__cu_from); \
1246 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
1247 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1248 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1249 __cu_len; \
1250 })
1251 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
1252 index 24603be..948052d 100644
1253 --- a/arch/ia64/kernel/module.c
1254 +++ b/arch/ia64/kernel/module.c
1255 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
1256 void
1257 module_free (struct module *mod, void *module_region)
1258 {
1259 - if (mod && mod->arch.init_unw_table &&
1260 - module_region == mod->module_init) {
1261 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1262 unw_remove_unwind_table(mod->arch.init_unw_table);
1263 mod->arch.init_unw_table = NULL;
1264 }
1265 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
1266 }
1267
1268 static inline int
1269 +in_init_rx (const struct module *mod, uint64_t addr)
1270 +{
1271 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1272 +}
1273 +
1274 +static inline int
1275 +in_init_rw (const struct module *mod, uint64_t addr)
1276 +{
1277 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1278 +}
1279 +
1280 +static inline int
1281 in_init (const struct module *mod, uint64_t addr)
1282 {
1283 - return addr - (uint64_t) mod->module_init < mod->init_size;
1284 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1285 +}
1286 +
1287 +static inline int
1288 +in_core_rx (const struct module *mod, uint64_t addr)
1289 +{
1290 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1291 +}
1292 +
1293 +static inline int
1294 +in_core_rw (const struct module *mod, uint64_t addr)
1295 +{
1296 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1297 }
1298
1299 static inline int
1300 in_core (const struct module *mod, uint64_t addr)
1301 {
1302 - return addr - (uint64_t) mod->module_core < mod->core_size;
1303 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1304 }
1305
1306 static inline int
1307 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
1308 break;
1309
1310 case RV_BDREL:
1311 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1312 + if (in_init_rx(mod, val))
1313 + val -= (uint64_t) mod->module_init_rx;
1314 + else if (in_init_rw(mod, val))
1315 + val -= (uint64_t) mod->module_init_rw;
1316 + else if (in_core_rx(mod, val))
1317 + val -= (uint64_t) mod->module_core_rx;
1318 + else if (in_core_rw(mod, val))
1319 + val -= (uint64_t) mod->module_core_rw;
1320 break;
1321
1322 case RV_LTV:
1323 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
1324 * addresses have been selected...
1325 */
1326 uint64_t gp;
1327 - if (mod->core_size > MAX_LTOFF)
1328 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1329 /*
1330 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1331 * at the end of the module.
1332 */
1333 - gp = mod->core_size - MAX_LTOFF / 2;
1334 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1335 else
1336 - gp = mod->core_size / 2;
1337 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1338 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1339 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1340 mod->arch.gp = gp;
1341 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1342 }
1343 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
1344 index 609d500..7dde2a8 100644
1345 --- a/arch/ia64/kernel/sys_ia64.c
1346 +++ b/arch/ia64/kernel/sys_ia64.c
1347 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
1348 if (REGION_NUMBER(addr) == RGN_HPAGE)
1349 addr = 0;
1350 #endif
1351 +
1352 +#ifdef CONFIG_PAX_RANDMMAP
1353 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1354 + addr = mm->free_area_cache;
1355 + else
1356 +#endif
1357 +
1358 if (!addr)
1359 addr = mm->free_area_cache;
1360
1361 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
1362 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1363 /* At this point: (!vma || addr < vma->vm_end). */
1364 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1365 - if (start_addr != TASK_UNMAPPED_BASE) {
1366 + if (start_addr != mm->mmap_base) {
1367 /* Start a new search --- just in case we missed some holes. */
1368 - addr = TASK_UNMAPPED_BASE;
1369 + addr = mm->mmap_base;
1370 goto full_search;
1371 }
1372 return -ENOMEM;
1373 }
1374 - if (!vma || addr + len <= vma->vm_start) {
1375 + if (check_heap_stack_gap(vma, addr, len)) {
1376 /* Remember the address where we stopped this search: */
1377 mm->free_area_cache = addr + len;
1378 return addr;
1379 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
1380 index 53c0ba0..2accdde 100644
1381 --- a/arch/ia64/kernel/vmlinux.lds.S
1382 +++ b/arch/ia64/kernel/vmlinux.lds.S
1383 @@ -199,7 +199,7 @@ SECTIONS {
1384 /* Per-cpu data: */
1385 . = ALIGN(PERCPU_PAGE_SIZE);
1386 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
1387 - __phys_per_cpu_start = __per_cpu_load;
1388 + __phys_per_cpu_start = per_cpu_load;
1389 /*
1390 * ensure percpu data fits
1391 * into percpu page size
1392 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
1393 index 20b3593..1ce77f0 100644
1394 --- a/arch/ia64/mm/fault.c
1395 +++ b/arch/ia64/mm/fault.c
1396 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
1397 return pte_present(pte);
1398 }
1399
1400 +#ifdef CONFIG_PAX_PAGEEXEC
1401 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1402 +{
1403 + unsigned long i;
1404 +
1405 + printk(KERN_ERR "PAX: bytes at PC: ");
1406 + for (i = 0; i < 8; i++) {
1407 + unsigned int c;
1408 + if (get_user(c, (unsigned int *)pc+i))
1409 + printk(KERN_CONT "???????? ");
1410 + else
1411 + printk(KERN_CONT "%08x ", c);
1412 + }
1413 + printk("\n");
1414 +}
1415 +#endif
1416 +
1417 void __kprobes
1418 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1419 {
1420 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
1421 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1422 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1423
1424 - if ((vma->vm_flags & mask) != mask)
1425 + if ((vma->vm_flags & mask) != mask) {
1426 +
1427 +#ifdef CONFIG_PAX_PAGEEXEC
1428 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1429 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1430 + goto bad_area;
1431 +
1432 + up_read(&mm->mmap_sem);
1433 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1434 + do_group_exit(SIGKILL);
1435 + }
1436 +#endif
1437 +
1438 goto bad_area;
1439
1440 + }
1441 +
1442 /*
1443 * If for any reason at all we couldn't handle the fault, make
1444 * sure we exit gracefully rather than endlessly redo the
1445 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
1446 index 5ca674b..e0e1b70 100644
1447 --- a/arch/ia64/mm/hugetlbpage.c
1448 +++ b/arch/ia64/mm/hugetlbpage.c
1449 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
1450 /* At this point: (!vmm || addr < vmm->vm_end). */
1451 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1452 return -ENOMEM;
1453 - if (!vmm || (addr + len) <= vmm->vm_start)
1454 + if (check_heap_stack_gap(vmm, addr, len))
1455 return addr;
1456 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1457 }
1458 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
1459 index 00cb0e2..2ad8024 100644
1460 --- a/arch/ia64/mm/init.c
1461 +++ b/arch/ia64/mm/init.c
1462 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
1463 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1464 vma->vm_end = vma->vm_start + PAGE_SIZE;
1465 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1466 +
1467 +#ifdef CONFIG_PAX_PAGEEXEC
1468 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1469 + vma->vm_flags &= ~VM_EXEC;
1470 +
1471 +#ifdef CONFIG_PAX_MPROTECT
1472 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
1473 + vma->vm_flags &= ~VM_MAYEXEC;
1474 +#endif
1475 +
1476 + }
1477 +#endif
1478 +
1479 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1480 down_write(&current->mm->mmap_sem);
1481 if (insert_vm_struct(current->mm, vma)) {
1482 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
1483 index 82abd15..d95ae5d 100644
1484 --- a/arch/m32r/lib/usercopy.c
1485 +++ b/arch/m32r/lib/usercopy.c
1486 @@ -14,6 +14,9 @@
1487 unsigned long
1488 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1489 {
1490 + if ((long)n < 0)
1491 + return n;
1492 +
1493 prefetch(from);
1494 if (access_ok(VERIFY_WRITE, to, n))
1495 __copy_user(to,from,n);
1496 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1497 unsigned long
1498 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1499 {
1500 + if ((long)n < 0)
1501 + return n;
1502 +
1503 prefetchw(to);
1504 if (access_ok(VERIFY_READ, from, n))
1505 __copy_user_zeroing(to,from,n);
1506 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
1507 index 455c0ac..ad65fbe 100644
1508 --- a/arch/mips/include/asm/elf.h
1509 +++ b/arch/mips/include/asm/elf.h
1510 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
1511 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1512 #endif
1513
1514 +#ifdef CONFIG_PAX_ASLR
1515 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1516 +
1517 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1518 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1519 +#endif
1520 +
1521 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1522 struct linux_binprm;
1523 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
1524 int uses_interp);
1525
1526 -struct mm_struct;
1527 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1528 -#define arch_randomize_brk arch_randomize_brk
1529 -
1530 #endif /* _ASM_ELF_H */
1531 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
1532 index e59cd1a..8e329d6 100644
1533 --- a/arch/mips/include/asm/page.h
1534 +++ b/arch/mips/include/asm/page.h
1535 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
1536 #ifdef CONFIG_CPU_MIPS32
1537 typedef struct { unsigned long pte_low, pte_high; } pte_t;
1538 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
1539 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
1540 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
1541 #else
1542 typedef struct { unsigned long long pte; } pte_t;
1543 #define pte_val(x) ((x).pte)
1544 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
1545 index 6018c80..7c37203 100644
1546 --- a/arch/mips/include/asm/system.h
1547 +++ b/arch/mips/include/asm/system.h
1548 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
1549 */
1550 #define __ARCH_WANT_UNLOCKED_CTXSW
1551
1552 -extern unsigned long arch_align_stack(unsigned long sp);
1553 +#define arch_align_stack(x) ((x) & ~0xfUL)
1554
1555 #endif /* _ASM_SYSTEM_H */
1556 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
1557 index 9fdd8bc..4bd7f1a 100644
1558 --- a/arch/mips/kernel/binfmt_elfn32.c
1559 +++ b/arch/mips/kernel/binfmt_elfn32.c
1560 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1561 #undef ELF_ET_DYN_BASE
1562 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1563
1564 +#ifdef CONFIG_PAX_ASLR
1565 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1566 +
1567 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1568 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1569 +#endif
1570 +
1571 #include <asm/processor.h>
1572 #include <linux/module.h>
1573 #include <linux/elfcore.h>
1574 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
1575 index ff44823..97f8906 100644
1576 --- a/arch/mips/kernel/binfmt_elfo32.c
1577 +++ b/arch/mips/kernel/binfmt_elfo32.c
1578 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1579 #undef ELF_ET_DYN_BASE
1580 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1581
1582 +#ifdef CONFIG_PAX_ASLR
1583 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1584 +
1585 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1586 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1587 +#endif
1588 +
1589 #include <asm/processor.h>
1590
1591 /*
1592 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
1593 index b30cb25..454c0a9 100644
1594 --- a/arch/mips/kernel/process.c
1595 +++ b/arch/mips/kernel/process.c
1596 @@ -481,15 +481,3 @@ unsigned long get_wchan(struct task_struct *task)
1597 out:
1598 return pc;
1599 }
1600 -
1601 -/*
1602 - * Don't forget that the stack pointer must be aligned on a 8 bytes
1603 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
1604 - */
1605 -unsigned long arch_align_stack(unsigned long sp)
1606 -{
1607 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1608 - sp -= get_random_int() & ~PAGE_MASK;
1609 -
1610 - return sp & ALMASK;
1611 -}
1612 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
1613 index 937cf33..adb39bb 100644
1614 --- a/arch/mips/mm/fault.c
1615 +++ b/arch/mips/mm/fault.c
1616 @@ -28,6 +28,23 @@
1617 #include <asm/highmem.h> /* For VMALLOC_END */
1618 #include <linux/kdebug.h>
1619
1620 +#ifdef CONFIG_PAX_PAGEEXEC
1621 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1622 +{
1623 + unsigned long i;
1624 +
1625 + printk(KERN_ERR "PAX: bytes at PC: ");
1626 + for (i = 0; i < 5; i++) {
1627 + unsigned int c;
1628 + if (get_user(c, (unsigned int *)pc+i))
1629 + printk(KERN_CONT "???????? ");
1630 + else
1631 + printk(KERN_CONT "%08x ", c);
1632 + }
1633 + printk("\n");
1634 +}
1635 +#endif
1636 +
1637 /*
1638 * This routine handles page faults. It determines the address,
1639 * and the problem, and then passes it off to one of the appropriate
1640 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
1641 index 302d779..7d35bf8 100644
1642 --- a/arch/mips/mm/mmap.c
1643 +++ b/arch/mips/mm/mmap.c
1644 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1645 do_color_align = 1;
1646
1647 /* requesting a specific address */
1648 +
1649 +#ifdef CONFIG_PAX_RANDMMAP
1650 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1651 +#endif
1652 +
1653 if (addr) {
1654 if (do_color_align)
1655 addr = COLOUR_ALIGN(addr, pgoff);
1656 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1657 addr = PAGE_ALIGN(addr);
1658
1659 vma = find_vma(mm, addr);
1660 - if (TASK_SIZE - len >= addr &&
1661 - (!vma || addr + len <= vma->vm_start))
1662 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
1663 return addr;
1664 }
1665
1666 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1667 /* At this point: (!vma || addr < vma->vm_end). */
1668 if (TASK_SIZE - len < addr)
1669 return -ENOMEM;
1670 - if (!vma || addr + len <= vma->vm_start)
1671 + if (check_heap_stack_gap(vmm, addr, len))
1672 return addr;
1673 addr = vma->vm_end;
1674 if (do_color_align)
1675 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1676 /* make sure it can fit in the remaining address space */
1677 if (likely(addr > len)) {
1678 vma = find_vma(mm, addr - len);
1679 - if (!vma || addr <= vma->vm_start) {
1680 + if (check_heap_stack_gap(vmm, addr - len, len))
1681 /* cache the address as a hint for next time */
1682 return mm->free_area_cache = addr - len;
1683 }
1684 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1685 * return with success:
1686 */
1687 vma = find_vma(mm, addr);
1688 - if (likely(!vma || addr + len <= vma->vm_start)) {
1689 + if (check_heap_stack_gap(vmm, addr, len)) {
1690 /* cache the address as a hint for next time */
1691 return mm->free_area_cache = addr;
1692 }
1693 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1694 mm->unmap_area = arch_unmap_area_topdown;
1695 }
1696 }
1697 -
1698 -static inline unsigned long brk_rnd(void)
1699 -{
1700 - unsigned long rnd = get_random_int();
1701 -
1702 - rnd = rnd << PAGE_SHIFT;
1703 - /* 8MB for 32bit, 256MB for 64bit */
1704 - if (TASK_IS_32BIT_ADDR)
1705 - rnd = rnd & 0x7ffffful;
1706 - else
1707 - rnd = rnd & 0xffffffful;
1708 -
1709 - return rnd;
1710 -}
1711 -
1712 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1713 -{
1714 - unsigned long base = mm->brk;
1715 - unsigned long ret;
1716 -
1717 - ret = PAGE_ALIGN(base + brk_rnd());
1718 -
1719 - if (ret < mm->brk)
1720 - return mm->brk;
1721 -
1722 - return ret;
1723 -}
1724 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
1725 index 19f6cb1..6c78cf2 100644
1726 --- a/arch/parisc/include/asm/elf.h
1727 +++ b/arch/parisc/include/asm/elf.h
1728 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
1729
1730 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
1731
1732 +#ifdef CONFIG_PAX_ASLR
1733 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
1734 +
1735 +#define PAX_DELTA_MMAP_LEN 16
1736 +#define PAX_DELTA_STACK_LEN 16
1737 +#endif
1738 +
1739 /* This yields a mask that user programs can use to figure out what
1740 instruction set this CPU supports. This could be done in user space,
1741 but it's not easy, and we've already done it here. */
1742 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
1743 index 22dadeb..f6c2be4 100644
1744 --- a/arch/parisc/include/asm/pgtable.h
1745 +++ b/arch/parisc/include/asm/pgtable.h
1746 @@ -210,6 +210,17 @@ struct vm_area_struct;
1747 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
1748 #define PAGE_COPY PAGE_EXECREAD
1749 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
1750 +
1751 +#ifdef CONFIG_PAX_PAGEEXEC
1752 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
1753 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1754 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1755 +#else
1756 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1757 +# define PAGE_COPY_NOEXEC PAGE_COPY
1758 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1759 +#endif
1760 +
1761 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
1762 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
1763 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
1764 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
1765 index 5e34ccf..672bc9c 100644
1766 --- a/arch/parisc/kernel/module.c
1767 +++ b/arch/parisc/kernel/module.c
1768 @@ -98,16 +98,38 @@
1769
1770 /* three functions to determine where in the module core
1771 * or init pieces the location is */
1772 +static inline int in_init_rx(struct module *me, void *loc)
1773 +{
1774 + return (loc >= me->module_init_rx &&
1775 + loc < (me->module_init_rx + me->init_size_rx));
1776 +}
1777 +
1778 +static inline int in_init_rw(struct module *me, void *loc)
1779 +{
1780 + return (loc >= me->module_init_rw &&
1781 + loc < (me->module_init_rw + me->init_size_rw));
1782 +}
1783 +
1784 static inline int in_init(struct module *me, void *loc)
1785 {
1786 - return (loc >= me->module_init &&
1787 - loc <= (me->module_init + me->init_size));
1788 + return in_init_rx(me, loc) || in_init_rw(me, loc);
1789 +}
1790 +
1791 +static inline int in_core_rx(struct module *me, void *loc)
1792 +{
1793 + return (loc >= me->module_core_rx &&
1794 + loc < (me->module_core_rx + me->core_size_rx));
1795 +}
1796 +
1797 +static inline int in_core_rw(struct module *me, void *loc)
1798 +{
1799 + return (loc >= me->module_core_rw &&
1800 + loc < (me->module_core_rw + me->core_size_rw));
1801 }
1802
1803 static inline int in_core(struct module *me, void *loc)
1804 {
1805 - return (loc >= me->module_core &&
1806 - loc <= (me->module_core + me->core_size));
1807 + return in_core_rx(me, loc) || in_core_rw(me, loc);
1808 }
1809
1810 static inline int in_local(struct module *me, void *loc)
1811 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
1812 }
1813
1814 /* align things a bit */
1815 - me->core_size = ALIGN(me->core_size, 16);
1816 - me->arch.got_offset = me->core_size;
1817 - me->core_size += gots * sizeof(struct got_entry);
1818 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
1819 + me->arch.got_offset = me->core_size_rw;
1820 + me->core_size_rw += gots * sizeof(struct got_entry);
1821
1822 - me->core_size = ALIGN(me->core_size, 16);
1823 - me->arch.fdesc_offset = me->core_size;
1824 - me->core_size += fdescs * sizeof(Elf_Fdesc);
1825 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
1826 + me->arch.fdesc_offset = me->core_size_rw;
1827 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
1828
1829 me->arch.got_max = gots;
1830 me->arch.fdesc_max = fdescs;
1831 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
1832
1833 BUG_ON(value == 0);
1834
1835 - got = me->module_core + me->arch.got_offset;
1836 + got = me->module_core_rw + me->arch.got_offset;
1837 for (i = 0; got[i].addr; i++)
1838 if (got[i].addr == value)
1839 goto out;
1840 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
1841 #ifdef CONFIG_64BIT
1842 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1843 {
1844 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1845 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
1846
1847 if (!value) {
1848 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1849 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1850
1851 /* Create new one */
1852 fdesc->addr = value;
1853 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1854 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1855 return (Elf_Addr)fdesc;
1856 }
1857 #endif /* CONFIG_64BIT */
1858 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
1859
1860 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
1861 end = table + sechdrs[me->arch.unwind_section].sh_size;
1862 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1863 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1864
1865 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
1866 me->arch.unwind_section, table, end, gp);
1867 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
1868 index c9b9322..02d8940 100644
1869 --- a/arch/parisc/kernel/sys_parisc.c
1870 +++ b/arch/parisc/kernel/sys_parisc.c
1871 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
1872 /* At this point: (!vma || addr < vma->vm_end). */
1873 if (TASK_SIZE - len < addr)
1874 return -ENOMEM;
1875 - if (!vma || addr + len <= vma->vm_start)
1876 + if (check_heap_stack_gap(vma, addr, len))
1877 return addr;
1878 addr = vma->vm_end;
1879 }
1880 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
1881 /* At this point: (!vma || addr < vma->vm_end). */
1882 if (TASK_SIZE - len < addr)
1883 return -ENOMEM;
1884 - if (!vma || addr + len <= vma->vm_start)
1885 + if (check_heap_stack_gap(vma, addr, len))
1886 return addr;
1887 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
1888 if (addr < vma->vm_end) /* handle wraparound */
1889 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
1890 if (flags & MAP_FIXED)
1891 return addr;
1892 if (!addr)
1893 - addr = TASK_UNMAPPED_BASE;
1894 + addr = current->mm->mmap_base;
1895
1896 if (filp) {
1897 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
1898 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
1899 index f19e660..414fe24 100644
1900 --- a/arch/parisc/kernel/traps.c
1901 +++ b/arch/parisc/kernel/traps.c
1902 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
1903
1904 down_read(&current->mm->mmap_sem);
1905 vma = find_vma(current->mm,regs->iaoq[0]);
1906 - if (vma && (regs->iaoq[0] >= vma->vm_start)
1907 - && (vma->vm_flags & VM_EXEC)) {
1908 -
1909 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
1910 fault_address = regs->iaoq[0];
1911 fault_space = regs->iasq[0];
1912
1913 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
1914 index 18162ce..94de376 100644
1915 --- a/arch/parisc/mm/fault.c
1916 +++ b/arch/parisc/mm/fault.c
1917 @@ -15,6 +15,7 @@
1918 #include <linux/sched.h>
1919 #include <linux/interrupt.h>
1920 #include <linux/module.h>
1921 +#include <linux/unistd.h>
1922
1923 #include <asm/uaccess.h>
1924 #include <asm/traps.h>
1925 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
1926 static unsigned long
1927 parisc_acctyp(unsigned long code, unsigned int inst)
1928 {
1929 - if (code == 6 || code == 16)
1930 + if (code == 6 || code == 7 || code == 16)
1931 return VM_EXEC;
1932
1933 switch (inst & 0xf0000000) {
1934 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
1935 }
1936 #endif
1937
1938 +#ifdef CONFIG_PAX_PAGEEXEC
1939 +/*
1940 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
1941 + *
1942 + * returns 1 when task should be killed
1943 + * 2 when rt_sigreturn trampoline was detected
1944 + * 3 when unpatched PLT trampoline was detected
1945 + */
1946 +static int pax_handle_fetch_fault(struct pt_regs *regs)
1947 +{
1948 +
1949 +#ifdef CONFIG_PAX_EMUPLT
1950 + int err;
1951 +
1952 + do { /* PaX: unpatched PLT emulation */
1953 + unsigned int bl, depwi;
1954 +
1955 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
1956 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
1957 +
1958 + if (err)
1959 + break;
1960 +
1961 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
1962 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
1963 +
1964 + err = get_user(ldw, (unsigned int *)addr);
1965 + err |= get_user(bv, (unsigned int *)(addr+4));
1966 + err |= get_user(ldw2, (unsigned int *)(addr+8));
1967 +
1968 + if (err)
1969 + break;
1970 +
1971 + if (ldw == 0x0E801096U &&
1972 + bv == 0xEAC0C000U &&
1973 + ldw2 == 0x0E881095U)
1974 + {
1975 + unsigned int resolver, map;
1976 +
1977 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
1978 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
1979 + if (err)
1980 + break;
1981 +
1982 + regs->gr[20] = instruction_pointer(regs)+8;
1983 + regs->gr[21] = map;
1984 + regs->gr[22] = resolver;
1985 + regs->iaoq[0] = resolver | 3UL;
1986 + regs->iaoq[1] = regs->iaoq[0] + 4;
1987 + return 3;
1988 + }
1989 + }
1990 + } while (0);
1991 +#endif
1992 +
1993 +#ifdef CONFIG_PAX_EMUTRAMP
1994 +
1995 +#ifndef CONFIG_PAX_EMUSIGRT
1996 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
1997 + return 1;
1998 +#endif
1999 +
2000 + do { /* PaX: rt_sigreturn emulation */
2001 + unsigned int ldi1, ldi2, bel, nop;
2002 +
2003 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
2004 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
2005 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
2006 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
2007 +
2008 + if (err)
2009 + break;
2010 +
2011 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
2012 + ldi2 == 0x3414015AU &&
2013 + bel == 0xE4008200U &&
2014 + nop == 0x08000240U)
2015 + {
2016 + regs->gr[25] = (ldi1 & 2) >> 1;
2017 + regs->gr[20] = __NR_rt_sigreturn;
2018 + regs->gr[31] = regs->iaoq[1] + 16;
2019 + regs->sr[0] = regs->iasq[1];
2020 + regs->iaoq[0] = 0x100UL;
2021 + regs->iaoq[1] = regs->iaoq[0] + 4;
2022 + regs->iasq[0] = regs->sr[2];
2023 + regs->iasq[1] = regs->sr[2];
2024 + return 2;
2025 + }
2026 + } while (0);
2027 +#endif
2028 +
2029 + return 1;
2030 +}
2031 +
2032 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2033 +{
2034 + unsigned long i;
2035 +
2036 + printk(KERN_ERR "PAX: bytes at PC: ");
2037 + for (i = 0; i < 5; i++) {
2038 + unsigned int c;
2039 + if (get_user(c, (unsigned int *)pc+i))
2040 + printk(KERN_CONT "???????? ");
2041 + else
2042 + printk(KERN_CONT "%08x ", c);
2043 + }
2044 + printk("\n");
2045 +}
2046 +#endif
2047 +
2048 int fixup_exception(struct pt_regs *regs)
2049 {
2050 const struct exception_table_entry *fix;
2051 @@ -192,8 +303,33 @@ good_area:
2052
2053 acc_type = parisc_acctyp(code,regs->iir);
2054
2055 - if ((vma->vm_flags & acc_type) != acc_type)
2056 + if ((vma->vm_flags & acc_type) != acc_type) {
2057 +
2058 +#ifdef CONFIG_PAX_PAGEEXEC
2059 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
2060 + (address & ~3UL) == instruction_pointer(regs))
2061 + {
2062 + up_read(&mm->mmap_sem);
2063 + switch (pax_handle_fetch_fault(regs)) {
2064 +
2065 +#ifdef CONFIG_PAX_EMUPLT
2066 + case 3:
2067 + return;
2068 +#endif
2069 +
2070 +#ifdef CONFIG_PAX_EMUTRAMP
2071 + case 2:
2072 + return;
2073 +#endif
2074 +
2075 + }
2076 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
2077 + do_group_exit(SIGKILL);
2078 + }
2079 +#endif
2080 +
2081 goto bad_area;
2082 + }
2083
2084 /*
2085 * If for any reason at all we couldn't handle the fault, make
2086 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
2087 index 3bf9cca..e7457d0 100644
2088 --- a/arch/powerpc/include/asm/elf.h
2089 +++ b/arch/powerpc/include/asm/elf.h
2090 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
2091 the loader. We need to make sure that it is out of the way of the program
2092 that it will "exec", and that there is sufficient room for the brk. */
2093
2094 -extern unsigned long randomize_et_dyn(unsigned long base);
2095 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
2096 +#define ELF_ET_DYN_BASE (0x20000000)
2097 +
2098 +#ifdef CONFIG_PAX_ASLR
2099 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
2100 +
2101 +#ifdef __powerpc64__
2102 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
2103 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
2104 +#else
2105 +#define PAX_DELTA_MMAP_LEN 15
2106 +#define PAX_DELTA_STACK_LEN 15
2107 +#endif
2108 +#endif
2109
2110 /*
2111 * Our registers are always unsigned longs, whether we're a 32 bit
2112 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2113 (0x7ff >> (PAGE_SHIFT - 12)) : \
2114 (0x3ffff >> (PAGE_SHIFT - 12)))
2115
2116 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2117 -#define arch_randomize_brk arch_randomize_brk
2118 -
2119 #endif /* __KERNEL__ */
2120
2121 /*
2122 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
2123 index bca8fdc..61e9580 100644
2124 --- a/arch/powerpc/include/asm/kmap_types.h
2125 +++ b/arch/powerpc/include/asm/kmap_types.h
2126 @@ -27,6 +27,7 @@ enum km_type {
2127 KM_PPC_SYNC_PAGE,
2128 KM_PPC_SYNC_ICACHE,
2129 KM_KDB,
2130 + KM_CLEARPAGE,
2131 KM_TYPE_NR
2132 };
2133
2134 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
2135 index d4a7f64..451de1c 100644
2136 --- a/arch/powerpc/include/asm/mman.h
2137 +++ b/arch/powerpc/include/asm/mman.h
2138 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
2139 }
2140 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
2141
2142 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
2143 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
2144 {
2145 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
2146 }
2147 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
2148 index 2cd664e..1d2e8a7 100644
2149 --- a/arch/powerpc/include/asm/page.h
2150 +++ b/arch/powerpc/include/asm/page.h
2151 @@ -129,8 +129,9 @@ extern phys_addr_t kernstart_addr;
2152 * and needs to be executable. This means the whole heap ends
2153 * up being executable.
2154 */
2155 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2156 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2157 +#define VM_DATA_DEFAULT_FLAGS32 \
2158 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2159 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2160
2161 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2162 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2163 @@ -158,6 +159,9 @@ extern phys_addr_t kernstart_addr;
2164 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
2165 #endif
2166
2167 +#define ktla_ktva(addr) (addr)
2168 +#define ktva_ktla(addr) (addr)
2169 +
2170 #ifndef __ASSEMBLY__
2171
2172 #undef STRICT_MM_TYPECHECKS
2173 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
2174 index 9356262..ea96148 100644
2175 --- a/arch/powerpc/include/asm/page_64.h
2176 +++ b/arch/powerpc/include/asm/page_64.h
2177 @@ -155,15 +155,18 @@ do { \
2178 * stack by default, so in the absence of a PT_GNU_STACK program header
2179 * we turn execute permission off.
2180 */
2181 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2182 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2183 +#define VM_STACK_DEFAULT_FLAGS32 \
2184 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2185 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2186
2187 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2188 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2189
2190 +#ifndef CONFIG_PAX_PAGEEXEC
2191 #define VM_STACK_DEFAULT_FLAGS \
2192 (is_32bit_task() ? \
2193 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
2194 +#endif
2195
2196 #include <asm-generic/getorder.h>
2197
2198 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
2199 index 88b0bd9..e32bc67 100644
2200 --- a/arch/powerpc/include/asm/pgtable.h
2201 +++ b/arch/powerpc/include/asm/pgtable.h
2202 @@ -2,6 +2,7 @@
2203 #define _ASM_POWERPC_PGTABLE_H
2204 #ifdef __KERNEL__
2205
2206 +#include <linux/const.h>
2207 #ifndef __ASSEMBLY__
2208 #include <asm/processor.h> /* For TASK_SIZE */
2209 #include <asm/mmu.h>
2210 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
2211 index 4aad413..85d86bf 100644
2212 --- a/arch/powerpc/include/asm/pte-hash32.h
2213 +++ b/arch/powerpc/include/asm/pte-hash32.h
2214 @@ -21,6 +21,7 @@
2215 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
2216 #define _PAGE_USER 0x004 /* usermode access allowed */
2217 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
2218 +#define _PAGE_EXEC _PAGE_GUARDED
2219 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
2220 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
2221 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
2222 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
2223 index 559da19..7e5835c 100644
2224 --- a/arch/powerpc/include/asm/reg.h
2225 +++ b/arch/powerpc/include/asm/reg.h
2226 @@ -212,6 +212,7 @@
2227 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
2228 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
2229 #define DSISR_NOHPTE 0x40000000 /* no translation found */
2230 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
2231 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
2232 #define DSISR_ISSTORE 0x02000000 /* access was a store */
2233 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
2234 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
2235 index e30a13d..2b7d994 100644
2236 --- a/arch/powerpc/include/asm/system.h
2237 +++ b/arch/powerpc/include/asm/system.h
2238 @@ -530,7 +530,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
2239 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
2240 #endif
2241
2242 -extern unsigned long arch_align_stack(unsigned long sp);
2243 +#define arch_align_stack(x) ((x) & ~0xfUL)
2244
2245 /* Used in very early kernel initialization. */
2246 extern unsigned long reloc_offset(void);
2247 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
2248 index bd0fb84..a42a14b 100644
2249 --- a/arch/powerpc/include/asm/uaccess.h
2250 +++ b/arch/powerpc/include/asm/uaccess.h
2251 @@ -13,6 +13,8 @@
2252 #define VERIFY_READ 0
2253 #define VERIFY_WRITE 1
2254
2255 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
2256 +
2257 /*
2258 * The fs value determines whether argument validity checking should be
2259 * performed or not. If get_fs() == USER_DS, checking is performed, with
2260 @@ -327,52 +329,6 @@ do { \
2261 extern unsigned long __copy_tofrom_user(void __user *to,
2262 const void __user *from, unsigned long size);
2263
2264 -#ifndef __powerpc64__
2265 -
2266 -static inline unsigned long copy_from_user(void *to,
2267 - const void __user *from, unsigned long n)
2268 -{
2269 - unsigned long over;
2270 -
2271 - if (access_ok(VERIFY_READ, from, n))
2272 - return __copy_tofrom_user((__force void __user *)to, from, n);
2273 - if ((unsigned long)from < TASK_SIZE) {
2274 - over = (unsigned long)from + n - TASK_SIZE;
2275 - return __copy_tofrom_user((__force void __user *)to, from,
2276 - n - over) + over;
2277 - }
2278 - return n;
2279 -}
2280 -
2281 -static inline unsigned long copy_to_user(void __user *to,
2282 - const void *from, unsigned long n)
2283 -{
2284 - unsigned long over;
2285 -
2286 - if (access_ok(VERIFY_WRITE, to, n))
2287 - return __copy_tofrom_user(to, (__force void __user *)from, n);
2288 - if ((unsigned long)to < TASK_SIZE) {
2289 - over = (unsigned long)to + n - TASK_SIZE;
2290 - return __copy_tofrom_user(to, (__force void __user *)from,
2291 - n - over) + over;
2292 - }
2293 - return n;
2294 -}
2295 -
2296 -#else /* __powerpc64__ */
2297 -
2298 -#define __copy_in_user(to, from, size) \
2299 - __copy_tofrom_user((to), (from), (size))
2300 -
2301 -extern unsigned long copy_from_user(void *to, const void __user *from,
2302 - unsigned long n);
2303 -extern unsigned long copy_to_user(void __user *to, const void *from,
2304 - unsigned long n);
2305 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
2306 - unsigned long n);
2307 -
2308 -#endif /* __powerpc64__ */
2309 -
2310 static inline unsigned long __copy_from_user_inatomic(void *to,
2311 const void __user *from, unsigned long n)
2312 {
2313 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
2314 if (ret == 0)
2315 return 0;
2316 }
2317 +
2318 + if (!__builtin_constant_p(n))
2319 + check_object_size(to, n, false);
2320 +
2321 return __copy_tofrom_user((__force void __user *)to, from, n);
2322 }
2323
2324 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
2325 if (ret == 0)
2326 return 0;
2327 }
2328 +
2329 + if (!__builtin_constant_p(n))
2330 + check_object_size(from, n, true);
2331 +
2332 return __copy_tofrom_user(to, (__force const void __user *)from, n);
2333 }
2334
2335 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
2336 return __copy_to_user_inatomic(to, from, size);
2337 }
2338
2339 +#ifndef __powerpc64__
2340 +
2341 +static inline unsigned long __must_check copy_from_user(void *to,
2342 + const void __user *from, unsigned long n)
2343 +{
2344 + unsigned long over;
2345 +
2346 + if ((long)n < 0)
2347 + return n;
2348 +
2349 + if (access_ok(VERIFY_READ, from, n)) {
2350 + if (!__builtin_constant_p(n))
2351 + check_object_size(to, n, false);
2352 + return __copy_tofrom_user((__force void __user *)to, from, n);
2353 + }
2354 + if ((unsigned long)from < TASK_SIZE) {
2355 + over = (unsigned long)from + n - TASK_SIZE;
2356 + if (!__builtin_constant_p(n - over))
2357 + check_object_size(to, n - over, false);
2358 + return __copy_tofrom_user((__force void __user *)to, from,
2359 + n - over) + over;
2360 + }
2361 + return n;
2362 +}
2363 +
2364 +static inline unsigned long __must_check copy_to_user(void __user *to,
2365 + const void *from, unsigned long n)
2366 +{
2367 + unsigned long over;
2368 +
2369 + if ((long)n < 0)
2370 + return n;
2371 +
2372 + if (access_ok(VERIFY_WRITE, to, n)) {
2373 + if (!__builtin_constant_p(n))
2374 + check_object_size(from, n, true);
2375 + return __copy_tofrom_user(to, (__force void __user *)from, n);
2376 + }
2377 + if ((unsigned long)to < TASK_SIZE) {
2378 + over = (unsigned long)to + n - TASK_SIZE;
2379 + if (!__builtin_constant_p(n))
2380 + check_object_size(from, n - over, true);
2381 + return __copy_tofrom_user(to, (__force void __user *)from,
2382 + n - over) + over;
2383 + }
2384 + return n;
2385 +}
2386 +
2387 +#else /* __powerpc64__ */
2388 +
2389 +#define __copy_in_user(to, from, size) \
2390 + __copy_tofrom_user((to), (from), (size))
2391 +
2392 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2393 +{
2394 + if ((long)n < 0 || n > INT_MAX)
2395 + return n;
2396 +
2397 + if (!__builtin_constant_p(n))
2398 + check_object_size(to, n, false);
2399 +
2400 + if (likely(access_ok(VERIFY_READ, from, n)))
2401 + n = __copy_from_user(to, from, n);
2402 + else
2403 + memset(to, 0, n);
2404 + return n;
2405 +}
2406 +
2407 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2408 +{
2409 + if ((long)n < 0 || n > INT_MAX)
2410 + return n;
2411 +
2412 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
2413 + if (!__builtin_constant_p(n))
2414 + check_object_size(from, n, true);
2415 + n = __copy_to_user(to, from, n);
2416 + }
2417 + return n;
2418 +}
2419 +
2420 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
2421 + unsigned long n);
2422 +
2423 +#endif /* __powerpc64__ */
2424 +
2425 extern unsigned long __clear_user(void __user *addr, unsigned long size);
2426
2427 static inline unsigned long clear_user(void __user *addr, unsigned long size)
2428 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
2429 index 429983c..7af363b 100644
2430 --- a/arch/powerpc/kernel/exceptions-64e.S
2431 +++ b/arch/powerpc/kernel/exceptions-64e.S
2432 @@ -587,6 +587,7 @@ storage_fault_common:
2433 std r14,_DAR(r1)
2434 std r15,_DSISR(r1)
2435 addi r3,r1,STACK_FRAME_OVERHEAD
2436 + bl .save_nvgprs
2437 mr r4,r14
2438 mr r5,r15
2439 ld r14,PACA_EXGEN+EX_R14(r13)
2440 @@ -596,8 +597,7 @@ storage_fault_common:
2441 cmpdi r3,0
2442 bne- 1f
2443 b .ret_from_except_lite
2444 -1: bl .save_nvgprs
2445 - mr r5,r3
2446 +1: mr r5,r3
2447 addi r3,r1,STACK_FRAME_OVERHEAD
2448 ld r4,_DAR(r1)
2449 bl .bad_page_fault
2450 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
2451 index 41b02c7..05e76fb 100644
2452 --- a/arch/powerpc/kernel/exceptions-64s.S
2453 +++ b/arch/powerpc/kernel/exceptions-64s.S
2454 @@ -1014,10 +1014,10 @@ handle_page_fault:
2455 11: ld r4,_DAR(r1)
2456 ld r5,_DSISR(r1)
2457 addi r3,r1,STACK_FRAME_OVERHEAD
2458 + bl .save_nvgprs
2459 bl .do_page_fault
2460 cmpdi r3,0
2461 beq+ 13f
2462 - bl .save_nvgprs
2463 mr r5,r3
2464 addi r3,r1,STACK_FRAME_OVERHEAD
2465 lwz r4,_DAR(r1)
2466 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
2467 index 0b6d796..d760ddb 100644
2468 --- a/arch/powerpc/kernel/module_32.c
2469 +++ b/arch/powerpc/kernel/module_32.c
2470 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
2471 me->arch.core_plt_section = i;
2472 }
2473 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
2474 - printk("Module doesn't contain .plt or .init.plt sections.\n");
2475 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
2476 return -ENOEXEC;
2477 }
2478
2479 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
2480
2481 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
2482 /* Init, or core PLT? */
2483 - if (location >= mod->module_core
2484 - && location < mod->module_core + mod->core_size)
2485 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
2486 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
2487 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
2488 - else
2489 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
2490 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
2491 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
2492 + else {
2493 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
2494 + return ~0UL;
2495 + }
2496
2497 /* Find this entry, or if that fails, the next avail. entry */
2498 while (entry->jump[0]) {
2499 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
2500 index 8f53954..a704ad6 100644
2501 --- a/arch/powerpc/kernel/process.c
2502 +++ b/arch/powerpc/kernel/process.c
2503 @@ -682,8 +682,8 @@ void show_regs(struct pt_regs * regs)
2504 * Lookup NIP late so we have the best change of getting the
2505 * above info out without failing
2506 */
2507 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
2508 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
2509 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
2510 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
2511 #endif
2512 show_stack(current, (unsigned long *) regs->gpr[1]);
2513 if (!user_mode(regs))
2514 @@ -1187,10 +1187,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
2515 newsp = stack[0];
2516 ip = stack[STACK_FRAME_LR_SAVE];
2517 if (!firstframe || ip != lr) {
2518 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
2519 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
2520 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
2521 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
2522 - printk(" (%pS)",
2523 + printk(" (%pA)",
2524 (void *)current->ret_stack[curr_frame].ret);
2525 curr_frame--;
2526 }
2527 @@ -1210,7 +1210,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
2528 struct pt_regs *regs = (struct pt_regs *)
2529 (sp + STACK_FRAME_OVERHEAD);
2530 lr = regs->link;
2531 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
2532 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
2533 regs->trap, (void *)regs->nip, (void *)lr);
2534 firstframe = 1;
2535 }
2536 @@ -1285,58 +1285,3 @@ void thread_info_cache_init(void)
2537 }
2538
2539 #endif /* THREAD_SHIFT < PAGE_SHIFT */
2540 -
2541 -unsigned long arch_align_stack(unsigned long sp)
2542 -{
2543 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2544 - sp -= get_random_int() & ~PAGE_MASK;
2545 - return sp & ~0xf;
2546 -}
2547 -
2548 -static inline unsigned long brk_rnd(void)
2549 -{
2550 - unsigned long rnd = 0;
2551 -
2552 - /* 8MB for 32bit, 1GB for 64bit */
2553 - if (is_32bit_task())
2554 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
2555 - else
2556 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
2557 -
2558 - return rnd << PAGE_SHIFT;
2559 -}
2560 -
2561 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2562 -{
2563 - unsigned long base = mm->brk;
2564 - unsigned long ret;
2565 -
2566 -#ifdef CONFIG_PPC_STD_MMU_64
2567 - /*
2568 - * If we are using 1TB segments and we are allowed to randomise
2569 - * the heap, we can put it above 1TB so it is backed by a 1TB
2570 - * segment. Otherwise the heap will be in the bottom 1TB
2571 - * which always uses 256MB segments and this may result in a
2572 - * performance penalty.
2573 - */
2574 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
2575 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
2576 -#endif
2577 -
2578 - ret = PAGE_ALIGN(base + brk_rnd());
2579 -
2580 - if (ret < mm->brk)
2581 - return mm->brk;
2582 -
2583 - return ret;
2584 -}
2585 -
2586 -unsigned long randomize_et_dyn(unsigned long base)
2587 -{
2588 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
2589 -
2590 - if (ret < base)
2591 - return base;
2592 -
2593 - return ret;
2594 -}
2595 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
2596 index 78b76dc..7f232ef 100644
2597 --- a/arch/powerpc/kernel/signal_32.c
2598 +++ b/arch/powerpc/kernel/signal_32.c
2599 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
2600 /* Save user registers on the stack */
2601 frame = &rt_sf->uc.uc_mcontext;
2602 addr = frame;
2603 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
2604 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2605 if (save_user_regs(regs, frame, 0, 1))
2606 goto badframe;
2607 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
2608 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
2609 index e91c736..742ec06 100644
2610 --- a/arch/powerpc/kernel/signal_64.c
2611 +++ b/arch/powerpc/kernel/signal_64.c
2612 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
2613 current->thread.fpscr.val = 0;
2614
2615 /* Set up to return from userspace. */
2616 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
2617 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2618 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
2619 } else {
2620 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
2621 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
2622 index f19d977..8ac286e 100644
2623 --- a/arch/powerpc/kernel/traps.c
2624 +++ b/arch/powerpc/kernel/traps.c
2625 @@ -98,6 +98,8 @@ static void pmac_backlight_unblank(void)
2626 static inline void pmac_backlight_unblank(void) { }
2627 #endif
2628
2629 +extern void gr_handle_kernel_exploit(void);
2630 +
2631 int die(const char *str, struct pt_regs *regs, long err)
2632 {
2633 static struct {
2634 @@ -171,6 +173,8 @@ int die(const char *str, struct pt_regs *regs, long err)
2635 if (panic_on_oops)
2636 panic("Fatal exception");
2637
2638 + gr_handle_kernel_exploit();
2639 +
2640 oops_exit();
2641 do_exit(err);
2642
2643 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
2644 index 142ab10..236e61a 100644
2645 --- a/arch/powerpc/kernel/vdso.c
2646 +++ b/arch/powerpc/kernel/vdso.c
2647 @@ -36,6 +36,7 @@
2648 #include <asm/firmware.h>
2649 #include <asm/vdso.h>
2650 #include <asm/vdso_datapage.h>
2651 +#include <asm/mman.h>
2652
2653 #include "setup.h"
2654
2655 @@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2656 vdso_base = VDSO32_MBASE;
2657 #endif
2658
2659 - current->mm->context.vdso_base = 0;
2660 + current->mm->context.vdso_base = ~0UL;
2661
2662 /* vDSO has a problem and was disabled, just don't "enable" it for the
2663 * process
2664 @@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2665 vdso_base = get_unmapped_area(NULL, vdso_base,
2666 (vdso_pages << PAGE_SHIFT) +
2667 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
2668 - 0, 0);
2669 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
2670 if (IS_ERR_VALUE(vdso_base)) {
2671 rc = vdso_base;
2672 goto fail_mmapsem;
2673 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
2674 index 5eea6f3..5d10396 100644
2675 --- a/arch/powerpc/lib/usercopy_64.c
2676 +++ b/arch/powerpc/lib/usercopy_64.c
2677 @@ -9,22 +9,6 @@
2678 #include <linux/module.h>
2679 #include <asm/uaccess.h>
2680
2681 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
2682 -{
2683 - if (likely(access_ok(VERIFY_READ, from, n)))
2684 - n = __copy_from_user(to, from, n);
2685 - else
2686 - memset(to, 0, n);
2687 - return n;
2688 -}
2689 -
2690 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
2691 -{
2692 - if (likely(access_ok(VERIFY_WRITE, to, n)))
2693 - n = __copy_to_user(to, from, n);
2694 - return n;
2695 -}
2696 -
2697 unsigned long copy_in_user(void __user *to, const void __user *from,
2698 unsigned long n)
2699 {
2700 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
2701 return n;
2702 }
2703
2704 -EXPORT_SYMBOL(copy_from_user);
2705 -EXPORT_SYMBOL(copy_to_user);
2706 EXPORT_SYMBOL(copy_in_user);
2707
2708 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
2709 index 5efe8c9..db9ceef 100644
2710 --- a/arch/powerpc/mm/fault.c
2711 +++ b/arch/powerpc/mm/fault.c
2712 @@ -32,6 +32,10 @@
2713 #include <linux/perf_event.h>
2714 #include <linux/magic.h>
2715 #include <linux/ratelimit.h>
2716 +#include <linux/slab.h>
2717 +#include <linux/pagemap.h>
2718 +#include <linux/compiler.h>
2719 +#include <linux/unistd.h>
2720
2721 #include <asm/firmware.h>
2722 #include <asm/page.h>
2723 @@ -43,6 +47,7 @@
2724 #include <asm/tlbflush.h>
2725 #include <asm/siginfo.h>
2726 #include <mm/mmu_decl.h>
2727 +#include <asm/ptrace.h>
2728
2729 #ifdef CONFIG_KPROBES
2730 static inline int notify_page_fault(struct pt_regs *regs)
2731 @@ -66,6 +71,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
2732 }
2733 #endif
2734
2735 +#ifdef CONFIG_PAX_PAGEEXEC
2736 +/*
2737 + * PaX: decide what to do with offenders (regs->nip = fault address)
2738 + *
2739 + * returns 1 when task should be killed
2740 + */
2741 +static int pax_handle_fetch_fault(struct pt_regs *regs)
2742 +{
2743 + return 1;
2744 +}
2745 +
2746 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2747 +{
2748 + unsigned long i;
2749 +
2750 + printk(KERN_ERR "PAX: bytes at PC: ");
2751 + for (i = 0; i < 5; i++) {
2752 + unsigned int c;
2753 + if (get_user(c, (unsigned int __user *)pc+i))
2754 + printk(KERN_CONT "???????? ");
2755 + else
2756 + printk(KERN_CONT "%08x ", c);
2757 + }
2758 + printk("\n");
2759 +}
2760 +#endif
2761 +
2762 /*
2763 * Check whether the instruction at regs->nip is a store using
2764 * an update addressing form which will update r1.
2765 @@ -136,7 +168,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
2766 * indicate errors in DSISR but can validly be set in SRR1.
2767 */
2768 if (trap == 0x400)
2769 - error_code &= 0x48200000;
2770 + error_code &= 0x58200000;
2771 else
2772 is_write = error_code & DSISR_ISSTORE;
2773 #else
2774 @@ -259,7 +291,7 @@ good_area:
2775 * "undefined". Of those that can be set, this is the only
2776 * one which seems bad.
2777 */
2778 - if (error_code & 0x10000000)
2779 + if (error_code & DSISR_GUARDED)
2780 /* Guarded storage error. */
2781 goto bad_area;
2782 #endif /* CONFIG_8xx */
2783 @@ -274,7 +306,7 @@ good_area:
2784 * processors use the same I/D cache coherency mechanism
2785 * as embedded.
2786 */
2787 - if (error_code & DSISR_PROTFAULT)
2788 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
2789 goto bad_area;
2790 #endif /* CONFIG_PPC_STD_MMU */
2791
2792 @@ -343,6 +375,23 @@ bad_area:
2793 bad_area_nosemaphore:
2794 /* User mode accesses cause a SIGSEGV */
2795 if (user_mode(regs)) {
2796 +
2797 +#ifdef CONFIG_PAX_PAGEEXEC
2798 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2799 +#ifdef CONFIG_PPC_STD_MMU
2800 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
2801 +#else
2802 + if (is_exec && regs->nip == address) {
2803 +#endif
2804 + switch (pax_handle_fetch_fault(regs)) {
2805 + }
2806 +
2807 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
2808 + do_group_exit(SIGKILL);
2809 + }
2810 + }
2811 +#endif
2812 +
2813 _exception(SIGSEGV, regs, code, address);
2814 return 0;
2815 }
2816 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
2817 index 5a783d8..c23e14b 100644
2818 --- a/arch/powerpc/mm/mmap_64.c
2819 +++ b/arch/powerpc/mm/mmap_64.c
2820 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2821 */
2822 if (mmap_is_legacy()) {
2823 mm->mmap_base = TASK_UNMAPPED_BASE;
2824 +
2825 +#ifdef CONFIG_PAX_RANDMMAP
2826 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2827 + mm->mmap_base += mm->delta_mmap;
2828 +#endif
2829 +
2830 mm->get_unmapped_area = arch_get_unmapped_area;
2831 mm->unmap_area = arch_unmap_area;
2832 } else {
2833 mm->mmap_base = mmap_base();
2834 +
2835 +#ifdef CONFIG_PAX_RANDMMAP
2836 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2837 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2838 +#endif
2839 +
2840 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2841 mm->unmap_area = arch_unmap_area_topdown;
2842 }
2843 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
2844 index ba51948..23009d9 100644
2845 --- a/arch/powerpc/mm/slice.c
2846 +++ b/arch/powerpc/mm/slice.c
2847 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
2848 if ((mm->task_size - len) < addr)
2849 return 0;
2850 vma = find_vma(mm, addr);
2851 - return (!vma || (addr + len) <= vma->vm_start);
2852 + return check_heap_stack_gap(vma, addr, len);
2853 }
2854
2855 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
2856 @@ -256,7 +256,7 @@ full_search:
2857 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
2858 continue;
2859 }
2860 - if (!vma || addr + len <= vma->vm_start) {
2861 + if (check_heap_stack_gap(vma, addr, len)) {
2862 /*
2863 * Remember the place where we stopped the search:
2864 */
2865 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
2866 }
2867 }
2868
2869 - addr = mm->mmap_base;
2870 - while (addr > len) {
2871 + if (mm->mmap_base < len)
2872 + addr = -ENOMEM;
2873 + else
2874 + addr = mm->mmap_base - len;
2875 +
2876 + while (!IS_ERR_VALUE(addr)) {
2877 /* Go down by chunk size */
2878 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
2879 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
2880
2881 /* Check for hit with different page size */
2882 mask = slice_range_to_mask(addr, len);
2883 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
2884 * return with success:
2885 */
2886 vma = find_vma(mm, addr);
2887 - if (!vma || (addr + len) <= vma->vm_start) {
2888 + if (check_heap_stack_gap(vma, addr, len)) {
2889 /* remember the address as a hint for next time */
2890 if (use_cache)
2891 mm->free_area_cache = addr;
2892 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
2893 mm->cached_hole_size = vma->vm_start - addr;
2894
2895 /* try just below the current vma->vm_start */
2896 - addr = vma->vm_start;
2897 + addr = skip_heap_stack_gap(vma, len);
2898 }
2899
2900 /*
2901 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
2902 if (fixed && addr > (mm->task_size - len))
2903 return -EINVAL;
2904
2905 +#ifdef CONFIG_PAX_RANDMMAP
2906 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
2907 + addr = 0;
2908 +#endif
2909 +
2910 /* If hint, make sure it matches our alignment restrictions */
2911 if (!fixed && addr) {
2912 addr = _ALIGN_UP(addr, 1ul << pshift);
2913 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
2914 index 547f1a6..3fff354 100644
2915 --- a/arch/s390/include/asm/elf.h
2916 +++ b/arch/s390/include/asm/elf.h
2917 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
2918 the loader. We need to make sure that it is out of the way of the program
2919 that it will "exec", and that there is sufficient room for the brk. */
2920
2921 -extern unsigned long randomize_et_dyn(unsigned long base);
2922 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
2923 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
2924 +
2925 +#ifdef CONFIG_PAX_ASLR
2926 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
2927 +
2928 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
2929 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
2930 +#endif
2931
2932 /* This yields a mask that user programs can use to figure out what
2933 instruction set this CPU supports. */
2934 @@ -211,7 +217,4 @@ struct linux_binprm;
2935 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2936 int arch_setup_additional_pages(struct linux_binprm *, int);
2937
2938 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2939 -#define arch_randomize_brk arch_randomize_brk
2940 -
2941 #endif
2942 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
2943 index 6582f69..b69906f 100644
2944 --- a/arch/s390/include/asm/system.h
2945 +++ b/arch/s390/include/asm/system.h
2946 @@ -256,7 +256,7 @@ extern void (*_machine_restart)(char *command);
2947 extern void (*_machine_halt)(void);
2948 extern void (*_machine_power_off)(void);
2949
2950 -extern unsigned long arch_align_stack(unsigned long sp);
2951 +#define arch_align_stack(x) ((x) & ~0xfUL)
2952
2953 static inline int tprot(unsigned long addr)
2954 {
2955 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
2956 index 2b23885..e136e31 100644
2957 --- a/arch/s390/include/asm/uaccess.h
2958 +++ b/arch/s390/include/asm/uaccess.h
2959 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
2960 copy_to_user(void __user *to, const void *from, unsigned long n)
2961 {
2962 might_fault();
2963 +
2964 + if ((long)n < 0)
2965 + return n;
2966 +
2967 if (access_ok(VERIFY_WRITE, to, n))
2968 n = __copy_to_user(to, from, n);
2969 return n;
2970 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
2971 static inline unsigned long __must_check
2972 __copy_from_user(void *to, const void __user *from, unsigned long n)
2973 {
2974 + if ((long)n < 0)
2975 + return n;
2976 +
2977 if (__builtin_constant_p(n) && (n <= 256))
2978 return uaccess.copy_from_user_small(n, from, to);
2979 else
2980 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
2981 unsigned int sz = __compiletime_object_size(to);
2982
2983 might_fault();
2984 +
2985 + if ((long)n < 0)
2986 + return n;
2987 +
2988 if (unlikely(sz != -1 && sz < n)) {
2989 copy_from_user_overflow();
2990 return n;
2991 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
2992 index dfcb343..eda788a 100644
2993 --- a/arch/s390/kernel/module.c
2994 +++ b/arch/s390/kernel/module.c
2995 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
2996
2997 /* Increase core size by size of got & plt and set start
2998 offsets for got and plt. */
2999 - me->core_size = ALIGN(me->core_size, 4);
3000 - me->arch.got_offset = me->core_size;
3001 - me->core_size += me->arch.got_size;
3002 - me->arch.plt_offset = me->core_size;
3003 - me->core_size += me->arch.plt_size;
3004 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
3005 + me->arch.got_offset = me->core_size_rw;
3006 + me->core_size_rw += me->arch.got_size;
3007 + me->arch.plt_offset = me->core_size_rx;
3008 + me->core_size_rx += me->arch.plt_size;
3009 return 0;
3010 }
3011
3012 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3013 if (info->got_initialized == 0) {
3014 Elf_Addr *gotent;
3015
3016 - gotent = me->module_core + me->arch.got_offset +
3017 + gotent = me->module_core_rw + me->arch.got_offset +
3018 info->got_offset;
3019 *gotent = val;
3020 info->got_initialized = 1;
3021 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3022 else if (r_type == R_390_GOTENT ||
3023 r_type == R_390_GOTPLTENT)
3024 *(unsigned int *) loc =
3025 - (val + (Elf_Addr) me->module_core - loc) >> 1;
3026 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
3027 else if (r_type == R_390_GOT64 ||
3028 r_type == R_390_GOTPLT64)
3029 *(unsigned long *) loc = val;
3030 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3031 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
3032 if (info->plt_initialized == 0) {
3033 unsigned int *ip;
3034 - ip = me->module_core + me->arch.plt_offset +
3035 + ip = me->module_core_rx + me->arch.plt_offset +
3036 info->plt_offset;
3037 #ifndef CONFIG_64BIT
3038 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
3039 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3040 val - loc + 0xffffUL < 0x1ffffeUL) ||
3041 (r_type == R_390_PLT32DBL &&
3042 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
3043 - val = (Elf_Addr) me->module_core +
3044 + val = (Elf_Addr) me->module_core_rx +
3045 me->arch.plt_offset +
3046 info->plt_offset;
3047 val += rela->r_addend - loc;
3048 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3049 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
3050 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
3051 val = val + rela->r_addend -
3052 - ((Elf_Addr) me->module_core + me->arch.got_offset);
3053 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
3054 if (r_type == R_390_GOTOFF16)
3055 *(unsigned short *) loc = val;
3056 else if (r_type == R_390_GOTOFF32)
3057 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3058 break;
3059 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
3060 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
3061 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
3062 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
3063 rela->r_addend - loc;
3064 if (r_type == R_390_GOTPC)
3065 *(unsigned int *) loc = val;
3066 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
3067 index 541a750..8739853 100644
3068 --- a/arch/s390/kernel/process.c
3069 +++ b/arch/s390/kernel/process.c
3070 @@ -319,39 +319,3 @@ unsigned long get_wchan(struct task_struct *p)
3071 }
3072 return 0;
3073 }
3074 -
3075 -unsigned long arch_align_stack(unsigned long sp)
3076 -{
3077 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3078 - sp -= get_random_int() & ~PAGE_MASK;
3079 - return sp & ~0xf;
3080 -}
3081 -
3082 -static inline unsigned long brk_rnd(void)
3083 -{
3084 - /* 8MB for 32bit, 1GB for 64bit */
3085 - if (is_32bit_task())
3086 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
3087 - else
3088 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
3089 -}
3090 -
3091 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3092 -{
3093 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
3094 -
3095 - if (ret < mm->brk)
3096 - return mm->brk;
3097 - return ret;
3098 -}
3099 -
3100 -unsigned long randomize_et_dyn(unsigned long base)
3101 -{
3102 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3103 -
3104 - if (!(current->flags & PF_RANDOMIZE))
3105 - return base;
3106 - if (ret < base)
3107 - return base;
3108 - return ret;
3109 -}
3110 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
3111 index c9a9f7f..60d0315 100644
3112 --- a/arch/s390/mm/mmap.c
3113 +++ b/arch/s390/mm/mmap.c
3114 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3115 */
3116 if (mmap_is_legacy()) {
3117 mm->mmap_base = TASK_UNMAPPED_BASE;
3118 +
3119 +#ifdef CONFIG_PAX_RANDMMAP
3120 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3121 + mm->mmap_base += mm->delta_mmap;
3122 +#endif
3123 +
3124 mm->get_unmapped_area = arch_get_unmapped_area;
3125 mm->unmap_area = arch_unmap_area;
3126 } else {
3127 mm->mmap_base = mmap_base();
3128 +
3129 +#ifdef CONFIG_PAX_RANDMMAP
3130 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3131 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3132 +#endif
3133 +
3134 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3135 mm->unmap_area = arch_unmap_area_topdown;
3136 }
3137 @@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3138 */
3139 if (mmap_is_legacy()) {
3140 mm->mmap_base = TASK_UNMAPPED_BASE;
3141 +
3142 +#ifdef CONFIG_PAX_RANDMMAP
3143 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3144 + mm->mmap_base += mm->delta_mmap;
3145 +#endif
3146 +
3147 mm->get_unmapped_area = s390_get_unmapped_area;
3148 mm->unmap_area = arch_unmap_area;
3149 } else {
3150 mm->mmap_base = mmap_base();
3151 +
3152 +#ifdef CONFIG_PAX_RANDMMAP
3153 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3154 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3155 +#endif
3156 +
3157 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
3158 mm->unmap_area = arch_unmap_area_topdown;
3159 }
3160 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
3161 index 589d5c7..669e274 100644
3162 --- a/arch/score/include/asm/system.h
3163 +++ b/arch/score/include/asm/system.h
3164 @@ -17,7 +17,7 @@ do { \
3165 #define finish_arch_switch(prev) do {} while (0)
3166
3167 typedef void (*vi_handler_t)(void);
3168 -extern unsigned long arch_align_stack(unsigned long sp);
3169 +#define arch_align_stack(x) (x)
3170
3171 #define mb() barrier()
3172 #define rmb() barrier()
3173 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
3174 index 25d0803..d6c8e36 100644
3175 --- a/arch/score/kernel/process.c
3176 +++ b/arch/score/kernel/process.c
3177 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
3178
3179 return task_pt_regs(task)->cp0_epc;
3180 }
3181 -
3182 -unsigned long arch_align_stack(unsigned long sp)
3183 -{
3184 - return sp;
3185 -}
3186 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
3187 index afeb710..d1d1289 100644
3188 --- a/arch/sh/mm/mmap.c
3189 +++ b/arch/sh/mm/mmap.c
3190 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3191 addr = PAGE_ALIGN(addr);
3192
3193 vma = find_vma(mm, addr);
3194 - if (TASK_SIZE - len >= addr &&
3195 - (!vma || addr + len <= vma->vm_start))
3196 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3197 return addr;
3198 }
3199
3200 @@ -106,7 +105,7 @@ full_search:
3201 }
3202 return -ENOMEM;
3203 }
3204 - if (likely(!vma || addr + len <= vma->vm_start)) {
3205 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3206 /*
3207 * Remember the place where we stopped the search:
3208 */
3209 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3210 addr = PAGE_ALIGN(addr);
3211
3212 vma = find_vma(mm, addr);
3213 - if (TASK_SIZE - len >= addr &&
3214 - (!vma || addr + len <= vma->vm_start))
3215 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3216 return addr;
3217 }
3218
3219 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3220 /* make sure it can fit in the remaining address space */
3221 if (likely(addr > len)) {
3222 vma = find_vma(mm, addr-len);
3223 - if (!vma || addr <= vma->vm_start) {
3224 + if (check_heap_stack_gap(vma, addr - len, len)) {
3225 /* remember the address as a hint for next time */
3226 return (mm->free_area_cache = addr-len);
3227 }
3228 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3229 if (unlikely(mm->mmap_base < len))
3230 goto bottomup;
3231
3232 - addr = mm->mmap_base-len;
3233 - if (do_colour_align)
3234 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3235 + addr = mm->mmap_base - len;
3236
3237 do {
3238 + if (do_colour_align)
3239 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3240 /*
3241 * Lookup failure means no vma is above this address,
3242 * else if new region fits below vma->vm_start,
3243 * return with success:
3244 */
3245 vma = find_vma(mm, addr);
3246 - if (likely(!vma || addr+len <= vma->vm_start)) {
3247 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3248 /* remember the address as a hint for next time */
3249 return (mm->free_area_cache = addr);
3250 }
3251 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3252 mm->cached_hole_size = vma->vm_start - addr;
3253
3254 /* try just below the current vma->vm_start */
3255 - addr = vma->vm_start-len;
3256 - if (do_colour_align)
3257 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3258 - } while (likely(len < vma->vm_start));
3259 + addr = skip_heap_stack_gap(vma, len);
3260 + } while (!IS_ERR_VALUE(addr));
3261
3262 bottomup:
3263 /*
3264 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
3265 index ad1fb5d..fc5315b 100644
3266 --- a/arch/sparc/Makefile
3267 +++ b/arch/sparc/Makefile
3268 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
3269 # Export what is needed by arch/sparc/boot/Makefile
3270 export VMLINUX_INIT VMLINUX_MAIN
3271 VMLINUX_INIT := $(head-y) $(init-y)
3272 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
3273 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
3274 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
3275 VMLINUX_MAIN += $(drivers-y) $(net-y)
3276
3277 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
3278 index 9f421df..b81fc12 100644
3279 --- a/arch/sparc/include/asm/atomic_64.h
3280 +++ b/arch/sparc/include/asm/atomic_64.h
3281 @@ -14,18 +14,40 @@
3282 #define ATOMIC64_INIT(i) { (i) }
3283
3284 #define atomic_read(v) (*(volatile int *)&(v)->counter)
3285 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
3286 +{
3287 + return v->counter;
3288 +}
3289 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
3290 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
3291 +{
3292 + return v->counter;
3293 +}
3294
3295 #define atomic_set(v, i) (((v)->counter) = i)
3296 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
3297 +{
3298 + v->counter = i;
3299 +}
3300 #define atomic64_set(v, i) (((v)->counter) = i)
3301 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
3302 +{
3303 + v->counter = i;
3304 +}
3305
3306 extern void atomic_add(int, atomic_t *);
3307 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
3308 extern void atomic64_add(long, atomic64_t *);
3309 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
3310 extern void atomic_sub(int, atomic_t *);
3311 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
3312 extern void atomic64_sub(long, atomic64_t *);
3313 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
3314
3315 extern int atomic_add_ret(int, atomic_t *);
3316 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
3317 extern long atomic64_add_ret(long, atomic64_t *);
3318 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
3319 extern int atomic_sub_ret(int, atomic_t *);
3320 extern long atomic64_sub_ret(long, atomic64_t *);
3321
3322 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
3323 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
3324
3325 #define atomic_inc_return(v) atomic_add_ret(1, v)
3326 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
3327 +{
3328 + return atomic_add_ret_unchecked(1, v);
3329 +}
3330 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
3331 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
3332 +{
3333 + return atomic64_add_ret_unchecked(1, v);
3334 +}
3335
3336 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
3337 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
3338
3339 #define atomic_add_return(i, v) atomic_add_ret(i, v)
3340 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
3341 +{
3342 + return atomic_add_ret_unchecked(i, v);
3343 +}
3344 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
3345 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
3346 +{
3347 + return atomic64_add_ret_unchecked(i, v);
3348 +}
3349
3350 /*
3351 * atomic_inc_and_test - increment and test
3352 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
3353 * other cases.
3354 */
3355 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
3356 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
3357 +{
3358 + return atomic_inc_return_unchecked(v) == 0;
3359 +}
3360 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
3361
3362 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
3363 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
3364 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
3365
3366 #define atomic_inc(v) atomic_add(1, v)
3367 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
3368 +{
3369 + atomic_add_unchecked(1, v);
3370 +}
3371 #define atomic64_inc(v) atomic64_add(1, v)
3372 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
3373 +{
3374 + atomic64_add_unchecked(1, v);
3375 +}
3376
3377 #define atomic_dec(v) atomic_sub(1, v)
3378 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
3379 +{
3380 + atomic_sub_unchecked(1, v);
3381 +}
3382 #define atomic64_dec(v) atomic64_sub(1, v)
3383 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
3384 +{
3385 + atomic64_sub_unchecked(1, v);
3386 +}
3387
3388 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
3389 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
3390
3391 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
3392 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
3393 +{
3394 + return cmpxchg(&v->counter, old, new);
3395 +}
3396 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
3397 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
3398 +{
3399 + return xchg(&v->counter, new);
3400 +}
3401
3402 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
3403 {
3404 - int c, old;
3405 + int c, old, new;
3406 c = atomic_read(v);
3407 for (;;) {
3408 - if (unlikely(c == (u)))
3409 + if (unlikely(c == u))
3410 break;
3411 - old = atomic_cmpxchg((v), c, c + (a));
3412 +
3413 + asm volatile("addcc %2, %0, %0\n"
3414 +
3415 +#ifdef CONFIG_PAX_REFCOUNT
3416 + "tvs %%icc, 6\n"
3417 +#endif
3418 +
3419 + : "=r" (new)
3420 + : "0" (c), "ir" (a)
3421 + : "cc");
3422 +
3423 + old = atomic_cmpxchg(v, c, new);
3424 if (likely(old == c))
3425 break;
3426 c = old;
3427 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
3428 #define atomic64_cmpxchg(v, o, n) \
3429 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
3430 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
3431 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
3432 +{
3433 + return xchg(&v->counter, new);
3434 +}
3435
3436 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
3437 {
3438 - long c, old;
3439 + long c, old, new;
3440 c = atomic64_read(v);
3441 for (;;) {
3442 - if (unlikely(c == (u)))
3443 + if (unlikely(c == u))
3444 break;
3445 - old = atomic64_cmpxchg((v), c, c + (a));
3446 +
3447 + asm volatile("addcc %2, %0, %0\n"
3448 +
3449 +#ifdef CONFIG_PAX_REFCOUNT
3450 + "tvs %%xcc, 6\n"
3451 +#endif
3452 +
3453 + : "=r" (new)
3454 + : "0" (c), "ir" (a)
3455 + : "cc");
3456 +
3457 + old = atomic64_cmpxchg(v, c, new);
3458 if (likely(old == c))
3459 break;
3460 c = old;
3461 }
3462 - return c != (u);
3463 + return c != u;
3464 }
3465
3466 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3467 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
3468 index 69358b5..17b4745 100644
3469 --- a/arch/sparc/include/asm/cache.h
3470 +++ b/arch/sparc/include/asm/cache.h
3471 @@ -10,7 +10,7 @@
3472 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
3473
3474 #define L1_CACHE_SHIFT 5
3475 -#define L1_CACHE_BYTES 32
3476 +#define L1_CACHE_BYTES 32UL
3477
3478 #ifdef CONFIG_SPARC32
3479 #define SMP_CACHE_BYTES_SHIFT 5
3480 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
3481 index 4269ca6..e3da77f 100644
3482 --- a/arch/sparc/include/asm/elf_32.h
3483 +++ b/arch/sparc/include/asm/elf_32.h
3484 @@ -114,6 +114,13 @@ typedef struct {
3485
3486 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
3487
3488 +#ifdef CONFIG_PAX_ASLR
3489 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3490 +
3491 +#define PAX_DELTA_MMAP_LEN 16
3492 +#define PAX_DELTA_STACK_LEN 16
3493 +#endif
3494 +
3495 /* This yields a mask that user programs can use to figure out what
3496 instruction set this cpu supports. This can NOT be done in userspace
3497 on Sparc. */
3498 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
3499 index 7df8b7f..4946269 100644
3500 --- a/arch/sparc/include/asm/elf_64.h
3501 +++ b/arch/sparc/include/asm/elf_64.h
3502 @@ -180,6 +180,13 @@ typedef struct {
3503 #define ELF_ET_DYN_BASE 0x0000010000000000UL
3504 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
3505
3506 +#ifdef CONFIG_PAX_ASLR
3507 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
3508 +
3509 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
3510 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
3511 +#endif
3512 +
3513 extern unsigned long sparc64_elf_hwcap;
3514 #define ELF_HWCAP sparc64_elf_hwcap
3515
3516 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
3517 index a790cc6..091ed94 100644
3518 --- a/arch/sparc/include/asm/pgtable_32.h
3519 +++ b/arch/sparc/include/asm/pgtable_32.h
3520 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
3521 BTFIXUPDEF_INT(page_none)
3522 BTFIXUPDEF_INT(page_copy)
3523 BTFIXUPDEF_INT(page_readonly)
3524 +
3525 +#ifdef CONFIG_PAX_PAGEEXEC
3526 +BTFIXUPDEF_INT(page_shared_noexec)
3527 +BTFIXUPDEF_INT(page_copy_noexec)
3528 +BTFIXUPDEF_INT(page_readonly_noexec)
3529 +#endif
3530 +
3531 BTFIXUPDEF_INT(page_kernel)
3532
3533 #define PMD_SHIFT SUN4C_PMD_SHIFT
3534 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
3535 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
3536 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
3537
3538 +#ifdef CONFIG_PAX_PAGEEXEC
3539 +extern pgprot_t PAGE_SHARED_NOEXEC;
3540 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
3541 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
3542 +#else
3543 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3544 +# define PAGE_COPY_NOEXEC PAGE_COPY
3545 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3546 +#endif
3547 +
3548 extern unsigned long page_kernel;
3549
3550 #ifdef MODULE
3551 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
3552 index f6ae2b2..b03ffc7 100644
3553 --- a/arch/sparc/include/asm/pgtsrmmu.h
3554 +++ b/arch/sparc/include/asm/pgtsrmmu.h
3555 @@ -115,6 +115,13 @@
3556 SRMMU_EXEC | SRMMU_REF)
3557 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
3558 SRMMU_EXEC | SRMMU_REF)
3559 +
3560 +#ifdef CONFIG_PAX_PAGEEXEC
3561 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
3562 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3563 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3564 +#endif
3565 +
3566 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
3567 SRMMU_DIRTY | SRMMU_REF)
3568
3569 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
3570 index 9689176..63c18ea 100644
3571 --- a/arch/sparc/include/asm/spinlock_64.h
3572 +++ b/arch/sparc/include/asm/spinlock_64.h
3573 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
3574
3575 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
3576
3577 -static void inline arch_read_lock(arch_rwlock_t *lock)
3578 +static inline void arch_read_lock(arch_rwlock_t *lock)
3579 {
3580 unsigned long tmp1, tmp2;
3581
3582 __asm__ __volatile__ (
3583 "1: ldsw [%2], %0\n"
3584 " brlz,pn %0, 2f\n"
3585 -"4: add %0, 1, %1\n"
3586 +"4: addcc %0, 1, %1\n"
3587 +
3588 +#ifdef CONFIG_PAX_REFCOUNT
3589 +" tvs %%icc, 6\n"
3590 +#endif
3591 +
3592 " cas [%2], %0, %1\n"
3593 " cmp %0, %1\n"
3594 " bne,pn %%icc, 1b\n"
3595 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
3596 " .previous"
3597 : "=&r" (tmp1), "=&r" (tmp2)
3598 : "r" (lock)
3599 - : "memory");
3600 + : "memory", "cc");
3601 }
3602
3603 -static int inline arch_read_trylock(arch_rwlock_t *lock)
3604 +static inline int arch_read_trylock(arch_rwlock_t *lock)
3605 {
3606 int tmp1, tmp2;
3607
3608 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
3609 "1: ldsw [%2], %0\n"
3610 " brlz,a,pn %0, 2f\n"
3611 " mov 0, %0\n"
3612 -" add %0, 1, %1\n"
3613 +" addcc %0, 1, %1\n"
3614 +
3615 +#ifdef CONFIG_PAX_REFCOUNT
3616 +" tvs %%icc, 6\n"
3617 +#endif
3618 +
3619 " cas [%2], %0, %1\n"
3620 " cmp %0, %1\n"
3621 " bne,pn %%icc, 1b\n"
3622 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
3623 return tmp1;
3624 }
3625
3626 -static void inline arch_read_unlock(arch_rwlock_t *lock)
3627 +static inline void arch_read_unlock(arch_rwlock_t *lock)
3628 {
3629 unsigned long tmp1, tmp2;
3630
3631 __asm__ __volatile__(
3632 "1: lduw [%2], %0\n"
3633 -" sub %0, 1, %1\n"
3634 +" subcc %0, 1, %1\n"
3635 +
3636 +#ifdef CONFIG_PAX_REFCOUNT
3637 +" tvs %%icc, 6\n"
3638 +#endif
3639 +
3640 " cas [%2], %0, %1\n"
3641 " cmp %0, %1\n"
3642 " bne,pn %%xcc, 1b\n"
3643 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
3644 : "memory");
3645 }
3646
3647 -static void inline arch_write_lock(arch_rwlock_t *lock)
3648 +static inline void arch_write_lock(arch_rwlock_t *lock)
3649 {
3650 unsigned long mask, tmp1, tmp2;
3651
3652 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
3653 : "memory");
3654 }
3655
3656 -static void inline arch_write_unlock(arch_rwlock_t *lock)
3657 +static inline void arch_write_unlock(arch_rwlock_t *lock)
3658 {
3659 __asm__ __volatile__(
3660 " stw %%g0, [%0]"
3661 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
3662 : "memory");
3663 }
3664
3665 -static int inline arch_write_trylock(arch_rwlock_t *lock)
3666 +static inline int arch_write_trylock(arch_rwlock_t *lock)
3667 {
3668 unsigned long mask, tmp1, tmp2, result;
3669
3670 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
3671 index fa57532..e1a4c53 100644
3672 --- a/arch/sparc/include/asm/thread_info_32.h
3673 +++ b/arch/sparc/include/asm/thread_info_32.h
3674 @@ -50,6 +50,8 @@ struct thread_info {
3675 unsigned long w_saved;
3676
3677 struct restart_block restart_block;
3678 +
3679 + unsigned long lowest_stack;
3680 };
3681
3682 /*
3683 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
3684 index 60d86be..952dea1 100644
3685 --- a/arch/sparc/include/asm/thread_info_64.h
3686 +++ b/arch/sparc/include/asm/thread_info_64.h
3687 @@ -63,6 +63,8 @@ struct thread_info {
3688 struct pt_regs *kern_una_regs;
3689 unsigned int kern_una_insn;
3690
3691 + unsigned long lowest_stack;
3692 +
3693 unsigned long fpregs[0] __attribute__ ((aligned(64)));
3694 };
3695
3696 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
3697 index e88fbe5..96b0ce5 100644
3698 --- a/arch/sparc/include/asm/uaccess.h
3699 +++ b/arch/sparc/include/asm/uaccess.h
3700 @@ -1,5 +1,13 @@
3701 #ifndef ___ASM_SPARC_UACCESS_H
3702 #define ___ASM_SPARC_UACCESS_H
3703 +
3704 +#ifdef __KERNEL__
3705 +#ifndef __ASSEMBLY__
3706 +#include <linux/types.h>
3707 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3708 +#endif
3709 +#endif
3710 +
3711 #if defined(__sparc__) && defined(__arch64__)
3712 #include <asm/uaccess_64.h>
3713 #else
3714 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
3715 index 8303ac4..07f333d 100644
3716 --- a/arch/sparc/include/asm/uaccess_32.h
3717 +++ b/arch/sparc/include/asm/uaccess_32.h
3718 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
3719
3720 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3721 {
3722 - if (n && __access_ok((unsigned long) to, n))
3723 + if ((long)n < 0)
3724 + return n;
3725 +
3726 + if (n && __access_ok((unsigned long) to, n)) {
3727 + if (!__builtin_constant_p(n))
3728 + check_object_size(from, n, true);
3729 return __copy_user(to, (__force void __user *) from, n);
3730 - else
3731 + } else
3732 return n;
3733 }
3734
3735 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
3736 {
3737 + if ((long)n < 0)
3738 + return n;
3739 +
3740 + if (!__builtin_constant_p(n))
3741 + check_object_size(from, n, true);
3742 +
3743 return __copy_user(to, (__force void __user *) from, n);
3744 }
3745
3746 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
3747 {
3748 - if (n && __access_ok((unsigned long) from, n))
3749 + if ((long)n < 0)
3750 + return n;
3751 +
3752 + if (n && __access_ok((unsigned long) from, n)) {
3753 + if (!__builtin_constant_p(n))
3754 + check_object_size(to, n, false);
3755 return __copy_user((__force void __user *) to, from, n);
3756 - else
3757 + } else
3758 return n;
3759 }
3760
3761 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
3762 {
3763 + if ((long)n < 0)
3764 + return n;
3765 +
3766 return __copy_user((__force void __user *) to, from, n);
3767 }
3768
3769 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
3770 index 3e1449f..5293a0e 100644
3771 --- a/arch/sparc/include/asm/uaccess_64.h
3772 +++ b/arch/sparc/include/asm/uaccess_64.h
3773 @@ -10,6 +10,7 @@
3774 #include <linux/compiler.h>
3775 #include <linux/string.h>
3776 #include <linux/thread_info.h>
3777 +#include <linux/kernel.h>
3778 #include <asm/asi.h>
3779 #include <asm/system.h>
3780 #include <asm/spitfire.h>
3781 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
3782 static inline unsigned long __must_check
3783 copy_from_user(void *to, const void __user *from, unsigned long size)
3784 {
3785 - unsigned long ret = ___copy_from_user(to, from, size);
3786 + unsigned long ret;
3787
3788 + if ((long)size < 0 || size > INT_MAX)
3789 + return size;
3790 +
3791 + if (!__builtin_constant_p(size))
3792 + check_object_size(to, size, false);
3793 +
3794 + ret = ___copy_from_user(to, from, size);
3795 if (unlikely(ret))
3796 ret = copy_from_user_fixup(to, from, size);
3797
3798 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
3799 static inline unsigned long __must_check
3800 copy_to_user(void __user *to, const void *from, unsigned long size)
3801 {
3802 - unsigned long ret = ___copy_to_user(to, from, size);
3803 + unsigned long ret;
3804
3805 + if ((long)size < 0 || size > INT_MAX)
3806 + return size;
3807 +
3808 + if (!__builtin_constant_p(size))
3809 + check_object_size(from, size, true);
3810 +
3811 + ret = ___copy_to_user(to, from, size);
3812 if (unlikely(ret))
3813 ret = copy_to_user_fixup(to, from, size);
3814 return ret;
3815 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
3816 index cb85458..e063f17 100644
3817 --- a/arch/sparc/kernel/Makefile
3818 +++ b/arch/sparc/kernel/Makefile
3819 @@ -3,7 +3,7 @@
3820 #
3821
3822 asflags-y := -ansi
3823 -ccflags-y := -Werror
3824 +#ccflags-y := -Werror
3825
3826 extra-y := head_$(BITS).o
3827 extra-y += init_task.o
3828 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
3829 index f793742..4d880af 100644
3830 --- a/arch/sparc/kernel/process_32.c
3831 +++ b/arch/sparc/kernel/process_32.c
3832 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
3833 rw->ins[4], rw->ins[5],
3834 rw->ins[6],
3835 rw->ins[7]);
3836 - printk("%pS\n", (void *) rw->ins[7]);
3837 + printk("%pA\n", (void *) rw->ins[7]);
3838 rw = (struct reg_window32 *) rw->ins[6];
3839 }
3840 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
3841 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
3842
3843 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
3844 r->psr, r->pc, r->npc, r->y, print_tainted());
3845 - printk("PC: <%pS>\n", (void *) r->pc);
3846 + printk("PC: <%pA>\n", (void *) r->pc);
3847 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
3848 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
3849 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
3850 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
3851 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
3852 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
3853 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
3854 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
3855
3856 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
3857 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
3858 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
3859 rw = (struct reg_window32 *) fp;
3860 pc = rw->ins[7];
3861 printk("[%08lx : ", pc);
3862 - printk("%pS ] ", (void *) pc);
3863 + printk("%pA ] ", (void *) pc);
3864 fp = rw->ins[6];
3865 } while (++count < 16);
3866 printk("\n");
3867 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
3868 index d959cd0..7b42812 100644
3869 --- a/arch/sparc/kernel/process_64.c
3870 +++ b/arch/sparc/kernel/process_64.c
3871 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_regs *regs)
3872 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
3873 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
3874 if (regs->tstate & TSTATE_PRIV)
3875 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
3876 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
3877 }
3878
3879 void show_regs(struct pt_regs *regs)
3880 {
3881 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
3882 regs->tpc, regs->tnpc, regs->y, print_tainted());
3883 - printk("TPC: <%pS>\n", (void *) regs->tpc);
3884 + printk("TPC: <%pA>\n", (void *) regs->tpc);
3885 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
3886 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
3887 regs->u_regs[3]);
3888 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
3889 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
3890 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
3891 regs->u_regs[15]);
3892 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
3893 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
3894 show_regwindow(regs);
3895 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
3896 }
3897 @@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void)
3898 ((tp && tp->task) ? tp->task->pid : -1));
3899
3900 if (gp->tstate & TSTATE_PRIV) {
3901 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
3902 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
3903 (void *) gp->tpc,
3904 (void *) gp->o7,
3905 (void *) gp->i7,
3906 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
3907 index 42b282f..28ce9f2 100644
3908 --- a/arch/sparc/kernel/sys_sparc_32.c
3909 +++ b/arch/sparc/kernel/sys_sparc_32.c
3910 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3911 if (ARCH_SUN4C && len > 0x20000000)
3912 return -ENOMEM;
3913 if (!addr)
3914 - addr = TASK_UNMAPPED_BASE;
3915 + addr = current->mm->mmap_base;
3916
3917 if (flags & MAP_SHARED)
3918 addr = COLOUR_ALIGN(addr);
3919 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3920 }
3921 if (TASK_SIZE - PAGE_SIZE - len < addr)
3922 return -ENOMEM;
3923 - if (!vmm || addr + len <= vmm->vm_start)
3924 + if (check_heap_stack_gap(vmm, addr, len))
3925 return addr;
3926 addr = vmm->vm_end;
3927 if (flags & MAP_SHARED)
3928 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
3929 index 908b47a..aa9e584 100644
3930 --- a/arch/sparc/kernel/sys_sparc_64.c
3931 +++ b/arch/sparc/kernel/sys_sparc_64.c
3932 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3933 /* We do not accept a shared mapping if it would violate
3934 * cache aliasing constraints.
3935 */
3936 - if ((flags & MAP_SHARED) &&
3937 + if ((filp || (flags & MAP_SHARED)) &&
3938 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
3939 return -EINVAL;
3940 return addr;
3941 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3942 if (filp || (flags & MAP_SHARED))
3943 do_color_align = 1;
3944
3945 +#ifdef CONFIG_PAX_RANDMMAP
3946 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3947 +#endif
3948 +
3949 if (addr) {
3950 if (do_color_align)
3951 addr = COLOUR_ALIGN(addr, pgoff);
3952 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3953 addr = PAGE_ALIGN(addr);
3954
3955 vma = find_vma(mm, addr);
3956 - if (task_size - len >= addr &&
3957 - (!vma || addr + len <= vma->vm_start))
3958 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
3959 return addr;
3960 }
3961
3962 if (len > mm->cached_hole_size) {
3963 - start_addr = addr = mm->free_area_cache;
3964 + start_addr = addr = mm->free_area_cache;
3965 } else {
3966 - start_addr = addr = TASK_UNMAPPED_BASE;
3967 + start_addr = addr = mm->mmap_base;
3968 mm->cached_hole_size = 0;
3969 }
3970
3971 @@ -174,14 +177,14 @@ full_search:
3972 vma = find_vma(mm, VA_EXCLUDE_END);
3973 }
3974 if (unlikely(task_size < addr)) {
3975 - if (start_addr != TASK_UNMAPPED_BASE) {
3976 - start_addr = addr = TASK_UNMAPPED_BASE;
3977 + if (start_addr != mm->mmap_base) {
3978 + start_addr = addr = mm->mmap_base;
3979 mm->cached_hole_size = 0;
3980 goto full_search;
3981 }
3982 return -ENOMEM;
3983 }
3984 - if (likely(!vma || addr + len <= vma->vm_start)) {
3985 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3986 /*
3987 * Remember the place where we stopped the search:
3988 */
3989 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3990 /* We do not accept a shared mapping if it would violate
3991 * cache aliasing constraints.
3992 */
3993 - if ((flags & MAP_SHARED) &&
3994 + if ((filp || (flags & MAP_SHARED)) &&
3995 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
3996 return -EINVAL;
3997 return addr;
3998 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3999 addr = PAGE_ALIGN(addr);
4000
4001 vma = find_vma(mm, addr);
4002 - if (task_size - len >= addr &&
4003 - (!vma || addr + len <= vma->vm_start))
4004 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4005 return addr;
4006 }
4007
4008 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4009 /* make sure it can fit in the remaining address space */
4010 if (likely(addr > len)) {
4011 vma = find_vma(mm, addr-len);
4012 - if (!vma || addr <= vma->vm_start) {
4013 + if (check_heap_stack_gap(vma, addr - len, len)) {
4014 /* remember the address as a hint for next time */
4015 return (mm->free_area_cache = addr-len);
4016 }
4017 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4018 if (unlikely(mm->mmap_base < len))
4019 goto bottomup;
4020
4021 - addr = mm->mmap_base-len;
4022 - if (do_color_align)
4023 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4024 + addr = mm->mmap_base - len;
4025
4026 do {
4027 + if (do_color_align)
4028 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4029 /*
4030 * Lookup failure means no vma is above this address,
4031 * else if new region fits below vma->vm_start,
4032 * return with success:
4033 */
4034 vma = find_vma(mm, addr);
4035 - if (likely(!vma || addr+len <= vma->vm_start)) {
4036 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4037 /* remember the address as a hint for next time */
4038 return (mm->free_area_cache = addr);
4039 }
4040 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4041 mm->cached_hole_size = vma->vm_start - addr;
4042
4043 /* try just below the current vma->vm_start */
4044 - addr = vma->vm_start-len;
4045 - if (do_color_align)
4046 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4047 - } while (likely(len < vma->vm_start));
4048 + addr = skip_heap_stack_gap(vma, len);
4049 + } while (!IS_ERR_VALUE(addr));
4050
4051 bottomup:
4052 /*
4053 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4054 gap == RLIM_INFINITY ||
4055 sysctl_legacy_va_layout) {
4056 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4057 +
4058 +#ifdef CONFIG_PAX_RANDMMAP
4059 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4060 + mm->mmap_base += mm->delta_mmap;
4061 +#endif
4062 +
4063 mm->get_unmapped_area = arch_get_unmapped_area;
4064 mm->unmap_area = arch_unmap_area;
4065 } else {
4066 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4067 gap = (task_size / 6 * 5);
4068
4069 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
4070 +
4071 +#ifdef CONFIG_PAX_RANDMMAP
4072 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4073 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4074 +#endif
4075 +
4076 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4077 mm->unmap_area = arch_unmap_area_topdown;
4078 }
4079 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
4080 index c0490c7..84959d1 100644
4081 --- a/arch/sparc/kernel/traps_32.c
4082 +++ b/arch/sparc/kernel/traps_32.c
4083 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
4084 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
4085 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
4086
4087 +extern void gr_handle_kernel_exploit(void);
4088 +
4089 void die_if_kernel(char *str, struct pt_regs *regs)
4090 {
4091 static int die_counter;
4092 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
4093 count++ < 30 &&
4094 (((unsigned long) rw) >= PAGE_OFFSET) &&
4095 !(((unsigned long) rw) & 0x7)) {
4096 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
4097 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
4098 (void *) rw->ins[7]);
4099 rw = (struct reg_window32 *)rw->ins[6];
4100 }
4101 }
4102 printk("Instruction DUMP:");
4103 instruction_dump ((unsigned long *) regs->pc);
4104 - if(regs->psr & PSR_PS)
4105 + if(regs->psr & PSR_PS) {
4106 + gr_handle_kernel_exploit();
4107 do_exit(SIGKILL);
4108 + }
4109 do_exit(SIGSEGV);
4110 }
4111
4112 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
4113 index 0cbdaa4..438e4c9 100644
4114 --- a/arch/sparc/kernel/traps_64.c
4115 +++ b/arch/sparc/kernel/traps_64.c
4116 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
4117 i + 1,
4118 p->trapstack[i].tstate, p->trapstack[i].tpc,
4119 p->trapstack[i].tnpc, p->trapstack[i].tt);
4120 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
4121 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
4122 }
4123 }
4124
4125 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
4126
4127 lvl -= 0x100;
4128 if (regs->tstate & TSTATE_PRIV) {
4129 +
4130 +#ifdef CONFIG_PAX_REFCOUNT
4131 + if (lvl == 6)
4132 + pax_report_refcount_overflow(regs);
4133 +#endif
4134 +
4135 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
4136 die_if_kernel(buffer, regs);
4137 }
4138 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
4139 void bad_trap_tl1(struct pt_regs *regs, long lvl)
4140 {
4141 char buffer[32];
4142 -
4143 +
4144 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
4145 0, lvl, SIGTRAP) == NOTIFY_STOP)
4146 return;
4147
4148 +#ifdef CONFIG_PAX_REFCOUNT
4149 + if (lvl == 6)
4150 + pax_report_refcount_overflow(regs);
4151 +#endif
4152 +
4153 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
4154
4155 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
4156 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
4157 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
4158 printk("%s" "ERROR(%d): ",
4159 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
4160 - printk("TPC<%pS>\n", (void *) regs->tpc);
4161 + printk("TPC<%pA>\n", (void *) regs->tpc);
4162 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
4163 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
4164 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
4165 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
4166 smp_processor_id(),
4167 (type & 0x1) ? 'I' : 'D',
4168 regs->tpc);
4169 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
4170 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
4171 panic("Irrecoverable Cheetah+ parity error.");
4172 }
4173
4174 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
4175 smp_processor_id(),
4176 (type & 0x1) ? 'I' : 'D',
4177 regs->tpc);
4178 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
4179 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
4180 }
4181
4182 struct sun4v_error_entry {
4183 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
4184
4185 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
4186 regs->tpc, tl);
4187 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
4188 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
4189 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4190 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
4191 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
4192 (void *) regs->u_regs[UREG_I7]);
4193 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
4194 "pte[%lx] error[%lx]\n",
4195 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
4196
4197 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
4198 regs->tpc, tl);
4199 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
4200 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
4201 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4202 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
4203 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
4204 (void *) regs->u_regs[UREG_I7]);
4205 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
4206 "pte[%lx] error[%lx]\n",
4207 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
4208 fp = (unsigned long)sf->fp + STACK_BIAS;
4209 }
4210
4211 - printk(" [%016lx] %pS\n", pc, (void *) pc);
4212 + printk(" [%016lx] %pA\n", pc, (void *) pc);
4213 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4214 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
4215 int index = tsk->curr_ret_stack;
4216 if (tsk->ret_stack && index >= graph) {
4217 pc = tsk->ret_stack[index - graph].ret;
4218 - printk(" [%016lx] %pS\n", pc, (void *) pc);
4219 + printk(" [%016lx] %pA\n", pc, (void *) pc);
4220 graph++;
4221 }
4222 }
4223 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
4224 return (struct reg_window *) (fp + STACK_BIAS);
4225 }
4226
4227 +extern void gr_handle_kernel_exploit(void);
4228 +
4229 void die_if_kernel(char *str, struct pt_regs *regs)
4230 {
4231 static int die_counter;
4232 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
4233 while (rw &&
4234 count++ < 30 &&
4235 kstack_valid(tp, (unsigned long) rw)) {
4236 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
4237 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
4238 (void *) rw->ins[7]);
4239
4240 rw = kernel_stack_up(rw);
4241 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
4242 }
4243 user_instruction_dump ((unsigned int __user *) regs->tpc);
4244 }
4245 - if (regs->tstate & TSTATE_PRIV)
4246 + if (regs->tstate & TSTATE_PRIV) {
4247 + gr_handle_kernel_exploit();
4248 do_exit(SIGKILL);
4249 + }
4250 do_exit(SIGSEGV);
4251 }
4252 EXPORT_SYMBOL(die_if_kernel);
4253 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
4254 index 76e4ac1..78f8bb1 100644
4255 --- a/arch/sparc/kernel/unaligned_64.c
4256 +++ b/arch/sparc/kernel/unaligned_64.c
4257 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
4258 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
4259
4260 if (__ratelimit(&ratelimit)) {
4261 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
4262 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
4263 regs->tpc, (void *) regs->tpc);
4264 }
4265 }
4266 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
4267 index a3fc437..fea9957 100644
4268 --- a/arch/sparc/lib/Makefile
4269 +++ b/arch/sparc/lib/Makefile
4270 @@ -2,7 +2,7 @@
4271 #
4272
4273 asflags-y := -ansi -DST_DIV0=0x02
4274 -ccflags-y := -Werror
4275 +#ccflags-y := -Werror
4276
4277 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
4278 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
4279 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
4280 index 59186e0..f747d7a 100644
4281 --- a/arch/sparc/lib/atomic_64.S
4282 +++ b/arch/sparc/lib/atomic_64.S
4283 @@ -18,7 +18,12 @@
4284 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4285 BACKOFF_SETUP(%o2)
4286 1: lduw [%o1], %g1
4287 - add %g1, %o0, %g7
4288 + addcc %g1, %o0, %g7
4289 +
4290 +#ifdef CONFIG_PAX_REFCOUNT
4291 + tvs %icc, 6
4292 +#endif
4293 +
4294 cas [%o1], %g1, %g7
4295 cmp %g1, %g7
4296 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4297 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4298 2: BACKOFF_SPIN(%o2, %o3, 1b)
4299 .size atomic_add, .-atomic_add
4300
4301 + .globl atomic_add_unchecked
4302 + .type atomic_add_unchecked,#function
4303 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4304 + BACKOFF_SETUP(%o2)
4305 +1: lduw [%o1], %g1
4306 + add %g1, %o0, %g7
4307 + cas [%o1], %g1, %g7
4308 + cmp %g1, %g7
4309 + bne,pn %icc, 2f
4310 + nop
4311 + retl
4312 + nop
4313 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4314 + .size atomic_add_unchecked, .-atomic_add_unchecked
4315 +
4316 .globl atomic_sub
4317 .type atomic_sub,#function
4318 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4319 BACKOFF_SETUP(%o2)
4320 1: lduw [%o1], %g1
4321 - sub %g1, %o0, %g7
4322 + subcc %g1, %o0, %g7
4323 +
4324 +#ifdef CONFIG_PAX_REFCOUNT
4325 + tvs %icc, 6
4326 +#endif
4327 +
4328 cas [%o1], %g1, %g7
4329 cmp %g1, %g7
4330 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4331 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4332 2: BACKOFF_SPIN(%o2, %o3, 1b)
4333 .size atomic_sub, .-atomic_sub
4334
4335 + .globl atomic_sub_unchecked
4336 + .type atomic_sub_unchecked,#function
4337 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4338 + BACKOFF_SETUP(%o2)
4339 +1: lduw [%o1], %g1
4340 + sub %g1, %o0, %g7
4341 + cas [%o1], %g1, %g7
4342 + cmp %g1, %g7
4343 + bne,pn %icc, 2f
4344 + nop
4345 + retl
4346 + nop
4347 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4348 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
4349 +
4350 .globl atomic_add_ret
4351 .type atomic_add_ret,#function
4352 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4353 BACKOFF_SETUP(%o2)
4354 1: lduw [%o1], %g1
4355 - add %g1, %o0, %g7
4356 + addcc %g1, %o0, %g7
4357 +
4358 +#ifdef CONFIG_PAX_REFCOUNT
4359 + tvs %icc, 6
4360 +#endif
4361 +
4362 cas [%o1], %g1, %g7
4363 cmp %g1, %g7
4364 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4365 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4366 2: BACKOFF_SPIN(%o2, %o3, 1b)
4367 .size atomic_add_ret, .-atomic_add_ret
4368
4369 + .globl atomic_add_ret_unchecked
4370 + .type atomic_add_ret_unchecked,#function
4371 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4372 + BACKOFF_SETUP(%o2)
4373 +1: lduw [%o1], %g1
4374 + addcc %g1, %o0, %g7
4375 + cas [%o1], %g1, %g7
4376 + cmp %g1, %g7
4377 + bne,pn %icc, 2f
4378 + add %g7, %o0, %g7
4379 + sra %g7, 0, %o0
4380 + retl
4381 + nop
4382 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4383 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
4384 +
4385 .globl atomic_sub_ret
4386 .type atomic_sub_ret,#function
4387 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4388 BACKOFF_SETUP(%o2)
4389 1: lduw [%o1], %g1
4390 - sub %g1, %o0, %g7
4391 + subcc %g1, %o0, %g7
4392 +
4393 +#ifdef CONFIG_PAX_REFCOUNT
4394 + tvs %icc, 6
4395 +#endif
4396 +
4397 cas [%o1], %g1, %g7
4398 cmp %g1, %g7
4399 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4400 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4401 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4402 BACKOFF_SETUP(%o2)
4403 1: ldx [%o1], %g1
4404 - add %g1, %o0, %g7
4405 + addcc %g1, %o0, %g7
4406 +
4407 +#ifdef CONFIG_PAX_REFCOUNT
4408 + tvs %xcc, 6
4409 +#endif
4410 +
4411 casx [%o1], %g1, %g7
4412 cmp %g1, %g7
4413 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4414 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4415 2: BACKOFF_SPIN(%o2, %o3, 1b)
4416 .size atomic64_add, .-atomic64_add
4417
4418 + .globl atomic64_add_unchecked
4419 + .type atomic64_add_unchecked,#function
4420 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4421 + BACKOFF_SETUP(%o2)
4422 +1: ldx [%o1], %g1
4423 + addcc %g1, %o0, %g7
4424 + casx [%o1], %g1, %g7
4425 + cmp %g1, %g7
4426 + bne,pn %xcc, 2f
4427 + nop
4428 + retl
4429 + nop
4430 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4431 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
4432 +
4433 .globl atomic64_sub
4434 .type atomic64_sub,#function
4435 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4436 BACKOFF_SETUP(%o2)
4437 1: ldx [%o1], %g1
4438 - sub %g1, %o0, %g7
4439 + subcc %g1, %o0, %g7
4440 +
4441 +#ifdef CONFIG_PAX_REFCOUNT
4442 + tvs %xcc, 6
4443 +#endif
4444 +
4445 casx [%o1], %g1, %g7
4446 cmp %g1, %g7
4447 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4448 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4449 2: BACKOFF_SPIN(%o2, %o3, 1b)
4450 .size atomic64_sub, .-atomic64_sub
4451
4452 + .globl atomic64_sub_unchecked
4453 + .type atomic64_sub_unchecked,#function
4454 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4455 + BACKOFF_SETUP(%o2)
4456 +1: ldx [%o1], %g1
4457 + subcc %g1, %o0, %g7
4458 + casx [%o1], %g1, %g7
4459 + cmp %g1, %g7
4460 + bne,pn %xcc, 2f
4461 + nop
4462 + retl
4463 + nop
4464 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4465 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
4466 +
4467 .globl atomic64_add_ret
4468 .type atomic64_add_ret,#function
4469 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4470 BACKOFF_SETUP(%o2)
4471 1: ldx [%o1], %g1
4472 - add %g1, %o0, %g7
4473 + addcc %g1, %o0, %g7
4474 +
4475 +#ifdef CONFIG_PAX_REFCOUNT
4476 + tvs %xcc, 6
4477 +#endif
4478 +
4479 casx [%o1], %g1, %g7
4480 cmp %g1, %g7
4481 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4482 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4483 2: BACKOFF_SPIN(%o2, %o3, 1b)
4484 .size atomic64_add_ret, .-atomic64_add_ret
4485
4486 + .globl atomic64_add_ret_unchecked
4487 + .type atomic64_add_ret_unchecked,#function
4488 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4489 + BACKOFF_SETUP(%o2)
4490 +1: ldx [%o1], %g1
4491 + addcc %g1, %o0, %g7
4492 + casx [%o1], %g1, %g7
4493 + cmp %g1, %g7
4494 + bne,pn %xcc, 2f
4495 + add %g7, %o0, %g7
4496 + mov %g7, %o0
4497 + retl
4498 + nop
4499 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4500 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
4501 +
4502 .globl atomic64_sub_ret
4503 .type atomic64_sub_ret,#function
4504 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4505 BACKOFF_SETUP(%o2)
4506 1: ldx [%o1], %g1
4507 - sub %g1, %o0, %g7
4508 + subcc %g1, %o0, %g7
4509 +
4510 +#ifdef CONFIG_PAX_REFCOUNT
4511 + tvs %xcc, 6
4512 +#endif
4513 +
4514 casx [%o1], %g1, %g7
4515 cmp %g1, %g7
4516 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4517 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
4518 index 1b30bb3..b4a16c7 100644
4519 --- a/arch/sparc/lib/ksyms.c
4520 +++ b/arch/sparc/lib/ksyms.c
4521 @@ -142,12 +142,18 @@ EXPORT_SYMBOL(__downgrade_write);
4522
4523 /* Atomic counter implementation. */
4524 EXPORT_SYMBOL(atomic_add);
4525 +EXPORT_SYMBOL(atomic_add_unchecked);
4526 EXPORT_SYMBOL(atomic_add_ret);
4527 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
4528 EXPORT_SYMBOL(atomic_sub);
4529 +EXPORT_SYMBOL(atomic_sub_unchecked);
4530 EXPORT_SYMBOL(atomic_sub_ret);
4531 EXPORT_SYMBOL(atomic64_add);
4532 +EXPORT_SYMBOL(atomic64_add_unchecked);
4533 EXPORT_SYMBOL(atomic64_add_ret);
4534 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
4535 EXPORT_SYMBOL(atomic64_sub);
4536 +EXPORT_SYMBOL(atomic64_sub_unchecked);
4537 EXPORT_SYMBOL(atomic64_sub_ret);
4538
4539 /* Atomic bit operations. */
4540 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
4541 index 301421c..e2535d1 100644
4542 --- a/arch/sparc/mm/Makefile
4543 +++ b/arch/sparc/mm/Makefile
4544 @@ -2,7 +2,7 @@
4545 #
4546
4547 asflags-y := -ansi
4548 -ccflags-y := -Werror
4549 +#ccflags-y := -Werror
4550
4551 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
4552 obj-y += fault_$(BITS).o
4553 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
4554 index aa1c1b1..f93e28f 100644
4555 --- a/arch/sparc/mm/fault_32.c
4556 +++ b/arch/sparc/mm/fault_32.c
4557 @@ -22,6 +22,9 @@
4558 #include <linux/interrupt.h>
4559 #include <linux/module.h>
4560 #include <linux/kdebug.h>
4561 +#include <linux/slab.h>
4562 +#include <linux/pagemap.h>
4563 +#include <linux/compiler.h>
4564
4565 #include <asm/system.h>
4566 #include <asm/page.h>
4567 @@ -209,6 +212,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
4568 return safe_compute_effective_address(regs, insn);
4569 }
4570
4571 +#ifdef CONFIG_PAX_PAGEEXEC
4572 +#ifdef CONFIG_PAX_DLRESOLVE
4573 +static void pax_emuplt_close(struct vm_area_struct *vma)
4574 +{
4575 + vma->vm_mm->call_dl_resolve = 0UL;
4576 +}
4577 +
4578 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4579 +{
4580 + unsigned int *kaddr;
4581 +
4582 + vmf->page = alloc_page(GFP_HIGHUSER);
4583 + if (!vmf->page)
4584 + return VM_FAULT_OOM;
4585 +
4586 + kaddr = kmap(vmf->page);
4587 + memset(kaddr, 0, PAGE_SIZE);
4588 + kaddr[0] = 0x9DE3BFA8U; /* save */
4589 + flush_dcache_page(vmf->page);
4590 + kunmap(vmf->page);
4591 + return VM_FAULT_MAJOR;
4592 +}
4593 +
4594 +static const struct vm_operations_struct pax_vm_ops = {
4595 + .close = pax_emuplt_close,
4596 + .fault = pax_emuplt_fault
4597 +};
4598 +
4599 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4600 +{
4601 + int ret;
4602 +
4603 + INIT_LIST_HEAD(&vma->anon_vma_chain);
4604 + vma->vm_mm = current->mm;
4605 + vma->vm_start = addr;
4606 + vma->vm_end = addr + PAGE_SIZE;
4607 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4608 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4609 + vma->vm_ops = &pax_vm_ops;
4610 +
4611 + ret = insert_vm_struct(current->mm, vma);
4612 + if (ret)
4613 + return ret;
4614 +
4615 + ++current->mm->total_vm;
4616 + return 0;
4617 +}
4618 +#endif
4619 +
4620 +/*
4621 + * PaX: decide what to do with offenders (regs->pc = fault address)
4622 + *
4623 + * returns 1 when task should be killed
4624 + * 2 when patched PLT trampoline was detected
4625 + * 3 when unpatched PLT trampoline was detected
4626 + */
4627 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4628 +{
4629 +
4630 +#ifdef CONFIG_PAX_EMUPLT
4631 + int err;
4632 +
4633 + do { /* PaX: patched PLT emulation #1 */
4634 + unsigned int sethi1, sethi2, jmpl;
4635 +
4636 + err = get_user(sethi1, (unsigned int *)regs->pc);
4637 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
4638 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
4639 +
4640 + if (err)
4641 + break;
4642 +
4643 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4644 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
4645 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
4646 + {
4647 + unsigned int addr;
4648 +
4649 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
4650 + addr = regs->u_regs[UREG_G1];
4651 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4652 + regs->pc = addr;
4653 + regs->npc = addr+4;
4654 + return 2;
4655 + }
4656 + } while (0);
4657 +
4658 + { /* PaX: patched PLT emulation #2 */
4659 + unsigned int ba;
4660 +
4661 + err = get_user(ba, (unsigned int *)regs->pc);
4662 +
4663 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
4664 + unsigned int addr;
4665 +
4666 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4667 + regs->pc = addr;
4668 + regs->npc = addr+4;
4669 + return 2;
4670 + }
4671 + }
4672 +
4673 + do { /* PaX: patched PLT emulation #3 */
4674 + unsigned int sethi, jmpl, nop;
4675 +
4676 + err = get_user(sethi, (unsigned int *)regs->pc);
4677 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
4678 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
4679 +
4680 + if (err)
4681 + break;
4682 +
4683 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
4684 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
4685 + nop == 0x01000000U)
4686 + {
4687 + unsigned int addr;
4688 +
4689 + addr = (sethi & 0x003FFFFFU) << 10;
4690 + regs->u_regs[UREG_G1] = addr;
4691 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4692 + regs->pc = addr;
4693 + regs->npc = addr+4;
4694 + return 2;
4695 + }
4696 + } while (0);
4697 +
4698 + do { /* PaX: unpatched PLT emulation step 1 */
4699 + unsigned int sethi, ba, nop;
4700 +
4701 + err = get_user(sethi, (unsigned int *)regs->pc);
4702 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
4703 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
4704 +
4705 + if (err)
4706 + break;
4707 +
4708 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
4709 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
4710 + nop == 0x01000000U)
4711 + {
4712 + unsigned int addr, save, call;
4713 +
4714 + if ((ba & 0xFFC00000U) == 0x30800000U)
4715 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4716 + else
4717 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
4718 +
4719 + err = get_user(save, (unsigned int *)addr);
4720 + err |= get_user(call, (unsigned int *)(addr+4));
4721 + err |= get_user(nop, (unsigned int *)(addr+8));
4722 + if (err)
4723 + break;
4724 +
4725 +#ifdef CONFIG_PAX_DLRESOLVE
4726 + if (save == 0x9DE3BFA8U &&
4727 + (call & 0xC0000000U) == 0x40000000U &&
4728 + nop == 0x01000000U)
4729 + {
4730 + struct vm_area_struct *vma;
4731 + unsigned long call_dl_resolve;
4732 +
4733 + down_read(&current->mm->mmap_sem);
4734 + call_dl_resolve = current->mm->call_dl_resolve;
4735 + up_read(&current->mm->mmap_sem);
4736 + if (likely(call_dl_resolve))
4737 + goto emulate;
4738 +
4739 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
4740 +
4741 + down_write(&current->mm->mmap_sem);
4742 + if (current->mm->call_dl_resolve) {
4743 + call_dl_resolve = current->mm->call_dl_resolve;
4744 + up_write(&current->mm->mmap_sem);
4745 + if (vma)
4746 + kmem_cache_free(vm_area_cachep, vma);
4747 + goto emulate;
4748 + }
4749 +
4750 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
4751 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
4752 + up_write(&current->mm->mmap_sem);
4753 + if (vma)
4754 + kmem_cache_free(vm_area_cachep, vma);
4755 + return 1;
4756 + }
4757 +
4758 + if (pax_insert_vma(vma, call_dl_resolve)) {
4759 + up_write(&current->mm->mmap_sem);
4760 + kmem_cache_free(vm_area_cachep, vma);
4761 + return 1;
4762 + }
4763 +
4764 + current->mm->call_dl_resolve = call_dl_resolve;
4765 + up_write(&current->mm->mmap_sem);
4766 +
4767 +emulate:
4768 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4769 + regs->pc = call_dl_resolve;
4770 + regs->npc = addr+4;
4771 + return 3;
4772 + }
4773 +#endif
4774 +
4775 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
4776 + if ((save & 0xFFC00000U) == 0x05000000U &&
4777 + (call & 0xFFFFE000U) == 0x85C0A000U &&
4778 + nop == 0x01000000U)
4779 + {
4780 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4781 + regs->u_regs[UREG_G2] = addr + 4;
4782 + addr = (save & 0x003FFFFFU) << 10;
4783 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4784 + regs->pc = addr;
4785 + regs->npc = addr+4;
4786 + return 3;
4787 + }
4788 + }
4789 + } while (0);
4790 +
4791 + do { /* PaX: unpatched PLT emulation step 2 */
4792 + unsigned int save, call, nop;
4793 +
4794 + err = get_user(save, (unsigned int *)(regs->pc-4));
4795 + err |= get_user(call, (unsigned int *)regs->pc);
4796 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
4797 + if (err)
4798 + break;
4799 +
4800 + if (save == 0x9DE3BFA8U &&
4801 + (call & 0xC0000000U) == 0x40000000U &&
4802 + nop == 0x01000000U)
4803 + {
4804 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
4805 +
4806 + regs->u_regs[UREG_RETPC] = regs->pc;
4807 + regs->pc = dl_resolve;
4808 + regs->npc = dl_resolve+4;
4809 + return 3;
4810 + }
4811 + } while (0);
4812 +#endif
4813 +
4814 + return 1;
4815 +}
4816 +
4817 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4818 +{
4819 + unsigned long i;
4820 +
4821 + printk(KERN_ERR "PAX: bytes at PC: ");
4822 + for (i = 0; i < 8; i++) {
4823 + unsigned int c;
4824 + if (get_user(c, (unsigned int *)pc+i))
4825 + printk(KERN_CONT "???????? ");
4826 + else
4827 + printk(KERN_CONT "%08x ", c);
4828 + }
4829 + printk("\n");
4830 +}
4831 +#endif
4832 +
4833 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
4834 int text_fault)
4835 {
4836 @@ -281,6 +546,24 @@ good_area:
4837 if(!(vma->vm_flags & VM_WRITE))
4838 goto bad_area;
4839 } else {
4840 +
4841 +#ifdef CONFIG_PAX_PAGEEXEC
4842 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
4843 + up_read(&mm->mmap_sem);
4844 + switch (pax_handle_fetch_fault(regs)) {
4845 +
4846 +#ifdef CONFIG_PAX_EMUPLT
4847 + case 2:
4848 + case 3:
4849 + return;
4850 +#endif
4851 +
4852 + }
4853 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
4854 + do_group_exit(SIGKILL);
4855 + }
4856 +#endif
4857 +
4858 /* Allow reads even for write-only mappings */
4859 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
4860 goto bad_area;
4861 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
4862 index 504c062..6fcb9c6 100644
4863 --- a/arch/sparc/mm/fault_64.c
4864 +++ b/arch/sparc/mm/fault_64.c
4865 @@ -21,6 +21,9 @@
4866 #include <linux/kprobes.h>
4867 #include <linux/kdebug.h>
4868 #include <linux/percpu.h>
4869 +#include <linux/slab.h>
4870 +#include <linux/pagemap.h>
4871 +#include <linux/compiler.h>
4872
4873 #include <asm/page.h>
4874 #include <asm/pgtable.h>
4875 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
4876 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
4877 regs->tpc);
4878 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
4879 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
4880 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
4881 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
4882 dump_stack();
4883 unhandled_fault(regs->tpc, current, regs);
4884 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
4885 show_regs(regs);
4886 }
4887
4888 +#ifdef CONFIG_PAX_PAGEEXEC
4889 +#ifdef CONFIG_PAX_DLRESOLVE
4890 +static void pax_emuplt_close(struct vm_area_struct *vma)
4891 +{
4892 + vma->vm_mm->call_dl_resolve = 0UL;
4893 +}
4894 +
4895 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4896 +{
4897 + unsigned int *kaddr;
4898 +
4899 + vmf->page = alloc_page(GFP_HIGHUSER);
4900 + if (!vmf->page)
4901 + return VM_FAULT_OOM;
4902 +
4903 + kaddr = kmap(vmf->page);
4904 + memset(kaddr, 0, PAGE_SIZE);
4905 + kaddr[0] = 0x9DE3BFA8U; /* save */
4906 + flush_dcache_page(vmf->page);
4907 + kunmap(vmf->page);
4908 + return VM_FAULT_MAJOR;
4909 +}
4910 +
4911 +static const struct vm_operations_struct pax_vm_ops = {
4912 + .close = pax_emuplt_close,
4913 + .fault = pax_emuplt_fault
4914 +};
4915 +
4916 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4917 +{
4918 + int ret;
4919 +
4920 + INIT_LIST_HEAD(&vma->anon_vma_chain);
4921 + vma->vm_mm = current->mm;
4922 + vma->vm_start = addr;
4923 + vma->vm_end = addr + PAGE_SIZE;
4924 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4925 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4926 + vma->vm_ops = &pax_vm_ops;
4927 +
4928 + ret = insert_vm_struct(current->mm, vma);
4929 + if (ret)
4930 + return ret;
4931 +
4932 + ++current->mm->total_vm;
4933 + return 0;
4934 +}
4935 +#endif
4936 +
4937 +/*
4938 + * PaX: decide what to do with offenders (regs->tpc = fault address)
4939 + *
4940 + * returns 1 when task should be killed
4941 + * 2 when patched PLT trampoline was detected
4942 + * 3 when unpatched PLT trampoline was detected
4943 + */
4944 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4945 +{
4946 +
4947 +#ifdef CONFIG_PAX_EMUPLT
4948 + int err;
4949 +
4950 + do { /* PaX: patched PLT emulation #1 */
4951 + unsigned int sethi1, sethi2, jmpl;
4952 +
4953 + err = get_user(sethi1, (unsigned int *)regs->tpc);
4954 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
4955 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
4956 +
4957 + if (err)
4958 + break;
4959 +
4960 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4961 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
4962 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
4963 + {
4964 + unsigned long addr;
4965 +
4966 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
4967 + addr = regs->u_regs[UREG_G1];
4968 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
4969 +
4970 + if (test_thread_flag(TIF_32BIT))
4971 + addr &= 0xFFFFFFFFUL;
4972 +
4973 + regs->tpc = addr;
4974 + regs->tnpc = addr+4;
4975 + return 2;
4976 + }
4977 + } while (0);
4978 +
4979 + { /* PaX: patched PLT emulation #2 */
4980 + unsigned int ba;
4981 +
4982 + err = get_user(ba, (unsigned int *)regs->tpc);
4983 +
4984 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
4985 + unsigned long addr;
4986 +
4987 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
4988 +
4989 + if (test_thread_flag(TIF_32BIT))
4990 + addr &= 0xFFFFFFFFUL;
4991 +
4992 + regs->tpc = addr;
4993 + regs->tnpc = addr+4;
4994 + return 2;
4995 + }
4996 + }
4997 +
4998 + do { /* PaX: patched PLT emulation #3 */
4999 + unsigned int sethi, jmpl, nop;
5000 +
5001 + err = get_user(sethi, (unsigned int *)regs->tpc);
5002 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
5003 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5004 +
5005 + if (err)
5006 + break;
5007 +
5008 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5009 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5010 + nop == 0x01000000U)
5011 + {
5012 + unsigned long addr;
5013 +
5014 + addr = (sethi & 0x003FFFFFU) << 10;
5015 + regs->u_regs[UREG_G1] = addr;
5016 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5017 +
5018 + if (test_thread_flag(TIF_32BIT))
5019 + addr &= 0xFFFFFFFFUL;
5020 +
5021 + regs->tpc = addr;
5022 + regs->tnpc = addr+4;
5023 + return 2;
5024 + }
5025 + } while (0);
5026 +
5027 + do { /* PaX: patched PLT emulation #4 */
5028 + unsigned int sethi, mov1, call, mov2;
5029 +
5030 + err = get_user(sethi, (unsigned int *)regs->tpc);
5031 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
5032 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
5033 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
5034 +
5035 + if (err)
5036 + break;
5037 +
5038 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5039 + mov1 == 0x8210000FU &&
5040 + (call & 0xC0000000U) == 0x40000000U &&
5041 + mov2 == 0x9E100001U)
5042 + {
5043 + unsigned long addr;
5044 +
5045 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
5046 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5047 +
5048 + if (test_thread_flag(TIF_32BIT))
5049 + addr &= 0xFFFFFFFFUL;
5050 +
5051 + regs->tpc = addr;
5052 + regs->tnpc = addr+4;
5053 + return 2;
5054 + }
5055 + } while (0);
5056 +
5057 + do { /* PaX: patched PLT emulation #5 */
5058 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
5059 +
5060 + err = get_user(sethi, (unsigned int *)regs->tpc);
5061 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5062 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5063 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
5064 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
5065 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
5066 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
5067 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
5068 +
5069 + if (err)
5070 + break;
5071 +
5072 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5073 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
5074 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5075 + (or1 & 0xFFFFE000U) == 0x82106000U &&
5076 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
5077 + sllx == 0x83287020U &&
5078 + jmpl == 0x81C04005U &&
5079 + nop == 0x01000000U)
5080 + {
5081 + unsigned long addr;
5082 +
5083 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5084 + regs->u_regs[UREG_G1] <<= 32;
5085 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5086 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5087 + regs->tpc = addr;
5088 + regs->tnpc = addr+4;
5089 + return 2;
5090 + }
5091 + } while (0);
5092 +
5093 + do { /* PaX: patched PLT emulation #6 */
5094 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
5095 +
5096 + err = get_user(sethi, (unsigned int *)regs->tpc);
5097 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5098 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5099 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
5100 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
5101 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
5102 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
5103 +
5104 + if (err)
5105 + break;
5106 +
5107 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5108 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
5109 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5110 + sllx == 0x83287020U &&
5111 + (or & 0xFFFFE000U) == 0x8A116000U &&
5112 + jmpl == 0x81C04005U &&
5113 + nop == 0x01000000U)
5114 + {
5115 + unsigned long addr;
5116 +
5117 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
5118 + regs->u_regs[UREG_G1] <<= 32;
5119 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
5120 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5121 + regs->tpc = addr;
5122 + regs->tnpc = addr+4;
5123 + return 2;
5124 + }
5125 + } while (0);
5126 +
5127 + do { /* PaX: unpatched PLT emulation step 1 */
5128 + unsigned int sethi, ba, nop;
5129 +
5130 + err = get_user(sethi, (unsigned int *)regs->tpc);
5131 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5132 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5133 +
5134 + if (err)
5135 + break;
5136 +
5137 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5138 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5139 + nop == 0x01000000U)
5140 + {
5141 + unsigned long addr;
5142 + unsigned int save, call;
5143 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
5144 +
5145 + if ((ba & 0xFFC00000U) == 0x30800000U)
5146 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5147 + else
5148 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5149 +
5150 + if (test_thread_flag(TIF_32BIT))
5151 + addr &= 0xFFFFFFFFUL;
5152 +
5153 + err = get_user(save, (unsigned int *)addr);
5154 + err |= get_user(call, (unsigned int *)(addr+4));
5155 + err |= get_user(nop, (unsigned int *)(addr+8));
5156 + if (err)
5157 + break;
5158 +
5159 +#ifdef CONFIG_PAX_DLRESOLVE
5160 + if (save == 0x9DE3BFA8U &&
5161 + (call & 0xC0000000U) == 0x40000000U &&
5162 + nop == 0x01000000U)
5163 + {
5164 + struct vm_area_struct *vma;
5165 + unsigned long call_dl_resolve;
5166 +
5167 + down_read(&current->mm->mmap_sem);
5168 + call_dl_resolve = current->mm->call_dl_resolve;
5169 + up_read(&current->mm->mmap_sem);
5170 + if (likely(call_dl_resolve))
5171 + goto emulate;
5172 +
5173 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5174 +
5175 + down_write(&current->mm->mmap_sem);
5176 + if (current->mm->call_dl_resolve) {
5177 + call_dl_resolve = current->mm->call_dl_resolve;
5178 + up_write(&current->mm->mmap_sem);
5179 + if (vma)
5180 + kmem_cache_free(vm_area_cachep, vma);
5181 + goto emulate;
5182 + }
5183 +
5184 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5185 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5186 + up_write(&current->mm->mmap_sem);
5187 + if (vma)
5188 + kmem_cache_free(vm_area_cachep, vma);
5189 + return 1;
5190 + }
5191 +
5192 + if (pax_insert_vma(vma, call_dl_resolve)) {
5193 + up_write(&current->mm->mmap_sem);
5194 + kmem_cache_free(vm_area_cachep, vma);
5195 + return 1;
5196 + }
5197 +
5198 + current->mm->call_dl_resolve = call_dl_resolve;
5199 + up_write(&current->mm->mmap_sem);
5200 +
5201 +emulate:
5202 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5203 + regs->tpc = call_dl_resolve;
5204 + regs->tnpc = addr+4;
5205 + return 3;
5206 + }
5207 +#endif
5208 +
5209 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5210 + if ((save & 0xFFC00000U) == 0x05000000U &&
5211 + (call & 0xFFFFE000U) == 0x85C0A000U &&
5212 + nop == 0x01000000U)
5213 + {
5214 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5215 + regs->u_regs[UREG_G2] = addr + 4;
5216 + addr = (save & 0x003FFFFFU) << 10;
5217 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5218 +
5219 + if (test_thread_flag(TIF_32BIT))
5220 + addr &= 0xFFFFFFFFUL;
5221 +
5222 + regs->tpc = addr;
5223 + regs->tnpc = addr+4;
5224 + return 3;
5225 + }
5226 +
5227 + /* PaX: 64-bit PLT stub */
5228 + err = get_user(sethi1, (unsigned int *)addr);
5229 + err |= get_user(sethi2, (unsigned int *)(addr+4));
5230 + err |= get_user(or1, (unsigned int *)(addr+8));
5231 + err |= get_user(or2, (unsigned int *)(addr+12));
5232 + err |= get_user(sllx, (unsigned int *)(addr+16));
5233 + err |= get_user(add, (unsigned int *)(addr+20));
5234 + err |= get_user(jmpl, (unsigned int *)(addr+24));
5235 + err |= get_user(nop, (unsigned int *)(addr+28));
5236 + if (err)
5237 + break;
5238 +
5239 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
5240 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5241 + (or1 & 0xFFFFE000U) == 0x88112000U &&
5242 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
5243 + sllx == 0x89293020U &&
5244 + add == 0x8A010005U &&
5245 + jmpl == 0x89C14000U &&
5246 + nop == 0x01000000U)
5247 + {
5248 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5249 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5250 + regs->u_regs[UREG_G4] <<= 32;
5251 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5252 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
5253 + regs->u_regs[UREG_G4] = addr + 24;
5254 + addr = regs->u_regs[UREG_G5];
5255 + regs->tpc = addr;
5256 + regs->tnpc = addr+4;
5257 + return 3;
5258 + }
5259 + }
5260 + } while (0);
5261 +
5262 +#ifdef CONFIG_PAX_DLRESOLVE
5263 + do { /* PaX: unpatched PLT emulation step 2 */
5264 + unsigned int save, call, nop;
5265 +
5266 + err = get_user(save, (unsigned int *)(regs->tpc-4));
5267 + err |= get_user(call, (unsigned int *)regs->tpc);
5268 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
5269 + if (err)
5270 + break;
5271 +
5272 + if (save == 0x9DE3BFA8U &&
5273 + (call & 0xC0000000U) == 0x40000000U &&
5274 + nop == 0x01000000U)
5275 + {
5276 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5277 +
5278 + if (test_thread_flag(TIF_32BIT))
5279 + dl_resolve &= 0xFFFFFFFFUL;
5280 +
5281 + regs->u_regs[UREG_RETPC] = regs->tpc;
5282 + regs->tpc = dl_resolve;
5283 + regs->tnpc = dl_resolve+4;
5284 + return 3;
5285 + }
5286 + } while (0);
5287 +#endif
5288 +
5289 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
5290 + unsigned int sethi, ba, nop;
5291 +
5292 + err = get_user(sethi, (unsigned int *)regs->tpc);
5293 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5294 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5295 +
5296 + if (err)
5297 + break;
5298 +
5299 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5300 + (ba & 0xFFF00000U) == 0x30600000U &&
5301 + nop == 0x01000000U)
5302 + {
5303 + unsigned long addr;
5304 +
5305 + addr = (sethi & 0x003FFFFFU) << 10;
5306 + regs->u_regs[UREG_G1] = addr;
5307 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5308 +
5309 + if (test_thread_flag(TIF_32BIT))
5310 + addr &= 0xFFFFFFFFUL;
5311 +
5312 + regs->tpc = addr;
5313 + regs->tnpc = addr+4;
5314 + return 2;
5315 + }
5316 + } while (0);
5317 +
5318 +#endif
5319 +
5320 + return 1;
5321 +}
5322 +
5323 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5324 +{
5325 + unsigned long i;
5326 +
5327 + printk(KERN_ERR "PAX: bytes at PC: ");
5328 + for (i = 0; i < 8; i++) {
5329 + unsigned int c;
5330 + if (get_user(c, (unsigned int *)pc+i))
5331 + printk(KERN_CONT "???????? ");
5332 + else
5333 + printk(KERN_CONT "%08x ", c);
5334 + }
5335 + printk("\n");
5336 +}
5337 +#endif
5338 +
5339 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5340 {
5341 struct mm_struct *mm = current->mm;
5342 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5343 if (!vma)
5344 goto bad_area;
5345
5346 +#ifdef CONFIG_PAX_PAGEEXEC
5347 + /* PaX: detect ITLB misses on non-exec pages */
5348 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
5349 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
5350 + {
5351 + if (address != regs->tpc)
5352 + goto good_area;
5353 +
5354 + up_read(&mm->mmap_sem);
5355 + switch (pax_handle_fetch_fault(regs)) {
5356 +
5357 +#ifdef CONFIG_PAX_EMUPLT
5358 + case 2:
5359 + case 3:
5360 + return;
5361 +#endif
5362 +
5363 + }
5364 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
5365 + do_group_exit(SIGKILL);
5366 + }
5367 +#endif
5368 +
5369 /* Pure DTLB misses do not tell us whether the fault causing
5370 * load/store/atomic was a write or not, it only says that there
5371 * was no match. So in such a case we (carefully) read the
5372 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
5373 index f4e9764..5682724 100644
5374 --- a/arch/sparc/mm/hugetlbpage.c
5375 +++ b/arch/sparc/mm/hugetlbpage.c
5376 @@ -68,7 +68,7 @@ full_search:
5377 }
5378 return -ENOMEM;
5379 }
5380 - if (likely(!vma || addr + len <= vma->vm_start)) {
5381 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5382 /*
5383 * Remember the place where we stopped the search:
5384 */
5385 @@ -107,7 +107,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5386 /* make sure it can fit in the remaining address space */
5387 if (likely(addr > len)) {
5388 vma = find_vma(mm, addr-len);
5389 - if (!vma || addr <= vma->vm_start) {
5390 + if (check_heap_stack_gap(vma, addr - len, len)) {
5391 /* remember the address as a hint for next time */
5392 return (mm->free_area_cache = addr-len);
5393 }
5394 @@ -116,16 +116,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5395 if (unlikely(mm->mmap_base < len))
5396 goto bottomup;
5397
5398 - addr = (mm->mmap_base-len) & HPAGE_MASK;
5399 + addr = mm->mmap_base - len;
5400
5401 do {
5402 + addr &= HPAGE_MASK;
5403 /*
5404 * Lookup failure means no vma is above this address,
5405 * else if new region fits below vma->vm_start,
5406 * return with success:
5407 */
5408 vma = find_vma(mm, addr);
5409 - if (likely(!vma || addr+len <= vma->vm_start)) {
5410 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5411 /* remember the address as a hint for next time */
5412 return (mm->free_area_cache = addr);
5413 }
5414 @@ -135,8 +136,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5415 mm->cached_hole_size = vma->vm_start - addr;
5416
5417 /* try just below the current vma->vm_start */
5418 - addr = (vma->vm_start-len) & HPAGE_MASK;
5419 - } while (likely(len < vma->vm_start));
5420 + addr = skip_heap_stack_gap(vma, len);
5421 + } while (!IS_ERR_VALUE(addr));
5422
5423 bottomup:
5424 /*
5425 @@ -182,8 +183,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
5426 if (addr) {
5427 addr = ALIGN(addr, HPAGE_SIZE);
5428 vma = find_vma(mm, addr);
5429 - if (task_size - len >= addr &&
5430 - (!vma || addr + len <= vma->vm_start))
5431 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5432 return addr;
5433 }
5434 if (mm->get_unmapped_area == arch_get_unmapped_area)
5435 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
5436 index 7b00de6..78239f4 100644
5437 --- a/arch/sparc/mm/init_32.c
5438 +++ b/arch/sparc/mm/init_32.c
5439 @@ -316,6 +316,9 @@ extern void device_scan(void);
5440 pgprot_t PAGE_SHARED __read_mostly;
5441 EXPORT_SYMBOL(PAGE_SHARED);
5442
5443 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
5444 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
5445 +
5446 void __init paging_init(void)
5447 {
5448 switch(sparc_cpu_model) {
5449 @@ -344,17 +347,17 @@ void __init paging_init(void)
5450
5451 /* Initialize the protection map with non-constant, MMU dependent values. */
5452 protection_map[0] = PAGE_NONE;
5453 - protection_map[1] = PAGE_READONLY;
5454 - protection_map[2] = PAGE_COPY;
5455 - protection_map[3] = PAGE_COPY;
5456 + protection_map[1] = PAGE_READONLY_NOEXEC;
5457 + protection_map[2] = PAGE_COPY_NOEXEC;
5458 + protection_map[3] = PAGE_COPY_NOEXEC;
5459 protection_map[4] = PAGE_READONLY;
5460 protection_map[5] = PAGE_READONLY;
5461 protection_map[6] = PAGE_COPY;
5462 protection_map[7] = PAGE_COPY;
5463 protection_map[8] = PAGE_NONE;
5464 - protection_map[9] = PAGE_READONLY;
5465 - protection_map[10] = PAGE_SHARED;
5466 - protection_map[11] = PAGE_SHARED;
5467 + protection_map[9] = PAGE_READONLY_NOEXEC;
5468 + protection_map[10] = PAGE_SHARED_NOEXEC;
5469 + protection_map[11] = PAGE_SHARED_NOEXEC;
5470 protection_map[12] = PAGE_READONLY;
5471 protection_map[13] = PAGE_READONLY;
5472 protection_map[14] = PAGE_SHARED;
5473 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
5474 index cbef74e..c38fead 100644
5475 --- a/arch/sparc/mm/srmmu.c
5476 +++ b/arch/sparc/mm/srmmu.c
5477 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
5478 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
5479 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
5480 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
5481 +
5482 +#ifdef CONFIG_PAX_PAGEEXEC
5483 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
5484 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
5485 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
5486 +#endif
5487 +
5488 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
5489 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
5490
5491 diff --git a/arch/um/Makefile b/arch/um/Makefile
5492 index c0f712c..3a5c4c9 100644
5493 --- a/arch/um/Makefile
5494 +++ b/arch/um/Makefile
5495 @@ -49,6 +49,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
5496 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
5497 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64
5498
5499 +ifdef CONSTIFY_PLUGIN
5500 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5501 +endif
5502 +
5503 include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)
5504
5505 #This will adjust *FLAGS accordingly to the platform.
5506 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
5507 index 6c03acd..a5e0215 100644
5508 --- a/arch/um/include/asm/kmap_types.h
5509 +++ b/arch/um/include/asm/kmap_types.h
5510 @@ -23,6 +23,7 @@ enum km_type {
5511 KM_IRQ1,
5512 KM_SOFTIRQ0,
5513 KM_SOFTIRQ1,
5514 + KM_CLEARPAGE,
5515 KM_TYPE_NR
5516 };
5517
5518 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
5519 index 4cc9b6c..02e5029 100644
5520 --- a/arch/um/include/asm/page.h
5521 +++ b/arch/um/include/asm/page.h
5522 @@ -14,6 +14,9 @@
5523 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
5524 #define PAGE_MASK (~(PAGE_SIZE-1))
5525
5526 +#define ktla_ktva(addr) (addr)
5527 +#define ktva_ktla(addr) (addr)
5528 +
5529 #ifndef __ASSEMBLY__
5530
5531 struct page;
5532 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
5533 index 21c1ae7..4640aaa 100644
5534 --- a/arch/um/kernel/process.c
5535 +++ b/arch/um/kernel/process.c
5536 @@ -404,22 +404,6 @@ int singlestepping(void * t)
5537 return 2;
5538 }
5539
5540 -/*
5541 - * Only x86 and x86_64 have an arch_align_stack().
5542 - * All other arches have "#define arch_align_stack(x) (x)"
5543 - * in their asm/system.h
5544 - * As this is included in UML from asm-um/system-generic.h,
5545 - * we can use it to behave as the subarch does.
5546 - */
5547 -#ifndef arch_align_stack
5548 -unsigned long arch_align_stack(unsigned long sp)
5549 -{
5550 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5551 - sp -= get_random_int() % 8192;
5552 - return sp & ~0xf;
5553 -}
5554 -#endif
5555 -
5556 unsigned long get_wchan(struct task_struct *p)
5557 {
5558 unsigned long stack_page, sp, ip;
5559 diff --git a/arch/um/sys-i386/shared/sysdep/system.h b/arch/um/sys-i386/shared/sysdep/system.h
5560 index d1b93c4..ae1b7fd 100644
5561 --- a/arch/um/sys-i386/shared/sysdep/system.h
5562 +++ b/arch/um/sys-i386/shared/sysdep/system.h
5563 @@ -17,7 +17,7 @@
5564 # define AT_VECTOR_SIZE_ARCH 1
5565 #endif
5566
5567 -extern unsigned long arch_align_stack(unsigned long sp);
5568 +#define arch_align_stack(x) ((x) & ~0xfUL)
5569
5570 void default_idle(void);
5571
5572 diff --git a/arch/um/sys-i386/syscalls.c b/arch/um/sys-i386/syscalls.c
5573 index 70ca357..728d1cc 100644
5574 --- a/arch/um/sys-i386/syscalls.c
5575 +++ b/arch/um/sys-i386/syscalls.c
5576 @@ -11,6 +11,21 @@
5577 #include "asm/uaccess.h"
5578 #include "asm/unistd.h"
5579
5580 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
5581 +{
5582 + unsigned long pax_task_size = TASK_SIZE;
5583 +
5584 +#ifdef CONFIG_PAX_SEGMEXEC
5585 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
5586 + pax_task_size = SEGMEXEC_TASK_SIZE;
5587 +#endif
5588 +
5589 + if (len > pax_task_size || addr > pax_task_size - len)
5590 + return -EINVAL;
5591 +
5592 + return 0;
5593 +}
5594 +
5595 /*
5596 * The prototype on i386 is:
5597 *
5598 diff --git a/arch/um/sys-x86_64/shared/sysdep/system.h b/arch/um/sys-x86_64/shared/sysdep/system.h
5599 index d1b93c4..ae1b7fd 100644
5600 --- a/arch/um/sys-x86_64/shared/sysdep/system.h
5601 +++ b/arch/um/sys-x86_64/shared/sysdep/system.h
5602 @@ -17,7 +17,7 @@
5603 # define AT_VECTOR_SIZE_ARCH 1
5604 #endif
5605
5606 -extern unsigned long arch_align_stack(unsigned long sp);
5607 +#define arch_align_stack(x) ((x) & ~0xfUL)
5608
5609 void default_idle(void);
5610
5611 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
5612 index 6a47bb2..dc9a868 100644
5613 --- a/arch/x86/Kconfig
5614 +++ b/arch/x86/Kconfig
5615 @@ -236,7 +236,7 @@ config X86_HT
5616
5617 config X86_32_LAZY_GS
5618 def_bool y
5619 - depends on X86_32 && !CC_STACKPROTECTOR
5620 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
5621
5622 config ARCH_HWEIGHT_CFLAGS
5623 string
5624 @@ -1019,7 +1019,7 @@ choice
5625
5626 config NOHIGHMEM
5627 bool "off"
5628 - depends on !X86_NUMAQ
5629 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
5630 ---help---
5631 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
5632 However, the address space of 32-bit x86 processors is only 4
5633 @@ -1056,7 +1056,7 @@ config NOHIGHMEM
5634
5635 config HIGHMEM4G
5636 bool "4GB"
5637 - depends on !X86_NUMAQ
5638 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
5639 ---help---
5640 Select this if you have a 32-bit processor and between 1 and 4
5641 gigabytes of physical RAM.
5642 @@ -1110,7 +1110,7 @@ config PAGE_OFFSET
5643 hex
5644 default 0xB0000000 if VMSPLIT_3G_OPT
5645 default 0x80000000 if VMSPLIT_2G
5646 - default 0x78000000 if VMSPLIT_2G_OPT
5647 + default 0x70000000 if VMSPLIT_2G_OPT
5648 default 0x40000000 if VMSPLIT_1G
5649 default 0xC0000000
5650 depends on X86_32
5651 @@ -1484,6 +1484,7 @@ config SECCOMP
5652
5653 config CC_STACKPROTECTOR
5654 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
5655 + depends on X86_64 || !PAX_MEMORY_UDEREF
5656 ---help---
5657 This option turns on the -fstack-protector GCC feature. This
5658 feature puts, at the beginning of functions, a canary value on
5659 @@ -1541,6 +1542,7 @@ config KEXEC_JUMP
5660 config PHYSICAL_START
5661 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
5662 default "0x1000000"
5663 + range 0x400000 0x40000000
5664 ---help---
5665 This gives the physical address where the kernel is loaded.
5666
5667 @@ -1604,6 +1606,7 @@ config X86_NEED_RELOCS
5668 config PHYSICAL_ALIGN
5669 hex "Alignment value to which kernel should be aligned" if X86_32
5670 default "0x1000000"
5671 + range 0x400000 0x1000000 if PAX_KERNEXEC
5672 range 0x2000 0x1000000
5673 ---help---
5674 This value puts the alignment restrictions on physical address
5675 @@ -1635,9 +1638,10 @@ config HOTPLUG_CPU
5676 Say N if you want to disable CPU hotplug.
5677
5678 config COMPAT_VDSO
5679 - def_bool y
5680 + def_bool n
5681 prompt "Compat VDSO support"
5682 depends on X86_32 || IA32_EMULATION
5683 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
5684 ---help---
5685 Map the 32-bit VDSO to the predictable old-style address too.
5686
5687 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
5688 index e3ca7e0..b30b28a 100644
5689 --- a/arch/x86/Kconfig.cpu
5690 +++ b/arch/x86/Kconfig.cpu
5691 @@ -341,7 +341,7 @@ config X86_PPRO_FENCE
5692
5693 config X86_F00F_BUG
5694 def_bool y
5695 - depends on M586MMX || M586TSC || M586 || M486 || M386
5696 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
5697
5698 config X86_INVD_BUG
5699 def_bool y
5700 @@ -365,7 +365,7 @@ config X86_POPAD_OK
5701
5702 config X86_ALIGNMENT_16
5703 def_bool y
5704 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
5705 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
5706
5707 config X86_INTEL_USERCOPY
5708 def_bool y
5709 @@ -411,7 +411,7 @@ config X86_CMPXCHG64
5710 # generates cmov.
5711 config X86_CMOV
5712 def_bool y
5713 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
5714 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
5715
5716 config X86_MINIMUM_CPU_FAMILY
5717 int
5718 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
5719 index c0f8a5c..6404f61 100644
5720 --- a/arch/x86/Kconfig.debug
5721 +++ b/arch/x86/Kconfig.debug
5722 @@ -81,7 +81,7 @@ config X86_PTDUMP
5723 config DEBUG_RODATA
5724 bool "Write protect kernel read-only data structures"
5725 default y
5726 - depends on DEBUG_KERNEL
5727 + depends on DEBUG_KERNEL && BROKEN
5728 ---help---
5729 Mark the kernel read-only data as write-protected in the pagetables,
5730 in order to catch accidental (and incorrect) writes to such const
5731 @@ -99,7 +99,7 @@ config DEBUG_RODATA_TEST
5732
5733 config DEBUG_SET_MODULE_RONX
5734 bool "Set loadable kernel module data as NX and text as RO"
5735 - depends on MODULES
5736 + depends on MODULES && BROKEN
5737 ---help---
5738 This option helps catch unintended modifications to loadable
5739 kernel module's text and read-only data. It also prevents execution
5740 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
5741 index b02e509..2631e48 100644
5742 --- a/arch/x86/Makefile
5743 +++ b/arch/x86/Makefile
5744 @@ -46,6 +46,7 @@ else
5745 UTS_MACHINE := x86_64
5746 CHECKFLAGS += -D__x86_64__ -m64
5747
5748 + biarch := $(call cc-option,-m64)
5749 KBUILD_AFLAGS += -m64
5750 KBUILD_CFLAGS += -m64
5751
5752 @@ -195,3 +196,12 @@ define archhelp
5753 echo ' FDARGS="..." arguments for the booted kernel'
5754 echo ' FDINITRD=file initrd for the booted kernel'
5755 endef
5756 +
5757 +define OLD_LD
5758 +
5759 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
5760 +*** Please upgrade your binutils to 2.18 or newer
5761 +endef
5762 +
5763 +archprepare:
5764 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
5765 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
5766 index 95365a8..52f857b 100644
5767 --- a/arch/x86/boot/Makefile
5768 +++ b/arch/x86/boot/Makefile
5769 @@ -63,6 +63,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
5770 $(call cc-option, -fno-stack-protector) \
5771 $(call cc-option, -mpreferred-stack-boundary=2)
5772 KBUILD_CFLAGS += $(call cc-option, -m32)
5773 +ifdef CONSTIFY_PLUGIN
5774 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5775 +endif
5776 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
5777 GCOV_PROFILE := n
5778
5779 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
5780 index 878e4b9..20537ab 100644
5781 --- a/arch/x86/boot/bitops.h
5782 +++ b/arch/x86/boot/bitops.h
5783 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
5784 u8 v;
5785 const u32 *p = (const u32 *)addr;
5786
5787 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5788 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5789 return v;
5790 }
5791
5792 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
5793
5794 static inline void set_bit(int nr, void *addr)
5795 {
5796 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5797 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5798 }
5799
5800 #endif /* BOOT_BITOPS_H */
5801 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
5802 index c7093bd..d4247ffe0 100644
5803 --- a/arch/x86/boot/boot.h
5804 +++ b/arch/x86/boot/boot.h
5805 @@ -85,7 +85,7 @@ static inline void io_delay(void)
5806 static inline u16 ds(void)
5807 {
5808 u16 seg;
5809 - asm("movw %%ds,%0" : "=rm" (seg));
5810 + asm volatile("movw %%ds,%0" : "=rm" (seg));
5811 return seg;
5812 }
5813
5814 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
5815 static inline int memcmp(const void *s1, const void *s2, size_t len)
5816 {
5817 u8 diff;
5818 - asm("repe; cmpsb; setnz %0"
5819 + asm volatile("repe; cmpsb; setnz %0"
5820 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
5821 return diff;
5822 }
5823 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
5824 index 09664ef..edc5d03 100644
5825 --- a/arch/x86/boot/compressed/Makefile
5826 +++ b/arch/x86/boot/compressed/Makefile
5827 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
5828 KBUILD_CFLAGS += $(cflags-y)
5829 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
5830 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
5831 +ifdef CONSTIFY_PLUGIN
5832 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5833 +endif
5834
5835 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
5836 GCOV_PROFILE := n
5837 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
5838 index 67a655a..b924059 100644
5839 --- a/arch/x86/boot/compressed/head_32.S
5840 +++ b/arch/x86/boot/compressed/head_32.S
5841 @@ -76,7 +76,7 @@ ENTRY(startup_32)
5842 notl %eax
5843 andl %eax, %ebx
5844 #else
5845 - movl $LOAD_PHYSICAL_ADDR, %ebx
5846 + movl $____LOAD_PHYSICAL_ADDR, %ebx
5847 #endif
5848
5849 /* Target address to relocate to for decompression */
5850 @@ -162,7 +162,7 @@ relocated:
5851 * and where it was actually loaded.
5852 */
5853 movl %ebp, %ebx
5854 - subl $LOAD_PHYSICAL_ADDR, %ebx
5855 + subl $____LOAD_PHYSICAL_ADDR, %ebx
5856 jz 2f /* Nothing to be done if loaded at compiled addr. */
5857 /*
5858 * Process relocations.
5859 @@ -170,8 +170,7 @@ relocated:
5860
5861 1: subl $4, %edi
5862 movl (%edi), %ecx
5863 - testl %ecx, %ecx
5864 - jz 2f
5865 + jecxz 2f
5866 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
5867 jmp 1b
5868 2:
5869 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
5870 index 35af09d..99c9676 100644
5871 --- a/arch/x86/boot/compressed/head_64.S
5872 +++ b/arch/x86/boot/compressed/head_64.S
5873 @@ -91,7 +91,7 @@ ENTRY(startup_32)
5874 notl %eax
5875 andl %eax, %ebx
5876 #else
5877 - movl $LOAD_PHYSICAL_ADDR, %ebx
5878 + movl $____LOAD_PHYSICAL_ADDR, %ebx
5879 #endif
5880
5881 /* Target address to relocate to for decompression */
5882 @@ -233,7 +233,7 @@ ENTRY(startup_64)
5883 notq %rax
5884 andq %rax, %rbp
5885 #else
5886 - movq $LOAD_PHYSICAL_ADDR, %rbp
5887 + movq $____LOAD_PHYSICAL_ADDR, %rbp
5888 #endif
5889
5890 /* Target address to relocate to for decompression */
5891 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
5892 index 3a19d04..7c1d55a 100644
5893 --- a/arch/x86/boot/compressed/misc.c
5894 +++ b/arch/x86/boot/compressed/misc.c
5895 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
5896 case PT_LOAD:
5897 #ifdef CONFIG_RELOCATABLE
5898 dest = output;
5899 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
5900 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
5901 #else
5902 dest = (void *)(phdr->p_paddr);
5903 #endif
5904 @@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
5905 error("Destination address too large");
5906 #endif
5907 #ifndef CONFIG_RELOCATABLE
5908 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
5909 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
5910 error("Wrong destination address");
5911 #endif
5912
5913 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
5914 index 89bbf4e..869908e 100644
5915 --- a/arch/x86/boot/compressed/relocs.c
5916 +++ b/arch/x86/boot/compressed/relocs.c
5917 @@ -13,8 +13,11 @@
5918
5919 static void die(char *fmt, ...);
5920
5921 +#include "../../../../include/generated/autoconf.h"
5922 +
5923 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
5924 static Elf32_Ehdr ehdr;
5925 +static Elf32_Phdr *phdr;
5926 static unsigned long reloc_count, reloc_idx;
5927 static unsigned long *relocs;
5928
5929 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
5930 }
5931 }
5932
5933 +static void read_phdrs(FILE *fp)
5934 +{
5935 + unsigned int i;
5936 +
5937 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
5938 + if (!phdr) {
5939 + die("Unable to allocate %d program headers\n",
5940 + ehdr.e_phnum);
5941 + }
5942 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
5943 + die("Seek to %d failed: %s\n",
5944 + ehdr.e_phoff, strerror(errno));
5945 + }
5946 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
5947 + die("Cannot read ELF program headers: %s\n",
5948 + strerror(errno));
5949 + }
5950 + for(i = 0; i < ehdr.e_phnum; i++) {
5951 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
5952 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
5953 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
5954 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
5955 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
5956 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
5957 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
5958 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
5959 + }
5960 +
5961 +}
5962 +
5963 static void read_shdrs(FILE *fp)
5964 {
5965 - int i;
5966 + unsigned int i;
5967 Elf32_Shdr shdr;
5968
5969 secs = calloc(ehdr.e_shnum, sizeof(struct section));
5970 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
5971
5972 static void read_strtabs(FILE *fp)
5973 {
5974 - int i;
5975 + unsigned int i;
5976 for (i = 0; i < ehdr.e_shnum; i++) {
5977 struct section *sec = &secs[i];
5978 if (sec->shdr.sh_type != SHT_STRTAB) {
5979 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
5980
5981 static void read_symtabs(FILE *fp)
5982 {
5983 - int i,j;
5984 + unsigned int i,j;
5985 for (i = 0; i < ehdr.e_shnum; i++) {
5986 struct section *sec = &secs[i];
5987 if (sec->shdr.sh_type != SHT_SYMTAB) {
5988 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
5989
5990 static void read_relocs(FILE *fp)
5991 {
5992 - int i,j;
5993 + unsigned int i,j;
5994 + uint32_t base;
5995 +
5996 for (i = 0; i < ehdr.e_shnum; i++) {
5997 struct section *sec = &secs[i];
5998 if (sec->shdr.sh_type != SHT_REL) {
5999 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
6000 die("Cannot read symbol table: %s\n",
6001 strerror(errno));
6002 }
6003 + base = 0;
6004 + for (j = 0; j < ehdr.e_phnum; j++) {
6005 + if (phdr[j].p_type != PT_LOAD )
6006 + continue;
6007 + 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)
6008 + continue;
6009 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
6010 + break;
6011 + }
6012 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
6013 Elf32_Rel *rel = &sec->reltab[j];
6014 - rel->r_offset = elf32_to_cpu(rel->r_offset);
6015 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
6016 rel->r_info = elf32_to_cpu(rel->r_info);
6017 }
6018 }
6019 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
6020
6021 static void print_absolute_symbols(void)
6022 {
6023 - int i;
6024 + unsigned int i;
6025 printf("Absolute symbols\n");
6026 printf(" Num: Value Size Type Bind Visibility Name\n");
6027 for (i = 0; i < ehdr.e_shnum; i++) {
6028 struct section *sec = &secs[i];
6029 char *sym_strtab;
6030 Elf32_Sym *sh_symtab;
6031 - int j;
6032 + unsigned int j;
6033
6034 if (sec->shdr.sh_type != SHT_SYMTAB) {
6035 continue;
6036 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
6037
6038 static void print_absolute_relocs(void)
6039 {
6040 - int i, printed = 0;
6041 + unsigned int i, printed = 0;
6042
6043 for (i = 0; i < ehdr.e_shnum; i++) {
6044 struct section *sec = &secs[i];
6045 struct section *sec_applies, *sec_symtab;
6046 char *sym_strtab;
6047 Elf32_Sym *sh_symtab;
6048 - int j;
6049 + unsigned int j;
6050 if (sec->shdr.sh_type != SHT_REL) {
6051 continue;
6052 }
6053 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
6054
6055 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6056 {
6057 - int i;
6058 + unsigned int i;
6059 /* Walk through the relocations */
6060 for (i = 0; i < ehdr.e_shnum; i++) {
6061 char *sym_strtab;
6062 Elf32_Sym *sh_symtab;
6063 struct section *sec_applies, *sec_symtab;
6064 - int j;
6065 + unsigned int j;
6066 struct section *sec = &secs[i];
6067
6068 if (sec->shdr.sh_type != SHT_REL) {
6069 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6070 !is_rel_reloc(sym_name(sym_strtab, sym))) {
6071 continue;
6072 }
6073 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
6074 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
6075 + continue;
6076 +
6077 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
6078 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
6079 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
6080 + continue;
6081 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
6082 + continue;
6083 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
6084 + continue;
6085 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
6086 + continue;
6087 +#endif
6088 +
6089 switch (r_type) {
6090 case R_386_NONE:
6091 case R_386_PC32:
6092 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, const void *vb)
6093
6094 static void emit_relocs(int as_text)
6095 {
6096 - int i;
6097 + unsigned int i;
6098 /* Count how many relocations I have and allocate space for them. */
6099 reloc_count = 0;
6100 walk_relocs(count_reloc);
6101 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
6102 fname, strerror(errno));
6103 }
6104 read_ehdr(fp);
6105 + read_phdrs(fp);
6106 read_shdrs(fp);
6107 read_strtabs(fp);
6108 read_symtabs(fp);
6109 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
6110 index 4d3ff03..e4972ff 100644
6111 --- a/arch/x86/boot/cpucheck.c
6112 +++ b/arch/x86/boot/cpucheck.c
6113 @@ -74,7 +74,7 @@ static int has_fpu(void)
6114 u16 fcw = -1, fsw = -1;
6115 u32 cr0;
6116
6117 - asm("movl %%cr0,%0" : "=r" (cr0));
6118 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
6119 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
6120 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
6121 asm volatile("movl %0,%%cr0" : : "r" (cr0));
6122 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
6123 {
6124 u32 f0, f1;
6125
6126 - asm("pushfl ; "
6127 + asm volatile("pushfl ; "
6128 "pushfl ; "
6129 "popl %0 ; "
6130 "movl %0,%1 ; "
6131 @@ -115,7 +115,7 @@ static void get_flags(void)
6132 set_bit(X86_FEATURE_FPU, cpu.flags);
6133
6134 if (has_eflag(X86_EFLAGS_ID)) {
6135 - asm("cpuid"
6136 + asm volatile("cpuid"
6137 : "=a" (max_intel_level),
6138 "=b" (cpu_vendor[0]),
6139 "=d" (cpu_vendor[1]),
6140 @@ -124,7 +124,7 @@ static void get_flags(void)
6141
6142 if (max_intel_level >= 0x00000001 &&
6143 max_intel_level <= 0x0000ffff) {
6144 - asm("cpuid"
6145 + asm volatile("cpuid"
6146 : "=a" (tfms),
6147 "=c" (cpu.flags[4]),
6148 "=d" (cpu.flags[0])
6149 @@ -136,7 +136,7 @@ static void get_flags(void)
6150 cpu.model += ((tfms >> 16) & 0xf) << 4;
6151 }
6152
6153 - asm("cpuid"
6154 + asm volatile("cpuid"
6155 : "=a" (max_amd_level)
6156 : "a" (0x80000000)
6157 : "ebx", "ecx", "edx");
6158 @@ -144,7 +144,7 @@ static void get_flags(void)
6159 if (max_amd_level >= 0x80000001 &&
6160 max_amd_level <= 0x8000ffff) {
6161 u32 eax = 0x80000001;
6162 - asm("cpuid"
6163 + asm volatile("cpuid"
6164 : "+a" (eax),
6165 "=c" (cpu.flags[6]),
6166 "=d" (cpu.flags[1])
6167 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
6168 u32 ecx = MSR_K7_HWCR;
6169 u32 eax, edx;
6170
6171 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6172 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6173 eax &= ~(1 << 15);
6174 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6175 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6176
6177 get_flags(); /* Make sure it really did something */
6178 err = check_flags();
6179 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
6180 u32 ecx = MSR_VIA_FCR;
6181 u32 eax, edx;
6182
6183 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6184 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6185 eax |= (1<<1)|(1<<7);
6186 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6187 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6188
6189 set_bit(X86_FEATURE_CX8, cpu.flags);
6190 err = check_flags();
6191 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
6192 u32 eax, edx;
6193 u32 level = 1;
6194
6195 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6196 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6197 - asm("cpuid"
6198 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6199 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6200 + asm volatile("cpuid"
6201 : "+a" (level), "=d" (cpu.flags[0])
6202 : : "ecx", "ebx");
6203 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6204 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6205
6206 err = check_flags();
6207 }
6208 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
6209 index 93e689f..504ba09 100644
6210 --- a/arch/x86/boot/header.S
6211 +++ b/arch/x86/boot/header.S
6212 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
6213 # single linked list of
6214 # struct setup_data
6215
6216 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
6217 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
6218
6219 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
6220 #define VO_INIT_SIZE (VO__end - VO__text)
6221 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
6222 index db75d07..8e6d0af 100644
6223 --- a/arch/x86/boot/memory.c
6224 +++ b/arch/x86/boot/memory.c
6225 @@ -19,7 +19,7 @@
6226
6227 static int detect_memory_e820(void)
6228 {
6229 - int count = 0;
6230 + unsigned int count = 0;
6231 struct biosregs ireg, oreg;
6232 struct e820entry *desc = boot_params.e820_map;
6233 static struct e820entry buf; /* static so it is zeroed */
6234 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
6235 index 11e8c6e..fdbb1ed 100644
6236 --- a/arch/x86/boot/video-vesa.c
6237 +++ b/arch/x86/boot/video-vesa.c
6238 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
6239
6240 boot_params.screen_info.vesapm_seg = oreg.es;
6241 boot_params.screen_info.vesapm_off = oreg.di;
6242 + boot_params.screen_info.vesapm_size = oreg.cx;
6243 }
6244
6245 /*
6246 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
6247 index 43eda28..5ab5fdb 100644
6248 --- a/arch/x86/boot/video.c
6249 +++ b/arch/x86/boot/video.c
6250 @@ -96,7 +96,7 @@ static void store_mode_params(void)
6251 static unsigned int get_entry(void)
6252 {
6253 char entry_buf[4];
6254 - int i, len = 0;
6255 + unsigned int i, len = 0;
6256 int key;
6257 unsigned int v;
6258
6259 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
6260 index 5b577d5..3c1fed4 100644
6261 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
6262 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
6263 @@ -8,6 +8,8 @@
6264 * including this sentence is retained in full.
6265 */
6266
6267 +#include <asm/alternative-asm.h>
6268 +
6269 .extern crypto_ft_tab
6270 .extern crypto_it_tab
6271 .extern crypto_fl_tab
6272 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
6273 je B192; \
6274 leaq 32(r9),r9;
6275
6276 +#define ret pax_force_retaddr 0, 1; ret
6277 +
6278 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
6279 movq r1,r2; \
6280 movq r3,r4; \
6281 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
6282 index be6d9e3..21fbbca 100644
6283 --- a/arch/x86/crypto/aesni-intel_asm.S
6284 +++ b/arch/x86/crypto/aesni-intel_asm.S
6285 @@ -31,6 +31,7 @@
6286
6287 #include <linux/linkage.h>
6288 #include <asm/inst.h>
6289 +#include <asm/alternative-asm.h>
6290
6291 #ifdef __x86_64__
6292 .data
6293 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
6294 pop %r14
6295 pop %r13
6296 pop %r12
6297 + pax_force_retaddr 0, 1
6298 ret
6299 +ENDPROC(aesni_gcm_dec)
6300
6301
6302 /*****************************************************************************
6303 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
6304 pop %r14
6305 pop %r13
6306 pop %r12
6307 + pax_force_retaddr 0, 1
6308 ret
6309 +ENDPROC(aesni_gcm_enc)
6310
6311 #endif
6312
6313 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
6314 pxor %xmm1, %xmm0
6315 movaps %xmm0, (TKEYP)
6316 add $0x10, TKEYP
6317 + pax_force_retaddr_bts
6318 ret
6319
6320 .align 4
6321 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
6322 shufps $0b01001110, %xmm2, %xmm1
6323 movaps %xmm1, 0x10(TKEYP)
6324 add $0x20, TKEYP
6325 + pax_force_retaddr_bts
6326 ret
6327
6328 .align 4
6329 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
6330
6331 movaps %xmm0, (TKEYP)
6332 add $0x10, TKEYP
6333 + pax_force_retaddr_bts
6334 ret
6335
6336 .align 4
6337 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
6338 pxor %xmm1, %xmm2
6339 movaps %xmm2, (TKEYP)
6340 add $0x10, TKEYP
6341 + pax_force_retaddr_bts
6342 ret
6343
6344 /*
6345 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
6346 #ifndef __x86_64__
6347 popl KEYP
6348 #endif
6349 + pax_force_retaddr 0, 1
6350 ret
6351 +ENDPROC(aesni_set_key)
6352
6353 /*
6354 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
6355 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
6356 popl KLEN
6357 popl KEYP
6358 #endif
6359 + pax_force_retaddr 0, 1
6360 ret
6361 +ENDPROC(aesni_enc)
6362
6363 /*
6364 * _aesni_enc1: internal ABI
6365 @@ -1959,6 +1972,7 @@ _aesni_enc1:
6366 AESENC KEY STATE
6367 movaps 0x70(TKEYP), KEY
6368 AESENCLAST KEY STATE
6369 + pax_force_retaddr_bts
6370 ret
6371
6372 /*
6373 @@ -2067,6 +2081,7 @@ _aesni_enc4:
6374 AESENCLAST KEY STATE2
6375 AESENCLAST KEY STATE3
6376 AESENCLAST KEY STATE4
6377 + pax_force_retaddr_bts
6378 ret
6379
6380 /*
6381 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
6382 popl KLEN
6383 popl KEYP
6384 #endif
6385 + pax_force_retaddr 0, 1
6386 ret
6387 +ENDPROC(aesni_dec)
6388
6389 /*
6390 * _aesni_dec1: internal ABI
6391 @@ -2146,6 +2163,7 @@ _aesni_dec1:
6392 AESDEC KEY STATE
6393 movaps 0x70(TKEYP), KEY
6394 AESDECLAST KEY STATE
6395 + pax_force_retaddr_bts
6396 ret
6397
6398 /*
6399 @@ -2254,6 +2272,7 @@ _aesni_dec4:
6400 AESDECLAST KEY STATE2
6401 AESDECLAST KEY STATE3
6402 AESDECLAST KEY STATE4
6403 + pax_force_retaddr_bts
6404 ret
6405
6406 /*
6407 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
6408 popl KEYP
6409 popl LEN
6410 #endif
6411 + pax_force_retaddr 0, 1
6412 ret
6413 +ENDPROC(aesni_ecb_enc)
6414
6415 /*
6416 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
6417 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
6418 popl KEYP
6419 popl LEN
6420 #endif
6421 + pax_force_retaddr 0, 1
6422 ret
6423 +ENDPROC(aesni_ecb_dec)
6424
6425 /*
6426 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
6427 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
6428 popl LEN
6429 popl IVP
6430 #endif
6431 + pax_force_retaddr 0, 1
6432 ret
6433 +ENDPROC(aesni_cbc_enc)
6434
6435 /*
6436 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
6437 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
6438 popl LEN
6439 popl IVP
6440 #endif
6441 + pax_force_retaddr 0, 1
6442 ret
6443 +ENDPROC(aesni_cbc_dec)
6444
6445 #ifdef __x86_64__
6446 .align 16
6447 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
6448 mov $1, TCTR_LOW
6449 MOVQ_R64_XMM TCTR_LOW INC
6450 MOVQ_R64_XMM CTR TCTR_LOW
6451 + pax_force_retaddr_bts
6452 ret
6453
6454 /*
6455 @@ -2552,6 +2580,7 @@ _aesni_inc:
6456 .Linc_low:
6457 movaps CTR, IV
6458 PSHUFB_XMM BSWAP_MASK IV
6459 + pax_force_retaddr_bts
6460 ret
6461
6462 /*
6463 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
6464 .Lctr_enc_ret:
6465 movups IV, (IVP)
6466 .Lctr_enc_just_ret:
6467 + pax_force_retaddr 0, 1
6468 ret
6469 +ENDPROC(aesni_ctr_enc)
6470 #endif
6471 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
6472 index 6214a9b..1f4fc9a 100644
6473 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
6474 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
6475 @@ -1,3 +1,5 @@
6476 +#include <asm/alternative-asm.h>
6477 +
6478 # enter ECRYPT_encrypt_bytes
6479 .text
6480 .p2align 5
6481 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
6482 add %r11,%rsp
6483 mov %rdi,%rax
6484 mov %rsi,%rdx
6485 + pax_force_retaddr 0, 1
6486 ret
6487 # bytesatleast65:
6488 ._bytesatleast65:
6489 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
6490 add %r11,%rsp
6491 mov %rdi,%rax
6492 mov %rsi,%rdx
6493 + pax_force_retaddr
6494 ret
6495 # enter ECRYPT_ivsetup
6496 .text
6497 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
6498 add %r11,%rsp
6499 mov %rdi,%rax
6500 mov %rsi,%rdx
6501 + pax_force_retaddr
6502 ret
6503 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
6504 index 573aa10..b73ad89 100644
6505 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
6506 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
6507 @@ -21,6 +21,7 @@
6508 .text
6509
6510 #include <asm/asm-offsets.h>
6511 +#include <asm/alternative-asm.h>
6512
6513 #define a_offset 0
6514 #define b_offset 4
6515 @@ -269,6 +270,7 @@ twofish_enc_blk:
6516
6517 popq R1
6518 movq $1,%rax
6519 + pax_force_retaddr 0, 1
6520 ret
6521
6522 twofish_dec_blk:
6523 @@ -321,4 +323,5 @@ twofish_dec_blk:
6524
6525 popq R1
6526 movq $1,%rax
6527 + pax_force_retaddr 0, 1
6528 ret
6529 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
6530 index fd84387..0b4af7d 100644
6531 --- a/arch/x86/ia32/ia32_aout.c
6532 +++ b/arch/x86/ia32/ia32_aout.c
6533 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
6534 unsigned long dump_start, dump_size;
6535 struct user32 dump;
6536
6537 + memset(&dump, 0, sizeof(dump));
6538 +
6539 fs = get_fs();
6540 set_fs(KERNEL_DS);
6541 has_dumped = 1;
6542 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
6543 index 6557769..ef6ae89 100644
6544 --- a/arch/x86/ia32/ia32_signal.c
6545 +++ b/arch/x86/ia32/ia32_signal.c
6546 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
6547 }
6548 seg = get_fs();
6549 set_fs(KERNEL_DS);
6550 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
6551 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
6552 set_fs(seg);
6553 if (ret >= 0 && uoss_ptr) {
6554 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
6555 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
6556 */
6557 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
6558 size_t frame_size,
6559 - void **fpstate)
6560 + void __user **fpstate)
6561 {
6562 unsigned long sp;
6563
6564 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
6565
6566 if (used_math()) {
6567 sp = sp - sig_xstate_ia32_size;
6568 - *fpstate = (struct _fpstate_ia32 *) sp;
6569 + *fpstate = (struct _fpstate_ia32 __user *) sp;
6570 if (save_i387_xstate_ia32(*fpstate) < 0)
6571 return (void __user *) -1L;
6572 }
6573 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
6574 sp -= frame_size;
6575 /* Align the stack pointer according to the i386 ABI,
6576 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
6577 - sp = ((sp + 4) & -16ul) - 4;
6578 + sp = ((sp - 12) & -16ul) - 4;
6579 return (void __user *) sp;
6580 }
6581
6582 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
6583 * These are actually not used anymore, but left because some
6584 * gdb versions depend on them as a marker.
6585 */
6586 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6587 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
6588 } put_user_catch(err);
6589
6590 if (err)
6591 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
6592 0xb8,
6593 __NR_ia32_rt_sigreturn,
6594 0x80cd,
6595 - 0,
6596 + 0
6597 };
6598
6599 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
6600 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
6601
6602 if (ka->sa.sa_flags & SA_RESTORER)
6603 restorer = ka->sa.sa_restorer;
6604 + else if (current->mm->context.vdso)
6605 + /* Return stub is in 32bit vsyscall page */
6606 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6607 else
6608 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
6609 - rt_sigreturn);
6610 + restorer = &frame->retcode;
6611 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
6612
6613 /*
6614 * Not actually used anymore, but left because some gdb
6615 * versions need it.
6616 */
6617 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6618 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
6619 } put_user_catch(err);
6620
6621 if (err)
6622 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
6623 index 54edb207..f5101b9 100644
6624 --- a/arch/x86/ia32/ia32entry.S
6625 +++ b/arch/x86/ia32/ia32entry.S
6626 @@ -13,7 +13,9 @@
6627 #include <asm/thread_info.h>
6628 #include <asm/segment.h>
6629 #include <asm/irqflags.h>
6630 +#include <asm/pgtable.h>
6631 #include <linux/linkage.h>
6632 +#include <asm/alternative-asm.h>
6633
6634 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
6635 #include <linux/elf-em.h>
6636 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
6637 ENDPROC(native_irq_enable_sysexit)
6638 #endif
6639
6640 + .macro pax_enter_kernel_user
6641 + pax_set_fptr_mask
6642 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6643 + call pax_enter_kernel_user
6644 +#endif
6645 + .endm
6646 +
6647 + .macro pax_exit_kernel_user
6648 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6649 + call pax_exit_kernel_user
6650 +#endif
6651 +#ifdef CONFIG_PAX_RANDKSTACK
6652 + pushq %rax
6653 + pushq %r11
6654 + call pax_randomize_kstack
6655 + popq %r11
6656 + popq %rax
6657 +#endif
6658 + .endm
6659 +
6660 +.macro pax_erase_kstack
6661 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
6662 + call pax_erase_kstack
6663 +#endif
6664 +.endm
6665 +
6666 /*
6667 * 32bit SYSENTER instruction entry.
6668 *
6669 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
6670 CFI_REGISTER rsp,rbp
6671 SWAPGS_UNSAFE_STACK
6672 movq PER_CPU_VAR(kernel_stack), %rsp
6673 - addq $(KERNEL_STACK_OFFSET),%rsp
6674 - /*
6675 - * No need to follow this irqs on/off section: the syscall
6676 - * disabled irqs, here we enable it straight after entry:
6677 - */
6678 - ENABLE_INTERRUPTS(CLBR_NONE)
6679 movl %ebp,%ebp /* zero extension */
6680 pushq_cfi $__USER32_DS
6681 /*CFI_REL_OFFSET ss,0*/
6682 @@ -134,25 +156,38 @@ ENTRY(ia32_sysenter_target)
6683 CFI_REL_OFFSET rsp,0
6684 pushfq_cfi
6685 /*CFI_REL_OFFSET rflags,0*/
6686 - movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
6687 - CFI_REGISTER rip,r10
6688 + GET_THREAD_INFO(%r11)
6689 + movl TI_sysenter_return(%r11), %r11d
6690 + CFI_REGISTER rip,r11
6691 pushq_cfi $__USER32_CS
6692 /*CFI_REL_OFFSET cs,0*/
6693 movl %eax, %eax
6694 - pushq_cfi %r10
6695 + pushq_cfi %r11
6696 CFI_REL_OFFSET rip,0
6697 pushq_cfi %rax
6698 cld
6699 SAVE_ARGS 0,1,0
6700 + pax_enter_kernel_user
6701 + /*
6702 + * No need to follow this irqs on/off section: the syscall
6703 + * disabled irqs, here we enable it straight after entry:
6704 + */
6705 + ENABLE_INTERRUPTS(CLBR_NONE)
6706 /* no need to do an access_ok check here because rbp has been
6707 32bit zero extended */
6708 +
6709 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6710 + mov $PAX_USER_SHADOW_BASE,%r11
6711 + add %r11,%rbp
6712 +#endif
6713 +
6714 1: movl (%rbp),%ebp
6715 .section __ex_table,"a"
6716 .quad 1b,ia32_badarg
6717 .previous
6718 - GET_THREAD_INFO(%r10)
6719 - orl $TS_COMPAT,TI_status(%r10)
6720 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
6721 + GET_THREAD_INFO(%r11)
6722 + orl $TS_COMPAT,TI_status(%r11)
6723 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
6724 CFI_REMEMBER_STATE
6725 jnz sysenter_tracesys
6726 cmpq $(IA32_NR_syscalls-1),%rax
6727 @@ -162,13 +197,15 @@ sysenter_do_call:
6728 sysenter_dispatch:
6729 call *ia32_sys_call_table(,%rax,8)
6730 movq %rax,RAX-ARGOFFSET(%rsp)
6731 - GET_THREAD_INFO(%r10)
6732 + GET_THREAD_INFO(%r11)
6733 DISABLE_INTERRUPTS(CLBR_NONE)
6734 TRACE_IRQS_OFF
6735 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6736 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
6737 jnz sysexit_audit
6738 sysexit_from_sys_call:
6739 - andl $~TS_COMPAT,TI_status(%r10)
6740 + pax_exit_kernel_user
6741 + pax_erase_kstack
6742 + andl $~TS_COMPAT,TI_status(%r11)
6743 /* clear IF, that popfq doesn't enable interrupts early */
6744 andl $~0x200,EFLAGS-R11(%rsp)
6745 movl RIP-R11(%rsp),%edx /* User %eip */
6746 @@ -194,6 +231,9 @@ sysexit_from_sys_call:
6747 movl %eax,%esi /* 2nd arg: syscall number */
6748 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
6749 call audit_syscall_entry
6750 +
6751 + pax_erase_kstack
6752 +
6753 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
6754 cmpq $(IA32_NR_syscalls-1),%rax
6755 ja ia32_badsys
6756 @@ -205,7 +245,7 @@ sysexit_from_sys_call:
6757 .endm
6758
6759 .macro auditsys_exit exit
6760 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
6761 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
6762 jnz ia32_ret_from_sys_call
6763 TRACE_IRQS_ON
6764 sti
6765 @@ -215,12 +255,12 @@ sysexit_from_sys_call:
6766 movzbl %al,%edi /* zero-extend that into %edi */
6767 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
6768 call audit_syscall_exit
6769 - GET_THREAD_INFO(%r10)
6770 + GET_THREAD_INFO(%r11)
6771 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */
6772 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
6773 cli
6774 TRACE_IRQS_OFF
6775 - testl %edi,TI_flags(%r10)
6776 + testl %edi,TI_flags(%r11)
6777 jz \exit
6778 CLEAR_RREGS -ARGOFFSET
6779 jmp int_with_check
6780 @@ -238,7 +278,7 @@ sysexit_audit:
6781
6782 sysenter_tracesys:
6783 #ifdef CONFIG_AUDITSYSCALL
6784 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
6785 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
6786 jz sysenter_auditsys
6787 #endif
6788 SAVE_REST
6789 @@ -246,6 +286,9 @@ sysenter_tracesys:
6790 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
6791 movq %rsp,%rdi /* &pt_regs -> arg1 */
6792 call syscall_trace_enter
6793 +
6794 + pax_erase_kstack
6795 +
6796 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
6797 RESTORE_REST
6798 cmpq $(IA32_NR_syscalls-1),%rax
6799 @@ -277,19 +320,20 @@ ENDPROC(ia32_sysenter_target)
6800 ENTRY(ia32_cstar_target)
6801 CFI_STARTPROC32 simple
6802 CFI_SIGNAL_FRAME
6803 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
6804 + CFI_DEF_CFA rsp,0
6805 CFI_REGISTER rip,rcx
6806 /*CFI_REGISTER rflags,r11*/
6807 SWAPGS_UNSAFE_STACK
6808 movl %esp,%r8d
6809 CFI_REGISTER rsp,r8
6810 movq PER_CPU_VAR(kernel_stack),%rsp
6811 + SAVE_ARGS 8*6,0,0
6812 + pax_enter_kernel_user
6813 /*
6814 * No need to follow this irqs on/off section: the syscall
6815 * disabled irqs and here we enable it straight after entry:
6816 */
6817 ENABLE_INTERRUPTS(CLBR_NONE)
6818 - SAVE_ARGS 8,0,0
6819 movl %eax,%eax /* zero extension */
6820 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
6821 movq %rcx,RIP-ARGOFFSET(%rsp)
6822 @@ -305,13 +349,19 @@ ENTRY(ia32_cstar_target)
6823 /* no need to do an access_ok check here because r8 has been
6824 32bit zero extended */
6825 /* hardware stack frame is complete now */
6826 +
6827 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6828 + mov $PAX_USER_SHADOW_BASE,%r11
6829 + add %r11,%r8
6830 +#endif
6831 +
6832 1: movl (%r8),%r9d
6833 .section __ex_table,"a"
6834 .quad 1b,ia32_badarg
6835 .previous
6836 - GET_THREAD_INFO(%r10)
6837 - orl $TS_COMPAT,TI_status(%r10)
6838 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
6839 + GET_THREAD_INFO(%r11)
6840 + orl $TS_COMPAT,TI_status(%r11)
6841 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
6842 CFI_REMEMBER_STATE
6843 jnz cstar_tracesys
6844 cmpq $IA32_NR_syscalls-1,%rax
6845 @@ -321,13 +371,15 @@ cstar_do_call:
6846 cstar_dispatch:
6847 call *ia32_sys_call_table(,%rax,8)
6848 movq %rax,RAX-ARGOFFSET(%rsp)
6849 - GET_THREAD_INFO(%r10)
6850 + GET_THREAD_INFO(%r11)
6851 DISABLE_INTERRUPTS(CLBR_NONE)
6852 TRACE_IRQS_OFF
6853 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6854 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
6855 jnz sysretl_audit
6856 sysretl_from_sys_call:
6857 - andl $~TS_COMPAT,TI_status(%r10)
6858 + pax_exit_kernel_user
6859 + pax_erase_kstack
6860 + andl $~TS_COMPAT,TI_status(%r11)
6861 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
6862 movl RIP-ARGOFFSET(%rsp),%ecx
6863 CFI_REGISTER rip,rcx
6864 @@ -355,7 +407,7 @@ sysretl_audit:
6865
6866 cstar_tracesys:
6867 #ifdef CONFIG_AUDITSYSCALL
6868 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
6869 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
6870 jz cstar_auditsys
6871 #endif
6872 xchgl %r9d,%ebp
6873 @@ -364,6 +416,9 @@ cstar_tracesys:
6874 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
6875 movq %rsp,%rdi /* &pt_regs -> arg1 */
6876 call syscall_trace_enter
6877 +
6878 + pax_erase_kstack
6879 +
6880 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
6881 RESTORE_REST
6882 xchgl %ebp,%r9d
6883 @@ -409,20 +464,21 @@ ENTRY(ia32_syscall)
6884 CFI_REL_OFFSET rip,RIP-RIP
6885 PARAVIRT_ADJUST_EXCEPTION_FRAME
6886 SWAPGS
6887 - /*
6888 - * No need to follow this irqs on/off section: the syscall
6889 - * disabled irqs and here we enable it straight after entry:
6890 - */
6891 - ENABLE_INTERRUPTS(CLBR_NONE)
6892 movl %eax,%eax
6893 pushq_cfi %rax
6894 cld
6895 /* note the registers are not zero extended to the sf.
6896 this could be a problem. */
6897 SAVE_ARGS 0,1,0
6898 - GET_THREAD_INFO(%r10)
6899 - orl $TS_COMPAT,TI_status(%r10)
6900 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
6901 + pax_enter_kernel_user
6902 + /*
6903 + * No need to follow this irqs on/off section: the syscall
6904 + * disabled irqs and here we enable it straight after entry:
6905 + */
6906 + ENABLE_INTERRUPTS(CLBR_NONE)
6907 + GET_THREAD_INFO(%r11)
6908 + orl $TS_COMPAT,TI_status(%r11)
6909 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
6910 jnz ia32_tracesys
6911 cmpq $(IA32_NR_syscalls-1),%rax
6912 ja ia32_badsys
6913 @@ -441,6 +497,9 @@ ia32_tracesys:
6914 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
6915 movq %rsp,%rdi /* &pt_regs -> arg1 */
6916 call syscall_trace_enter
6917 +
6918 + pax_erase_kstack
6919 +
6920 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
6921 RESTORE_REST
6922 cmpq $(IA32_NR_syscalls-1),%rax
6923 @@ -455,6 +514,7 @@ ia32_badsys:
6924
6925 quiet_ni_syscall:
6926 movq $-ENOSYS,%rax
6927 + pax_force_retaddr
6928 ret
6929 CFI_ENDPROC
6930
6931 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
6932 index f6f5c53..b358b28 100644
6933 --- a/arch/x86/ia32/sys_ia32.c
6934 +++ b/arch/x86/ia32/sys_ia32.c
6935 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
6936 */
6937 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
6938 {
6939 - typeof(ubuf->st_uid) uid = 0;
6940 - typeof(ubuf->st_gid) gid = 0;
6941 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
6942 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
6943 SET_UID(uid, stat->uid);
6944 SET_GID(gid, stat->gid);
6945 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
6946 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
6947 }
6948 set_fs(KERNEL_DS);
6949 ret = sys_rt_sigprocmask(how,
6950 - set ? (sigset_t __user *)&s : NULL,
6951 - oset ? (sigset_t __user *)&s : NULL,
6952 + set ? (sigset_t __force_user *)&s : NULL,
6953 + oset ? (sigset_t __force_user *)&s : NULL,
6954 sigsetsize);
6955 set_fs(old_fs);
6956 if (ret)
6957 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
6958 return alarm_setitimer(seconds);
6959 }
6960
6961 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
6962 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
6963 int options)
6964 {
6965 return compat_sys_wait4(pid, stat_addr, options, NULL);
6966 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
6967 mm_segment_t old_fs = get_fs();
6968
6969 set_fs(KERNEL_DS);
6970 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
6971 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
6972 set_fs(old_fs);
6973 if (put_compat_timespec(&t, interval))
6974 return -EFAULT;
6975 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
6976 mm_segment_t old_fs = get_fs();
6977
6978 set_fs(KERNEL_DS);
6979 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
6980 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
6981 set_fs(old_fs);
6982 if (!ret) {
6983 switch (_NSIG_WORDS) {
6984 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
6985 if (copy_siginfo_from_user32(&info, uinfo))
6986 return -EFAULT;
6987 set_fs(KERNEL_DS);
6988 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
6989 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
6990 set_fs(old_fs);
6991 return ret;
6992 }
6993 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
6994 return -EFAULT;
6995
6996 set_fs(KERNEL_DS);
6997 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
6998 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
6999 count);
7000 set_fs(old_fs);
7001
7002 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
7003 index 091508b..e245ff2 100644
7004 --- a/arch/x86/include/asm/alternative-asm.h
7005 +++ b/arch/x86/include/asm/alternative-asm.h
7006 @@ -4,10 +4,10 @@
7007
7008 #ifdef CONFIG_SMP
7009 .macro LOCK_PREFIX
7010 -1: lock
7011 +672: lock
7012 .section .smp_locks,"a"
7013 .balign 4
7014 - .long 1b - .
7015 + .long 672b - .
7016 .previous
7017 .endm
7018 #else
7019 @@ -15,6 +15,45 @@
7020 .endm
7021 #endif
7022
7023 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
7024 + .macro pax_force_retaddr_bts rip=0
7025 + btsq $63,\rip(%rsp)
7026 + .endm
7027 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
7028 + .macro pax_force_retaddr rip=0, reload=0
7029 + btsq $63,\rip(%rsp)
7030 + .endm
7031 + .macro pax_force_fptr ptr
7032 + btsq $63,\ptr
7033 + .endm
7034 + .macro pax_set_fptr_mask
7035 + .endm
7036 +#endif
7037 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
7038 + .macro pax_force_retaddr rip=0, reload=0
7039 + .if \reload
7040 + pax_set_fptr_mask
7041 + .endif
7042 + orq %r10,\rip(%rsp)
7043 + .endm
7044 + .macro pax_force_fptr ptr
7045 + orq %r10,\ptr
7046 + .endm
7047 + .macro pax_set_fptr_mask
7048 + movabs $0x8000000000000000,%r10
7049 + .endm
7050 +#endif
7051 +#else
7052 + .macro pax_force_retaddr rip=0, reload=0
7053 + .endm
7054 + .macro pax_force_fptr ptr
7055 + .endm
7056 + .macro pax_force_retaddr_bts rip=0
7057 + .endm
7058 + .macro pax_set_fptr_mask
7059 + .endm
7060 +#endif
7061 +
7062 .macro altinstruction_entry orig alt feature orig_len alt_len
7063 .long \orig - .
7064 .long \alt - .
7065 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
7066 index 37ad100..7d47faa 100644
7067 --- a/arch/x86/include/asm/alternative.h
7068 +++ b/arch/x86/include/asm/alternative.h
7069 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
7070 ".section .discard,\"aw\",@progbits\n" \
7071 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
7072 ".previous\n" \
7073 - ".section .altinstr_replacement, \"ax\"\n" \
7074 + ".section .altinstr_replacement, \"a\"\n" \
7075 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
7076 ".previous"
7077
7078 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
7079 index 9b7273c..e9fcc24 100644
7080 --- a/arch/x86/include/asm/apic.h
7081 +++ b/arch/x86/include/asm/apic.h
7082 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
7083
7084 #ifdef CONFIG_X86_LOCAL_APIC
7085
7086 -extern unsigned int apic_verbosity;
7087 +extern int apic_verbosity;
7088 extern int local_apic_timer_c2_ok;
7089
7090 extern int disable_apic;
7091 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
7092 index 20370c6..a2eb9b0 100644
7093 --- a/arch/x86/include/asm/apm.h
7094 +++ b/arch/x86/include/asm/apm.h
7095 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
7096 __asm__ __volatile__(APM_DO_ZERO_SEGS
7097 "pushl %%edi\n\t"
7098 "pushl %%ebp\n\t"
7099 - "lcall *%%cs:apm_bios_entry\n\t"
7100 + "lcall *%%ss:apm_bios_entry\n\t"
7101 "setc %%al\n\t"
7102 "popl %%ebp\n\t"
7103 "popl %%edi\n\t"
7104 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
7105 __asm__ __volatile__(APM_DO_ZERO_SEGS
7106 "pushl %%edi\n\t"
7107 "pushl %%ebp\n\t"
7108 - "lcall *%%cs:apm_bios_entry\n\t"
7109 + "lcall *%%ss:apm_bios_entry\n\t"
7110 "setc %%bl\n\t"
7111 "popl %%ebp\n\t"
7112 "popl %%edi\n\t"
7113 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
7114 index 10572e3..392d0bc 100644
7115 --- a/arch/x86/include/asm/atomic.h
7116 +++ b/arch/x86/include/asm/atomic.h
7117 @@ -22,7 +22,18 @@
7118 */
7119 static inline int atomic_read(const atomic_t *v)
7120 {
7121 - return (*(volatile int *)&(v)->counter);
7122 + return (*(volatile const int *)&(v)->counter);
7123 +}
7124 +
7125 +/**
7126 + * atomic_read_unchecked - read atomic variable
7127 + * @v: pointer of type atomic_unchecked_t
7128 + *
7129 + * Atomically reads the value of @v.
7130 + */
7131 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7132 +{
7133 + return (*(volatile const int *)&(v)->counter);
7134 }
7135
7136 /**
7137 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
7138 }
7139
7140 /**
7141 + * atomic_set_unchecked - set atomic variable
7142 + * @v: pointer of type atomic_unchecked_t
7143 + * @i: required value
7144 + *
7145 + * Atomically sets the value of @v to @i.
7146 + */
7147 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7148 +{
7149 + v->counter = i;
7150 +}
7151 +
7152 +/**
7153 * atomic_add - add integer to atomic variable
7154 * @i: integer value to add
7155 * @v: pointer of type atomic_t
7156 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
7157 */
7158 static inline void atomic_add(int i, atomic_t *v)
7159 {
7160 - asm volatile(LOCK_PREFIX "addl %1,%0"
7161 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
7162 +
7163 +#ifdef CONFIG_PAX_REFCOUNT
7164 + "jno 0f\n"
7165 + LOCK_PREFIX "subl %1,%0\n"
7166 + "int $4\n0:\n"
7167 + _ASM_EXTABLE(0b, 0b)
7168 +#endif
7169 +
7170 + : "+m" (v->counter)
7171 + : "ir" (i));
7172 +}
7173 +
7174 +/**
7175 + * atomic_add_unchecked - add integer to atomic variable
7176 + * @i: integer value to add
7177 + * @v: pointer of type atomic_unchecked_t
7178 + *
7179 + * Atomically adds @i to @v.
7180 + */
7181 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
7182 +{
7183 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
7184 : "+m" (v->counter)
7185 : "ir" (i));
7186 }
7187 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
7188 */
7189 static inline void atomic_sub(int i, atomic_t *v)
7190 {
7191 - asm volatile(LOCK_PREFIX "subl %1,%0"
7192 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
7193 +
7194 +#ifdef CONFIG_PAX_REFCOUNT
7195 + "jno 0f\n"
7196 + LOCK_PREFIX "addl %1,%0\n"
7197 + "int $4\n0:\n"
7198 + _ASM_EXTABLE(0b, 0b)
7199 +#endif
7200 +
7201 + : "+m" (v->counter)
7202 + : "ir" (i));
7203 +}
7204 +
7205 +/**
7206 + * atomic_sub_unchecked - subtract integer from atomic variable
7207 + * @i: integer value to subtract
7208 + * @v: pointer of type atomic_unchecked_t
7209 + *
7210 + * Atomically subtracts @i from @v.
7211 + */
7212 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
7213 +{
7214 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
7215 : "+m" (v->counter)
7216 : "ir" (i));
7217 }
7218 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
7219 {
7220 unsigned char c;
7221
7222 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
7223 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
7224 +
7225 +#ifdef CONFIG_PAX_REFCOUNT
7226 + "jno 0f\n"
7227 + LOCK_PREFIX "addl %2,%0\n"
7228 + "int $4\n0:\n"
7229 + _ASM_EXTABLE(0b, 0b)
7230 +#endif
7231 +
7232 + "sete %1\n"
7233 : "+m" (v->counter), "=qm" (c)
7234 : "ir" (i) : "memory");
7235 return c;
7236 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
7237 */
7238 static inline void atomic_inc(atomic_t *v)
7239 {
7240 - asm volatile(LOCK_PREFIX "incl %0"
7241 + asm volatile(LOCK_PREFIX "incl %0\n"
7242 +
7243 +#ifdef CONFIG_PAX_REFCOUNT
7244 + "jno 0f\n"
7245 + LOCK_PREFIX "decl %0\n"
7246 + "int $4\n0:\n"
7247 + _ASM_EXTABLE(0b, 0b)
7248 +#endif
7249 +
7250 + : "+m" (v->counter));
7251 +}
7252 +
7253 +/**
7254 + * atomic_inc_unchecked - increment atomic variable
7255 + * @v: pointer of type atomic_unchecked_t
7256 + *
7257 + * Atomically increments @v by 1.
7258 + */
7259 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7260 +{
7261 + asm volatile(LOCK_PREFIX "incl %0\n"
7262 : "+m" (v->counter));
7263 }
7264
7265 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
7266 */
7267 static inline void atomic_dec(atomic_t *v)
7268 {
7269 - asm volatile(LOCK_PREFIX "decl %0"
7270 + asm volatile(LOCK_PREFIX "decl %0\n"
7271 +
7272 +#ifdef CONFIG_PAX_REFCOUNT
7273 + "jno 0f\n"
7274 + LOCK_PREFIX "incl %0\n"
7275 + "int $4\n0:\n"
7276 + _ASM_EXTABLE(0b, 0b)
7277 +#endif
7278 +
7279 + : "+m" (v->counter));
7280 +}
7281 +
7282 +/**
7283 + * atomic_dec_unchecked - decrement atomic variable
7284 + * @v: pointer of type atomic_unchecked_t
7285 + *
7286 + * Atomically decrements @v by 1.
7287 + */
7288 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7289 +{
7290 + asm volatile(LOCK_PREFIX "decl %0\n"
7291 : "+m" (v->counter));
7292 }
7293
7294 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
7295 {
7296 unsigned char c;
7297
7298 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
7299 + asm volatile(LOCK_PREFIX "decl %0\n"
7300 +
7301 +#ifdef CONFIG_PAX_REFCOUNT
7302 + "jno 0f\n"
7303 + LOCK_PREFIX "incl %0\n"
7304 + "int $4\n0:\n"
7305 + _ASM_EXTABLE(0b, 0b)
7306 +#endif
7307 +
7308 + "sete %1\n"
7309 : "+m" (v->counter), "=qm" (c)
7310 : : "memory");
7311 return c != 0;
7312 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
7313 {
7314 unsigned char c;
7315
7316 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
7317 + asm volatile(LOCK_PREFIX "incl %0\n"
7318 +
7319 +#ifdef CONFIG_PAX_REFCOUNT
7320 + "jno 0f\n"
7321 + LOCK_PREFIX "decl %0\n"
7322 + "int $4\n0:\n"
7323 + _ASM_EXTABLE(0b, 0b)
7324 +#endif
7325 +
7326 + "sete %1\n"
7327 + : "+m" (v->counter), "=qm" (c)
7328 + : : "memory");
7329 + return c != 0;
7330 +}
7331 +
7332 +/**
7333 + * atomic_inc_and_test_unchecked - increment and test
7334 + * @v: pointer of type atomic_unchecked_t
7335 + *
7336 + * Atomically increments @v by 1
7337 + * and returns true if the result is zero, or false for all
7338 + * other cases.
7339 + */
7340 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7341 +{
7342 + unsigned char c;
7343 +
7344 + asm volatile(LOCK_PREFIX "incl %0\n"
7345 + "sete %1\n"
7346 : "+m" (v->counter), "=qm" (c)
7347 : : "memory");
7348 return c != 0;
7349 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
7350 {
7351 unsigned char c;
7352
7353 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
7354 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
7355 +
7356 +#ifdef CONFIG_PAX_REFCOUNT
7357 + "jno 0f\n"
7358 + LOCK_PREFIX "subl %2,%0\n"
7359 + "int $4\n0:\n"
7360 + _ASM_EXTABLE(0b, 0b)
7361 +#endif
7362 +
7363 + "sets %1\n"
7364 : "+m" (v->counter), "=qm" (c)
7365 : "ir" (i) : "memory");
7366 return c;
7367 @@ -180,16 +342,56 @@ static inline int atomic_add_return(int i, atomic_t *v)
7368 #endif
7369 /* Modern 486+ processor */
7370 __i = i;
7371 - asm volatile(LOCK_PREFIX "xaddl %0, %1"
7372 + asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
7373 +
7374 +#ifdef CONFIG_PAX_REFCOUNT
7375 + "jno 0f\n"
7376 + "movl %0, %1\n"
7377 + "int $4\n0:\n"
7378 + _ASM_EXTABLE(0b, 0b)
7379 +#endif
7380 +
7381 : "+r" (i), "+m" (v->counter)
7382 : : "memory");
7383 return i + __i;
7384
7385 #ifdef CONFIG_M386
7386 no_xadd: /* Legacy 386 processor */
7387 - raw_local_irq_save(flags);
7388 + local_irq_save(flags);
7389 __i = atomic_read(v);
7390 atomic_set(v, i + __i);
7391 + local_irq_restore(flags);
7392 + return i + __i;
7393 +#endif
7394 +}
7395 +
7396 +/**
7397 + * atomic_add_return_unchecked - add integer and return
7398 + * @v: pointer of type atomic_unchecked_t
7399 + * @i: integer value to add
7400 + *
7401 + * Atomically adds @i to @v and returns @i + @v
7402 + */
7403 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7404 +{
7405 + int __i;
7406 +#ifdef CONFIG_M386
7407 + unsigned long flags;
7408 + if (unlikely(boot_cpu_data.x86 <= 3))
7409 + goto no_xadd;
7410 +#endif
7411 + /* Modern 486+ processor */
7412 + __i = i;
7413 + asm volatile(LOCK_PREFIX "xaddl %0, %1"
7414 + : "+r" (i), "+m" (v->counter)
7415 + : : "memory");
7416 + return i + __i;
7417 +
7418 +#ifdef CONFIG_M386
7419 +no_xadd: /* Legacy 386 processor */
7420 + raw_local_irq_save(flags);
7421 + __i = atomic_read_unchecked(v);
7422 + atomic_set_unchecked(v, i + __i);
7423 raw_local_irq_restore(flags);
7424 return i + __i;
7425 #endif
7426 @@ -208,6 +410,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
7427 }
7428
7429 #define atomic_inc_return(v) (atomic_add_return(1, v))
7430 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7431 +{
7432 + return atomic_add_return_unchecked(1, v);
7433 +}
7434 #define atomic_dec_return(v) (atomic_sub_return(1, v))
7435
7436 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
7437 @@ -215,11 +421,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
7438 return cmpxchg(&v->counter, old, new);
7439 }
7440
7441 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7442 +{
7443 + return cmpxchg(&v->counter, old, new);
7444 +}
7445 +
7446 static inline int atomic_xchg(atomic_t *v, int new)
7447 {
7448 return xchg(&v->counter, new);
7449 }
7450
7451 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7452 +{
7453 + return xchg(&v->counter, new);
7454 +}
7455 +
7456 /**
7457 * __atomic_add_unless - add unless the number is already a given value
7458 * @v: pointer of type atomic_t
7459 @@ -231,12 +447,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
7460 */
7461 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7462 {
7463 - int c, old;
7464 + int c, old, new;
7465 c = atomic_read(v);
7466 for (;;) {
7467 - if (unlikely(c == (u)))
7468 + if (unlikely(c == u))
7469 break;
7470 - old = atomic_cmpxchg((v), c, c + (a));
7471 +
7472 + asm volatile("addl %2,%0\n"
7473 +
7474 +#ifdef CONFIG_PAX_REFCOUNT
7475 + "jno 0f\n"
7476 + "subl %2,%0\n"
7477 + "int $4\n0:\n"
7478 + _ASM_EXTABLE(0b, 0b)
7479 +#endif
7480 +
7481 + : "=r" (new)
7482 + : "0" (c), "ir" (a));
7483 +
7484 + old = atomic_cmpxchg(v, c, new);
7485 if (likely(old == c))
7486 break;
7487 c = old;
7488 @@ -244,6 +473,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7489 return c;
7490 }
7491
7492 +/**
7493 + * atomic_inc_not_zero_hint - increment if not null
7494 + * @v: pointer of type atomic_t
7495 + * @hint: probable value of the atomic before the increment
7496 + *
7497 + * This version of atomic_inc_not_zero() gives a hint of probable
7498 + * value of the atomic. This helps processor to not read the memory
7499 + * before doing the atomic read/modify/write cycle, lowering
7500 + * number of bus transactions on some arches.
7501 + *
7502 + * Returns: 0 if increment was not done, 1 otherwise.
7503 + */
7504 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
7505 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
7506 +{
7507 + int val, c = hint, new;
7508 +
7509 + /* sanity test, should be removed by compiler if hint is a constant */
7510 + if (!hint)
7511 + return __atomic_add_unless(v, 1, 0);
7512 +
7513 + do {
7514 + asm volatile("incl %0\n"
7515 +
7516 +#ifdef CONFIG_PAX_REFCOUNT
7517 + "jno 0f\n"
7518 + "decl %0\n"
7519 + "int $4\n0:\n"
7520 + _ASM_EXTABLE(0b, 0b)
7521 +#endif
7522 +
7523 + : "=r" (new)
7524 + : "0" (c));
7525 +
7526 + val = atomic_cmpxchg(v, c, new);
7527 + if (val == c)
7528 + return 1;
7529 + c = val;
7530 + } while (c);
7531 +
7532 + return 0;
7533 +}
7534
7535 /*
7536 * atomic_dec_if_positive - decrement by 1 if old value positive
7537 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
7538 index 24098aa..1e37723 100644
7539 --- a/arch/x86/include/asm/atomic64_32.h
7540 +++ b/arch/x86/include/asm/atomic64_32.h
7541 @@ -12,6 +12,14 @@ typedef struct {
7542 u64 __aligned(8) counter;
7543 } atomic64_t;
7544
7545 +#ifdef CONFIG_PAX_REFCOUNT
7546 +typedef struct {
7547 + u64 __aligned(8) counter;
7548 +} atomic64_unchecked_t;
7549 +#else
7550 +typedef atomic64_t atomic64_unchecked_t;
7551 +#endif
7552 +
7553 #define ATOMIC64_INIT(val) { (val) }
7554
7555 #ifdef CONFIG_X86_CMPXCHG64
7556 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
7557 }
7558
7559 /**
7560 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
7561 + * @p: pointer to type atomic64_unchecked_t
7562 + * @o: expected value
7563 + * @n: new value
7564 + *
7565 + * Atomically sets @v to @n if it was equal to @o and returns
7566 + * the old value.
7567 + */
7568 +
7569 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
7570 +{
7571 + return cmpxchg64(&v->counter, o, n);
7572 +}
7573 +
7574 +/**
7575 * atomic64_xchg - xchg atomic64 variable
7576 * @v: pointer to type atomic64_t
7577 * @n: value to assign
7578 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
7579 }
7580
7581 /**
7582 + * atomic64_set_unchecked - set atomic64 variable
7583 + * @v: pointer to type atomic64_unchecked_t
7584 + * @n: value to assign
7585 + *
7586 + * Atomically sets the value of @v to @n.
7587 + */
7588 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
7589 +{
7590 + unsigned high = (unsigned)(i >> 32);
7591 + unsigned low = (unsigned)i;
7592 + asm volatile(ATOMIC64_ALTERNATIVE(set)
7593 + : "+b" (low), "+c" (high)
7594 + : "S" (v)
7595 + : "eax", "edx", "memory"
7596 + );
7597 +}
7598 +
7599 +/**
7600 * atomic64_read - read atomic64 variable
7601 * @v: pointer to type atomic64_t
7602 *
7603 @@ -93,6 +134,22 @@ static inline long long atomic64_read(atomic64_t *v)
7604 }
7605
7606 /**
7607 + * atomic64_read_unchecked - read atomic64 variable
7608 + * @v: pointer to type atomic64_unchecked_t
7609 + *
7610 + * Atomically reads the value of @v and returns it.
7611 + */
7612 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
7613 +{
7614 + long long r;
7615 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
7616 + : "=A" (r), "+c" (v)
7617 + : : "memory"
7618 + );
7619 + return r;
7620 + }
7621 +
7622 +/**
7623 * atomic64_add_return - add and return
7624 * @i: integer value to add
7625 * @v: pointer to type atomic64_t
7626 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
7627 return i;
7628 }
7629
7630 +/**
7631 + * atomic64_add_return_unchecked - add and return
7632 + * @i: integer value to add
7633 + * @v: pointer to type atomic64_unchecked_t
7634 + *
7635 + * Atomically adds @i to @v and returns @i + *@v
7636 + */
7637 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
7638 +{
7639 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
7640 + : "+A" (i), "+c" (v)
7641 + : : "memory"
7642 + );
7643 + return i;
7644 +}
7645 +
7646 /*
7647 * Other variants with different arithmetic operators:
7648 */
7649 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
7650 return a;
7651 }
7652
7653 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7654 +{
7655 + long long a;
7656 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
7657 + : "=A" (a)
7658 + : "S" (v)
7659 + : "memory", "ecx"
7660 + );
7661 + return a;
7662 +}
7663 +
7664 static inline long long atomic64_dec_return(atomic64_t *v)
7665 {
7666 long long a;
7667 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
7668 }
7669
7670 /**
7671 + * atomic64_add_unchecked - add integer to atomic64 variable
7672 + * @i: integer value to add
7673 + * @v: pointer to type atomic64_unchecked_t
7674 + *
7675 + * Atomically adds @i to @v.
7676 + */
7677 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
7678 +{
7679 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
7680 + : "+A" (i), "+c" (v)
7681 + : : "memory"
7682 + );
7683 + return i;
7684 +}
7685 +
7686 +/**
7687 * atomic64_sub - subtract the atomic64 variable
7688 * @i: integer value to subtract
7689 * @v: pointer to type atomic64_t
7690 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
7691 index 017594d..d3fcf72 100644
7692 --- a/arch/x86/include/asm/atomic64_64.h
7693 +++ b/arch/x86/include/asm/atomic64_64.h
7694 @@ -18,7 +18,19 @@
7695 */
7696 static inline long atomic64_read(const atomic64_t *v)
7697 {
7698 - return (*(volatile long *)&(v)->counter);
7699 + return (*(volatile const long *)&(v)->counter);
7700 +}
7701 +
7702 +/**
7703 + * atomic64_read_unchecked - read atomic64 variable
7704 + * @v: pointer of type atomic64_unchecked_t
7705 + *
7706 + * Atomically reads the value of @v.
7707 + * Doesn't imply a read memory barrier.
7708 + */
7709 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7710 +{
7711 + return (*(volatile const long *)&(v)->counter);
7712 }
7713
7714 /**
7715 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
7716 }
7717
7718 /**
7719 + * atomic64_set_unchecked - set atomic64 variable
7720 + * @v: pointer to type atomic64_unchecked_t
7721 + * @i: required value
7722 + *
7723 + * Atomically sets the value of @v to @i.
7724 + */
7725 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7726 +{
7727 + v->counter = i;
7728 +}
7729 +
7730 +/**
7731 * atomic64_add - add integer to atomic64 variable
7732 * @i: integer value to add
7733 * @v: pointer to type atomic64_t
7734 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
7735 */
7736 static inline void atomic64_add(long i, atomic64_t *v)
7737 {
7738 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
7739 +
7740 +#ifdef CONFIG_PAX_REFCOUNT
7741 + "jno 0f\n"
7742 + LOCK_PREFIX "subq %1,%0\n"
7743 + "int $4\n0:\n"
7744 + _ASM_EXTABLE(0b, 0b)
7745 +#endif
7746 +
7747 + : "=m" (v->counter)
7748 + : "er" (i), "m" (v->counter));
7749 +}
7750 +
7751 +/**
7752 + * atomic64_add_unchecked - add integer to atomic64 variable
7753 + * @i: integer value to add
7754 + * @v: pointer to type atomic64_unchecked_t
7755 + *
7756 + * Atomically adds @i to @v.
7757 + */
7758 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
7759 +{
7760 asm volatile(LOCK_PREFIX "addq %1,%0"
7761 : "=m" (v->counter)
7762 : "er" (i), "m" (v->counter));
7763 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
7764 */
7765 static inline void atomic64_sub(long i, atomic64_t *v)
7766 {
7767 - asm volatile(LOCK_PREFIX "subq %1,%0"
7768 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
7769 +
7770 +#ifdef CONFIG_PAX_REFCOUNT
7771 + "jno 0f\n"
7772 + LOCK_PREFIX "addq %1,%0\n"
7773 + "int $4\n0:\n"
7774 + _ASM_EXTABLE(0b, 0b)
7775 +#endif
7776 +
7777 + : "=m" (v->counter)
7778 + : "er" (i), "m" (v->counter));
7779 +}
7780 +
7781 +/**
7782 + * atomic64_sub_unchecked - subtract the atomic64 variable
7783 + * @i: integer value to subtract
7784 + * @v: pointer to type atomic64_unchecked_t
7785 + *
7786 + * Atomically subtracts @i from @v.
7787 + */
7788 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
7789 +{
7790 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
7791 : "=m" (v->counter)
7792 : "er" (i), "m" (v->counter));
7793 }
7794 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
7795 {
7796 unsigned char c;
7797
7798 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
7799 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
7800 +
7801 +#ifdef CONFIG_PAX_REFCOUNT
7802 + "jno 0f\n"
7803 + LOCK_PREFIX "addq %2,%0\n"
7804 + "int $4\n0:\n"
7805 + _ASM_EXTABLE(0b, 0b)
7806 +#endif
7807 +
7808 + "sete %1\n"
7809 : "=m" (v->counter), "=qm" (c)
7810 : "er" (i), "m" (v->counter) : "memory");
7811 return c;
7812 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
7813 */
7814 static inline void atomic64_inc(atomic64_t *v)
7815 {
7816 + asm volatile(LOCK_PREFIX "incq %0\n"
7817 +
7818 +#ifdef CONFIG_PAX_REFCOUNT
7819 + "jno 0f\n"
7820 + LOCK_PREFIX "decq %0\n"
7821 + "int $4\n0:\n"
7822 + _ASM_EXTABLE(0b, 0b)
7823 +#endif
7824 +
7825 + : "=m" (v->counter)
7826 + : "m" (v->counter));
7827 +}
7828 +
7829 +/**
7830 + * atomic64_inc_unchecked - increment atomic64 variable
7831 + * @v: pointer to type atomic64_unchecked_t
7832 + *
7833 + * Atomically increments @v by 1.
7834 + */
7835 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7836 +{
7837 asm volatile(LOCK_PREFIX "incq %0"
7838 : "=m" (v->counter)
7839 : "m" (v->counter));
7840 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
7841 */
7842 static inline void atomic64_dec(atomic64_t *v)
7843 {
7844 - asm volatile(LOCK_PREFIX "decq %0"
7845 + asm volatile(LOCK_PREFIX "decq %0\n"
7846 +
7847 +#ifdef CONFIG_PAX_REFCOUNT
7848 + "jno 0f\n"
7849 + LOCK_PREFIX "incq %0\n"
7850 + "int $4\n0:\n"
7851 + _ASM_EXTABLE(0b, 0b)
7852 +#endif
7853 +
7854 + : "=m" (v->counter)
7855 + : "m" (v->counter));
7856 +}
7857 +
7858 +/**
7859 + * atomic64_dec_unchecked - decrement atomic64 variable
7860 + * @v: pointer to type atomic64_t
7861 + *
7862 + * Atomically decrements @v by 1.
7863 + */
7864 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7865 +{
7866 + asm volatile(LOCK_PREFIX "decq %0\n"
7867 : "=m" (v->counter)
7868 : "m" (v->counter));
7869 }
7870 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
7871 {
7872 unsigned char c;
7873
7874 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
7875 + asm volatile(LOCK_PREFIX "decq %0\n"
7876 +
7877 +#ifdef CONFIG_PAX_REFCOUNT
7878 + "jno 0f\n"
7879 + LOCK_PREFIX "incq %0\n"
7880 + "int $4\n0:\n"
7881 + _ASM_EXTABLE(0b, 0b)
7882 +#endif
7883 +
7884 + "sete %1\n"
7885 : "=m" (v->counter), "=qm" (c)
7886 : "m" (v->counter) : "memory");
7887 return c != 0;
7888 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
7889 {
7890 unsigned char c;
7891
7892 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
7893 + asm volatile(LOCK_PREFIX "incq %0\n"
7894 +
7895 +#ifdef CONFIG_PAX_REFCOUNT
7896 + "jno 0f\n"
7897 + LOCK_PREFIX "decq %0\n"
7898 + "int $4\n0:\n"
7899 + _ASM_EXTABLE(0b, 0b)
7900 +#endif
7901 +
7902 + "sete %1\n"
7903 : "=m" (v->counter), "=qm" (c)
7904 : "m" (v->counter) : "memory");
7905 return c != 0;
7906 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
7907 {
7908 unsigned char c;
7909
7910 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
7911 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
7912 +
7913 +#ifdef CONFIG_PAX_REFCOUNT
7914 + "jno 0f\n"
7915 + LOCK_PREFIX "subq %2,%0\n"
7916 + "int $4\n0:\n"
7917 + _ASM_EXTABLE(0b, 0b)
7918 +#endif
7919 +
7920 + "sets %1\n"
7921 : "=m" (v->counter), "=qm" (c)
7922 : "er" (i), "m" (v->counter) : "memory");
7923 return c;
7924 @@ -171,7 +317,31 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
7925 static inline long atomic64_add_return(long i, atomic64_t *v)
7926 {
7927 long __i = i;
7928 - asm volatile(LOCK_PREFIX "xaddq %0, %1;"
7929 + asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
7930 +
7931 +#ifdef CONFIG_PAX_REFCOUNT
7932 + "jno 0f\n"
7933 + "movq %0, %1\n"
7934 + "int $4\n0:\n"
7935 + _ASM_EXTABLE(0b, 0b)
7936 +#endif
7937 +
7938 + : "+r" (i), "+m" (v->counter)
7939 + : : "memory");
7940 + return i + __i;
7941 +}
7942 +
7943 +/**
7944 + * atomic64_add_return_unchecked - add and return
7945 + * @i: integer value to add
7946 + * @v: pointer to type atomic64_unchecked_t
7947 + *
7948 + * Atomically adds @i to @v and returns @i + @v
7949 + */
7950 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7951 +{
7952 + long __i = i;
7953 + asm volatile(LOCK_PREFIX "xaddq %0, %1"
7954 : "+r" (i), "+m" (v->counter)
7955 : : "memory");
7956 return i + __i;
7957 @@ -183,6 +353,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
7958 }
7959
7960 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
7961 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7962 +{
7963 + return atomic64_add_return_unchecked(1, v);
7964 +}
7965 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
7966
7967 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
7968 @@ -190,6 +364,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
7969 return cmpxchg(&v->counter, old, new);
7970 }
7971
7972 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
7973 +{
7974 + return cmpxchg(&v->counter, old, new);
7975 +}
7976 +
7977 static inline long atomic64_xchg(atomic64_t *v, long new)
7978 {
7979 return xchg(&v->counter, new);
7980 @@ -206,17 +385,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
7981 */
7982 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
7983 {
7984 - long c, old;
7985 + long c, old, new;
7986 c = atomic64_read(v);
7987 for (;;) {
7988 - if (unlikely(c == (u)))
7989 + if (unlikely(c == u))
7990 break;
7991 - old = atomic64_cmpxchg((v), c, c + (a));
7992 +
7993 + asm volatile("add %2,%0\n"
7994 +
7995 +#ifdef CONFIG_PAX_REFCOUNT
7996 + "jno 0f\n"
7997 + "sub %2,%0\n"
7998 + "int $4\n0:\n"
7999 + _ASM_EXTABLE(0b, 0b)
8000 +#endif
8001 +
8002 + : "=r" (new)
8003 + : "0" (c), "ir" (a));
8004 +
8005 + old = atomic64_cmpxchg(v, c, new);
8006 if (likely(old == c))
8007 break;
8008 c = old;
8009 }
8010 - return c != (u);
8011 + return c != u;
8012 }
8013
8014 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8015 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
8016 index 1775d6e..b65017f 100644
8017 --- a/arch/x86/include/asm/bitops.h
8018 +++ b/arch/x86/include/asm/bitops.h
8019 @@ -38,7 +38,7 @@
8020 * a mask operation on a byte.
8021 */
8022 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
8023 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
8024 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
8025 #define CONST_MASK(nr) (1 << ((nr) & 7))
8026
8027 /**
8028 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
8029 index 5e1a2ee..c9f9533 100644
8030 --- a/arch/x86/include/asm/boot.h
8031 +++ b/arch/x86/include/asm/boot.h
8032 @@ -11,10 +11,15 @@
8033 #include <asm/pgtable_types.h>
8034
8035 /* Physical address where kernel should be loaded. */
8036 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8037 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8038 + (CONFIG_PHYSICAL_ALIGN - 1)) \
8039 & ~(CONFIG_PHYSICAL_ALIGN - 1))
8040
8041 +#ifndef __ASSEMBLY__
8042 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
8043 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
8044 +#endif
8045 +
8046 /* Minimum kernel alignment, as a power of two */
8047 #ifdef CONFIG_X86_64
8048 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
8049 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
8050 index 48f99f1..d78ebf9 100644
8051 --- a/arch/x86/include/asm/cache.h
8052 +++ b/arch/x86/include/asm/cache.h
8053 @@ -5,12 +5,13 @@
8054
8055 /* L1 cache line size */
8056 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8057 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8058 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8059
8060 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8061 +#define __read_only __attribute__((__section__(".data..read_only")))
8062
8063 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
8064 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
8065 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
8066
8067 #ifdef CONFIG_X86_VSMP
8068 #ifdef CONFIG_SMP
8069 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
8070 index 4e12668..501d239 100644
8071 --- a/arch/x86/include/asm/cacheflush.h
8072 +++ b/arch/x86/include/asm/cacheflush.h
8073 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
8074 unsigned long pg_flags = pg->flags & _PGMT_MASK;
8075
8076 if (pg_flags == _PGMT_DEFAULT)
8077 - return -1;
8078 + return ~0UL;
8079 else if (pg_flags == _PGMT_WC)
8080 return _PAGE_CACHE_WC;
8081 else if (pg_flags == _PGMT_UC_MINUS)
8082 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
8083 index 46fc474..b02b0f9 100644
8084 --- a/arch/x86/include/asm/checksum_32.h
8085 +++ b/arch/x86/include/asm/checksum_32.h
8086 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
8087 int len, __wsum sum,
8088 int *src_err_ptr, int *dst_err_ptr);
8089
8090 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
8091 + int len, __wsum sum,
8092 + int *src_err_ptr, int *dst_err_ptr);
8093 +
8094 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
8095 + int len, __wsum sum,
8096 + int *src_err_ptr, int *dst_err_ptr);
8097 +
8098 /*
8099 * Note: when you get a NULL pointer exception here this means someone
8100 * passed in an incorrect kernel address to one of these functions.
8101 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
8102 int *err_ptr)
8103 {
8104 might_sleep();
8105 - return csum_partial_copy_generic((__force void *)src, dst,
8106 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
8107 len, sum, err_ptr, NULL);
8108 }
8109
8110 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
8111 {
8112 might_sleep();
8113 if (access_ok(VERIFY_WRITE, dst, len))
8114 - return csum_partial_copy_generic(src, (__force void *)dst,
8115 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
8116 len, sum, NULL, err_ptr);
8117
8118 if (len)
8119 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
8120 index 88b23a4..d2e5f9f 100644
8121 --- a/arch/x86/include/asm/cpufeature.h
8122 +++ b/arch/x86/include/asm/cpufeature.h
8123 @@ -358,7 +358,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
8124 ".section .discard,\"aw\",@progbits\n"
8125 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
8126 ".previous\n"
8127 - ".section .altinstr_replacement,\"ax\"\n"
8128 + ".section .altinstr_replacement,\"a\"\n"
8129 "3: movb $1,%0\n"
8130 "4:\n"
8131 ".previous\n"
8132 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
8133 index 41935fa..3b40db8 100644
8134 --- a/arch/x86/include/asm/desc.h
8135 +++ b/arch/x86/include/asm/desc.h
8136 @@ -4,6 +4,7 @@
8137 #include <asm/desc_defs.h>
8138 #include <asm/ldt.h>
8139 #include <asm/mmu.h>
8140 +#include <asm/pgtable.h>
8141
8142 #include <linux/smp.h>
8143
8144 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
8145
8146 desc->type = (info->read_exec_only ^ 1) << 1;
8147 desc->type |= info->contents << 2;
8148 + desc->type |= info->seg_not_present ^ 1;
8149
8150 desc->s = 1;
8151 desc->dpl = 0x3;
8152 @@ -34,17 +36,12 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
8153 }
8154
8155 extern struct desc_ptr idt_descr;
8156 -extern gate_desc idt_table[];
8157 -
8158 -struct gdt_page {
8159 - struct desc_struct gdt[GDT_ENTRIES];
8160 -} __attribute__((aligned(PAGE_SIZE)));
8161 -
8162 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
8163 +extern gate_desc idt_table[256];
8164
8165 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
8166 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
8167 {
8168 - return per_cpu(gdt_page, cpu).gdt;
8169 + return cpu_gdt_table[cpu];
8170 }
8171
8172 #ifdef CONFIG_X86_64
8173 @@ -69,8 +66,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
8174 unsigned long base, unsigned dpl, unsigned flags,
8175 unsigned short seg)
8176 {
8177 - gate->a = (seg << 16) | (base & 0xffff);
8178 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
8179 + gate->gate.offset_low = base;
8180 + gate->gate.seg = seg;
8181 + gate->gate.reserved = 0;
8182 + gate->gate.type = type;
8183 + gate->gate.s = 0;
8184 + gate->gate.dpl = dpl;
8185 + gate->gate.p = 1;
8186 + gate->gate.offset_high = base >> 16;
8187 }
8188
8189 #endif
8190 @@ -115,12 +118,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
8191
8192 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
8193 {
8194 + pax_open_kernel();
8195 memcpy(&idt[entry], gate, sizeof(*gate));
8196 + pax_close_kernel();
8197 }
8198
8199 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
8200 {
8201 + pax_open_kernel();
8202 memcpy(&ldt[entry], desc, 8);
8203 + pax_close_kernel();
8204 }
8205
8206 static inline void
8207 @@ -134,7 +141,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
8208 default: size = sizeof(*gdt); break;
8209 }
8210
8211 + pax_open_kernel();
8212 memcpy(&gdt[entry], desc, size);
8213 + pax_close_kernel();
8214 }
8215
8216 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
8217 @@ -207,7 +216,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
8218
8219 static inline void native_load_tr_desc(void)
8220 {
8221 + pax_open_kernel();
8222 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
8223 + pax_close_kernel();
8224 }
8225
8226 static inline void native_load_gdt(const struct desc_ptr *dtr)
8227 @@ -244,8 +255,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
8228 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
8229 unsigned int i;
8230
8231 + pax_open_kernel();
8232 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
8233 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
8234 + pax_close_kernel();
8235 }
8236
8237 #define _LDT_empty(info) \
8238 @@ -307,7 +320,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
8239 desc->limit = (limit >> 16) & 0xf;
8240 }
8241
8242 -static inline void _set_gate(int gate, unsigned type, void *addr,
8243 +static inline void _set_gate(int gate, unsigned type, const void *addr,
8244 unsigned dpl, unsigned ist, unsigned seg)
8245 {
8246 gate_desc s;
8247 @@ -326,7 +339,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
8248 * Pentium F0 0F bugfix can have resulted in the mapped
8249 * IDT being write-protected.
8250 */
8251 -static inline void set_intr_gate(unsigned int n, void *addr)
8252 +static inline void set_intr_gate(unsigned int n, const void *addr)
8253 {
8254 BUG_ON((unsigned)n > 0xFF);
8255 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
8256 @@ -356,19 +369,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
8257 /*
8258 * This routine sets up an interrupt gate at directory privilege level 3.
8259 */
8260 -static inline void set_system_intr_gate(unsigned int n, void *addr)
8261 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
8262 {
8263 BUG_ON((unsigned)n > 0xFF);
8264 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
8265 }
8266
8267 -static inline void set_system_trap_gate(unsigned int n, void *addr)
8268 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
8269 {
8270 BUG_ON((unsigned)n > 0xFF);
8271 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
8272 }
8273
8274 -static inline void set_trap_gate(unsigned int n, void *addr)
8275 +static inline void set_trap_gate(unsigned int n, const void *addr)
8276 {
8277 BUG_ON((unsigned)n > 0xFF);
8278 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
8279 @@ -377,19 +390,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
8280 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
8281 {
8282 BUG_ON((unsigned)n > 0xFF);
8283 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
8284 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
8285 }
8286
8287 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
8288 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
8289 {
8290 BUG_ON((unsigned)n > 0xFF);
8291 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
8292 }
8293
8294 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
8295 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
8296 {
8297 BUG_ON((unsigned)n > 0xFF);
8298 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
8299 }
8300
8301 +#ifdef CONFIG_X86_32
8302 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
8303 +{
8304 + struct desc_struct d;
8305 +
8306 + if (likely(limit))
8307 + limit = (limit - 1UL) >> PAGE_SHIFT;
8308 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
8309 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
8310 +}
8311 +#endif
8312 +
8313 #endif /* _ASM_X86_DESC_H */
8314 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
8315 index 278441f..b95a174 100644
8316 --- a/arch/x86/include/asm/desc_defs.h
8317 +++ b/arch/x86/include/asm/desc_defs.h
8318 @@ -31,6 +31,12 @@ struct desc_struct {
8319 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
8320 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
8321 };
8322 + struct {
8323 + u16 offset_low;
8324 + u16 seg;
8325 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
8326 + unsigned offset_high: 16;
8327 + } gate;
8328 };
8329 } __attribute__((packed));
8330
8331 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
8332 index 908b969..a1f4eb4 100644
8333 --- a/arch/x86/include/asm/e820.h
8334 +++ b/arch/x86/include/asm/e820.h
8335 @@ -69,7 +69,7 @@ struct e820map {
8336 #define ISA_START_ADDRESS 0xa0000
8337 #define ISA_END_ADDRESS 0x100000
8338
8339 -#define BIOS_BEGIN 0x000a0000
8340 +#define BIOS_BEGIN 0x000c0000
8341 #define BIOS_END 0x00100000
8342
8343 #define BIOS_ROM_BASE 0xffe00000
8344 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
8345 index f2ad216..eb24c96 100644
8346 --- a/arch/x86/include/asm/elf.h
8347 +++ b/arch/x86/include/asm/elf.h
8348 @@ -237,7 +237,25 @@ extern int force_personality32;
8349 the loader. We need to make sure that it is out of the way of the program
8350 that it will "exec", and that there is sufficient room for the brk. */
8351
8352 +#ifdef CONFIG_PAX_SEGMEXEC
8353 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
8354 +#else
8355 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
8356 +#endif
8357 +
8358 +#ifdef CONFIG_PAX_ASLR
8359 +#ifdef CONFIG_X86_32
8360 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
8361 +
8362 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8363 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8364 +#else
8365 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
8366 +
8367 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8368 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8369 +#endif
8370 +#endif
8371
8372 /* This yields a mask that user programs can use to figure out what
8373 instruction set this CPU supports. This could be done in user space,
8374 @@ -290,9 +308,7 @@ do { \
8375
8376 #define ARCH_DLINFO \
8377 do { \
8378 - if (vdso_enabled) \
8379 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
8380 - (unsigned long)current->mm->context.vdso); \
8381 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
8382 } while (0)
8383
8384 #define AT_SYSINFO 32
8385 @@ -303,7 +319,7 @@ do { \
8386
8387 #endif /* !CONFIG_X86_32 */
8388
8389 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
8390 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
8391
8392 #define VDSO_ENTRY \
8393 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
8394 @@ -317,7 +333,4 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8395 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
8396 #define compat_arch_setup_additional_pages syscall32_setup_pages
8397
8398 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8399 -#define arch_randomize_brk arch_randomize_brk
8400 -
8401 #endif /* _ASM_X86_ELF_H */
8402 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
8403 index cc70c1c..d96d011 100644
8404 --- a/arch/x86/include/asm/emergency-restart.h
8405 +++ b/arch/x86/include/asm/emergency-restart.h
8406 @@ -15,6 +15,6 @@ enum reboot_type {
8407
8408 extern enum reboot_type reboot_type;
8409
8410 -extern void machine_emergency_restart(void);
8411 +extern void machine_emergency_restart(void) __noreturn;
8412
8413 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
8414 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
8415 index d09bb03..4ea4194 100644
8416 --- a/arch/x86/include/asm/futex.h
8417 +++ b/arch/x86/include/asm/futex.h
8418 @@ -12,16 +12,18 @@
8419 #include <asm/system.h>
8420
8421 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
8422 + typecheck(u32 __user *, uaddr); \
8423 asm volatile("1:\t" insn "\n" \
8424 "2:\t.section .fixup,\"ax\"\n" \
8425 "3:\tmov\t%3, %1\n" \
8426 "\tjmp\t2b\n" \
8427 "\t.previous\n" \
8428 _ASM_EXTABLE(1b, 3b) \
8429 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
8430 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
8431 : "i" (-EFAULT), "0" (oparg), "1" (0))
8432
8433 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
8434 + typecheck(u32 __user *, uaddr); \
8435 asm volatile("1:\tmovl %2, %0\n" \
8436 "\tmovl\t%0, %3\n" \
8437 "\t" insn "\n" \
8438 @@ -34,7 +36,7 @@
8439 _ASM_EXTABLE(1b, 4b) \
8440 _ASM_EXTABLE(2b, 4b) \
8441 : "=&a" (oldval), "=&r" (ret), \
8442 - "+m" (*uaddr), "=&r" (tem) \
8443 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
8444 : "r" (oparg), "i" (-EFAULT), "1" (0))
8445
8446 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
8447 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
8448
8449 switch (op) {
8450 case FUTEX_OP_SET:
8451 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
8452 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
8453 break;
8454 case FUTEX_OP_ADD:
8455 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
8456 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
8457 uaddr, oparg);
8458 break;
8459 case FUTEX_OP_OR:
8460 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
8461 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
8462 return -EFAULT;
8463
8464 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
8465 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
8466 "2:\t.section .fixup, \"ax\"\n"
8467 "3:\tmov %3, %0\n"
8468 "\tjmp 2b\n"
8469 "\t.previous\n"
8470 _ASM_EXTABLE(1b, 3b)
8471 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
8472 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
8473 : "i" (-EFAULT), "r" (newval), "1" (oldval)
8474 : "memory"
8475 );
8476 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
8477 index 0919905..2cf38d6 100644
8478 --- a/arch/x86/include/asm/hw_irq.h
8479 +++ b/arch/x86/include/asm/hw_irq.h
8480 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
8481 extern void enable_IO_APIC(void);
8482
8483 /* Statistics */
8484 -extern atomic_t irq_err_count;
8485 -extern atomic_t irq_mis_count;
8486 +extern atomic_unchecked_t irq_err_count;
8487 +extern atomic_unchecked_t irq_mis_count;
8488
8489 /* EISA */
8490 extern void eisa_set_level_irq(unsigned int irq);
8491 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
8492 index c9e09ea..73888df 100644
8493 --- a/arch/x86/include/asm/i387.h
8494 +++ b/arch/x86/include/asm/i387.h
8495 @@ -92,6 +92,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
8496 {
8497 int err;
8498
8499 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8500 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8501 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
8502 +#endif
8503 +
8504 /* See comment in fxsave() below. */
8505 #ifdef CONFIG_AS_FXSAVEQ
8506 asm volatile("1: fxrstorq %[fx]\n\t"
8507 @@ -121,6 +126,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
8508 {
8509 int err;
8510
8511 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8512 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8513 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
8514 +#endif
8515 +
8516 /*
8517 * Clear the bytes not touched by the fxsave and reserved
8518 * for the SW usage.
8519 @@ -213,13 +223,8 @@ static inline void fpu_fxsave(struct fpu *fpu)
8520 #endif /* CONFIG_X86_64 */
8521
8522 /* We need a safe address that is cheap to find and that is already
8523 - in L1 during context switch. The best choices are unfortunately
8524 - different for UP and SMP */
8525 -#ifdef CONFIG_SMP
8526 -#define safe_address (__per_cpu_offset[0])
8527 -#else
8528 -#define safe_address (kstat_cpu(0).cpustat.user)
8529 -#endif
8530 + in L1 during context switch. */
8531 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
8532
8533 /*
8534 * These must be called with preempt disabled
8535 @@ -312,7 +317,7 @@ static inline void kernel_fpu_begin(void)
8536 struct thread_info *me = current_thread_info();
8537 preempt_disable();
8538 if (me->status & TS_USEDFPU)
8539 - __save_init_fpu(me->task);
8540 + __save_init_fpu(current);
8541 else
8542 clts();
8543 }
8544 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
8545 index d8e8eef..99f81ae 100644
8546 --- a/arch/x86/include/asm/io.h
8547 +++ b/arch/x86/include/asm/io.h
8548 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
8549
8550 #include <linux/vmalloc.h>
8551
8552 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
8553 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
8554 +{
8555 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8556 +}
8557 +
8558 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
8559 +{
8560 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8561 +}
8562 +
8563 /*
8564 * Convert a virtual cached pointer to an uncached pointer
8565 */
8566 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
8567 index bba3cf8..06bc8da 100644
8568 --- a/arch/x86/include/asm/irqflags.h
8569 +++ b/arch/x86/include/asm/irqflags.h
8570 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
8571 sti; \
8572 sysexit
8573
8574 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
8575 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
8576 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
8577 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
8578 +
8579 #else
8580 #define INTERRUPT_RETURN iret
8581 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
8582 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
8583 index 5478825..839e88c 100644
8584 --- a/arch/x86/include/asm/kprobes.h
8585 +++ b/arch/x86/include/asm/kprobes.h
8586 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
8587 #define RELATIVEJUMP_SIZE 5
8588 #define RELATIVECALL_OPCODE 0xe8
8589 #define RELATIVE_ADDR_SIZE 4
8590 -#define MAX_STACK_SIZE 64
8591 -#define MIN_STACK_SIZE(ADDR) \
8592 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
8593 - THREAD_SIZE - (unsigned long)(ADDR))) \
8594 - ? (MAX_STACK_SIZE) \
8595 - : (((unsigned long)current_thread_info()) + \
8596 - THREAD_SIZE - (unsigned long)(ADDR)))
8597 +#define MAX_STACK_SIZE 64UL
8598 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
8599
8600 #define flush_insn_slot(p) do { } while (0)
8601
8602 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
8603 index dd51c83..66cbfac 100644
8604 --- a/arch/x86/include/asm/kvm_host.h
8605 +++ b/arch/x86/include/asm/kvm_host.h
8606 @@ -456,7 +456,7 @@ struct kvm_arch {
8607 unsigned int n_requested_mmu_pages;
8608 unsigned int n_max_mmu_pages;
8609 unsigned int indirect_shadow_pages;
8610 - atomic_t invlpg_counter;
8611 + atomic_unchecked_t invlpg_counter;
8612 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
8613 /*
8614 * Hash table of struct kvm_mmu_page.
8615 @@ -636,7 +636,7 @@ struct kvm_x86_ops {
8616 enum x86_intercept_stage stage);
8617
8618 const struct trace_print_flags *exit_reasons_str;
8619 -};
8620 +} __do_const;
8621
8622 struct kvm_arch_async_pf {
8623 u32 token;
8624 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
8625 index 9cdae5d..300d20f 100644
8626 --- a/arch/x86/include/asm/local.h
8627 +++ b/arch/x86/include/asm/local.h
8628 @@ -18,26 +18,58 @@ typedef struct {
8629
8630 static inline void local_inc(local_t *l)
8631 {
8632 - asm volatile(_ASM_INC "%0"
8633 + asm volatile(_ASM_INC "%0\n"
8634 +
8635 +#ifdef CONFIG_PAX_REFCOUNT
8636 + "jno 0f\n"
8637 + _ASM_DEC "%0\n"
8638 + "int $4\n0:\n"
8639 + _ASM_EXTABLE(0b, 0b)
8640 +#endif
8641 +
8642 : "+m" (l->a.counter));
8643 }
8644
8645 static inline void local_dec(local_t *l)
8646 {
8647 - asm volatile(_ASM_DEC "%0"
8648 + asm volatile(_ASM_DEC "%0\n"
8649 +
8650 +#ifdef CONFIG_PAX_REFCOUNT
8651 + "jno 0f\n"
8652 + _ASM_INC "%0\n"
8653 + "int $4\n0:\n"
8654 + _ASM_EXTABLE(0b, 0b)
8655 +#endif
8656 +
8657 : "+m" (l->a.counter));
8658 }
8659
8660 static inline void local_add(long i, local_t *l)
8661 {
8662 - asm volatile(_ASM_ADD "%1,%0"
8663 + asm volatile(_ASM_ADD "%1,%0\n"
8664 +
8665 +#ifdef CONFIG_PAX_REFCOUNT
8666 + "jno 0f\n"
8667 + _ASM_SUB "%1,%0\n"
8668 + "int $4\n0:\n"
8669 + _ASM_EXTABLE(0b, 0b)
8670 +#endif
8671 +
8672 : "+m" (l->a.counter)
8673 : "ir" (i));
8674 }
8675
8676 static inline void local_sub(long i, local_t *l)
8677 {
8678 - asm volatile(_ASM_SUB "%1,%0"
8679 + asm volatile(_ASM_SUB "%1,%0\n"
8680 +
8681 +#ifdef CONFIG_PAX_REFCOUNT
8682 + "jno 0f\n"
8683 + _ASM_ADD "%1,%0\n"
8684 + "int $4\n0:\n"
8685 + _ASM_EXTABLE(0b, 0b)
8686 +#endif
8687 +
8688 : "+m" (l->a.counter)
8689 : "ir" (i));
8690 }
8691 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
8692 {
8693 unsigned char c;
8694
8695 - asm volatile(_ASM_SUB "%2,%0; sete %1"
8696 + asm volatile(_ASM_SUB "%2,%0\n"
8697 +
8698 +#ifdef CONFIG_PAX_REFCOUNT
8699 + "jno 0f\n"
8700 + _ASM_ADD "%2,%0\n"
8701 + "int $4\n0:\n"
8702 + _ASM_EXTABLE(0b, 0b)
8703 +#endif
8704 +
8705 + "sete %1\n"
8706 : "+m" (l->a.counter), "=qm" (c)
8707 : "ir" (i) : "memory");
8708 return c;
8709 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
8710 {
8711 unsigned char c;
8712
8713 - asm volatile(_ASM_DEC "%0; sete %1"
8714 + asm volatile(_ASM_DEC "%0\n"
8715 +
8716 +#ifdef CONFIG_PAX_REFCOUNT
8717 + "jno 0f\n"
8718 + _ASM_INC "%0\n"
8719 + "int $4\n0:\n"
8720 + _ASM_EXTABLE(0b, 0b)
8721 +#endif
8722 +
8723 + "sete %1\n"
8724 : "+m" (l->a.counter), "=qm" (c)
8725 : : "memory");
8726 return c != 0;
8727 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
8728 {
8729 unsigned char c;
8730
8731 - asm volatile(_ASM_INC "%0; sete %1"
8732 + asm volatile(_ASM_INC "%0\n"
8733 +
8734 +#ifdef CONFIG_PAX_REFCOUNT
8735 + "jno 0f\n"
8736 + _ASM_DEC "%0\n"
8737 + "int $4\n0:\n"
8738 + _ASM_EXTABLE(0b, 0b)
8739 +#endif
8740 +
8741 + "sete %1\n"
8742 : "+m" (l->a.counter), "=qm" (c)
8743 : : "memory");
8744 return c != 0;
8745 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
8746 {
8747 unsigned char c;
8748
8749 - asm volatile(_ASM_ADD "%2,%0; sets %1"
8750 + asm volatile(_ASM_ADD "%2,%0\n"
8751 +
8752 +#ifdef CONFIG_PAX_REFCOUNT
8753 + "jno 0f\n"
8754 + _ASM_SUB "%2,%0\n"
8755 + "int $4\n0:\n"
8756 + _ASM_EXTABLE(0b, 0b)
8757 +#endif
8758 +
8759 + "sets %1\n"
8760 : "+m" (l->a.counter), "=qm" (c)
8761 : "ir" (i) : "memory");
8762 return c;
8763 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
8764 #endif
8765 /* Modern 486+ processor */
8766 __i = i;
8767 - asm volatile(_ASM_XADD "%0, %1;"
8768 + asm volatile(_ASM_XADD "%0, %1\n"
8769 +
8770 +#ifdef CONFIG_PAX_REFCOUNT
8771 + "jno 0f\n"
8772 + _ASM_MOV "%0,%1\n"
8773 + "int $4\n0:\n"
8774 + _ASM_EXTABLE(0b, 0b)
8775 +#endif
8776 +
8777 : "+r" (i), "+m" (l->a.counter)
8778 : : "memory");
8779 return i + __i;
8780 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
8781 index 593e51d..fa69c9a 100644
8782 --- a/arch/x86/include/asm/mman.h
8783 +++ b/arch/x86/include/asm/mman.h
8784 @@ -5,4 +5,14 @@
8785
8786 #include <asm-generic/mman.h>
8787
8788 +#ifdef __KERNEL__
8789 +#ifndef __ASSEMBLY__
8790 +#ifdef CONFIG_X86_32
8791 +#define arch_mmap_check i386_mmap_check
8792 +int i386_mmap_check(unsigned long addr, unsigned long len,
8793 + unsigned long flags);
8794 +#endif
8795 +#endif
8796 +#endif
8797 +
8798 #endif /* _ASM_X86_MMAN_H */
8799 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
8800 index 5f55e69..e20bfb1 100644
8801 --- a/arch/x86/include/asm/mmu.h
8802 +++ b/arch/x86/include/asm/mmu.h
8803 @@ -9,7 +9,7 @@
8804 * we put the segment information here.
8805 */
8806 typedef struct {
8807 - void *ldt;
8808 + struct desc_struct *ldt;
8809 int size;
8810
8811 #ifdef CONFIG_X86_64
8812 @@ -18,7 +18,19 @@ typedef struct {
8813 #endif
8814
8815 struct mutex lock;
8816 - void *vdso;
8817 + unsigned long vdso;
8818 +
8819 +#ifdef CONFIG_X86_32
8820 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
8821 + unsigned long user_cs_base;
8822 + unsigned long user_cs_limit;
8823 +
8824 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
8825 + cpumask_t cpu_user_cs_mask;
8826 +#endif
8827 +
8828 +#endif
8829 +#endif
8830 } mm_context_t;
8831
8832 #ifdef CONFIG_SMP
8833 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
8834 index 6902152..399f3a2 100644
8835 --- a/arch/x86/include/asm/mmu_context.h
8836 +++ b/arch/x86/include/asm/mmu_context.h
8837 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
8838
8839 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
8840 {
8841 +
8842 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8843 + unsigned int i;
8844 + pgd_t *pgd;
8845 +
8846 + pax_open_kernel();
8847 + pgd = get_cpu_pgd(smp_processor_id());
8848 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
8849 + set_pgd_batched(pgd+i, native_make_pgd(0));
8850 + pax_close_kernel();
8851 +#endif
8852 +
8853 #ifdef CONFIG_SMP
8854 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
8855 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
8856 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
8857 struct task_struct *tsk)
8858 {
8859 unsigned cpu = smp_processor_id();
8860 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
8861 + int tlbstate = TLBSTATE_OK;
8862 +#endif
8863
8864 if (likely(prev != next)) {
8865 #ifdef CONFIG_SMP
8866 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
8867 + tlbstate = percpu_read(cpu_tlbstate.state);
8868 +#endif
8869 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
8870 percpu_write(cpu_tlbstate.active_mm, next);
8871 #endif
8872 cpumask_set_cpu(cpu, mm_cpumask(next));
8873
8874 /* Re-load page tables */
8875 +#ifdef CONFIG_PAX_PER_CPU_PGD
8876 + pax_open_kernel();
8877 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
8878 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
8879 + pax_close_kernel();
8880 + load_cr3(get_cpu_pgd(cpu));
8881 +#else
8882 load_cr3(next->pgd);
8883 +#endif
8884
8885 /* stop flush ipis for the previous mm */
8886 cpumask_clear_cpu(cpu, mm_cpumask(prev));
8887 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
8888 */
8889 if (unlikely(prev->context.ldt != next->context.ldt))
8890 load_LDT_nolock(&next->context);
8891 - }
8892 +
8893 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
8894 + if (!(__supported_pte_mask & _PAGE_NX)) {
8895 + smp_mb__before_clear_bit();
8896 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
8897 + smp_mb__after_clear_bit();
8898 + cpu_set(cpu, next->context.cpu_user_cs_mask);
8899 + }
8900 +#endif
8901 +
8902 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
8903 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
8904 + prev->context.user_cs_limit != next->context.user_cs_limit))
8905 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8906 #ifdef CONFIG_SMP
8907 + else if (unlikely(tlbstate != TLBSTATE_OK))
8908 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8909 +#endif
8910 +#endif
8911 +
8912 + }
8913 else {
8914 +
8915 +#ifdef CONFIG_PAX_PER_CPU_PGD
8916 + pax_open_kernel();
8917 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
8918 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
8919 + pax_close_kernel();
8920 + load_cr3(get_cpu_pgd(cpu));
8921 +#endif
8922 +
8923 +#ifdef CONFIG_SMP
8924 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
8925 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
8926
8927 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
8928 * tlb flush IPI delivery. We must reload CR3
8929 * to make sure to use no freed page tables.
8930 */
8931 +
8932 +#ifndef CONFIG_PAX_PER_CPU_PGD
8933 load_cr3(next->pgd);
8934 +#endif
8935 +
8936 load_LDT_nolock(&next->context);
8937 +
8938 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
8939 + if (!(__supported_pte_mask & _PAGE_NX))
8940 + cpu_set(cpu, next->context.cpu_user_cs_mask);
8941 +#endif
8942 +
8943 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
8944 +#ifdef CONFIG_PAX_PAGEEXEC
8945 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
8946 +#endif
8947 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8948 +#endif
8949 +
8950 }
8951 +#endif
8952 }
8953 -#endif
8954 }
8955
8956 #define activate_mm(prev, next) \
8957 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
8958 index 9eae775..c914fea 100644
8959 --- a/arch/x86/include/asm/module.h
8960 +++ b/arch/x86/include/asm/module.h
8961 @@ -5,6 +5,7 @@
8962
8963 #ifdef CONFIG_X86_64
8964 /* X86_64 does not define MODULE_PROC_FAMILY */
8965 +#define MODULE_PROC_FAMILY ""
8966 #elif defined CONFIG_M386
8967 #define MODULE_PROC_FAMILY "386 "
8968 #elif defined CONFIG_M486
8969 @@ -59,8 +60,20 @@
8970 #error unknown processor family
8971 #endif
8972
8973 -#ifdef CONFIG_X86_32
8974 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
8975 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8976 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
8977 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
8978 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
8979 +#else
8980 +#define MODULE_PAX_KERNEXEC ""
8981 #endif
8982
8983 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8984 +#define MODULE_PAX_UDEREF "UDEREF "
8985 +#else
8986 +#define MODULE_PAX_UDEREF ""
8987 +#endif
8988 +
8989 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
8990 +
8991 #endif /* _ASM_X86_MODULE_H */
8992 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
8993 index 7639dbf..e08a58c 100644
8994 --- a/arch/x86/include/asm/page_64_types.h
8995 +++ b/arch/x86/include/asm/page_64_types.h
8996 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
8997
8998 /* duplicated to the one in bootmem.h */
8999 extern unsigned long max_pfn;
9000 -extern unsigned long phys_base;
9001 +extern const unsigned long phys_base;
9002
9003 extern unsigned long __phys_addr(unsigned long);
9004 #define __phys_reloc_hide(x) (x)
9005 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
9006 index a7d2db9..edb023e 100644
9007 --- a/arch/x86/include/asm/paravirt.h
9008 +++ b/arch/x86/include/asm/paravirt.h
9009 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
9010 val);
9011 }
9012
9013 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
9014 +{
9015 + pgdval_t val = native_pgd_val(pgd);
9016 +
9017 + if (sizeof(pgdval_t) > sizeof(long))
9018 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
9019 + val, (u64)val >> 32);
9020 + else
9021 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
9022 + val);
9023 +}
9024 +
9025 static inline void pgd_clear(pgd_t *pgdp)
9026 {
9027 set_pgd(pgdp, __pgd(0));
9028 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
9029 pv_mmu_ops.set_fixmap(idx, phys, flags);
9030 }
9031
9032 +#ifdef CONFIG_PAX_KERNEXEC
9033 +static inline unsigned long pax_open_kernel(void)
9034 +{
9035 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
9036 +}
9037 +
9038 +static inline unsigned long pax_close_kernel(void)
9039 +{
9040 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
9041 +}
9042 +#else
9043 +static inline unsigned long pax_open_kernel(void) { return 0; }
9044 +static inline unsigned long pax_close_kernel(void) { return 0; }
9045 +#endif
9046 +
9047 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
9048
9049 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
9050 @@ -964,7 +991,7 @@ extern void default_banner(void);
9051
9052 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
9053 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
9054 -#define PARA_INDIRECT(addr) *%cs:addr
9055 +#define PARA_INDIRECT(addr) *%ss:addr
9056 #endif
9057
9058 #define INTERRUPT_RETURN \
9059 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
9060 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
9061 CLBR_NONE, \
9062 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
9063 +
9064 +#define GET_CR0_INTO_RDI \
9065 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
9066 + mov %rax,%rdi
9067 +
9068 +#define SET_RDI_INTO_CR0 \
9069 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
9070 +
9071 +#define GET_CR3_INTO_RDI \
9072 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
9073 + mov %rax,%rdi
9074 +
9075 +#define SET_RDI_INTO_CR3 \
9076 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
9077 +
9078 #endif /* CONFIG_X86_32 */
9079
9080 #endif /* __ASSEMBLY__ */
9081 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
9082 index 8e8b9a4..f07d725 100644
9083 --- a/arch/x86/include/asm/paravirt_types.h
9084 +++ b/arch/x86/include/asm/paravirt_types.h
9085 @@ -84,20 +84,20 @@ struct pv_init_ops {
9086 */
9087 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
9088 unsigned long addr, unsigned len);
9089 -};
9090 +} __no_const;
9091
9092
9093 struct pv_lazy_ops {
9094 /* Set deferred update mode, used for batching operations. */
9095 void (*enter)(void);
9096 void (*leave)(void);
9097 -};
9098 +} __no_const;
9099
9100 struct pv_time_ops {
9101 unsigned long long (*sched_clock)(void);
9102 unsigned long long (*steal_clock)(int cpu);
9103 unsigned long (*get_tsc_khz)(void);
9104 -};
9105 +} __no_const;
9106
9107 struct pv_cpu_ops {
9108 /* hooks for various privileged instructions */
9109 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
9110
9111 void (*start_context_switch)(struct task_struct *prev);
9112 void (*end_context_switch)(struct task_struct *next);
9113 -};
9114 +} __no_const;
9115
9116 struct pv_irq_ops {
9117 /*
9118 @@ -224,7 +224,7 @@ struct pv_apic_ops {
9119 unsigned long start_eip,
9120 unsigned long start_esp);
9121 #endif
9122 -};
9123 +} __no_const;
9124
9125 struct pv_mmu_ops {
9126 unsigned long (*read_cr2)(void);
9127 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
9128 struct paravirt_callee_save make_pud;
9129
9130 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
9131 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
9132 #endif /* PAGETABLE_LEVELS == 4 */
9133 #endif /* PAGETABLE_LEVELS >= 3 */
9134
9135 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
9136 an mfn. We can tell which is which from the index. */
9137 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
9138 phys_addr_t phys, pgprot_t flags);
9139 +
9140 +#ifdef CONFIG_PAX_KERNEXEC
9141 + unsigned long (*pax_open_kernel)(void);
9142 + unsigned long (*pax_close_kernel)(void);
9143 +#endif
9144 +
9145 };
9146
9147 struct arch_spinlock;
9148 @@ -334,7 +341,7 @@ struct pv_lock_ops {
9149 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
9150 int (*spin_trylock)(struct arch_spinlock *lock);
9151 void (*spin_unlock)(struct arch_spinlock *lock);
9152 -};
9153 +} __no_const;
9154
9155 /* This contains all the paravirt structures: we get a convenient
9156 * number for each function using the offset which we use to indicate
9157 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
9158 index b4389a4..b7ff22c 100644
9159 --- a/arch/x86/include/asm/pgalloc.h
9160 +++ b/arch/x86/include/asm/pgalloc.h
9161 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
9162 pmd_t *pmd, pte_t *pte)
9163 {
9164 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
9165 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
9166 +}
9167 +
9168 +static inline void pmd_populate_user(struct mm_struct *mm,
9169 + pmd_t *pmd, pte_t *pte)
9170 +{
9171 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
9172 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
9173 }
9174
9175 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
9176 index 98391db..8f6984e 100644
9177 --- a/arch/x86/include/asm/pgtable-2level.h
9178 +++ b/arch/x86/include/asm/pgtable-2level.h
9179 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
9180
9181 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9182 {
9183 + pax_open_kernel();
9184 *pmdp = pmd;
9185 + pax_close_kernel();
9186 }
9187
9188 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9189 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
9190 index effff47..f9e4035 100644
9191 --- a/arch/x86/include/asm/pgtable-3level.h
9192 +++ b/arch/x86/include/asm/pgtable-3level.h
9193 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9194
9195 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9196 {
9197 + pax_open_kernel();
9198 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
9199 + pax_close_kernel();
9200 }
9201
9202 static inline void native_set_pud(pud_t *pudp, pud_t pud)
9203 {
9204 + pax_open_kernel();
9205 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
9206 + pax_close_kernel();
9207 }
9208
9209 /*
9210 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
9211 index 18601c8..3d716d1 100644
9212 --- a/arch/x86/include/asm/pgtable.h
9213 +++ b/arch/x86/include/asm/pgtable.h
9214 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
9215
9216 #ifndef __PAGETABLE_PUD_FOLDED
9217 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
9218 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
9219 #define pgd_clear(pgd) native_pgd_clear(pgd)
9220 #endif
9221
9222 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
9223
9224 #define arch_end_context_switch(prev) do {} while(0)
9225
9226 +#define pax_open_kernel() native_pax_open_kernel()
9227 +#define pax_close_kernel() native_pax_close_kernel()
9228 #endif /* CONFIG_PARAVIRT */
9229
9230 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
9231 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
9232 +
9233 +#ifdef CONFIG_PAX_KERNEXEC
9234 +static inline unsigned long native_pax_open_kernel(void)
9235 +{
9236 + unsigned long cr0;
9237 +
9238 + preempt_disable();
9239 + barrier();
9240 + cr0 = read_cr0() ^ X86_CR0_WP;
9241 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
9242 + write_cr0(cr0);
9243 + return cr0 ^ X86_CR0_WP;
9244 +}
9245 +
9246 +static inline unsigned long native_pax_close_kernel(void)
9247 +{
9248 + unsigned long cr0;
9249 +
9250 + cr0 = read_cr0() ^ X86_CR0_WP;
9251 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
9252 + write_cr0(cr0);
9253 + barrier();
9254 + preempt_enable_no_resched();
9255 + return cr0 ^ X86_CR0_WP;
9256 +}
9257 +#else
9258 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
9259 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
9260 +#endif
9261 +
9262 /*
9263 * The following only work if pte_present() is true.
9264 * Undefined behaviour if not..
9265 */
9266 +static inline int pte_user(pte_t pte)
9267 +{
9268 + return pte_val(pte) & _PAGE_USER;
9269 +}
9270 +
9271 static inline int pte_dirty(pte_t pte)
9272 {
9273 return pte_flags(pte) & _PAGE_DIRTY;
9274 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
9275 return pte_clear_flags(pte, _PAGE_RW);
9276 }
9277
9278 +static inline pte_t pte_mkread(pte_t pte)
9279 +{
9280 + return __pte(pte_val(pte) | _PAGE_USER);
9281 +}
9282 +
9283 static inline pte_t pte_mkexec(pte_t pte)
9284 {
9285 - return pte_clear_flags(pte, _PAGE_NX);
9286 +#ifdef CONFIG_X86_PAE
9287 + if (__supported_pte_mask & _PAGE_NX)
9288 + return pte_clear_flags(pte, _PAGE_NX);
9289 + else
9290 +#endif
9291 + return pte_set_flags(pte, _PAGE_USER);
9292 +}
9293 +
9294 +static inline pte_t pte_exprotect(pte_t pte)
9295 +{
9296 +#ifdef CONFIG_X86_PAE
9297 + if (__supported_pte_mask & _PAGE_NX)
9298 + return pte_set_flags(pte, _PAGE_NX);
9299 + else
9300 +#endif
9301 + return pte_clear_flags(pte, _PAGE_USER);
9302 }
9303
9304 static inline pte_t pte_mkdirty(pte_t pte)
9305 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
9306 #endif
9307
9308 #ifndef __ASSEMBLY__
9309 +
9310 +#ifdef CONFIG_PAX_PER_CPU_PGD
9311 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
9312 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
9313 +{
9314 + return cpu_pgd[cpu];
9315 +}
9316 +#endif
9317 +
9318 #include <linux/mm_types.h>
9319
9320 static inline int pte_none(pte_t pte)
9321 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
9322
9323 static inline int pgd_bad(pgd_t pgd)
9324 {
9325 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
9326 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
9327 }
9328
9329 static inline int pgd_none(pgd_t pgd)
9330 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
9331 * pgd_offset() returns a (pgd_t *)
9332 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
9333 */
9334 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
9335 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
9336 +
9337 +#ifdef CONFIG_PAX_PER_CPU_PGD
9338 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
9339 +#endif
9340 +
9341 /*
9342 * a shortcut which implies the use of the kernel's pgd, instead
9343 * of a process's
9344 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
9345 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
9346 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
9347
9348 +#ifdef CONFIG_X86_32
9349 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
9350 +#else
9351 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
9352 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
9353 +
9354 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9355 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
9356 +#else
9357 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
9358 +#endif
9359 +
9360 +#endif
9361 +
9362 #ifndef __ASSEMBLY__
9363
9364 extern int direct_gbpages;
9365 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
9366 * dst and src can be on the same page, but the range must not overlap,
9367 * and must not cross a page boundary.
9368 */
9369 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
9370 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
9371 {
9372 - memcpy(dst, src, count * sizeof(pgd_t));
9373 + pax_open_kernel();
9374 + while (count--)
9375 + *dst++ = *src++;
9376 + pax_close_kernel();
9377 }
9378
9379 +#ifdef CONFIG_PAX_PER_CPU_PGD
9380 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9381 +#endif
9382 +
9383 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9384 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9385 +#else
9386 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
9387 +#endif
9388
9389 #include <asm-generic/pgtable.h>
9390 #endif /* __ASSEMBLY__ */
9391 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
9392 index 0c92113..34a77c6 100644
9393 --- a/arch/x86/include/asm/pgtable_32.h
9394 +++ b/arch/x86/include/asm/pgtable_32.h
9395 @@ -25,9 +25,6 @@
9396 struct mm_struct;
9397 struct vm_area_struct;
9398
9399 -extern pgd_t swapper_pg_dir[1024];
9400 -extern pgd_t initial_page_table[1024];
9401 -
9402 static inline void pgtable_cache_init(void) { }
9403 static inline void check_pgt_cache(void) { }
9404 void paging_init(void);
9405 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
9406 # include <asm/pgtable-2level.h>
9407 #endif
9408
9409 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
9410 +extern pgd_t initial_page_table[PTRS_PER_PGD];
9411 +#ifdef CONFIG_X86_PAE
9412 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
9413 +#endif
9414 +
9415 #if defined(CONFIG_HIGHPTE)
9416 #define pte_offset_map(dir, address) \
9417 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
9418 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
9419 /* Clear a kernel PTE and flush it from the TLB */
9420 #define kpte_clear_flush(ptep, vaddr) \
9421 do { \
9422 + pax_open_kernel(); \
9423 pte_clear(&init_mm, (vaddr), (ptep)); \
9424 + pax_close_kernel(); \
9425 __flush_tlb_one((vaddr)); \
9426 } while (0)
9427
9428 @@ -74,6 +79,9 @@ do { \
9429
9430 #endif /* !__ASSEMBLY__ */
9431
9432 +#define HAVE_ARCH_UNMAPPED_AREA
9433 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
9434 +
9435 /*
9436 * kern_addr_valid() is (1) for FLATMEM and (0) for
9437 * SPARSEMEM and DISCONTIGMEM
9438 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
9439 index ed5903b..c7fe163 100644
9440 --- a/arch/x86/include/asm/pgtable_32_types.h
9441 +++ b/arch/x86/include/asm/pgtable_32_types.h
9442 @@ -8,7 +8,7 @@
9443 */
9444 #ifdef CONFIG_X86_PAE
9445 # include <asm/pgtable-3level_types.h>
9446 -# define PMD_SIZE (1UL << PMD_SHIFT)
9447 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
9448 # define PMD_MASK (~(PMD_SIZE - 1))
9449 #else
9450 # include <asm/pgtable-2level_types.h>
9451 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
9452 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
9453 #endif
9454
9455 +#ifdef CONFIG_PAX_KERNEXEC
9456 +#ifndef __ASSEMBLY__
9457 +extern unsigned char MODULES_EXEC_VADDR[];
9458 +extern unsigned char MODULES_EXEC_END[];
9459 +#endif
9460 +#include <asm/boot.h>
9461 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
9462 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
9463 +#else
9464 +#define ktla_ktva(addr) (addr)
9465 +#define ktva_ktla(addr) (addr)
9466 +#endif
9467 +
9468 #define MODULES_VADDR VMALLOC_START
9469 #define MODULES_END VMALLOC_END
9470 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
9471 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
9472 index 975f709..107976d 100644
9473 --- a/arch/x86/include/asm/pgtable_64.h
9474 +++ b/arch/x86/include/asm/pgtable_64.h
9475 @@ -16,10 +16,14 @@
9476
9477 extern pud_t level3_kernel_pgt[512];
9478 extern pud_t level3_ident_pgt[512];
9479 +extern pud_t level3_vmalloc_start_pgt[512];
9480 +extern pud_t level3_vmalloc_end_pgt[512];
9481 +extern pud_t level3_vmemmap_pgt[512];
9482 +extern pud_t level2_vmemmap_pgt[512];
9483 extern pmd_t level2_kernel_pgt[512];
9484 extern pmd_t level2_fixmap_pgt[512];
9485 -extern pmd_t level2_ident_pgt[512];
9486 -extern pgd_t init_level4_pgt[];
9487 +extern pmd_t level2_ident_pgt[512*2];
9488 +extern pgd_t init_level4_pgt[512];
9489
9490 #define swapper_pg_dir init_level4_pgt
9491
9492 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9493
9494 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9495 {
9496 + pax_open_kernel();
9497 *pmdp = pmd;
9498 + pax_close_kernel();
9499 }
9500
9501 static inline void native_pmd_clear(pmd_t *pmd)
9502 @@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
9503
9504 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
9505 {
9506 + pax_open_kernel();
9507 + *pgdp = pgd;
9508 + pax_close_kernel();
9509 +}
9510 +
9511 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
9512 +{
9513 *pgdp = pgd;
9514 }
9515
9516 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
9517 index 766ea16..5b96cb3 100644
9518 --- a/arch/x86/include/asm/pgtable_64_types.h
9519 +++ b/arch/x86/include/asm/pgtable_64_types.h
9520 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
9521 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
9522 #define MODULES_END _AC(0xffffffffff000000, UL)
9523 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
9524 +#define MODULES_EXEC_VADDR MODULES_VADDR
9525 +#define MODULES_EXEC_END MODULES_END
9526 +
9527 +#define ktla_ktva(addr) (addr)
9528 +#define ktva_ktla(addr) (addr)
9529
9530 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
9531 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
9532 index 013286a..8b42f4f 100644
9533 --- a/arch/x86/include/asm/pgtable_types.h
9534 +++ b/arch/x86/include/asm/pgtable_types.h
9535 @@ -16,13 +16,12 @@
9536 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
9537 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
9538 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
9539 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
9540 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
9541 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
9542 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
9543 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
9544 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
9545 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
9546 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
9547 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
9548 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
9549 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
9550
9551 /* If _PAGE_BIT_PRESENT is clear, we use these: */
9552 @@ -40,7 +39,6 @@
9553 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
9554 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
9555 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
9556 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
9557 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
9558 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
9559 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
9560 @@ -57,8 +55,10 @@
9561
9562 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
9563 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
9564 -#else
9565 +#elif defined(CONFIG_KMEMCHECK)
9566 #define _PAGE_NX (_AT(pteval_t, 0))
9567 +#else
9568 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
9569 #endif
9570
9571 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
9572 @@ -96,6 +96,9 @@
9573 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
9574 _PAGE_ACCESSED)
9575
9576 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
9577 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
9578 +
9579 #define __PAGE_KERNEL_EXEC \
9580 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
9581 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
9582 @@ -106,7 +109,7 @@
9583 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
9584 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
9585 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
9586 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
9587 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
9588 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
9589 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
9590 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
9591 @@ -168,8 +171,8 @@
9592 * bits are combined, this will alow user to access the high address mapped
9593 * VDSO in the presence of CONFIG_COMPAT_VDSO
9594 */
9595 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
9596 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
9597 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9598 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9599 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
9600 #endif
9601
9602 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
9603 {
9604 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
9605 }
9606 +#endif
9607
9608 +#if PAGETABLE_LEVELS == 3
9609 +#include <asm-generic/pgtable-nopud.h>
9610 +#endif
9611 +
9612 +#if PAGETABLE_LEVELS == 2
9613 +#include <asm-generic/pgtable-nopmd.h>
9614 +#endif
9615 +
9616 +#ifndef __ASSEMBLY__
9617 #if PAGETABLE_LEVELS > 3
9618 typedef struct { pudval_t pud; } pud_t;
9619
9620 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
9621 return pud.pud;
9622 }
9623 #else
9624 -#include <asm-generic/pgtable-nopud.h>
9625 -
9626 static inline pudval_t native_pud_val(pud_t pud)
9627 {
9628 return native_pgd_val(pud.pgd);
9629 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
9630 return pmd.pmd;
9631 }
9632 #else
9633 -#include <asm-generic/pgtable-nopmd.h>
9634 -
9635 static inline pmdval_t native_pmd_val(pmd_t pmd)
9636 {
9637 return native_pgd_val(pmd.pud.pgd);
9638 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
9639
9640 extern pteval_t __supported_pte_mask;
9641 extern void set_nx(void);
9642 -extern int nx_enabled;
9643
9644 #define pgprot_writecombine pgprot_writecombine
9645 extern pgprot_t pgprot_writecombine(pgprot_t prot);
9646 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
9647 index 0d1171c..36571a9 100644
9648 --- a/arch/x86/include/asm/processor.h
9649 +++ b/arch/x86/include/asm/processor.h
9650 @@ -266,7 +266,7 @@ struct tss_struct {
9651
9652 } ____cacheline_aligned;
9653
9654 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
9655 +extern struct tss_struct init_tss[NR_CPUS];
9656
9657 /*
9658 * Save the original ist values for checking stack pointers during debugging
9659 @@ -858,11 +858,18 @@ static inline void spin_lock_prefetch(const void *x)
9660 */
9661 #define TASK_SIZE PAGE_OFFSET
9662 #define TASK_SIZE_MAX TASK_SIZE
9663 +
9664 +#ifdef CONFIG_PAX_SEGMEXEC
9665 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
9666 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
9667 +#else
9668 #define STACK_TOP TASK_SIZE
9669 -#define STACK_TOP_MAX STACK_TOP
9670 +#endif
9671 +
9672 +#define STACK_TOP_MAX TASK_SIZE
9673
9674 #define INIT_THREAD { \
9675 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
9676 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
9677 .vm86_info = NULL, \
9678 .sysenter_cs = __KERNEL_CS, \
9679 .io_bitmap_ptr = NULL, \
9680 @@ -876,7 +883,7 @@ static inline void spin_lock_prefetch(const void *x)
9681 */
9682 #define INIT_TSS { \
9683 .x86_tss = { \
9684 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
9685 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
9686 .ss0 = __KERNEL_DS, \
9687 .ss1 = __KERNEL_CS, \
9688 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
9689 @@ -887,11 +894,7 @@ static inline void spin_lock_prefetch(const void *x)
9690 extern unsigned long thread_saved_pc(struct task_struct *tsk);
9691
9692 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
9693 -#define KSTK_TOP(info) \
9694 -({ \
9695 - unsigned long *__ptr = (unsigned long *)(info); \
9696 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
9697 -})
9698 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
9699
9700 /*
9701 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
9702 @@ -906,7 +909,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
9703 #define task_pt_regs(task) \
9704 ({ \
9705 struct pt_regs *__regs__; \
9706 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
9707 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
9708 __regs__ - 1; \
9709 })
9710
9711 @@ -916,13 +919,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
9712 /*
9713 * User space process size. 47bits minus one guard page.
9714 */
9715 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
9716 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
9717
9718 /* This decides where the kernel will search for a free chunk of vm
9719 * space during mmap's.
9720 */
9721 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
9722 - 0xc0000000 : 0xFFFFe000)
9723 + 0xc0000000 : 0xFFFFf000)
9724
9725 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
9726 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
9727 @@ -933,11 +936,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
9728 #define STACK_TOP_MAX TASK_SIZE_MAX
9729
9730 #define INIT_THREAD { \
9731 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
9732 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
9733 }
9734
9735 #define INIT_TSS { \
9736 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
9737 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
9738 }
9739
9740 /*
9741 @@ -959,6 +962,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
9742 */
9743 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
9744
9745 +#ifdef CONFIG_PAX_SEGMEXEC
9746 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
9747 +#endif
9748 +
9749 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
9750
9751 /* Get/set a process' ability to use the timestamp counter instruction */
9752 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
9753 index 3566454..4bdfb8c 100644
9754 --- a/arch/x86/include/asm/ptrace.h
9755 +++ b/arch/x86/include/asm/ptrace.h
9756 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
9757 }
9758
9759 /*
9760 - * user_mode_vm(regs) determines whether a register set came from user mode.
9761 + * user_mode(regs) determines whether a register set came from user mode.
9762 * This is true if V8086 mode was enabled OR if the register set was from
9763 * protected mode with RPL-3 CS value. This tricky test checks that with
9764 * one comparison. Many places in the kernel can bypass this full check
9765 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
9766 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
9767 + * be used.
9768 */
9769 -static inline int user_mode(struct pt_regs *regs)
9770 +static inline int user_mode_novm(struct pt_regs *regs)
9771 {
9772 #ifdef CONFIG_X86_32
9773 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
9774 #else
9775 - return !!(regs->cs & 3);
9776 + return !!(regs->cs & SEGMENT_RPL_MASK);
9777 #endif
9778 }
9779
9780 -static inline int user_mode_vm(struct pt_regs *regs)
9781 +static inline int user_mode(struct pt_regs *regs)
9782 {
9783 #ifdef CONFIG_X86_32
9784 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
9785 USER_RPL;
9786 #else
9787 - return user_mode(regs);
9788 + return user_mode_novm(regs);
9789 #endif
9790 }
9791
9792 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
9793 #ifdef CONFIG_X86_64
9794 static inline bool user_64bit_mode(struct pt_regs *regs)
9795 {
9796 + unsigned long cs = regs->cs & 0xffff;
9797 #ifndef CONFIG_PARAVIRT
9798 /*
9799 * On non-paravirt systems, this is the only long mode CPL 3
9800 * selector. We do not allow long mode selectors in the LDT.
9801 */
9802 - return regs->cs == __USER_CS;
9803 + return cs == __USER_CS;
9804 #else
9805 /* Headers are too twisted for this to go in paravirt.h. */
9806 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
9807 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
9808 #endif
9809 }
9810 #endif
9811 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
9812 index 3250e3d..20db631 100644
9813 --- a/arch/x86/include/asm/reboot.h
9814 +++ b/arch/x86/include/asm/reboot.h
9815 @@ -6,19 +6,19 @@
9816 struct pt_regs;
9817
9818 struct machine_ops {
9819 - void (*restart)(char *cmd);
9820 - void (*halt)(void);
9821 - void (*power_off)(void);
9822 + void (* __noreturn restart)(char *cmd);
9823 + void (* __noreturn halt)(void);
9824 + void (* __noreturn power_off)(void);
9825 void (*shutdown)(void);
9826 void (*crash_shutdown)(struct pt_regs *);
9827 - void (*emergency_restart)(void);
9828 -};
9829 + void (* __noreturn emergency_restart)(void);
9830 +} __no_const;
9831
9832 extern struct machine_ops machine_ops;
9833
9834 void native_machine_crash_shutdown(struct pt_regs *regs);
9835 void native_machine_shutdown(void);
9836 -void machine_real_restart(unsigned int type);
9837 +void machine_real_restart(unsigned int type) __noreturn;
9838 /* These must match dispatch_table in reboot_32.S */
9839 #define MRR_BIOS 0
9840 #define MRR_APM 1
9841 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
9842 index df4cd32..27ae072 100644
9843 --- a/arch/x86/include/asm/rwsem.h
9844 +++ b/arch/x86/include/asm/rwsem.h
9845 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
9846 {
9847 asm volatile("# beginning down_read\n\t"
9848 LOCK_PREFIX _ASM_INC "(%1)\n\t"
9849 +
9850 +#ifdef CONFIG_PAX_REFCOUNT
9851 + "jno 0f\n"
9852 + LOCK_PREFIX _ASM_DEC "(%1)\n"
9853 + "int $4\n0:\n"
9854 + _ASM_EXTABLE(0b, 0b)
9855 +#endif
9856 +
9857 /* adds 0x00000001 */
9858 " jns 1f\n"
9859 " call call_rwsem_down_read_failed\n"
9860 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
9861 "1:\n\t"
9862 " mov %1,%2\n\t"
9863 " add %3,%2\n\t"
9864 +
9865 +#ifdef CONFIG_PAX_REFCOUNT
9866 + "jno 0f\n"
9867 + "sub %3,%2\n"
9868 + "int $4\n0:\n"
9869 + _ASM_EXTABLE(0b, 0b)
9870 +#endif
9871 +
9872 " jle 2f\n\t"
9873 LOCK_PREFIX " cmpxchg %2,%0\n\t"
9874 " jnz 1b\n\t"
9875 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
9876 long tmp;
9877 asm volatile("# beginning down_write\n\t"
9878 LOCK_PREFIX " xadd %1,(%2)\n\t"
9879 +
9880 +#ifdef CONFIG_PAX_REFCOUNT
9881 + "jno 0f\n"
9882 + "mov %1,(%2)\n"
9883 + "int $4\n0:\n"
9884 + _ASM_EXTABLE(0b, 0b)
9885 +#endif
9886 +
9887 /* adds 0xffff0001, returns the old value */
9888 " test %1,%1\n\t"
9889 /* was the count 0 before? */
9890 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
9891 long tmp;
9892 asm volatile("# beginning __up_read\n\t"
9893 LOCK_PREFIX " xadd %1,(%2)\n\t"
9894 +
9895 +#ifdef CONFIG_PAX_REFCOUNT
9896 + "jno 0f\n"
9897 + "mov %1,(%2)\n"
9898 + "int $4\n0:\n"
9899 + _ASM_EXTABLE(0b, 0b)
9900 +#endif
9901 +
9902 /* subtracts 1, returns the old value */
9903 " jns 1f\n\t"
9904 " call call_rwsem_wake\n" /* expects old value in %edx */
9905 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
9906 long tmp;
9907 asm volatile("# beginning __up_write\n\t"
9908 LOCK_PREFIX " xadd %1,(%2)\n\t"
9909 +
9910 +#ifdef CONFIG_PAX_REFCOUNT
9911 + "jno 0f\n"
9912 + "mov %1,(%2)\n"
9913 + "int $4\n0:\n"
9914 + _ASM_EXTABLE(0b, 0b)
9915 +#endif
9916 +
9917 /* subtracts 0xffff0001, returns the old value */
9918 " jns 1f\n\t"
9919 " call call_rwsem_wake\n" /* expects old value in %edx */
9920 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
9921 {
9922 asm volatile("# beginning __downgrade_write\n\t"
9923 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
9924 +
9925 +#ifdef CONFIG_PAX_REFCOUNT
9926 + "jno 0f\n"
9927 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
9928 + "int $4\n0:\n"
9929 + _ASM_EXTABLE(0b, 0b)
9930 +#endif
9931 +
9932 /*
9933 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
9934 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
9935 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
9936 */
9937 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
9938 {
9939 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
9940 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
9941 +
9942 +#ifdef CONFIG_PAX_REFCOUNT
9943 + "jno 0f\n"
9944 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
9945 + "int $4\n0:\n"
9946 + _ASM_EXTABLE(0b, 0b)
9947 +#endif
9948 +
9949 : "+m" (sem->count)
9950 : "er" (delta));
9951 }
9952 @@ -206,7 +262,15 @@ static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
9953 {
9954 long tmp = delta;
9955
9956 - asm volatile(LOCK_PREFIX "xadd %0,%1"
9957 + asm volatile(LOCK_PREFIX "xadd %0,%1\n"
9958 +
9959 +#ifdef CONFIG_PAX_REFCOUNT
9960 + "jno 0f\n"
9961 + "mov %0,%1\n"
9962 + "int $4\n0:\n"
9963 + _ASM_EXTABLE(0b, 0b)
9964 +#endif
9965 +
9966 : "+r" (tmp), "+m" (sem->count)
9967 : : "memory");
9968
9969 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
9970 index 5e64171..f58957e 100644
9971 --- a/arch/x86/include/asm/segment.h
9972 +++ b/arch/x86/include/asm/segment.h
9973 @@ -64,10 +64,15 @@
9974 * 26 - ESPFIX small SS
9975 * 27 - per-cpu [ offset to per-cpu data area ]
9976 * 28 - stack_canary-20 [ for stack protector ]
9977 - * 29 - unused
9978 - * 30 - unused
9979 + * 29 - PCI BIOS CS
9980 + * 30 - PCI BIOS DS
9981 * 31 - TSS for double fault handler
9982 */
9983 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
9984 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
9985 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
9986 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
9987 +
9988 #define GDT_ENTRY_TLS_MIN 6
9989 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
9990
9991 @@ -79,6 +84,8 @@
9992
9993 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
9994
9995 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
9996 +
9997 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
9998
9999 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
10000 @@ -104,6 +111,12 @@
10001 #define __KERNEL_STACK_CANARY 0
10002 #endif
10003
10004 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
10005 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
10006 +
10007 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
10008 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
10009 +
10010 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
10011
10012 /*
10013 @@ -141,7 +154,7 @@
10014 */
10015
10016 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
10017 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
10018 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
10019
10020
10021 #else
10022 @@ -165,6 +178,8 @@
10023 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
10024 #define __USER32_DS __USER_DS
10025
10026 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
10027 +
10028 #define GDT_ENTRY_TSS 8 /* needs two entries */
10029 #define GDT_ENTRY_LDT 10 /* needs two entries */
10030 #define GDT_ENTRY_TLS_MIN 12
10031 @@ -185,6 +200,7 @@
10032 #endif
10033
10034 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
10035 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
10036 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
10037 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
10038 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
10039 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
10040 index 73b11bc..d4a3b63 100644
10041 --- a/arch/x86/include/asm/smp.h
10042 +++ b/arch/x86/include/asm/smp.h
10043 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
10044 /* cpus sharing the last level cache: */
10045 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
10046 DECLARE_PER_CPU(u16, cpu_llc_id);
10047 -DECLARE_PER_CPU(int, cpu_number);
10048 +DECLARE_PER_CPU(unsigned int, cpu_number);
10049
10050 static inline struct cpumask *cpu_sibling_mask(int cpu)
10051 {
10052 @@ -77,7 +77,7 @@ struct smp_ops {
10053
10054 void (*send_call_func_ipi)(const struct cpumask *mask);
10055 void (*send_call_func_single_ipi)(int cpu);
10056 -};
10057 +} __no_const;
10058
10059 /* Globals due to paravirt */
10060 extern void set_cpu_sibling_map(int cpu);
10061 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
10062 extern int safe_smp_processor_id(void);
10063
10064 #elif defined(CONFIG_X86_64_SMP)
10065 -#define raw_smp_processor_id() (percpu_read(cpu_number))
10066 -
10067 -#define stack_smp_processor_id() \
10068 -({ \
10069 - struct thread_info *ti; \
10070 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
10071 - ti->cpu; \
10072 -})
10073 +#define raw_smp_processor_id() (percpu_read(cpu_number))
10074 +#define stack_smp_processor_id() raw_smp_processor_id()
10075 #define safe_smp_processor_id() smp_processor_id()
10076
10077 #endif
10078 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
10079 index ee67edf..49c796b 100644
10080 --- a/arch/x86/include/asm/spinlock.h
10081 +++ b/arch/x86/include/asm/spinlock.h
10082 @@ -248,6 +248,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
10083 static inline void arch_read_lock(arch_rwlock_t *rw)
10084 {
10085 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
10086 +
10087 +#ifdef CONFIG_PAX_REFCOUNT
10088 + "jno 0f\n"
10089 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
10090 + "int $4\n0:\n"
10091 + _ASM_EXTABLE(0b, 0b)
10092 +#endif
10093 +
10094 "jns 1f\n"
10095 "call __read_lock_failed\n\t"
10096 "1:\n"
10097 @@ -257,6 +265,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
10098 static inline void arch_write_lock(arch_rwlock_t *rw)
10099 {
10100 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
10101 +
10102 +#ifdef CONFIG_PAX_REFCOUNT
10103 + "jno 0f\n"
10104 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
10105 + "int $4\n0:\n"
10106 + _ASM_EXTABLE(0b, 0b)
10107 +#endif
10108 +
10109 "jz 1f\n"
10110 "call __write_lock_failed\n\t"
10111 "1:\n"
10112 @@ -286,13 +302,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
10113
10114 static inline void arch_read_unlock(arch_rwlock_t *rw)
10115 {
10116 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
10117 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
10118 +
10119 +#ifdef CONFIG_PAX_REFCOUNT
10120 + "jno 0f\n"
10121 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
10122 + "int $4\n0:\n"
10123 + _ASM_EXTABLE(0b, 0b)
10124 +#endif
10125 +
10126 :"+m" (rw->lock) : : "memory");
10127 }
10128
10129 static inline void arch_write_unlock(arch_rwlock_t *rw)
10130 {
10131 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
10132 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
10133 +
10134 +#ifdef CONFIG_PAX_REFCOUNT
10135 + "jno 0f\n"
10136 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
10137 + "int $4\n0:\n"
10138 + _ASM_EXTABLE(0b, 0b)
10139 +#endif
10140 +
10141 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
10142 }
10143
10144 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
10145 index 1575177..cb23f52 100644
10146 --- a/arch/x86/include/asm/stackprotector.h
10147 +++ b/arch/x86/include/asm/stackprotector.h
10148 @@ -48,7 +48,7 @@
10149 * head_32 for boot CPU and setup_per_cpu_areas() for others.
10150 */
10151 #define GDT_STACK_CANARY_INIT \
10152 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
10153 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
10154
10155 /*
10156 * Initialize the stackprotector canary value.
10157 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
10158
10159 static inline void load_stack_canary_segment(void)
10160 {
10161 -#ifdef CONFIG_X86_32
10162 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
10163 asm volatile ("mov %0, %%gs" : : "r" (0));
10164 #endif
10165 }
10166 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
10167 index 70bbe39..4ae2bd4 100644
10168 --- a/arch/x86/include/asm/stacktrace.h
10169 +++ b/arch/x86/include/asm/stacktrace.h
10170 @@ -11,28 +11,20 @@
10171
10172 extern int kstack_depth_to_print;
10173
10174 -struct thread_info;
10175 +struct task_struct;
10176 struct stacktrace_ops;
10177
10178 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
10179 - unsigned long *stack,
10180 - unsigned long bp,
10181 - const struct stacktrace_ops *ops,
10182 - void *data,
10183 - unsigned long *end,
10184 - int *graph);
10185 +typedef unsigned long walk_stack_t(struct task_struct *task,
10186 + void *stack_start,
10187 + unsigned long *stack,
10188 + unsigned long bp,
10189 + const struct stacktrace_ops *ops,
10190 + void *data,
10191 + unsigned long *end,
10192 + int *graph);
10193
10194 -extern unsigned long
10195 -print_context_stack(struct thread_info *tinfo,
10196 - unsigned long *stack, unsigned long bp,
10197 - const struct stacktrace_ops *ops, void *data,
10198 - unsigned long *end, int *graph);
10199 -
10200 -extern unsigned long
10201 -print_context_stack_bp(struct thread_info *tinfo,
10202 - unsigned long *stack, unsigned long bp,
10203 - const struct stacktrace_ops *ops, void *data,
10204 - unsigned long *end, int *graph);
10205 +extern walk_stack_t print_context_stack;
10206 +extern walk_stack_t print_context_stack_bp;
10207
10208 /* Generic stack tracer with callbacks */
10209
10210 @@ -40,7 +32,7 @@ struct stacktrace_ops {
10211 void (*address)(void *data, unsigned long address, int reliable);
10212 /* On negative return stop dumping */
10213 int (*stack)(void *data, char *name);
10214 - walk_stack_t walk_stack;
10215 + walk_stack_t *walk_stack;
10216 };
10217
10218 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
10219 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
10220 index cb23852..2dde194 100644
10221 --- a/arch/x86/include/asm/sys_ia32.h
10222 +++ b/arch/x86/include/asm/sys_ia32.h
10223 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
10224 compat_sigset_t __user *, unsigned int);
10225 asmlinkage long sys32_alarm(unsigned int);
10226
10227 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
10228 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
10229 asmlinkage long sys32_sysfs(int, u32, u32);
10230
10231 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
10232 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
10233 index 2d2f01c..f985723 100644
10234 --- a/arch/x86/include/asm/system.h
10235 +++ b/arch/x86/include/asm/system.h
10236 @@ -129,7 +129,7 @@ do { \
10237 "call __switch_to\n\t" \
10238 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
10239 __switch_canary \
10240 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
10241 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
10242 "movq %%rax,%%rdi\n\t" \
10243 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
10244 "jnz ret_from_fork\n\t" \
10245 @@ -140,7 +140,7 @@ do { \
10246 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
10247 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
10248 [_tif_fork] "i" (_TIF_FORK), \
10249 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
10250 + [thread_info] "m" (current_tinfo), \
10251 [current_task] "m" (current_task) \
10252 __switch_canary_iparam \
10253 : "memory", "cc" __EXTRA_CLOBBER)
10254 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
10255 {
10256 unsigned long __limit;
10257 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
10258 - return __limit + 1;
10259 + return __limit;
10260 }
10261
10262 static inline void native_clts(void)
10263 @@ -397,13 +397,13 @@ void enable_hlt(void);
10264
10265 void cpu_idle_wait(void);
10266
10267 -extern unsigned long arch_align_stack(unsigned long sp);
10268 +#define arch_align_stack(x) ((x) & ~0xfUL)
10269 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
10270
10271 void default_idle(void);
10272 bool set_pm_idle_to_default(void);
10273
10274 -void stop_this_cpu(void *dummy);
10275 +void stop_this_cpu(void *dummy) __noreturn;
10276
10277 /*
10278 * Force strict CPU ordering.
10279 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
10280 index a1fe5c1..ee326d8 100644
10281 --- a/arch/x86/include/asm/thread_info.h
10282 +++ b/arch/x86/include/asm/thread_info.h
10283 @@ -10,6 +10,7 @@
10284 #include <linux/compiler.h>
10285 #include <asm/page.h>
10286 #include <asm/types.h>
10287 +#include <asm/percpu.h>
10288
10289 /*
10290 * low level task data that entry.S needs immediate access to
10291 @@ -24,7 +25,6 @@ struct exec_domain;
10292 #include <linux/atomic.h>
10293
10294 struct thread_info {
10295 - struct task_struct *task; /* main task structure */
10296 struct exec_domain *exec_domain; /* execution domain */
10297 __u32 flags; /* low level flags */
10298 __u32 status; /* thread synchronous flags */
10299 @@ -34,18 +34,12 @@ struct thread_info {
10300 mm_segment_t addr_limit;
10301 struct restart_block restart_block;
10302 void __user *sysenter_return;
10303 -#ifdef CONFIG_X86_32
10304 - unsigned long previous_esp; /* ESP of the previous stack in
10305 - case of nested (IRQ) stacks
10306 - */
10307 - __u8 supervisor_stack[0];
10308 -#endif
10309 + unsigned long lowest_stack;
10310 int uaccess_err;
10311 };
10312
10313 -#define INIT_THREAD_INFO(tsk) \
10314 +#define INIT_THREAD_INFO \
10315 { \
10316 - .task = &tsk, \
10317 .exec_domain = &default_exec_domain, \
10318 .flags = 0, \
10319 .cpu = 0, \
10320 @@ -56,7 +50,7 @@ struct thread_info {
10321 }, \
10322 }
10323
10324 -#define init_thread_info (init_thread_union.thread_info)
10325 +#define init_thread_info (init_thread_union.stack)
10326 #define init_stack (init_thread_union.stack)
10327
10328 #else /* !__ASSEMBLY__ */
10329 @@ -170,45 +164,40 @@ struct thread_info {
10330 ret; \
10331 })
10332
10333 -#ifdef CONFIG_X86_32
10334 -
10335 -#define STACK_WARN (THREAD_SIZE/8)
10336 -/*
10337 - * macros/functions for gaining access to the thread information structure
10338 - *
10339 - * preempt_count needs to be 1 initially, until the scheduler is functional.
10340 - */
10341 -#ifndef __ASSEMBLY__
10342 -
10343 -
10344 -/* how to get the current stack pointer from C */
10345 -register unsigned long current_stack_pointer asm("esp") __used;
10346 -
10347 -/* how to get the thread information struct from C */
10348 -static inline struct thread_info *current_thread_info(void)
10349 -{
10350 - return (struct thread_info *)
10351 - (current_stack_pointer & ~(THREAD_SIZE - 1));
10352 -}
10353 -
10354 -#else /* !__ASSEMBLY__ */
10355 -
10356 +#ifdef __ASSEMBLY__
10357 /* how to get the thread information struct from ASM */
10358 #define GET_THREAD_INFO(reg) \
10359 - movl $-THREAD_SIZE, reg; \
10360 - andl %esp, reg
10361 + mov PER_CPU_VAR(current_tinfo), reg
10362
10363 /* use this one if reg already contains %esp */
10364 -#define GET_THREAD_INFO_WITH_ESP(reg) \
10365 - andl $-THREAD_SIZE, reg
10366 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
10367 +#else
10368 +/* how to get the thread information struct from C */
10369 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
10370 +
10371 +static __always_inline struct thread_info *current_thread_info(void)
10372 +{
10373 + return percpu_read_stable(current_tinfo);
10374 +}
10375 +#endif
10376 +
10377 +#ifdef CONFIG_X86_32
10378 +
10379 +#define STACK_WARN (THREAD_SIZE/8)
10380 +/*
10381 + * macros/functions for gaining access to the thread information structure
10382 + *
10383 + * preempt_count needs to be 1 initially, until the scheduler is functional.
10384 + */
10385 +#ifndef __ASSEMBLY__
10386 +
10387 +/* how to get the current stack pointer from C */
10388 +register unsigned long current_stack_pointer asm("esp") __used;
10389
10390 #endif
10391
10392 #else /* X86_32 */
10393
10394 -#include <asm/percpu.h>
10395 -#define KERNEL_STACK_OFFSET (5*8)
10396 -
10397 /*
10398 * macros/functions for gaining access to the thread information structure
10399 * preempt_count needs to be 1 initially, until the scheduler is functional.
10400 @@ -216,21 +205,8 @@ static inline struct thread_info *current_thread_info(void)
10401 #ifndef __ASSEMBLY__
10402 DECLARE_PER_CPU(unsigned long, kernel_stack);
10403
10404 -static inline struct thread_info *current_thread_info(void)
10405 -{
10406 - struct thread_info *ti;
10407 - ti = (void *)(percpu_read_stable(kernel_stack) +
10408 - KERNEL_STACK_OFFSET - THREAD_SIZE);
10409 - return ti;
10410 -}
10411 -
10412 -#else /* !__ASSEMBLY__ */
10413 -
10414 -/* how to get the thread information struct from ASM */
10415 -#define GET_THREAD_INFO(reg) \
10416 - movq PER_CPU_VAR(kernel_stack),reg ; \
10417 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
10418 -
10419 +/* how to get the current stack pointer from C */
10420 +register unsigned long current_stack_pointer asm("rsp") __used;
10421 #endif
10422
10423 #endif /* !X86_32 */
10424 @@ -266,5 +242,16 @@ extern void arch_task_cache_init(void);
10425 extern void free_thread_info(struct thread_info *ti);
10426 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
10427 #define arch_task_cache_init arch_task_cache_init
10428 +
10429 +#define __HAVE_THREAD_FUNCTIONS
10430 +#define task_thread_info(task) (&(task)->tinfo)
10431 +#define task_stack_page(task) ((task)->stack)
10432 +#define setup_thread_stack(p, org) do {} while (0)
10433 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
10434 +
10435 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
10436 +extern struct task_struct *alloc_task_struct_node(int node);
10437 +extern void free_task_struct(struct task_struct *);
10438 +
10439 #endif
10440 #endif /* _ASM_X86_THREAD_INFO_H */
10441 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
10442 index 36361bf..324f262 100644
10443 --- a/arch/x86/include/asm/uaccess.h
10444 +++ b/arch/x86/include/asm/uaccess.h
10445 @@ -7,12 +7,15 @@
10446 #include <linux/compiler.h>
10447 #include <linux/thread_info.h>
10448 #include <linux/string.h>
10449 +#include <linux/sched.h>
10450 #include <asm/asm.h>
10451 #include <asm/page.h>
10452
10453 #define VERIFY_READ 0
10454 #define VERIFY_WRITE 1
10455
10456 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
10457 +
10458 /*
10459 * The fs value determines whether argument validity checking should be
10460 * performed or not. If get_fs() == USER_DS, checking is performed, with
10461 @@ -28,7 +31,12 @@
10462
10463 #define get_ds() (KERNEL_DS)
10464 #define get_fs() (current_thread_info()->addr_limit)
10465 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
10466 +void __set_fs(mm_segment_t x);
10467 +void set_fs(mm_segment_t x);
10468 +#else
10469 #define set_fs(x) (current_thread_info()->addr_limit = (x))
10470 +#endif
10471
10472 #define segment_eq(a, b) ((a).seg == (b).seg)
10473
10474 @@ -76,7 +84,33 @@
10475 * checks that the pointer is in the user space range - after calling
10476 * this function, memory access functions may still return -EFAULT.
10477 */
10478 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
10479 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
10480 +#define access_ok(type, addr, size) \
10481 +({ \
10482 + long __size = size; \
10483 + unsigned long __addr = (unsigned long)addr; \
10484 + unsigned long __addr_ao = __addr & PAGE_MASK; \
10485 + unsigned long __end_ao = __addr + __size - 1; \
10486 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
10487 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
10488 + while(__addr_ao <= __end_ao) { \
10489 + char __c_ao; \
10490 + __addr_ao += PAGE_SIZE; \
10491 + if (__size > PAGE_SIZE) \
10492 + cond_resched(); \
10493 + if (__get_user(__c_ao, (char __user *)__addr)) \
10494 + break; \
10495 + if (type != VERIFY_WRITE) { \
10496 + __addr = __addr_ao; \
10497 + continue; \
10498 + } \
10499 + if (__put_user(__c_ao, (char __user *)__addr)) \
10500 + break; \
10501 + __addr = __addr_ao; \
10502 + } \
10503 + } \
10504 + __ret_ao; \
10505 +})
10506
10507 /*
10508 * The exception table consists of pairs of addresses: the first is the
10509 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
10510 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
10511 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
10512
10513 -
10514 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
10515 +#define __copyuser_seg "gs;"
10516 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
10517 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
10518 +#else
10519 +#define __copyuser_seg
10520 +#define __COPYUSER_SET_ES
10521 +#define __COPYUSER_RESTORE_ES
10522 +#endif
10523
10524 #ifdef CONFIG_X86_32
10525 #define __put_user_asm_u64(x, addr, err, errret) \
10526 - asm volatile("1: movl %%eax,0(%2)\n" \
10527 - "2: movl %%edx,4(%2)\n" \
10528 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
10529 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
10530 "3:\n" \
10531 ".section .fixup,\"ax\"\n" \
10532 "4: movl %3,%0\n" \
10533 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
10534 : "A" (x), "r" (addr), "i" (errret), "0" (err))
10535
10536 #define __put_user_asm_ex_u64(x, addr) \
10537 - asm volatile("1: movl %%eax,0(%1)\n" \
10538 - "2: movl %%edx,4(%1)\n" \
10539 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
10540 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
10541 "3:\n" \
10542 _ASM_EXTABLE(1b, 2b - 1b) \
10543 _ASM_EXTABLE(2b, 3b - 2b) \
10544 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
10545 __typeof__(*(ptr)) __pu_val; \
10546 __chk_user_ptr(ptr); \
10547 might_fault(); \
10548 - __pu_val = x; \
10549 + __pu_val = (x); \
10550 switch (sizeof(*(ptr))) { \
10551 case 1: \
10552 __put_user_x(1, __pu_val, ptr, __ret_pu); \
10553 @@ -373,7 +415,7 @@ do { \
10554 } while (0)
10555
10556 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
10557 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
10558 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
10559 "2:\n" \
10560 ".section .fixup,\"ax\"\n" \
10561 "3: mov %3,%0\n" \
10562 @@ -381,7 +423,7 @@ do { \
10563 " jmp 2b\n" \
10564 ".previous\n" \
10565 _ASM_EXTABLE(1b, 3b) \
10566 - : "=r" (err), ltype(x) \
10567 + : "=r" (err), ltype (x) \
10568 : "m" (__m(addr)), "i" (errret), "0" (err))
10569
10570 #define __get_user_size_ex(x, ptr, size) \
10571 @@ -406,7 +448,7 @@ do { \
10572 } while (0)
10573
10574 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
10575 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
10576 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
10577 "2:\n" \
10578 _ASM_EXTABLE(1b, 2b - 1b) \
10579 : ltype(x) : "m" (__m(addr)))
10580 @@ -423,13 +465,24 @@ do { \
10581 int __gu_err; \
10582 unsigned long __gu_val; \
10583 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
10584 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
10585 + (x) = (__typeof__(*(ptr)))__gu_val; \
10586 __gu_err; \
10587 })
10588
10589 /* FIXME: this hack is definitely wrong -AK */
10590 struct __large_struct { unsigned long buf[100]; };
10591 -#define __m(x) (*(struct __large_struct __user *)(x))
10592 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10593 +#define ____m(x) \
10594 +({ \
10595 + unsigned long ____x = (unsigned long)(x); \
10596 + if (____x < PAX_USER_SHADOW_BASE) \
10597 + ____x += PAX_USER_SHADOW_BASE; \
10598 + (void __user *)____x; \
10599 +})
10600 +#else
10601 +#define ____m(x) (x)
10602 +#endif
10603 +#define __m(x) (*(struct __large_struct __user *)____m(x))
10604
10605 /*
10606 * Tell gcc we read from memory instead of writing: this is because
10607 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
10608 * aliasing issues.
10609 */
10610 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
10611 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
10612 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
10613 "2:\n" \
10614 ".section .fixup,\"ax\"\n" \
10615 "3: mov %3,%0\n" \
10616 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
10617 ".previous\n" \
10618 _ASM_EXTABLE(1b, 3b) \
10619 : "=r"(err) \
10620 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
10621 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
10622
10623 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
10624 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
10625 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
10626 "2:\n" \
10627 _ASM_EXTABLE(1b, 2b - 1b) \
10628 : : ltype(x), "m" (__m(addr)))
10629 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
10630 * On error, the variable @x is set to zero.
10631 */
10632
10633 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10634 +#define __get_user(x, ptr) get_user((x), (ptr))
10635 +#else
10636 #define __get_user(x, ptr) \
10637 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
10638 +#endif
10639
10640 /**
10641 * __put_user: - Write a simple value into user space, with less checking.
10642 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
10643 * Returns zero on success, or -EFAULT on error.
10644 */
10645
10646 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10647 +#define __put_user(x, ptr) put_user((x), (ptr))
10648 +#else
10649 #define __put_user(x, ptr) \
10650 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
10651 +#endif
10652
10653 #define __get_user_unaligned __get_user
10654 #define __put_user_unaligned __put_user
10655 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
10656 #define get_user_ex(x, ptr) do { \
10657 unsigned long __gue_val; \
10658 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
10659 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
10660 + (x) = (__typeof__(*(ptr)))__gue_val; \
10661 } while (0)
10662
10663 #ifdef CONFIG_X86_WP_WORKS_OK
10664 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
10665 index 566e803..89f1e60 100644
10666 --- a/arch/x86/include/asm/uaccess_32.h
10667 +++ b/arch/x86/include/asm/uaccess_32.h
10668 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
10669 static __always_inline unsigned long __must_check
10670 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
10671 {
10672 + pax_track_stack();
10673 +
10674 + if ((long)n < 0)
10675 + return n;
10676 +
10677 if (__builtin_constant_p(n)) {
10678 unsigned long ret;
10679
10680 @@ -61,6 +66,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
10681 return ret;
10682 }
10683 }
10684 + if (!__builtin_constant_p(n))
10685 + check_object_size(from, n, true);
10686 return __copy_to_user_ll(to, from, n);
10687 }
10688
10689 @@ -82,12 +89,16 @@ static __always_inline unsigned long __must_check
10690 __copy_to_user(void __user *to, const void *from, unsigned long n)
10691 {
10692 might_fault();
10693 +
10694 return __copy_to_user_inatomic(to, from, n);
10695 }
10696
10697 static __always_inline unsigned long
10698 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
10699 {
10700 + if ((long)n < 0)
10701 + return n;
10702 +
10703 /* Avoid zeroing the tail if the copy fails..
10704 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
10705 * but as the zeroing behaviour is only significant when n is not
10706 @@ -137,6 +148,12 @@ static __always_inline unsigned long
10707 __copy_from_user(void *to, const void __user *from, unsigned long n)
10708 {
10709 might_fault();
10710 +
10711 + pax_track_stack();
10712 +
10713 + if ((long)n < 0)
10714 + return n;
10715 +
10716 if (__builtin_constant_p(n)) {
10717 unsigned long ret;
10718
10719 @@ -152,6 +169,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
10720 return ret;
10721 }
10722 }
10723 + if (!__builtin_constant_p(n))
10724 + check_object_size(to, n, false);
10725 return __copy_from_user_ll(to, from, n);
10726 }
10727
10728 @@ -159,6 +178,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
10729 const void __user *from, unsigned long n)
10730 {
10731 might_fault();
10732 +
10733 + if ((long)n < 0)
10734 + return n;
10735 +
10736 if (__builtin_constant_p(n)) {
10737 unsigned long ret;
10738
10739 @@ -181,15 +204,19 @@ static __always_inline unsigned long
10740 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
10741 unsigned long n)
10742 {
10743 - return __copy_from_user_ll_nocache_nozero(to, from, n);
10744 + if ((long)n < 0)
10745 + return n;
10746 +
10747 + return __copy_from_user_ll_nocache_nozero(to, from, n);
10748 }
10749
10750 -unsigned long __must_check copy_to_user(void __user *to,
10751 - const void *from, unsigned long n);
10752 -unsigned long __must_check _copy_from_user(void *to,
10753 - const void __user *from,
10754 - unsigned long n);
10755 -
10756 +extern void copy_to_user_overflow(void)
10757 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
10758 + __compiletime_error("copy_to_user() buffer size is not provably correct")
10759 +#else
10760 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
10761 +#endif
10762 +;
10763
10764 extern void copy_from_user_overflow(void)
10765 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
10766 @@ -199,17 +226,61 @@ extern void copy_from_user_overflow(void)
10767 #endif
10768 ;
10769
10770 -static inline unsigned long __must_check copy_from_user(void *to,
10771 - const void __user *from,
10772 - unsigned long n)
10773 +/**
10774 + * copy_to_user: - Copy a block of data into user space.
10775 + * @to: Destination address, in user space.
10776 + * @from: Source address, in kernel space.
10777 + * @n: Number of bytes to copy.
10778 + *
10779 + * Context: User context only. This function may sleep.
10780 + *
10781 + * Copy data from kernel space to user space.
10782 + *
10783 + * Returns number of bytes that could not be copied.
10784 + * On success, this will be zero.
10785 + */
10786 +static inline unsigned long __must_check
10787 +copy_to_user(void __user *to, const void *from, unsigned long n)
10788 +{
10789 + int sz = __compiletime_object_size(from);
10790 +
10791 + if (unlikely(sz != -1 && sz < n))
10792 + copy_to_user_overflow();
10793 + else if (access_ok(VERIFY_WRITE, to, n))
10794 + n = __copy_to_user(to, from, n);
10795 + return n;
10796 +}
10797 +
10798 +/**
10799 + * copy_from_user: - Copy a block of data from user space.
10800 + * @to: Destination address, in kernel space.
10801 + * @from: Source address, in user space.
10802 + * @n: Number of bytes to copy.
10803 + *
10804 + * Context: User context only. This function may sleep.
10805 + *
10806 + * Copy data from user space to kernel space.
10807 + *
10808 + * Returns number of bytes that could not be copied.
10809 + * On success, this will be zero.
10810 + *
10811 + * If some data could not be copied, this function will pad the copied
10812 + * data to the requested size using zero bytes.
10813 + */
10814 +static inline unsigned long __must_check
10815 +copy_from_user(void *to, const void __user *from, unsigned long n)
10816 {
10817 int sz = __compiletime_object_size(to);
10818
10819 - if (likely(sz == -1 || sz >= n))
10820 - n = _copy_from_user(to, from, n);
10821 - else
10822 + if (unlikely(sz != -1 && sz < n))
10823 copy_from_user_overflow();
10824 -
10825 + else if (access_ok(VERIFY_READ, from, n))
10826 + n = __copy_from_user(to, from, n);
10827 + else if ((long)n > 0) {
10828 + if (!__builtin_constant_p(n))
10829 + check_object_size(to, n, false);
10830 + memset(to, 0, n);
10831 + }
10832 return n;
10833 }
10834
10835 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
10836 index 1c66d30..59bd7d4 100644
10837 --- a/arch/x86/include/asm/uaccess_64.h
10838 +++ b/arch/x86/include/asm/uaccess_64.h
10839 @@ -10,6 +10,9 @@
10840 #include <asm/alternative.h>
10841 #include <asm/cpufeature.h>
10842 #include <asm/page.h>
10843 +#include <asm/pgtable.h>
10844 +
10845 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
10846
10847 /*
10848 * Copy To/From Userspace
10849 @@ -17,12 +20,12 @@
10850
10851 /* Handles exceptions in both to and from, but doesn't do access_ok */
10852 __must_check unsigned long
10853 -copy_user_generic_string(void *to, const void *from, unsigned len);
10854 +copy_user_generic_string(void *to, const void *from, unsigned long len);
10855 __must_check unsigned long
10856 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
10857 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len);
10858
10859 static __always_inline __must_check unsigned long
10860 -copy_user_generic(void *to, const void *from, unsigned len)
10861 +copy_user_generic(void *to, const void *from, unsigned long len)
10862 {
10863 unsigned ret;
10864
10865 @@ -36,138 +39,226 @@ copy_user_generic(void *to, const void *from, unsigned len)
10866 return ret;
10867 }
10868
10869 +static __always_inline __must_check unsigned long
10870 +__copy_to_user(void __user *to, const void *from, unsigned long len);
10871 +static __always_inline __must_check unsigned long
10872 +__copy_from_user(void *to, const void __user *from, unsigned long len);
10873 __must_check unsigned long
10874 -_copy_to_user(void __user *to, const void *from, unsigned len);
10875 -__must_check unsigned long
10876 -_copy_from_user(void *to, const void __user *from, unsigned len);
10877 -__must_check unsigned long
10878 -copy_in_user(void __user *to, const void __user *from, unsigned len);
10879 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
10880
10881 static inline unsigned long __must_check copy_from_user(void *to,
10882 const void __user *from,
10883 - unsigned long n)
10884 + unsigned n)
10885 {
10886 - int sz = __compiletime_object_size(to);
10887 -
10888 might_fault();
10889 - if (likely(sz == -1 || sz >= n))
10890 - n = _copy_from_user(to, from, n);
10891 -#ifdef CONFIG_DEBUG_VM
10892 - else
10893 - WARN(1, "Buffer overflow detected!\n");
10894 -#endif
10895 +
10896 + if (access_ok(VERIFY_READ, from, n))
10897 + n = __copy_from_user(to, from, n);
10898 + else if (n < INT_MAX) {
10899 + if (!__builtin_constant_p(n))
10900 + check_object_size(to, n, false);
10901 + memset(to, 0, n);
10902 + }
10903 return n;
10904 }
10905
10906 static __always_inline __must_check
10907 -int copy_to_user(void __user *dst, const void *src, unsigned size)
10908 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
10909 {
10910 might_fault();
10911
10912 - return _copy_to_user(dst, src, size);
10913 + if (access_ok(VERIFY_WRITE, dst, size))
10914 + size = __copy_to_user(dst, src, size);
10915 + return size;
10916 }
10917
10918 static __always_inline __must_check
10919 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
10920 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
10921 {
10922 - int ret = 0;
10923 + int sz = __compiletime_object_size(dst);
10924 + unsigned ret = 0;
10925
10926 might_fault();
10927 - if (!__builtin_constant_p(size))
10928 - return copy_user_generic(dst, (__force void *)src, size);
10929 +
10930 + pax_track_stack();
10931 +
10932 + if (size > INT_MAX)
10933 + return size;
10934 +
10935 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10936 + if (!__access_ok(VERIFY_READ, src, size))
10937 + return size;
10938 +#endif
10939 +
10940 + if (unlikely(sz != -1 && sz < size)) {
10941 +#ifdef CONFIG_DEBUG_VM
10942 + WARN(1, "Buffer overflow detected!\n");
10943 +#endif
10944 + return size;
10945 + }
10946 +
10947 + if (!__builtin_constant_p(size)) {
10948 + check_object_size(dst, size, false);
10949 +
10950 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10951 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10952 + src += PAX_USER_SHADOW_BASE;
10953 +#endif
10954 +
10955 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
10956 + }
10957 switch (size) {
10958 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
10959 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
10960 ret, "b", "b", "=q", 1);
10961 return ret;
10962 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
10963 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
10964 ret, "w", "w", "=r", 2);
10965 return ret;
10966 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
10967 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
10968 ret, "l", "k", "=r", 4);
10969 return ret;
10970 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
10971 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
10972 ret, "q", "", "=r", 8);
10973 return ret;
10974 case 10:
10975 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
10976 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
10977 ret, "q", "", "=r", 10);
10978 if (unlikely(ret))
10979 return ret;
10980 __get_user_asm(*(u16 *)(8 + (char *)dst),
10981 - (u16 __user *)(8 + (char __user *)src),
10982 + (const u16 __user *)(8 + (const char __user *)src),
10983 ret, "w", "w", "=r", 2);
10984 return ret;
10985 case 16:
10986 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
10987 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
10988 ret, "q", "", "=r", 16);
10989 if (unlikely(ret))
10990 return ret;
10991 __get_user_asm(*(u64 *)(8 + (char *)dst),
10992 - (u64 __user *)(8 + (char __user *)src),
10993 + (const u64 __user *)(8 + (const char __user *)src),
10994 ret, "q", "", "=r", 8);
10995 return ret;
10996 default:
10997 - return copy_user_generic(dst, (__force void *)src, size);
10998 +
10999 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11000 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11001 + src += PAX_USER_SHADOW_BASE;
11002 +#endif
11003 +
11004 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11005 }
11006 }
11007
11008 static __always_inline __must_check
11009 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
11010 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
11011 {
11012 - int ret = 0;
11013 + int sz = __compiletime_object_size(src);
11014 + unsigned ret = 0;
11015
11016 might_fault();
11017 - if (!__builtin_constant_p(size))
11018 - return copy_user_generic((__force void *)dst, src, size);
11019 +
11020 + pax_track_stack();
11021 +
11022 + if (size > INT_MAX)
11023 + return size;
11024 +
11025 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11026 + if (!__access_ok(VERIFY_WRITE, dst, size))
11027 + return size;
11028 +#endif
11029 +
11030 + if (unlikely(sz != -1 && sz < size)) {
11031 +#ifdef CONFIG_DEBUG_VM
11032 + WARN(1, "Buffer overflow detected!\n");
11033 +#endif
11034 + return size;
11035 + }
11036 +
11037 + if (!__builtin_constant_p(size)) {
11038 + check_object_size(src, size, true);
11039 +
11040 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11041 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11042 + dst += PAX_USER_SHADOW_BASE;
11043 +#endif
11044 +
11045 + return copy_user_generic((__force_kernel void *)dst, src, size);
11046 + }
11047 switch (size) {
11048 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
11049 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
11050 ret, "b", "b", "iq", 1);
11051 return ret;
11052 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
11053 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
11054 ret, "w", "w", "ir", 2);
11055 return ret;
11056 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
11057 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
11058 ret, "l", "k", "ir", 4);
11059 return ret;
11060 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
11061 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11062 ret, "q", "", "er", 8);
11063 return ret;
11064 case 10:
11065 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11066 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11067 ret, "q", "", "er", 10);
11068 if (unlikely(ret))
11069 return ret;
11070 asm("":::"memory");
11071 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
11072 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
11073 ret, "w", "w", "ir", 2);
11074 return ret;
11075 case 16:
11076 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11077 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11078 ret, "q", "", "er", 16);
11079 if (unlikely(ret))
11080 return ret;
11081 asm("":::"memory");
11082 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
11083 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
11084 ret, "q", "", "er", 8);
11085 return ret;
11086 default:
11087 - return copy_user_generic((__force void *)dst, src, size);
11088 +
11089 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11090 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11091 + dst += PAX_USER_SHADOW_BASE;
11092 +#endif
11093 +
11094 + return copy_user_generic((__force_kernel void *)dst, src, size);
11095 }
11096 }
11097
11098 static __always_inline __must_check
11099 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11100 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
11101 {
11102 - int ret = 0;
11103 + unsigned ret = 0;
11104
11105 might_fault();
11106 - if (!__builtin_constant_p(size))
11107 - return copy_user_generic((__force void *)dst,
11108 - (__force void *)src, size);
11109 +
11110 + if (size > INT_MAX)
11111 + return size;
11112 +
11113 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11114 + if (!__access_ok(VERIFY_READ, src, size))
11115 + return size;
11116 + if (!__access_ok(VERIFY_WRITE, dst, size))
11117 + return size;
11118 +#endif
11119 +
11120 + if (!__builtin_constant_p(size)) {
11121 +
11122 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11123 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11124 + src += PAX_USER_SHADOW_BASE;
11125 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11126 + dst += PAX_USER_SHADOW_BASE;
11127 +#endif
11128 +
11129 + return copy_user_generic((__force_kernel void *)dst,
11130 + (__force_kernel const void *)src, size);
11131 + }
11132 switch (size) {
11133 case 1: {
11134 u8 tmp;
11135 - __get_user_asm(tmp, (u8 __user *)src,
11136 + __get_user_asm(tmp, (const u8 __user *)src,
11137 ret, "b", "b", "=q", 1);
11138 if (likely(!ret))
11139 __put_user_asm(tmp, (u8 __user *)dst,
11140 @@ -176,7 +267,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11141 }
11142 case 2: {
11143 u16 tmp;
11144 - __get_user_asm(tmp, (u16 __user *)src,
11145 + __get_user_asm(tmp, (const u16 __user *)src,
11146 ret, "w", "w", "=r", 2);
11147 if (likely(!ret))
11148 __put_user_asm(tmp, (u16 __user *)dst,
11149 @@ -186,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11150
11151 case 4: {
11152 u32 tmp;
11153 - __get_user_asm(tmp, (u32 __user *)src,
11154 + __get_user_asm(tmp, (const u32 __user *)src,
11155 ret, "l", "k", "=r", 4);
11156 if (likely(!ret))
11157 __put_user_asm(tmp, (u32 __user *)dst,
11158 @@ -195,7 +286,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11159 }
11160 case 8: {
11161 u64 tmp;
11162 - __get_user_asm(tmp, (u64 __user *)src,
11163 + __get_user_asm(tmp, (const u64 __user *)src,
11164 ret, "q", "", "=r", 8);
11165 if (likely(!ret))
11166 __put_user_asm(tmp, (u64 __user *)dst,
11167 @@ -203,8 +294,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11168 return ret;
11169 }
11170 default:
11171 - return copy_user_generic((__force void *)dst,
11172 - (__force void *)src, size);
11173 +
11174 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11175 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11176 + src += PAX_USER_SHADOW_BASE;
11177 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11178 + dst += PAX_USER_SHADOW_BASE;
11179 +#endif
11180 +
11181 + return copy_user_generic((__force_kernel void *)dst,
11182 + (__force_kernel const void *)src, size);
11183 }
11184 }
11185
11186 @@ -219,35 +318,74 @@ __must_check unsigned long clear_user(void __user *mem, unsigned long len);
11187 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
11188
11189 static __must_check __always_inline int
11190 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
11191 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
11192 {
11193 - return copy_user_generic(dst, (__force const void *)src, size);
11194 + pax_track_stack();
11195 +
11196 + if (size > INT_MAX)
11197 + return size;
11198 +
11199 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11200 + if (!__access_ok(VERIFY_READ, src, size))
11201 + return size;
11202 +
11203 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11204 + src += PAX_USER_SHADOW_BASE;
11205 +#endif
11206 +
11207 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11208 }
11209
11210 -static __must_check __always_inline int
11211 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
11212 +static __must_check __always_inline unsigned long
11213 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
11214 {
11215 - return copy_user_generic((__force void *)dst, src, size);
11216 + if (size > INT_MAX)
11217 + return size;
11218 +
11219 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11220 + if (!__access_ok(VERIFY_WRITE, dst, size))
11221 + return size;
11222 +
11223 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11224 + dst += PAX_USER_SHADOW_BASE;
11225 +#endif
11226 +
11227 + return copy_user_generic((__force_kernel void *)dst, src, size);
11228 }
11229
11230 -extern long __copy_user_nocache(void *dst, const void __user *src,
11231 - unsigned size, int zerorest);
11232 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
11233 + unsigned long size, int zerorest);
11234
11235 -static inline int
11236 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
11237 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
11238 {
11239 might_sleep();
11240 +
11241 + if (size > INT_MAX)
11242 + return size;
11243 +
11244 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11245 + if (!__access_ok(VERIFY_READ, src, size))
11246 + return size;
11247 +#endif
11248 +
11249 return __copy_user_nocache(dst, src, size, 1);
11250 }
11251
11252 -static inline int
11253 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
11254 - unsigned size)
11255 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
11256 + unsigned long size)
11257 {
11258 + if (size > INT_MAX)
11259 + return size;
11260 +
11261 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11262 + if (!__access_ok(VERIFY_READ, src, size))
11263 + return size;
11264 +#endif
11265 +
11266 return __copy_user_nocache(dst, src, size, 0);
11267 }
11268
11269 -unsigned long
11270 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
11271 +extern unsigned long
11272 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest);
11273
11274 #endif /* _ASM_X86_UACCESS_64_H */
11275 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
11276 index bb05228..d763d5b 100644
11277 --- a/arch/x86/include/asm/vdso.h
11278 +++ b/arch/x86/include/asm/vdso.h
11279 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
11280 #define VDSO32_SYMBOL(base, name) \
11281 ({ \
11282 extern const char VDSO32_##name[]; \
11283 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
11284 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
11285 })
11286 #endif
11287
11288 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
11289 index d3d8590..d296b5f 100644
11290 --- a/arch/x86/include/asm/x86_init.h
11291 +++ b/arch/x86/include/asm/x86_init.h
11292 @@ -28,7 +28,7 @@ struct x86_init_mpparse {
11293 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
11294 void (*find_smp_config)(void);
11295 void (*get_smp_config)(unsigned int early);
11296 -};
11297 +} __no_const;
11298
11299 /**
11300 * struct x86_init_resources - platform specific resource related ops
11301 @@ -42,7 +42,7 @@ struct x86_init_resources {
11302 void (*probe_roms)(void);
11303 void (*reserve_resources)(void);
11304 char *(*memory_setup)(void);
11305 -};
11306 +} __no_const;
11307
11308 /**
11309 * struct x86_init_irqs - platform specific interrupt setup
11310 @@ -55,7 +55,7 @@ struct x86_init_irqs {
11311 void (*pre_vector_init)(void);
11312 void (*intr_init)(void);
11313 void (*trap_init)(void);
11314 -};
11315 +} __no_const;
11316
11317 /**
11318 * struct x86_init_oem - oem platform specific customizing functions
11319 @@ -65,7 +65,7 @@ struct x86_init_irqs {
11320 struct x86_init_oem {
11321 void (*arch_setup)(void);
11322 void (*banner)(void);
11323 -};
11324 +} __no_const;
11325
11326 /**
11327 * struct x86_init_mapping - platform specific initial kernel pagetable setup
11328 @@ -76,7 +76,7 @@ struct x86_init_oem {
11329 */
11330 struct x86_init_mapping {
11331 void (*pagetable_reserve)(u64 start, u64 end);
11332 -};
11333 +} __no_const;
11334
11335 /**
11336 * struct x86_init_paging - platform specific paging functions
11337 @@ -86,7 +86,7 @@ struct x86_init_mapping {
11338 struct x86_init_paging {
11339 void (*pagetable_setup_start)(pgd_t *base);
11340 void (*pagetable_setup_done)(pgd_t *base);
11341 -};
11342 +} __no_const;
11343
11344 /**
11345 * struct x86_init_timers - platform specific timer setup
11346 @@ -101,7 +101,7 @@ struct x86_init_timers {
11347 void (*tsc_pre_init)(void);
11348 void (*timer_init)(void);
11349 void (*wallclock_init)(void);
11350 -};
11351 +} __no_const;
11352
11353 /**
11354 * struct x86_init_iommu - platform specific iommu setup
11355 @@ -109,7 +109,7 @@ struct x86_init_timers {
11356 */
11357 struct x86_init_iommu {
11358 int (*iommu_init)(void);
11359 -};
11360 +} __no_const;
11361
11362 /**
11363 * struct x86_init_pci - platform specific pci init functions
11364 @@ -123,7 +123,7 @@ struct x86_init_pci {
11365 int (*init)(void);
11366 void (*init_irq)(void);
11367 void (*fixup_irqs)(void);
11368 -};
11369 +} __no_const;
11370
11371 /**
11372 * struct x86_init_ops - functions for platform specific setup
11373 @@ -139,7 +139,7 @@ struct x86_init_ops {
11374 struct x86_init_timers timers;
11375 struct x86_init_iommu iommu;
11376 struct x86_init_pci pci;
11377 -};
11378 +} __no_const;
11379
11380 /**
11381 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
11382 @@ -147,7 +147,7 @@ struct x86_init_ops {
11383 */
11384 struct x86_cpuinit_ops {
11385 void (*setup_percpu_clockev)(void);
11386 -};
11387 +} __no_const;
11388
11389 /**
11390 * struct x86_platform_ops - platform specific runtime functions
11391 @@ -166,7 +166,7 @@ struct x86_platform_ops {
11392 bool (*is_untracked_pat_range)(u64 start, u64 end);
11393 void (*nmi_init)(void);
11394 int (*i8042_detect)(void);
11395 -};
11396 +} __no_const;
11397
11398 struct pci_dev;
11399
11400 @@ -174,7 +174,7 @@ struct x86_msi_ops {
11401 int (*setup_msi_irqs)(struct pci_dev *dev, int nvec, int type);
11402 void (*teardown_msi_irq)(unsigned int irq);
11403 void (*teardown_msi_irqs)(struct pci_dev *dev);
11404 -};
11405 +} __no_const;
11406
11407 extern struct x86_init_ops x86_init;
11408 extern struct x86_cpuinit_ops x86_cpuinit;
11409 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
11410 index c6ce245..ffbdab7 100644
11411 --- a/arch/x86/include/asm/xsave.h
11412 +++ b/arch/x86/include/asm/xsave.h
11413 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
11414 {
11415 int err;
11416
11417 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11418 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
11419 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
11420 +#endif
11421 +
11422 /*
11423 * Clear the xsave header first, so that reserved fields are
11424 * initialized to zero.
11425 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
11426 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
11427 {
11428 int err;
11429 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
11430 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
11431 u32 lmask = mask;
11432 u32 hmask = mask >> 32;
11433
11434 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11435 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
11436 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
11437 +#endif
11438 +
11439 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
11440 "2:\n"
11441 ".section .fixup,\"ax\"\n"
11442 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
11443 index 6a564ac..9b1340c 100644
11444 --- a/arch/x86/kernel/acpi/realmode/Makefile
11445 +++ b/arch/x86/kernel/acpi/realmode/Makefile
11446 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
11447 $(call cc-option, -fno-stack-protector) \
11448 $(call cc-option, -mpreferred-stack-boundary=2)
11449 KBUILD_CFLAGS += $(call cc-option, -m32)
11450 +ifdef CONSTIFY_PLUGIN
11451 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
11452 +endif
11453 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11454 GCOV_PROFILE := n
11455
11456 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
11457 index b4fd836..4358fe3 100644
11458 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
11459 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
11460 @@ -108,6 +108,9 @@ wakeup_code:
11461 /* Do any other stuff... */
11462
11463 #ifndef CONFIG_64BIT
11464 + /* Recheck NX bit overrides (64bit path does this in trampoline */
11465 + call verify_cpu
11466 +
11467 /* This could also be done in C code... */
11468 movl pmode_cr3, %eax
11469 movl %eax, %cr3
11470 @@ -131,6 +134,7 @@ wakeup_code:
11471 movl pmode_cr0, %eax
11472 movl %eax, %cr0
11473 jmp pmode_return
11474 +# include "../../verify_cpu.S"
11475 #else
11476 pushw $0
11477 pushw trampoline_segment
11478 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
11479 index 103b6ab..2004d0a 100644
11480 --- a/arch/x86/kernel/acpi/sleep.c
11481 +++ b/arch/x86/kernel/acpi/sleep.c
11482 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
11483 header->trampoline_segment = trampoline_address() >> 4;
11484 #ifdef CONFIG_SMP
11485 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
11486 +
11487 + pax_open_kernel();
11488 early_gdt_descr.address =
11489 (unsigned long)get_cpu_gdt_table(smp_processor_id());
11490 + pax_close_kernel();
11491 +
11492 initial_gs = per_cpu_offset(smp_processor_id());
11493 #endif
11494 initial_code = (unsigned long)wakeup_long64;
11495 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
11496 index 13ab720..95d5442 100644
11497 --- a/arch/x86/kernel/acpi/wakeup_32.S
11498 +++ b/arch/x86/kernel/acpi/wakeup_32.S
11499 @@ -30,13 +30,11 @@ wakeup_pmode_return:
11500 # and restore the stack ... but you need gdt for this to work
11501 movl saved_context_esp, %esp
11502
11503 - movl %cs:saved_magic, %eax
11504 - cmpl $0x12345678, %eax
11505 + cmpl $0x12345678, saved_magic
11506 jne bogus_magic
11507
11508 # jump to place where we left off
11509 - movl saved_eip, %eax
11510 - jmp *%eax
11511 + jmp *(saved_eip)
11512
11513 bogus_magic:
11514 jmp bogus_magic
11515 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
11516 index c638228..16dfa8d 100644
11517 --- a/arch/x86/kernel/alternative.c
11518 +++ b/arch/x86/kernel/alternative.c
11519 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
11520 */
11521 for (a = start; a < end; a++) {
11522 instr = (u8 *)&a->instr_offset + a->instr_offset;
11523 +
11524 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11525 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11526 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
11527 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11528 +#endif
11529 +
11530 replacement = (u8 *)&a->repl_offset + a->repl_offset;
11531 BUG_ON(a->replacementlen > a->instrlen);
11532 BUG_ON(a->instrlen > sizeof(insnbuf));
11533 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
11534 for (poff = start; poff < end; poff++) {
11535 u8 *ptr = (u8 *)poff + *poff;
11536
11537 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11538 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11539 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
11540 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11541 +#endif
11542 +
11543 if (!*poff || ptr < text || ptr >= text_end)
11544 continue;
11545 /* turn DS segment override prefix into lock prefix */
11546 - if (*ptr == 0x3e)
11547 + if (*ktla_ktva(ptr) == 0x3e)
11548 text_poke(ptr, ((unsigned char []){0xf0}), 1);
11549 };
11550 mutex_unlock(&text_mutex);
11551 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
11552 for (poff = start; poff < end; poff++) {
11553 u8 *ptr = (u8 *)poff + *poff;
11554
11555 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11556 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11557 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
11558 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11559 +#endif
11560 +
11561 if (!*poff || ptr < text || ptr >= text_end)
11562 continue;
11563 /* turn lock prefix into DS segment override prefix */
11564 - if (*ptr == 0xf0)
11565 + if (*ktla_ktva(ptr) == 0xf0)
11566 text_poke(ptr, ((unsigned char []){0x3E}), 1);
11567 };
11568 mutex_unlock(&text_mutex);
11569 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
11570
11571 BUG_ON(p->len > MAX_PATCH_LEN);
11572 /* prep the buffer with the original instructions */
11573 - memcpy(insnbuf, p->instr, p->len);
11574 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
11575 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
11576 (unsigned long)p->instr, p->len);
11577
11578 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
11579 if (smp_alt_once)
11580 free_init_pages("SMP alternatives",
11581 (unsigned long)__smp_locks,
11582 - (unsigned long)__smp_locks_end);
11583 + PAGE_ALIGN((unsigned long)__smp_locks_end));
11584
11585 restart_nmi();
11586 }
11587 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
11588 * instructions. And on the local CPU you need to be protected again NMI or MCE
11589 * handlers seeing an inconsistent instruction while you patch.
11590 */
11591 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
11592 +void *__kprobes text_poke_early(void *addr, const void *opcode,
11593 size_t len)
11594 {
11595 unsigned long flags;
11596 local_irq_save(flags);
11597 - memcpy(addr, opcode, len);
11598 +
11599 + pax_open_kernel();
11600 + memcpy(ktla_ktva(addr), opcode, len);
11601 sync_core();
11602 + pax_close_kernel();
11603 +
11604 local_irq_restore(flags);
11605 /* Could also do a CLFLUSH here to speed up CPU recovery; but
11606 that causes hangs on some VIA CPUs. */
11607 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
11608 */
11609 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
11610 {
11611 - unsigned long flags;
11612 - char *vaddr;
11613 + unsigned char *vaddr = ktla_ktva(addr);
11614 struct page *pages[2];
11615 - int i;
11616 + size_t i;
11617
11618 if (!core_kernel_text((unsigned long)addr)) {
11619 - pages[0] = vmalloc_to_page(addr);
11620 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
11621 + pages[0] = vmalloc_to_page(vaddr);
11622 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
11623 } else {
11624 - pages[0] = virt_to_page(addr);
11625 + pages[0] = virt_to_page(vaddr);
11626 WARN_ON(!PageReserved(pages[0]));
11627 - pages[1] = virt_to_page(addr + PAGE_SIZE);
11628 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
11629 }
11630 BUG_ON(!pages[0]);
11631 - local_irq_save(flags);
11632 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
11633 - if (pages[1])
11634 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
11635 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
11636 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
11637 - clear_fixmap(FIX_TEXT_POKE0);
11638 - if (pages[1])
11639 - clear_fixmap(FIX_TEXT_POKE1);
11640 - local_flush_tlb();
11641 - sync_core();
11642 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
11643 - that causes hangs on some VIA CPUs. */
11644 + text_poke_early(addr, opcode, len);
11645 for (i = 0; i < len; i++)
11646 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
11647 - local_irq_restore(flags);
11648 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
11649 return addr;
11650 }
11651
11652 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
11653 index 52fa563..5de9d9c 100644
11654 --- a/arch/x86/kernel/apic/apic.c
11655 +++ b/arch/x86/kernel/apic/apic.c
11656 @@ -174,7 +174,7 @@ int first_system_vector = 0xfe;
11657 /*
11658 * Debug level, exported for io_apic.c
11659 */
11660 -unsigned int apic_verbosity;
11661 +int apic_verbosity;
11662
11663 int pic_mode;
11664
11665 @@ -1835,7 +1835,7 @@ void smp_error_interrupt(struct pt_regs *regs)
11666 apic_write(APIC_ESR, 0);
11667 v1 = apic_read(APIC_ESR);
11668 ack_APIC_irq();
11669 - atomic_inc(&irq_err_count);
11670 + atomic_inc_unchecked(&irq_err_count);
11671
11672 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
11673 smp_processor_id(), v0 , v1);
11674 @@ -2209,6 +2209,8 @@ static int __cpuinit apic_cluster_num(void)
11675 u16 *bios_cpu_apicid;
11676 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
11677
11678 + pax_track_stack();
11679 +
11680 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
11681 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
11682
11683 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
11684 index 8eb863e..32e6934 100644
11685 --- a/arch/x86/kernel/apic/io_apic.c
11686 +++ b/arch/x86/kernel/apic/io_apic.c
11687 @@ -1028,7 +1028,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
11688 }
11689 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
11690
11691 -void lock_vector_lock(void)
11692 +void lock_vector_lock(void) __acquires(vector_lock)
11693 {
11694 /* Used to the online set of cpus does not change
11695 * during assign_irq_vector.
11696 @@ -1036,7 +1036,7 @@ void lock_vector_lock(void)
11697 raw_spin_lock(&vector_lock);
11698 }
11699
11700 -void unlock_vector_lock(void)
11701 +void unlock_vector_lock(void) __releases(vector_lock)
11702 {
11703 raw_spin_unlock(&vector_lock);
11704 }
11705 @@ -2405,7 +2405,7 @@ static void ack_apic_edge(struct irq_data *data)
11706 ack_APIC_irq();
11707 }
11708
11709 -atomic_t irq_mis_count;
11710 +atomic_unchecked_t irq_mis_count;
11711
11712 /*
11713 * IO-APIC versions below 0x20 don't support EOI register.
11714 @@ -2513,7 +2513,7 @@ static void ack_apic_level(struct irq_data *data)
11715 * at the cpu.
11716 */
11717 if (!(v & (1 << (i & 0x1f)))) {
11718 - atomic_inc(&irq_mis_count);
11719 + atomic_inc_unchecked(&irq_mis_count);
11720
11721 eoi_ioapic_irq(irq, cfg);
11722 }
11723 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
11724 index 0371c48..54cdf63 100644
11725 --- a/arch/x86/kernel/apm_32.c
11726 +++ b/arch/x86/kernel/apm_32.c
11727 @@ -413,7 +413,7 @@ static DEFINE_MUTEX(apm_mutex);
11728 * This is for buggy BIOS's that refer to (real mode) segment 0x40
11729 * even though they are called in protected mode.
11730 */
11731 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
11732 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
11733 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
11734
11735 static const char driver_version[] = "1.16ac"; /* no spaces */
11736 @@ -591,7 +591,10 @@ static long __apm_bios_call(void *_call)
11737 BUG_ON(cpu != 0);
11738 gdt = get_cpu_gdt_table(cpu);
11739 save_desc_40 = gdt[0x40 / 8];
11740 +
11741 + pax_open_kernel();
11742 gdt[0x40 / 8] = bad_bios_desc;
11743 + pax_close_kernel();
11744
11745 apm_irq_save(flags);
11746 APM_DO_SAVE_SEGS;
11747 @@ -600,7 +603,11 @@ static long __apm_bios_call(void *_call)
11748 &call->esi);
11749 APM_DO_RESTORE_SEGS;
11750 apm_irq_restore(flags);
11751 +
11752 + pax_open_kernel();
11753 gdt[0x40 / 8] = save_desc_40;
11754 + pax_close_kernel();
11755 +
11756 put_cpu();
11757
11758 return call->eax & 0xff;
11759 @@ -667,7 +674,10 @@ static long __apm_bios_call_simple(void *_call)
11760 BUG_ON(cpu != 0);
11761 gdt = get_cpu_gdt_table(cpu);
11762 save_desc_40 = gdt[0x40 / 8];
11763 +
11764 + pax_open_kernel();
11765 gdt[0x40 / 8] = bad_bios_desc;
11766 + pax_close_kernel();
11767
11768 apm_irq_save(flags);
11769 APM_DO_SAVE_SEGS;
11770 @@ -675,7 +685,11 @@ static long __apm_bios_call_simple(void *_call)
11771 &call->eax);
11772 APM_DO_RESTORE_SEGS;
11773 apm_irq_restore(flags);
11774 +
11775 + pax_open_kernel();
11776 gdt[0x40 / 8] = save_desc_40;
11777 + pax_close_kernel();
11778 +
11779 put_cpu();
11780 return error;
11781 }
11782 @@ -2349,12 +2363,15 @@ static int __init apm_init(void)
11783 * code to that CPU.
11784 */
11785 gdt = get_cpu_gdt_table(0);
11786 +
11787 + pax_open_kernel();
11788 set_desc_base(&gdt[APM_CS >> 3],
11789 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
11790 set_desc_base(&gdt[APM_CS_16 >> 3],
11791 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
11792 set_desc_base(&gdt[APM_DS >> 3],
11793 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
11794 + pax_close_kernel();
11795
11796 proc_create("apm", 0, NULL, &apm_file_ops);
11797
11798 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
11799 index 4f13faf..87db5d2 100644
11800 --- a/arch/x86/kernel/asm-offsets.c
11801 +++ b/arch/x86/kernel/asm-offsets.c
11802 @@ -33,6 +33,8 @@ void common(void) {
11803 OFFSET(TI_status, thread_info, status);
11804 OFFSET(TI_addr_limit, thread_info, addr_limit);
11805 OFFSET(TI_preempt_count, thread_info, preempt_count);
11806 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
11807 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
11808
11809 BLANK();
11810 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
11811 @@ -53,8 +55,26 @@ void common(void) {
11812 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
11813 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
11814 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
11815 +
11816 +#ifdef CONFIG_PAX_KERNEXEC
11817 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
11818 #endif
11819
11820 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11821 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
11822 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
11823 +#ifdef CONFIG_X86_64
11824 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
11825 +#endif
11826 +#endif
11827 +
11828 +#endif
11829 +
11830 + BLANK();
11831 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
11832 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
11833 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
11834 +
11835 #ifdef CONFIG_XEN
11836 BLANK();
11837 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
11838 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
11839 index e72a119..6e2955d 100644
11840 --- a/arch/x86/kernel/asm-offsets_64.c
11841 +++ b/arch/x86/kernel/asm-offsets_64.c
11842 @@ -69,6 +69,7 @@ int main(void)
11843 BLANK();
11844 #undef ENTRY
11845
11846 + DEFINE(TSS_size, sizeof(struct tss_struct));
11847 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
11848 BLANK();
11849
11850 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
11851 index 6042981..e638266 100644
11852 --- a/arch/x86/kernel/cpu/Makefile
11853 +++ b/arch/x86/kernel/cpu/Makefile
11854 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
11855 CFLAGS_REMOVE_perf_event.o = -pg
11856 endif
11857
11858 -# Make sure load_percpu_segment has no stackprotector
11859 -nostackp := $(call cc-option, -fno-stack-protector)
11860 -CFLAGS_common.o := $(nostackp)
11861 -
11862 obj-y := intel_cacheinfo.o scattered.o topology.o
11863 obj-y += proc.o capflags.o powerflags.o common.o
11864 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
11865 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
11866 index b13ed39..603286c 100644
11867 --- a/arch/x86/kernel/cpu/amd.c
11868 +++ b/arch/x86/kernel/cpu/amd.c
11869 @@ -647,7 +647,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
11870 unsigned int size)
11871 {
11872 /* AMD errata T13 (order #21922) */
11873 - if ((c->x86 == 6)) {
11874 + if (c->x86 == 6) {
11875 /* Duron Rev A0 */
11876 if (c->x86_model == 3 && c->x86_mask == 0)
11877 size = 64;
11878 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
11879 index 6218439..ab2e4ab 100644
11880 --- a/arch/x86/kernel/cpu/common.c
11881 +++ b/arch/x86/kernel/cpu/common.c
11882 @@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
11883
11884 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
11885
11886 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
11887 -#ifdef CONFIG_X86_64
11888 - /*
11889 - * We need valid kernel segments for data and code in long mode too
11890 - * IRET will check the segment types kkeil 2000/10/28
11891 - * Also sysret mandates a special GDT layout
11892 - *
11893 - * TLS descriptors are currently at a different place compared to i386.
11894 - * Hopefully nobody expects them at a fixed place (Wine?)
11895 - */
11896 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
11897 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
11898 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
11899 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
11900 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
11901 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
11902 -#else
11903 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
11904 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
11905 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
11906 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
11907 - /*
11908 - * Segments used for calling PnP BIOS have byte granularity.
11909 - * They code segments and data segments have fixed 64k limits,
11910 - * the transfer segment sizes are set at run time.
11911 - */
11912 - /* 32-bit code */
11913 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
11914 - /* 16-bit code */
11915 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
11916 - /* 16-bit data */
11917 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
11918 - /* 16-bit data */
11919 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
11920 - /* 16-bit data */
11921 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
11922 - /*
11923 - * The APM segments have byte granularity and their bases
11924 - * are set at run time. All have 64k limits.
11925 - */
11926 - /* 32-bit code */
11927 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
11928 - /* 16-bit code */
11929 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
11930 - /* data */
11931 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
11932 -
11933 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
11934 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
11935 - GDT_STACK_CANARY_INIT
11936 -#endif
11937 -} };
11938 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
11939 -
11940 static int __init x86_xsave_setup(char *s)
11941 {
11942 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
11943 @@ -371,7 +317,7 @@ void switch_to_new_gdt(int cpu)
11944 {
11945 struct desc_ptr gdt_descr;
11946
11947 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
11948 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
11949 gdt_descr.size = GDT_SIZE - 1;
11950 load_gdt(&gdt_descr);
11951 /* Reload the per-cpu base */
11952 @@ -840,6 +786,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
11953 /* Filter out anything that depends on CPUID levels we don't have */
11954 filter_cpuid_features(c, true);
11955
11956 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
11957 + setup_clear_cpu_cap(X86_FEATURE_SEP);
11958 +#endif
11959 +
11960 /* If the model name is still unset, do table lookup. */
11961 if (!c->x86_model_id[0]) {
11962 const char *p;
11963 @@ -1019,6 +969,9 @@ static __init int setup_disablecpuid(char *arg)
11964 }
11965 __setup("clearcpuid=", setup_disablecpuid);
11966
11967 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
11968 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
11969 +
11970 #ifdef CONFIG_X86_64
11971 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
11972
11973 @@ -1034,7 +987,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
11974 EXPORT_PER_CPU_SYMBOL(current_task);
11975
11976 DEFINE_PER_CPU(unsigned long, kernel_stack) =
11977 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
11978 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
11979 EXPORT_PER_CPU_SYMBOL(kernel_stack);
11980
11981 DEFINE_PER_CPU(char *, irq_stack_ptr) =
11982 @@ -1099,7 +1052,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
11983 {
11984 memset(regs, 0, sizeof(struct pt_regs));
11985 regs->fs = __KERNEL_PERCPU;
11986 - regs->gs = __KERNEL_STACK_CANARY;
11987 + savesegment(gs, regs->gs);
11988
11989 return regs;
11990 }
11991 @@ -1154,7 +1107,7 @@ void __cpuinit cpu_init(void)
11992 int i;
11993
11994 cpu = stack_smp_processor_id();
11995 - t = &per_cpu(init_tss, cpu);
11996 + t = init_tss + cpu;
11997 oist = &per_cpu(orig_ist, cpu);
11998
11999 #ifdef CONFIG_NUMA
12000 @@ -1180,7 +1133,7 @@ void __cpuinit cpu_init(void)
12001 switch_to_new_gdt(cpu);
12002 loadsegment(fs, 0);
12003
12004 - load_idt((const struct desc_ptr *)&idt_descr);
12005 + load_idt(&idt_descr);
12006
12007 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
12008 syscall_init();
12009 @@ -1189,7 +1142,6 @@ void __cpuinit cpu_init(void)
12010 wrmsrl(MSR_KERNEL_GS_BASE, 0);
12011 barrier();
12012
12013 - x86_configure_nx();
12014 if (cpu != 0)
12015 enable_x2apic();
12016
12017 @@ -1243,7 +1195,7 @@ void __cpuinit cpu_init(void)
12018 {
12019 int cpu = smp_processor_id();
12020 struct task_struct *curr = current;
12021 - struct tss_struct *t = &per_cpu(init_tss, cpu);
12022 + struct tss_struct *t = init_tss + cpu;
12023 struct thread_struct *thread = &curr->thread;
12024
12025 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
12026 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
12027 index ed6086e..a1dcf29 100644
12028 --- a/arch/x86/kernel/cpu/intel.c
12029 +++ b/arch/x86/kernel/cpu/intel.c
12030 @@ -172,7 +172,7 @@ static void __cpuinit trap_init_f00f_bug(void)
12031 * Update the IDT descriptor and reload the IDT so that
12032 * it uses the read-only mapped virtual address.
12033 */
12034 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
12035 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
12036 load_idt(&idt_descr);
12037 }
12038 #endif
12039 diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
12040 index 0ed633c..82cef2a 100644
12041 --- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
12042 +++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
12043 @@ -215,7 +215,9 @@ static int inject_init(void)
12044 if (!alloc_cpumask_var(&mce_inject_cpumask, GFP_KERNEL))
12045 return -ENOMEM;
12046 printk(KERN_INFO "Machine check injector initialized\n");
12047 - mce_chrdev_ops.write = mce_write;
12048 + pax_open_kernel();
12049 + *(void **)&mce_chrdev_ops.write = mce_write;
12050 + pax_close_kernel();
12051 register_die_notifier(&mce_raise_nb);
12052 return 0;
12053 }
12054 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
12055 index 08363b0..ee26113 100644
12056 --- a/arch/x86/kernel/cpu/mcheck/mce.c
12057 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
12058 @@ -42,6 +42,7 @@
12059 #include <asm/processor.h>
12060 #include <asm/mce.h>
12061 #include <asm/msr.h>
12062 +#include <asm/local.h>
12063
12064 #include "mce-internal.h"
12065
12066 @@ -205,7 +206,7 @@ static void print_mce(struct mce *m)
12067 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
12068 m->cs, m->ip);
12069
12070 - if (m->cs == __KERNEL_CS)
12071 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
12072 print_symbol("{%s}", m->ip);
12073 pr_cont("\n");
12074 }
12075 @@ -233,10 +234,10 @@ static void print_mce(struct mce *m)
12076
12077 #define PANIC_TIMEOUT 5 /* 5 seconds */
12078
12079 -static atomic_t mce_paniced;
12080 +static atomic_unchecked_t mce_paniced;
12081
12082 static int fake_panic;
12083 -static atomic_t mce_fake_paniced;
12084 +static atomic_unchecked_t mce_fake_paniced;
12085
12086 /* Panic in progress. Enable interrupts and wait for final IPI */
12087 static void wait_for_panic(void)
12088 @@ -260,7 +261,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
12089 /*
12090 * Make sure only one CPU runs in machine check panic
12091 */
12092 - if (atomic_inc_return(&mce_paniced) > 1)
12093 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
12094 wait_for_panic();
12095 barrier();
12096
12097 @@ -268,7 +269,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
12098 console_verbose();
12099 } else {
12100 /* Don't log too much for fake panic */
12101 - if (atomic_inc_return(&mce_fake_paniced) > 1)
12102 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
12103 return;
12104 }
12105 /* First print corrected ones that are still unlogged */
12106 @@ -610,7 +611,7 @@ static int mce_timed_out(u64 *t)
12107 * might have been modified by someone else.
12108 */
12109 rmb();
12110 - if (atomic_read(&mce_paniced))
12111 + if (atomic_read_unchecked(&mce_paniced))
12112 wait_for_panic();
12113 if (!monarch_timeout)
12114 goto out;
12115 @@ -1392,7 +1393,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
12116 }
12117
12118 /* Call the installed machine check handler for this CPU setup. */
12119 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
12120 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
12121 unexpected_machine_check;
12122
12123 /*
12124 @@ -1415,7 +1416,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
12125 return;
12126 }
12127
12128 + pax_open_kernel();
12129 machine_check_vector = do_machine_check;
12130 + pax_close_kernel();
12131
12132 __mcheck_cpu_init_generic();
12133 __mcheck_cpu_init_vendor(c);
12134 @@ -1429,7 +1432,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
12135 */
12136
12137 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
12138 -static int mce_chrdev_open_count; /* #times opened */
12139 +static local_t mce_chrdev_open_count; /* #times opened */
12140 static int mce_chrdev_open_exclu; /* already open exclusive? */
12141
12142 static int mce_chrdev_open(struct inode *inode, struct file *file)
12143 @@ -1437,7 +1440,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
12144 spin_lock(&mce_chrdev_state_lock);
12145
12146 if (mce_chrdev_open_exclu ||
12147 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
12148 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
12149 spin_unlock(&mce_chrdev_state_lock);
12150
12151 return -EBUSY;
12152 @@ -1445,7 +1448,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
12153
12154 if (file->f_flags & O_EXCL)
12155 mce_chrdev_open_exclu = 1;
12156 - mce_chrdev_open_count++;
12157 + local_inc(&mce_chrdev_open_count);
12158
12159 spin_unlock(&mce_chrdev_state_lock);
12160
12161 @@ -1456,7 +1459,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
12162 {
12163 spin_lock(&mce_chrdev_state_lock);
12164
12165 - mce_chrdev_open_count--;
12166 + local_dec(&mce_chrdev_open_count);
12167 mce_chrdev_open_exclu = 0;
12168
12169 spin_unlock(&mce_chrdev_state_lock);
12170 @@ -2147,7 +2150,7 @@ struct dentry *mce_get_debugfs_dir(void)
12171 static void mce_reset(void)
12172 {
12173 cpu_missing = 0;
12174 - atomic_set(&mce_fake_paniced, 0);
12175 + atomic_set_unchecked(&mce_fake_paniced, 0);
12176 atomic_set(&mce_executing, 0);
12177 atomic_set(&mce_callin, 0);
12178 atomic_set(&global_nwo, 0);
12179 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
12180 index 5c0e653..1e82c7c 100644
12181 --- a/arch/x86/kernel/cpu/mcheck/p5.c
12182 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
12183 @@ -50,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
12184 if (!cpu_has(c, X86_FEATURE_MCE))
12185 return;
12186
12187 + pax_open_kernel();
12188 machine_check_vector = pentium_machine_check;
12189 + pax_close_kernel();
12190 /* Make sure the vector pointer is visible before we enable MCEs: */
12191 wmb();
12192
12193 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
12194 index 54060f5..e6ba93d 100644
12195 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
12196 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
12197 @@ -24,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
12198 {
12199 u32 lo, hi;
12200
12201 + pax_open_kernel();
12202 machine_check_vector = winchip_machine_check;
12203 + pax_close_kernel();
12204 /* Make sure the vector pointer is visible before we enable MCEs: */
12205 wmb();
12206
12207 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
12208 index 6b96110..0da73eb 100644
12209 --- a/arch/x86/kernel/cpu/mtrr/main.c
12210 +++ b/arch/x86/kernel/cpu/mtrr/main.c
12211 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
12212 u64 size_or_mask, size_and_mask;
12213 static bool mtrr_aps_delayed_init;
12214
12215 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
12216 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
12217
12218 const struct mtrr_ops *mtrr_if;
12219
12220 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
12221 index df5e41f..816c719 100644
12222 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
12223 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
12224 @@ -25,7 +25,7 @@ struct mtrr_ops {
12225 int (*validate_add_page)(unsigned long base, unsigned long size,
12226 unsigned int type);
12227 int (*have_wrcomb)(void);
12228 -};
12229 +} __do_const;
12230
12231 extern int generic_get_free_region(unsigned long base, unsigned long size,
12232 int replace_reg);
12233 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
12234 index cfa62ec..9250dd7 100644
12235 --- a/arch/x86/kernel/cpu/perf_event.c
12236 +++ b/arch/x86/kernel/cpu/perf_event.c
12237 @@ -795,6 +795,8 @@ static int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign)
12238 int i, j, w, wmax, num = 0;
12239 struct hw_perf_event *hwc;
12240
12241 + pax_track_stack();
12242 +
12243 bitmap_zero(used_mask, X86_PMC_IDX_MAX);
12244
12245 for (i = 0; i < n; i++) {
12246 @@ -1919,7 +1921,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
12247 break;
12248
12249 perf_callchain_store(entry, frame.return_address);
12250 - fp = frame.next_frame;
12251 + fp = (const void __force_user *)frame.next_frame;
12252 }
12253 }
12254
12255 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
12256 index 764c7c2..c5d9c7b 100644
12257 --- a/arch/x86/kernel/crash.c
12258 +++ b/arch/x86/kernel/crash.c
12259 @@ -42,7 +42,7 @@ static void kdump_nmi_callback(int cpu, struct die_args *args)
12260 regs = args->regs;
12261
12262 #ifdef CONFIG_X86_32
12263 - if (!user_mode_vm(regs)) {
12264 + if (!user_mode(regs)) {
12265 crash_fixup_ss_esp(&fixed_regs, regs);
12266 regs = &fixed_regs;
12267 }
12268 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
12269 index 37250fe..bf2ec74 100644
12270 --- a/arch/x86/kernel/doublefault_32.c
12271 +++ b/arch/x86/kernel/doublefault_32.c
12272 @@ -11,7 +11,7 @@
12273
12274 #define DOUBLEFAULT_STACKSIZE (1024)
12275 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
12276 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
12277 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
12278
12279 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
12280
12281 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
12282 unsigned long gdt, tss;
12283
12284 store_gdt(&gdt_desc);
12285 - gdt = gdt_desc.address;
12286 + gdt = (unsigned long)gdt_desc.address;
12287
12288 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
12289
12290 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
12291 /* 0x2 bit is always set */
12292 .flags = X86_EFLAGS_SF | 0x2,
12293 .sp = STACK_START,
12294 - .es = __USER_DS,
12295 + .es = __KERNEL_DS,
12296 .cs = __KERNEL_CS,
12297 .ss = __KERNEL_DS,
12298 - .ds = __USER_DS,
12299 + .ds = __KERNEL_DS,
12300 .fs = __KERNEL_PERCPU,
12301
12302 .__cr3 = __pa_nodebug(swapper_pg_dir),
12303 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
12304 index 1aae78f..aab3a3d 100644
12305 --- a/arch/x86/kernel/dumpstack.c
12306 +++ b/arch/x86/kernel/dumpstack.c
12307 @@ -2,6 +2,9 @@
12308 * Copyright (C) 1991, 1992 Linus Torvalds
12309 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
12310 */
12311 +#ifdef CONFIG_GRKERNSEC_HIDESYM
12312 +#define __INCLUDED_BY_HIDESYM 1
12313 +#endif
12314 #include <linux/kallsyms.h>
12315 #include <linux/kprobes.h>
12316 #include <linux/uaccess.h>
12317 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
12318 static void
12319 print_ftrace_graph_addr(unsigned long addr, void *data,
12320 const struct stacktrace_ops *ops,
12321 - struct thread_info *tinfo, int *graph)
12322 + struct task_struct *task, int *graph)
12323 {
12324 - struct task_struct *task = tinfo->task;
12325 unsigned long ret_addr;
12326 int index = task->curr_ret_stack;
12327
12328 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
12329 static inline void
12330 print_ftrace_graph_addr(unsigned long addr, void *data,
12331 const struct stacktrace_ops *ops,
12332 - struct thread_info *tinfo, int *graph)
12333 + struct task_struct *task, int *graph)
12334 { }
12335 #endif
12336
12337 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
12338 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
12339 */
12340
12341 -static inline int valid_stack_ptr(struct thread_info *tinfo,
12342 - void *p, unsigned int size, void *end)
12343 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
12344 {
12345 - void *t = tinfo;
12346 if (end) {
12347 if (p < end && p >= (end-THREAD_SIZE))
12348 return 1;
12349 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
12350 }
12351
12352 unsigned long
12353 -print_context_stack(struct thread_info *tinfo,
12354 +print_context_stack(struct task_struct *task, void *stack_start,
12355 unsigned long *stack, unsigned long bp,
12356 const struct stacktrace_ops *ops, void *data,
12357 unsigned long *end, int *graph)
12358 {
12359 struct stack_frame *frame = (struct stack_frame *)bp;
12360
12361 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
12362 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
12363 unsigned long addr;
12364
12365 addr = *stack;
12366 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
12367 } else {
12368 ops->address(data, addr, 0);
12369 }
12370 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12371 + print_ftrace_graph_addr(addr, data, ops, task, graph);
12372 }
12373 stack++;
12374 }
12375 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
12376 EXPORT_SYMBOL_GPL(print_context_stack);
12377
12378 unsigned long
12379 -print_context_stack_bp(struct thread_info *tinfo,
12380 +print_context_stack_bp(struct task_struct *task, void *stack_start,
12381 unsigned long *stack, unsigned long bp,
12382 const struct stacktrace_ops *ops, void *data,
12383 unsigned long *end, int *graph)
12384 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
12385 struct stack_frame *frame = (struct stack_frame *)bp;
12386 unsigned long *ret_addr = &frame->return_address;
12387
12388 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
12389 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
12390 unsigned long addr = *ret_addr;
12391
12392 if (!__kernel_text_address(addr))
12393 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
12394 ops->address(data, addr, 1);
12395 frame = frame->next_frame;
12396 ret_addr = &frame->return_address;
12397 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12398 + print_ftrace_graph_addr(addr, data, ops, task, graph);
12399 }
12400
12401 return (unsigned long)frame;
12402 @@ -186,7 +186,7 @@ void dump_stack(void)
12403
12404 bp = stack_frame(current, NULL);
12405 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
12406 - current->pid, current->comm, print_tainted(),
12407 + task_pid_nr(current), current->comm, print_tainted(),
12408 init_utsname()->release,
12409 (int)strcspn(init_utsname()->version, " "),
12410 init_utsname()->version);
12411 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
12412 }
12413 EXPORT_SYMBOL_GPL(oops_begin);
12414
12415 +extern void gr_handle_kernel_exploit(void);
12416 +
12417 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12418 {
12419 if (regs && kexec_should_crash(current))
12420 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12421 panic("Fatal exception in interrupt");
12422 if (panic_on_oops)
12423 panic("Fatal exception");
12424 - do_exit(signr);
12425 +
12426 + gr_handle_kernel_exploit();
12427 +
12428 + do_group_exit(signr);
12429 }
12430
12431 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12432 @@ -269,7 +274,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12433
12434 show_registers(regs);
12435 #ifdef CONFIG_X86_32
12436 - if (user_mode_vm(regs)) {
12437 + if (user_mode(regs)) {
12438 sp = regs->sp;
12439 ss = regs->ss & 0xffff;
12440 } else {
12441 @@ -297,7 +302,7 @@ void die(const char *str, struct pt_regs *regs, long err)
12442 unsigned long flags = oops_begin();
12443 int sig = SIGSEGV;
12444
12445 - if (!user_mode_vm(regs))
12446 + if (!user_mode(regs))
12447 report_bug(regs->ip, regs);
12448
12449 if (__die(str, regs, err))
12450 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
12451 index 3b97a80..667ce7a 100644
12452 --- a/arch/x86/kernel/dumpstack_32.c
12453 +++ b/arch/x86/kernel/dumpstack_32.c
12454 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12455 bp = stack_frame(task, regs);
12456
12457 for (;;) {
12458 - struct thread_info *context;
12459 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12460
12461 - context = (struct thread_info *)
12462 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
12463 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
12464 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12465
12466 - stack = (unsigned long *)context->previous_esp;
12467 - if (!stack)
12468 + if (stack_start == task_stack_page(task))
12469 break;
12470 + stack = *(unsigned long **)stack_start;
12471 if (ops->stack(data, "IRQ") < 0)
12472 break;
12473 touch_nmi_watchdog();
12474 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
12475 * When in-kernel, we also print out the stack and code at the
12476 * time of the fault..
12477 */
12478 - if (!user_mode_vm(regs)) {
12479 + if (!user_mode(regs)) {
12480 unsigned int code_prologue = code_bytes * 43 / 64;
12481 unsigned int code_len = code_bytes;
12482 unsigned char c;
12483 u8 *ip;
12484 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
12485
12486 printk(KERN_EMERG "Stack:\n");
12487 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
12488
12489 printk(KERN_EMERG "Code: ");
12490
12491 - ip = (u8 *)regs->ip - code_prologue;
12492 + ip = (u8 *)regs->ip - code_prologue + cs_base;
12493 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
12494 /* try starting at IP */
12495 - ip = (u8 *)regs->ip;
12496 + ip = (u8 *)regs->ip + cs_base;
12497 code_len = code_len - code_prologue + 1;
12498 }
12499 for (i = 0; i < code_len; i++, ip++) {
12500 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
12501 printk(" Bad EIP value.");
12502 break;
12503 }
12504 - if (ip == (u8 *)regs->ip)
12505 + if (ip == (u8 *)regs->ip + cs_base)
12506 printk("<%02x> ", c);
12507 else
12508 printk("%02x ", c);
12509 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
12510 {
12511 unsigned short ud2;
12512
12513 + ip = ktla_ktva(ip);
12514 if (ip < PAGE_OFFSET)
12515 return 0;
12516 if (probe_kernel_address((unsigned short *)ip, ud2))
12517 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
12518
12519 return ud2 == 0x0b0f;
12520 }
12521 +
12522 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12523 +void pax_check_alloca(unsigned long size)
12524 +{
12525 + unsigned long sp = (unsigned long)&sp, stack_left;
12526 +
12527 + /* all kernel stacks are of the same size */
12528 + stack_left = sp & (THREAD_SIZE - 1);
12529 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12530 +}
12531 +EXPORT_SYMBOL(pax_check_alloca);
12532 +#endif
12533 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
12534 index 19853ad..508ca79 100644
12535 --- a/arch/x86/kernel/dumpstack_64.c
12536 +++ b/arch/x86/kernel/dumpstack_64.c
12537 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12538 unsigned long *irq_stack_end =
12539 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
12540 unsigned used = 0;
12541 - struct thread_info *tinfo;
12542 int graph = 0;
12543 unsigned long dummy;
12544 + void *stack_start;
12545
12546 if (!task)
12547 task = current;
12548 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12549 * current stack address. If the stacks consist of nested
12550 * exceptions
12551 */
12552 - tinfo = task_thread_info(task);
12553 for (;;) {
12554 char *id;
12555 unsigned long *estack_end;
12556 +
12557 estack_end = in_exception_stack(cpu, (unsigned long)stack,
12558 &used, &id);
12559
12560 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12561 if (ops->stack(data, id) < 0)
12562 break;
12563
12564 - bp = ops->walk_stack(tinfo, stack, bp, ops,
12565 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
12566 data, estack_end, &graph);
12567 ops->stack(data, "<EOE>");
12568 /*
12569 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12570 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
12571 if (ops->stack(data, "IRQ") < 0)
12572 break;
12573 - bp = ops->walk_stack(tinfo, stack, bp,
12574 + bp = ops->walk_stack(task, irq_stack, stack, bp,
12575 ops, data, irq_stack_end, &graph);
12576 /*
12577 * We link to the next stack (which would be
12578 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12579 /*
12580 * This handles the process stack:
12581 */
12582 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
12583 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12584 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12585 put_cpu();
12586 }
12587 EXPORT_SYMBOL(dump_trace);
12588 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
12589
12590 return ud2 == 0x0b0f;
12591 }
12592 +
12593 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12594 +void pax_check_alloca(unsigned long size)
12595 +{
12596 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
12597 + unsigned cpu, used;
12598 + char *id;
12599 +
12600 + /* check the process stack first */
12601 + stack_start = (unsigned long)task_stack_page(current);
12602 + stack_end = stack_start + THREAD_SIZE;
12603 + if (likely(stack_start <= sp && sp < stack_end)) {
12604 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
12605 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12606 + return;
12607 + }
12608 +
12609 + cpu = get_cpu();
12610 +
12611 + /* check the irq stacks */
12612 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
12613 + stack_start = stack_end - IRQ_STACK_SIZE;
12614 + if (stack_start <= sp && sp < stack_end) {
12615 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
12616 + put_cpu();
12617 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12618 + return;
12619 + }
12620 +
12621 + /* check the exception stacks */
12622 + used = 0;
12623 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
12624 + stack_start = stack_end - EXCEPTION_STKSZ;
12625 + if (stack_end && stack_start <= sp && sp < stack_end) {
12626 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
12627 + put_cpu();
12628 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12629 + return;
12630 + }
12631 +
12632 + put_cpu();
12633 +
12634 + /* unknown stack */
12635 + BUG();
12636 +}
12637 +EXPORT_SYMBOL(pax_check_alloca);
12638 +#endif
12639 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
12640 index cd28a35..2601699 100644
12641 --- a/arch/x86/kernel/early_printk.c
12642 +++ b/arch/x86/kernel/early_printk.c
12643 @@ -7,6 +7,7 @@
12644 #include <linux/pci_regs.h>
12645 #include <linux/pci_ids.h>
12646 #include <linux/errno.h>
12647 +#include <linux/sched.h>
12648 #include <asm/io.h>
12649 #include <asm/processor.h>
12650 #include <asm/fcntl.h>
12651 @@ -179,6 +180,8 @@ asmlinkage void early_printk(const char *fmt, ...)
12652 int n;
12653 va_list ap;
12654
12655 + pax_track_stack();
12656 +
12657 va_start(ap, fmt);
12658 n = vscnprintf(buf, sizeof(buf), fmt, ap);
12659 early_console->write(early_console, buf, n);
12660 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
12661 index f3f6f53..0841b66 100644
12662 --- a/arch/x86/kernel/entry_32.S
12663 +++ b/arch/x86/kernel/entry_32.S
12664 @@ -186,13 +186,146 @@
12665 /*CFI_REL_OFFSET gs, PT_GS*/
12666 .endm
12667 .macro SET_KERNEL_GS reg
12668 +
12669 +#ifdef CONFIG_CC_STACKPROTECTOR
12670 movl $(__KERNEL_STACK_CANARY), \reg
12671 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
12672 + movl $(__USER_DS), \reg
12673 +#else
12674 + xorl \reg, \reg
12675 +#endif
12676 +
12677 movl \reg, %gs
12678 .endm
12679
12680 #endif /* CONFIG_X86_32_LAZY_GS */
12681
12682 -.macro SAVE_ALL
12683 +.macro pax_enter_kernel
12684 +#ifdef CONFIG_PAX_KERNEXEC
12685 + call pax_enter_kernel
12686 +#endif
12687 +.endm
12688 +
12689 +.macro pax_exit_kernel
12690 +#ifdef CONFIG_PAX_KERNEXEC
12691 + call pax_exit_kernel
12692 +#endif
12693 +.endm
12694 +
12695 +#ifdef CONFIG_PAX_KERNEXEC
12696 +ENTRY(pax_enter_kernel)
12697 +#ifdef CONFIG_PARAVIRT
12698 + pushl %eax
12699 + pushl %ecx
12700 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
12701 + mov %eax, %esi
12702 +#else
12703 + mov %cr0, %esi
12704 +#endif
12705 + bts $16, %esi
12706 + jnc 1f
12707 + mov %cs, %esi
12708 + cmp $__KERNEL_CS, %esi
12709 + jz 3f
12710 + ljmp $__KERNEL_CS, $3f
12711 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
12712 +2:
12713 +#ifdef CONFIG_PARAVIRT
12714 + mov %esi, %eax
12715 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12716 +#else
12717 + mov %esi, %cr0
12718 +#endif
12719 +3:
12720 +#ifdef CONFIG_PARAVIRT
12721 + popl %ecx
12722 + popl %eax
12723 +#endif
12724 + ret
12725 +ENDPROC(pax_enter_kernel)
12726 +
12727 +ENTRY(pax_exit_kernel)
12728 +#ifdef CONFIG_PARAVIRT
12729 + pushl %eax
12730 + pushl %ecx
12731 +#endif
12732 + mov %cs, %esi
12733 + cmp $__KERNEXEC_KERNEL_CS, %esi
12734 + jnz 2f
12735 +#ifdef CONFIG_PARAVIRT
12736 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
12737 + mov %eax, %esi
12738 +#else
12739 + mov %cr0, %esi
12740 +#endif
12741 + btr $16, %esi
12742 + ljmp $__KERNEL_CS, $1f
12743 +1:
12744 +#ifdef CONFIG_PARAVIRT
12745 + mov %esi, %eax
12746 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
12747 +#else
12748 + mov %esi, %cr0
12749 +#endif
12750 +2:
12751 +#ifdef CONFIG_PARAVIRT
12752 + popl %ecx
12753 + popl %eax
12754 +#endif
12755 + ret
12756 +ENDPROC(pax_exit_kernel)
12757 +#endif
12758 +
12759 +.macro pax_erase_kstack
12760 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12761 + call pax_erase_kstack
12762 +#endif
12763 +.endm
12764 +
12765 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12766 +/*
12767 + * ebp: thread_info
12768 + * ecx, edx: can be clobbered
12769 + */
12770 +ENTRY(pax_erase_kstack)
12771 + pushl %edi
12772 + pushl %eax
12773 +
12774 + mov TI_lowest_stack(%ebp), %edi
12775 + mov $-0xBEEF, %eax
12776 + std
12777 +
12778 +1: mov %edi, %ecx
12779 + and $THREAD_SIZE_asm - 1, %ecx
12780 + shr $2, %ecx
12781 + repne scasl
12782 + jecxz 2f
12783 +
12784 + cmp $2*16, %ecx
12785 + jc 2f
12786 +
12787 + mov $2*16, %ecx
12788 + repe scasl
12789 + jecxz 2f
12790 + jne 1b
12791 +
12792 +2: cld
12793 + mov %esp, %ecx
12794 + sub %edi, %ecx
12795 + shr $2, %ecx
12796 + rep stosl
12797 +
12798 + mov TI_task_thread_sp0(%ebp), %edi
12799 + sub $128, %edi
12800 + mov %edi, TI_lowest_stack(%ebp)
12801 +
12802 + popl %eax
12803 + popl %edi
12804 + ret
12805 +ENDPROC(pax_erase_kstack)
12806 +#endif
12807 +
12808 +.macro __SAVE_ALL _DS
12809 cld
12810 PUSH_GS
12811 pushl_cfi %fs
12812 @@ -215,7 +348,7 @@
12813 CFI_REL_OFFSET ecx, 0
12814 pushl_cfi %ebx
12815 CFI_REL_OFFSET ebx, 0
12816 - movl $(__USER_DS), %edx
12817 + movl $\_DS, %edx
12818 movl %edx, %ds
12819 movl %edx, %es
12820 movl $(__KERNEL_PERCPU), %edx
12821 @@ -223,6 +356,15 @@
12822 SET_KERNEL_GS %edx
12823 .endm
12824
12825 +.macro SAVE_ALL
12826 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
12827 + __SAVE_ALL __KERNEL_DS
12828 + pax_enter_kernel
12829 +#else
12830 + __SAVE_ALL __USER_DS
12831 +#endif
12832 +.endm
12833 +
12834 .macro RESTORE_INT_REGS
12835 popl_cfi %ebx
12836 CFI_RESTORE ebx
12837 @@ -308,7 +450,7 @@ ENTRY(ret_from_fork)
12838 popfl_cfi
12839 jmp syscall_exit
12840 CFI_ENDPROC
12841 -END(ret_from_fork)
12842 +ENDPROC(ret_from_fork)
12843
12844 /*
12845 * Interrupt exit functions should be protected against kprobes
12846 @@ -333,7 +475,15 @@ check_userspace:
12847 movb PT_CS(%esp), %al
12848 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
12849 cmpl $USER_RPL, %eax
12850 +
12851 +#ifdef CONFIG_PAX_KERNEXEC
12852 + jae resume_userspace
12853 +
12854 + PAX_EXIT_KERNEL
12855 + jmp resume_kernel
12856 +#else
12857 jb resume_kernel # not returning to v8086 or userspace
12858 +#endif
12859
12860 ENTRY(resume_userspace)
12861 LOCKDEP_SYS_EXIT
12862 @@ -345,8 +495,8 @@ ENTRY(resume_userspace)
12863 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
12864 # int/exception return?
12865 jne work_pending
12866 - jmp restore_all
12867 -END(ret_from_exception)
12868 + jmp restore_all_pax
12869 +ENDPROC(ret_from_exception)
12870
12871 #ifdef CONFIG_PREEMPT
12872 ENTRY(resume_kernel)
12873 @@ -361,7 +511,7 @@ need_resched:
12874 jz restore_all
12875 call preempt_schedule_irq
12876 jmp need_resched
12877 -END(resume_kernel)
12878 +ENDPROC(resume_kernel)
12879 #endif
12880 CFI_ENDPROC
12881 /*
12882 @@ -395,23 +545,34 @@ sysenter_past_esp:
12883 /*CFI_REL_OFFSET cs, 0*/
12884 /*
12885 * Push current_thread_info()->sysenter_return to the stack.
12886 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
12887 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
12888 */
12889 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
12890 + pushl_cfi $0
12891 CFI_REL_OFFSET eip, 0
12892
12893 pushl_cfi %eax
12894 SAVE_ALL
12895 + GET_THREAD_INFO(%ebp)
12896 + movl TI_sysenter_return(%ebp),%ebp
12897 + movl %ebp,PT_EIP(%esp)
12898 ENABLE_INTERRUPTS(CLBR_NONE)
12899
12900 /*
12901 * Load the potential sixth argument from user stack.
12902 * Careful about security.
12903 */
12904 + movl PT_OLDESP(%esp),%ebp
12905 +
12906 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12907 + mov PT_OLDSS(%esp),%ds
12908 +1: movl %ds:(%ebp),%ebp
12909 + push %ss
12910 + pop %ds
12911 +#else
12912 cmpl $__PAGE_OFFSET-3,%ebp
12913 jae syscall_fault
12914 1: movl (%ebp),%ebp
12915 +#endif
12916 +
12917 movl %ebp,PT_EBP(%esp)
12918 .section __ex_table,"a"
12919 .align 4
12920 @@ -434,12 +595,24 @@ sysenter_do_call:
12921 testl $_TIF_ALLWORK_MASK, %ecx
12922 jne sysexit_audit
12923 sysenter_exit:
12924 +
12925 +#ifdef CONFIG_PAX_RANDKSTACK
12926 + pushl_cfi %eax
12927 + movl %esp, %eax
12928 + call pax_randomize_kstack
12929 + popl_cfi %eax
12930 +#endif
12931 +
12932 + pax_erase_kstack
12933 +
12934 /* if something modifies registers it must also disable sysexit */
12935 movl PT_EIP(%esp), %edx
12936 movl PT_OLDESP(%esp), %ecx
12937 xorl %ebp,%ebp
12938 TRACE_IRQS_ON
12939 1: mov PT_FS(%esp), %fs
12940 +2: mov PT_DS(%esp), %ds
12941 +3: mov PT_ES(%esp), %es
12942 PTGS_TO_GS
12943 ENABLE_INTERRUPTS_SYSEXIT
12944
12945 @@ -456,6 +629,9 @@ sysenter_audit:
12946 movl %eax,%edx /* 2nd arg: syscall number */
12947 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
12948 call audit_syscall_entry
12949 +
12950 + pax_erase_kstack
12951 +
12952 pushl_cfi %ebx
12953 movl PT_EAX(%esp),%eax /* reload syscall number */
12954 jmp sysenter_do_call
12955 @@ -482,11 +658,17 @@ sysexit_audit:
12956
12957 CFI_ENDPROC
12958 .pushsection .fixup,"ax"
12959 -2: movl $0,PT_FS(%esp)
12960 +4: movl $0,PT_FS(%esp)
12961 + jmp 1b
12962 +5: movl $0,PT_DS(%esp)
12963 + jmp 1b
12964 +6: movl $0,PT_ES(%esp)
12965 jmp 1b
12966 .section __ex_table,"a"
12967 .align 4
12968 - .long 1b,2b
12969 + .long 1b,4b
12970 + .long 2b,5b
12971 + .long 3b,6b
12972 .popsection
12973 PTGS_TO_GS_EX
12974 ENDPROC(ia32_sysenter_target)
12975 @@ -519,6 +701,15 @@ syscall_exit:
12976 testl $_TIF_ALLWORK_MASK, %ecx # current->work
12977 jne syscall_exit_work
12978
12979 +restore_all_pax:
12980 +
12981 +#ifdef CONFIG_PAX_RANDKSTACK
12982 + movl %esp, %eax
12983 + call pax_randomize_kstack
12984 +#endif
12985 +
12986 + pax_erase_kstack
12987 +
12988 restore_all:
12989 TRACE_IRQS_IRET
12990 restore_all_notrace:
12991 @@ -578,14 +769,34 @@ ldt_ss:
12992 * compensating for the offset by changing to the ESPFIX segment with
12993 * a base address that matches for the difference.
12994 */
12995 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
12996 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
12997 mov %esp, %edx /* load kernel esp */
12998 mov PT_OLDESP(%esp), %eax /* load userspace esp */
12999 mov %dx, %ax /* eax: new kernel esp */
13000 sub %eax, %edx /* offset (low word is 0) */
13001 +#ifdef CONFIG_SMP
13002 + movl PER_CPU_VAR(cpu_number), %ebx
13003 + shll $PAGE_SHIFT_asm, %ebx
13004 + addl $cpu_gdt_table, %ebx
13005 +#else
13006 + movl $cpu_gdt_table, %ebx
13007 +#endif
13008 shr $16, %edx
13009 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
13010 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
13011 +
13012 +#ifdef CONFIG_PAX_KERNEXEC
13013 + mov %cr0, %esi
13014 + btr $16, %esi
13015 + mov %esi, %cr0
13016 +#endif
13017 +
13018 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
13019 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
13020 +
13021 +#ifdef CONFIG_PAX_KERNEXEC
13022 + bts $16, %esi
13023 + mov %esi, %cr0
13024 +#endif
13025 +
13026 pushl_cfi $__ESPFIX_SS
13027 pushl_cfi %eax /* new kernel esp */
13028 /* Disable interrupts, but do not irqtrace this section: we
13029 @@ -614,34 +825,28 @@ work_resched:
13030 movl TI_flags(%ebp), %ecx
13031 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
13032 # than syscall tracing?
13033 - jz restore_all
13034 + jz restore_all_pax
13035 testb $_TIF_NEED_RESCHED, %cl
13036 jnz work_resched
13037
13038 work_notifysig: # deal with pending signals and
13039 # notify-resume requests
13040 + movl %esp, %eax
13041 #ifdef CONFIG_VM86
13042 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
13043 - movl %esp, %eax
13044 - jne work_notifysig_v86 # returning to kernel-space or
13045 + jz 1f # returning to kernel-space or
13046 # vm86-space
13047 - xorl %edx, %edx
13048 - call do_notify_resume
13049 - jmp resume_userspace_sig
13050
13051 - ALIGN
13052 -work_notifysig_v86:
13053 pushl_cfi %ecx # save ti_flags for do_notify_resume
13054 call save_v86_state # %eax contains pt_regs pointer
13055 popl_cfi %ecx
13056 movl %eax, %esp
13057 -#else
13058 - movl %esp, %eax
13059 +1:
13060 #endif
13061 xorl %edx, %edx
13062 call do_notify_resume
13063 jmp resume_userspace_sig
13064 -END(work_pending)
13065 +ENDPROC(work_pending)
13066
13067 # perform syscall exit tracing
13068 ALIGN
13069 @@ -649,11 +854,14 @@ syscall_trace_entry:
13070 movl $-ENOSYS,PT_EAX(%esp)
13071 movl %esp, %eax
13072 call syscall_trace_enter
13073 +
13074 + pax_erase_kstack
13075 +
13076 /* What it returned is what we'll actually use. */
13077 cmpl $(nr_syscalls), %eax
13078 jnae syscall_call
13079 jmp syscall_exit
13080 -END(syscall_trace_entry)
13081 +ENDPROC(syscall_trace_entry)
13082
13083 # perform syscall exit tracing
13084 ALIGN
13085 @@ -666,20 +874,24 @@ syscall_exit_work:
13086 movl %esp, %eax
13087 call syscall_trace_leave
13088 jmp resume_userspace
13089 -END(syscall_exit_work)
13090 +ENDPROC(syscall_exit_work)
13091 CFI_ENDPROC
13092
13093 RING0_INT_FRAME # can't unwind into user space anyway
13094 syscall_fault:
13095 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13096 + push %ss
13097 + pop %ds
13098 +#endif
13099 GET_THREAD_INFO(%ebp)
13100 movl $-EFAULT,PT_EAX(%esp)
13101 jmp resume_userspace
13102 -END(syscall_fault)
13103 +ENDPROC(syscall_fault)
13104
13105 syscall_badsys:
13106 movl $-ENOSYS,PT_EAX(%esp)
13107 jmp resume_userspace
13108 -END(syscall_badsys)
13109 +ENDPROC(syscall_badsys)
13110 CFI_ENDPROC
13111 /*
13112 * End of kprobes section
13113 @@ -753,6 +965,36 @@ ptregs_clone:
13114 CFI_ENDPROC
13115 ENDPROC(ptregs_clone)
13116
13117 + ALIGN;
13118 +ENTRY(kernel_execve)
13119 + CFI_STARTPROC
13120 + pushl_cfi %ebp
13121 + sub $PT_OLDSS+4,%esp
13122 + pushl_cfi %edi
13123 + pushl_cfi %ecx
13124 + pushl_cfi %eax
13125 + lea 3*4(%esp),%edi
13126 + mov $PT_OLDSS/4+1,%ecx
13127 + xorl %eax,%eax
13128 + rep stosl
13129 + popl_cfi %eax
13130 + popl_cfi %ecx
13131 + popl_cfi %edi
13132 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
13133 + pushl_cfi %esp
13134 + call sys_execve
13135 + add $4,%esp
13136 + CFI_ADJUST_CFA_OFFSET -4
13137 + GET_THREAD_INFO(%ebp)
13138 + test %eax,%eax
13139 + jz syscall_exit
13140 + add $PT_OLDSS+4,%esp
13141 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
13142 + popl_cfi %ebp
13143 + ret
13144 + CFI_ENDPROC
13145 +ENDPROC(kernel_execve)
13146 +
13147 .macro FIXUP_ESPFIX_STACK
13148 /*
13149 * Switch back for ESPFIX stack to the normal zerobased stack
13150 @@ -762,8 +1004,15 @@ ENDPROC(ptregs_clone)
13151 * normal stack and adjusts ESP with the matching offset.
13152 */
13153 /* fixup the stack */
13154 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
13155 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
13156 +#ifdef CONFIG_SMP
13157 + movl PER_CPU_VAR(cpu_number), %ebx
13158 + shll $PAGE_SHIFT_asm, %ebx
13159 + addl $cpu_gdt_table, %ebx
13160 +#else
13161 + movl $cpu_gdt_table, %ebx
13162 +#endif
13163 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
13164 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
13165 shl $16, %eax
13166 addl %esp, %eax /* the adjusted stack pointer */
13167 pushl_cfi $__KERNEL_DS
13168 @@ -816,7 +1065,7 @@ vector=vector+1
13169 .endr
13170 2: jmp common_interrupt
13171 .endr
13172 -END(irq_entries_start)
13173 +ENDPROC(irq_entries_start)
13174
13175 .previous
13176 END(interrupt)
13177 @@ -864,7 +1113,7 @@ ENTRY(coprocessor_error)
13178 pushl_cfi $do_coprocessor_error
13179 jmp error_code
13180 CFI_ENDPROC
13181 -END(coprocessor_error)
13182 +ENDPROC(coprocessor_error)
13183
13184 ENTRY(simd_coprocessor_error)
13185 RING0_INT_FRAME
13186 @@ -885,7 +1134,7 @@ ENTRY(simd_coprocessor_error)
13187 #endif
13188 jmp error_code
13189 CFI_ENDPROC
13190 -END(simd_coprocessor_error)
13191 +ENDPROC(simd_coprocessor_error)
13192
13193 ENTRY(device_not_available)
13194 RING0_INT_FRAME
13195 @@ -893,7 +1142,7 @@ ENTRY(device_not_available)
13196 pushl_cfi $do_device_not_available
13197 jmp error_code
13198 CFI_ENDPROC
13199 -END(device_not_available)
13200 +ENDPROC(device_not_available)
13201
13202 #ifdef CONFIG_PARAVIRT
13203 ENTRY(native_iret)
13204 @@ -902,12 +1151,12 @@ ENTRY(native_iret)
13205 .align 4
13206 .long native_iret, iret_exc
13207 .previous
13208 -END(native_iret)
13209 +ENDPROC(native_iret)
13210
13211 ENTRY(native_irq_enable_sysexit)
13212 sti
13213 sysexit
13214 -END(native_irq_enable_sysexit)
13215 +ENDPROC(native_irq_enable_sysexit)
13216 #endif
13217
13218 ENTRY(overflow)
13219 @@ -916,7 +1165,7 @@ ENTRY(overflow)
13220 pushl_cfi $do_overflow
13221 jmp error_code
13222 CFI_ENDPROC
13223 -END(overflow)
13224 +ENDPROC(overflow)
13225
13226 ENTRY(bounds)
13227 RING0_INT_FRAME
13228 @@ -924,7 +1173,7 @@ ENTRY(bounds)
13229 pushl_cfi $do_bounds
13230 jmp error_code
13231 CFI_ENDPROC
13232 -END(bounds)
13233 +ENDPROC(bounds)
13234
13235 ENTRY(invalid_op)
13236 RING0_INT_FRAME
13237 @@ -932,7 +1181,7 @@ ENTRY(invalid_op)
13238 pushl_cfi $do_invalid_op
13239 jmp error_code
13240 CFI_ENDPROC
13241 -END(invalid_op)
13242 +ENDPROC(invalid_op)
13243
13244 ENTRY(coprocessor_segment_overrun)
13245 RING0_INT_FRAME
13246 @@ -940,35 +1189,35 @@ ENTRY(coprocessor_segment_overrun)
13247 pushl_cfi $do_coprocessor_segment_overrun
13248 jmp error_code
13249 CFI_ENDPROC
13250 -END(coprocessor_segment_overrun)
13251 +ENDPROC(coprocessor_segment_overrun)
13252
13253 ENTRY(invalid_TSS)
13254 RING0_EC_FRAME
13255 pushl_cfi $do_invalid_TSS
13256 jmp error_code
13257 CFI_ENDPROC
13258 -END(invalid_TSS)
13259 +ENDPROC(invalid_TSS)
13260
13261 ENTRY(segment_not_present)
13262 RING0_EC_FRAME
13263 pushl_cfi $do_segment_not_present
13264 jmp error_code
13265 CFI_ENDPROC
13266 -END(segment_not_present)
13267 +ENDPROC(segment_not_present)
13268
13269 ENTRY(stack_segment)
13270 RING0_EC_FRAME
13271 pushl_cfi $do_stack_segment
13272 jmp error_code
13273 CFI_ENDPROC
13274 -END(stack_segment)
13275 +ENDPROC(stack_segment)
13276
13277 ENTRY(alignment_check)
13278 RING0_EC_FRAME
13279 pushl_cfi $do_alignment_check
13280 jmp error_code
13281 CFI_ENDPROC
13282 -END(alignment_check)
13283 +ENDPROC(alignment_check)
13284
13285 ENTRY(divide_error)
13286 RING0_INT_FRAME
13287 @@ -976,7 +1225,7 @@ ENTRY(divide_error)
13288 pushl_cfi $do_divide_error
13289 jmp error_code
13290 CFI_ENDPROC
13291 -END(divide_error)
13292 +ENDPROC(divide_error)
13293
13294 #ifdef CONFIG_X86_MCE
13295 ENTRY(machine_check)
13296 @@ -985,7 +1234,7 @@ ENTRY(machine_check)
13297 pushl_cfi machine_check_vector
13298 jmp error_code
13299 CFI_ENDPROC
13300 -END(machine_check)
13301 +ENDPROC(machine_check)
13302 #endif
13303
13304 ENTRY(spurious_interrupt_bug)
13305 @@ -994,7 +1243,7 @@ ENTRY(spurious_interrupt_bug)
13306 pushl_cfi $do_spurious_interrupt_bug
13307 jmp error_code
13308 CFI_ENDPROC
13309 -END(spurious_interrupt_bug)
13310 +ENDPROC(spurious_interrupt_bug)
13311 /*
13312 * End of kprobes section
13313 */
13314 @@ -1109,7 +1358,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
13315
13316 ENTRY(mcount)
13317 ret
13318 -END(mcount)
13319 +ENDPROC(mcount)
13320
13321 ENTRY(ftrace_caller)
13322 cmpl $0, function_trace_stop
13323 @@ -1138,7 +1387,7 @@ ftrace_graph_call:
13324 .globl ftrace_stub
13325 ftrace_stub:
13326 ret
13327 -END(ftrace_caller)
13328 +ENDPROC(ftrace_caller)
13329
13330 #else /* ! CONFIG_DYNAMIC_FTRACE */
13331
13332 @@ -1174,7 +1423,7 @@ trace:
13333 popl %ecx
13334 popl %eax
13335 jmp ftrace_stub
13336 -END(mcount)
13337 +ENDPROC(mcount)
13338 #endif /* CONFIG_DYNAMIC_FTRACE */
13339 #endif /* CONFIG_FUNCTION_TRACER */
13340
13341 @@ -1195,7 +1444,7 @@ ENTRY(ftrace_graph_caller)
13342 popl %ecx
13343 popl %eax
13344 ret
13345 -END(ftrace_graph_caller)
13346 +ENDPROC(ftrace_graph_caller)
13347
13348 .globl return_to_handler
13349 return_to_handler:
13350 @@ -1209,7 +1458,6 @@ return_to_handler:
13351 jmp *%ecx
13352 #endif
13353
13354 -.section .rodata,"a"
13355 #include "syscall_table_32.S"
13356
13357 syscall_table_size=(.-sys_call_table)
13358 @@ -1255,15 +1503,18 @@ error_code:
13359 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
13360 REG_TO_PTGS %ecx
13361 SET_KERNEL_GS %ecx
13362 - movl $(__USER_DS), %ecx
13363 + movl $(__KERNEL_DS), %ecx
13364 movl %ecx, %ds
13365 movl %ecx, %es
13366 +
13367 + pax_enter_kernel
13368 +
13369 TRACE_IRQS_OFF
13370 movl %esp,%eax # pt_regs pointer
13371 call *%edi
13372 jmp ret_from_exception
13373 CFI_ENDPROC
13374 -END(page_fault)
13375 +ENDPROC(page_fault)
13376
13377 /*
13378 * Debug traps and NMI can happen at the one SYSENTER instruction
13379 @@ -1305,7 +1556,7 @@ debug_stack_correct:
13380 call do_debug
13381 jmp ret_from_exception
13382 CFI_ENDPROC
13383 -END(debug)
13384 +ENDPROC(debug)
13385
13386 /*
13387 * NMI is doubly nasty. It can happen _while_ we're handling
13388 @@ -1342,6 +1593,9 @@ nmi_stack_correct:
13389 xorl %edx,%edx # zero error code
13390 movl %esp,%eax # pt_regs pointer
13391 call do_nmi
13392 +
13393 + pax_exit_kernel
13394 +
13395 jmp restore_all_notrace
13396 CFI_ENDPROC
13397
13398 @@ -1378,12 +1632,15 @@ nmi_espfix_stack:
13399 FIXUP_ESPFIX_STACK # %eax == %esp
13400 xorl %edx,%edx # zero error code
13401 call do_nmi
13402 +
13403 + pax_exit_kernel
13404 +
13405 RESTORE_REGS
13406 lss 12+4(%esp), %esp # back to espfix stack
13407 CFI_ADJUST_CFA_OFFSET -24
13408 jmp irq_return
13409 CFI_ENDPROC
13410 -END(nmi)
13411 +ENDPROC(nmi)
13412
13413 ENTRY(int3)
13414 RING0_INT_FRAME
13415 @@ -1395,14 +1652,14 @@ ENTRY(int3)
13416 call do_int3
13417 jmp ret_from_exception
13418 CFI_ENDPROC
13419 -END(int3)
13420 +ENDPROC(int3)
13421
13422 ENTRY(general_protection)
13423 RING0_EC_FRAME
13424 pushl_cfi $do_general_protection
13425 jmp error_code
13426 CFI_ENDPROC
13427 -END(general_protection)
13428 +ENDPROC(general_protection)
13429
13430 #ifdef CONFIG_KVM_GUEST
13431 ENTRY(async_page_fault)
13432 @@ -1410,7 +1667,7 @@ ENTRY(async_page_fault)
13433 pushl_cfi $do_async_page_fault
13434 jmp error_code
13435 CFI_ENDPROC
13436 -END(async_page_fault)
13437 +ENDPROC(async_page_fault)
13438 #endif
13439
13440 /*
13441 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
13442 index 6419bb0..bb59ca4 100644
13443 --- a/arch/x86/kernel/entry_64.S
13444 +++ b/arch/x86/kernel/entry_64.S
13445 @@ -55,6 +55,8 @@
13446 #include <asm/paravirt.h>
13447 #include <asm/ftrace.h>
13448 #include <asm/percpu.h>
13449 +#include <asm/pgtable.h>
13450 +#include <asm/alternative-asm.h>
13451
13452 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13453 #include <linux/elf-em.h>
13454 @@ -68,8 +70,9 @@
13455 #ifdef CONFIG_FUNCTION_TRACER
13456 #ifdef CONFIG_DYNAMIC_FTRACE
13457 ENTRY(mcount)
13458 + pax_force_retaddr
13459 retq
13460 -END(mcount)
13461 +ENDPROC(mcount)
13462
13463 ENTRY(ftrace_caller)
13464 cmpl $0, function_trace_stop
13465 @@ -92,8 +95,9 @@ GLOBAL(ftrace_graph_call)
13466 #endif
13467
13468 GLOBAL(ftrace_stub)
13469 + pax_force_retaddr
13470 retq
13471 -END(ftrace_caller)
13472 +ENDPROC(ftrace_caller)
13473
13474 #else /* ! CONFIG_DYNAMIC_FTRACE */
13475 ENTRY(mcount)
13476 @@ -112,6 +116,7 @@ ENTRY(mcount)
13477 #endif
13478
13479 GLOBAL(ftrace_stub)
13480 + pax_force_retaddr
13481 retq
13482
13483 trace:
13484 @@ -121,12 +126,13 @@ trace:
13485 movq 8(%rbp), %rsi
13486 subq $MCOUNT_INSN_SIZE, %rdi
13487
13488 + pax_force_fptr ftrace_trace_function
13489 call *ftrace_trace_function
13490
13491 MCOUNT_RESTORE_FRAME
13492
13493 jmp ftrace_stub
13494 -END(mcount)
13495 +ENDPROC(mcount)
13496 #endif /* CONFIG_DYNAMIC_FTRACE */
13497 #endif /* CONFIG_FUNCTION_TRACER */
13498
13499 @@ -146,8 +152,9 @@ ENTRY(ftrace_graph_caller)
13500
13501 MCOUNT_RESTORE_FRAME
13502
13503 + pax_force_retaddr
13504 retq
13505 -END(ftrace_graph_caller)
13506 +ENDPROC(ftrace_graph_caller)
13507
13508 GLOBAL(return_to_handler)
13509 subq $24, %rsp
13510 @@ -163,6 +170,7 @@ GLOBAL(return_to_handler)
13511 movq 8(%rsp), %rdx
13512 movq (%rsp), %rax
13513 addq $24, %rsp
13514 + pax_force_fptr %rdi
13515 jmp *%rdi
13516 #endif
13517
13518 @@ -178,6 +186,282 @@ ENTRY(native_usergs_sysret64)
13519 ENDPROC(native_usergs_sysret64)
13520 #endif /* CONFIG_PARAVIRT */
13521
13522 + .macro ljmpq sel, off
13523 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
13524 + .byte 0x48; ljmp *1234f(%rip)
13525 + .pushsection .rodata
13526 + .align 16
13527 + 1234: .quad \off; .word \sel
13528 + .popsection
13529 +#else
13530 + pushq $\sel
13531 + pushq $\off
13532 + lretq
13533 +#endif
13534 + .endm
13535 +
13536 + .macro pax_enter_kernel
13537 + pax_set_fptr_mask
13538 +#ifdef CONFIG_PAX_KERNEXEC
13539 + call pax_enter_kernel
13540 +#endif
13541 + .endm
13542 +
13543 + .macro pax_exit_kernel
13544 +#ifdef CONFIG_PAX_KERNEXEC
13545 + call pax_exit_kernel
13546 +#endif
13547 + .endm
13548 +
13549 +#ifdef CONFIG_PAX_KERNEXEC
13550 +ENTRY(pax_enter_kernel)
13551 + pushq %rdi
13552 +
13553 +#ifdef CONFIG_PARAVIRT
13554 + PV_SAVE_REGS(CLBR_RDI)
13555 +#endif
13556 +
13557 + GET_CR0_INTO_RDI
13558 + bts $16,%rdi
13559 + jnc 3f
13560 + mov %cs,%edi
13561 + cmp $__KERNEL_CS,%edi
13562 + jnz 2f
13563 +1:
13564 +
13565 +#ifdef CONFIG_PARAVIRT
13566 + PV_RESTORE_REGS(CLBR_RDI)
13567 +#endif
13568 +
13569 + popq %rdi
13570 + pax_force_retaddr
13571 + retq
13572 +
13573 +2: ljmpq __KERNEL_CS,1f
13574 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
13575 +4: SET_RDI_INTO_CR0
13576 + jmp 1b
13577 +ENDPROC(pax_enter_kernel)
13578 +
13579 +ENTRY(pax_exit_kernel)
13580 + pushq %rdi
13581 +
13582 +#ifdef CONFIG_PARAVIRT
13583 + PV_SAVE_REGS(CLBR_RDI)
13584 +#endif
13585 +
13586 + mov %cs,%rdi
13587 + cmp $__KERNEXEC_KERNEL_CS,%edi
13588 + jz 2f
13589 +1:
13590 +
13591 +#ifdef CONFIG_PARAVIRT
13592 + PV_RESTORE_REGS(CLBR_RDI);
13593 +#endif
13594 +
13595 + popq %rdi
13596 + pax_force_retaddr
13597 + retq
13598 +
13599 +2: GET_CR0_INTO_RDI
13600 + btr $16,%rdi
13601 + ljmpq __KERNEL_CS,3f
13602 +3: SET_RDI_INTO_CR0
13603 + jmp 1b
13604 +#ifdef CONFIG_PARAVIRT
13605 + PV_RESTORE_REGS(CLBR_RDI);
13606 +#endif
13607 +
13608 + popq %rdi
13609 + pax_force_retaddr
13610 + retq
13611 +ENDPROC(pax_exit_kernel)
13612 +#endif
13613 +
13614 + .macro pax_enter_kernel_user
13615 + pax_set_fptr_mask
13616 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13617 + call pax_enter_kernel_user
13618 +#endif
13619 + .endm
13620 +
13621 + .macro pax_exit_kernel_user
13622 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13623 + call pax_exit_kernel_user
13624 +#endif
13625 +#ifdef CONFIG_PAX_RANDKSTACK
13626 + pushq %rax
13627 + call pax_randomize_kstack
13628 + popq %rax
13629 +#endif
13630 + .endm
13631 +
13632 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13633 +ENTRY(pax_enter_kernel_user)
13634 + pushq %rdi
13635 + pushq %rbx
13636 +
13637 +#ifdef CONFIG_PARAVIRT
13638 + PV_SAVE_REGS(CLBR_RDI)
13639 +#endif
13640 +
13641 + GET_CR3_INTO_RDI
13642 + mov %rdi,%rbx
13643 + add $__START_KERNEL_map,%rbx
13644 + sub phys_base(%rip),%rbx
13645 +
13646 +#ifdef CONFIG_PARAVIRT
13647 + pushq %rdi
13648 + cmpl $0, pv_info+PARAVIRT_enabled
13649 + jz 1f
13650 + i = 0
13651 + .rept USER_PGD_PTRS
13652 + mov i*8(%rbx),%rsi
13653 + mov $0,%sil
13654 + lea i*8(%rbx),%rdi
13655 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
13656 + i = i + 1
13657 + .endr
13658 + jmp 2f
13659 +1:
13660 +#endif
13661 +
13662 + i = 0
13663 + .rept USER_PGD_PTRS
13664 + movb $0,i*8(%rbx)
13665 + i = i + 1
13666 + .endr
13667 +
13668 +#ifdef CONFIG_PARAVIRT
13669 +2: popq %rdi
13670 +#endif
13671 + SET_RDI_INTO_CR3
13672 +
13673 +#ifdef CONFIG_PAX_KERNEXEC
13674 + GET_CR0_INTO_RDI
13675 + bts $16,%rdi
13676 + SET_RDI_INTO_CR0
13677 +#endif
13678 +
13679 +#ifdef CONFIG_PARAVIRT
13680 + PV_RESTORE_REGS(CLBR_RDI)
13681 +#endif
13682 +
13683 + popq %rbx
13684 + popq %rdi
13685 + pax_force_retaddr
13686 + retq
13687 +ENDPROC(pax_enter_kernel_user)
13688 +
13689 +ENTRY(pax_exit_kernel_user)
13690 + push %rdi
13691 +
13692 +#ifdef CONFIG_PARAVIRT
13693 + pushq %rbx
13694 + PV_SAVE_REGS(CLBR_RDI)
13695 +#endif
13696 +
13697 +#ifdef CONFIG_PAX_KERNEXEC
13698 + GET_CR0_INTO_RDI
13699 + btr $16,%rdi
13700 + SET_RDI_INTO_CR0
13701 +#endif
13702 +
13703 + GET_CR3_INTO_RDI
13704 + add $__START_KERNEL_map,%rdi
13705 + sub phys_base(%rip),%rdi
13706 +
13707 +#ifdef CONFIG_PARAVIRT
13708 + cmpl $0, pv_info+PARAVIRT_enabled
13709 + jz 1f
13710 + mov %rdi,%rbx
13711 + i = 0
13712 + .rept USER_PGD_PTRS
13713 + mov i*8(%rbx),%rsi
13714 + mov $0x67,%sil
13715 + lea i*8(%rbx),%rdi
13716 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
13717 + i = i + 1
13718 + .endr
13719 + jmp 2f
13720 +1:
13721 +#endif
13722 +
13723 + i = 0
13724 + .rept USER_PGD_PTRS
13725 + movb $0x67,i*8(%rdi)
13726 + i = i + 1
13727 + .endr
13728 +
13729 +#ifdef CONFIG_PARAVIRT
13730 +2: PV_RESTORE_REGS(CLBR_RDI)
13731 + popq %rbx
13732 +#endif
13733 +
13734 + popq %rdi
13735 + pax_force_retaddr
13736 + retq
13737 +ENDPROC(pax_exit_kernel_user)
13738 +#endif
13739 +
13740 +.macro pax_erase_kstack
13741 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13742 + call pax_erase_kstack
13743 +#endif
13744 +.endm
13745 +
13746 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13747 +/*
13748 + * r11: thread_info
13749 + * rcx, rdx: can be clobbered
13750 + */
13751 +ENTRY(pax_erase_kstack)
13752 + pushq %rdi
13753 + pushq %rax
13754 + pushq %r11
13755 +
13756 + GET_THREAD_INFO(%r11)
13757 + mov TI_lowest_stack(%r11), %rdi
13758 + mov $-0xBEEF, %rax
13759 + std
13760 +
13761 +1: mov %edi, %ecx
13762 + and $THREAD_SIZE_asm - 1, %ecx
13763 + shr $3, %ecx
13764 + repne scasq
13765 + jecxz 2f
13766 +
13767 + cmp $2*8, %ecx
13768 + jc 2f
13769 +
13770 + mov $2*8, %ecx
13771 + repe scasq
13772 + jecxz 2f
13773 + jne 1b
13774 +
13775 +2: cld
13776 + mov %esp, %ecx
13777 + sub %edi, %ecx
13778 +
13779 + cmp $THREAD_SIZE_asm, %rcx
13780 + jb 3f
13781 + ud2
13782 +3:
13783 +
13784 + shr $3, %ecx
13785 + rep stosq
13786 +
13787 + mov TI_task_thread_sp0(%r11), %rdi
13788 + sub $256, %rdi
13789 + mov %rdi, TI_lowest_stack(%r11)
13790 +
13791 + popq %r11
13792 + popq %rax
13793 + popq %rdi
13794 + pax_force_retaddr
13795 + ret
13796 +ENDPROC(pax_erase_kstack)
13797 +#endif
13798
13799 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
13800 #ifdef CONFIG_TRACE_IRQFLAGS
13801 @@ -231,8 +515,8 @@ ENDPROC(native_usergs_sysret64)
13802 .endm
13803
13804 .macro UNFAKE_STACK_FRAME
13805 - addq $8*6, %rsp
13806 - CFI_ADJUST_CFA_OFFSET -(6*8)
13807 + addq $8*6 + ARG_SKIP, %rsp
13808 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
13809 .endm
13810
13811 /*
13812 @@ -319,7 +603,7 @@ ENDPROC(native_usergs_sysret64)
13813 movq %rsp, %rsi
13814
13815 leaq -RBP(%rsp),%rdi /* arg1 for handler */
13816 - testl $3, CS(%rdi)
13817 + testb $3, CS(%rdi)
13818 je 1f
13819 SWAPGS
13820 /*
13821 @@ -350,9 +634,10 @@ ENTRY(save_rest)
13822 movq_cfi r15, R15+16
13823 movq %r11, 8(%rsp) /* return address */
13824 FIXUP_TOP_OF_STACK %r11, 16
13825 + pax_force_retaddr
13826 ret
13827 CFI_ENDPROC
13828 -END(save_rest)
13829 +ENDPROC(save_rest)
13830
13831 /* save complete stack frame */
13832 .pushsection .kprobes.text, "ax"
13833 @@ -381,9 +666,10 @@ ENTRY(save_paranoid)
13834 js 1f /* negative -> in kernel */
13835 SWAPGS
13836 xorl %ebx,%ebx
13837 -1: ret
13838 +1: pax_force_retaddr_bts
13839 + ret
13840 CFI_ENDPROC
13841 -END(save_paranoid)
13842 +ENDPROC(save_paranoid)
13843 .popsection
13844
13845 /*
13846 @@ -405,7 +691,7 @@ ENTRY(ret_from_fork)
13847
13848 RESTORE_REST
13849
13850 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
13851 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
13852 je int_ret_from_sys_call
13853
13854 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
13855 @@ -415,7 +701,7 @@ ENTRY(ret_from_fork)
13856 jmp ret_from_sys_call # go to the SYSRET fastpath
13857
13858 CFI_ENDPROC
13859 -END(ret_from_fork)
13860 +ENDPROC(ret_from_fork)
13861
13862 /*
13863 * System call entry. Up to 6 arguments in registers are supported.
13864 @@ -451,7 +737,7 @@ END(ret_from_fork)
13865 ENTRY(system_call)
13866 CFI_STARTPROC simple
13867 CFI_SIGNAL_FRAME
13868 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13869 + CFI_DEF_CFA rsp,0
13870 CFI_REGISTER rip,rcx
13871 /*CFI_REGISTER rflags,r11*/
13872 SWAPGS_UNSAFE_STACK
13873 @@ -464,12 +750,13 @@ ENTRY(system_call_after_swapgs)
13874
13875 movq %rsp,PER_CPU_VAR(old_rsp)
13876 movq PER_CPU_VAR(kernel_stack),%rsp
13877 + SAVE_ARGS 8*6,0
13878 + pax_enter_kernel_user
13879 /*
13880 * No need to follow this irqs off/on section - it's straight
13881 * and short:
13882 */
13883 ENABLE_INTERRUPTS(CLBR_NONE)
13884 - SAVE_ARGS 8,0
13885 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13886 movq %rcx,RIP-ARGOFFSET(%rsp)
13887 CFI_REL_OFFSET rip,RIP-ARGOFFSET
13888 @@ -479,7 +766,7 @@ ENTRY(system_call_after_swapgs)
13889 system_call_fastpath:
13890 cmpq $__NR_syscall_max,%rax
13891 ja badsys
13892 - movq %r10,%rcx
13893 + movq R10-ARGOFFSET(%rsp),%rcx
13894 call *sys_call_table(,%rax,8) # XXX: rip relative
13895 movq %rax,RAX-ARGOFFSET(%rsp)
13896 /*
13897 @@ -498,6 +785,8 @@ sysret_check:
13898 andl %edi,%edx
13899 jnz sysret_careful
13900 CFI_REMEMBER_STATE
13901 + pax_exit_kernel_user
13902 + pax_erase_kstack
13903 /*
13904 * sysretq will re-enable interrupts:
13905 */
13906 @@ -549,14 +838,18 @@ badsys:
13907 * jump back to the normal fast path.
13908 */
13909 auditsys:
13910 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
13911 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
13912 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
13913 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
13914 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
13915 movq %rax,%rsi /* 2nd arg: syscall number */
13916 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
13917 call audit_syscall_entry
13918 +
13919 + pax_erase_kstack
13920 +
13921 LOAD_ARGS 0 /* reload call-clobbered registers */
13922 + pax_set_fptr_mask
13923 jmp system_call_fastpath
13924
13925 /*
13926 @@ -586,16 +879,20 @@ tracesys:
13927 FIXUP_TOP_OF_STACK %rdi
13928 movq %rsp,%rdi
13929 call syscall_trace_enter
13930 +
13931 + pax_erase_kstack
13932 +
13933 /*
13934 * Reload arg registers from stack in case ptrace changed them.
13935 * We don't reload %rax because syscall_trace_enter() returned
13936 * the value it wants us to use in the table lookup.
13937 */
13938 LOAD_ARGS ARGOFFSET, 1
13939 + pax_set_fptr_mask
13940 RESTORE_REST
13941 cmpq $__NR_syscall_max,%rax
13942 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
13943 - movq %r10,%rcx /* fixup for C */
13944 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
13945 call *sys_call_table(,%rax,8)
13946 movq %rax,RAX-ARGOFFSET(%rsp)
13947 /* Use IRET because user could have changed frame */
13948 @@ -607,7 +904,7 @@ tracesys:
13949 GLOBAL(int_ret_from_sys_call)
13950 DISABLE_INTERRUPTS(CLBR_NONE)
13951 TRACE_IRQS_OFF
13952 - testl $3,CS-ARGOFFSET(%rsp)
13953 + testb $3,CS-ARGOFFSET(%rsp)
13954 je retint_restore_args
13955 movl $_TIF_ALLWORK_MASK,%edi
13956 /* edi: mask to check */
13957 @@ -664,7 +961,7 @@ int_restore_rest:
13958 TRACE_IRQS_OFF
13959 jmp int_with_check
13960 CFI_ENDPROC
13961 -END(system_call)
13962 +ENDPROC(system_call)
13963
13964 /*
13965 * Certain special system calls that need to save a complete full stack frame.
13966 @@ -680,7 +977,7 @@ ENTRY(\label)
13967 call \func
13968 jmp ptregscall_common
13969 CFI_ENDPROC
13970 -END(\label)
13971 +ENDPROC(\label)
13972 .endm
13973
13974 PTREGSCALL stub_clone, sys_clone, %r8
13975 @@ -698,9 +995,10 @@ ENTRY(ptregscall_common)
13976 movq_cfi_restore R12+8, r12
13977 movq_cfi_restore RBP+8, rbp
13978 movq_cfi_restore RBX+8, rbx
13979 + pax_force_retaddr
13980 ret $REST_SKIP /* pop extended registers */
13981 CFI_ENDPROC
13982 -END(ptregscall_common)
13983 +ENDPROC(ptregscall_common)
13984
13985 ENTRY(stub_execve)
13986 CFI_STARTPROC
13987 @@ -715,7 +1013,7 @@ ENTRY(stub_execve)
13988 RESTORE_REST
13989 jmp int_ret_from_sys_call
13990 CFI_ENDPROC
13991 -END(stub_execve)
13992 +ENDPROC(stub_execve)
13993
13994 /*
13995 * sigreturn is special because it needs to restore all registers on return.
13996 @@ -733,7 +1031,7 @@ ENTRY(stub_rt_sigreturn)
13997 RESTORE_REST
13998 jmp int_ret_from_sys_call
13999 CFI_ENDPROC
14000 -END(stub_rt_sigreturn)
14001 +ENDPROC(stub_rt_sigreturn)
14002
14003 /*
14004 * Build the entry stubs and pointer table with some assembler magic.
14005 @@ -768,7 +1066,7 @@ vector=vector+1
14006 2: jmp common_interrupt
14007 .endr
14008 CFI_ENDPROC
14009 -END(irq_entries_start)
14010 +ENDPROC(irq_entries_start)
14011
14012 .previous
14013 END(interrupt)
14014 @@ -789,6 +1087,16 @@ END(interrupt)
14015 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
14016 SAVE_ARGS_IRQ
14017 PARTIAL_FRAME 0
14018 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14019 + testb $3, CS(%rdi)
14020 + jnz 1f
14021 + pax_enter_kernel
14022 + jmp 2f
14023 +1: pax_enter_kernel_user
14024 +2:
14025 +#else
14026 + pax_enter_kernel
14027 +#endif
14028 call \func
14029 .endm
14030
14031 @@ -820,7 +1128,7 @@ ret_from_intr:
14032
14033 exit_intr:
14034 GET_THREAD_INFO(%rcx)
14035 - testl $3,CS-ARGOFFSET(%rsp)
14036 + testb $3,CS-ARGOFFSET(%rsp)
14037 je retint_kernel
14038
14039 /* Interrupt came from user space */
14040 @@ -842,12 +1150,16 @@ retint_swapgs: /* return to user-space */
14041 * The iretq could re-enable interrupts:
14042 */
14043 DISABLE_INTERRUPTS(CLBR_ANY)
14044 + pax_exit_kernel_user
14045 + pax_erase_kstack
14046 TRACE_IRQS_IRETQ
14047 SWAPGS
14048 jmp restore_args
14049
14050 retint_restore_args: /* return to kernel space */
14051 DISABLE_INTERRUPTS(CLBR_ANY)
14052 + pax_exit_kernel
14053 + pax_force_retaddr RIP-ARGOFFSET
14054 /*
14055 * The iretq could re-enable interrupts:
14056 */
14057 @@ -936,7 +1248,7 @@ ENTRY(retint_kernel)
14058 #endif
14059
14060 CFI_ENDPROC
14061 -END(common_interrupt)
14062 +ENDPROC(common_interrupt)
14063 /*
14064 * End of kprobes section
14065 */
14066 @@ -952,7 +1264,7 @@ ENTRY(\sym)
14067 interrupt \do_sym
14068 jmp ret_from_intr
14069 CFI_ENDPROC
14070 -END(\sym)
14071 +ENDPROC(\sym)
14072 .endm
14073
14074 #ifdef CONFIG_SMP
14075 @@ -1017,12 +1329,22 @@ ENTRY(\sym)
14076 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14077 call error_entry
14078 DEFAULT_FRAME 0
14079 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14080 + testb $3, CS(%rsp)
14081 + jnz 1f
14082 + pax_enter_kernel
14083 + jmp 2f
14084 +1: pax_enter_kernel_user
14085 +2:
14086 +#else
14087 + pax_enter_kernel
14088 +#endif
14089 movq %rsp,%rdi /* pt_regs pointer */
14090 xorl %esi,%esi /* no error code */
14091 call \do_sym
14092 jmp error_exit /* %ebx: no swapgs flag */
14093 CFI_ENDPROC
14094 -END(\sym)
14095 +ENDPROC(\sym)
14096 .endm
14097
14098 .macro paranoidzeroentry sym do_sym
14099 @@ -1034,15 +1356,25 @@ ENTRY(\sym)
14100 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14101 call save_paranoid
14102 TRACE_IRQS_OFF
14103 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14104 + testb $3, CS(%rsp)
14105 + jnz 1f
14106 + pax_enter_kernel
14107 + jmp 2f
14108 +1: pax_enter_kernel_user
14109 +2:
14110 +#else
14111 + pax_enter_kernel
14112 +#endif
14113 movq %rsp,%rdi /* pt_regs pointer */
14114 xorl %esi,%esi /* no error code */
14115 call \do_sym
14116 jmp paranoid_exit /* %ebx: no swapgs flag */
14117 CFI_ENDPROC
14118 -END(\sym)
14119 +ENDPROC(\sym)
14120 .endm
14121
14122 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
14123 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
14124 .macro paranoidzeroentry_ist sym do_sym ist
14125 ENTRY(\sym)
14126 INTR_FRAME
14127 @@ -1052,14 +1384,30 @@ ENTRY(\sym)
14128 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14129 call save_paranoid
14130 TRACE_IRQS_OFF
14131 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14132 + testb $3, CS(%rsp)
14133 + jnz 1f
14134 + pax_enter_kernel
14135 + jmp 2f
14136 +1: pax_enter_kernel_user
14137 +2:
14138 +#else
14139 + pax_enter_kernel
14140 +#endif
14141 movq %rsp,%rdi /* pt_regs pointer */
14142 xorl %esi,%esi /* no error code */
14143 +#ifdef CONFIG_SMP
14144 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
14145 + lea init_tss(%r12), %r12
14146 +#else
14147 + lea init_tss(%rip), %r12
14148 +#endif
14149 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14150 call \do_sym
14151 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14152 jmp paranoid_exit /* %ebx: no swapgs flag */
14153 CFI_ENDPROC
14154 -END(\sym)
14155 +ENDPROC(\sym)
14156 .endm
14157
14158 .macro errorentry sym do_sym
14159 @@ -1070,13 +1418,23 @@ ENTRY(\sym)
14160 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14161 call error_entry
14162 DEFAULT_FRAME 0
14163 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14164 + testb $3, CS(%rsp)
14165 + jnz 1f
14166 + pax_enter_kernel
14167 + jmp 2f
14168 +1: pax_enter_kernel_user
14169 +2:
14170 +#else
14171 + pax_enter_kernel
14172 +#endif
14173 movq %rsp,%rdi /* pt_regs pointer */
14174 movq ORIG_RAX(%rsp),%rsi /* get error code */
14175 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14176 call \do_sym
14177 jmp error_exit /* %ebx: no swapgs flag */
14178 CFI_ENDPROC
14179 -END(\sym)
14180 +ENDPROC(\sym)
14181 .endm
14182
14183 /* error code is on the stack already */
14184 @@ -1089,13 +1447,23 @@ ENTRY(\sym)
14185 call save_paranoid
14186 DEFAULT_FRAME 0
14187 TRACE_IRQS_OFF
14188 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14189 + testb $3, CS(%rsp)
14190 + jnz 1f
14191 + pax_enter_kernel
14192 + jmp 2f
14193 +1: pax_enter_kernel_user
14194 +2:
14195 +#else
14196 + pax_enter_kernel
14197 +#endif
14198 movq %rsp,%rdi /* pt_regs pointer */
14199 movq ORIG_RAX(%rsp),%rsi /* get error code */
14200 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14201 call \do_sym
14202 jmp paranoid_exit /* %ebx: no swapgs flag */
14203 CFI_ENDPROC
14204 -END(\sym)
14205 +ENDPROC(\sym)
14206 .endm
14207
14208 zeroentry divide_error do_divide_error
14209 @@ -1125,9 +1493,10 @@ gs_change:
14210 2: mfence /* workaround */
14211 SWAPGS
14212 popfq_cfi
14213 + pax_force_retaddr
14214 ret
14215 CFI_ENDPROC
14216 -END(native_load_gs_index)
14217 +ENDPROC(native_load_gs_index)
14218
14219 .section __ex_table,"a"
14220 .align 8
14221 @@ -1149,13 +1518,14 @@ ENTRY(kernel_thread_helper)
14222 * Here we are in the child and the registers are set as they were
14223 * at kernel_thread() invocation in the parent.
14224 */
14225 + pax_force_fptr %rsi
14226 call *%rsi
14227 # exit
14228 mov %eax, %edi
14229 call do_exit
14230 ud2 # padding for call trace
14231 CFI_ENDPROC
14232 -END(kernel_thread_helper)
14233 +ENDPROC(kernel_thread_helper)
14234
14235 /*
14236 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
14237 @@ -1182,11 +1552,11 @@ ENTRY(kernel_execve)
14238 RESTORE_REST
14239 testq %rax,%rax
14240 je int_ret_from_sys_call
14241 - RESTORE_ARGS
14242 UNFAKE_STACK_FRAME
14243 + pax_force_retaddr
14244 ret
14245 CFI_ENDPROC
14246 -END(kernel_execve)
14247 +ENDPROC(kernel_execve)
14248
14249 /* Call softirq on interrupt stack. Interrupts are off. */
14250 ENTRY(call_softirq)
14251 @@ -1204,9 +1574,10 @@ ENTRY(call_softirq)
14252 CFI_DEF_CFA_REGISTER rsp
14253 CFI_ADJUST_CFA_OFFSET -8
14254 decl PER_CPU_VAR(irq_count)
14255 + pax_force_retaddr
14256 ret
14257 CFI_ENDPROC
14258 -END(call_softirq)
14259 +ENDPROC(call_softirq)
14260
14261 #ifdef CONFIG_XEN
14262 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
14263 @@ -1244,7 +1615,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
14264 decl PER_CPU_VAR(irq_count)
14265 jmp error_exit
14266 CFI_ENDPROC
14267 -END(xen_do_hypervisor_callback)
14268 +ENDPROC(xen_do_hypervisor_callback)
14269
14270 /*
14271 * Hypervisor uses this for application faults while it executes.
14272 @@ -1303,7 +1674,7 @@ ENTRY(xen_failsafe_callback)
14273 SAVE_ALL
14274 jmp error_exit
14275 CFI_ENDPROC
14276 -END(xen_failsafe_callback)
14277 +ENDPROC(xen_failsafe_callback)
14278
14279 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
14280 xen_hvm_callback_vector xen_evtchn_do_upcall
14281 @@ -1352,16 +1723,31 @@ ENTRY(paranoid_exit)
14282 TRACE_IRQS_OFF
14283 testl %ebx,%ebx /* swapgs needed? */
14284 jnz paranoid_restore
14285 - testl $3,CS(%rsp)
14286 + testb $3,CS(%rsp)
14287 jnz paranoid_userspace
14288 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14289 + pax_exit_kernel
14290 + TRACE_IRQS_IRETQ 0
14291 + SWAPGS_UNSAFE_STACK
14292 + RESTORE_ALL 8
14293 + pax_force_retaddr_bts
14294 + jmp irq_return
14295 +#endif
14296 paranoid_swapgs:
14297 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14298 + pax_exit_kernel_user
14299 +#else
14300 + pax_exit_kernel
14301 +#endif
14302 TRACE_IRQS_IRETQ 0
14303 SWAPGS_UNSAFE_STACK
14304 RESTORE_ALL 8
14305 jmp irq_return
14306 paranoid_restore:
14307 + pax_exit_kernel
14308 TRACE_IRQS_IRETQ 0
14309 RESTORE_ALL 8
14310 + pax_force_retaddr_bts
14311 jmp irq_return
14312 paranoid_userspace:
14313 GET_THREAD_INFO(%rcx)
14314 @@ -1390,7 +1776,7 @@ paranoid_schedule:
14315 TRACE_IRQS_OFF
14316 jmp paranoid_userspace
14317 CFI_ENDPROC
14318 -END(paranoid_exit)
14319 +ENDPROC(paranoid_exit)
14320
14321 /*
14322 * Exception entry point. This expects an error code/orig_rax on the stack.
14323 @@ -1417,12 +1803,13 @@ ENTRY(error_entry)
14324 movq_cfi r14, R14+8
14325 movq_cfi r15, R15+8
14326 xorl %ebx,%ebx
14327 - testl $3,CS+8(%rsp)
14328 + testb $3,CS+8(%rsp)
14329 je error_kernelspace
14330 error_swapgs:
14331 SWAPGS
14332 error_sti:
14333 TRACE_IRQS_OFF
14334 + pax_force_retaddr_bts
14335 ret
14336
14337 /*
14338 @@ -1449,7 +1836,7 @@ bstep_iret:
14339 movq %rcx,RIP+8(%rsp)
14340 jmp error_swapgs
14341 CFI_ENDPROC
14342 -END(error_entry)
14343 +ENDPROC(error_entry)
14344
14345
14346 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
14347 @@ -1469,7 +1856,7 @@ ENTRY(error_exit)
14348 jnz retint_careful
14349 jmp retint_swapgs
14350 CFI_ENDPROC
14351 -END(error_exit)
14352 +ENDPROC(error_exit)
14353
14354
14355 /* runs on exception stack */
14356 @@ -1481,6 +1868,16 @@ ENTRY(nmi)
14357 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14358 call save_paranoid
14359 DEFAULT_FRAME 0
14360 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14361 + testb $3, CS(%rsp)
14362 + jnz 1f
14363 + pax_enter_kernel
14364 + jmp 2f
14365 +1: pax_enter_kernel_user
14366 +2:
14367 +#else
14368 + pax_enter_kernel
14369 +#endif
14370 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
14371 movq %rsp,%rdi
14372 movq $-1,%rsi
14373 @@ -1491,12 +1888,28 @@ ENTRY(nmi)
14374 DISABLE_INTERRUPTS(CLBR_NONE)
14375 testl %ebx,%ebx /* swapgs needed? */
14376 jnz nmi_restore
14377 - testl $3,CS(%rsp)
14378 + testb $3,CS(%rsp)
14379 jnz nmi_userspace
14380 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14381 + pax_exit_kernel
14382 + SWAPGS_UNSAFE_STACK
14383 + RESTORE_ALL 8
14384 + pax_force_retaddr_bts
14385 + jmp irq_return
14386 +#endif
14387 nmi_swapgs:
14388 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14389 + pax_exit_kernel_user
14390 +#else
14391 + pax_exit_kernel
14392 +#endif
14393 SWAPGS_UNSAFE_STACK
14394 + RESTORE_ALL 8
14395 + jmp irq_return
14396 nmi_restore:
14397 + pax_exit_kernel
14398 RESTORE_ALL 8
14399 + pax_force_retaddr_bts
14400 jmp irq_return
14401 nmi_userspace:
14402 GET_THREAD_INFO(%rcx)
14403 @@ -1525,14 +1938,14 @@ nmi_schedule:
14404 jmp paranoid_exit
14405 CFI_ENDPROC
14406 #endif
14407 -END(nmi)
14408 +ENDPROC(nmi)
14409
14410 ENTRY(ignore_sysret)
14411 CFI_STARTPROC
14412 mov $-ENOSYS,%eax
14413 sysret
14414 CFI_ENDPROC
14415 -END(ignore_sysret)
14416 +ENDPROC(ignore_sysret)
14417
14418 /*
14419 * End of kprobes section
14420 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
14421 index c9a281f..ce2f317 100644
14422 --- a/arch/x86/kernel/ftrace.c
14423 +++ b/arch/x86/kernel/ftrace.c
14424 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
14425 static const void *mod_code_newcode; /* holds the text to write to the IP */
14426
14427 static unsigned nmi_wait_count;
14428 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
14429 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
14430
14431 int ftrace_arch_read_dyn_info(char *buf, int size)
14432 {
14433 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
14434
14435 r = snprintf(buf, size, "%u %u",
14436 nmi_wait_count,
14437 - atomic_read(&nmi_update_count));
14438 + atomic_read_unchecked(&nmi_update_count));
14439 return r;
14440 }
14441
14442 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
14443
14444 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
14445 smp_rmb();
14446 + pax_open_kernel();
14447 ftrace_mod_code();
14448 - atomic_inc(&nmi_update_count);
14449 + pax_close_kernel();
14450 + atomic_inc_unchecked(&nmi_update_count);
14451 }
14452 /* Must have previous changes seen before executions */
14453 smp_mb();
14454 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
14455 {
14456 unsigned char replaced[MCOUNT_INSN_SIZE];
14457
14458 + ip = ktla_ktva(ip);
14459 +
14460 /*
14461 * Note: Due to modules and __init, code can
14462 * disappear and change, we need to protect against faulting
14463 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
14464 unsigned char old[MCOUNT_INSN_SIZE], *new;
14465 int ret;
14466
14467 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
14468 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
14469 new = ftrace_call_replace(ip, (unsigned long)func);
14470 ret = ftrace_modify_code(ip, old, new);
14471
14472 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
14473 {
14474 unsigned char code[MCOUNT_INSN_SIZE];
14475
14476 + ip = ktla_ktva(ip);
14477 +
14478 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
14479 return -EFAULT;
14480
14481 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
14482 index 3bb0850..55a56f4 100644
14483 --- a/arch/x86/kernel/head32.c
14484 +++ b/arch/x86/kernel/head32.c
14485 @@ -19,6 +19,7 @@
14486 #include <asm/io_apic.h>
14487 #include <asm/bios_ebda.h>
14488 #include <asm/tlbflush.h>
14489 +#include <asm/boot.h>
14490
14491 static void __init i386_default_early_setup(void)
14492 {
14493 @@ -33,7 +34,7 @@ void __init i386_start_kernel(void)
14494 {
14495 memblock_init();
14496
14497 - memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14498 + memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14499
14500 #ifdef CONFIG_BLK_DEV_INITRD
14501 /* Reserve INITRD */
14502 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
14503 index ce0be7c..c41476e 100644
14504 --- a/arch/x86/kernel/head_32.S
14505 +++ b/arch/x86/kernel/head_32.S
14506 @@ -25,6 +25,12 @@
14507 /* Physical address */
14508 #define pa(X) ((X) - __PAGE_OFFSET)
14509
14510 +#ifdef CONFIG_PAX_KERNEXEC
14511 +#define ta(X) (X)
14512 +#else
14513 +#define ta(X) ((X) - __PAGE_OFFSET)
14514 +#endif
14515 +
14516 /*
14517 * References to members of the new_cpu_data structure.
14518 */
14519 @@ -54,11 +60,7 @@
14520 * and small than max_low_pfn, otherwise will waste some page table entries
14521 */
14522
14523 -#if PTRS_PER_PMD > 1
14524 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
14525 -#else
14526 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
14527 -#endif
14528 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
14529
14530 /* Number of possible pages in the lowmem region */
14531 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
14532 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
14533 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14534
14535 /*
14536 + * Real beginning of normal "text" segment
14537 + */
14538 +ENTRY(stext)
14539 +ENTRY(_stext)
14540 +
14541 +/*
14542 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
14543 * %esi points to the real-mode code as a 32-bit pointer.
14544 * CS and DS must be 4 GB flat segments, but we don't depend on
14545 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14546 * can.
14547 */
14548 __HEAD
14549 +
14550 +#ifdef CONFIG_PAX_KERNEXEC
14551 + jmp startup_32
14552 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
14553 +.fill PAGE_SIZE-5,1,0xcc
14554 +#endif
14555 +
14556 ENTRY(startup_32)
14557 movl pa(stack_start),%ecx
14558
14559 @@ -105,6 +120,57 @@ ENTRY(startup_32)
14560 2:
14561 leal -__PAGE_OFFSET(%ecx),%esp
14562
14563 +#ifdef CONFIG_SMP
14564 + movl $pa(cpu_gdt_table),%edi
14565 + movl $__per_cpu_load,%eax
14566 + movw %ax,__KERNEL_PERCPU + 2(%edi)
14567 + rorl $16,%eax
14568 + movb %al,__KERNEL_PERCPU + 4(%edi)
14569 + movb %ah,__KERNEL_PERCPU + 7(%edi)
14570 + movl $__per_cpu_end - 1,%eax
14571 + subl $__per_cpu_start,%eax
14572 + movw %ax,__KERNEL_PERCPU + 0(%edi)
14573 +#endif
14574 +
14575 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14576 + movl $NR_CPUS,%ecx
14577 + movl $pa(cpu_gdt_table),%edi
14578 +1:
14579 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
14580 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
14581 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
14582 + addl $PAGE_SIZE_asm,%edi
14583 + loop 1b
14584 +#endif
14585 +
14586 +#ifdef CONFIG_PAX_KERNEXEC
14587 + movl $pa(boot_gdt),%edi
14588 + movl $__LOAD_PHYSICAL_ADDR,%eax
14589 + movw %ax,__BOOT_CS + 2(%edi)
14590 + rorl $16,%eax
14591 + movb %al,__BOOT_CS + 4(%edi)
14592 + movb %ah,__BOOT_CS + 7(%edi)
14593 + rorl $16,%eax
14594 +
14595 + ljmp $(__BOOT_CS),$1f
14596 +1:
14597 +
14598 + movl $NR_CPUS,%ecx
14599 + movl $pa(cpu_gdt_table),%edi
14600 + addl $__PAGE_OFFSET,%eax
14601 +1:
14602 + movw %ax,__KERNEL_CS + 2(%edi)
14603 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
14604 + rorl $16,%eax
14605 + movb %al,__KERNEL_CS + 4(%edi)
14606 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
14607 + movb %ah,__KERNEL_CS + 7(%edi)
14608 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
14609 + rorl $16,%eax
14610 + addl $PAGE_SIZE_asm,%edi
14611 + loop 1b
14612 +#endif
14613 +
14614 /*
14615 * Clear BSS first so that there are no surprises...
14616 */
14617 @@ -195,8 +261,11 @@ ENTRY(startup_32)
14618 movl %eax, pa(max_pfn_mapped)
14619
14620 /* Do early initialization of the fixmap area */
14621 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14622 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
14623 +#ifdef CONFIG_COMPAT_VDSO
14624 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
14625 +#else
14626 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
14627 +#endif
14628 #else /* Not PAE */
14629
14630 page_pde_offset = (__PAGE_OFFSET >> 20);
14631 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14632 movl %eax, pa(max_pfn_mapped)
14633
14634 /* Do early initialization of the fixmap area */
14635 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14636 - movl %eax,pa(initial_page_table+0xffc)
14637 +#ifdef CONFIG_COMPAT_VDSO
14638 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
14639 +#else
14640 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
14641 +#endif
14642 #endif
14643
14644 #ifdef CONFIG_PARAVIRT
14645 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14646 cmpl $num_subarch_entries, %eax
14647 jae bad_subarch
14648
14649 - movl pa(subarch_entries)(,%eax,4), %eax
14650 - subl $__PAGE_OFFSET, %eax
14651 - jmp *%eax
14652 + jmp *pa(subarch_entries)(,%eax,4)
14653
14654 bad_subarch:
14655 WEAK(lguest_entry)
14656 @@ -255,10 +325,10 @@ WEAK(xen_entry)
14657 __INITDATA
14658
14659 subarch_entries:
14660 - .long default_entry /* normal x86/PC */
14661 - .long lguest_entry /* lguest hypervisor */
14662 - .long xen_entry /* Xen hypervisor */
14663 - .long default_entry /* Moorestown MID */
14664 + .long ta(default_entry) /* normal x86/PC */
14665 + .long ta(lguest_entry) /* lguest hypervisor */
14666 + .long ta(xen_entry) /* Xen hypervisor */
14667 + .long ta(default_entry) /* Moorestown MID */
14668 num_subarch_entries = (. - subarch_entries) / 4
14669 .previous
14670 #else
14671 @@ -312,6 +382,7 @@ default_entry:
14672 orl %edx,%eax
14673 movl %eax,%cr4
14674
14675 +#ifdef CONFIG_X86_PAE
14676 testb $X86_CR4_PAE, %al # check if PAE is enabled
14677 jz 6f
14678
14679 @@ -340,6 +411,9 @@ default_entry:
14680 /* Make changes effective */
14681 wrmsr
14682
14683 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
14684 +#endif
14685 +
14686 6:
14687
14688 /*
14689 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
14690 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
14691 movl %eax,%ss # after changing gdt.
14692
14693 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
14694 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
14695 movl %eax,%ds
14696 movl %eax,%es
14697
14698 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
14699 */
14700 cmpb $0,ready
14701 jne 1f
14702 - movl $gdt_page,%eax
14703 + movl $cpu_gdt_table,%eax
14704 movl $stack_canary,%ecx
14705 +#ifdef CONFIG_SMP
14706 + addl $__per_cpu_load,%ecx
14707 +#endif
14708 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
14709 shrl $16, %ecx
14710 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
14711 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
14712 1:
14713 -#endif
14714 movl $(__KERNEL_STACK_CANARY),%eax
14715 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14716 + movl $(__USER_DS),%eax
14717 +#else
14718 + xorl %eax,%eax
14719 +#endif
14720 movl %eax,%gs
14721
14722 xorl %eax,%eax # Clear LDT
14723 @@ -558,22 +639,22 @@ early_page_fault:
14724 jmp early_fault
14725
14726 early_fault:
14727 - cld
14728 #ifdef CONFIG_PRINTK
14729 + cmpl $1,%ss:early_recursion_flag
14730 + je hlt_loop
14731 + incl %ss:early_recursion_flag
14732 + cld
14733 pusha
14734 movl $(__KERNEL_DS),%eax
14735 movl %eax,%ds
14736 movl %eax,%es
14737 - cmpl $2,early_recursion_flag
14738 - je hlt_loop
14739 - incl early_recursion_flag
14740 movl %cr2,%eax
14741 pushl %eax
14742 pushl %edx /* trapno */
14743 pushl $fault_msg
14744 call printk
14745 +; call dump_stack
14746 #endif
14747 - call dump_stack
14748 hlt_loop:
14749 hlt
14750 jmp hlt_loop
14751 @@ -581,8 +662,11 @@ hlt_loop:
14752 /* This is the default interrupt "handler" :-) */
14753 ALIGN
14754 ignore_int:
14755 - cld
14756 #ifdef CONFIG_PRINTK
14757 + cmpl $2,%ss:early_recursion_flag
14758 + je hlt_loop
14759 + incl %ss:early_recursion_flag
14760 + cld
14761 pushl %eax
14762 pushl %ecx
14763 pushl %edx
14764 @@ -591,9 +675,6 @@ ignore_int:
14765 movl $(__KERNEL_DS),%eax
14766 movl %eax,%ds
14767 movl %eax,%es
14768 - cmpl $2,early_recursion_flag
14769 - je hlt_loop
14770 - incl early_recursion_flag
14771 pushl 16(%esp)
14772 pushl 24(%esp)
14773 pushl 32(%esp)
14774 @@ -622,29 +703,43 @@ ENTRY(initial_code)
14775 /*
14776 * BSS section
14777 */
14778 -__PAGE_ALIGNED_BSS
14779 - .align PAGE_SIZE
14780 #ifdef CONFIG_X86_PAE
14781 +.section .initial_pg_pmd,"a",@progbits
14782 initial_pg_pmd:
14783 .fill 1024*KPMDS,4,0
14784 #else
14785 +.section .initial_page_table,"a",@progbits
14786 ENTRY(initial_page_table)
14787 .fill 1024,4,0
14788 #endif
14789 +.section .initial_pg_fixmap,"a",@progbits
14790 initial_pg_fixmap:
14791 .fill 1024,4,0
14792 +.section .empty_zero_page,"a",@progbits
14793 ENTRY(empty_zero_page)
14794 .fill 4096,1,0
14795 +.section .swapper_pg_dir,"a",@progbits
14796 ENTRY(swapper_pg_dir)
14797 +#ifdef CONFIG_X86_PAE
14798 + .fill 4,8,0
14799 +#else
14800 .fill 1024,4,0
14801 +#endif
14802 +
14803 +/*
14804 + * The IDT has to be page-aligned to simplify the Pentium
14805 + * F0 0F bug workaround.. We have a special link segment
14806 + * for this.
14807 + */
14808 +.section .idt,"a",@progbits
14809 +ENTRY(idt_table)
14810 + .fill 256,8,0
14811
14812 /*
14813 * This starts the data section.
14814 */
14815 #ifdef CONFIG_X86_PAE
14816 -__PAGE_ALIGNED_DATA
14817 - /* Page-aligned for the benefit of paravirt? */
14818 - .align PAGE_SIZE
14819 +.section .initial_page_table,"a",@progbits
14820 ENTRY(initial_page_table)
14821 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
14822 # if KPMDS == 3
14823 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
14824 # error "Kernel PMDs should be 1, 2 or 3"
14825 # endif
14826 .align PAGE_SIZE /* needs to be page-sized too */
14827 +
14828 +#ifdef CONFIG_PAX_PER_CPU_PGD
14829 +ENTRY(cpu_pgd)
14830 + .rept NR_CPUS
14831 + .fill 4,8,0
14832 + .endr
14833 +#endif
14834 +
14835 #endif
14836
14837 .data
14838 .balign 4
14839 ENTRY(stack_start)
14840 - .long init_thread_union+THREAD_SIZE
14841 + .long init_thread_union+THREAD_SIZE-8
14842
14843 +ready: .byte 0
14844 +
14845 +.section .rodata,"a",@progbits
14846 early_recursion_flag:
14847 .long 0
14848
14849 -ready: .byte 0
14850 -
14851 int_msg:
14852 .asciz "Unknown interrupt or fault at: %p %p %p\n"
14853
14854 @@ -707,7 +811,7 @@ fault_msg:
14855 .word 0 # 32 bit align gdt_desc.address
14856 boot_gdt_descr:
14857 .word __BOOT_DS+7
14858 - .long boot_gdt - __PAGE_OFFSET
14859 + .long pa(boot_gdt)
14860
14861 .word 0 # 32-bit align idt_desc.address
14862 idt_descr:
14863 @@ -718,7 +822,7 @@ idt_descr:
14864 .word 0 # 32 bit align gdt_desc.address
14865 ENTRY(early_gdt_descr)
14866 .word GDT_ENTRIES*8-1
14867 - .long gdt_page /* Overwritten for secondary CPUs */
14868 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
14869
14870 /*
14871 * The boot_gdt must mirror the equivalent in setup.S and is
14872 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
14873 .align L1_CACHE_BYTES
14874 ENTRY(boot_gdt)
14875 .fill GDT_ENTRY_BOOT_CS,8,0
14876 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
14877 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
14878 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
14879 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
14880 +
14881 + .align PAGE_SIZE_asm
14882 +ENTRY(cpu_gdt_table)
14883 + .rept NR_CPUS
14884 + .quad 0x0000000000000000 /* NULL descriptor */
14885 + .quad 0x0000000000000000 /* 0x0b reserved */
14886 + .quad 0x0000000000000000 /* 0x13 reserved */
14887 + .quad 0x0000000000000000 /* 0x1b reserved */
14888 +
14889 +#ifdef CONFIG_PAX_KERNEXEC
14890 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
14891 +#else
14892 + .quad 0x0000000000000000 /* 0x20 unused */
14893 +#endif
14894 +
14895 + .quad 0x0000000000000000 /* 0x28 unused */
14896 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
14897 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
14898 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
14899 + .quad 0x0000000000000000 /* 0x4b reserved */
14900 + .quad 0x0000000000000000 /* 0x53 reserved */
14901 + .quad 0x0000000000000000 /* 0x5b reserved */
14902 +
14903 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
14904 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
14905 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
14906 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
14907 +
14908 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
14909 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
14910 +
14911 + /*
14912 + * Segments used for calling PnP BIOS have byte granularity.
14913 + * The code segments and data segments have fixed 64k limits,
14914 + * the transfer segment sizes are set at run time.
14915 + */
14916 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
14917 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
14918 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
14919 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
14920 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
14921 +
14922 + /*
14923 + * The APM segments have byte granularity and their bases
14924 + * are set at run time. All have 64k limits.
14925 + */
14926 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
14927 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
14928 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
14929 +
14930 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
14931 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
14932 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
14933 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
14934 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
14935 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
14936 +
14937 + /* Be sure this is zeroed to avoid false validations in Xen */
14938 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
14939 + .endr
14940 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
14941 index e11e394..9aebc5d 100644
14942 --- a/arch/x86/kernel/head_64.S
14943 +++ b/arch/x86/kernel/head_64.S
14944 @@ -19,6 +19,8 @@
14945 #include <asm/cache.h>
14946 #include <asm/processor-flags.h>
14947 #include <asm/percpu.h>
14948 +#include <asm/cpufeature.h>
14949 +#include <asm/alternative-asm.h>
14950
14951 #ifdef CONFIG_PARAVIRT
14952 #include <asm/asm-offsets.h>
14953 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
14954 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
14955 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
14956 L3_START_KERNEL = pud_index(__START_KERNEL_map)
14957 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
14958 +L3_VMALLOC_START = pud_index(VMALLOC_START)
14959 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
14960 +L3_VMALLOC_END = pud_index(VMALLOC_END)
14961 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
14962 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
14963
14964 .text
14965 __HEAD
14966 @@ -85,35 +93,23 @@ startup_64:
14967 */
14968 addq %rbp, init_level4_pgt + 0(%rip)
14969 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
14970 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
14971 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
14972 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
14973 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
14974
14975 addq %rbp, level3_ident_pgt + 0(%rip)
14976 +#ifndef CONFIG_XEN
14977 + addq %rbp, level3_ident_pgt + 8(%rip)
14978 +#endif
14979
14980 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
14981 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
14982 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
14983 +
14984 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
14985 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
14986
14987 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
14988 -
14989 - /* Add an Identity mapping if I am above 1G */
14990 - leaq _text(%rip), %rdi
14991 - andq $PMD_PAGE_MASK, %rdi
14992 -
14993 - movq %rdi, %rax
14994 - shrq $PUD_SHIFT, %rax
14995 - andq $(PTRS_PER_PUD - 1), %rax
14996 - jz ident_complete
14997 -
14998 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
14999 - leaq level3_ident_pgt(%rip), %rbx
15000 - movq %rdx, 0(%rbx, %rax, 8)
15001 -
15002 - movq %rdi, %rax
15003 - shrq $PMD_SHIFT, %rax
15004 - andq $(PTRS_PER_PMD - 1), %rax
15005 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
15006 - leaq level2_spare_pgt(%rip), %rbx
15007 - movq %rdx, 0(%rbx, %rax, 8)
15008 -ident_complete:
15009 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
15010
15011 /*
15012 * Fixup the kernel text+data virtual addresses. Note that
15013 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
15014 * after the boot processor executes this code.
15015 */
15016
15017 - /* Enable PAE mode and PGE */
15018 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
15019 + /* Enable PAE mode and PSE/PGE */
15020 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
15021 movq %rax, %cr4
15022
15023 /* Setup early boot stage 4 level pagetables. */
15024 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
15025 movl $MSR_EFER, %ecx
15026 rdmsr
15027 btsl $_EFER_SCE, %eax /* Enable System Call */
15028 - btl $20,%edi /* No Execute supported? */
15029 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
15030 jnc 1f
15031 btsl $_EFER_NX, %eax
15032 + leaq init_level4_pgt(%rip), %rdi
15033 +#ifndef CONFIG_EFI
15034 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
15035 +#endif
15036 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
15037 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
15038 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
15039 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
15040 1: wrmsr /* Make changes effective */
15041
15042 /* Setup cr0 */
15043 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
15044 * jump. In addition we need to ensure %cs is set so we make this
15045 * a far return.
15046 */
15047 + pax_set_fptr_mask
15048 movq initial_code(%rip),%rax
15049 pushq $0 # fake return address to stop unwinder
15050 pushq $__KERNEL_CS # set correct cs
15051 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
15052 bad_address:
15053 jmp bad_address
15054
15055 - .section ".init.text","ax"
15056 + __INIT
15057 #ifdef CONFIG_EARLY_PRINTK
15058 .globl early_idt_handlers
15059 early_idt_handlers:
15060 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
15061 #endif /* EARLY_PRINTK */
15062 1: hlt
15063 jmp 1b
15064 + .previous
15065
15066 #ifdef CONFIG_EARLY_PRINTK
15067 + __INITDATA
15068 early_recursion_flag:
15069 .long 0
15070 + .previous
15071
15072 + .section .rodata,"a",@progbits
15073 early_idt_msg:
15074 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
15075 early_idt_ripmsg:
15076 .asciz "RIP %s\n"
15077 + .previous
15078 #endif /* CONFIG_EARLY_PRINTK */
15079 - .previous
15080
15081 + .section .rodata,"a",@progbits
15082 #define NEXT_PAGE(name) \
15083 .balign PAGE_SIZE; \
15084 ENTRY(name)
15085 @@ -338,7 +348,6 @@ ENTRY(name)
15086 i = i + 1 ; \
15087 .endr
15088
15089 - .data
15090 /*
15091 * This default setting generates an ident mapping at address 0x100000
15092 * and a mapping for the kernel that precisely maps virtual address
15093 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
15094 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15095 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
15096 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15097 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
15098 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
15099 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
15100 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
15101 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
15102 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15103 .org init_level4_pgt + L4_START_KERNEL*8, 0
15104 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
15105 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
15106
15107 +#ifdef CONFIG_PAX_PER_CPU_PGD
15108 +NEXT_PAGE(cpu_pgd)
15109 + .rept NR_CPUS
15110 + .fill 512,8,0
15111 + .endr
15112 +#endif
15113 +
15114 NEXT_PAGE(level3_ident_pgt)
15115 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15116 +#ifdef CONFIG_XEN
15117 .fill 511,8,0
15118 +#else
15119 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
15120 + .fill 510,8,0
15121 +#endif
15122 +
15123 +NEXT_PAGE(level3_vmalloc_start_pgt)
15124 + .fill 512,8,0
15125 +
15126 +NEXT_PAGE(level3_vmalloc_end_pgt)
15127 + .fill 512,8,0
15128 +
15129 +NEXT_PAGE(level3_vmemmap_pgt)
15130 + .fill L3_VMEMMAP_START,8,0
15131 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15132
15133 NEXT_PAGE(level3_kernel_pgt)
15134 .fill L3_START_KERNEL,8,0
15135 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
15136 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
15137 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15138
15139 +NEXT_PAGE(level2_vmemmap_pgt)
15140 + .fill 512,8,0
15141 +
15142 NEXT_PAGE(level2_fixmap_pgt)
15143 - .fill 506,8,0
15144 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15145 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
15146 - .fill 5,8,0
15147 + .fill 507,8,0
15148 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
15149 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
15150 + .fill 4,8,0
15151
15152 -NEXT_PAGE(level1_fixmap_pgt)
15153 +NEXT_PAGE(level1_vsyscall_pgt)
15154 .fill 512,8,0
15155
15156 -NEXT_PAGE(level2_ident_pgt)
15157 - /* Since I easily can, map the first 1G.
15158 + /* Since I easily can, map the first 2G.
15159 * Don't set NX because code runs from these pages.
15160 */
15161 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
15162 +NEXT_PAGE(level2_ident_pgt)
15163 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
15164
15165 NEXT_PAGE(level2_kernel_pgt)
15166 /*
15167 @@ -389,33 +429,55 @@ NEXT_PAGE(level2_kernel_pgt)
15168 * If you want to increase this then increase MODULES_VADDR
15169 * too.)
15170 */
15171 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
15172 - KERNEL_IMAGE_SIZE/PMD_SIZE)
15173 -
15174 -NEXT_PAGE(level2_spare_pgt)
15175 - .fill 512, 8, 0
15176 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
15177
15178 #undef PMDS
15179 #undef NEXT_PAGE
15180
15181 - .data
15182 + .align PAGE_SIZE
15183 +ENTRY(cpu_gdt_table)
15184 + .rept NR_CPUS
15185 + .quad 0x0000000000000000 /* NULL descriptor */
15186 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
15187 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
15188 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
15189 + .quad 0x00cffb000000ffff /* __USER32_CS */
15190 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
15191 + .quad 0x00affb000000ffff /* __USER_CS */
15192 +
15193 +#ifdef CONFIG_PAX_KERNEXEC
15194 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
15195 +#else
15196 + .quad 0x0 /* unused */
15197 +#endif
15198 +
15199 + .quad 0,0 /* TSS */
15200 + .quad 0,0 /* LDT */
15201 + .quad 0,0,0 /* three TLS descriptors */
15202 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
15203 + /* asm/segment.h:GDT_ENTRIES must match this */
15204 +
15205 + /* zero the remaining page */
15206 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
15207 + .endr
15208 +
15209 .align 16
15210 .globl early_gdt_descr
15211 early_gdt_descr:
15212 .word GDT_ENTRIES*8-1
15213 early_gdt_descr_base:
15214 - .quad INIT_PER_CPU_VAR(gdt_page)
15215 + .quad cpu_gdt_table
15216
15217 ENTRY(phys_base)
15218 /* This must match the first entry in level2_kernel_pgt */
15219 .quad 0x0000000000000000
15220
15221 #include "../../x86/xen/xen-head.S"
15222 -
15223 - .section .bss, "aw", @nobits
15224 +
15225 + .section .rodata,"a",@progbits
15226 .align L1_CACHE_BYTES
15227 ENTRY(idt_table)
15228 - .skip IDT_ENTRIES * 16
15229 + .fill 512,8,0
15230
15231 __PAGE_ALIGNED_BSS
15232 .align PAGE_SIZE
15233 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
15234 index 9c3bd4a..e1d9b35 100644
15235 --- a/arch/x86/kernel/i386_ksyms_32.c
15236 +++ b/arch/x86/kernel/i386_ksyms_32.c
15237 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
15238 EXPORT_SYMBOL(cmpxchg8b_emu);
15239 #endif
15240
15241 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
15242 +
15243 /* Networking helper routines. */
15244 EXPORT_SYMBOL(csum_partial_copy_generic);
15245 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
15246 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
15247
15248 EXPORT_SYMBOL(__get_user_1);
15249 EXPORT_SYMBOL(__get_user_2);
15250 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
15251
15252 EXPORT_SYMBOL(csum_partial);
15253 EXPORT_SYMBOL(empty_zero_page);
15254 +
15255 +#ifdef CONFIG_PAX_KERNEXEC
15256 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
15257 +#endif
15258 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
15259 index 6104852..6114160 100644
15260 --- a/arch/x86/kernel/i8259.c
15261 +++ b/arch/x86/kernel/i8259.c
15262 @@ -210,7 +210,7 @@ spurious_8259A_irq:
15263 "spurious 8259A interrupt: IRQ%d.\n", irq);
15264 spurious_irq_mask |= irqmask;
15265 }
15266 - atomic_inc(&irq_err_count);
15267 + atomic_inc_unchecked(&irq_err_count);
15268 /*
15269 * Theoretically we do not have to handle this IRQ,
15270 * but in Linux this does not cause problems and is
15271 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
15272 index 43e9ccf..44ccf6f 100644
15273 --- a/arch/x86/kernel/init_task.c
15274 +++ b/arch/x86/kernel/init_task.c
15275 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
15276 * way process stacks are handled. This is done by having a special
15277 * "init_task" linker map entry..
15278 */
15279 -union thread_union init_thread_union __init_task_data =
15280 - { INIT_THREAD_INFO(init_task) };
15281 +union thread_union init_thread_union __init_task_data;
15282
15283 /*
15284 * Initial task structure.
15285 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
15286 * section. Since TSS's are completely CPU-local, we want them
15287 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
15288 */
15289 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
15290 -
15291 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
15292 +EXPORT_SYMBOL(init_tss);
15293 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
15294 index 8c96897..be66bfa 100644
15295 --- a/arch/x86/kernel/ioport.c
15296 +++ b/arch/x86/kernel/ioport.c
15297 @@ -6,6 +6,7 @@
15298 #include <linux/sched.h>
15299 #include <linux/kernel.h>
15300 #include <linux/capability.h>
15301 +#include <linux/security.h>
15302 #include <linux/errno.h>
15303 #include <linux/types.h>
15304 #include <linux/ioport.h>
15305 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
15306
15307 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
15308 return -EINVAL;
15309 +#ifdef CONFIG_GRKERNSEC_IO
15310 + if (turn_on && grsec_disable_privio) {
15311 + gr_handle_ioperm();
15312 + return -EPERM;
15313 + }
15314 +#endif
15315 if (turn_on && !capable(CAP_SYS_RAWIO))
15316 return -EPERM;
15317
15318 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
15319 * because the ->io_bitmap_max value must match the bitmap
15320 * contents:
15321 */
15322 - tss = &per_cpu(init_tss, get_cpu());
15323 + tss = init_tss + get_cpu();
15324
15325 if (turn_on)
15326 bitmap_clear(t->io_bitmap_ptr, from, num);
15327 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
15328 return -EINVAL;
15329 /* Trying to gain more privileges? */
15330 if (level > old) {
15331 +#ifdef CONFIG_GRKERNSEC_IO
15332 + if (grsec_disable_privio) {
15333 + gr_handle_iopl();
15334 + return -EPERM;
15335 + }
15336 +#endif
15337 if (!capable(CAP_SYS_RAWIO))
15338 return -EPERM;
15339 }
15340 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
15341 index 6c0802e..bea25ae 100644
15342 --- a/arch/x86/kernel/irq.c
15343 +++ b/arch/x86/kernel/irq.c
15344 @@ -17,7 +17,7 @@
15345 #include <asm/mce.h>
15346 #include <asm/hw_irq.h>
15347
15348 -atomic_t irq_err_count;
15349 +atomic_unchecked_t irq_err_count;
15350
15351 /* Function pointer for generic interrupt vector handling */
15352 void (*x86_platform_ipi_callback)(void) = NULL;
15353 @@ -116,9 +116,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
15354 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
15355 seq_printf(p, " Machine check polls\n");
15356 #endif
15357 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
15358 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
15359 #if defined(CONFIG_X86_IO_APIC)
15360 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
15361 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
15362 #endif
15363 return 0;
15364 }
15365 @@ -158,10 +158,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
15366
15367 u64 arch_irq_stat(void)
15368 {
15369 - u64 sum = atomic_read(&irq_err_count);
15370 + u64 sum = atomic_read_unchecked(&irq_err_count);
15371
15372 #ifdef CONFIG_X86_IO_APIC
15373 - sum += atomic_read(&irq_mis_count);
15374 + sum += atomic_read_unchecked(&irq_mis_count);
15375 #endif
15376 return sum;
15377 }
15378 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
15379 index 7209070..cbcd71a 100644
15380 --- a/arch/x86/kernel/irq_32.c
15381 +++ b/arch/x86/kernel/irq_32.c
15382 @@ -36,7 +36,7 @@ static int check_stack_overflow(void)
15383 __asm__ __volatile__("andl %%esp,%0" :
15384 "=r" (sp) : "0" (THREAD_SIZE - 1));
15385
15386 - return sp < (sizeof(struct thread_info) + STACK_WARN);
15387 + return sp < STACK_WARN;
15388 }
15389
15390 static void print_stack_overflow(void)
15391 @@ -54,8 +54,8 @@ static inline void print_stack_overflow(void) { }
15392 * per-CPU IRQ handling contexts (thread information and stack)
15393 */
15394 union irq_ctx {
15395 - struct thread_info tinfo;
15396 - u32 stack[THREAD_SIZE/sizeof(u32)];
15397 + unsigned long previous_esp;
15398 + u32 stack[THREAD_SIZE/sizeof(u32)];
15399 } __attribute__((aligned(THREAD_SIZE)));
15400
15401 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
15402 @@ -75,10 +75,9 @@ static void call_on_stack(void *func, void *stack)
15403 static inline int
15404 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15405 {
15406 - union irq_ctx *curctx, *irqctx;
15407 + union irq_ctx *irqctx;
15408 u32 *isp, arg1, arg2;
15409
15410 - curctx = (union irq_ctx *) current_thread_info();
15411 irqctx = __this_cpu_read(hardirq_ctx);
15412
15413 /*
15414 @@ -87,21 +86,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15415 * handler) we can't do that and just have to keep using the
15416 * current stack (which is the irq stack already after all)
15417 */
15418 - if (unlikely(curctx == irqctx))
15419 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
15420 return 0;
15421
15422 /* build the stack frame on the IRQ stack */
15423 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15424 - irqctx->tinfo.task = curctx->tinfo.task;
15425 - irqctx->tinfo.previous_esp = current_stack_pointer;
15426 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15427 + irqctx->previous_esp = current_stack_pointer;
15428
15429 - /*
15430 - * Copy the softirq bits in preempt_count so that the
15431 - * softirq checks work in the hardirq context.
15432 - */
15433 - irqctx->tinfo.preempt_count =
15434 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
15435 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
15436 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15437 + __set_fs(MAKE_MM_SEG(0));
15438 +#endif
15439
15440 if (unlikely(overflow))
15441 call_on_stack(print_stack_overflow, isp);
15442 @@ -113,6 +107,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15443 : "0" (irq), "1" (desc), "2" (isp),
15444 "D" (desc->handle_irq)
15445 : "memory", "cc", "ecx");
15446 +
15447 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15448 + __set_fs(current_thread_info()->addr_limit);
15449 +#endif
15450 +
15451 return 1;
15452 }
15453
15454 @@ -121,29 +120,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15455 */
15456 void __cpuinit irq_ctx_init(int cpu)
15457 {
15458 - union irq_ctx *irqctx;
15459 -
15460 if (per_cpu(hardirq_ctx, cpu))
15461 return;
15462
15463 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15464 - THREAD_FLAGS,
15465 - THREAD_ORDER));
15466 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15467 - irqctx->tinfo.cpu = cpu;
15468 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
15469 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15470 -
15471 - per_cpu(hardirq_ctx, cpu) = irqctx;
15472 -
15473 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15474 - THREAD_FLAGS,
15475 - THREAD_ORDER));
15476 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15477 - irqctx->tinfo.cpu = cpu;
15478 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15479 -
15480 - per_cpu(softirq_ctx, cpu) = irqctx;
15481 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15482 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15483
15484 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
15485 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
15486 @@ -152,7 +133,6 @@ void __cpuinit irq_ctx_init(int cpu)
15487 asmlinkage void do_softirq(void)
15488 {
15489 unsigned long flags;
15490 - struct thread_info *curctx;
15491 union irq_ctx *irqctx;
15492 u32 *isp;
15493
15494 @@ -162,15 +142,22 @@ asmlinkage void do_softirq(void)
15495 local_irq_save(flags);
15496
15497 if (local_softirq_pending()) {
15498 - curctx = current_thread_info();
15499 irqctx = __this_cpu_read(softirq_ctx);
15500 - irqctx->tinfo.task = curctx->task;
15501 - irqctx->tinfo.previous_esp = current_stack_pointer;
15502 + irqctx->previous_esp = current_stack_pointer;
15503
15504 /* build the stack frame on the softirq stack */
15505 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15506 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15507 +
15508 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15509 + __set_fs(MAKE_MM_SEG(0));
15510 +#endif
15511
15512 call_on_stack(__do_softirq, isp);
15513 +
15514 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15515 + __set_fs(current_thread_info()->addr_limit);
15516 +#endif
15517 +
15518 /*
15519 * Shouldn't happen, we returned above if in_interrupt():
15520 */
15521 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
15522 index 00354d4..187ae44 100644
15523 --- a/arch/x86/kernel/kgdb.c
15524 +++ b/arch/x86/kernel/kgdb.c
15525 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
15526 #ifdef CONFIG_X86_32
15527 switch (regno) {
15528 case GDB_SS:
15529 - if (!user_mode_vm(regs))
15530 + if (!user_mode(regs))
15531 *(unsigned long *)mem = __KERNEL_DS;
15532 break;
15533 case GDB_SP:
15534 - if (!user_mode_vm(regs))
15535 + if (!user_mode(regs))
15536 *(unsigned long *)mem = kernel_stack_pointer(regs);
15537 break;
15538 case GDB_GS:
15539 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
15540 case 'k':
15541 /* clear the trace bit */
15542 linux_regs->flags &= ~X86_EFLAGS_TF;
15543 - atomic_set(&kgdb_cpu_doing_single_step, -1);
15544 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
15545
15546 /* set the trace bit if we're stepping */
15547 if (remcomInBuffer[0] == 's') {
15548 linux_regs->flags |= X86_EFLAGS_TF;
15549 - atomic_set(&kgdb_cpu_doing_single_step,
15550 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
15551 raw_smp_processor_id());
15552 }
15553
15554 @@ -534,7 +534,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
15555 return NOTIFY_DONE;
15556
15557 case DIE_DEBUG:
15558 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
15559 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
15560 if (user_mode(regs))
15561 return single_step_cont(regs, args);
15562 break;
15563 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
15564 index 794bc95..c6e29e9 100644
15565 --- a/arch/x86/kernel/kprobes.c
15566 +++ b/arch/x86/kernel/kprobes.c
15567 @@ -117,8 +117,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
15568 } __attribute__((packed)) *insn;
15569
15570 insn = (struct __arch_relative_insn *)from;
15571 +
15572 + pax_open_kernel();
15573 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
15574 insn->op = op;
15575 + pax_close_kernel();
15576 }
15577
15578 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
15579 @@ -155,7 +158,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
15580 kprobe_opcode_t opcode;
15581 kprobe_opcode_t *orig_opcodes = opcodes;
15582
15583 - if (search_exception_tables((unsigned long)opcodes))
15584 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
15585 return 0; /* Page fault may occur on this address. */
15586
15587 retry:
15588 @@ -316,7 +319,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
15589 }
15590 }
15591 insn_get_length(&insn);
15592 + pax_open_kernel();
15593 memcpy(dest, insn.kaddr, insn.length);
15594 + pax_close_kernel();
15595
15596 #ifdef CONFIG_X86_64
15597 if (insn_rip_relative(&insn)) {
15598 @@ -340,7 +345,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
15599 (u8 *) dest;
15600 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
15601 disp = (u8 *) dest + insn_offset_displacement(&insn);
15602 + pax_open_kernel();
15603 *(s32 *) disp = (s32) newdisp;
15604 + pax_close_kernel();
15605 }
15606 #endif
15607 return insn.length;
15608 @@ -354,12 +361,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
15609 */
15610 __copy_instruction(p->ainsn.insn, p->addr, 0);
15611
15612 - if (can_boost(p->addr))
15613 + if (can_boost(ktla_ktva(p->addr)))
15614 p->ainsn.boostable = 0;
15615 else
15616 p->ainsn.boostable = -1;
15617
15618 - p->opcode = *p->addr;
15619 + p->opcode = *(ktla_ktva(p->addr));
15620 }
15621
15622 int __kprobes arch_prepare_kprobe(struct kprobe *p)
15623 @@ -476,7 +483,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
15624 * nor set current_kprobe, because it doesn't use single
15625 * stepping.
15626 */
15627 - regs->ip = (unsigned long)p->ainsn.insn;
15628 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15629 preempt_enable_no_resched();
15630 return;
15631 }
15632 @@ -495,7 +502,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
15633 if (p->opcode == BREAKPOINT_INSTRUCTION)
15634 regs->ip = (unsigned long)p->addr;
15635 else
15636 - regs->ip = (unsigned long)p->ainsn.insn;
15637 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15638 }
15639
15640 /*
15641 @@ -574,7 +581,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
15642 setup_singlestep(p, regs, kcb, 0);
15643 return 1;
15644 }
15645 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
15646 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
15647 /*
15648 * The breakpoint instruction was removed right
15649 * after we hit it. Another cpu has removed
15650 @@ -682,6 +689,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
15651 " movq %rax, 152(%rsp)\n"
15652 RESTORE_REGS_STRING
15653 " popfq\n"
15654 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
15655 + " btsq $63,(%rsp)\n"
15656 +#endif
15657 #else
15658 " pushf\n"
15659 SAVE_REGS_STRING
15660 @@ -819,7 +829,7 @@ static void __kprobes resume_execution(struct kprobe *p,
15661 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
15662 {
15663 unsigned long *tos = stack_addr(regs);
15664 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
15665 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
15666 unsigned long orig_ip = (unsigned long)p->addr;
15667 kprobe_opcode_t *insn = p->ainsn.insn;
15668
15669 @@ -1001,7 +1011,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
15670 struct die_args *args = data;
15671 int ret = NOTIFY_DONE;
15672
15673 - if (args->regs && user_mode_vm(args->regs))
15674 + if (args->regs && user_mode(args->regs))
15675 return ret;
15676
15677 switch (val) {
15678 @@ -1383,7 +1393,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
15679 * Verify if the address gap is in 2GB range, because this uses
15680 * a relative jump.
15681 */
15682 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
15683 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
15684 if (abs(rel) > 0x7fffffff)
15685 return -ERANGE;
15686
15687 @@ -1404,11 +1414,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
15688 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
15689
15690 /* Set probe function call */
15691 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
15692 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
15693
15694 /* Set returning jmp instruction at the tail of out-of-line buffer */
15695 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
15696 - (u8 *)op->kp.addr + op->optinsn.size);
15697 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
15698
15699 flush_icache_range((unsigned long) buf,
15700 (unsigned long) buf + TMPL_END_IDX +
15701 @@ -1430,7 +1440,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
15702 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
15703
15704 /* Backup instructions which will be replaced by jump address */
15705 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
15706 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
15707 RELATIVE_ADDR_SIZE);
15708
15709 insn_buf[0] = RELATIVEJUMP_OPCODE;
15710 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
15711 index a9c2116..a52d4fc 100644
15712 --- a/arch/x86/kernel/kvm.c
15713 +++ b/arch/x86/kernel/kvm.c
15714 @@ -437,6 +437,7 @@ static void __init paravirt_ops_setup(void)
15715 pv_mmu_ops.set_pud = kvm_set_pud;
15716 #if PAGETABLE_LEVELS == 4
15717 pv_mmu_ops.set_pgd = kvm_set_pgd;
15718 + pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
15719 #endif
15720 #endif
15721 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
15722 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
15723 index ea69726..604d066 100644
15724 --- a/arch/x86/kernel/ldt.c
15725 +++ b/arch/x86/kernel/ldt.c
15726 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
15727 if (reload) {
15728 #ifdef CONFIG_SMP
15729 preempt_disable();
15730 - load_LDT(pc);
15731 + load_LDT_nolock(pc);
15732 if (!cpumask_equal(mm_cpumask(current->mm),
15733 cpumask_of(smp_processor_id())))
15734 smp_call_function(flush_ldt, current->mm, 1);
15735 preempt_enable();
15736 #else
15737 - load_LDT(pc);
15738 + load_LDT_nolock(pc);
15739 #endif
15740 }
15741 if (oldsize) {
15742 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
15743 return err;
15744
15745 for (i = 0; i < old->size; i++)
15746 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
15747 + write_ldt_entry(new->ldt, i, old->ldt + i);
15748 return 0;
15749 }
15750
15751 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
15752 retval = copy_ldt(&mm->context, &old_mm->context);
15753 mutex_unlock(&old_mm->context.lock);
15754 }
15755 +
15756 + if (tsk == current) {
15757 + mm->context.vdso = 0;
15758 +
15759 +#ifdef CONFIG_X86_32
15760 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15761 + mm->context.user_cs_base = 0UL;
15762 + mm->context.user_cs_limit = ~0UL;
15763 +
15764 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15765 + cpus_clear(mm->context.cpu_user_cs_mask);
15766 +#endif
15767 +
15768 +#endif
15769 +#endif
15770 +
15771 + }
15772 +
15773 return retval;
15774 }
15775
15776 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
15777 }
15778 }
15779
15780 +#ifdef CONFIG_PAX_SEGMEXEC
15781 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
15782 + error = -EINVAL;
15783 + goto out_unlock;
15784 + }
15785 +#endif
15786 +
15787 fill_ldt(&ldt, &ldt_info);
15788 if (oldmode)
15789 ldt.avl = 0;
15790 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
15791 index a3fa43b..8966f4c 100644
15792 --- a/arch/x86/kernel/machine_kexec_32.c
15793 +++ b/arch/x86/kernel/machine_kexec_32.c
15794 @@ -27,7 +27,7 @@
15795 #include <asm/cacheflush.h>
15796 #include <asm/debugreg.h>
15797
15798 -static void set_idt(void *newidt, __u16 limit)
15799 +static void set_idt(struct desc_struct *newidt, __u16 limit)
15800 {
15801 struct desc_ptr curidt;
15802
15803 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
15804 }
15805
15806
15807 -static void set_gdt(void *newgdt, __u16 limit)
15808 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
15809 {
15810 struct desc_ptr curgdt;
15811
15812 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
15813 }
15814
15815 control_page = page_address(image->control_code_page);
15816 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
15817 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
15818
15819 relocate_kernel_ptr = control_page;
15820 page_list[PA_CONTROL_PAGE] = __pa(control_page);
15821 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
15822 index 1a1b606..5c89b55 100644
15823 --- a/arch/x86/kernel/microcode_intel.c
15824 +++ b/arch/x86/kernel/microcode_intel.c
15825 @@ -440,13 +440,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
15826
15827 static int get_ucode_user(void *to, const void *from, size_t n)
15828 {
15829 - return copy_from_user(to, from, n);
15830 + return copy_from_user(to, (const void __force_user *)from, n);
15831 }
15832
15833 static enum ucode_state
15834 request_microcode_user(int cpu, const void __user *buf, size_t size)
15835 {
15836 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
15837 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
15838 }
15839
15840 static void microcode_fini_cpu(int cpu)
15841 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
15842 index 925179f..85bec6c 100644
15843 --- a/arch/x86/kernel/module.c
15844 +++ b/arch/x86/kernel/module.c
15845 @@ -36,15 +36,60 @@
15846 #define DEBUGP(fmt...)
15847 #endif
15848
15849 -void *module_alloc(unsigned long size)
15850 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
15851 {
15852 if (PAGE_ALIGN(size) > MODULES_LEN)
15853 return NULL;
15854 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
15855 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
15856 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
15857 -1, __builtin_return_address(0));
15858 }
15859
15860 +void *module_alloc(unsigned long size)
15861 +{
15862 +
15863 +#ifdef CONFIG_PAX_KERNEXEC
15864 + return __module_alloc(size, PAGE_KERNEL);
15865 +#else
15866 + return __module_alloc(size, PAGE_KERNEL_EXEC);
15867 +#endif
15868 +
15869 +}
15870 +
15871 +#ifdef CONFIG_PAX_KERNEXEC
15872 +#ifdef CONFIG_X86_32
15873 +void *module_alloc_exec(unsigned long size)
15874 +{
15875 + struct vm_struct *area;
15876 +
15877 + if (size == 0)
15878 + return NULL;
15879 +
15880 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
15881 + return area ? area->addr : NULL;
15882 +}
15883 +EXPORT_SYMBOL(module_alloc_exec);
15884 +
15885 +void module_free_exec(struct module *mod, void *module_region)
15886 +{
15887 + vunmap(module_region);
15888 +}
15889 +EXPORT_SYMBOL(module_free_exec);
15890 +#else
15891 +void module_free_exec(struct module *mod, void *module_region)
15892 +{
15893 + module_free(mod, module_region);
15894 +}
15895 +EXPORT_SYMBOL(module_free_exec);
15896 +
15897 +void *module_alloc_exec(unsigned long size)
15898 +{
15899 + return __module_alloc(size, PAGE_KERNEL_RX);
15900 +}
15901 +EXPORT_SYMBOL(module_alloc_exec);
15902 +#endif
15903 +#endif
15904 +
15905 #ifdef CONFIG_X86_32
15906 int apply_relocate(Elf32_Shdr *sechdrs,
15907 const char *strtab,
15908 @@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
15909 unsigned int i;
15910 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
15911 Elf32_Sym *sym;
15912 - uint32_t *location;
15913 + uint32_t *plocation, location;
15914
15915 DEBUGP("Applying relocate section %u to %u\n", relsec,
15916 sechdrs[relsec].sh_info);
15917 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
15918 /* This is where to make the change */
15919 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
15920 - + rel[i].r_offset;
15921 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
15922 + location = (uint32_t)plocation;
15923 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
15924 + plocation = ktla_ktva((void *)plocation);
15925 /* This is the symbol it is referring to. Note that all
15926 undefined symbols have been resolved. */
15927 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
15928 @@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
15929 switch (ELF32_R_TYPE(rel[i].r_info)) {
15930 case R_386_32:
15931 /* We add the value into the location given */
15932 - *location += sym->st_value;
15933 + pax_open_kernel();
15934 + *plocation += sym->st_value;
15935 + pax_close_kernel();
15936 break;
15937 case R_386_PC32:
15938 /* Add the value, subtract its postition */
15939 - *location += sym->st_value - (uint32_t)location;
15940 + pax_open_kernel();
15941 + *plocation += sym->st_value - location;
15942 + pax_close_kernel();
15943 break;
15944 default:
15945 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
15946 @@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
15947 case R_X86_64_NONE:
15948 break;
15949 case R_X86_64_64:
15950 + pax_open_kernel();
15951 *(u64 *)loc = val;
15952 + pax_close_kernel();
15953 break;
15954 case R_X86_64_32:
15955 + pax_open_kernel();
15956 *(u32 *)loc = val;
15957 + pax_close_kernel();
15958 if (val != *(u32 *)loc)
15959 goto overflow;
15960 break;
15961 case R_X86_64_32S:
15962 + pax_open_kernel();
15963 *(s32 *)loc = val;
15964 + pax_close_kernel();
15965 if ((s64)val != *(s32 *)loc)
15966 goto overflow;
15967 break;
15968 case R_X86_64_PC32:
15969 val -= (u64)loc;
15970 + pax_open_kernel();
15971 *(u32 *)loc = val;
15972 + pax_close_kernel();
15973 +
15974 #if 0
15975 if ((s64)val != *(s32 *)loc)
15976 goto overflow;
15977 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
15978 index 676b8c7..870ba04 100644
15979 --- a/arch/x86/kernel/paravirt-spinlocks.c
15980 +++ b/arch/x86/kernel/paravirt-spinlocks.c
15981 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
15982 arch_spin_lock(lock);
15983 }
15984
15985 -struct pv_lock_ops pv_lock_ops = {
15986 +struct pv_lock_ops pv_lock_ops __read_only = {
15987 #ifdef CONFIG_SMP
15988 .spin_is_locked = __ticket_spin_is_locked,
15989 .spin_is_contended = __ticket_spin_is_contended,
15990 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
15991 index d90272e..2d54e8e 100644
15992 --- a/arch/x86/kernel/paravirt.c
15993 +++ b/arch/x86/kernel/paravirt.c
15994 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
15995 {
15996 return x;
15997 }
15998 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
15999 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
16000 +#endif
16001
16002 void __init default_banner(void)
16003 {
16004 @@ -133,6 +136,9 @@ static void *get_call_destination(u8 type)
16005 .pv_lock_ops = pv_lock_ops,
16006 #endif
16007 };
16008 +
16009 + pax_track_stack();
16010 +
16011 return *((void **)&tmpl + type);
16012 }
16013
16014 @@ -145,15 +151,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
16015 if (opfunc == NULL)
16016 /* If there's no function, patch it with a ud2a (BUG) */
16017 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
16018 - else if (opfunc == _paravirt_nop)
16019 + else if (opfunc == (void *)_paravirt_nop)
16020 /* If the operation is a nop, then nop the callsite */
16021 ret = paravirt_patch_nop();
16022
16023 /* identity functions just return their single argument */
16024 - else if (opfunc == _paravirt_ident_32)
16025 + else if (opfunc == (void *)_paravirt_ident_32)
16026 ret = paravirt_patch_ident_32(insnbuf, len);
16027 - else if (opfunc == _paravirt_ident_64)
16028 + else if (opfunc == (void *)_paravirt_ident_64)
16029 ret = paravirt_patch_ident_64(insnbuf, len);
16030 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
16031 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
16032 + ret = paravirt_patch_ident_64(insnbuf, len);
16033 +#endif
16034
16035 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
16036 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
16037 @@ -178,7 +188,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
16038 if (insn_len > len || start == NULL)
16039 insn_len = len;
16040 else
16041 - memcpy(insnbuf, start, insn_len);
16042 + memcpy(insnbuf, ktla_ktva(start), insn_len);
16043
16044 return insn_len;
16045 }
16046 @@ -302,7 +312,7 @@ void arch_flush_lazy_mmu_mode(void)
16047 preempt_enable();
16048 }
16049
16050 -struct pv_info pv_info = {
16051 +struct pv_info pv_info __read_only = {
16052 .name = "bare hardware",
16053 .paravirt_enabled = 0,
16054 .kernel_rpl = 0,
16055 @@ -313,16 +323,16 @@ struct pv_info pv_info = {
16056 #endif
16057 };
16058
16059 -struct pv_init_ops pv_init_ops = {
16060 +struct pv_init_ops pv_init_ops __read_only = {
16061 .patch = native_patch,
16062 };
16063
16064 -struct pv_time_ops pv_time_ops = {
16065 +struct pv_time_ops pv_time_ops __read_only = {
16066 .sched_clock = native_sched_clock,
16067 .steal_clock = native_steal_clock,
16068 };
16069
16070 -struct pv_irq_ops pv_irq_ops = {
16071 +struct pv_irq_ops pv_irq_ops __read_only = {
16072 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
16073 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
16074 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
16075 @@ -334,7 +344,7 @@ struct pv_irq_ops pv_irq_ops = {
16076 #endif
16077 };
16078
16079 -struct pv_cpu_ops pv_cpu_ops = {
16080 +struct pv_cpu_ops pv_cpu_ops __read_only = {
16081 .cpuid = native_cpuid,
16082 .get_debugreg = native_get_debugreg,
16083 .set_debugreg = native_set_debugreg,
16084 @@ -395,21 +405,26 @@ struct pv_cpu_ops pv_cpu_ops = {
16085 .end_context_switch = paravirt_nop,
16086 };
16087
16088 -struct pv_apic_ops pv_apic_ops = {
16089 +struct pv_apic_ops pv_apic_ops __read_only = {
16090 #ifdef CONFIG_X86_LOCAL_APIC
16091 .startup_ipi_hook = paravirt_nop,
16092 #endif
16093 };
16094
16095 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
16096 +#ifdef CONFIG_X86_32
16097 +#ifdef CONFIG_X86_PAE
16098 +/* 64-bit pagetable entries */
16099 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
16100 +#else
16101 /* 32-bit pagetable entries */
16102 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
16103 +#endif
16104 #else
16105 /* 64-bit pagetable entries */
16106 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
16107 #endif
16108
16109 -struct pv_mmu_ops pv_mmu_ops = {
16110 +struct pv_mmu_ops pv_mmu_ops __read_only = {
16111
16112 .read_cr2 = native_read_cr2,
16113 .write_cr2 = native_write_cr2,
16114 @@ -459,6 +474,7 @@ struct pv_mmu_ops pv_mmu_ops = {
16115 .make_pud = PTE_IDENT,
16116
16117 .set_pgd = native_set_pgd,
16118 + .set_pgd_batched = native_set_pgd_batched,
16119 #endif
16120 #endif /* PAGETABLE_LEVELS >= 3 */
16121
16122 @@ -478,6 +494,12 @@ struct pv_mmu_ops pv_mmu_ops = {
16123 },
16124
16125 .set_fixmap = native_set_fixmap,
16126 +
16127 +#ifdef CONFIG_PAX_KERNEXEC
16128 + .pax_open_kernel = native_pax_open_kernel,
16129 + .pax_close_kernel = native_pax_close_kernel,
16130 +#endif
16131 +
16132 };
16133
16134 EXPORT_SYMBOL_GPL(pv_time_ops);
16135 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
16136 index 35ccf75..67e7d4d 100644
16137 --- a/arch/x86/kernel/pci-iommu_table.c
16138 +++ b/arch/x86/kernel/pci-iommu_table.c
16139 @@ -2,7 +2,7 @@
16140 #include <asm/iommu_table.h>
16141 #include <linux/string.h>
16142 #include <linux/kallsyms.h>
16143 -
16144 +#include <linux/sched.h>
16145
16146 #define DEBUG 1
16147
16148 @@ -51,6 +51,8 @@ void __init check_iommu_entries(struct iommu_table_entry *start,
16149 {
16150 struct iommu_table_entry *p, *q, *x;
16151
16152 + pax_track_stack();
16153 +
16154 /* Simple cyclic dependency checker. */
16155 for (p = start; p < finish; p++) {
16156 q = find_dependents_of(start, finish, p);
16157 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
16158 index 30eb651..37fa2d7 100644
16159 --- a/arch/x86/kernel/process.c
16160 +++ b/arch/x86/kernel/process.c
16161 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
16162
16163 void free_thread_info(struct thread_info *ti)
16164 {
16165 - free_thread_xstate(ti->task);
16166 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
16167 }
16168
16169 +static struct kmem_cache *task_struct_cachep;
16170 +
16171 void arch_task_cache_init(void)
16172 {
16173 - task_xstate_cachep =
16174 - kmem_cache_create("task_xstate", xstate_size,
16175 + /* create a slab on which task_structs can be allocated */
16176 + task_struct_cachep =
16177 + kmem_cache_create("task_struct", sizeof(struct task_struct),
16178 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
16179 +
16180 + task_xstate_cachep =
16181 + kmem_cache_create("task_xstate", xstate_size,
16182 __alignof__(union thread_xstate),
16183 - SLAB_PANIC | SLAB_NOTRACK, NULL);
16184 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
16185 +}
16186 +
16187 +struct task_struct *alloc_task_struct_node(int node)
16188 +{
16189 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
16190 +}
16191 +
16192 +void free_task_struct(struct task_struct *task)
16193 +{
16194 + free_thread_xstate(task);
16195 + kmem_cache_free(task_struct_cachep, task);
16196 }
16197
16198 /*
16199 @@ -70,7 +87,7 @@ void exit_thread(void)
16200 unsigned long *bp = t->io_bitmap_ptr;
16201
16202 if (bp) {
16203 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
16204 + struct tss_struct *tss = init_tss + get_cpu();
16205
16206 t->io_bitmap_ptr = NULL;
16207 clear_thread_flag(TIF_IO_BITMAP);
16208 @@ -106,7 +123,7 @@ void show_regs_common(void)
16209
16210 printk(KERN_CONT "\n");
16211 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
16212 - current->pid, current->comm, print_tainted(),
16213 + task_pid_nr(current), current->comm, print_tainted(),
16214 init_utsname()->release,
16215 (int)strcspn(init_utsname()->version, " "),
16216 init_utsname()->version);
16217 @@ -120,6 +137,9 @@ void flush_thread(void)
16218 {
16219 struct task_struct *tsk = current;
16220
16221 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16222 + loadsegment(gs, 0);
16223 +#endif
16224 flush_ptrace_hw_breakpoint(tsk);
16225 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
16226 /*
16227 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
16228 regs.di = (unsigned long) arg;
16229
16230 #ifdef CONFIG_X86_32
16231 - regs.ds = __USER_DS;
16232 - regs.es = __USER_DS;
16233 + regs.ds = __KERNEL_DS;
16234 + regs.es = __KERNEL_DS;
16235 regs.fs = __KERNEL_PERCPU;
16236 - regs.gs = __KERNEL_STACK_CANARY;
16237 + savesegment(gs, regs.gs);
16238 #else
16239 regs.ss = __KERNEL_DS;
16240 #endif
16241 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
16242
16243 return ret;
16244 }
16245 -void stop_this_cpu(void *dummy)
16246 +__noreturn void stop_this_cpu(void *dummy)
16247 {
16248 local_irq_disable();
16249 /*
16250 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
16251 }
16252 early_param("idle", idle_setup);
16253
16254 -unsigned long arch_align_stack(unsigned long sp)
16255 +#ifdef CONFIG_PAX_RANDKSTACK
16256 +void pax_randomize_kstack(struct pt_regs *regs)
16257 {
16258 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
16259 - sp -= get_random_int() % 8192;
16260 - return sp & ~0xf;
16261 -}
16262 + struct thread_struct *thread = &current->thread;
16263 + unsigned long time;
16264
16265 -unsigned long arch_randomize_brk(struct mm_struct *mm)
16266 -{
16267 - unsigned long range_end = mm->brk + 0x02000000;
16268 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
16269 -}
16270 + if (!randomize_va_space)
16271 + return;
16272 +
16273 + if (v8086_mode(regs))
16274 + return;
16275
16276 + rdtscl(time);
16277 +
16278 + /* P4 seems to return a 0 LSB, ignore it */
16279 +#ifdef CONFIG_MPENTIUM4
16280 + time &= 0x3EUL;
16281 + time <<= 2;
16282 +#elif defined(CONFIG_X86_64)
16283 + time &= 0xFUL;
16284 + time <<= 4;
16285 +#else
16286 + time &= 0x1FUL;
16287 + time <<= 3;
16288 +#endif
16289 +
16290 + thread->sp0 ^= time;
16291 + load_sp0(init_tss + smp_processor_id(), thread);
16292 +
16293 +#ifdef CONFIG_X86_64
16294 + percpu_write(kernel_stack, thread->sp0);
16295 +#endif
16296 +}
16297 +#endif
16298 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
16299 index 7a3b651..5a946f6 100644
16300 --- a/arch/x86/kernel/process_32.c
16301 +++ b/arch/x86/kernel/process_32.c
16302 @@ -66,6 +66,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
16303 unsigned long thread_saved_pc(struct task_struct *tsk)
16304 {
16305 return ((unsigned long *)tsk->thread.sp)[3];
16306 +//XXX return tsk->thread.eip;
16307 }
16308
16309 #ifndef CONFIG_SMP
16310 @@ -128,15 +129,14 @@ void __show_regs(struct pt_regs *regs, int all)
16311 unsigned long sp;
16312 unsigned short ss, gs;
16313
16314 - if (user_mode_vm(regs)) {
16315 + if (user_mode(regs)) {
16316 sp = regs->sp;
16317 ss = regs->ss & 0xffff;
16318 - gs = get_user_gs(regs);
16319 } else {
16320 sp = kernel_stack_pointer(regs);
16321 savesegment(ss, ss);
16322 - savesegment(gs, gs);
16323 }
16324 + gs = get_user_gs(regs);
16325
16326 show_regs_common();
16327
16328 @@ -198,13 +198,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16329 struct task_struct *tsk;
16330 int err;
16331
16332 - childregs = task_pt_regs(p);
16333 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
16334 *childregs = *regs;
16335 childregs->ax = 0;
16336 childregs->sp = sp;
16337
16338 p->thread.sp = (unsigned long) childregs;
16339 p->thread.sp0 = (unsigned long) (childregs+1);
16340 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16341
16342 p->thread.ip = (unsigned long) ret_from_fork;
16343
16344 @@ -294,7 +295,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16345 struct thread_struct *prev = &prev_p->thread,
16346 *next = &next_p->thread;
16347 int cpu = smp_processor_id();
16348 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16349 + struct tss_struct *tss = init_tss + cpu;
16350 bool preload_fpu;
16351
16352 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
16353 @@ -329,6 +330,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16354 */
16355 lazy_save_gs(prev->gs);
16356
16357 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16358 + __set_fs(task_thread_info(next_p)->addr_limit);
16359 +#endif
16360 +
16361 /*
16362 * Load the per-thread Thread-Local Storage descriptor.
16363 */
16364 @@ -364,6 +369,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16365 */
16366 arch_end_context_switch(next_p);
16367
16368 + percpu_write(current_task, next_p);
16369 + percpu_write(current_tinfo, &next_p->tinfo);
16370 +
16371 if (preload_fpu)
16372 __math_state_restore();
16373
16374 @@ -373,8 +381,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16375 if (prev->gs | next->gs)
16376 lazy_load_gs(next->gs);
16377
16378 - percpu_write(current_task, next_p);
16379 -
16380 return prev_p;
16381 }
16382
16383 @@ -404,4 +410,3 @@ unsigned long get_wchan(struct task_struct *p)
16384 } while (count++ < 16);
16385 return 0;
16386 }
16387 -
16388 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
16389 index f693e44..3c979b2 100644
16390 --- a/arch/x86/kernel/process_64.c
16391 +++ b/arch/x86/kernel/process_64.c
16392 @@ -88,7 +88,7 @@ static void __exit_idle(void)
16393 void exit_idle(void)
16394 {
16395 /* idle loop has pid 0 */
16396 - if (current->pid)
16397 + if (task_pid_nr(current))
16398 return;
16399 __exit_idle();
16400 }
16401 @@ -262,8 +262,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16402 struct pt_regs *childregs;
16403 struct task_struct *me = current;
16404
16405 - childregs = ((struct pt_regs *)
16406 - (THREAD_SIZE + task_stack_page(p))) - 1;
16407 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
16408 *childregs = *regs;
16409
16410 childregs->ax = 0;
16411 @@ -275,6 +274,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16412 p->thread.sp = (unsigned long) childregs;
16413 p->thread.sp0 = (unsigned long) (childregs+1);
16414 p->thread.usersp = me->thread.usersp;
16415 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16416
16417 set_tsk_thread_flag(p, TIF_FORK);
16418
16419 @@ -377,7 +377,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16420 struct thread_struct *prev = &prev_p->thread;
16421 struct thread_struct *next = &next_p->thread;
16422 int cpu = smp_processor_id();
16423 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16424 + struct tss_struct *tss = init_tss + cpu;
16425 unsigned fsindex, gsindex;
16426 bool preload_fpu;
16427
16428 @@ -473,10 +473,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16429 prev->usersp = percpu_read(old_rsp);
16430 percpu_write(old_rsp, next->usersp);
16431 percpu_write(current_task, next_p);
16432 + percpu_write(current_tinfo, &next_p->tinfo);
16433
16434 - percpu_write(kernel_stack,
16435 - (unsigned long)task_stack_page(next_p) +
16436 - THREAD_SIZE - KERNEL_STACK_OFFSET);
16437 + percpu_write(kernel_stack, next->sp0);
16438
16439 /*
16440 * Now maybe reload the debug registers and handle I/O bitmaps
16441 @@ -538,12 +537,11 @@ unsigned long get_wchan(struct task_struct *p)
16442 if (!p || p == current || p->state == TASK_RUNNING)
16443 return 0;
16444 stack = (unsigned long)task_stack_page(p);
16445 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
16446 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
16447 return 0;
16448 fp = *(u64 *)(p->thread.sp);
16449 do {
16450 - if (fp < (unsigned long)stack ||
16451 - fp >= (unsigned long)stack+THREAD_SIZE)
16452 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
16453 return 0;
16454 ip = *(u64 *)(fp+8);
16455 if (!in_sched_functions(ip))
16456 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
16457 index 8252879..d3219e0 100644
16458 --- a/arch/x86/kernel/ptrace.c
16459 +++ b/arch/x86/kernel/ptrace.c
16460 @@ -822,7 +822,7 @@ long arch_ptrace(struct task_struct *child, long request,
16461 unsigned long addr, unsigned long data)
16462 {
16463 int ret;
16464 - unsigned long __user *datap = (unsigned long __user *)data;
16465 + unsigned long __user *datap = (__force unsigned long __user *)data;
16466
16467 switch (request) {
16468 /* read the word at location addr in the USER area. */
16469 @@ -907,14 +907,14 @@ long arch_ptrace(struct task_struct *child, long request,
16470 if ((int) addr < 0)
16471 return -EIO;
16472 ret = do_get_thread_area(child, addr,
16473 - (struct user_desc __user *)data);
16474 + (__force struct user_desc __user *) data);
16475 break;
16476
16477 case PTRACE_SET_THREAD_AREA:
16478 if ((int) addr < 0)
16479 return -EIO;
16480 ret = do_set_thread_area(child, addr,
16481 - (struct user_desc __user *)data, 0);
16482 + (__force struct user_desc __user *) data, 0);
16483 break;
16484 #endif
16485
16486 @@ -1331,7 +1331,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
16487 memset(info, 0, sizeof(*info));
16488 info->si_signo = SIGTRAP;
16489 info->si_code = si_code;
16490 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
16491 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
16492 }
16493
16494 void user_single_step_siginfo(struct task_struct *tsk,
16495 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
16496 index 42eb330..139955c 100644
16497 --- a/arch/x86/kernel/pvclock.c
16498 +++ b/arch/x86/kernel/pvclock.c
16499 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
16500 return pv_tsc_khz;
16501 }
16502
16503 -static atomic64_t last_value = ATOMIC64_INIT(0);
16504 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
16505
16506 void pvclock_resume(void)
16507 {
16508 - atomic64_set(&last_value, 0);
16509 + atomic64_set_unchecked(&last_value, 0);
16510 }
16511
16512 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16513 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16514 * updating at the same time, and one of them could be slightly behind,
16515 * making the assumption that last_value always go forward fail to hold.
16516 */
16517 - last = atomic64_read(&last_value);
16518 + last = atomic64_read_unchecked(&last_value);
16519 do {
16520 if (ret < last)
16521 return last;
16522 - last = atomic64_cmpxchg(&last_value, last, ret);
16523 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
16524 } while (unlikely(last != ret));
16525
16526 return ret;
16527 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
16528 index d4a705f..ef8f1a9 100644
16529 --- a/arch/x86/kernel/reboot.c
16530 +++ b/arch/x86/kernel/reboot.c
16531 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
16532 EXPORT_SYMBOL(pm_power_off);
16533
16534 static const struct desc_ptr no_idt = {};
16535 -static int reboot_mode;
16536 +static unsigned short reboot_mode;
16537 enum reboot_type reboot_type = BOOT_ACPI;
16538 int reboot_force;
16539
16540 @@ -324,13 +324,17 @@ core_initcall(reboot_init);
16541 extern const unsigned char machine_real_restart_asm[];
16542 extern const u64 machine_real_restart_gdt[3];
16543
16544 -void machine_real_restart(unsigned int type)
16545 +__noreturn void machine_real_restart(unsigned int type)
16546 {
16547 void *restart_va;
16548 unsigned long restart_pa;
16549 - void (*restart_lowmem)(unsigned int);
16550 + void (* __noreturn restart_lowmem)(unsigned int);
16551 u64 *lowmem_gdt;
16552
16553 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16554 + struct desc_struct *gdt;
16555 +#endif
16556 +
16557 local_irq_disable();
16558
16559 /* Write zero to CMOS register number 0x0f, which the BIOS POST
16560 @@ -356,14 +360,14 @@ void machine_real_restart(unsigned int type)
16561 boot)". This seems like a fairly standard thing that gets set by
16562 REBOOT.COM programs, and the previous reset routine did this
16563 too. */
16564 - *((unsigned short *)0x472) = reboot_mode;
16565 + *(unsigned short *)(__va(0x472)) = reboot_mode;
16566
16567 /* Patch the GDT in the low memory trampoline */
16568 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
16569
16570 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
16571 restart_pa = virt_to_phys(restart_va);
16572 - restart_lowmem = (void (*)(unsigned int))restart_pa;
16573 + restart_lowmem = (void *)restart_pa;
16574
16575 /* GDT[0]: GDT self-pointer */
16576 lowmem_gdt[0] =
16577 @@ -374,7 +378,33 @@ void machine_real_restart(unsigned int type)
16578 GDT_ENTRY(0x009b, restart_pa, 0xffff);
16579
16580 /* Jump to the identity-mapped low memory code */
16581 +
16582 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16583 + gdt = get_cpu_gdt_table(smp_processor_id());
16584 + pax_open_kernel();
16585 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16586 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
16587 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
16588 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
16589 +#endif
16590 +#ifdef CONFIG_PAX_KERNEXEC
16591 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
16592 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
16593 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
16594 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
16595 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
16596 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
16597 +#endif
16598 + pax_close_kernel();
16599 +#endif
16600 +
16601 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16602 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
16603 + unreachable();
16604 +#else
16605 restart_lowmem(type);
16606 +#endif
16607 +
16608 }
16609 #ifdef CONFIG_APM_MODULE
16610 EXPORT_SYMBOL(machine_real_restart);
16611 @@ -532,7 +562,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
16612 * try to force a triple fault and then cycle between hitting the keyboard
16613 * controller and doing that
16614 */
16615 -static void native_machine_emergency_restart(void)
16616 +__noreturn static void native_machine_emergency_restart(void)
16617 {
16618 int i;
16619 int attempt = 0;
16620 @@ -656,13 +686,13 @@ void native_machine_shutdown(void)
16621 #endif
16622 }
16623
16624 -static void __machine_emergency_restart(int emergency)
16625 +static __noreturn void __machine_emergency_restart(int emergency)
16626 {
16627 reboot_emergency = emergency;
16628 machine_ops.emergency_restart();
16629 }
16630
16631 -static void native_machine_restart(char *__unused)
16632 +static __noreturn void native_machine_restart(char *__unused)
16633 {
16634 printk("machine restart\n");
16635
16636 @@ -671,7 +701,7 @@ static void native_machine_restart(char *__unused)
16637 __machine_emergency_restart(0);
16638 }
16639
16640 -static void native_machine_halt(void)
16641 +static __noreturn void native_machine_halt(void)
16642 {
16643 /* stop other cpus and apics */
16644 machine_shutdown();
16645 @@ -682,7 +712,7 @@ static void native_machine_halt(void)
16646 stop_this_cpu(NULL);
16647 }
16648
16649 -static void native_machine_power_off(void)
16650 +__noreturn static void native_machine_power_off(void)
16651 {
16652 if (pm_power_off) {
16653 if (!reboot_force)
16654 @@ -691,6 +721,7 @@ static void native_machine_power_off(void)
16655 }
16656 /* a fallback in case there is no PM info available */
16657 tboot_shutdown(TB_SHUTDOWN_HALT);
16658 + unreachable();
16659 }
16660
16661 struct machine_ops machine_ops = {
16662 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
16663 index 7a6f3b3..bed145d7 100644
16664 --- a/arch/x86/kernel/relocate_kernel_64.S
16665 +++ b/arch/x86/kernel/relocate_kernel_64.S
16666 @@ -11,6 +11,7 @@
16667 #include <asm/kexec.h>
16668 #include <asm/processor-flags.h>
16669 #include <asm/pgtable_types.h>
16670 +#include <asm/alternative-asm.h>
16671
16672 /*
16673 * Must be relocatable PIC code callable as a C function
16674 @@ -160,13 +161,14 @@ identity_mapped:
16675 xorq %rbp, %rbp
16676 xorq %r8, %r8
16677 xorq %r9, %r9
16678 - xorq %r10, %r9
16679 + xorq %r10, %r10
16680 xorq %r11, %r11
16681 xorq %r12, %r12
16682 xorq %r13, %r13
16683 xorq %r14, %r14
16684 xorq %r15, %r15
16685
16686 + pax_force_retaddr 0, 1
16687 ret
16688
16689 1:
16690 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
16691 index afaf384..1a101fe 100644
16692 --- a/arch/x86/kernel/setup.c
16693 +++ b/arch/x86/kernel/setup.c
16694 @@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
16695
16696 switch (data->type) {
16697 case SETUP_E820_EXT:
16698 - parse_e820_ext(data);
16699 + parse_e820_ext((struct setup_data __force_kernel *)data);
16700 break;
16701 case SETUP_DTB:
16702 add_dtb(pa_data);
16703 @@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
16704 * area (640->1Mb) as ram even though it is not.
16705 * take them out.
16706 */
16707 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
16708 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
16709 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
16710 }
16711
16712 @@ -773,14 +773,14 @@ void __init setup_arch(char **cmdline_p)
16713
16714 if (!boot_params.hdr.root_flags)
16715 root_mountflags &= ~MS_RDONLY;
16716 - init_mm.start_code = (unsigned long) _text;
16717 - init_mm.end_code = (unsigned long) _etext;
16718 + init_mm.start_code = ktla_ktva((unsigned long) _text);
16719 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
16720 init_mm.end_data = (unsigned long) _edata;
16721 init_mm.brk = _brk_end;
16722
16723 - code_resource.start = virt_to_phys(_text);
16724 - code_resource.end = virt_to_phys(_etext)-1;
16725 - data_resource.start = virt_to_phys(_etext);
16726 + code_resource.start = virt_to_phys(ktla_ktva(_text));
16727 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
16728 + data_resource.start = virt_to_phys(_sdata);
16729 data_resource.end = virt_to_phys(_edata)-1;
16730 bss_resource.start = virt_to_phys(&__bss_start);
16731 bss_resource.end = virt_to_phys(&__bss_stop)-1;
16732 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
16733 index 71f4727..16dc9f7 100644
16734 --- a/arch/x86/kernel/setup_percpu.c
16735 +++ b/arch/x86/kernel/setup_percpu.c
16736 @@ -21,19 +21,17 @@
16737 #include <asm/cpu.h>
16738 #include <asm/stackprotector.h>
16739
16740 -DEFINE_PER_CPU(int, cpu_number);
16741 +#ifdef CONFIG_SMP
16742 +DEFINE_PER_CPU(unsigned int, cpu_number);
16743 EXPORT_PER_CPU_SYMBOL(cpu_number);
16744 +#endif
16745
16746 -#ifdef CONFIG_X86_64
16747 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
16748 -#else
16749 -#define BOOT_PERCPU_OFFSET 0
16750 -#endif
16751
16752 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
16753 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
16754
16755 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
16756 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
16757 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
16758 };
16759 EXPORT_SYMBOL(__per_cpu_offset);
16760 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
16761 {
16762 #ifdef CONFIG_X86_32
16763 struct desc_struct gdt;
16764 + unsigned long base = per_cpu_offset(cpu);
16765
16766 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
16767 - 0x2 | DESCTYPE_S, 0x8);
16768 - gdt.s = 1;
16769 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
16770 + 0x83 | DESCTYPE_S, 0xC);
16771 write_gdt_entry(get_cpu_gdt_table(cpu),
16772 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
16773 #endif
16774 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
16775 /* alrighty, percpu areas up and running */
16776 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
16777 for_each_possible_cpu(cpu) {
16778 +#ifdef CONFIG_CC_STACKPROTECTOR
16779 +#ifdef CONFIG_X86_32
16780 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
16781 +#endif
16782 +#endif
16783 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
16784 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
16785 per_cpu(cpu_number, cpu) = cpu;
16786 @@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
16787 */
16788 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
16789 #endif
16790 +#ifdef CONFIG_CC_STACKPROTECTOR
16791 +#ifdef CONFIG_X86_32
16792 + if (!cpu)
16793 + per_cpu(stack_canary.canary, cpu) = canary;
16794 +#endif
16795 +#endif
16796 /*
16797 * Up to this point, the boot CPU has been using .init.data
16798 * area. Reload any changed state for the boot CPU.
16799 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
16800 index 54ddaeb2..a6aa4d2 100644
16801 --- a/arch/x86/kernel/signal.c
16802 +++ b/arch/x86/kernel/signal.c
16803 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
16804 * Align the stack pointer according to the i386 ABI,
16805 * i.e. so that on function entry ((sp + 4) & 15) == 0.
16806 */
16807 - sp = ((sp + 4) & -16ul) - 4;
16808 + sp = ((sp - 12) & -16ul) - 4;
16809 #else /* !CONFIG_X86_32 */
16810 sp = round_down(sp, 16) - 8;
16811 #endif
16812 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
16813 * Return an always-bogus address instead so we will die with SIGSEGV.
16814 */
16815 if (onsigstack && !likely(on_sig_stack(sp)))
16816 - return (void __user *)-1L;
16817 + return (__force void __user *)-1L;
16818
16819 /* save i387 state */
16820 if (used_math() && save_i387_xstate(*fpstate) < 0)
16821 - return (void __user *)-1L;
16822 + return (__force void __user *)-1L;
16823
16824 return (void __user *)sp;
16825 }
16826 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
16827 }
16828
16829 if (current->mm->context.vdso)
16830 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
16831 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
16832 else
16833 - restorer = &frame->retcode;
16834 + restorer = (void __user *)&frame->retcode;
16835 if (ka->sa.sa_flags & SA_RESTORER)
16836 restorer = ka->sa.sa_restorer;
16837
16838 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
16839 * reasons and because gdb uses it as a signature to notice
16840 * signal handler stack frames.
16841 */
16842 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
16843 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
16844
16845 if (err)
16846 return -EFAULT;
16847 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
16848 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
16849
16850 /* Set up to return from userspace. */
16851 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
16852 + if (current->mm->context.vdso)
16853 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
16854 + else
16855 + restorer = (void __user *)&frame->retcode;
16856 if (ka->sa.sa_flags & SA_RESTORER)
16857 restorer = ka->sa.sa_restorer;
16858 put_user_ex(restorer, &frame->pretcode);
16859 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
16860 * reasons and because gdb uses it as a signature to notice
16861 * signal handler stack frames.
16862 */
16863 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
16864 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
16865 } put_user_catch(err);
16866
16867 if (err)
16868 @@ -762,6 +765,8 @@ static void do_signal(struct pt_regs *regs)
16869 siginfo_t info;
16870 int signr;
16871
16872 + pax_track_stack();
16873 +
16874 /*
16875 * We want the common case to go fast, which is why we may in certain
16876 * cases get here from kernel mode. Just return without doing anything
16877 @@ -769,7 +774,7 @@ static void do_signal(struct pt_regs *regs)
16878 * X86_32: vm86 regs switched out by assembly code before reaching
16879 * here, so testing against kernel CS suffices.
16880 */
16881 - if (!user_mode(regs))
16882 + if (!user_mode_novm(regs))
16883 return;
16884
16885 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
16886 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
16887 index 9f548cb..caf76f7 100644
16888 --- a/arch/x86/kernel/smpboot.c
16889 +++ b/arch/x86/kernel/smpboot.c
16890 @@ -709,17 +709,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
16891 set_idle_for_cpu(cpu, c_idle.idle);
16892 do_rest:
16893 per_cpu(current_task, cpu) = c_idle.idle;
16894 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
16895 #ifdef CONFIG_X86_32
16896 /* Stack for startup_32 can be just as for start_secondary onwards */
16897 irq_ctx_init(cpu);
16898 #else
16899 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
16900 initial_gs = per_cpu_offset(cpu);
16901 - per_cpu(kernel_stack, cpu) =
16902 - (unsigned long)task_stack_page(c_idle.idle) -
16903 - KERNEL_STACK_OFFSET + THREAD_SIZE;
16904 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
16905 #endif
16906 +
16907 + pax_open_kernel();
16908 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16909 + pax_close_kernel();
16910 +
16911 initial_code = (unsigned long)start_secondary;
16912 stack_start = c_idle.idle->thread.sp;
16913
16914 @@ -861,6 +864,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
16915
16916 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
16917
16918 +#ifdef CONFIG_PAX_PER_CPU_PGD
16919 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
16920 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
16921 + KERNEL_PGD_PTRS);
16922 +#endif
16923 +
16924 err = do_boot_cpu(apicid, cpu);
16925 if (err) {
16926 pr_debug("do_boot_cpu failed %d\n", err);
16927 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
16928 index c346d11..d43b163 100644
16929 --- a/arch/x86/kernel/step.c
16930 +++ b/arch/x86/kernel/step.c
16931 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
16932 struct desc_struct *desc;
16933 unsigned long base;
16934
16935 - seg &= ~7UL;
16936 + seg >>= 3;
16937
16938 mutex_lock(&child->mm->context.lock);
16939 - if (unlikely((seg >> 3) >= child->mm->context.size))
16940 + if (unlikely(seg >= child->mm->context.size))
16941 addr = -1L; /* bogus selector, access would fault */
16942 else {
16943 desc = child->mm->context.ldt + seg;
16944 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
16945 addr += base;
16946 }
16947 mutex_unlock(&child->mm->context.lock);
16948 - }
16949 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
16950 + addr = ktla_ktva(addr);
16951
16952 return addr;
16953 }
16954 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
16955 unsigned char opcode[15];
16956 unsigned long addr = convert_ip_to_linear(child, regs);
16957
16958 + if (addr == -EINVAL)
16959 + return 0;
16960 +
16961 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
16962 for (i = 0; i < copied; i++) {
16963 switch (opcode[i]) {
16964 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
16965 index 0b0cb5f..db6b9ed 100644
16966 --- a/arch/x86/kernel/sys_i386_32.c
16967 +++ b/arch/x86/kernel/sys_i386_32.c
16968 @@ -24,17 +24,224 @@
16969
16970 #include <asm/syscalls.h>
16971
16972 -/*
16973 - * Do a system call from kernel instead of calling sys_execve so we
16974 - * end up with proper pt_regs.
16975 - */
16976 -int kernel_execve(const char *filename,
16977 - const char *const argv[],
16978 - const char *const envp[])
16979 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
16980 {
16981 - long __res;
16982 - asm volatile ("int $0x80"
16983 - : "=a" (__res)
16984 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
16985 - return __res;
16986 + unsigned long pax_task_size = TASK_SIZE;
16987 +
16988 +#ifdef CONFIG_PAX_SEGMEXEC
16989 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
16990 + pax_task_size = SEGMEXEC_TASK_SIZE;
16991 +#endif
16992 +
16993 + if (len > pax_task_size || addr > pax_task_size - len)
16994 + return -EINVAL;
16995 +
16996 + return 0;
16997 +}
16998 +
16999 +unsigned long
17000 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
17001 + unsigned long len, unsigned long pgoff, unsigned long flags)
17002 +{
17003 + struct mm_struct *mm = current->mm;
17004 + struct vm_area_struct *vma;
17005 + unsigned long start_addr, pax_task_size = TASK_SIZE;
17006 +
17007 +#ifdef CONFIG_PAX_SEGMEXEC
17008 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17009 + pax_task_size = SEGMEXEC_TASK_SIZE;
17010 +#endif
17011 +
17012 + pax_task_size -= PAGE_SIZE;
17013 +
17014 + if (len > pax_task_size)
17015 + return -ENOMEM;
17016 +
17017 + if (flags & MAP_FIXED)
17018 + return addr;
17019 +
17020 +#ifdef CONFIG_PAX_RANDMMAP
17021 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17022 +#endif
17023 +
17024 + if (addr) {
17025 + addr = PAGE_ALIGN(addr);
17026 + if (pax_task_size - len >= addr) {
17027 + vma = find_vma(mm, addr);
17028 + if (check_heap_stack_gap(vma, addr, len))
17029 + return addr;
17030 + }
17031 + }
17032 + if (len > mm->cached_hole_size) {
17033 + start_addr = addr = mm->free_area_cache;
17034 + } else {
17035 + start_addr = addr = mm->mmap_base;
17036 + mm->cached_hole_size = 0;
17037 + }
17038 +
17039 +#ifdef CONFIG_PAX_PAGEEXEC
17040 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
17041 + start_addr = 0x00110000UL;
17042 +
17043 +#ifdef CONFIG_PAX_RANDMMAP
17044 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17045 + start_addr += mm->delta_mmap & 0x03FFF000UL;
17046 +#endif
17047 +
17048 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
17049 + start_addr = addr = mm->mmap_base;
17050 + else
17051 + addr = start_addr;
17052 + }
17053 +#endif
17054 +
17055 +full_search:
17056 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17057 + /* At this point: (!vma || addr < vma->vm_end). */
17058 + if (pax_task_size - len < addr) {
17059 + /*
17060 + * Start a new search - just in case we missed
17061 + * some holes.
17062 + */
17063 + if (start_addr != mm->mmap_base) {
17064 + start_addr = addr = mm->mmap_base;
17065 + mm->cached_hole_size = 0;
17066 + goto full_search;
17067 + }
17068 + return -ENOMEM;
17069 + }
17070 + if (check_heap_stack_gap(vma, addr, len))
17071 + break;
17072 + if (addr + mm->cached_hole_size < vma->vm_start)
17073 + mm->cached_hole_size = vma->vm_start - addr;
17074 + addr = vma->vm_end;
17075 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
17076 + start_addr = addr = mm->mmap_base;
17077 + mm->cached_hole_size = 0;
17078 + goto full_search;
17079 + }
17080 + }
17081 +
17082 + /*
17083 + * Remember the place where we stopped the search:
17084 + */
17085 + mm->free_area_cache = addr + len;
17086 + return addr;
17087 +}
17088 +
17089 +unsigned long
17090 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17091 + const unsigned long len, const unsigned long pgoff,
17092 + const unsigned long flags)
17093 +{
17094 + struct vm_area_struct *vma;
17095 + struct mm_struct *mm = current->mm;
17096 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
17097 +
17098 +#ifdef CONFIG_PAX_SEGMEXEC
17099 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17100 + pax_task_size = SEGMEXEC_TASK_SIZE;
17101 +#endif
17102 +
17103 + pax_task_size -= PAGE_SIZE;
17104 +
17105 + /* requested length too big for entire address space */
17106 + if (len > pax_task_size)
17107 + return -ENOMEM;
17108 +
17109 + if (flags & MAP_FIXED)
17110 + return addr;
17111 +
17112 +#ifdef CONFIG_PAX_PAGEEXEC
17113 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
17114 + goto bottomup;
17115 +#endif
17116 +
17117 +#ifdef CONFIG_PAX_RANDMMAP
17118 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17119 +#endif
17120 +
17121 + /* requesting a specific address */
17122 + if (addr) {
17123 + addr = PAGE_ALIGN(addr);
17124 + if (pax_task_size - len >= addr) {
17125 + vma = find_vma(mm, addr);
17126 + if (check_heap_stack_gap(vma, addr, len))
17127 + return addr;
17128 + }
17129 + }
17130 +
17131 + /* check if free_area_cache is useful for us */
17132 + if (len <= mm->cached_hole_size) {
17133 + mm->cached_hole_size = 0;
17134 + mm->free_area_cache = mm->mmap_base;
17135 + }
17136 +
17137 + /* either no address requested or can't fit in requested address hole */
17138 + addr = mm->free_area_cache;
17139 +
17140 + /* make sure it can fit in the remaining address space */
17141 + if (addr > len) {
17142 + vma = find_vma(mm, addr-len);
17143 + if (check_heap_stack_gap(vma, addr - len, len))
17144 + /* remember the address as a hint for next time */
17145 + return (mm->free_area_cache = addr-len);
17146 + }
17147 +
17148 + if (mm->mmap_base < len)
17149 + goto bottomup;
17150 +
17151 + addr = mm->mmap_base-len;
17152 +
17153 + do {
17154 + /*
17155 + * Lookup failure means no vma is above this address,
17156 + * else if new region fits below vma->vm_start,
17157 + * return with success:
17158 + */
17159 + vma = find_vma(mm, addr);
17160 + if (check_heap_stack_gap(vma, addr, len))
17161 + /* remember the address as a hint for next time */
17162 + return (mm->free_area_cache = addr);
17163 +
17164 + /* remember the largest hole we saw so far */
17165 + if (addr + mm->cached_hole_size < vma->vm_start)
17166 + mm->cached_hole_size = vma->vm_start - addr;
17167 +
17168 + /* try just below the current vma->vm_start */
17169 + addr = skip_heap_stack_gap(vma, len);
17170 + } while (!IS_ERR_VALUE(addr));
17171 +
17172 +bottomup:
17173 + /*
17174 + * A failed mmap() very likely causes application failure,
17175 + * so fall back to the bottom-up function here. This scenario
17176 + * can happen with large stack limits and large mmap()
17177 + * allocations.
17178 + */
17179 +
17180 +#ifdef CONFIG_PAX_SEGMEXEC
17181 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17182 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
17183 + else
17184 +#endif
17185 +
17186 + mm->mmap_base = TASK_UNMAPPED_BASE;
17187 +
17188 +#ifdef CONFIG_PAX_RANDMMAP
17189 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17190 + mm->mmap_base += mm->delta_mmap;
17191 +#endif
17192 +
17193 + mm->free_area_cache = mm->mmap_base;
17194 + mm->cached_hole_size = ~0UL;
17195 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17196 + /*
17197 + * Restore the topdown base:
17198 + */
17199 + mm->mmap_base = base;
17200 + mm->free_area_cache = base;
17201 + mm->cached_hole_size = ~0UL;
17202 +
17203 + return addr;
17204 }
17205 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
17206 index ff14a50..35626c3 100644
17207 --- a/arch/x86/kernel/sys_x86_64.c
17208 +++ b/arch/x86/kernel/sys_x86_64.c
17209 @@ -32,8 +32,8 @@ out:
17210 return error;
17211 }
17212
17213 -static void find_start_end(unsigned long flags, unsigned long *begin,
17214 - unsigned long *end)
17215 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
17216 + unsigned long *begin, unsigned long *end)
17217 {
17218 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
17219 unsigned long new_begin;
17220 @@ -52,7 +52,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
17221 *begin = new_begin;
17222 }
17223 } else {
17224 - *begin = TASK_UNMAPPED_BASE;
17225 + *begin = mm->mmap_base;
17226 *end = TASK_SIZE;
17227 }
17228 }
17229 @@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
17230 if (flags & MAP_FIXED)
17231 return addr;
17232
17233 - find_start_end(flags, &begin, &end);
17234 + find_start_end(mm, flags, &begin, &end);
17235
17236 if (len > end)
17237 return -ENOMEM;
17238
17239 +#ifdef CONFIG_PAX_RANDMMAP
17240 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17241 +#endif
17242 +
17243 if (addr) {
17244 addr = PAGE_ALIGN(addr);
17245 vma = find_vma(mm, addr);
17246 - if (end - len >= addr &&
17247 - (!vma || addr + len <= vma->vm_start))
17248 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
17249 return addr;
17250 }
17251 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
17252 @@ -106,7 +109,7 @@ full_search:
17253 }
17254 return -ENOMEM;
17255 }
17256 - if (!vma || addr + len <= vma->vm_start) {
17257 + if (check_heap_stack_gap(vma, addr, len)) {
17258 /*
17259 * Remember the place where we stopped the search:
17260 */
17261 @@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17262 {
17263 struct vm_area_struct *vma;
17264 struct mm_struct *mm = current->mm;
17265 - unsigned long addr = addr0;
17266 + unsigned long base = mm->mmap_base, addr = addr0;
17267
17268 /* requested length too big for entire address space */
17269 if (len > TASK_SIZE)
17270 @@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17271 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
17272 goto bottomup;
17273
17274 +#ifdef CONFIG_PAX_RANDMMAP
17275 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17276 +#endif
17277 +
17278 /* requesting a specific address */
17279 if (addr) {
17280 addr = PAGE_ALIGN(addr);
17281 - vma = find_vma(mm, addr);
17282 - if (TASK_SIZE - len >= addr &&
17283 - (!vma || addr + len <= vma->vm_start))
17284 - return addr;
17285 + if (TASK_SIZE - len >= addr) {
17286 + vma = find_vma(mm, addr);
17287 + if (check_heap_stack_gap(vma, addr, len))
17288 + return addr;
17289 + }
17290 }
17291
17292 /* check if free_area_cache is useful for us */
17293 @@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17294 /* make sure it can fit in the remaining address space */
17295 if (addr > len) {
17296 vma = find_vma(mm, addr-len);
17297 - if (!vma || addr <= vma->vm_start)
17298 + if (check_heap_stack_gap(vma, addr - len, len))
17299 /* remember the address as a hint for next time */
17300 return mm->free_area_cache = addr-len;
17301 }
17302 @@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17303 * return with success:
17304 */
17305 vma = find_vma(mm, addr);
17306 - if (!vma || addr+len <= vma->vm_start)
17307 + if (check_heap_stack_gap(vma, addr, len))
17308 /* remember the address as a hint for next time */
17309 return mm->free_area_cache = addr;
17310
17311 @@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17312 mm->cached_hole_size = vma->vm_start - addr;
17313
17314 /* try just below the current vma->vm_start */
17315 - addr = vma->vm_start-len;
17316 - } while (len < vma->vm_start);
17317 + addr = skip_heap_stack_gap(vma, len);
17318 + } while (!IS_ERR_VALUE(addr));
17319
17320 bottomup:
17321 /*
17322 @@ -198,13 +206,21 @@ bottomup:
17323 * can happen with large stack limits and large mmap()
17324 * allocations.
17325 */
17326 + mm->mmap_base = TASK_UNMAPPED_BASE;
17327 +
17328 +#ifdef CONFIG_PAX_RANDMMAP
17329 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17330 + mm->mmap_base += mm->delta_mmap;
17331 +#endif
17332 +
17333 + mm->free_area_cache = mm->mmap_base;
17334 mm->cached_hole_size = ~0UL;
17335 - mm->free_area_cache = TASK_UNMAPPED_BASE;
17336 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17337 /*
17338 * Restore the topdown base:
17339 */
17340 - mm->free_area_cache = mm->mmap_base;
17341 + mm->mmap_base = base;
17342 + mm->free_area_cache = base;
17343 mm->cached_hole_size = ~0UL;
17344
17345 return addr;
17346 diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
17347 index bc19be3..0f5fbf7 100644
17348 --- a/arch/x86/kernel/syscall_table_32.S
17349 +++ b/arch/x86/kernel/syscall_table_32.S
17350 @@ -1,3 +1,4 @@
17351 +.section .rodata,"a",@progbits
17352 ENTRY(sys_call_table)
17353 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
17354 .long sys_exit
17355 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
17356 index e07a2fc..db0369d 100644
17357 --- a/arch/x86/kernel/tboot.c
17358 +++ b/arch/x86/kernel/tboot.c
17359 @@ -218,7 +218,7 @@ static int tboot_setup_sleep(void)
17360
17361 void tboot_shutdown(u32 shutdown_type)
17362 {
17363 - void (*shutdown)(void);
17364 + void (* __noreturn shutdown)(void);
17365
17366 if (!tboot_enabled())
17367 return;
17368 @@ -240,7 +240,7 @@ void tboot_shutdown(u32 shutdown_type)
17369
17370 switch_to_tboot_pt();
17371
17372 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
17373 + shutdown = (void *)tboot->shutdown_entry;
17374 shutdown();
17375
17376 /* should not reach here */
17377 @@ -297,7 +297,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
17378 tboot_shutdown(acpi_shutdown_map[sleep_state]);
17379 }
17380
17381 -static atomic_t ap_wfs_count;
17382 +static atomic_unchecked_t ap_wfs_count;
17383
17384 static int tboot_wait_for_aps(int num_aps)
17385 {
17386 @@ -321,9 +321,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
17387 {
17388 switch (action) {
17389 case CPU_DYING:
17390 - atomic_inc(&ap_wfs_count);
17391 + atomic_inc_unchecked(&ap_wfs_count);
17392 if (num_online_cpus() == 1)
17393 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
17394 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
17395 return NOTIFY_BAD;
17396 break;
17397 }
17398 @@ -342,7 +342,7 @@ static __init int tboot_late_init(void)
17399
17400 tboot_create_trampoline();
17401
17402 - atomic_set(&ap_wfs_count, 0);
17403 + atomic_set_unchecked(&ap_wfs_count, 0);
17404 register_hotcpu_notifier(&tboot_cpu_notifier);
17405 return 0;
17406 }
17407 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
17408 index 5a64d05..804587b 100644
17409 --- a/arch/x86/kernel/time.c
17410 +++ b/arch/x86/kernel/time.c
17411 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
17412 {
17413 unsigned long pc = instruction_pointer(regs);
17414
17415 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
17416 + if (!user_mode(regs) && in_lock_functions(pc)) {
17417 #ifdef CONFIG_FRAME_POINTER
17418 - return *(unsigned long *)(regs->bp + sizeof(long));
17419 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
17420 #else
17421 unsigned long *sp =
17422 (unsigned long *)kernel_stack_pointer(regs);
17423 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
17424 * or above a saved flags. Eflags has bits 22-31 zero,
17425 * kernel addresses don't.
17426 */
17427 +
17428 +#ifdef CONFIG_PAX_KERNEXEC
17429 + return ktla_ktva(sp[0]);
17430 +#else
17431 if (sp[0] >> 22)
17432 return sp[0];
17433 if (sp[1] >> 22)
17434 return sp[1];
17435 #endif
17436 +
17437 +#endif
17438 }
17439 return pc;
17440 }
17441 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
17442 index 6bb7b85..dd853e1 100644
17443 --- a/arch/x86/kernel/tls.c
17444 +++ b/arch/x86/kernel/tls.c
17445 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
17446 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
17447 return -EINVAL;
17448
17449 +#ifdef CONFIG_PAX_SEGMEXEC
17450 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
17451 + return -EINVAL;
17452 +#endif
17453 +
17454 set_tls_desc(p, idx, &info, 1);
17455
17456 return 0;
17457 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
17458 index 451c0a7..e57f551 100644
17459 --- a/arch/x86/kernel/trampoline_32.S
17460 +++ b/arch/x86/kernel/trampoline_32.S
17461 @@ -32,6 +32,12 @@
17462 #include <asm/segment.h>
17463 #include <asm/page_types.h>
17464
17465 +#ifdef CONFIG_PAX_KERNEXEC
17466 +#define ta(X) (X)
17467 +#else
17468 +#define ta(X) ((X) - __PAGE_OFFSET)
17469 +#endif
17470 +
17471 #ifdef CONFIG_SMP
17472
17473 .section ".x86_trampoline","a"
17474 @@ -62,7 +68,7 @@ r_base = .
17475 inc %ax # protected mode (PE) bit
17476 lmsw %ax # into protected mode
17477 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
17478 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
17479 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
17480
17481 # These need to be in the same 64K segment as the above;
17482 # hence we don't use the boot_gdt_descr defined in head.S
17483 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
17484 index 09ff517..df19fbff 100644
17485 --- a/arch/x86/kernel/trampoline_64.S
17486 +++ b/arch/x86/kernel/trampoline_64.S
17487 @@ -90,7 +90,7 @@ startup_32:
17488 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
17489 movl %eax, %ds
17490
17491 - movl $X86_CR4_PAE, %eax
17492 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17493 movl %eax, %cr4 # Enable PAE mode
17494
17495 # Setup trampoline 4 level pagetables
17496 @@ -138,7 +138,7 @@ tidt:
17497 # so the kernel can live anywhere
17498 .balign 4
17499 tgdt:
17500 - .short tgdt_end - tgdt # gdt limit
17501 + .short tgdt_end - tgdt - 1 # gdt limit
17502 .long tgdt - r_base
17503 .short 0
17504 .quad 0x00cf9b000000ffff # __KERNEL32_CS
17505 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
17506 index 6913369..7e7dff6 100644
17507 --- a/arch/x86/kernel/traps.c
17508 +++ b/arch/x86/kernel/traps.c
17509 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
17510
17511 /* Do we ignore FPU interrupts ? */
17512 char ignore_fpu_irq;
17513 -
17514 -/*
17515 - * The IDT has to be page-aligned to simplify the Pentium
17516 - * F0 0F bug workaround.
17517 - */
17518 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
17519 #endif
17520
17521 DECLARE_BITMAP(used_vectors, NR_VECTORS);
17522 @@ -117,13 +111,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
17523 }
17524
17525 static void __kprobes
17526 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17527 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
17528 long error_code, siginfo_t *info)
17529 {
17530 struct task_struct *tsk = current;
17531
17532 #ifdef CONFIG_X86_32
17533 - if (regs->flags & X86_VM_MASK) {
17534 + if (v8086_mode(regs)) {
17535 /*
17536 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
17537 * On nmi (interrupt 2), do_trap should not be called.
17538 @@ -134,7 +128,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17539 }
17540 #endif
17541
17542 - if (!user_mode(regs))
17543 + if (!user_mode_novm(regs))
17544 goto kernel_trap;
17545
17546 #ifdef CONFIG_X86_32
17547 @@ -157,7 +151,7 @@ trap_signal:
17548 printk_ratelimit()) {
17549 printk(KERN_INFO
17550 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
17551 - tsk->comm, tsk->pid, str,
17552 + tsk->comm, task_pid_nr(tsk), str,
17553 regs->ip, regs->sp, error_code);
17554 print_vma_addr(" in ", regs->ip);
17555 printk("\n");
17556 @@ -174,8 +168,20 @@ kernel_trap:
17557 if (!fixup_exception(regs)) {
17558 tsk->thread.error_code = error_code;
17559 tsk->thread.trap_no = trapnr;
17560 +
17561 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17562 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
17563 + str = "PAX: suspicious stack segment fault";
17564 +#endif
17565 +
17566 die(str, regs, error_code);
17567 }
17568 +
17569 +#ifdef CONFIG_PAX_REFCOUNT
17570 + if (trapnr == 4)
17571 + pax_report_refcount_overflow(regs);
17572 +#endif
17573 +
17574 return;
17575
17576 #ifdef CONFIG_X86_32
17577 @@ -264,14 +270,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
17578 conditional_sti(regs);
17579
17580 #ifdef CONFIG_X86_32
17581 - if (regs->flags & X86_VM_MASK)
17582 + if (v8086_mode(regs))
17583 goto gp_in_vm86;
17584 #endif
17585
17586 tsk = current;
17587 - if (!user_mode(regs))
17588 + if (!user_mode_novm(regs))
17589 goto gp_in_kernel;
17590
17591 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17592 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
17593 + struct mm_struct *mm = tsk->mm;
17594 + unsigned long limit;
17595 +
17596 + down_write(&mm->mmap_sem);
17597 + limit = mm->context.user_cs_limit;
17598 + if (limit < TASK_SIZE) {
17599 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
17600 + up_write(&mm->mmap_sem);
17601 + return;
17602 + }
17603 + up_write(&mm->mmap_sem);
17604 + }
17605 +#endif
17606 +
17607 tsk->thread.error_code = error_code;
17608 tsk->thread.trap_no = 13;
17609
17610 @@ -304,6 +326,13 @@ gp_in_kernel:
17611 if (notify_die(DIE_GPF, "general protection fault", regs,
17612 error_code, 13, SIGSEGV) == NOTIFY_STOP)
17613 return;
17614 +
17615 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17616 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
17617 + die("PAX: suspicious general protection fault", regs, error_code);
17618 + else
17619 +#endif
17620 +
17621 die("general protection fault", regs, error_code);
17622 }
17623
17624 @@ -433,6 +462,17 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
17625 dotraplinkage notrace __kprobes void
17626 do_nmi(struct pt_regs *regs, long error_code)
17627 {
17628 +
17629 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17630 + if (!user_mode(regs)) {
17631 + unsigned long cs = regs->cs & 0xFFFF;
17632 + unsigned long ip = ktva_ktla(regs->ip);
17633 +
17634 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
17635 + regs->ip = ip;
17636 + }
17637 +#endif
17638 +
17639 nmi_enter();
17640
17641 inc_irq_stat(__nmi_count);
17642 @@ -569,7 +609,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
17643 /* It's safe to allow irq's after DR6 has been saved */
17644 preempt_conditional_sti(regs);
17645
17646 - if (regs->flags & X86_VM_MASK) {
17647 + if (v8086_mode(regs)) {
17648 handle_vm86_trap((struct kernel_vm86_regs *) regs,
17649 error_code, 1);
17650 preempt_conditional_cli(regs);
17651 @@ -583,7 +623,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
17652 * We already checked v86 mode above, so we can check for kernel mode
17653 * by just checking the CPL of CS.
17654 */
17655 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
17656 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
17657 tsk->thread.debugreg6 &= ~DR_STEP;
17658 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
17659 regs->flags &= ~X86_EFLAGS_TF;
17660 @@ -612,7 +652,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
17661 return;
17662 conditional_sti(regs);
17663
17664 - if (!user_mode_vm(regs))
17665 + if (!user_mode(regs))
17666 {
17667 if (!fixup_exception(regs)) {
17668 task->thread.error_code = error_code;
17669 @@ -723,7 +763,7 @@ asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
17670 void __math_state_restore(void)
17671 {
17672 struct thread_info *thread = current_thread_info();
17673 - struct task_struct *tsk = thread->task;
17674 + struct task_struct *tsk = current;
17675
17676 /*
17677 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
17678 @@ -750,8 +790,7 @@ void __math_state_restore(void)
17679 */
17680 asmlinkage void math_state_restore(void)
17681 {
17682 - struct thread_info *thread = current_thread_info();
17683 - struct task_struct *tsk = thread->task;
17684 + struct task_struct *tsk = current;
17685
17686 if (!tsk_used_math(tsk)) {
17687 local_irq_enable();
17688 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
17689 index b9242ba..50c5edd 100644
17690 --- a/arch/x86/kernel/verify_cpu.S
17691 +++ b/arch/x86/kernel/verify_cpu.S
17692 @@ -20,6 +20,7 @@
17693 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
17694 * arch/x86/kernel/trampoline_64.S: secondary processor verification
17695 * arch/x86/kernel/head_32.S: processor startup
17696 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
17697 *
17698 * verify_cpu, returns the status of longmode and SSE in register %eax.
17699 * 0: Success 1: Failure
17700 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
17701 index 863f875..4307295 100644
17702 --- a/arch/x86/kernel/vm86_32.c
17703 +++ b/arch/x86/kernel/vm86_32.c
17704 @@ -41,6 +41,7 @@
17705 #include <linux/ptrace.h>
17706 #include <linux/audit.h>
17707 #include <linux/stddef.h>
17708 +#include <linux/grsecurity.h>
17709
17710 #include <asm/uaccess.h>
17711 #include <asm/io.h>
17712 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
17713 do_exit(SIGSEGV);
17714 }
17715
17716 - tss = &per_cpu(init_tss, get_cpu());
17717 + tss = init_tss + get_cpu();
17718 current->thread.sp0 = current->thread.saved_sp0;
17719 current->thread.sysenter_cs = __KERNEL_CS;
17720 load_sp0(tss, &current->thread);
17721 @@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
17722 struct task_struct *tsk;
17723 int tmp, ret = -EPERM;
17724
17725 +#ifdef CONFIG_GRKERNSEC_VM86
17726 + if (!capable(CAP_SYS_RAWIO)) {
17727 + gr_handle_vm86();
17728 + goto out;
17729 + }
17730 +#endif
17731 +
17732 tsk = current;
17733 if (tsk->thread.saved_sp0)
17734 goto out;
17735 @@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
17736 int tmp, ret;
17737 struct vm86plus_struct __user *v86;
17738
17739 +#ifdef CONFIG_GRKERNSEC_VM86
17740 + if (!capable(CAP_SYS_RAWIO)) {
17741 + gr_handle_vm86();
17742 + ret = -EPERM;
17743 + goto out;
17744 + }
17745 +#endif
17746 +
17747 tsk = current;
17748 switch (cmd) {
17749 case VM86_REQUEST_IRQ:
17750 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
17751 tsk->thread.saved_fs = info->regs32->fs;
17752 tsk->thread.saved_gs = get_user_gs(info->regs32);
17753
17754 - tss = &per_cpu(init_tss, get_cpu());
17755 + tss = init_tss + get_cpu();
17756 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
17757 if (cpu_has_sep)
17758 tsk->thread.sysenter_cs = 0;
17759 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
17760 goto cannot_handle;
17761 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
17762 goto cannot_handle;
17763 - intr_ptr = (unsigned long __user *) (i << 2);
17764 + intr_ptr = (__force unsigned long __user *) (i << 2);
17765 if (get_user(segoffs, intr_ptr))
17766 goto cannot_handle;
17767 if ((segoffs >> 16) == BIOSSEG)
17768 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
17769 index 0f703f1..9e15f64 100644
17770 --- a/arch/x86/kernel/vmlinux.lds.S
17771 +++ b/arch/x86/kernel/vmlinux.lds.S
17772 @@ -26,6 +26,13 @@
17773 #include <asm/page_types.h>
17774 #include <asm/cache.h>
17775 #include <asm/boot.h>
17776 +#include <asm/segment.h>
17777 +
17778 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17779 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
17780 +#else
17781 +#define __KERNEL_TEXT_OFFSET 0
17782 +#endif
17783
17784 #undef i386 /* in case the preprocessor is a 32bit one */
17785
17786 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
17787
17788 PHDRS {
17789 text PT_LOAD FLAGS(5); /* R_E */
17790 +#ifdef CONFIG_X86_32
17791 + module PT_LOAD FLAGS(5); /* R_E */
17792 +#endif
17793 +#ifdef CONFIG_XEN
17794 + rodata PT_LOAD FLAGS(5); /* R_E */
17795 +#else
17796 + rodata PT_LOAD FLAGS(4); /* R__ */
17797 +#endif
17798 data PT_LOAD FLAGS(6); /* RW_ */
17799 -#ifdef CONFIG_X86_64
17800 + init.begin PT_LOAD FLAGS(6); /* RW_ */
17801 #ifdef CONFIG_SMP
17802 percpu PT_LOAD FLAGS(6); /* RW_ */
17803 #endif
17804 + text.init PT_LOAD FLAGS(5); /* R_E */
17805 + text.exit PT_LOAD FLAGS(5); /* R_E */
17806 init PT_LOAD FLAGS(7); /* RWE */
17807 -#endif
17808 note PT_NOTE FLAGS(0); /* ___ */
17809 }
17810
17811 SECTIONS
17812 {
17813 #ifdef CONFIG_X86_32
17814 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
17815 - phys_startup_32 = startup_32 - LOAD_OFFSET;
17816 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
17817 #else
17818 - . = __START_KERNEL;
17819 - phys_startup_64 = startup_64 - LOAD_OFFSET;
17820 + . = __START_KERNEL;
17821 #endif
17822
17823 /* Text and read-only data */
17824 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
17825 - _text = .;
17826 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
17827 /* bootstrapping code */
17828 +#ifdef CONFIG_X86_32
17829 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
17830 +#else
17831 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
17832 +#endif
17833 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
17834 + _text = .;
17835 HEAD_TEXT
17836 #ifdef CONFIG_X86_32
17837 . = ALIGN(PAGE_SIZE);
17838 @@ -108,13 +128,47 @@ SECTIONS
17839 IRQENTRY_TEXT
17840 *(.fixup)
17841 *(.gnu.warning)
17842 - /* End of text section */
17843 - _etext = .;
17844 } :text = 0x9090
17845
17846 - NOTES :text :note
17847 + . += __KERNEL_TEXT_OFFSET;
17848
17849 - EXCEPTION_TABLE(16) :text = 0x9090
17850 +#ifdef CONFIG_X86_32
17851 + . = ALIGN(PAGE_SIZE);
17852 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
17853 +
17854 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
17855 + MODULES_EXEC_VADDR = .;
17856 + BYTE(0)
17857 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
17858 + . = ALIGN(HPAGE_SIZE);
17859 + MODULES_EXEC_END = . - 1;
17860 +#endif
17861 +
17862 + } :module
17863 +#endif
17864 +
17865 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
17866 + /* End of text section */
17867 + _etext = . - __KERNEL_TEXT_OFFSET;
17868 + }
17869 +
17870 +#ifdef CONFIG_X86_32
17871 + . = ALIGN(PAGE_SIZE);
17872 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
17873 + *(.idt)
17874 + . = ALIGN(PAGE_SIZE);
17875 + *(.empty_zero_page)
17876 + *(.initial_pg_fixmap)
17877 + *(.initial_pg_pmd)
17878 + *(.initial_page_table)
17879 + *(.swapper_pg_dir)
17880 + } :rodata
17881 +#endif
17882 +
17883 + . = ALIGN(PAGE_SIZE);
17884 + NOTES :rodata :note
17885 +
17886 + EXCEPTION_TABLE(16) :rodata
17887
17888 #if defined(CONFIG_DEBUG_RODATA)
17889 /* .text should occupy whole number of pages */
17890 @@ -126,16 +180,20 @@ SECTIONS
17891
17892 /* Data */
17893 .data : AT(ADDR(.data) - LOAD_OFFSET) {
17894 +
17895 +#ifdef CONFIG_PAX_KERNEXEC
17896 + . = ALIGN(HPAGE_SIZE);
17897 +#else
17898 + . = ALIGN(PAGE_SIZE);
17899 +#endif
17900 +
17901 /* Start of data section */
17902 _sdata = .;
17903
17904 /* init_task */
17905 INIT_TASK_DATA(THREAD_SIZE)
17906
17907 -#ifdef CONFIG_X86_32
17908 - /* 32 bit has nosave before _edata */
17909 NOSAVE_DATA
17910 -#endif
17911
17912 PAGE_ALIGNED_DATA(PAGE_SIZE)
17913
17914 @@ -176,12 +234,19 @@ SECTIONS
17915 #endif /* CONFIG_X86_64 */
17916
17917 /* Init code and data - will be freed after init */
17918 - . = ALIGN(PAGE_SIZE);
17919 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
17920 + BYTE(0)
17921 +
17922 +#ifdef CONFIG_PAX_KERNEXEC
17923 + . = ALIGN(HPAGE_SIZE);
17924 +#else
17925 + . = ALIGN(PAGE_SIZE);
17926 +#endif
17927 +
17928 __init_begin = .; /* paired with __init_end */
17929 - }
17930 + } :init.begin
17931
17932 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
17933 +#ifdef CONFIG_SMP
17934 /*
17935 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
17936 * output PHDR, so the next output section - .init.text - should
17937 @@ -190,12 +255,27 @@ SECTIONS
17938 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
17939 #endif
17940
17941 - INIT_TEXT_SECTION(PAGE_SIZE)
17942 -#ifdef CONFIG_X86_64
17943 - :init
17944 -#endif
17945 + . = ALIGN(PAGE_SIZE);
17946 + init_begin = .;
17947 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
17948 + VMLINUX_SYMBOL(_sinittext) = .;
17949 + INIT_TEXT
17950 + VMLINUX_SYMBOL(_einittext) = .;
17951 + . = ALIGN(PAGE_SIZE);
17952 + } :text.init
17953
17954 - INIT_DATA_SECTION(16)
17955 + /*
17956 + * .exit.text is discard at runtime, not link time, to deal with
17957 + * references from .altinstructions and .eh_frame
17958 + */
17959 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
17960 + EXIT_TEXT
17961 + . = ALIGN(16);
17962 + } :text.exit
17963 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
17964 +
17965 + . = ALIGN(PAGE_SIZE);
17966 + INIT_DATA_SECTION(16) :init
17967
17968 /*
17969 * Code and data for a variety of lowlevel trampolines, to be
17970 @@ -269,19 +349,12 @@ SECTIONS
17971 }
17972
17973 . = ALIGN(8);
17974 - /*
17975 - * .exit.text is discard at runtime, not link time, to deal with
17976 - * references from .altinstructions and .eh_frame
17977 - */
17978 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
17979 - EXIT_TEXT
17980 - }
17981
17982 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
17983 EXIT_DATA
17984 }
17985
17986 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
17987 +#ifndef CONFIG_SMP
17988 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
17989 #endif
17990
17991 @@ -300,16 +373,10 @@ SECTIONS
17992 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
17993 __smp_locks = .;
17994 *(.smp_locks)
17995 - . = ALIGN(PAGE_SIZE);
17996 __smp_locks_end = .;
17997 + . = ALIGN(PAGE_SIZE);
17998 }
17999
18000 -#ifdef CONFIG_X86_64
18001 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
18002 - NOSAVE_DATA
18003 - }
18004 -#endif
18005 -
18006 /* BSS */
18007 . = ALIGN(PAGE_SIZE);
18008 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
18009 @@ -325,6 +392,7 @@ SECTIONS
18010 __brk_base = .;
18011 . += 64 * 1024; /* 64k alignment slop space */
18012 *(.brk_reservation) /* areas brk users have reserved */
18013 + . = ALIGN(HPAGE_SIZE);
18014 __brk_limit = .;
18015 }
18016
18017 @@ -351,13 +419,12 @@ SECTIONS
18018 * for the boot processor.
18019 */
18020 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
18021 -INIT_PER_CPU(gdt_page);
18022 INIT_PER_CPU(irq_stack_union);
18023
18024 /*
18025 * Build-time check on the image size:
18026 */
18027 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
18028 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
18029 "kernel image bigger than KERNEL_IMAGE_SIZE");
18030
18031 #ifdef CONFIG_SMP
18032 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
18033 index b56c65de..561a55b 100644
18034 --- a/arch/x86/kernel/vsyscall_64.c
18035 +++ b/arch/x86/kernel/vsyscall_64.c
18036 @@ -56,15 +56,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
18037 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
18038 };
18039
18040 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = NATIVE;
18041 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
18042
18043 static int __init vsyscall_setup(char *str)
18044 {
18045 if (str) {
18046 if (!strcmp("emulate", str))
18047 vsyscall_mode = EMULATE;
18048 - else if (!strcmp("native", str))
18049 - vsyscall_mode = NATIVE;
18050 else if (!strcmp("none", str))
18051 vsyscall_mode = NONE;
18052 else
18053 @@ -177,7 +175,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
18054
18055 tsk = current;
18056 if (seccomp_mode(&tsk->seccomp))
18057 - do_exit(SIGKILL);
18058 + do_group_exit(SIGKILL);
18059
18060 switch (vsyscall_nr) {
18061 case 0:
18062 @@ -219,8 +217,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
18063 return true;
18064
18065 sigsegv:
18066 - force_sig(SIGSEGV, current);
18067 - return true;
18068 + do_group_exit(SIGKILL);
18069 }
18070
18071 /*
18072 @@ -273,10 +270,7 @@ void __init map_vsyscall(void)
18073 extern char __vvar_page;
18074 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
18075
18076 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
18077 - vsyscall_mode == NATIVE
18078 - ? PAGE_KERNEL_VSYSCALL
18079 - : PAGE_KERNEL_VVAR);
18080 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
18081 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
18082 (unsigned long)VSYSCALL_START);
18083
18084 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
18085 index 9796c2f..f686fbf 100644
18086 --- a/arch/x86/kernel/x8664_ksyms_64.c
18087 +++ b/arch/x86/kernel/x8664_ksyms_64.c
18088 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
18089 EXPORT_SYMBOL(copy_user_generic_string);
18090 EXPORT_SYMBOL(copy_user_generic_unrolled);
18091 EXPORT_SYMBOL(__copy_user_nocache);
18092 -EXPORT_SYMBOL(_copy_from_user);
18093 -EXPORT_SYMBOL(_copy_to_user);
18094
18095 EXPORT_SYMBOL(copy_page);
18096 EXPORT_SYMBOL(clear_page);
18097 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
18098 index a391134..d0b63b6e 100644
18099 --- a/arch/x86/kernel/xsave.c
18100 +++ b/arch/x86/kernel/xsave.c
18101 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
18102 fx_sw_user->xstate_size > fx_sw_user->extended_size)
18103 return -EINVAL;
18104
18105 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
18106 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
18107 fx_sw_user->extended_size -
18108 FP_XSTATE_MAGIC2_SIZE));
18109 if (err)
18110 @@ -267,7 +267,7 @@ fx_only:
18111 * the other extended state.
18112 */
18113 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
18114 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
18115 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
18116 }
18117
18118 /*
18119 @@ -299,7 +299,7 @@ int restore_i387_xstate(void __user *buf)
18120 if (use_xsave())
18121 err = restore_user_xstate(buf);
18122 else
18123 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
18124 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
18125 buf);
18126 if (unlikely(err)) {
18127 /*
18128 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
18129 index 8b4cc5f..f086b5b 100644
18130 --- a/arch/x86/kvm/emulate.c
18131 +++ b/arch/x86/kvm/emulate.c
18132 @@ -96,7 +96,7 @@
18133 #define Src2ImmByte (2<<29)
18134 #define Src2One (3<<29)
18135 #define Src2Imm (4<<29)
18136 -#define Src2Mask (7<<29)
18137 +#define Src2Mask (7U<<29)
18138
18139 #define X2(x...) x, x
18140 #define X3(x...) X2(x), x
18141 @@ -207,6 +207,7 @@ struct gprefix {
18142
18143 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix, _dsttype) \
18144 do { \
18145 + unsigned long _tmp; \
18146 __asm__ __volatile__ ( \
18147 _PRE_EFLAGS("0", "4", "2") \
18148 _op _suffix " %"_x"3,%1; " \
18149 @@ -220,8 +221,6 @@ struct gprefix {
18150 /* Raw emulation: instruction has two explicit operands. */
18151 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
18152 do { \
18153 - unsigned long _tmp; \
18154 - \
18155 switch ((_dst).bytes) { \
18156 case 2: \
18157 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w",u16);\
18158 @@ -237,7 +236,6 @@ struct gprefix {
18159
18160 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
18161 do { \
18162 - unsigned long _tmp; \
18163 switch ((_dst).bytes) { \
18164 case 1: \
18165 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b",u8); \
18166 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
18167 index 57dcbd4..79aba9b 100644
18168 --- a/arch/x86/kvm/lapic.c
18169 +++ b/arch/x86/kvm/lapic.c
18170 @@ -53,7 +53,7 @@
18171 #define APIC_BUS_CYCLE_NS 1
18172
18173 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
18174 -#define apic_debug(fmt, arg...)
18175 +#define apic_debug(fmt, arg...) do {} while (0)
18176
18177 #define APIC_LVT_NUM 6
18178 /* 14 is the version for Xeon and Pentium 8.4.8*/
18179 diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
18180 index 8e8da79..13bc641 100644
18181 --- a/arch/x86/kvm/mmu.c
18182 +++ b/arch/x86/kvm/mmu.c
18183 @@ -3552,7 +3552,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
18184
18185 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
18186
18187 - invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
18188 + invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
18189
18190 /*
18191 * Assume that the pte write on a page table of the same type
18192 @@ -3584,7 +3584,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
18193 }
18194
18195 spin_lock(&vcpu->kvm->mmu_lock);
18196 - if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18197 + if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18198 gentry = 0;
18199 kvm_mmu_free_some_pages(vcpu);
18200 ++vcpu->kvm->stat.mmu_pte_write;
18201 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
18202 index 507e2b8..fc55f89 100644
18203 --- a/arch/x86/kvm/paging_tmpl.h
18204 +++ b/arch/x86/kvm/paging_tmpl.h
18205 @@ -197,7 +197,7 @@ retry_walk:
18206 if (unlikely(kvm_is_error_hva(host_addr)))
18207 goto error;
18208
18209 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
18210 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
18211 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
18212 goto error;
18213
18214 @@ -575,6 +575,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, u32 error_code,
18215 unsigned long mmu_seq;
18216 bool map_writable;
18217
18218 + pax_track_stack();
18219 +
18220 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
18221
18222 if (unlikely(error_code & PFERR_RSVD_MASK))
18223 @@ -701,7 +703,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
18224 if (need_flush)
18225 kvm_flush_remote_tlbs(vcpu->kvm);
18226
18227 - atomic_inc(&vcpu->kvm->arch.invlpg_counter);
18228 + atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
18229
18230 spin_unlock(&vcpu->kvm->mmu_lock);
18231
18232 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
18233 index 475d1c9..33658ff 100644
18234 --- a/arch/x86/kvm/svm.c
18235 +++ b/arch/x86/kvm/svm.c
18236 @@ -3381,7 +3381,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
18237 int cpu = raw_smp_processor_id();
18238
18239 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
18240 +
18241 + pax_open_kernel();
18242 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
18243 + pax_close_kernel();
18244 +
18245 load_TR_desc();
18246 }
18247
18248 @@ -3759,6 +3763,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
18249 #endif
18250 #endif
18251
18252 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18253 + __set_fs(current_thread_info()->addr_limit);
18254 +#endif
18255 +
18256 reload_tss(vcpu);
18257
18258 local_irq_disable();
18259 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
18260 index e65a158..656dc24 100644
18261 --- a/arch/x86/kvm/vmx.c
18262 +++ b/arch/x86/kvm/vmx.c
18263 @@ -1251,7 +1251,11 @@ static void reload_tss(void)
18264 struct desc_struct *descs;
18265
18266 descs = (void *)gdt->address;
18267 +
18268 + pax_open_kernel();
18269 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
18270 + pax_close_kernel();
18271 +
18272 load_TR_desc();
18273 }
18274
18275 @@ -2520,8 +2524,11 @@ static __init int hardware_setup(void)
18276 if (!cpu_has_vmx_flexpriority())
18277 flexpriority_enabled = 0;
18278
18279 - if (!cpu_has_vmx_tpr_shadow())
18280 - kvm_x86_ops->update_cr8_intercept = NULL;
18281 + if (!cpu_has_vmx_tpr_shadow()) {
18282 + pax_open_kernel();
18283 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
18284 + pax_close_kernel();
18285 + }
18286
18287 if (enable_ept && !cpu_has_vmx_ept_2m_page())
18288 kvm_disable_largepages();
18289 @@ -3535,7 +3542,7 @@ static void vmx_set_constant_host_state(void)
18290 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
18291
18292 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
18293 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
18294 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
18295
18296 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
18297 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
18298 @@ -6021,6 +6028,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18299 "jmp .Lkvm_vmx_return \n\t"
18300 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
18301 ".Lkvm_vmx_return: "
18302 +
18303 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18304 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
18305 + ".Lkvm_vmx_return2: "
18306 +#endif
18307 +
18308 /* Save guest registers, load host registers, keep flags */
18309 "mov %0, %c[wordsize](%%"R"sp) \n\t"
18310 "pop %0 \n\t"
18311 @@ -6069,6 +6082,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18312 #endif
18313 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
18314 [wordsize]"i"(sizeof(ulong))
18315 +
18316 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18317 + ,[cs]"i"(__KERNEL_CS)
18318 +#endif
18319 +
18320 : "cc", "memory"
18321 , R"ax", R"bx", R"di", R"si"
18322 #ifdef CONFIG_X86_64
18323 @@ -6097,7 +6115,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18324 }
18325 }
18326
18327 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
18328 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
18329 +
18330 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18331 + loadsegment(fs, __KERNEL_PERCPU);
18332 +#endif
18333 +
18334 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18335 + __set_fs(current_thread_info()->addr_limit);
18336 +#endif
18337 +
18338 vmx->loaded_vmcs->launched = 1;
18339
18340 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
18341 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
18342 index 84a28ea..9326501 100644
18343 --- a/arch/x86/kvm/x86.c
18344 +++ b/arch/x86/kvm/x86.c
18345 @@ -1334,8 +1334,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
18346 {
18347 struct kvm *kvm = vcpu->kvm;
18348 int lm = is_long_mode(vcpu);
18349 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
18350 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
18351 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
18352 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
18353 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
18354 : kvm->arch.xen_hvm_config.blob_size_32;
18355 u32 page_num = data & ~PAGE_MASK;
18356 @@ -2137,6 +2137,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
18357 if (n < msr_list.nmsrs)
18358 goto out;
18359 r = -EFAULT;
18360 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
18361 + goto out;
18362 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
18363 num_msrs_to_save * sizeof(u32)))
18364 goto out;
18365 @@ -2312,15 +2314,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
18366 struct kvm_cpuid2 *cpuid,
18367 struct kvm_cpuid_entry2 __user *entries)
18368 {
18369 - int r;
18370 + int r, i;
18371
18372 r = -E2BIG;
18373 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
18374 goto out;
18375 r = -EFAULT;
18376 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
18377 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18378 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18379 goto out;
18380 + for (i = 0; i < cpuid->nent; ++i) {
18381 + struct kvm_cpuid_entry2 cpuid_entry;
18382 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
18383 + goto out;
18384 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
18385 + }
18386 vcpu->arch.cpuid_nent = cpuid->nent;
18387 kvm_apic_set_version(vcpu);
18388 kvm_x86_ops->cpuid_update(vcpu);
18389 @@ -2335,15 +2342,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
18390 struct kvm_cpuid2 *cpuid,
18391 struct kvm_cpuid_entry2 __user *entries)
18392 {
18393 - int r;
18394 + int r, i;
18395
18396 r = -E2BIG;
18397 if (cpuid->nent < vcpu->arch.cpuid_nent)
18398 goto out;
18399 r = -EFAULT;
18400 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
18401 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18402 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18403 goto out;
18404 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
18405 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
18406 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
18407 + goto out;
18408 + }
18409 return 0;
18410
18411 out:
18412 @@ -2718,7 +2729,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
18413 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
18414 struct kvm_interrupt *irq)
18415 {
18416 - if (irq->irq < 0 || irq->irq >= 256)
18417 + if (irq->irq >= 256)
18418 return -EINVAL;
18419 if (irqchip_in_kernel(vcpu->kvm))
18420 return -ENXIO;
18421 @@ -5089,7 +5100,7 @@ static void kvm_set_mmio_spte_mask(void)
18422 kvm_mmu_set_mmio_spte_mask(mask);
18423 }
18424
18425 -int kvm_arch_init(void *opaque)
18426 +int kvm_arch_init(const void *opaque)
18427 {
18428 int r;
18429 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
18430 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
18431 index 13ee258..b9632f6 100644
18432 --- a/arch/x86/lguest/boot.c
18433 +++ b/arch/x86/lguest/boot.c
18434 @@ -1184,9 +1184,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
18435 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
18436 * Launcher to reboot us.
18437 */
18438 -static void lguest_restart(char *reason)
18439 +static __noreturn void lguest_restart(char *reason)
18440 {
18441 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
18442 + BUG();
18443 }
18444
18445 /*G:050
18446 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
18447 index 042f682..c92afb6 100644
18448 --- a/arch/x86/lib/atomic64_32.c
18449 +++ b/arch/x86/lib/atomic64_32.c
18450 @@ -8,18 +8,30 @@
18451
18452 long long atomic64_read_cx8(long long, const atomic64_t *v);
18453 EXPORT_SYMBOL(atomic64_read_cx8);
18454 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18455 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
18456 long long atomic64_set_cx8(long long, const atomic64_t *v);
18457 EXPORT_SYMBOL(atomic64_set_cx8);
18458 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18459 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
18460 long long atomic64_xchg_cx8(long long, unsigned high);
18461 EXPORT_SYMBOL(atomic64_xchg_cx8);
18462 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
18463 EXPORT_SYMBOL(atomic64_add_return_cx8);
18464 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18465 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
18466 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
18467 EXPORT_SYMBOL(atomic64_sub_return_cx8);
18468 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18469 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
18470 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
18471 EXPORT_SYMBOL(atomic64_inc_return_cx8);
18472 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18473 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
18474 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
18475 EXPORT_SYMBOL(atomic64_dec_return_cx8);
18476 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18477 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
18478 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
18479 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
18480 int atomic64_inc_not_zero_cx8(atomic64_t *v);
18481 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
18482 #ifndef CONFIG_X86_CMPXCHG64
18483 long long atomic64_read_386(long long, const atomic64_t *v);
18484 EXPORT_SYMBOL(atomic64_read_386);
18485 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
18486 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
18487 long long atomic64_set_386(long long, const atomic64_t *v);
18488 EXPORT_SYMBOL(atomic64_set_386);
18489 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
18490 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
18491 long long atomic64_xchg_386(long long, unsigned high);
18492 EXPORT_SYMBOL(atomic64_xchg_386);
18493 long long atomic64_add_return_386(long long a, atomic64_t *v);
18494 EXPORT_SYMBOL(atomic64_add_return_386);
18495 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18496 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
18497 long long atomic64_sub_return_386(long long a, atomic64_t *v);
18498 EXPORT_SYMBOL(atomic64_sub_return_386);
18499 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18500 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
18501 long long atomic64_inc_return_386(long long a, atomic64_t *v);
18502 EXPORT_SYMBOL(atomic64_inc_return_386);
18503 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18504 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
18505 long long atomic64_dec_return_386(long long a, atomic64_t *v);
18506 EXPORT_SYMBOL(atomic64_dec_return_386);
18507 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18508 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
18509 long long atomic64_add_386(long long a, atomic64_t *v);
18510 EXPORT_SYMBOL(atomic64_add_386);
18511 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
18512 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
18513 long long atomic64_sub_386(long long a, atomic64_t *v);
18514 EXPORT_SYMBOL(atomic64_sub_386);
18515 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
18516 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
18517 long long atomic64_inc_386(long long a, atomic64_t *v);
18518 EXPORT_SYMBOL(atomic64_inc_386);
18519 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
18520 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
18521 long long atomic64_dec_386(long long a, atomic64_t *v);
18522 EXPORT_SYMBOL(atomic64_dec_386);
18523 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
18524 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
18525 long long atomic64_dec_if_positive_386(atomic64_t *v);
18526 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
18527 int atomic64_inc_not_zero_386(atomic64_t *v);
18528 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
18529 index e8e7e0d..56fd1b0 100644
18530 --- a/arch/x86/lib/atomic64_386_32.S
18531 +++ b/arch/x86/lib/atomic64_386_32.S
18532 @@ -48,6 +48,10 @@ BEGIN(read)
18533 movl (v), %eax
18534 movl 4(v), %edx
18535 RET_ENDP
18536 +BEGIN(read_unchecked)
18537 + movl (v), %eax
18538 + movl 4(v), %edx
18539 +RET_ENDP
18540 #undef v
18541
18542 #define v %esi
18543 @@ -55,6 +59,10 @@ BEGIN(set)
18544 movl %ebx, (v)
18545 movl %ecx, 4(v)
18546 RET_ENDP
18547 +BEGIN(set_unchecked)
18548 + movl %ebx, (v)
18549 + movl %ecx, 4(v)
18550 +RET_ENDP
18551 #undef v
18552
18553 #define v %esi
18554 @@ -70,6 +78,20 @@ RET_ENDP
18555 BEGIN(add)
18556 addl %eax, (v)
18557 adcl %edx, 4(v)
18558 +
18559 +#ifdef CONFIG_PAX_REFCOUNT
18560 + jno 0f
18561 + subl %eax, (v)
18562 + sbbl %edx, 4(v)
18563 + int $4
18564 +0:
18565 + _ASM_EXTABLE(0b, 0b)
18566 +#endif
18567 +
18568 +RET_ENDP
18569 +BEGIN(add_unchecked)
18570 + addl %eax, (v)
18571 + adcl %edx, 4(v)
18572 RET_ENDP
18573 #undef v
18574
18575 @@ -77,6 +99,24 @@ RET_ENDP
18576 BEGIN(add_return)
18577 addl (v), %eax
18578 adcl 4(v), %edx
18579 +
18580 +#ifdef CONFIG_PAX_REFCOUNT
18581 + into
18582 +1234:
18583 + _ASM_EXTABLE(1234b, 2f)
18584 +#endif
18585 +
18586 + movl %eax, (v)
18587 + movl %edx, 4(v)
18588 +
18589 +#ifdef CONFIG_PAX_REFCOUNT
18590 +2:
18591 +#endif
18592 +
18593 +RET_ENDP
18594 +BEGIN(add_return_unchecked)
18595 + addl (v), %eax
18596 + adcl 4(v), %edx
18597 movl %eax, (v)
18598 movl %edx, 4(v)
18599 RET_ENDP
18600 @@ -86,6 +126,20 @@ RET_ENDP
18601 BEGIN(sub)
18602 subl %eax, (v)
18603 sbbl %edx, 4(v)
18604 +
18605 +#ifdef CONFIG_PAX_REFCOUNT
18606 + jno 0f
18607 + addl %eax, (v)
18608 + adcl %edx, 4(v)
18609 + int $4
18610 +0:
18611 + _ASM_EXTABLE(0b, 0b)
18612 +#endif
18613 +
18614 +RET_ENDP
18615 +BEGIN(sub_unchecked)
18616 + subl %eax, (v)
18617 + sbbl %edx, 4(v)
18618 RET_ENDP
18619 #undef v
18620
18621 @@ -96,6 +150,27 @@ BEGIN(sub_return)
18622 sbbl $0, %edx
18623 addl (v), %eax
18624 adcl 4(v), %edx
18625 +
18626 +#ifdef CONFIG_PAX_REFCOUNT
18627 + into
18628 +1234:
18629 + _ASM_EXTABLE(1234b, 2f)
18630 +#endif
18631 +
18632 + movl %eax, (v)
18633 + movl %edx, 4(v)
18634 +
18635 +#ifdef CONFIG_PAX_REFCOUNT
18636 +2:
18637 +#endif
18638 +
18639 +RET_ENDP
18640 +BEGIN(sub_return_unchecked)
18641 + negl %edx
18642 + negl %eax
18643 + sbbl $0, %edx
18644 + addl (v), %eax
18645 + adcl 4(v), %edx
18646 movl %eax, (v)
18647 movl %edx, 4(v)
18648 RET_ENDP
18649 @@ -105,6 +180,20 @@ RET_ENDP
18650 BEGIN(inc)
18651 addl $1, (v)
18652 adcl $0, 4(v)
18653 +
18654 +#ifdef CONFIG_PAX_REFCOUNT
18655 + jno 0f
18656 + subl $1, (v)
18657 + sbbl $0, 4(v)
18658 + int $4
18659 +0:
18660 + _ASM_EXTABLE(0b, 0b)
18661 +#endif
18662 +
18663 +RET_ENDP
18664 +BEGIN(inc_unchecked)
18665 + addl $1, (v)
18666 + adcl $0, 4(v)
18667 RET_ENDP
18668 #undef v
18669
18670 @@ -114,6 +203,26 @@ BEGIN(inc_return)
18671 movl 4(v), %edx
18672 addl $1, %eax
18673 adcl $0, %edx
18674 +
18675 +#ifdef CONFIG_PAX_REFCOUNT
18676 + into
18677 +1234:
18678 + _ASM_EXTABLE(1234b, 2f)
18679 +#endif
18680 +
18681 + movl %eax, (v)
18682 + movl %edx, 4(v)
18683 +
18684 +#ifdef CONFIG_PAX_REFCOUNT
18685 +2:
18686 +#endif
18687 +
18688 +RET_ENDP
18689 +BEGIN(inc_return_unchecked)
18690 + movl (v), %eax
18691 + movl 4(v), %edx
18692 + addl $1, %eax
18693 + adcl $0, %edx
18694 movl %eax, (v)
18695 movl %edx, 4(v)
18696 RET_ENDP
18697 @@ -123,6 +232,20 @@ RET_ENDP
18698 BEGIN(dec)
18699 subl $1, (v)
18700 sbbl $0, 4(v)
18701 +
18702 +#ifdef CONFIG_PAX_REFCOUNT
18703 + jno 0f
18704 + addl $1, (v)
18705 + adcl $0, 4(v)
18706 + int $4
18707 +0:
18708 + _ASM_EXTABLE(0b, 0b)
18709 +#endif
18710 +
18711 +RET_ENDP
18712 +BEGIN(dec_unchecked)
18713 + subl $1, (v)
18714 + sbbl $0, 4(v)
18715 RET_ENDP
18716 #undef v
18717
18718 @@ -132,6 +255,26 @@ BEGIN(dec_return)
18719 movl 4(v), %edx
18720 subl $1, %eax
18721 sbbl $0, %edx
18722 +
18723 +#ifdef CONFIG_PAX_REFCOUNT
18724 + into
18725 +1234:
18726 + _ASM_EXTABLE(1234b, 2f)
18727 +#endif
18728 +
18729 + movl %eax, (v)
18730 + movl %edx, 4(v)
18731 +
18732 +#ifdef CONFIG_PAX_REFCOUNT
18733 +2:
18734 +#endif
18735 +
18736 +RET_ENDP
18737 +BEGIN(dec_return_unchecked)
18738 + movl (v), %eax
18739 + movl 4(v), %edx
18740 + subl $1, %eax
18741 + sbbl $0, %edx
18742 movl %eax, (v)
18743 movl %edx, 4(v)
18744 RET_ENDP
18745 @@ -143,6 +286,13 @@ BEGIN(add_unless)
18746 adcl %edx, %edi
18747 addl (v), %eax
18748 adcl 4(v), %edx
18749 +
18750 +#ifdef CONFIG_PAX_REFCOUNT
18751 + into
18752 +1234:
18753 + _ASM_EXTABLE(1234b, 2f)
18754 +#endif
18755 +
18756 cmpl %eax, %esi
18757 je 3f
18758 1:
18759 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
18760 1:
18761 addl $1, %eax
18762 adcl $0, %edx
18763 +
18764 +#ifdef CONFIG_PAX_REFCOUNT
18765 + into
18766 +1234:
18767 + _ASM_EXTABLE(1234b, 2f)
18768 +#endif
18769 +
18770 movl %eax, (v)
18771 movl %edx, 4(v)
18772 movl $1, %eax
18773 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
18774 movl 4(v), %edx
18775 subl $1, %eax
18776 sbbl $0, %edx
18777 +
18778 +#ifdef CONFIG_PAX_REFCOUNT
18779 + into
18780 +1234:
18781 + _ASM_EXTABLE(1234b, 1f)
18782 +#endif
18783 +
18784 js 1f
18785 movl %eax, (v)
18786 movl %edx, 4(v)
18787 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
18788 index 391a083..d658e9f 100644
18789 --- a/arch/x86/lib/atomic64_cx8_32.S
18790 +++ b/arch/x86/lib/atomic64_cx8_32.S
18791 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
18792 CFI_STARTPROC
18793
18794 read64 %ecx
18795 + pax_force_retaddr
18796 ret
18797 CFI_ENDPROC
18798 ENDPROC(atomic64_read_cx8)
18799
18800 +ENTRY(atomic64_read_unchecked_cx8)
18801 + CFI_STARTPROC
18802 +
18803 + read64 %ecx
18804 + pax_force_retaddr
18805 + ret
18806 + CFI_ENDPROC
18807 +ENDPROC(atomic64_read_unchecked_cx8)
18808 +
18809 ENTRY(atomic64_set_cx8)
18810 CFI_STARTPROC
18811
18812 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
18813 cmpxchg8b (%esi)
18814 jne 1b
18815
18816 + pax_force_retaddr
18817 ret
18818 CFI_ENDPROC
18819 ENDPROC(atomic64_set_cx8)
18820
18821 +ENTRY(atomic64_set_unchecked_cx8)
18822 + CFI_STARTPROC
18823 +
18824 +1:
18825 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
18826 + * are atomic on 586 and newer */
18827 + cmpxchg8b (%esi)
18828 + jne 1b
18829 +
18830 + pax_force_retaddr
18831 + ret
18832 + CFI_ENDPROC
18833 +ENDPROC(atomic64_set_unchecked_cx8)
18834 +
18835 ENTRY(atomic64_xchg_cx8)
18836 CFI_STARTPROC
18837
18838 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
18839 cmpxchg8b (%esi)
18840 jne 1b
18841
18842 + pax_force_retaddr
18843 ret
18844 CFI_ENDPROC
18845 ENDPROC(atomic64_xchg_cx8)
18846
18847 -.macro addsub_return func ins insc
18848 -ENTRY(atomic64_\func\()_return_cx8)
18849 +.macro addsub_return func ins insc unchecked=""
18850 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
18851 CFI_STARTPROC
18852 SAVE ebp
18853 SAVE ebx
18854 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
18855 movl %edx, %ecx
18856 \ins\()l %esi, %ebx
18857 \insc\()l %edi, %ecx
18858 +
18859 +.ifb \unchecked
18860 +#ifdef CONFIG_PAX_REFCOUNT
18861 + into
18862 +2:
18863 + _ASM_EXTABLE(2b, 3f)
18864 +#endif
18865 +.endif
18866 +
18867 LOCK_PREFIX
18868 cmpxchg8b (%ebp)
18869 jne 1b
18870 -
18871 -10:
18872 movl %ebx, %eax
18873 movl %ecx, %edx
18874 +
18875 +.ifb \unchecked
18876 +#ifdef CONFIG_PAX_REFCOUNT
18877 +3:
18878 +#endif
18879 +.endif
18880 +
18881 RESTORE edi
18882 RESTORE esi
18883 RESTORE ebx
18884 RESTORE ebp
18885 + pax_force_retaddr
18886 ret
18887 CFI_ENDPROC
18888 -ENDPROC(atomic64_\func\()_return_cx8)
18889 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
18890 .endm
18891
18892 addsub_return add add adc
18893 addsub_return sub sub sbb
18894 +addsub_return add add adc _unchecked
18895 +addsub_return sub sub sbb _unchecked
18896
18897 -.macro incdec_return func ins insc
18898 -ENTRY(atomic64_\func\()_return_cx8)
18899 +.macro incdec_return func ins insc unchecked
18900 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
18901 CFI_STARTPROC
18902 SAVE ebx
18903
18904 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
18905 movl %edx, %ecx
18906 \ins\()l $1, %ebx
18907 \insc\()l $0, %ecx
18908 +
18909 +.ifb \unchecked
18910 +#ifdef CONFIG_PAX_REFCOUNT
18911 + into
18912 +2:
18913 + _ASM_EXTABLE(2b, 3f)
18914 +#endif
18915 +.endif
18916 +
18917 LOCK_PREFIX
18918 cmpxchg8b (%esi)
18919 jne 1b
18920
18921 -10:
18922 movl %ebx, %eax
18923 movl %ecx, %edx
18924 +
18925 +.ifb \unchecked
18926 +#ifdef CONFIG_PAX_REFCOUNT
18927 +3:
18928 +#endif
18929 +.endif
18930 +
18931 RESTORE ebx
18932 + pax_force_retaddr
18933 ret
18934 CFI_ENDPROC
18935 -ENDPROC(atomic64_\func\()_return_cx8)
18936 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
18937 .endm
18938
18939 incdec_return inc add adc
18940 incdec_return dec sub sbb
18941 +incdec_return inc add adc _unchecked
18942 +incdec_return dec sub sbb _unchecked
18943
18944 ENTRY(atomic64_dec_if_positive_cx8)
18945 CFI_STARTPROC
18946 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
18947 movl %edx, %ecx
18948 subl $1, %ebx
18949 sbb $0, %ecx
18950 +
18951 +#ifdef CONFIG_PAX_REFCOUNT
18952 + into
18953 +1234:
18954 + _ASM_EXTABLE(1234b, 2f)
18955 +#endif
18956 +
18957 js 2f
18958 LOCK_PREFIX
18959 cmpxchg8b (%esi)
18960 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
18961 movl %ebx, %eax
18962 movl %ecx, %edx
18963 RESTORE ebx
18964 + pax_force_retaddr
18965 ret
18966 CFI_ENDPROC
18967 ENDPROC(atomic64_dec_if_positive_cx8)
18968 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
18969 movl %edx, %ecx
18970 addl %esi, %ebx
18971 adcl %edi, %ecx
18972 +
18973 +#ifdef CONFIG_PAX_REFCOUNT
18974 + into
18975 +1234:
18976 + _ASM_EXTABLE(1234b, 3f)
18977 +#endif
18978 +
18979 LOCK_PREFIX
18980 cmpxchg8b (%ebp)
18981 jne 1b
18982 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
18983 CFI_ADJUST_CFA_OFFSET -8
18984 RESTORE ebx
18985 RESTORE ebp
18986 + pax_force_retaddr
18987 ret
18988 4:
18989 cmpl %edx, 4(%esp)
18990 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
18991 movl %edx, %ecx
18992 addl $1, %ebx
18993 adcl $0, %ecx
18994 +
18995 +#ifdef CONFIG_PAX_REFCOUNT
18996 + into
18997 +1234:
18998 + _ASM_EXTABLE(1234b, 3f)
18999 +#endif
19000 +
19001 LOCK_PREFIX
19002 cmpxchg8b (%esi)
19003 jne 1b
19004 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
19005 movl $1, %eax
19006 3:
19007 RESTORE ebx
19008 + pax_force_retaddr
19009 ret
19010 4:
19011 testl %edx, %edx
19012 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
19013 index 78d16a5..fbcf666 100644
19014 --- a/arch/x86/lib/checksum_32.S
19015 +++ b/arch/x86/lib/checksum_32.S
19016 @@ -28,7 +28,8 @@
19017 #include <linux/linkage.h>
19018 #include <asm/dwarf2.h>
19019 #include <asm/errno.h>
19020 -
19021 +#include <asm/segment.h>
19022 +
19023 /*
19024 * computes a partial checksum, e.g. for TCP/UDP fragments
19025 */
19026 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
19027
19028 #define ARGBASE 16
19029 #define FP 12
19030 -
19031 -ENTRY(csum_partial_copy_generic)
19032 +
19033 +ENTRY(csum_partial_copy_generic_to_user)
19034 CFI_STARTPROC
19035 +
19036 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19037 + pushl_cfi %gs
19038 + popl_cfi %es
19039 + jmp csum_partial_copy_generic
19040 +#endif
19041 +
19042 +ENTRY(csum_partial_copy_generic_from_user)
19043 +
19044 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19045 + pushl_cfi %gs
19046 + popl_cfi %ds
19047 +#endif
19048 +
19049 +ENTRY(csum_partial_copy_generic)
19050 subl $4,%esp
19051 CFI_ADJUST_CFA_OFFSET 4
19052 pushl_cfi %edi
19053 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
19054 jmp 4f
19055 SRC(1: movw (%esi), %bx )
19056 addl $2, %esi
19057 -DST( movw %bx, (%edi) )
19058 +DST( movw %bx, %es:(%edi) )
19059 addl $2, %edi
19060 addw %bx, %ax
19061 adcl $0, %eax
19062 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
19063 SRC(1: movl (%esi), %ebx )
19064 SRC( movl 4(%esi), %edx )
19065 adcl %ebx, %eax
19066 -DST( movl %ebx, (%edi) )
19067 +DST( movl %ebx, %es:(%edi) )
19068 adcl %edx, %eax
19069 -DST( movl %edx, 4(%edi) )
19070 +DST( movl %edx, %es:4(%edi) )
19071
19072 SRC( movl 8(%esi), %ebx )
19073 SRC( movl 12(%esi), %edx )
19074 adcl %ebx, %eax
19075 -DST( movl %ebx, 8(%edi) )
19076 +DST( movl %ebx, %es:8(%edi) )
19077 adcl %edx, %eax
19078 -DST( movl %edx, 12(%edi) )
19079 +DST( movl %edx, %es:12(%edi) )
19080
19081 SRC( movl 16(%esi), %ebx )
19082 SRC( movl 20(%esi), %edx )
19083 adcl %ebx, %eax
19084 -DST( movl %ebx, 16(%edi) )
19085 +DST( movl %ebx, %es:16(%edi) )
19086 adcl %edx, %eax
19087 -DST( movl %edx, 20(%edi) )
19088 +DST( movl %edx, %es:20(%edi) )
19089
19090 SRC( movl 24(%esi), %ebx )
19091 SRC( movl 28(%esi), %edx )
19092 adcl %ebx, %eax
19093 -DST( movl %ebx, 24(%edi) )
19094 +DST( movl %ebx, %es:24(%edi) )
19095 adcl %edx, %eax
19096 -DST( movl %edx, 28(%edi) )
19097 +DST( movl %edx, %es:28(%edi) )
19098
19099 lea 32(%esi), %esi
19100 lea 32(%edi), %edi
19101 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
19102 shrl $2, %edx # This clears CF
19103 SRC(3: movl (%esi), %ebx )
19104 adcl %ebx, %eax
19105 -DST( movl %ebx, (%edi) )
19106 +DST( movl %ebx, %es:(%edi) )
19107 lea 4(%esi), %esi
19108 lea 4(%edi), %edi
19109 dec %edx
19110 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
19111 jb 5f
19112 SRC( movw (%esi), %cx )
19113 leal 2(%esi), %esi
19114 -DST( movw %cx, (%edi) )
19115 +DST( movw %cx, %es:(%edi) )
19116 leal 2(%edi), %edi
19117 je 6f
19118 shll $16,%ecx
19119 SRC(5: movb (%esi), %cl )
19120 -DST( movb %cl, (%edi) )
19121 +DST( movb %cl, %es:(%edi) )
19122 6: addl %ecx, %eax
19123 adcl $0, %eax
19124 7:
19125 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
19126
19127 6001:
19128 movl ARGBASE+20(%esp), %ebx # src_err_ptr
19129 - movl $-EFAULT, (%ebx)
19130 + movl $-EFAULT, %ss:(%ebx)
19131
19132 # zero the complete destination - computing the rest
19133 # is too much work
19134 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
19135
19136 6002:
19137 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19138 - movl $-EFAULT,(%ebx)
19139 + movl $-EFAULT,%ss:(%ebx)
19140 jmp 5000b
19141
19142 .previous
19143
19144 + pushl_cfi %ss
19145 + popl_cfi %ds
19146 + pushl_cfi %ss
19147 + popl_cfi %es
19148 popl_cfi %ebx
19149 CFI_RESTORE ebx
19150 popl_cfi %esi
19151 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
19152 popl_cfi %ecx # equivalent to addl $4,%esp
19153 ret
19154 CFI_ENDPROC
19155 -ENDPROC(csum_partial_copy_generic)
19156 +ENDPROC(csum_partial_copy_generic_to_user)
19157
19158 #else
19159
19160 /* Version for PentiumII/PPro */
19161
19162 #define ROUND1(x) \
19163 + nop; nop; nop; \
19164 SRC(movl x(%esi), %ebx ) ; \
19165 addl %ebx, %eax ; \
19166 - DST(movl %ebx, x(%edi) ) ;
19167 + DST(movl %ebx, %es:x(%edi)) ;
19168
19169 #define ROUND(x) \
19170 + nop; nop; nop; \
19171 SRC(movl x(%esi), %ebx ) ; \
19172 adcl %ebx, %eax ; \
19173 - DST(movl %ebx, x(%edi) ) ;
19174 + DST(movl %ebx, %es:x(%edi)) ;
19175
19176 #define ARGBASE 12
19177 -
19178 -ENTRY(csum_partial_copy_generic)
19179 +
19180 +ENTRY(csum_partial_copy_generic_to_user)
19181 CFI_STARTPROC
19182 +
19183 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19184 + pushl_cfi %gs
19185 + popl_cfi %es
19186 + jmp csum_partial_copy_generic
19187 +#endif
19188 +
19189 +ENTRY(csum_partial_copy_generic_from_user)
19190 +
19191 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19192 + pushl_cfi %gs
19193 + popl_cfi %ds
19194 +#endif
19195 +
19196 +ENTRY(csum_partial_copy_generic)
19197 pushl_cfi %ebx
19198 CFI_REL_OFFSET ebx, 0
19199 pushl_cfi %edi
19200 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
19201 subl %ebx, %edi
19202 lea -1(%esi),%edx
19203 andl $-32,%edx
19204 - lea 3f(%ebx,%ebx), %ebx
19205 + lea 3f(%ebx,%ebx,2), %ebx
19206 testl %esi, %esi
19207 jmp *%ebx
19208 1: addl $64,%esi
19209 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
19210 jb 5f
19211 SRC( movw (%esi), %dx )
19212 leal 2(%esi), %esi
19213 -DST( movw %dx, (%edi) )
19214 +DST( movw %dx, %es:(%edi) )
19215 leal 2(%edi), %edi
19216 je 6f
19217 shll $16,%edx
19218 5:
19219 SRC( movb (%esi), %dl )
19220 -DST( movb %dl, (%edi) )
19221 +DST( movb %dl, %es:(%edi) )
19222 6: addl %edx, %eax
19223 adcl $0, %eax
19224 7:
19225 .section .fixup, "ax"
19226 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
19227 - movl $-EFAULT, (%ebx)
19228 + movl $-EFAULT, %ss:(%ebx)
19229 # zero the complete destination (computing the rest is too much work)
19230 movl ARGBASE+8(%esp),%edi # dst
19231 movl ARGBASE+12(%esp),%ecx # len
19232 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
19233 rep; stosb
19234 jmp 7b
19235 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19236 - movl $-EFAULT, (%ebx)
19237 + movl $-EFAULT, %ss:(%ebx)
19238 jmp 7b
19239 .previous
19240
19241 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19242 + pushl_cfi %ss
19243 + popl_cfi %ds
19244 + pushl_cfi %ss
19245 + popl_cfi %es
19246 +#endif
19247 +
19248 popl_cfi %esi
19249 CFI_RESTORE esi
19250 popl_cfi %edi
19251 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
19252 CFI_RESTORE ebx
19253 ret
19254 CFI_ENDPROC
19255 -ENDPROC(csum_partial_copy_generic)
19256 +ENDPROC(csum_partial_copy_generic_to_user)
19257
19258 #undef ROUND
19259 #undef ROUND1
19260 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
19261 index f2145cf..cea889d 100644
19262 --- a/arch/x86/lib/clear_page_64.S
19263 +++ b/arch/x86/lib/clear_page_64.S
19264 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
19265 movl $4096/8,%ecx
19266 xorl %eax,%eax
19267 rep stosq
19268 + pax_force_retaddr
19269 ret
19270 CFI_ENDPROC
19271 ENDPROC(clear_page_c)
19272 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
19273 movl $4096,%ecx
19274 xorl %eax,%eax
19275 rep stosb
19276 + pax_force_retaddr
19277 ret
19278 CFI_ENDPROC
19279 ENDPROC(clear_page_c_e)
19280 @@ -43,6 +45,7 @@ ENTRY(clear_page)
19281 leaq 64(%rdi),%rdi
19282 jnz .Lloop
19283 nop
19284 + pax_force_retaddr
19285 ret
19286 CFI_ENDPROC
19287 .Lclear_page_end:
19288 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
19289
19290 #include <asm/cpufeature.h>
19291
19292 - .section .altinstr_replacement,"ax"
19293 + .section .altinstr_replacement,"a"
19294 1: .byte 0xeb /* jmp <disp8> */
19295 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
19296 2: .byte 0xeb /* jmp <disp8> */
19297 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
19298 index 1e572c5..2a162cd 100644
19299 --- a/arch/x86/lib/cmpxchg16b_emu.S
19300 +++ b/arch/x86/lib/cmpxchg16b_emu.S
19301 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
19302
19303 popf
19304 mov $1, %al
19305 + pax_force_retaddr
19306 ret
19307
19308 not_same:
19309 popf
19310 xor %al,%al
19311 + pax_force_retaddr
19312 ret
19313
19314 CFI_ENDPROC
19315 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
19316 index 01c805b..dccb07f 100644
19317 --- a/arch/x86/lib/copy_page_64.S
19318 +++ b/arch/x86/lib/copy_page_64.S
19319 @@ -9,6 +9,7 @@ copy_page_c:
19320 CFI_STARTPROC
19321 movl $4096/8,%ecx
19322 rep movsq
19323 + pax_force_retaddr
19324 ret
19325 CFI_ENDPROC
19326 ENDPROC(copy_page_c)
19327 @@ -39,7 +40,7 @@ ENTRY(copy_page)
19328 movq 16 (%rsi), %rdx
19329 movq 24 (%rsi), %r8
19330 movq 32 (%rsi), %r9
19331 - movq 40 (%rsi), %r10
19332 + movq 40 (%rsi), %r13
19333 movq 48 (%rsi), %r11
19334 movq 56 (%rsi), %r12
19335
19336 @@ -50,7 +51,7 @@ ENTRY(copy_page)
19337 movq %rdx, 16 (%rdi)
19338 movq %r8, 24 (%rdi)
19339 movq %r9, 32 (%rdi)
19340 - movq %r10, 40 (%rdi)
19341 + movq %r13, 40 (%rdi)
19342 movq %r11, 48 (%rdi)
19343 movq %r12, 56 (%rdi)
19344
19345 @@ -69,7 +70,7 @@ ENTRY(copy_page)
19346 movq 16 (%rsi), %rdx
19347 movq 24 (%rsi), %r8
19348 movq 32 (%rsi), %r9
19349 - movq 40 (%rsi), %r10
19350 + movq 40 (%rsi), %r13
19351 movq 48 (%rsi), %r11
19352 movq 56 (%rsi), %r12
19353
19354 @@ -78,7 +79,7 @@ ENTRY(copy_page)
19355 movq %rdx, 16 (%rdi)
19356 movq %r8, 24 (%rdi)
19357 movq %r9, 32 (%rdi)
19358 - movq %r10, 40 (%rdi)
19359 + movq %r13, 40 (%rdi)
19360 movq %r11, 48 (%rdi)
19361 movq %r12, 56 (%rdi)
19362
19363 @@ -95,6 +96,7 @@ ENTRY(copy_page)
19364 CFI_RESTORE r13
19365 addq $3*8,%rsp
19366 CFI_ADJUST_CFA_OFFSET -3*8
19367 + pax_force_retaddr
19368 ret
19369 .Lcopy_page_end:
19370 CFI_ENDPROC
19371 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
19372
19373 #include <asm/cpufeature.h>
19374
19375 - .section .altinstr_replacement,"ax"
19376 + .section .altinstr_replacement,"a"
19377 1: .byte 0xeb /* jmp <disp8> */
19378 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
19379 2:
19380 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
19381 index 0248402..821c786 100644
19382 --- a/arch/x86/lib/copy_user_64.S
19383 +++ b/arch/x86/lib/copy_user_64.S
19384 @@ -16,6 +16,7 @@
19385 #include <asm/thread_info.h>
19386 #include <asm/cpufeature.h>
19387 #include <asm/alternative-asm.h>
19388 +#include <asm/pgtable.h>
19389
19390 /*
19391 * By placing feature2 after feature1 in altinstructions section, we logically
19392 @@ -29,7 +30,7 @@
19393 .byte 0xe9 /* 32bit jump */
19394 .long \orig-1f /* by default jump to orig */
19395 1:
19396 - .section .altinstr_replacement,"ax"
19397 + .section .altinstr_replacement,"a"
19398 2: .byte 0xe9 /* near jump with 32bit immediate */
19399 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
19400 3: .byte 0xe9 /* near jump with 32bit immediate */
19401 @@ -71,47 +72,20 @@
19402 #endif
19403 .endm
19404
19405 -/* Standard copy_to_user with segment limit checking */
19406 -ENTRY(_copy_to_user)
19407 - CFI_STARTPROC
19408 - GET_THREAD_INFO(%rax)
19409 - movq %rdi,%rcx
19410 - addq %rdx,%rcx
19411 - jc bad_to_user
19412 - cmpq TI_addr_limit(%rax),%rcx
19413 - ja bad_to_user
19414 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
19415 - copy_user_generic_unrolled,copy_user_generic_string, \
19416 - copy_user_enhanced_fast_string
19417 - CFI_ENDPROC
19418 -ENDPROC(_copy_to_user)
19419 -
19420 -/* Standard copy_from_user with segment limit checking */
19421 -ENTRY(_copy_from_user)
19422 - CFI_STARTPROC
19423 - GET_THREAD_INFO(%rax)
19424 - movq %rsi,%rcx
19425 - addq %rdx,%rcx
19426 - jc bad_from_user
19427 - cmpq TI_addr_limit(%rax),%rcx
19428 - ja bad_from_user
19429 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
19430 - copy_user_generic_unrolled,copy_user_generic_string, \
19431 - copy_user_enhanced_fast_string
19432 - CFI_ENDPROC
19433 -ENDPROC(_copy_from_user)
19434 -
19435 .section .fixup,"ax"
19436 /* must zero dest */
19437 ENTRY(bad_from_user)
19438 bad_from_user:
19439 CFI_STARTPROC
19440 + testl %edx,%edx
19441 + js bad_to_user
19442 movl %edx,%ecx
19443 xorl %eax,%eax
19444 rep
19445 stosb
19446 bad_to_user:
19447 movl %edx,%eax
19448 + pax_force_retaddr
19449 ret
19450 CFI_ENDPROC
19451 ENDPROC(bad_from_user)
19452 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
19453 jz 17f
19454 1: movq (%rsi),%r8
19455 2: movq 1*8(%rsi),%r9
19456 -3: movq 2*8(%rsi),%r10
19457 +3: movq 2*8(%rsi),%rax
19458 4: movq 3*8(%rsi),%r11
19459 5: movq %r8,(%rdi)
19460 6: movq %r9,1*8(%rdi)
19461 -7: movq %r10,2*8(%rdi)
19462 +7: movq %rax,2*8(%rdi)
19463 8: movq %r11,3*8(%rdi)
19464 9: movq 4*8(%rsi),%r8
19465 10: movq 5*8(%rsi),%r9
19466 -11: movq 6*8(%rsi),%r10
19467 +11: movq 6*8(%rsi),%rax
19468 12: movq 7*8(%rsi),%r11
19469 13: movq %r8,4*8(%rdi)
19470 14: movq %r9,5*8(%rdi)
19471 -15: movq %r10,6*8(%rdi)
19472 +15: movq %rax,6*8(%rdi)
19473 16: movq %r11,7*8(%rdi)
19474 leaq 64(%rsi),%rsi
19475 leaq 64(%rdi),%rdi
19476 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
19477 decl %ecx
19478 jnz 21b
19479 23: xor %eax,%eax
19480 + pax_force_retaddr
19481 ret
19482
19483 .section .fixup,"ax"
19484 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
19485 3: rep
19486 movsb
19487 4: xorl %eax,%eax
19488 + pax_force_retaddr
19489 ret
19490
19491 .section .fixup,"ax"
19492 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
19493 1: rep
19494 movsb
19495 2: xorl %eax,%eax
19496 + pax_force_retaddr
19497 ret
19498
19499 .section .fixup,"ax"
19500 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
19501 index cb0c112..e3a6895 100644
19502 --- a/arch/x86/lib/copy_user_nocache_64.S
19503 +++ b/arch/x86/lib/copy_user_nocache_64.S
19504 @@ -8,12 +8,14 @@
19505
19506 #include <linux/linkage.h>
19507 #include <asm/dwarf2.h>
19508 +#include <asm/alternative-asm.h>
19509
19510 #define FIX_ALIGNMENT 1
19511
19512 #include <asm/current.h>
19513 #include <asm/asm-offsets.h>
19514 #include <asm/thread_info.h>
19515 +#include <asm/pgtable.h>
19516
19517 .macro ALIGN_DESTINATION
19518 #ifdef FIX_ALIGNMENT
19519 @@ -50,6 +52,15 @@
19520 */
19521 ENTRY(__copy_user_nocache)
19522 CFI_STARTPROC
19523 +
19524 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19525 + mov $PAX_USER_SHADOW_BASE,%rcx
19526 + cmp %rcx,%rsi
19527 + jae 1f
19528 + add %rcx,%rsi
19529 +1:
19530 +#endif
19531 +
19532 cmpl $8,%edx
19533 jb 20f /* less then 8 bytes, go to byte copy loop */
19534 ALIGN_DESTINATION
19535 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
19536 jz 17f
19537 1: movq (%rsi),%r8
19538 2: movq 1*8(%rsi),%r9
19539 -3: movq 2*8(%rsi),%r10
19540 +3: movq 2*8(%rsi),%rax
19541 4: movq 3*8(%rsi),%r11
19542 5: movnti %r8,(%rdi)
19543 6: movnti %r9,1*8(%rdi)
19544 -7: movnti %r10,2*8(%rdi)
19545 +7: movnti %rax,2*8(%rdi)
19546 8: movnti %r11,3*8(%rdi)
19547 9: movq 4*8(%rsi),%r8
19548 10: movq 5*8(%rsi),%r9
19549 -11: movq 6*8(%rsi),%r10
19550 +11: movq 6*8(%rsi),%rax
19551 12: movq 7*8(%rsi),%r11
19552 13: movnti %r8,4*8(%rdi)
19553 14: movnti %r9,5*8(%rdi)
19554 -15: movnti %r10,6*8(%rdi)
19555 +15: movnti %rax,6*8(%rdi)
19556 16: movnti %r11,7*8(%rdi)
19557 leaq 64(%rsi),%rsi
19558 leaq 64(%rdi),%rdi
19559 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
19560 jnz 21b
19561 23: xorl %eax,%eax
19562 sfence
19563 + pax_force_retaddr
19564 ret
19565
19566 .section .fixup,"ax"
19567 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
19568 index fb903b7..c92b7f7 100644
19569 --- a/arch/x86/lib/csum-copy_64.S
19570 +++ b/arch/x86/lib/csum-copy_64.S
19571 @@ -8,6 +8,7 @@
19572 #include <linux/linkage.h>
19573 #include <asm/dwarf2.h>
19574 #include <asm/errno.h>
19575 +#include <asm/alternative-asm.h>
19576
19577 /*
19578 * Checksum copy with exception handling.
19579 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
19580 CFI_RESTORE rbp
19581 addq $7*8, %rsp
19582 CFI_ADJUST_CFA_OFFSET -7*8
19583 + pax_force_retaddr 0, 1
19584 ret
19585 CFI_RESTORE_STATE
19586
19587 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
19588 index 459b58a..9570bc7 100644
19589 --- a/arch/x86/lib/csum-wrappers_64.c
19590 +++ b/arch/x86/lib/csum-wrappers_64.c
19591 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
19592 len -= 2;
19593 }
19594 }
19595 - isum = csum_partial_copy_generic((__force const void *)src,
19596 +
19597 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19598 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19599 + src += PAX_USER_SHADOW_BASE;
19600 +#endif
19601 +
19602 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
19603 dst, len, isum, errp, NULL);
19604 if (unlikely(*errp))
19605 goto out_err;
19606 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
19607 }
19608
19609 *errp = 0;
19610 - return csum_partial_copy_generic(src, (void __force *)dst,
19611 +
19612 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19613 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
19614 + dst += PAX_USER_SHADOW_BASE;
19615 +#endif
19616 +
19617 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
19618 len, isum, NULL, errp);
19619 }
19620 EXPORT_SYMBOL(csum_partial_copy_to_user);
19621 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
19622 index 51f1504..ddac4c1 100644
19623 --- a/arch/x86/lib/getuser.S
19624 +++ b/arch/x86/lib/getuser.S
19625 @@ -33,15 +33,38 @@
19626 #include <asm/asm-offsets.h>
19627 #include <asm/thread_info.h>
19628 #include <asm/asm.h>
19629 +#include <asm/segment.h>
19630 +#include <asm/pgtable.h>
19631 +#include <asm/alternative-asm.h>
19632 +
19633 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19634 +#define __copyuser_seg gs;
19635 +#else
19636 +#define __copyuser_seg
19637 +#endif
19638
19639 .text
19640 ENTRY(__get_user_1)
19641 CFI_STARTPROC
19642 +
19643 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19644 GET_THREAD_INFO(%_ASM_DX)
19645 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19646 jae bad_get_user
19647 -1: movzb (%_ASM_AX),%edx
19648 +
19649 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19650 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19651 + cmp %_ASM_DX,%_ASM_AX
19652 + jae 1234f
19653 + add %_ASM_DX,%_ASM_AX
19654 +1234:
19655 +#endif
19656 +
19657 +#endif
19658 +
19659 +1: __copyuser_seg movzb (%_ASM_AX),%edx
19660 xor %eax,%eax
19661 + pax_force_retaddr
19662 ret
19663 CFI_ENDPROC
19664 ENDPROC(__get_user_1)
19665 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
19666 ENTRY(__get_user_2)
19667 CFI_STARTPROC
19668 add $1,%_ASM_AX
19669 +
19670 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19671 jc bad_get_user
19672 GET_THREAD_INFO(%_ASM_DX)
19673 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19674 jae bad_get_user
19675 -2: movzwl -1(%_ASM_AX),%edx
19676 +
19677 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19678 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19679 + cmp %_ASM_DX,%_ASM_AX
19680 + jae 1234f
19681 + add %_ASM_DX,%_ASM_AX
19682 +1234:
19683 +#endif
19684 +
19685 +#endif
19686 +
19687 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
19688 xor %eax,%eax
19689 + pax_force_retaddr
19690 ret
19691 CFI_ENDPROC
19692 ENDPROC(__get_user_2)
19693 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
19694 ENTRY(__get_user_4)
19695 CFI_STARTPROC
19696 add $3,%_ASM_AX
19697 +
19698 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19699 jc bad_get_user
19700 GET_THREAD_INFO(%_ASM_DX)
19701 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19702 jae bad_get_user
19703 -3: mov -3(%_ASM_AX),%edx
19704 +
19705 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19706 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19707 + cmp %_ASM_DX,%_ASM_AX
19708 + jae 1234f
19709 + add %_ASM_DX,%_ASM_AX
19710 +1234:
19711 +#endif
19712 +
19713 +#endif
19714 +
19715 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
19716 xor %eax,%eax
19717 + pax_force_retaddr
19718 ret
19719 CFI_ENDPROC
19720 ENDPROC(__get_user_4)
19721 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
19722 GET_THREAD_INFO(%_ASM_DX)
19723 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19724 jae bad_get_user
19725 +
19726 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19727 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19728 + cmp %_ASM_DX,%_ASM_AX
19729 + jae 1234f
19730 + add %_ASM_DX,%_ASM_AX
19731 +1234:
19732 +#endif
19733 +
19734 4: movq -7(%_ASM_AX),%_ASM_DX
19735 xor %eax,%eax
19736 + pax_force_retaddr
19737 ret
19738 CFI_ENDPROC
19739 ENDPROC(__get_user_8)
19740 @@ -91,6 +152,7 @@ bad_get_user:
19741 CFI_STARTPROC
19742 xor %edx,%edx
19743 mov $(-EFAULT),%_ASM_AX
19744 + pax_force_retaddr
19745 ret
19746 CFI_ENDPROC
19747 END(bad_get_user)
19748 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
19749 index 9f33b98..dfc7678 100644
19750 --- a/arch/x86/lib/insn.c
19751 +++ b/arch/x86/lib/insn.c
19752 @@ -21,6 +21,11 @@
19753 #include <linux/string.h>
19754 #include <asm/inat.h>
19755 #include <asm/insn.h>
19756 +#ifdef __KERNEL__
19757 +#include <asm/pgtable_types.h>
19758 +#else
19759 +#define ktla_ktva(addr) addr
19760 +#endif
19761
19762 #define get_next(t, insn) \
19763 ({t r; r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
19764 @@ -40,8 +45,8 @@
19765 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
19766 {
19767 memset(insn, 0, sizeof(*insn));
19768 - insn->kaddr = kaddr;
19769 - insn->next_byte = kaddr;
19770 + insn->kaddr = ktla_ktva(kaddr);
19771 + insn->next_byte = ktla_ktva(kaddr);
19772 insn->x86_64 = x86_64 ? 1 : 0;
19773 insn->opnd_bytes = 4;
19774 if (x86_64)
19775 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
19776 index 05a95e7..326f2fa 100644
19777 --- a/arch/x86/lib/iomap_copy_64.S
19778 +++ b/arch/x86/lib/iomap_copy_64.S
19779 @@ -17,6 +17,7 @@
19780
19781 #include <linux/linkage.h>
19782 #include <asm/dwarf2.h>
19783 +#include <asm/alternative-asm.h>
19784
19785 /*
19786 * override generic version in lib/iomap_copy.c
19787 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
19788 CFI_STARTPROC
19789 movl %edx,%ecx
19790 rep movsd
19791 + pax_force_retaddr
19792 ret
19793 CFI_ENDPROC
19794 ENDPROC(__iowrite32_copy)
19795 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
19796 index efbf2a0..8893637 100644
19797 --- a/arch/x86/lib/memcpy_64.S
19798 +++ b/arch/x86/lib/memcpy_64.S
19799 @@ -34,6 +34,7 @@
19800 rep movsq
19801 movl %edx, %ecx
19802 rep movsb
19803 + pax_force_retaddr
19804 ret
19805 .Lmemcpy_e:
19806 .previous
19807 @@ -51,6 +52,7 @@
19808
19809 movl %edx, %ecx
19810 rep movsb
19811 + pax_force_retaddr
19812 ret
19813 .Lmemcpy_e_e:
19814 .previous
19815 @@ -81,13 +83,13 @@ ENTRY(memcpy)
19816 */
19817 movq 0*8(%rsi), %r8
19818 movq 1*8(%rsi), %r9
19819 - movq 2*8(%rsi), %r10
19820 + movq 2*8(%rsi), %rcx
19821 movq 3*8(%rsi), %r11
19822 leaq 4*8(%rsi), %rsi
19823
19824 movq %r8, 0*8(%rdi)
19825 movq %r9, 1*8(%rdi)
19826 - movq %r10, 2*8(%rdi)
19827 + movq %rcx, 2*8(%rdi)
19828 movq %r11, 3*8(%rdi)
19829 leaq 4*8(%rdi), %rdi
19830 jae .Lcopy_forward_loop
19831 @@ -110,12 +112,12 @@ ENTRY(memcpy)
19832 subq $0x20, %rdx
19833 movq -1*8(%rsi), %r8
19834 movq -2*8(%rsi), %r9
19835 - movq -3*8(%rsi), %r10
19836 + movq -3*8(%rsi), %rcx
19837 movq -4*8(%rsi), %r11
19838 leaq -4*8(%rsi), %rsi
19839 movq %r8, -1*8(%rdi)
19840 movq %r9, -2*8(%rdi)
19841 - movq %r10, -3*8(%rdi)
19842 + movq %rcx, -3*8(%rdi)
19843 movq %r11, -4*8(%rdi)
19844 leaq -4*8(%rdi), %rdi
19845 jae .Lcopy_backward_loop
19846 @@ -135,12 +137,13 @@ ENTRY(memcpy)
19847 */
19848 movq 0*8(%rsi), %r8
19849 movq 1*8(%rsi), %r9
19850 - movq -2*8(%rsi, %rdx), %r10
19851 + movq -2*8(%rsi, %rdx), %rcx
19852 movq -1*8(%rsi, %rdx), %r11
19853 movq %r8, 0*8(%rdi)
19854 movq %r9, 1*8(%rdi)
19855 - movq %r10, -2*8(%rdi, %rdx)
19856 + movq %rcx, -2*8(%rdi, %rdx)
19857 movq %r11, -1*8(%rdi, %rdx)
19858 + pax_force_retaddr
19859 retq
19860 .p2align 4
19861 .Lless_16bytes:
19862 @@ -153,6 +156,7 @@ ENTRY(memcpy)
19863 movq -1*8(%rsi, %rdx), %r9
19864 movq %r8, 0*8(%rdi)
19865 movq %r9, -1*8(%rdi, %rdx)
19866 + pax_force_retaddr
19867 retq
19868 .p2align 4
19869 .Lless_8bytes:
19870 @@ -166,6 +170,7 @@ ENTRY(memcpy)
19871 movl -4(%rsi, %rdx), %r8d
19872 movl %ecx, (%rdi)
19873 movl %r8d, -4(%rdi, %rdx)
19874 + pax_force_retaddr
19875 retq
19876 .p2align 4
19877 .Lless_3bytes:
19878 @@ -183,6 +188,7 @@ ENTRY(memcpy)
19879 jnz .Lloop_1
19880
19881 .Lend:
19882 + pax_force_retaddr
19883 retq
19884 CFI_ENDPROC
19885 ENDPROC(memcpy)
19886 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
19887 index ee16461..c39c199 100644
19888 --- a/arch/x86/lib/memmove_64.S
19889 +++ b/arch/x86/lib/memmove_64.S
19890 @@ -61,13 +61,13 @@ ENTRY(memmove)
19891 5:
19892 sub $0x20, %rdx
19893 movq 0*8(%rsi), %r11
19894 - movq 1*8(%rsi), %r10
19895 + movq 1*8(%rsi), %rcx
19896 movq 2*8(%rsi), %r9
19897 movq 3*8(%rsi), %r8
19898 leaq 4*8(%rsi), %rsi
19899
19900 movq %r11, 0*8(%rdi)
19901 - movq %r10, 1*8(%rdi)
19902 + movq %rcx, 1*8(%rdi)
19903 movq %r9, 2*8(%rdi)
19904 movq %r8, 3*8(%rdi)
19905 leaq 4*8(%rdi), %rdi
19906 @@ -81,10 +81,10 @@ ENTRY(memmove)
19907 4:
19908 movq %rdx, %rcx
19909 movq -8(%rsi, %rdx), %r11
19910 - lea -8(%rdi, %rdx), %r10
19911 + lea -8(%rdi, %rdx), %r9
19912 shrq $3, %rcx
19913 rep movsq
19914 - movq %r11, (%r10)
19915 + movq %r11, (%r9)
19916 jmp 13f
19917 .Lmemmove_end_forward:
19918
19919 @@ -95,14 +95,14 @@ ENTRY(memmove)
19920 7:
19921 movq %rdx, %rcx
19922 movq (%rsi), %r11
19923 - movq %rdi, %r10
19924 + movq %rdi, %r9
19925 leaq -8(%rsi, %rdx), %rsi
19926 leaq -8(%rdi, %rdx), %rdi
19927 shrq $3, %rcx
19928 std
19929 rep movsq
19930 cld
19931 - movq %r11, (%r10)
19932 + movq %r11, (%r9)
19933 jmp 13f
19934
19935 /*
19936 @@ -127,13 +127,13 @@ ENTRY(memmove)
19937 8:
19938 subq $0x20, %rdx
19939 movq -1*8(%rsi), %r11
19940 - movq -2*8(%rsi), %r10
19941 + movq -2*8(%rsi), %rcx
19942 movq -3*8(%rsi), %r9
19943 movq -4*8(%rsi), %r8
19944 leaq -4*8(%rsi), %rsi
19945
19946 movq %r11, -1*8(%rdi)
19947 - movq %r10, -2*8(%rdi)
19948 + movq %rcx, -2*8(%rdi)
19949 movq %r9, -3*8(%rdi)
19950 movq %r8, -4*8(%rdi)
19951 leaq -4*8(%rdi), %rdi
19952 @@ -151,11 +151,11 @@ ENTRY(memmove)
19953 * Move data from 16 bytes to 31 bytes.
19954 */
19955 movq 0*8(%rsi), %r11
19956 - movq 1*8(%rsi), %r10
19957 + movq 1*8(%rsi), %rcx
19958 movq -2*8(%rsi, %rdx), %r9
19959 movq -1*8(%rsi, %rdx), %r8
19960 movq %r11, 0*8(%rdi)
19961 - movq %r10, 1*8(%rdi)
19962 + movq %rcx, 1*8(%rdi)
19963 movq %r9, -2*8(%rdi, %rdx)
19964 movq %r8, -1*8(%rdi, %rdx)
19965 jmp 13f
19966 @@ -167,9 +167,9 @@ ENTRY(memmove)
19967 * Move data from 8 bytes to 15 bytes.
19968 */
19969 movq 0*8(%rsi), %r11
19970 - movq -1*8(%rsi, %rdx), %r10
19971 + movq -1*8(%rsi, %rdx), %r9
19972 movq %r11, 0*8(%rdi)
19973 - movq %r10, -1*8(%rdi, %rdx)
19974 + movq %r9, -1*8(%rdi, %rdx)
19975 jmp 13f
19976 10:
19977 cmpq $4, %rdx
19978 @@ -178,9 +178,9 @@ ENTRY(memmove)
19979 * Move data from 4 bytes to 7 bytes.
19980 */
19981 movl (%rsi), %r11d
19982 - movl -4(%rsi, %rdx), %r10d
19983 + movl -4(%rsi, %rdx), %r9d
19984 movl %r11d, (%rdi)
19985 - movl %r10d, -4(%rdi, %rdx)
19986 + movl %r9d, -4(%rdi, %rdx)
19987 jmp 13f
19988 11:
19989 cmp $2, %rdx
19990 @@ -189,9 +189,9 @@ ENTRY(memmove)
19991 * Move data from 2 bytes to 3 bytes.
19992 */
19993 movw (%rsi), %r11w
19994 - movw -2(%rsi, %rdx), %r10w
19995 + movw -2(%rsi, %rdx), %r9w
19996 movw %r11w, (%rdi)
19997 - movw %r10w, -2(%rdi, %rdx)
19998 + movw %r9w, -2(%rdi, %rdx)
19999 jmp 13f
20000 12:
20001 cmp $1, %rdx
20002 @@ -202,6 +202,7 @@ ENTRY(memmove)
20003 movb (%rsi), %r11b
20004 movb %r11b, (%rdi)
20005 13:
20006 + pax_force_retaddr
20007 retq
20008 CFI_ENDPROC
20009
20010 @@ -210,6 +211,7 @@ ENTRY(memmove)
20011 /* Forward moving data. */
20012 movq %rdx, %rcx
20013 rep movsb
20014 + pax_force_retaddr
20015 retq
20016 .Lmemmove_end_forward_efs:
20017 .previous
20018 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
20019 index 79bd454..dff325a 100644
20020 --- a/arch/x86/lib/memset_64.S
20021 +++ b/arch/x86/lib/memset_64.S
20022 @@ -31,6 +31,7 @@
20023 movl %r8d,%ecx
20024 rep stosb
20025 movq %r9,%rax
20026 + pax_force_retaddr
20027 ret
20028 .Lmemset_e:
20029 .previous
20030 @@ -53,6 +54,7 @@
20031 movl %edx,%ecx
20032 rep stosb
20033 movq %r9,%rax
20034 + pax_force_retaddr
20035 ret
20036 .Lmemset_e_e:
20037 .previous
20038 @@ -60,13 +62,13 @@
20039 ENTRY(memset)
20040 ENTRY(__memset)
20041 CFI_STARTPROC
20042 - movq %rdi,%r10
20043 movq %rdx,%r11
20044
20045 /* expand byte value */
20046 movzbl %sil,%ecx
20047 movabs $0x0101010101010101,%rax
20048 mul %rcx /* with rax, clobbers rdx */
20049 + movq %rdi,%rdx
20050
20051 /* align dst */
20052 movl %edi,%r9d
20053 @@ -120,7 +122,8 @@ ENTRY(__memset)
20054 jnz .Lloop_1
20055
20056 .Lende:
20057 - movq %r10,%rax
20058 + movq %rdx,%rax
20059 + pax_force_retaddr
20060 ret
20061
20062 CFI_RESTORE_STATE
20063 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
20064 index c9f2d9b..e7fd2c0 100644
20065 --- a/arch/x86/lib/mmx_32.c
20066 +++ b/arch/x86/lib/mmx_32.c
20067 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
20068 {
20069 void *p;
20070 int i;
20071 + unsigned long cr0;
20072
20073 if (unlikely(in_interrupt()))
20074 return __memcpy(to, from, len);
20075 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
20076 kernel_fpu_begin();
20077
20078 __asm__ __volatile__ (
20079 - "1: prefetch (%0)\n" /* This set is 28 bytes */
20080 - " prefetch 64(%0)\n"
20081 - " prefetch 128(%0)\n"
20082 - " prefetch 192(%0)\n"
20083 - " prefetch 256(%0)\n"
20084 + "1: prefetch (%1)\n" /* This set is 28 bytes */
20085 + " prefetch 64(%1)\n"
20086 + " prefetch 128(%1)\n"
20087 + " prefetch 192(%1)\n"
20088 + " prefetch 256(%1)\n"
20089 "2: \n"
20090 ".section .fixup, \"ax\"\n"
20091 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20092 + "3: \n"
20093 +
20094 +#ifdef CONFIG_PAX_KERNEXEC
20095 + " movl %%cr0, %0\n"
20096 + " movl %0, %%eax\n"
20097 + " andl $0xFFFEFFFF, %%eax\n"
20098 + " movl %%eax, %%cr0\n"
20099 +#endif
20100 +
20101 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20102 +
20103 +#ifdef CONFIG_PAX_KERNEXEC
20104 + " movl %0, %%cr0\n"
20105 +#endif
20106 +
20107 " jmp 2b\n"
20108 ".previous\n"
20109 _ASM_EXTABLE(1b, 3b)
20110 - : : "r" (from));
20111 + : "=&r" (cr0) : "r" (from) : "ax");
20112
20113 for ( ; i > 5; i--) {
20114 __asm__ __volatile__ (
20115 - "1: prefetch 320(%0)\n"
20116 - "2: movq (%0), %%mm0\n"
20117 - " movq 8(%0), %%mm1\n"
20118 - " movq 16(%0), %%mm2\n"
20119 - " movq 24(%0), %%mm3\n"
20120 - " movq %%mm0, (%1)\n"
20121 - " movq %%mm1, 8(%1)\n"
20122 - " movq %%mm2, 16(%1)\n"
20123 - " movq %%mm3, 24(%1)\n"
20124 - " movq 32(%0), %%mm0\n"
20125 - " movq 40(%0), %%mm1\n"
20126 - " movq 48(%0), %%mm2\n"
20127 - " movq 56(%0), %%mm3\n"
20128 - " movq %%mm0, 32(%1)\n"
20129 - " movq %%mm1, 40(%1)\n"
20130 - " movq %%mm2, 48(%1)\n"
20131 - " movq %%mm3, 56(%1)\n"
20132 + "1: prefetch 320(%1)\n"
20133 + "2: movq (%1), %%mm0\n"
20134 + " movq 8(%1), %%mm1\n"
20135 + " movq 16(%1), %%mm2\n"
20136 + " movq 24(%1), %%mm3\n"
20137 + " movq %%mm0, (%2)\n"
20138 + " movq %%mm1, 8(%2)\n"
20139 + " movq %%mm2, 16(%2)\n"
20140 + " movq %%mm3, 24(%2)\n"
20141 + " movq 32(%1), %%mm0\n"
20142 + " movq 40(%1), %%mm1\n"
20143 + " movq 48(%1), %%mm2\n"
20144 + " movq 56(%1), %%mm3\n"
20145 + " movq %%mm0, 32(%2)\n"
20146 + " movq %%mm1, 40(%2)\n"
20147 + " movq %%mm2, 48(%2)\n"
20148 + " movq %%mm3, 56(%2)\n"
20149 ".section .fixup, \"ax\"\n"
20150 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20151 + "3:\n"
20152 +
20153 +#ifdef CONFIG_PAX_KERNEXEC
20154 + " movl %%cr0, %0\n"
20155 + " movl %0, %%eax\n"
20156 + " andl $0xFFFEFFFF, %%eax\n"
20157 + " movl %%eax, %%cr0\n"
20158 +#endif
20159 +
20160 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20161 +
20162 +#ifdef CONFIG_PAX_KERNEXEC
20163 + " movl %0, %%cr0\n"
20164 +#endif
20165 +
20166 " jmp 2b\n"
20167 ".previous\n"
20168 _ASM_EXTABLE(1b, 3b)
20169 - : : "r" (from), "r" (to) : "memory");
20170 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20171
20172 from += 64;
20173 to += 64;
20174 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
20175 static void fast_copy_page(void *to, void *from)
20176 {
20177 int i;
20178 + unsigned long cr0;
20179
20180 kernel_fpu_begin();
20181
20182 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
20183 * but that is for later. -AV
20184 */
20185 __asm__ __volatile__(
20186 - "1: prefetch (%0)\n"
20187 - " prefetch 64(%0)\n"
20188 - " prefetch 128(%0)\n"
20189 - " prefetch 192(%0)\n"
20190 - " prefetch 256(%0)\n"
20191 + "1: prefetch (%1)\n"
20192 + " prefetch 64(%1)\n"
20193 + " prefetch 128(%1)\n"
20194 + " prefetch 192(%1)\n"
20195 + " prefetch 256(%1)\n"
20196 "2: \n"
20197 ".section .fixup, \"ax\"\n"
20198 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20199 + "3: \n"
20200 +
20201 +#ifdef CONFIG_PAX_KERNEXEC
20202 + " movl %%cr0, %0\n"
20203 + " movl %0, %%eax\n"
20204 + " andl $0xFFFEFFFF, %%eax\n"
20205 + " movl %%eax, %%cr0\n"
20206 +#endif
20207 +
20208 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20209 +
20210 +#ifdef CONFIG_PAX_KERNEXEC
20211 + " movl %0, %%cr0\n"
20212 +#endif
20213 +
20214 " jmp 2b\n"
20215 ".previous\n"
20216 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
20217 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20218
20219 for (i = 0; i < (4096-320)/64; i++) {
20220 __asm__ __volatile__ (
20221 - "1: prefetch 320(%0)\n"
20222 - "2: movq (%0), %%mm0\n"
20223 - " movntq %%mm0, (%1)\n"
20224 - " movq 8(%0), %%mm1\n"
20225 - " movntq %%mm1, 8(%1)\n"
20226 - " movq 16(%0), %%mm2\n"
20227 - " movntq %%mm2, 16(%1)\n"
20228 - " movq 24(%0), %%mm3\n"
20229 - " movntq %%mm3, 24(%1)\n"
20230 - " movq 32(%0), %%mm4\n"
20231 - " movntq %%mm4, 32(%1)\n"
20232 - " movq 40(%0), %%mm5\n"
20233 - " movntq %%mm5, 40(%1)\n"
20234 - " movq 48(%0), %%mm6\n"
20235 - " movntq %%mm6, 48(%1)\n"
20236 - " movq 56(%0), %%mm7\n"
20237 - " movntq %%mm7, 56(%1)\n"
20238 + "1: prefetch 320(%1)\n"
20239 + "2: movq (%1), %%mm0\n"
20240 + " movntq %%mm0, (%2)\n"
20241 + " movq 8(%1), %%mm1\n"
20242 + " movntq %%mm1, 8(%2)\n"
20243 + " movq 16(%1), %%mm2\n"
20244 + " movntq %%mm2, 16(%2)\n"
20245 + " movq 24(%1), %%mm3\n"
20246 + " movntq %%mm3, 24(%2)\n"
20247 + " movq 32(%1), %%mm4\n"
20248 + " movntq %%mm4, 32(%2)\n"
20249 + " movq 40(%1), %%mm5\n"
20250 + " movntq %%mm5, 40(%2)\n"
20251 + " movq 48(%1), %%mm6\n"
20252 + " movntq %%mm6, 48(%2)\n"
20253 + " movq 56(%1), %%mm7\n"
20254 + " movntq %%mm7, 56(%2)\n"
20255 ".section .fixup, \"ax\"\n"
20256 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20257 + "3:\n"
20258 +
20259 +#ifdef CONFIG_PAX_KERNEXEC
20260 + " movl %%cr0, %0\n"
20261 + " movl %0, %%eax\n"
20262 + " andl $0xFFFEFFFF, %%eax\n"
20263 + " movl %%eax, %%cr0\n"
20264 +#endif
20265 +
20266 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20267 +
20268 +#ifdef CONFIG_PAX_KERNEXEC
20269 + " movl %0, %%cr0\n"
20270 +#endif
20271 +
20272 " jmp 2b\n"
20273 ".previous\n"
20274 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
20275 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20276
20277 from += 64;
20278 to += 64;
20279 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
20280 static void fast_copy_page(void *to, void *from)
20281 {
20282 int i;
20283 + unsigned long cr0;
20284
20285 kernel_fpu_begin();
20286
20287 __asm__ __volatile__ (
20288 - "1: prefetch (%0)\n"
20289 - " prefetch 64(%0)\n"
20290 - " prefetch 128(%0)\n"
20291 - " prefetch 192(%0)\n"
20292 - " prefetch 256(%0)\n"
20293 + "1: prefetch (%1)\n"
20294 + " prefetch 64(%1)\n"
20295 + " prefetch 128(%1)\n"
20296 + " prefetch 192(%1)\n"
20297 + " prefetch 256(%1)\n"
20298 "2: \n"
20299 ".section .fixup, \"ax\"\n"
20300 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20301 + "3: \n"
20302 +
20303 +#ifdef CONFIG_PAX_KERNEXEC
20304 + " movl %%cr0, %0\n"
20305 + " movl %0, %%eax\n"
20306 + " andl $0xFFFEFFFF, %%eax\n"
20307 + " movl %%eax, %%cr0\n"
20308 +#endif
20309 +
20310 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20311 +
20312 +#ifdef CONFIG_PAX_KERNEXEC
20313 + " movl %0, %%cr0\n"
20314 +#endif
20315 +
20316 " jmp 2b\n"
20317 ".previous\n"
20318 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
20319 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20320
20321 for (i = 0; i < 4096/64; i++) {
20322 __asm__ __volatile__ (
20323 - "1: prefetch 320(%0)\n"
20324 - "2: movq (%0), %%mm0\n"
20325 - " movq 8(%0), %%mm1\n"
20326 - " movq 16(%0), %%mm2\n"
20327 - " movq 24(%0), %%mm3\n"
20328 - " movq %%mm0, (%1)\n"
20329 - " movq %%mm1, 8(%1)\n"
20330 - " movq %%mm2, 16(%1)\n"
20331 - " movq %%mm3, 24(%1)\n"
20332 - " movq 32(%0), %%mm0\n"
20333 - " movq 40(%0), %%mm1\n"
20334 - " movq 48(%0), %%mm2\n"
20335 - " movq 56(%0), %%mm3\n"
20336 - " movq %%mm0, 32(%1)\n"
20337 - " movq %%mm1, 40(%1)\n"
20338 - " movq %%mm2, 48(%1)\n"
20339 - " movq %%mm3, 56(%1)\n"
20340 + "1: prefetch 320(%1)\n"
20341 + "2: movq (%1), %%mm0\n"
20342 + " movq 8(%1), %%mm1\n"
20343 + " movq 16(%1), %%mm2\n"
20344 + " movq 24(%1), %%mm3\n"
20345 + " movq %%mm0, (%2)\n"
20346 + " movq %%mm1, 8(%2)\n"
20347 + " movq %%mm2, 16(%2)\n"
20348 + " movq %%mm3, 24(%2)\n"
20349 + " movq 32(%1), %%mm0\n"
20350 + " movq 40(%1), %%mm1\n"
20351 + " movq 48(%1), %%mm2\n"
20352 + " movq 56(%1), %%mm3\n"
20353 + " movq %%mm0, 32(%2)\n"
20354 + " movq %%mm1, 40(%2)\n"
20355 + " movq %%mm2, 48(%2)\n"
20356 + " movq %%mm3, 56(%2)\n"
20357 ".section .fixup, \"ax\"\n"
20358 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20359 + "3:\n"
20360 +
20361 +#ifdef CONFIG_PAX_KERNEXEC
20362 + " movl %%cr0, %0\n"
20363 + " movl %0, %%eax\n"
20364 + " andl $0xFFFEFFFF, %%eax\n"
20365 + " movl %%eax, %%cr0\n"
20366 +#endif
20367 +
20368 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20369 +
20370 +#ifdef CONFIG_PAX_KERNEXEC
20371 + " movl %0, %%cr0\n"
20372 +#endif
20373 +
20374 " jmp 2b\n"
20375 ".previous\n"
20376 _ASM_EXTABLE(1b, 3b)
20377 - : : "r" (from), "r" (to) : "memory");
20378 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20379
20380 from += 64;
20381 to += 64;
20382 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
20383 index 69fa106..adda88b 100644
20384 --- a/arch/x86/lib/msr-reg.S
20385 +++ b/arch/x86/lib/msr-reg.S
20386 @@ -3,6 +3,7 @@
20387 #include <asm/dwarf2.h>
20388 #include <asm/asm.h>
20389 #include <asm/msr.h>
20390 +#include <asm/alternative-asm.h>
20391
20392 #ifdef CONFIG_X86_64
20393 /*
20394 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
20395 CFI_STARTPROC
20396 pushq_cfi %rbx
20397 pushq_cfi %rbp
20398 - movq %rdi, %r10 /* Save pointer */
20399 + movq %rdi, %r9 /* Save pointer */
20400 xorl %r11d, %r11d /* Return value */
20401 movl (%rdi), %eax
20402 movl 4(%rdi), %ecx
20403 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
20404 movl 28(%rdi), %edi
20405 CFI_REMEMBER_STATE
20406 1: \op
20407 -2: movl %eax, (%r10)
20408 +2: movl %eax, (%r9)
20409 movl %r11d, %eax /* Return value */
20410 - movl %ecx, 4(%r10)
20411 - movl %edx, 8(%r10)
20412 - movl %ebx, 12(%r10)
20413 - movl %ebp, 20(%r10)
20414 - movl %esi, 24(%r10)
20415 - movl %edi, 28(%r10)
20416 + movl %ecx, 4(%r9)
20417 + movl %edx, 8(%r9)
20418 + movl %ebx, 12(%r9)
20419 + movl %ebp, 20(%r9)
20420 + movl %esi, 24(%r9)
20421 + movl %edi, 28(%r9)
20422 popq_cfi %rbp
20423 popq_cfi %rbx
20424 + pax_force_retaddr
20425 ret
20426 3:
20427 CFI_RESTORE_STATE
20428 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
20429 index 36b0d15..d381858 100644
20430 --- a/arch/x86/lib/putuser.S
20431 +++ b/arch/x86/lib/putuser.S
20432 @@ -15,7 +15,9 @@
20433 #include <asm/thread_info.h>
20434 #include <asm/errno.h>
20435 #include <asm/asm.h>
20436 -
20437 +#include <asm/segment.h>
20438 +#include <asm/pgtable.h>
20439 +#include <asm/alternative-asm.h>
20440
20441 /*
20442 * __put_user_X
20443 @@ -29,52 +31,119 @@
20444 * as they get called from within inline assembly.
20445 */
20446
20447 -#define ENTER CFI_STARTPROC ; \
20448 - GET_THREAD_INFO(%_ASM_BX)
20449 -#define EXIT ret ; \
20450 +#define ENTER CFI_STARTPROC
20451 +#define EXIT pax_force_retaddr; ret ; \
20452 CFI_ENDPROC
20453
20454 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20455 +#define _DEST %_ASM_CX,%_ASM_BX
20456 +#else
20457 +#define _DEST %_ASM_CX
20458 +#endif
20459 +
20460 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20461 +#define __copyuser_seg gs;
20462 +#else
20463 +#define __copyuser_seg
20464 +#endif
20465 +
20466 .text
20467 ENTRY(__put_user_1)
20468 ENTER
20469 +
20470 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20471 + GET_THREAD_INFO(%_ASM_BX)
20472 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
20473 jae bad_put_user
20474 -1: movb %al,(%_ASM_CX)
20475 +
20476 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20477 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20478 + cmp %_ASM_BX,%_ASM_CX
20479 + jb 1234f
20480 + xor %ebx,%ebx
20481 +1234:
20482 +#endif
20483 +
20484 +#endif
20485 +
20486 +1: __copyuser_seg movb %al,(_DEST)
20487 xor %eax,%eax
20488 EXIT
20489 ENDPROC(__put_user_1)
20490
20491 ENTRY(__put_user_2)
20492 ENTER
20493 +
20494 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20495 + GET_THREAD_INFO(%_ASM_BX)
20496 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20497 sub $1,%_ASM_BX
20498 cmp %_ASM_BX,%_ASM_CX
20499 jae bad_put_user
20500 -2: movw %ax,(%_ASM_CX)
20501 +
20502 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20503 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20504 + cmp %_ASM_BX,%_ASM_CX
20505 + jb 1234f
20506 + xor %ebx,%ebx
20507 +1234:
20508 +#endif
20509 +
20510 +#endif
20511 +
20512 +2: __copyuser_seg movw %ax,(_DEST)
20513 xor %eax,%eax
20514 EXIT
20515 ENDPROC(__put_user_2)
20516
20517 ENTRY(__put_user_4)
20518 ENTER
20519 +
20520 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20521 + GET_THREAD_INFO(%_ASM_BX)
20522 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20523 sub $3,%_ASM_BX
20524 cmp %_ASM_BX,%_ASM_CX
20525 jae bad_put_user
20526 -3: movl %eax,(%_ASM_CX)
20527 +
20528 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20529 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20530 + cmp %_ASM_BX,%_ASM_CX
20531 + jb 1234f
20532 + xor %ebx,%ebx
20533 +1234:
20534 +#endif
20535 +
20536 +#endif
20537 +
20538 +3: __copyuser_seg movl %eax,(_DEST)
20539 xor %eax,%eax
20540 EXIT
20541 ENDPROC(__put_user_4)
20542
20543 ENTRY(__put_user_8)
20544 ENTER
20545 +
20546 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20547 + GET_THREAD_INFO(%_ASM_BX)
20548 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20549 sub $7,%_ASM_BX
20550 cmp %_ASM_BX,%_ASM_CX
20551 jae bad_put_user
20552 -4: mov %_ASM_AX,(%_ASM_CX)
20553 +
20554 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20555 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20556 + cmp %_ASM_BX,%_ASM_CX
20557 + jb 1234f
20558 + xor %ebx,%ebx
20559 +1234:
20560 +#endif
20561 +
20562 +#endif
20563 +
20564 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
20565 #ifdef CONFIG_X86_32
20566 -5: movl %edx,4(%_ASM_CX)
20567 +5: __copyuser_seg movl %edx,4(_DEST)
20568 #endif
20569 xor %eax,%eax
20570 EXIT
20571 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
20572 index 1cad221..de671ee 100644
20573 --- a/arch/x86/lib/rwlock.S
20574 +++ b/arch/x86/lib/rwlock.S
20575 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
20576 FRAME
20577 0: LOCK_PREFIX
20578 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
20579 +
20580 +#ifdef CONFIG_PAX_REFCOUNT
20581 + jno 1234f
20582 + LOCK_PREFIX
20583 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
20584 + int $4
20585 +1234:
20586 + _ASM_EXTABLE(1234b, 1234b)
20587 +#endif
20588 +
20589 1: rep; nop
20590 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
20591 jne 1b
20592 LOCK_PREFIX
20593 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
20594 +
20595 +#ifdef CONFIG_PAX_REFCOUNT
20596 + jno 1234f
20597 + LOCK_PREFIX
20598 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
20599 + int $4
20600 +1234:
20601 + _ASM_EXTABLE(1234b, 1234b)
20602 +#endif
20603 +
20604 jnz 0b
20605 ENDFRAME
20606 + pax_force_retaddr
20607 ret
20608 CFI_ENDPROC
20609 END(__write_lock_failed)
20610 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
20611 FRAME
20612 0: LOCK_PREFIX
20613 READ_LOCK_SIZE(inc) (%__lock_ptr)
20614 +
20615 +#ifdef CONFIG_PAX_REFCOUNT
20616 + jno 1234f
20617 + LOCK_PREFIX
20618 + READ_LOCK_SIZE(dec) (%__lock_ptr)
20619 + int $4
20620 +1234:
20621 + _ASM_EXTABLE(1234b, 1234b)
20622 +#endif
20623 +
20624 1: rep; nop
20625 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
20626 js 1b
20627 LOCK_PREFIX
20628 READ_LOCK_SIZE(dec) (%__lock_ptr)
20629 +
20630 +#ifdef CONFIG_PAX_REFCOUNT
20631 + jno 1234f
20632 + LOCK_PREFIX
20633 + READ_LOCK_SIZE(inc) (%__lock_ptr)
20634 + int $4
20635 +1234:
20636 + _ASM_EXTABLE(1234b, 1234b)
20637 +#endif
20638 +
20639 js 0b
20640 ENDFRAME
20641 + pax_force_retaddr
20642 ret
20643 CFI_ENDPROC
20644 END(__read_lock_failed)
20645 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
20646 index 5dff5f0..cadebf4 100644
20647 --- a/arch/x86/lib/rwsem.S
20648 +++ b/arch/x86/lib/rwsem.S
20649 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
20650 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
20651 CFI_RESTORE __ASM_REG(dx)
20652 restore_common_regs
20653 + pax_force_retaddr
20654 ret
20655 CFI_ENDPROC
20656 ENDPROC(call_rwsem_down_read_failed)
20657 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
20658 movq %rax,%rdi
20659 call rwsem_down_write_failed
20660 restore_common_regs
20661 + pax_force_retaddr
20662 ret
20663 CFI_ENDPROC
20664 ENDPROC(call_rwsem_down_write_failed)
20665 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
20666 movq %rax,%rdi
20667 call rwsem_wake
20668 restore_common_regs
20669 -1: ret
20670 +1: pax_force_retaddr
20671 + ret
20672 CFI_ENDPROC
20673 ENDPROC(call_rwsem_wake)
20674
20675 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
20676 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
20677 CFI_RESTORE __ASM_REG(dx)
20678 restore_common_regs
20679 + pax_force_retaddr
20680 ret
20681 CFI_ENDPROC
20682 ENDPROC(call_rwsem_downgrade_wake)
20683 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
20684 index a63efd6..ccecad8 100644
20685 --- a/arch/x86/lib/thunk_64.S
20686 +++ b/arch/x86/lib/thunk_64.S
20687 @@ -8,6 +8,7 @@
20688 #include <linux/linkage.h>
20689 #include <asm/dwarf2.h>
20690 #include <asm/calling.h>
20691 +#include <asm/alternative-asm.h>
20692
20693 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
20694 .macro THUNK name, func, put_ret_addr_in_rdi=0
20695 @@ -41,5 +42,6 @@
20696 SAVE_ARGS
20697 restore:
20698 RESTORE_ARGS
20699 + pax_force_retaddr
20700 ret
20701 CFI_ENDPROC
20702 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
20703 index e218d5d..35679b4 100644
20704 --- a/arch/x86/lib/usercopy_32.c
20705 +++ b/arch/x86/lib/usercopy_32.c
20706 @@ -43,7 +43,7 @@ do { \
20707 __asm__ __volatile__( \
20708 " testl %1,%1\n" \
20709 " jz 2f\n" \
20710 - "0: lodsb\n" \
20711 + "0: "__copyuser_seg"lodsb\n" \
20712 " stosb\n" \
20713 " testb %%al,%%al\n" \
20714 " jz 1f\n" \
20715 @@ -128,10 +128,12 @@ do { \
20716 int __d0; \
20717 might_fault(); \
20718 __asm__ __volatile__( \
20719 + __COPYUSER_SET_ES \
20720 "0: rep; stosl\n" \
20721 " movl %2,%0\n" \
20722 "1: rep; stosb\n" \
20723 "2:\n" \
20724 + __COPYUSER_RESTORE_ES \
20725 ".section .fixup,\"ax\"\n" \
20726 "3: lea 0(%2,%0,4),%0\n" \
20727 " jmp 2b\n" \
20728 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
20729 might_fault();
20730
20731 __asm__ __volatile__(
20732 + __COPYUSER_SET_ES
20733 " testl %0, %0\n"
20734 " jz 3f\n"
20735 " andl %0,%%ecx\n"
20736 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
20737 " subl %%ecx,%0\n"
20738 " addl %0,%%eax\n"
20739 "1:\n"
20740 + __COPYUSER_RESTORE_ES
20741 ".section .fixup,\"ax\"\n"
20742 "2: xorl %%eax,%%eax\n"
20743 " jmp 1b\n"
20744 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
20745
20746 #ifdef CONFIG_X86_INTEL_USERCOPY
20747 static unsigned long
20748 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
20749 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
20750 {
20751 int d0, d1;
20752 __asm__ __volatile__(
20753 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
20754 " .align 2,0x90\n"
20755 "3: movl 0(%4), %%eax\n"
20756 "4: movl 4(%4), %%edx\n"
20757 - "5: movl %%eax, 0(%3)\n"
20758 - "6: movl %%edx, 4(%3)\n"
20759 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
20760 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
20761 "7: movl 8(%4), %%eax\n"
20762 "8: movl 12(%4),%%edx\n"
20763 - "9: movl %%eax, 8(%3)\n"
20764 - "10: movl %%edx, 12(%3)\n"
20765 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
20766 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
20767 "11: movl 16(%4), %%eax\n"
20768 "12: movl 20(%4), %%edx\n"
20769 - "13: movl %%eax, 16(%3)\n"
20770 - "14: movl %%edx, 20(%3)\n"
20771 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
20772 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
20773 "15: movl 24(%4), %%eax\n"
20774 "16: movl 28(%4), %%edx\n"
20775 - "17: movl %%eax, 24(%3)\n"
20776 - "18: movl %%edx, 28(%3)\n"
20777 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
20778 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
20779 "19: movl 32(%4), %%eax\n"
20780 "20: movl 36(%4), %%edx\n"
20781 - "21: movl %%eax, 32(%3)\n"
20782 - "22: movl %%edx, 36(%3)\n"
20783 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
20784 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
20785 "23: movl 40(%4), %%eax\n"
20786 "24: movl 44(%4), %%edx\n"
20787 - "25: movl %%eax, 40(%3)\n"
20788 - "26: movl %%edx, 44(%3)\n"
20789 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
20790 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
20791 "27: movl 48(%4), %%eax\n"
20792 "28: movl 52(%4), %%edx\n"
20793 - "29: movl %%eax, 48(%3)\n"
20794 - "30: movl %%edx, 52(%3)\n"
20795 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
20796 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
20797 "31: movl 56(%4), %%eax\n"
20798 "32: movl 60(%4), %%edx\n"
20799 - "33: movl %%eax, 56(%3)\n"
20800 - "34: movl %%edx, 60(%3)\n"
20801 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
20802 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
20803 " addl $-64, %0\n"
20804 " addl $64, %4\n"
20805 " addl $64, %3\n"
20806 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
20807 " shrl $2, %0\n"
20808 " andl $3, %%eax\n"
20809 " cld\n"
20810 + __COPYUSER_SET_ES
20811 "99: rep; movsl\n"
20812 "36: movl %%eax, %0\n"
20813 "37: rep; movsb\n"
20814 "100:\n"
20815 + __COPYUSER_RESTORE_ES
20816 + ".section .fixup,\"ax\"\n"
20817 + "101: lea 0(%%eax,%0,4),%0\n"
20818 + " jmp 100b\n"
20819 + ".previous\n"
20820 + ".section __ex_table,\"a\"\n"
20821 + " .align 4\n"
20822 + " .long 1b,100b\n"
20823 + " .long 2b,100b\n"
20824 + " .long 3b,100b\n"
20825 + " .long 4b,100b\n"
20826 + " .long 5b,100b\n"
20827 + " .long 6b,100b\n"
20828 + " .long 7b,100b\n"
20829 + " .long 8b,100b\n"
20830 + " .long 9b,100b\n"
20831 + " .long 10b,100b\n"
20832 + " .long 11b,100b\n"
20833 + " .long 12b,100b\n"
20834 + " .long 13b,100b\n"
20835 + " .long 14b,100b\n"
20836 + " .long 15b,100b\n"
20837 + " .long 16b,100b\n"
20838 + " .long 17b,100b\n"
20839 + " .long 18b,100b\n"
20840 + " .long 19b,100b\n"
20841 + " .long 20b,100b\n"
20842 + " .long 21b,100b\n"
20843 + " .long 22b,100b\n"
20844 + " .long 23b,100b\n"
20845 + " .long 24b,100b\n"
20846 + " .long 25b,100b\n"
20847 + " .long 26b,100b\n"
20848 + " .long 27b,100b\n"
20849 + " .long 28b,100b\n"
20850 + " .long 29b,100b\n"
20851 + " .long 30b,100b\n"
20852 + " .long 31b,100b\n"
20853 + " .long 32b,100b\n"
20854 + " .long 33b,100b\n"
20855 + " .long 34b,100b\n"
20856 + " .long 35b,100b\n"
20857 + " .long 36b,100b\n"
20858 + " .long 37b,100b\n"
20859 + " .long 99b,101b\n"
20860 + ".previous"
20861 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
20862 + : "1"(to), "2"(from), "0"(size)
20863 + : "eax", "edx", "memory");
20864 + return size;
20865 +}
20866 +
20867 +static unsigned long
20868 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
20869 +{
20870 + int d0, d1;
20871 + __asm__ __volatile__(
20872 + " .align 2,0x90\n"
20873 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
20874 + " cmpl $67, %0\n"
20875 + " jbe 3f\n"
20876 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
20877 + " .align 2,0x90\n"
20878 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
20879 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
20880 + "5: movl %%eax, 0(%3)\n"
20881 + "6: movl %%edx, 4(%3)\n"
20882 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
20883 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
20884 + "9: movl %%eax, 8(%3)\n"
20885 + "10: movl %%edx, 12(%3)\n"
20886 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
20887 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
20888 + "13: movl %%eax, 16(%3)\n"
20889 + "14: movl %%edx, 20(%3)\n"
20890 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
20891 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
20892 + "17: movl %%eax, 24(%3)\n"
20893 + "18: movl %%edx, 28(%3)\n"
20894 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
20895 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
20896 + "21: movl %%eax, 32(%3)\n"
20897 + "22: movl %%edx, 36(%3)\n"
20898 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
20899 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
20900 + "25: movl %%eax, 40(%3)\n"
20901 + "26: movl %%edx, 44(%3)\n"
20902 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
20903 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
20904 + "29: movl %%eax, 48(%3)\n"
20905 + "30: movl %%edx, 52(%3)\n"
20906 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
20907 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
20908 + "33: movl %%eax, 56(%3)\n"
20909 + "34: movl %%edx, 60(%3)\n"
20910 + " addl $-64, %0\n"
20911 + " addl $64, %4\n"
20912 + " addl $64, %3\n"
20913 + " cmpl $63, %0\n"
20914 + " ja 1b\n"
20915 + "35: movl %0, %%eax\n"
20916 + " shrl $2, %0\n"
20917 + " andl $3, %%eax\n"
20918 + " cld\n"
20919 + "99: rep; "__copyuser_seg" movsl\n"
20920 + "36: movl %%eax, %0\n"
20921 + "37: rep; "__copyuser_seg" movsb\n"
20922 + "100:\n"
20923 ".section .fixup,\"ax\"\n"
20924 "101: lea 0(%%eax,%0,4),%0\n"
20925 " jmp 100b\n"
20926 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
20927 int d0, d1;
20928 __asm__ __volatile__(
20929 " .align 2,0x90\n"
20930 - "0: movl 32(%4), %%eax\n"
20931 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20932 " cmpl $67, %0\n"
20933 " jbe 2f\n"
20934 - "1: movl 64(%4), %%eax\n"
20935 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20936 " .align 2,0x90\n"
20937 - "2: movl 0(%4), %%eax\n"
20938 - "21: movl 4(%4), %%edx\n"
20939 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20940 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20941 " movl %%eax, 0(%3)\n"
20942 " movl %%edx, 4(%3)\n"
20943 - "3: movl 8(%4), %%eax\n"
20944 - "31: movl 12(%4),%%edx\n"
20945 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20946 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20947 " movl %%eax, 8(%3)\n"
20948 " movl %%edx, 12(%3)\n"
20949 - "4: movl 16(%4), %%eax\n"
20950 - "41: movl 20(%4), %%edx\n"
20951 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20952 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20953 " movl %%eax, 16(%3)\n"
20954 " movl %%edx, 20(%3)\n"
20955 - "10: movl 24(%4), %%eax\n"
20956 - "51: movl 28(%4), %%edx\n"
20957 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20958 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20959 " movl %%eax, 24(%3)\n"
20960 " movl %%edx, 28(%3)\n"
20961 - "11: movl 32(%4), %%eax\n"
20962 - "61: movl 36(%4), %%edx\n"
20963 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20964 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20965 " movl %%eax, 32(%3)\n"
20966 " movl %%edx, 36(%3)\n"
20967 - "12: movl 40(%4), %%eax\n"
20968 - "71: movl 44(%4), %%edx\n"
20969 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20970 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20971 " movl %%eax, 40(%3)\n"
20972 " movl %%edx, 44(%3)\n"
20973 - "13: movl 48(%4), %%eax\n"
20974 - "81: movl 52(%4), %%edx\n"
20975 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20976 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20977 " movl %%eax, 48(%3)\n"
20978 " movl %%edx, 52(%3)\n"
20979 - "14: movl 56(%4), %%eax\n"
20980 - "91: movl 60(%4), %%edx\n"
20981 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20982 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20983 " movl %%eax, 56(%3)\n"
20984 " movl %%edx, 60(%3)\n"
20985 " addl $-64, %0\n"
20986 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
20987 " shrl $2, %0\n"
20988 " andl $3, %%eax\n"
20989 " cld\n"
20990 - "6: rep; movsl\n"
20991 + "6: rep; "__copyuser_seg" movsl\n"
20992 " movl %%eax,%0\n"
20993 - "7: rep; movsb\n"
20994 + "7: rep; "__copyuser_seg" movsb\n"
20995 "8:\n"
20996 ".section .fixup,\"ax\"\n"
20997 "9: lea 0(%%eax,%0,4),%0\n"
20998 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
20999
21000 __asm__ __volatile__(
21001 " .align 2,0x90\n"
21002 - "0: movl 32(%4), %%eax\n"
21003 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21004 " cmpl $67, %0\n"
21005 " jbe 2f\n"
21006 - "1: movl 64(%4), %%eax\n"
21007 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21008 " .align 2,0x90\n"
21009 - "2: movl 0(%4), %%eax\n"
21010 - "21: movl 4(%4), %%edx\n"
21011 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21012 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21013 " movnti %%eax, 0(%3)\n"
21014 " movnti %%edx, 4(%3)\n"
21015 - "3: movl 8(%4), %%eax\n"
21016 - "31: movl 12(%4),%%edx\n"
21017 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21018 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21019 " movnti %%eax, 8(%3)\n"
21020 " movnti %%edx, 12(%3)\n"
21021 - "4: movl 16(%4), %%eax\n"
21022 - "41: movl 20(%4), %%edx\n"
21023 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21024 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21025 " movnti %%eax, 16(%3)\n"
21026 " movnti %%edx, 20(%3)\n"
21027 - "10: movl 24(%4), %%eax\n"
21028 - "51: movl 28(%4), %%edx\n"
21029 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21030 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21031 " movnti %%eax, 24(%3)\n"
21032 " movnti %%edx, 28(%3)\n"
21033 - "11: movl 32(%4), %%eax\n"
21034 - "61: movl 36(%4), %%edx\n"
21035 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21036 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21037 " movnti %%eax, 32(%3)\n"
21038 " movnti %%edx, 36(%3)\n"
21039 - "12: movl 40(%4), %%eax\n"
21040 - "71: movl 44(%4), %%edx\n"
21041 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21042 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21043 " movnti %%eax, 40(%3)\n"
21044 " movnti %%edx, 44(%3)\n"
21045 - "13: movl 48(%4), %%eax\n"
21046 - "81: movl 52(%4), %%edx\n"
21047 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21048 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21049 " movnti %%eax, 48(%3)\n"
21050 " movnti %%edx, 52(%3)\n"
21051 - "14: movl 56(%4), %%eax\n"
21052 - "91: movl 60(%4), %%edx\n"
21053 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21054 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21055 " movnti %%eax, 56(%3)\n"
21056 " movnti %%edx, 60(%3)\n"
21057 " addl $-64, %0\n"
21058 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
21059 " shrl $2, %0\n"
21060 " andl $3, %%eax\n"
21061 " cld\n"
21062 - "6: rep; movsl\n"
21063 + "6: rep; "__copyuser_seg" movsl\n"
21064 " movl %%eax,%0\n"
21065 - "7: rep; movsb\n"
21066 + "7: rep; "__copyuser_seg" movsb\n"
21067 "8:\n"
21068 ".section .fixup,\"ax\"\n"
21069 "9: lea 0(%%eax,%0,4),%0\n"
21070 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
21071
21072 __asm__ __volatile__(
21073 " .align 2,0x90\n"
21074 - "0: movl 32(%4), %%eax\n"
21075 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21076 " cmpl $67, %0\n"
21077 " jbe 2f\n"
21078 - "1: movl 64(%4), %%eax\n"
21079 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21080 " .align 2,0x90\n"
21081 - "2: movl 0(%4), %%eax\n"
21082 - "21: movl 4(%4), %%edx\n"
21083 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21084 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21085 " movnti %%eax, 0(%3)\n"
21086 " movnti %%edx, 4(%3)\n"
21087 - "3: movl 8(%4), %%eax\n"
21088 - "31: movl 12(%4),%%edx\n"
21089 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21090 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21091 " movnti %%eax, 8(%3)\n"
21092 " movnti %%edx, 12(%3)\n"
21093 - "4: movl 16(%4), %%eax\n"
21094 - "41: movl 20(%4), %%edx\n"
21095 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21096 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21097 " movnti %%eax, 16(%3)\n"
21098 " movnti %%edx, 20(%3)\n"
21099 - "10: movl 24(%4), %%eax\n"
21100 - "51: movl 28(%4), %%edx\n"
21101 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21102 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21103 " movnti %%eax, 24(%3)\n"
21104 " movnti %%edx, 28(%3)\n"
21105 - "11: movl 32(%4), %%eax\n"
21106 - "61: movl 36(%4), %%edx\n"
21107 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21108 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21109 " movnti %%eax, 32(%3)\n"
21110 " movnti %%edx, 36(%3)\n"
21111 - "12: movl 40(%4), %%eax\n"
21112 - "71: movl 44(%4), %%edx\n"
21113 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21114 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21115 " movnti %%eax, 40(%3)\n"
21116 " movnti %%edx, 44(%3)\n"
21117 - "13: movl 48(%4), %%eax\n"
21118 - "81: movl 52(%4), %%edx\n"
21119 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21120 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21121 " movnti %%eax, 48(%3)\n"
21122 " movnti %%edx, 52(%3)\n"
21123 - "14: movl 56(%4), %%eax\n"
21124 - "91: movl 60(%4), %%edx\n"
21125 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21126 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21127 " movnti %%eax, 56(%3)\n"
21128 " movnti %%edx, 60(%3)\n"
21129 " addl $-64, %0\n"
21130 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
21131 " shrl $2, %0\n"
21132 " andl $3, %%eax\n"
21133 " cld\n"
21134 - "6: rep; movsl\n"
21135 + "6: rep; "__copyuser_seg" movsl\n"
21136 " movl %%eax,%0\n"
21137 - "7: rep; movsb\n"
21138 + "7: rep; "__copyuser_seg" movsb\n"
21139 "8:\n"
21140 ".section .fixup,\"ax\"\n"
21141 "9: lea 0(%%eax,%0,4),%0\n"
21142 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
21143 */
21144 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
21145 unsigned long size);
21146 -unsigned long __copy_user_intel(void __user *to, const void *from,
21147 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
21148 + unsigned long size);
21149 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
21150 unsigned long size);
21151 unsigned long __copy_user_zeroing_intel_nocache(void *to,
21152 const void __user *from, unsigned long size);
21153 #endif /* CONFIG_X86_INTEL_USERCOPY */
21154
21155 /* Generic arbitrary sized copy. */
21156 -#define __copy_user(to, from, size) \
21157 +#define __copy_user(to, from, size, prefix, set, restore) \
21158 do { \
21159 int __d0, __d1, __d2; \
21160 __asm__ __volatile__( \
21161 + set \
21162 " cmp $7,%0\n" \
21163 " jbe 1f\n" \
21164 " movl %1,%0\n" \
21165 " negl %0\n" \
21166 " andl $7,%0\n" \
21167 " subl %0,%3\n" \
21168 - "4: rep; movsb\n" \
21169 + "4: rep; "prefix"movsb\n" \
21170 " movl %3,%0\n" \
21171 " shrl $2,%0\n" \
21172 " andl $3,%3\n" \
21173 " .align 2,0x90\n" \
21174 - "0: rep; movsl\n" \
21175 + "0: rep; "prefix"movsl\n" \
21176 " movl %3,%0\n" \
21177 - "1: rep; movsb\n" \
21178 + "1: rep; "prefix"movsb\n" \
21179 "2:\n" \
21180 + restore \
21181 ".section .fixup,\"ax\"\n" \
21182 "5: addl %3,%0\n" \
21183 " jmp 2b\n" \
21184 @@ -682,14 +799,14 @@ do { \
21185 " negl %0\n" \
21186 " andl $7,%0\n" \
21187 " subl %0,%3\n" \
21188 - "4: rep; movsb\n" \
21189 + "4: rep; "__copyuser_seg"movsb\n" \
21190 " movl %3,%0\n" \
21191 " shrl $2,%0\n" \
21192 " andl $3,%3\n" \
21193 " .align 2,0x90\n" \
21194 - "0: rep; movsl\n" \
21195 + "0: rep; "__copyuser_seg"movsl\n" \
21196 " movl %3,%0\n" \
21197 - "1: rep; movsb\n" \
21198 + "1: rep; "__copyuser_seg"movsb\n" \
21199 "2:\n" \
21200 ".section .fixup,\"ax\"\n" \
21201 "5: addl %3,%0\n" \
21202 @@ -775,9 +892,9 @@ survive:
21203 }
21204 #endif
21205 if (movsl_is_ok(to, from, n))
21206 - __copy_user(to, from, n);
21207 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
21208 else
21209 - n = __copy_user_intel(to, from, n);
21210 + n = __generic_copy_to_user_intel(to, from, n);
21211 return n;
21212 }
21213 EXPORT_SYMBOL(__copy_to_user_ll);
21214 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
21215 unsigned long n)
21216 {
21217 if (movsl_is_ok(to, from, n))
21218 - __copy_user(to, from, n);
21219 + __copy_user(to, from, n, __copyuser_seg, "", "");
21220 else
21221 - n = __copy_user_intel((void __user *)to,
21222 - (const void *)from, n);
21223 + n = __generic_copy_from_user_intel(to, from, n);
21224 return n;
21225 }
21226 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
21227 @@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
21228 if (n > 64 && cpu_has_xmm2)
21229 n = __copy_user_intel_nocache(to, from, n);
21230 else
21231 - __copy_user(to, from, n);
21232 + __copy_user(to, from, n, __copyuser_seg, "", "");
21233 #else
21234 - __copy_user(to, from, n);
21235 + __copy_user(to, from, n, __copyuser_seg, "", "");
21236 #endif
21237 return n;
21238 }
21239 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
21240
21241 -/**
21242 - * copy_to_user: - Copy a block of data into user space.
21243 - * @to: Destination address, in user space.
21244 - * @from: Source address, in kernel space.
21245 - * @n: Number of bytes to copy.
21246 - *
21247 - * Context: User context only. This function may sleep.
21248 - *
21249 - * Copy data from kernel space to user space.
21250 - *
21251 - * Returns number of bytes that could not be copied.
21252 - * On success, this will be zero.
21253 - */
21254 -unsigned long
21255 -copy_to_user(void __user *to, const void *from, unsigned long n)
21256 -{
21257 - if (access_ok(VERIFY_WRITE, to, n))
21258 - n = __copy_to_user(to, from, n);
21259 - return n;
21260 -}
21261 -EXPORT_SYMBOL(copy_to_user);
21262 -
21263 -/**
21264 - * copy_from_user: - Copy a block of data from user space.
21265 - * @to: Destination address, in kernel space.
21266 - * @from: Source address, in user space.
21267 - * @n: Number of bytes to copy.
21268 - *
21269 - * Context: User context only. This function may sleep.
21270 - *
21271 - * Copy data from user space to kernel space.
21272 - *
21273 - * Returns number of bytes that could not be copied.
21274 - * On success, this will be zero.
21275 - *
21276 - * If some data could not be copied, this function will pad the copied
21277 - * data to the requested size using zero bytes.
21278 - */
21279 -unsigned long
21280 -_copy_from_user(void *to, const void __user *from, unsigned long n)
21281 -{
21282 - if (access_ok(VERIFY_READ, from, n))
21283 - n = __copy_from_user(to, from, n);
21284 - else
21285 - memset(to, 0, n);
21286 - return n;
21287 -}
21288 -EXPORT_SYMBOL(_copy_from_user);
21289 -
21290 void copy_from_user_overflow(void)
21291 {
21292 WARN(1, "Buffer overflow detected!\n");
21293 }
21294 EXPORT_SYMBOL(copy_from_user_overflow);
21295 +
21296 +void copy_to_user_overflow(void)
21297 +{
21298 + WARN(1, "Buffer overflow detected!\n");
21299 +}
21300 +EXPORT_SYMBOL(copy_to_user_overflow);
21301 +
21302 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21303 +void __set_fs(mm_segment_t x)
21304 +{
21305 + switch (x.seg) {
21306 + case 0:
21307 + loadsegment(gs, 0);
21308 + break;
21309 + case TASK_SIZE_MAX:
21310 + loadsegment(gs, __USER_DS);
21311 + break;
21312 + case -1UL:
21313 + loadsegment(gs, __KERNEL_DS);
21314 + break;
21315 + default:
21316 + BUG();
21317 + }
21318 + return;
21319 +}
21320 +EXPORT_SYMBOL(__set_fs);
21321 +
21322 +void set_fs(mm_segment_t x)
21323 +{
21324 + current_thread_info()->addr_limit = x;
21325 + __set_fs(x);
21326 +}
21327 +EXPORT_SYMBOL(set_fs);
21328 +#endif
21329 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
21330 index b7c2849..8633ad8 100644
21331 --- a/arch/x86/lib/usercopy_64.c
21332 +++ b/arch/x86/lib/usercopy_64.c
21333 @@ -42,6 +42,12 @@ long
21334 __strncpy_from_user(char *dst, const char __user *src, long count)
21335 {
21336 long res;
21337 +
21338 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21339 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21340 + src += PAX_USER_SHADOW_BASE;
21341 +#endif
21342 +
21343 __do_strncpy_from_user(dst, src, count, res);
21344 return res;
21345 }
21346 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
21347 {
21348 long __d0;
21349 might_fault();
21350 +
21351 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21352 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
21353 + addr += PAX_USER_SHADOW_BASE;
21354 +#endif
21355 +
21356 /* no memory constraint because it doesn't change any memory gcc knows
21357 about */
21358 asm volatile(
21359 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
21360 }
21361 EXPORT_SYMBOL(strlen_user);
21362
21363 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
21364 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
21365 {
21366 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
21367 - return copy_user_generic((__force void *)to, (__force void *)from, len);
21368 - }
21369 - return len;
21370 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
21371 +
21372 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21373 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
21374 + to += PAX_USER_SHADOW_BASE;
21375 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
21376 + from += PAX_USER_SHADOW_BASE;
21377 +#endif
21378 +
21379 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
21380 + }
21381 + return len;
21382 }
21383 EXPORT_SYMBOL(copy_in_user);
21384
21385 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
21386 * it is not necessary to optimize tail handling.
21387 */
21388 unsigned long
21389 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
21390 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
21391 {
21392 char c;
21393 unsigned zero_len;
21394 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
21395 index d0474ad..36e9257 100644
21396 --- a/arch/x86/mm/extable.c
21397 +++ b/arch/x86/mm/extable.c
21398 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
21399 const struct exception_table_entry *fixup;
21400
21401 #ifdef CONFIG_PNPBIOS
21402 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
21403 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
21404 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
21405 extern u32 pnp_bios_is_utter_crap;
21406 pnp_bios_is_utter_crap = 1;
21407 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
21408 index 0d17c8c..c5d9925 100644
21409 --- a/arch/x86/mm/fault.c
21410 +++ b/arch/x86/mm/fault.c
21411 @@ -13,11 +13,18 @@
21412 #include <linux/perf_event.h> /* perf_sw_event */
21413 #include <linux/hugetlb.h> /* hstate_index_to_shift */
21414 #include <linux/prefetch.h> /* prefetchw */
21415 +#include <linux/unistd.h>
21416 +#include <linux/compiler.h>
21417
21418 #include <asm/traps.h> /* dotraplinkage, ... */
21419 #include <asm/pgalloc.h> /* pgd_*(), ... */
21420 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
21421 #include <asm/vsyscall.h>
21422 +#include <asm/tlbflush.h>
21423 +
21424 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21425 +#include <asm/stacktrace.h>
21426 +#endif
21427
21428 /*
21429 * Page fault error code bits:
21430 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
21431 int ret = 0;
21432
21433 /* kprobe_running() needs smp_processor_id() */
21434 - if (kprobes_built_in() && !user_mode_vm(regs)) {
21435 + if (kprobes_built_in() && !user_mode(regs)) {
21436 preempt_disable();
21437 if (kprobe_running() && kprobe_fault_handler(regs, 14))
21438 ret = 1;
21439 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
21440 return !instr_lo || (instr_lo>>1) == 1;
21441 case 0x00:
21442 /* Prefetch instruction is 0x0F0D or 0x0F18 */
21443 - if (probe_kernel_address(instr, opcode))
21444 + if (user_mode(regs)) {
21445 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
21446 + return 0;
21447 + } else if (probe_kernel_address(instr, opcode))
21448 return 0;
21449
21450 *prefetch = (instr_lo == 0xF) &&
21451 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
21452 while (instr < max_instr) {
21453 unsigned char opcode;
21454
21455 - if (probe_kernel_address(instr, opcode))
21456 + if (user_mode(regs)) {
21457 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
21458 + break;
21459 + } else if (probe_kernel_address(instr, opcode))
21460 break;
21461
21462 instr++;
21463 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
21464 force_sig_info(si_signo, &info, tsk);
21465 }
21466
21467 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21468 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
21469 +#endif
21470 +
21471 +#ifdef CONFIG_PAX_EMUTRAMP
21472 +static int pax_handle_fetch_fault(struct pt_regs *regs);
21473 +#endif
21474 +
21475 +#ifdef CONFIG_PAX_PAGEEXEC
21476 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
21477 +{
21478 + pgd_t *pgd;
21479 + pud_t *pud;
21480 + pmd_t *pmd;
21481 +
21482 + pgd = pgd_offset(mm, address);
21483 + if (!pgd_present(*pgd))
21484 + return NULL;
21485 + pud = pud_offset(pgd, address);
21486 + if (!pud_present(*pud))
21487 + return NULL;
21488 + pmd = pmd_offset(pud, address);
21489 + if (!pmd_present(*pmd))
21490 + return NULL;
21491 + return pmd;
21492 +}
21493 +#endif
21494 +
21495 DEFINE_SPINLOCK(pgd_lock);
21496 LIST_HEAD(pgd_list);
21497
21498 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
21499 for (address = VMALLOC_START & PMD_MASK;
21500 address >= TASK_SIZE && address < FIXADDR_TOP;
21501 address += PMD_SIZE) {
21502 +
21503 +#ifdef CONFIG_PAX_PER_CPU_PGD
21504 + unsigned long cpu;
21505 +#else
21506 struct page *page;
21507 +#endif
21508
21509 spin_lock(&pgd_lock);
21510 +
21511 +#ifdef CONFIG_PAX_PER_CPU_PGD
21512 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
21513 + pgd_t *pgd = get_cpu_pgd(cpu);
21514 + pmd_t *ret;
21515 +#else
21516 list_for_each_entry(page, &pgd_list, lru) {
21517 + pgd_t *pgd = page_address(page);
21518 spinlock_t *pgt_lock;
21519 pmd_t *ret;
21520
21521 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
21522 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
21523
21524 spin_lock(pgt_lock);
21525 - ret = vmalloc_sync_one(page_address(page), address);
21526 +#endif
21527 +
21528 + ret = vmalloc_sync_one(pgd, address);
21529 +
21530 +#ifndef CONFIG_PAX_PER_CPU_PGD
21531 spin_unlock(pgt_lock);
21532 +#endif
21533
21534 if (!ret)
21535 break;
21536 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
21537 * an interrupt in the middle of a task switch..
21538 */
21539 pgd_paddr = read_cr3();
21540 +
21541 +#ifdef CONFIG_PAX_PER_CPU_PGD
21542 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
21543 +#endif
21544 +
21545 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
21546 if (!pmd_k)
21547 return -1;
21548 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
21549 * happen within a race in page table update. In the later
21550 * case just flush:
21551 */
21552 +
21553 +#ifdef CONFIG_PAX_PER_CPU_PGD
21554 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
21555 + pgd = pgd_offset_cpu(smp_processor_id(), address);
21556 +#else
21557 pgd = pgd_offset(current->active_mm, address);
21558 +#endif
21559 +
21560 pgd_ref = pgd_offset_k(address);
21561 if (pgd_none(*pgd_ref))
21562 return -1;
21563 @@ -534,7 +604,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
21564 static int is_errata100(struct pt_regs *regs, unsigned long address)
21565 {
21566 #ifdef CONFIG_X86_64
21567 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
21568 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
21569 return 1;
21570 #endif
21571 return 0;
21572 @@ -561,7 +631,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
21573 }
21574
21575 static const char nx_warning[] = KERN_CRIT
21576 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
21577 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
21578
21579 static void
21580 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21581 @@ -570,15 +640,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21582 if (!oops_may_print())
21583 return;
21584
21585 - if (error_code & PF_INSTR) {
21586 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
21587 unsigned int level;
21588
21589 pte_t *pte = lookup_address(address, &level);
21590
21591 if (pte && pte_present(*pte) && !pte_exec(*pte))
21592 - printk(nx_warning, current_uid());
21593 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
21594 }
21595
21596 +#ifdef CONFIG_PAX_KERNEXEC
21597 + if (init_mm.start_code <= address && address < init_mm.end_code) {
21598 + if (current->signal->curr_ip)
21599 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21600 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
21601 + else
21602 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21603 + current->comm, task_pid_nr(current), current_uid(), current_euid());
21604 + }
21605 +#endif
21606 +
21607 printk(KERN_ALERT "BUG: unable to handle kernel ");
21608 if (address < PAGE_SIZE)
21609 printk(KERN_CONT "NULL pointer dereference");
21610 @@ -733,6 +814,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
21611 }
21612 #endif
21613
21614 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21615 + if (pax_is_fetch_fault(regs, error_code, address)) {
21616 +
21617 +#ifdef CONFIG_PAX_EMUTRAMP
21618 + switch (pax_handle_fetch_fault(regs)) {
21619 + case 2:
21620 + return;
21621 + }
21622 +#endif
21623 +
21624 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21625 + do_group_exit(SIGKILL);
21626 + }
21627 +#endif
21628 +
21629 if (unlikely(show_unhandled_signals))
21630 show_signal_msg(regs, error_code, address, tsk);
21631
21632 @@ -829,7 +925,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
21633 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
21634 printk(KERN_ERR
21635 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
21636 - tsk->comm, tsk->pid, address);
21637 + tsk->comm, task_pid_nr(tsk), address);
21638 code = BUS_MCEERR_AR;
21639 }
21640 #endif
21641 @@ -884,6 +980,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
21642 return 1;
21643 }
21644
21645 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21646 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
21647 +{
21648 + pte_t *pte;
21649 + pmd_t *pmd;
21650 + spinlock_t *ptl;
21651 + unsigned char pte_mask;
21652 +
21653 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
21654 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
21655 + return 0;
21656 +
21657 + /* PaX: it's our fault, let's handle it if we can */
21658 +
21659 + /* PaX: take a look at read faults before acquiring any locks */
21660 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
21661 + /* instruction fetch attempt from a protected page in user mode */
21662 + up_read(&mm->mmap_sem);
21663 +
21664 +#ifdef CONFIG_PAX_EMUTRAMP
21665 + switch (pax_handle_fetch_fault(regs)) {
21666 + case 2:
21667 + return 1;
21668 + }
21669 +#endif
21670 +
21671 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21672 + do_group_exit(SIGKILL);
21673 + }
21674 +
21675 + pmd = pax_get_pmd(mm, address);
21676 + if (unlikely(!pmd))
21677 + return 0;
21678 +
21679 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
21680 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
21681 + pte_unmap_unlock(pte, ptl);
21682 + return 0;
21683 + }
21684 +
21685 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
21686 + /* write attempt to a protected page in user mode */
21687 + pte_unmap_unlock(pte, ptl);
21688 + return 0;
21689 + }
21690 +
21691 +#ifdef CONFIG_SMP
21692 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
21693 +#else
21694 + if (likely(address > get_limit(regs->cs)))
21695 +#endif
21696 + {
21697 + set_pte(pte, pte_mkread(*pte));
21698 + __flush_tlb_one(address);
21699 + pte_unmap_unlock(pte, ptl);
21700 + up_read(&mm->mmap_sem);
21701 + return 1;
21702 + }
21703 +
21704 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
21705 +
21706 + /*
21707 + * PaX: fill DTLB with user rights and retry
21708 + */
21709 + __asm__ __volatile__ (
21710 + "orb %2,(%1)\n"
21711 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
21712 +/*
21713 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
21714 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
21715 + * page fault when examined during a TLB load attempt. this is true not only
21716 + * for PTEs holding a non-present entry but also present entries that will
21717 + * raise a page fault (such as those set up by PaX, or the copy-on-write
21718 + * mechanism). in effect it means that we do *not* need to flush the TLBs
21719 + * for our target pages since their PTEs are simply not in the TLBs at all.
21720 +
21721 + * the best thing in omitting it is that we gain around 15-20% speed in the
21722 + * fast path of the page fault handler and can get rid of tracing since we
21723 + * can no longer flush unintended entries.
21724 + */
21725 + "invlpg (%0)\n"
21726 +#endif
21727 + __copyuser_seg"testb $0,(%0)\n"
21728 + "xorb %3,(%1)\n"
21729 + :
21730 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
21731 + : "memory", "cc");
21732 + pte_unmap_unlock(pte, ptl);
21733 + up_read(&mm->mmap_sem);
21734 + return 1;
21735 +}
21736 +#endif
21737 +
21738 /*
21739 * Handle a spurious fault caused by a stale TLB entry.
21740 *
21741 @@ -956,6 +1145,9 @@ int show_unhandled_signals = 1;
21742 static inline int
21743 access_error(unsigned long error_code, struct vm_area_struct *vma)
21744 {
21745 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
21746 + return 1;
21747 +
21748 if (error_code & PF_WRITE) {
21749 /* write, present and write, not present: */
21750 if (unlikely(!(vma->vm_flags & VM_WRITE)))
21751 @@ -989,18 +1181,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
21752 {
21753 struct vm_area_struct *vma;
21754 struct task_struct *tsk;
21755 - unsigned long address;
21756 struct mm_struct *mm;
21757 int fault;
21758 int write = error_code & PF_WRITE;
21759 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
21760 (write ? FAULT_FLAG_WRITE : 0);
21761
21762 - tsk = current;
21763 - mm = tsk->mm;
21764 -
21765 /* Get the faulting address: */
21766 - address = read_cr2();
21767 + unsigned long address = read_cr2();
21768 +
21769 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21770 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
21771 + if (!search_exception_tables(regs->ip)) {
21772 + bad_area_nosemaphore(regs, error_code, address);
21773 + return;
21774 + }
21775 + if (address < PAX_USER_SHADOW_BASE) {
21776 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
21777 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
21778 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
21779 + } else
21780 + address -= PAX_USER_SHADOW_BASE;
21781 + }
21782 +#endif
21783 +
21784 + tsk = current;
21785 + mm = tsk->mm;
21786
21787 /*
21788 * Detect and handle instructions that would cause a page fault for
21789 @@ -1061,7 +1267,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
21790 * User-mode registers count as a user access even for any
21791 * potential system fault or CPU buglet:
21792 */
21793 - if (user_mode_vm(regs)) {
21794 + if (user_mode(regs)) {
21795 local_irq_enable();
21796 error_code |= PF_USER;
21797 } else {
21798 @@ -1116,6 +1322,11 @@ retry:
21799 might_sleep();
21800 }
21801
21802 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21803 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
21804 + return;
21805 +#endif
21806 +
21807 vma = find_vma(mm, address);
21808 if (unlikely(!vma)) {
21809 bad_area(regs, error_code, address);
21810 @@ -1127,18 +1338,24 @@ retry:
21811 bad_area(regs, error_code, address);
21812 return;
21813 }
21814 - if (error_code & PF_USER) {
21815 - /*
21816 - * Accessing the stack below %sp is always a bug.
21817 - * The large cushion allows instructions like enter
21818 - * and pusha to work. ("enter $65535, $31" pushes
21819 - * 32 pointers and then decrements %sp by 65535.)
21820 - */
21821 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
21822 - bad_area(regs, error_code, address);
21823 - return;
21824 - }
21825 + /*
21826 + * Accessing the stack below %sp is always a bug.
21827 + * The large cushion allows instructions like enter
21828 + * and pusha to work. ("enter $65535, $31" pushes
21829 + * 32 pointers and then decrements %sp by 65535.)
21830 + */
21831 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
21832 + bad_area(regs, error_code, address);
21833 + return;
21834 }
21835 +
21836 +#ifdef CONFIG_PAX_SEGMEXEC
21837 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
21838 + bad_area(regs, error_code, address);
21839 + return;
21840 + }
21841 +#endif
21842 +
21843 if (unlikely(expand_stack(vma, address))) {
21844 bad_area(regs, error_code, address);
21845 return;
21846 @@ -1193,3 +1410,292 @@ good_area:
21847
21848 up_read(&mm->mmap_sem);
21849 }
21850 +
21851 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21852 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
21853 +{
21854 + struct mm_struct *mm = current->mm;
21855 + unsigned long ip = regs->ip;
21856 +
21857 + if (v8086_mode(regs))
21858 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
21859 +
21860 +#ifdef CONFIG_PAX_PAGEEXEC
21861 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
21862 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
21863 + return true;
21864 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
21865 + return true;
21866 + return false;
21867 + }
21868 +#endif
21869 +
21870 +#ifdef CONFIG_PAX_SEGMEXEC
21871 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
21872 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
21873 + return true;
21874 + return false;
21875 + }
21876 +#endif
21877 +
21878 + return false;
21879 +}
21880 +#endif
21881 +
21882 +#ifdef CONFIG_PAX_EMUTRAMP
21883 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
21884 +{
21885 + int err;
21886 +
21887 + do { /* PaX: libffi trampoline emulation */
21888 + unsigned char mov, jmp;
21889 + unsigned int addr1, addr2;
21890 +
21891 +#ifdef CONFIG_X86_64
21892 + if ((regs->ip + 9) >> 32)
21893 + break;
21894 +#endif
21895 +
21896 + err = get_user(mov, (unsigned char __user *)regs->ip);
21897 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21898 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21899 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21900 +
21901 + if (err)
21902 + break;
21903 +
21904 + if (mov == 0xB8 && jmp == 0xE9) {
21905 + regs->ax = addr1;
21906 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21907 + return 2;
21908 + }
21909 + } while (0);
21910 +
21911 + do { /* PaX: gcc trampoline emulation #1 */
21912 + unsigned char mov1, mov2;
21913 + unsigned short jmp;
21914 + unsigned int addr1, addr2;
21915 +
21916 +#ifdef CONFIG_X86_64
21917 + if ((regs->ip + 11) >> 32)
21918 + break;
21919 +#endif
21920 +
21921 + err = get_user(mov1, (unsigned char __user *)regs->ip);
21922 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21923 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
21924 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21925 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
21926 +
21927 + if (err)
21928 + break;
21929 +
21930 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
21931 + regs->cx = addr1;
21932 + regs->ax = addr2;
21933 + regs->ip = addr2;
21934 + return 2;
21935 + }
21936 + } while (0);
21937 +
21938 + do { /* PaX: gcc trampoline emulation #2 */
21939 + unsigned char mov, jmp;
21940 + unsigned int addr1, addr2;
21941 +
21942 +#ifdef CONFIG_X86_64
21943 + if ((regs->ip + 9) >> 32)
21944 + break;
21945 +#endif
21946 +
21947 + err = get_user(mov, (unsigned char __user *)regs->ip);
21948 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21949 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21950 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21951 +
21952 + if (err)
21953 + break;
21954 +
21955 + if (mov == 0xB9 && jmp == 0xE9) {
21956 + regs->cx = addr1;
21957 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21958 + return 2;
21959 + }
21960 + } while (0);
21961 +
21962 + return 1; /* PaX in action */
21963 +}
21964 +
21965 +#ifdef CONFIG_X86_64
21966 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
21967 +{
21968 + int err;
21969 +
21970 + do { /* PaX: libffi trampoline emulation */
21971 + unsigned short mov1, mov2, jmp1;
21972 + unsigned char stcclc, jmp2;
21973 + unsigned long addr1, addr2;
21974 +
21975 + err = get_user(mov1, (unsigned short __user *)regs->ip);
21976 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
21977 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
21978 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
21979 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
21980 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
21981 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
21982 +
21983 + if (err)
21984 + break;
21985 +
21986 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21987 + regs->r11 = addr1;
21988 + regs->r10 = addr2;
21989 + if (stcclc == 0xF8)
21990 + regs->flags &= ~X86_EFLAGS_CF;
21991 + else
21992 + regs->flags |= X86_EFLAGS_CF;
21993 + regs->ip = addr1;
21994 + return 2;
21995 + }
21996 + } while (0);
21997 +
21998 + do { /* PaX: gcc trampoline emulation #1 */
21999 + unsigned short mov1, mov2, jmp1;
22000 + unsigned char jmp2;
22001 + unsigned int addr1;
22002 + unsigned long addr2;
22003 +
22004 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22005 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
22006 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
22007 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
22008 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
22009 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
22010 +
22011 + if (err)
22012 + break;
22013 +
22014 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22015 + regs->r11 = addr1;
22016 + regs->r10 = addr2;
22017 + regs->ip = addr1;
22018 + return 2;
22019 + }
22020 + } while (0);
22021 +
22022 + do { /* PaX: gcc trampoline emulation #2 */
22023 + unsigned short mov1, mov2, jmp1;
22024 + unsigned char jmp2;
22025 + unsigned long addr1, addr2;
22026 +
22027 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22028 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
22029 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
22030 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
22031 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
22032 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
22033 +
22034 + if (err)
22035 + break;
22036 +
22037 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22038 + regs->r11 = addr1;
22039 + regs->r10 = addr2;
22040 + regs->ip = addr1;
22041 + return 2;
22042 + }
22043 + } while (0);
22044 +
22045 + return 1; /* PaX in action */
22046 +}
22047 +#endif
22048 +
22049 +/*
22050 + * PaX: decide what to do with offenders (regs->ip = fault address)
22051 + *
22052 + * returns 1 when task should be killed
22053 + * 2 when gcc trampoline was detected
22054 + */
22055 +static int pax_handle_fetch_fault(struct pt_regs *regs)
22056 +{
22057 + if (v8086_mode(regs))
22058 + return 1;
22059 +
22060 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
22061 + return 1;
22062 +
22063 +#ifdef CONFIG_X86_32
22064 + return pax_handle_fetch_fault_32(regs);
22065 +#else
22066 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
22067 + return pax_handle_fetch_fault_32(regs);
22068 + else
22069 + return pax_handle_fetch_fault_64(regs);
22070 +#endif
22071 +}
22072 +#endif
22073 +
22074 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22075 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
22076 +{
22077 + long i;
22078 +
22079 + printk(KERN_ERR "PAX: bytes at PC: ");
22080 + for (i = 0; i < 20; i++) {
22081 + unsigned char c;
22082 + if (get_user(c, (unsigned char __force_user *)pc+i))
22083 + printk(KERN_CONT "?? ");
22084 + else
22085 + printk(KERN_CONT "%02x ", c);
22086 + }
22087 + printk("\n");
22088 +
22089 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
22090 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
22091 + unsigned long c;
22092 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
22093 +#ifdef CONFIG_X86_32
22094 + printk(KERN_CONT "???????? ");
22095 +#else
22096 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
22097 + printk(KERN_CONT "???????? ???????? ");
22098 + else
22099 + printk(KERN_CONT "???????????????? ");
22100 +#endif
22101 + } else {
22102 +#ifdef CONFIG_X86_64
22103 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
22104 + printk(KERN_CONT "%08x ", (unsigned int)c);
22105 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
22106 + } else
22107 +#endif
22108 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
22109 + }
22110 + }
22111 + printk("\n");
22112 +}
22113 +#endif
22114 +
22115 +/**
22116 + * probe_kernel_write(): safely attempt to write to a location
22117 + * @dst: address to write to
22118 + * @src: pointer to the data that shall be written
22119 + * @size: size of the data chunk
22120 + *
22121 + * Safely write to address @dst from the buffer at @src. If a kernel fault
22122 + * happens, handle that and return -EFAULT.
22123 + */
22124 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
22125 +{
22126 + long ret;
22127 + mm_segment_t old_fs = get_fs();
22128 +
22129 + set_fs(KERNEL_DS);
22130 + pagefault_disable();
22131 + pax_open_kernel();
22132 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
22133 + pax_close_kernel();
22134 + pagefault_enable();
22135 + set_fs(old_fs);
22136 +
22137 + return ret ? -EFAULT : 0;
22138 +}
22139 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
22140 index dd74e46..7d26398 100644
22141 --- a/arch/x86/mm/gup.c
22142 +++ b/arch/x86/mm/gup.c
22143 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
22144 addr = start;
22145 len = (unsigned long) nr_pages << PAGE_SHIFT;
22146 end = start + len;
22147 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
22148 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
22149 (void __user *)start, len)))
22150 return 0;
22151
22152 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
22153 index f4f29b1..5cac4fb 100644
22154 --- a/arch/x86/mm/highmem_32.c
22155 +++ b/arch/x86/mm/highmem_32.c
22156 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
22157 idx = type + KM_TYPE_NR*smp_processor_id();
22158 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22159 BUG_ON(!pte_none(*(kmap_pte-idx)));
22160 +
22161 + pax_open_kernel();
22162 set_pte(kmap_pte-idx, mk_pte(page, prot));
22163 + pax_close_kernel();
22164 +
22165 arch_flush_lazy_mmu_mode();
22166
22167 return (void *)vaddr;
22168 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
22169 index f581a18..29efd37 100644
22170 --- a/arch/x86/mm/hugetlbpage.c
22171 +++ b/arch/x86/mm/hugetlbpage.c
22172 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
22173 struct hstate *h = hstate_file(file);
22174 struct mm_struct *mm = current->mm;
22175 struct vm_area_struct *vma;
22176 - unsigned long start_addr;
22177 + unsigned long start_addr, pax_task_size = TASK_SIZE;
22178 +
22179 +#ifdef CONFIG_PAX_SEGMEXEC
22180 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22181 + pax_task_size = SEGMEXEC_TASK_SIZE;
22182 +#endif
22183 +
22184 + pax_task_size -= PAGE_SIZE;
22185
22186 if (len > mm->cached_hole_size) {
22187 - start_addr = mm->free_area_cache;
22188 + start_addr = mm->free_area_cache;
22189 } else {
22190 - start_addr = TASK_UNMAPPED_BASE;
22191 - mm->cached_hole_size = 0;
22192 + start_addr = mm->mmap_base;
22193 + mm->cached_hole_size = 0;
22194 }
22195
22196 full_search:
22197 @@ -280,26 +287,27 @@ full_search:
22198
22199 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22200 /* At this point: (!vma || addr < vma->vm_end). */
22201 - if (TASK_SIZE - len < addr) {
22202 + if (pax_task_size - len < addr) {
22203 /*
22204 * Start a new search - just in case we missed
22205 * some holes.
22206 */
22207 - if (start_addr != TASK_UNMAPPED_BASE) {
22208 - start_addr = TASK_UNMAPPED_BASE;
22209 + if (start_addr != mm->mmap_base) {
22210 + start_addr = mm->mmap_base;
22211 mm->cached_hole_size = 0;
22212 goto full_search;
22213 }
22214 return -ENOMEM;
22215 }
22216 - if (!vma || addr + len <= vma->vm_start) {
22217 - mm->free_area_cache = addr + len;
22218 - return addr;
22219 - }
22220 + if (check_heap_stack_gap(vma, addr, len))
22221 + break;
22222 if (addr + mm->cached_hole_size < vma->vm_start)
22223 mm->cached_hole_size = vma->vm_start - addr;
22224 addr = ALIGN(vma->vm_end, huge_page_size(h));
22225 }
22226 +
22227 + mm->free_area_cache = addr + len;
22228 + return addr;
22229 }
22230
22231 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22232 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22233 {
22234 struct hstate *h = hstate_file(file);
22235 struct mm_struct *mm = current->mm;
22236 - struct vm_area_struct *vma, *prev_vma;
22237 - unsigned long base = mm->mmap_base, addr = addr0;
22238 + struct vm_area_struct *vma;
22239 + unsigned long base = mm->mmap_base, addr;
22240 unsigned long largest_hole = mm->cached_hole_size;
22241 - int first_time = 1;
22242
22243 /* don't allow allocations above current base */
22244 if (mm->free_area_cache > base)
22245 @@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22246 largest_hole = 0;
22247 mm->free_area_cache = base;
22248 }
22249 -try_again:
22250 +
22251 /* make sure it can fit in the remaining address space */
22252 if (mm->free_area_cache < len)
22253 goto fail;
22254
22255 /* either no address requested or can't fit in requested address hole */
22256 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
22257 + addr = (mm->free_area_cache - len);
22258 do {
22259 + addr &= huge_page_mask(h);
22260 + vma = find_vma(mm, addr);
22261 /*
22262 * Lookup failure means no vma is above this address,
22263 * i.e. return with success:
22264 - */
22265 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
22266 - return addr;
22267 -
22268 - /*
22269 * new region fits between prev_vma->vm_end and
22270 * vma->vm_start, use it:
22271 */
22272 - if (addr + len <= vma->vm_start &&
22273 - (!prev_vma || (addr >= prev_vma->vm_end))) {
22274 + if (check_heap_stack_gap(vma, addr, len)) {
22275 /* remember the address as a hint for next time */
22276 - mm->cached_hole_size = largest_hole;
22277 - return (mm->free_area_cache = addr);
22278 - } else {
22279 - /* pull free_area_cache down to the first hole */
22280 - if (mm->free_area_cache == vma->vm_end) {
22281 - mm->free_area_cache = vma->vm_start;
22282 - mm->cached_hole_size = largest_hole;
22283 - }
22284 + mm->cached_hole_size = largest_hole;
22285 + return (mm->free_area_cache = addr);
22286 + }
22287 + /* pull free_area_cache down to the first hole */
22288 + if (mm->free_area_cache == vma->vm_end) {
22289 + mm->free_area_cache = vma->vm_start;
22290 + mm->cached_hole_size = largest_hole;
22291 }
22292
22293 /* remember the largest hole we saw so far */
22294 if (addr + largest_hole < vma->vm_start)
22295 - largest_hole = vma->vm_start - addr;
22296 + largest_hole = vma->vm_start - addr;
22297
22298 /* try just below the current vma->vm_start */
22299 - addr = (vma->vm_start - len) & huge_page_mask(h);
22300 - } while (len <= vma->vm_start);
22301 + addr = skip_heap_stack_gap(vma, len);
22302 + } while (!IS_ERR_VALUE(addr));
22303
22304 fail:
22305 /*
22306 - * if hint left us with no space for the requested
22307 - * mapping then try again:
22308 - */
22309 - if (first_time) {
22310 - mm->free_area_cache = base;
22311 - largest_hole = 0;
22312 - first_time = 0;
22313 - goto try_again;
22314 - }
22315 - /*
22316 * A failed mmap() very likely causes application failure,
22317 * so fall back to the bottom-up function here. This scenario
22318 * can happen with large stack limits and large mmap()
22319 * allocations.
22320 */
22321 - mm->free_area_cache = TASK_UNMAPPED_BASE;
22322 +
22323 +#ifdef CONFIG_PAX_SEGMEXEC
22324 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22325 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22326 + else
22327 +#endif
22328 +
22329 + mm->mmap_base = TASK_UNMAPPED_BASE;
22330 +
22331 +#ifdef CONFIG_PAX_RANDMMAP
22332 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22333 + mm->mmap_base += mm->delta_mmap;
22334 +#endif
22335 +
22336 + mm->free_area_cache = mm->mmap_base;
22337 mm->cached_hole_size = ~0UL;
22338 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
22339 len, pgoff, flags);
22340 @@ -386,6 +392,7 @@ fail:
22341 /*
22342 * Restore the topdown base:
22343 */
22344 + mm->mmap_base = base;
22345 mm->free_area_cache = base;
22346 mm->cached_hole_size = ~0UL;
22347
22348 @@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
22349 struct hstate *h = hstate_file(file);
22350 struct mm_struct *mm = current->mm;
22351 struct vm_area_struct *vma;
22352 + unsigned long pax_task_size = TASK_SIZE;
22353
22354 if (len & ~huge_page_mask(h))
22355 return -EINVAL;
22356 - if (len > TASK_SIZE)
22357 +
22358 +#ifdef CONFIG_PAX_SEGMEXEC
22359 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22360 + pax_task_size = SEGMEXEC_TASK_SIZE;
22361 +#endif
22362 +
22363 + pax_task_size -= PAGE_SIZE;
22364 +
22365 + if (len > pax_task_size)
22366 return -ENOMEM;
22367
22368 if (flags & MAP_FIXED) {
22369 @@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
22370 if (addr) {
22371 addr = ALIGN(addr, huge_page_size(h));
22372 vma = find_vma(mm, addr);
22373 - if (TASK_SIZE - len >= addr &&
22374 - (!vma || addr + len <= vma->vm_start))
22375 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
22376 return addr;
22377 }
22378 if (mm->get_unmapped_area == arch_get_unmapped_area)
22379 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
22380 index 87488b9..7129f32 100644
22381 --- a/arch/x86/mm/init.c
22382 +++ b/arch/x86/mm/init.c
22383 @@ -31,7 +31,7 @@ int direct_gbpages
22384 static void __init find_early_table_space(unsigned long end, int use_pse,
22385 int use_gbpages)
22386 {
22387 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
22388 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
22389 phys_addr_t base;
22390
22391 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
22392 @@ -312,8 +312,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
22393 */
22394 int devmem_is_allowed(unsigned long pagenr)
22395 {
22396 +#ifdef CONFIG_GRKERNSEC_KMEM
22397 + /* allow BDA */
22398 + if (!pagenr)
22399 + return 1;
22400 + /* allow EBDA */
22401 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
22402 + return 1;
22403 +#else
22404 + if (!pagenr)
22405 + return 1;
22406 +#ifdef CONFIG_VM86
22407 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
22408 + return 1;
22409 +#endif
22410 +#endif
22411 +
22412 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22413 + return 1;
22414 +#ifdef CONFIG_GRKERNSEC_KMEM
22415 + /* throw out everything else below 1MB */
22416 if (pagenr <= 256)
22417 - return 1;
22418 + return 0;
22419 +#endif
22420 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
22421 return 0;
22422 if (!page_is_ram(pagenr))
22423 @@ -372,6 +393,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
22424
22425 void free_initmem(void)
22426 {
22427 +
22428 +#ifdef CONFIG_PAX_KERNEXEC
22429 +#ifdef CONFIG_X86_32
22430 + /* PaX: limit KERNEL_CS to actual size */
22431 + unsigned long addr, limit;
22432 + struct desc_struct d;
22433 + int cpu;
22434 +
22435 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
22436 + limit = (limit - 1UL) >> PAGE_SHIFT;
22437 +
22438 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
22439 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
22440 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
22441 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
22442 + }
22443 +
22444 + /* PaX: make KERNEL_CS read-only */
22445 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
22446 + if (!paravirt_enabled())
22447 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
22448 +/*
22449 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
22450 + pgd = pgd_offset_k(addr);
22451 + pud = pud_offset(pgd, addr);
22452 + pmd = pmd_offset(pud, addr);
22453 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22454 + }
22455 +*/
22456 +#ifdef CONFIG_X86_PAE
22457 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
22458 +/*
22459 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
22460 + pgd = pgd_offset_k(addr);
22461 + pud = pud_offset(pgd, addr);
22462 + pmd = pmd_offset(pud, addr);
22463 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22464 + }
22465 +*/
22466 +#endif
22467 +
22468 +#ifdef CONFIG_MODULES
22469 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
22470 +#endif
22471 +
22472 +#else
22473 + pgd_t *pgd;
22474 + pud_t *pud;
22475 + pmd_t *pmd;
22476 + unsigned long addr, end;
22477 +
22478 + /* PaX: make kernel code/rodata read-only, rest non-executable */
22479 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
22480 + pgd = pgd_offset_k(addr);
22481 + pud = pud_offset(pgd, addr);
22482 + pmd = pmd_offset(pud, addr);
22483 + if (!pmd_present(*pmd))
22484 + continue;
22485 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
22486 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22487 + else
22488 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22489 + }
22490 +
22491 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
22492 + end = addr + KERNEL_IMAGE_SIZE;
22493 + for (; addr < end; addr += PMD_SIZE) {
22494 + pgd = pgd_offset_k(addr);
22495 + pud = pud_offset(pgd, addr);
22496 + pmd = pmd_offset(pud, addr);
22497 + if (!pmd_present(*pmd))
22498 + continue;
22499 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
22500 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22501 + }
22502 +#endif
22503 +
22504 + flush_tlb_all();
22505 +#endif
22506 +
22507 free_init_pages("unused kernel memory",
22508 (unsigned long)(&__init_begin),
22509 (unsigned long)(&__init_end));
22510 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
22511 index 29f7c6d..b46b35b 100644
22512 --- a/arch/x86/mm/init_32.c
22513 +++ b/arch/x86/mm/init_32.c
22514 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
22515 }
22516
22517 /*
22518 - * Creates a middle page table and puts a pointer to it in the
22519 - * given global directory entry. This only returns the gd entry
22520 - * in non-PAE compilation mode, since the middle layer is folded.
22521 - */
22522 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
22523 -{
22524 - pud_t *pud;
22525 - pmd_t *pmd_table;
22526 -
22527 -#ifdef CONFIG_X86_PAE
22528 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
22529 - if (after_bootmem)
22530 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
22531 - else
22532 - pmd_table = (pmd_t *)alloc_low_page();
22533 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
22534 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
22535 - pud = pud_offset(pgd, 0);
22536 - BUG_ON(pmd_table != pmd_offset(pud, 0));
22537 -
22538 - return pmd_table;
22539 - }
22540 -#endif
22541 - pud = pud_offset(pgd, 0);
22542 - pmd_table = pmd_offset(pud, 0);
22543 -
22544 - return pmd_table;
22545 -}
22546 -
22547 -/*
22548 * Create a page table and place a pointer to it in a middle page
22549 * directory entry:
22550 */
22551 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
22552 page_table = (pte_t *)alloc_low_page();
22553
22554 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
22555 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22556 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
22557 +#else
22558 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
22559 +#endif
22560 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
22561 }
22562
22563 return pte_offset_kernel(pmd, 0);
22564 }
22565
22566 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
22567 +{
22568 + pud_t *pud;
22569 + pmd_t *pmd_table;
22570 +
22571 + pud = pud_offset(pgd, 0);
22572 + pmd_table = pmd_offset(pud, 0);
22573 +
22574 + return pmd_table;
22575 +}
22576 +
22577 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
22578 {
22579 int pgd_idx = pgd_index(vaddr);
22580 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22581 int pgd_idx, pmd_idx;
22582 unsigned long vaddr;
22583 pgd_t *pgd;
22584 + pud_t *pud;
22585 pmd_t *pmd;
22586 pte_t *pte = NULL;
22587
22588 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22589 pgd = pgd_base + pgd_idx;
22590
22591 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
22592 - pmd = one_md_table_init(pgd);
22593 - pmd = pmd + pmd_index(vaddr);
22594 + pud = pud_offset(pgd, vaddr);
22595 + pmd = pmd_offset(pud, vaddr);
22596 +
22597 +#ifdef CONFIG_X86_PAE
22598 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22599 +#endif
22600 +
22601 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
22602 pmd++, pmd_idx++) {
22603 pte = page_table_kmap_check(one_page_table_init(pmd),
22604 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22605 }
22606 }
22607
22608 -static inline int is_kernel_text(unsigned long addr)
22609 +static inline int is_kernel_text(unsigned long start, unsigned long end)
22610 {
22611 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
22612 - return 1;
22613 - return 0;
22614 + if ((start > ktla_ktva((unsigned long)_etext) ||
22615 + end <= ktla_ktva((unsigned long)_stext)) &&
22616 + (start > ktla_ktva((unsigned long)_einittext) ||
22617 + end <= ktla_ktva((unsigned long)_sinittext)) &&
22618 +
22619 +#ifdef CONFIG_ACPI_SLEEP
22620 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
22621 +#endif
22622 +
22623 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
22624 + return 0;
22625 + return 1;
22626 }
22627
22628 /*
22629 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
22630 unsigned long last_map_addr = end;
22631 unsigned long start_pfn, end_pfn;
22632 pgd_t *pgd_base = swapper_pg_dir;
22633 - int pgd_idx, pmd_idx, pte_ofs;
22634 + unsigned int pgd_idx, pmd_idx, pte_ofs;
22635 unsigned long pfn;
22636 pgd_t *pgd;
22637 + pud_t *pud;
22638 pmd_t *pmd;
22639 pte_t *pte;
22640 unsigned pages_2m, pages_4k;
22641 @@ -281,8 +282,13 @@ repeat:
22642 pfn = start_pfn;
22643 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22644 pgd = pgd_base + pgd_idx;
22645 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
22646 - pmd = one_md_table_init(pgd);
22647 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
22648 + pud = pud_offset(pgd, 0);
22649 + pmd = pmd_offset(pud, 0);
22650 +
22651 +#ifdef CONFIG_X86_PAE
22652 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22653 +#endif
22654
22655 if (pfn >= end_pfn)
22656 continue;
22657 @@ -294,14 +300,13 @@ repeat:
22658 #endif
22659 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
22660 pmd++, pmd_idx++) {
22661 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
22662 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
22663
22664 /*
22665 * Map with big pages if possible, otherwise
22666 * create normal page tables:
22667 */
22668 if (use_pse) {
22669 - unsigned int addr2;
22670 pgprot_t prot = PAGE_KERNEL_LARGE;
22671 /*
22672 * first pass will use the same initial
22673 @@ -311,11 +316,7 @@ repeat:
22674 __pgprot(PTE_IDENT_ATTR |
22675 _PAGE_PSE);
22676
22677 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
22678 - PAGE_OFFSET + PAGE_SIZE-1;
22679 -
22680 - if (is_kernel_text(addr) ||
22681 - is_kernel_text(addr2))
22682 + if (is_kernel_text(address, address + PMD_SIZE))
22683 prot = PAGE_KERNEL_LARGE_EXEC;
22684
22685 pages_2m++;
22686 @@ -332,7 +333,7 @@ repeat:
22687 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22688 pte += pte_ofs;
22689 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
22690 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
22691 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
22692 pgprot_t prot = PAGE_KERNEL;
22693 /*
22694 * first pass will use the same initial
22695 @@ -340,7 +341,7 @@ repeat:
22696 */
22697 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
22698
22699 - if (is_kernel_text(addr))
22700 + if (is_kernel_text(address, address + PAGE_SIZE))
22701 prot = PAGE_KERNEL_EXEC;
22702
22703 pages_4k++;
22704 @@ -472,7 +473,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
22705
22706 pud = pud_offset(pgd, va);
22707 pmd = pmd_offset(pud, va);
22708 - if (!pmd_present(*pmd))
22709 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
22710 break;
22711
22712 pte = pte_offset_kernel(pmd, va);
22713 @@ -524,12 +525,10 @@ void __init early_ioremap_page_table_range_init(void)
22714
22715 static void __init pagetable_init(void)
22716 {
22717 - pgd_t *pgd_base = swapper_pg_dir;
22718 -
22719 - permanent_kmaps_init(pgd_base);
22720 + permanent_kmaps_init(swapper_pg_dir);
22721 }
22722
22723 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22724 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22725 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22726
22727 /* user-defined highmem size */
22728 @@ -757,6 +756,12 @@ void __init mem_init(void)
22729
22730 pci_iommu_alloc();
22731
22732 +#ifdef CONFIG_PAX_PER_CPU_PGD
22733 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22734 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22735 + KERNEL_PGD_PTRS);
22736 +#endif
22737 +
22738 #ifdef CONFIG_FLATMEM
22739 BUG_ON(!mem_map);
22740 #endif
22741 @@ -774,7 +779,7 @@ void __init mem_init(void)
22742 set_highmem_pages_init();
22743
22744 codesize = (unsigned long) &_etext - (unsigned long) &_text;
22745 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
22746 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
22747 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
22748
22749 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
22750 @@ -815,10 +820,10 @@ void __init mem_init(void)
22751 ((unsigned long)&__init_end -
22752 (unsigned long)&__init_begin) >> 10,
22753
22754 - (unsigned long)&_etext, (unsigned long)&_edata,
22755 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
22756 + (unsigned long)&_sdata, (unsigned long)&_edata,
22757 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
22758
22759 - (unsigned long)&_text, (unsigned long)&_etext,
22760 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
22761 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
22762
22763 /*
22764 @@ -896,6 +901,7 @@ void set_kernel_text_rw(void)
22765 if (!kernel_set_to_readonly)
22766 return;
22767
22768 + start = ktla_ktva(start);
22769 pr_debug("Set kernel text: %lx - %lx for read write\n",
22770 start, start+size);
22771
22772 @@ -910,6 +916,7 @@ void set_kernel_text_ro(void)
22773 if (!kernel_set_to_readonly)
22774 return;
22775
22776 + start = ktla_ktva(start);
22777 pr_debug("Set kernel text: %lx - %lx for read only\n",
22778 start, start+size);
22779
22780 @@ -938,6 +945,7 @@ void mark_rodata_ro(void)
22781 unsigned long start = PFN_ALIGN(_text);
22782 unsigned long size = PFN_ALIGN(_etext) - start;
22783
22784 + start = ktla_ktva(start);
22785 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
22786 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
22787 size >> 10);
22788 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
22789 index bbaaa00..16dffad 100644
22790 --- a/arch/x86/mm/init_64.c
22791 +++ b/arch/x86/mm/init_64.c
22792 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
22793 * around without checking the pgd every time.
22794 */
22795
22796 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
22797 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
22798 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22799
22800 int force_personality32;
22801 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
22802
22803 for (address = start; address <= end; address += PGDIR_SIZE) {
22804 const pgd_t *pgd_ref = pgd_offset_k(address);
22805 +
22806 +#ifdef CONFIG_PAX_PER_CPU_PGD
22807 + unsigned long cpu;
22808 +#else
22809 struct page *page;
22810 +#endif
22811
22812 if (pgd_none(*pgd_ref))
22813 continue;
22814
22815 spin_lock(&pgd_lock);
22816 +
22817 +#ifdef CONFIG_PAX_PER_CPU_PGD
22818 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22819 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
22820 +#else
22821 list_for_each_entry(page, &pgd_list, lru) {
22822 pgd_t *pgd;
22823 spinlock_t *pgt_lock;
22824 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
22825 /* the pgt_lock only for Xen */
22826 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
22827 spin_lock(pgt_lock);
22828 +#endif
22829
22830 if (pgd_none(*pgd))
22831 set_pgd(pgd, *pgd_ref);
22832 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
22833 BUG_ON(pgd_page_vaddr(*pgd)
22834 != pgd_page_vaddr(*pgd_ref));
22835
22836 +#ifndef CONFIG_PAX_PER_CPU_PGD
22837 spin_unlock(pgt_lock);
22838 +#endif
22839 +
22840 }
22841 spin_unlock(&pgd_lock);
22842 }
22843 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
22844 pmd = fill_pmd(pud, vaddr);
22845 pte = fill_pte(pmd, vaddr);
22846
22847 + pax_open_kernel();
22848 set_pte(pte, new_pte);
22849 + pax_close_kernel();
22850
22851 /*
22852 * It's enough to flush this one mapping.
22853 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
22854 pgd = pgd_offset_k((unsigned long)__va(phys));
22855 if (pgd_none(*pgd)) {
22856 pud = (pud_t *) spp_getpage();
22857 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
22858 - _PAGE_USER));
22859 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
22860 }
22861 pud = pud_offset(pgd, (unsigned long)__va(phys));
22862 if (pud_none(*pud)) {
22863 pmd = (pmd_t *) spp_getpage();
22864 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
22865 - _PAGE_USER));
22866 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
22867 }
22868 pmd = pmd_offset(pud, phys);
22869 BUG_ON(!pmd_none(*pmd));
22870 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
22871 if (pfn >= pgt_buf_top)
22872 panic("alloc_low_page: ran out of memory");
22873
22874 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
22875 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
22876 clear_page(adr);
22877 *phys = pfn * PAGE_SIZE;
22878 return adr;
22879 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
22880
22881 phys = __pa(virt);
22882 left = phys & (PAGE_SIZE - 1);
22883 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
22884 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
22885 adr = (void *)(((unsigned long)adr) | left);
22886
22887 return adr;
22888 @@ -693,6 +707,12 @@ void __init mem_init(void)
22889
22890 pci_iommu_alloc();
22891
22892 +#ifdef CONFIG_PAX_PER_CPU_PGD
22893 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22894 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22895 + KERNEL_PGD_PTRS);
22896 +#endif
22897 +
22898 /* clear_bss() already clear the empty_zero_page */
22899
22900 reservedpages = 0;
22901 @@ -853,8 +873,8 @@ int kern_addr_valid(unsigned long addr)
22902 static struct vm_area_struct gate_vma = {
22903 .vm_start = VSYSCALL_START,
22904 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
22905 - .vm_page_prot = PAGE_READONLY_EXEC,
22906 - .vm_flags = VM_READ | VM_EXEC
22907 + .vm_page_prot = PAGE_READONLY,
22908 + .vm_flags = VM_READ
22909 };
22910
22911 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
22912 @@ -888,7 +908,7 @@ int in_gate_area_no_mm(unsigned long addr)
22913
22914 const char *arch_vma_name(struct vm_area_struct *vma)
22915 {
22916 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
22917 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
22918 return "[vdso]";
22919 if (vma == &gate_vma)
22920 return "[vsyscall]";
22921 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
22922 index 7b179b4..6bd1777 100644
22923 --- a/arch/x86/mm/iomap_32.c
22924 +++ b/arch/x86/mm/iomap_32.c
22925 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
22926 type = kmap_atomic_idx_push();
22927 idx = type + KM_TYPE_NR * smp_processor_id();
22928 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22929 +
22930 + pax_open_kernel();
22931 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
22932 + pax_close_kernel();
22933 +
22934 arch_flush_lazy_mmu_mode();
22935
22936 return (void *)vaddr;
22937 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
22938 index be1ef57..9680edc 100644
22939 --- a/arch/x86/mm/ioremap.c
22940 +++ b/arch/x86/mm/ioremap.c
22941 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
22942 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
22943 int is_ram = page_is_ram(pfn);
22944
22945 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
22946 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
22947 return NULL;
22948 WARN_ON_ONCE(is_ram);
22949 }
22950 @@ -344,7 +344,7 @@ static int __init early_ioremap_debug_setup(char *str)
22951 early_param("early_ioremap_debug", early_ioremap_debug_setup);
22952
22953 static __initdata int after_paging_init;
22954 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
22955 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
22956
22957 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
22958 {
22959 @@ -381,8 +381,7 @@ void __init early_ioremap_init(void)
22960 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
22961
22962 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
22963 - memset(bm_pte, 0, sizeof(bm_pte));
22964 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
22965 + pmd_populate_user(&init_mm, pmd, bm_pte);
22966
22967 /*
22968 * The boot-ioremap range spans multiple pmds, for which
22969 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
22970 index d87dd6d..bf3fa66 100644
22971 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
22972 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
22973 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
22974 * memory (e.g. tracked pages)? For now, we need this to avoid
22975 * invoking kmemcheck for PnP BIOS calls.
22976 */
22977 - if (regs->flags & X86_VM_MASK)
22978 + if (v8086_mode(regs))
22979 return false;
22980 - if (regs->cs != __KERNEL_CS)
22981 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
22982 return false;
22983
22984 pte = kmemcheck_pte_lookup(address);
22985 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
22986 index 1dab519..60a7e5f 100644
22987 --- a/arch/x86/mm/mmap.c
22988 +++ b/arch/x86/mm/mmap.c
22989 @@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size(void)
22990 * Leave an at least ~128 MB hole with possible stack randomization.
22991 */
22992 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
22993 -#define MAX_GAP (TASK_SIZE/6*5)
22994 +#define MAX_GAP (pax_task_size/6*5)
22995
22996 /*
22997 * True on X86_32 or when emulating IA32 on X86_64
22998 @@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
22999 return rnd << PAGE_SHIFT;
23000 }
23001
23002 -static unsigned long mmap_base(void)
23003 +static unsigned long mmap_base(struct mm_struct *mm)
23004 {
23005 unsigned long gap = rlimit(RLIMIT_STACK);
23006 + unsigned long pax_task_size = TASK_SIZE;
23007 +
23008 +#ifdef CONFIG_PAX_SEGMEXEC
23009 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23010 + pax_task_size = SEGMEXEC_TASK_SIZE;
23011 +#endif
23012
23013 if (gap < MIN_GAP)
23014 gap = MIN_GAP;
23015 else if (gap > MAX_GAP)
23016 gap = MAX_GAP;
23017
23018 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
23019 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
23020 }
23021
23022 /*
23023 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
23024 * does, but not when emulating X86_32
23025 */
23026 -static unsigned long mmap_legacy_base(void)
23027 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
23028 {
23029 - if (mmap_is_ia32())
23030 + if (mmap_is_ia32()) {
23031 +
23032 +#ifdef CONFIG_PAX_SEGMEXEC
23033 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23034 + return SEGMEXEC_TASK_UNMAPPED_BASE;
23035 + else
23036 +#endif
23037 +
23038 return TASK_UNMAPPED_BASE;
23039 - else
23040 + } else
23041 return TASK_UNMAPPED_BASE + mmap_rnd();
23042 }
23043
23044 @@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(void)
23045 void arch_pick_mmap_layout(struct mm_struct *mm)
23046 {
23047 if (mmap_is_legacy()) {
23048 - mm->mmap_base = mmap_legacy_base();
23049 + mm->mmap_base = mmap_legacy_base(mm);
23050 +
23051 +#ifdef CONFIG_PAX_RANDMMAP
23052 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23053 + mm->mmap_base += mm->delta_mmap;
23054 +#endif
23055 +
23056 mm->get_unmapped_area = arch_get_unmapped_area;
23057 mm->unmap_area = arch_unmap_area;
23058 } else {
23059 - mm->mmap_base = mmap_base();
23060 + mm->mmap_base = mmap_base(mm);
23061 +
23062 +#ifdef CONFIG_PAX_RANDMMAP
23063 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23064 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
23065 +#endif
23066 +
23067 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
23068 mm->unmap_area = arch_unmap_area_topdown;
23069 }
23070 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
23071 index 67421f3..8d6b107 100644
23072 --- a/arch/x86/mm/mmio-mod.c
23073 +++ b/arch/x86/mm/mmio-mod.c
23074 @@ -195,7 +195,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
23075 break;
23076 default:
23077 {
23078 - unsigned char *ip = (unsigned char *)instptr;
23079 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
23080 my_trace->opcode = MMIO_UNKNOWN_OP;
23081 my_trace->width = 0;
23082 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
23083 @@ -235,7 +235,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
23084 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
23085 void __iomem *addr)
23086 {
23087 - static atomic_t next_id;
23088 + static atomic_unchecked_t next_id;
23089 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
23090 /* These are page-unaligned. */
23091 struct mmiotrace_map map = {
23092 @@ -259,7 +259,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
23093 .private = trace
23094 },
23095 .phys = offset,
23096 - .id = atomic_inc_return(&next_id)
23097 + .id = atomic_inc_return_unchecked(&next_id)
23098 };
23099 map.map_id = trace->id;
23100
23101 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
23102 index b008656..773eac2 100644
23103 --- a/arch/x86/mm/pageattr-test.c
23104 +++ b/arch/x86/mm/pageattr-test.c
23105 @@ -36,7 +36,7 @@ enum {
23106
23107 static int pte_testbit(pte_t pte)
23108 {
23109 - return pte_flags(pte) & _PAGE_UNUSED1;
23110 + return pte_flags(pte) & _PAGE_CPA_TEST;
23111 }
23112
23113 struct split_state {
23114 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
23115 index f9e5267..6f6e27f 100644
23116 --- a/arch/x86/mm/pageattr.c
23117 +++ b/arch/x86/mm/pageattr.c
23118 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23119 */
23120 #ifdef CONFIG_PCI_BIOS
23121 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
23122 - pgprot_val(forbidden) |= _PAGE_NX;
23123 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23124 #endif
23125
23126 /*
23127 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23128 * Does not cover __inittext since that is gone later on. On
23129 * 64bit we do not enforce !NX on the low mapping
23130 */
23131 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
23132 - pgprot_val(forbidden) |= _PAGE_NX;
23133 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
23134 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23135
23136 +#ifdef CONFIG_DEBUG_RODATA
23137 /*
23138 * The .rodata section needs to be read-only. Using the pfn
23139 * catches all aliases.
23140 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23141 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
23142 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
23143 pgprot_val(forbidden) |= _PAGE_RW;
23144 +#endif
23145
23146 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
23147 /*
23148 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23149 }
23150 #endif
23151
23152 +#ifdef CONFIG_PAX_KERNEXEC
23153 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
23154 + pgprot_val(forbidden) |= _PAGE_RW;
23155 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23156 + }
23157 +#endif
23158 +
23159 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
23160
23161 return prot;
23162 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
23163 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
23164 {
23165 /* change init_mm */
23166 + pax_open_kernel();
23167 set_pte_atomic(kpte, pte);
23168 +
23169 #ifdef CONFIG_X86_32
23170 if (!SHARED_KERNEL_PMD) {
23171 +
23172 +#ifdef CONFIG_PAX_PER_CPU_PGD
23173 + unsigned long cpu;
23174 +#else
23175 struct page *page;
23176 +#endif
23177
23178 +#ifdef CONFIG_PAX_PER_CPU_PGD
23179 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
23180 + pgd_t *pgd = get_cpu_pgd(cpu);
23181 +#else
23182 list_for_each_entry(page, &pgd_list, lru) {
23183 - pgd_t *pgd;
23184 + pgd_t *pgd = (pgd_t *)page_address(page);
23185 +#endif
23186 +
23187 pud_t *pud;
23188 pmd_t *pmd;
23189
23190 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
23191 + pgd += pgd_index(address);
23192 pud = pud_offset(pgd, address);
23193 pmd = pmd_offset(pud, address);
23194 set_pte_atomic((pte_t *)pmd, pte);
23195 }
23196 }
23197 #endif
23198 + pax_close_kernel();
23199 }
23200
23201 static int
23202 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
23203 index f6ff57b..481690f 100644
23204 --- a/arch/x86/mm/pat.c
23205 +++ b/arch/x86/mm/pat.c
23206 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
23207
23208 if (!entry) {
23209 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
23210 - current->comm, current->pid, start, end);
23211 + current->comm, task_pid_nr(current), start, end);
23212 return -EINVAL;
23213 }
23214
23215 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
23216 while (cursor < to) {
23217 if (!devmem_is_allowed(pfn)) {
23218 printk(KERN_INFO
23219 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
23220 - current->comm, from, to);
23221 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
23222 + current->comm, from, to, cursor);
23223 return 0;
23224 }
23225 cursor += PAGE_SIZE;
23226 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
23227 printk(KERN_INFO
23228 "%s:%d ioremap_change_attr failed %s "
23229 "for %Lx-%Lx\n",
23230 - current->comm, current->pid,
23231 + current->comm, task_pid_nr(current),
23232 cattr_name(flags),
23233 base, (unsigned long long)(base + size));
23234 return -EINVAL;
23235 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
23236 if (want_flags != flags) {
23237 printk(KERN_WARNING
23238 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
23239 - current->comm, current->pid,
23240 + current->comm, task_pid_nr(current),
23241 cattr_name(want_flags),
23242 (unsigned long long)paddr,
23243 (unsigned long long)(paddr + size),
23244 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
23245 free_memtype(paddr, paddr + size);
23246 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
23247 " for %Lx-%Lx, got %s\n",
23248 - current->comm, current->pid,
23249 + current->comm, task_pid_nr(current),
23250 cattr_name(want_flags),
23251 (unsigned long long)paddr,
23252 (unsigned long long)(paddr + size),
23253 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
23254 index 9f0614d..92ae64a 100644
23255 --- a/arch/x86/mm/pf_in.c
23256 +++ b/arch/x86/mm/pf_in.c
23257 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
23258 int i;
23259 enum reason_type rv = OTHERS;
23260
23261 - p = (unsigned char *)ins_addr;
23262 + p = (unsigned char *)ktla_ktva(ins_addr);
23263 p += skip_prefix(p, &prf);
23264 p += get_opcode(p, &opcode);
23265
23266 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
23267 struct prefix_bits prf;
23268 int i;
23269
23270 - p = (unsigned char *)ins_addr;
23271 + p = (unsigned char *)ktla_ktva(ins_addr);
23272 p += skip_prefix(p, &prf);
23273 p += get_opcode(p, &opcode);
23274
23275 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
23276 struct prefix_bits prf;
23277 int i;
23278
23279 - p = (unsigned char *)ins_addr;
23280 + p = (unsigned char *)ktla_ktva(ins_addr);
23281 p += skip_prefix(p, &prf);
23282 p += get_opcode(p, &opcode);
23283
23284 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
23285 struct prefix_bits prf;
23286 int i;
23287
23288 - p = (unsigned char *)ins_addr;
23289 + p = (unsigned char *)ktla_ktva(ins_addr);
23290 p += skip_prefix(p, &prf);
23291 p += get_opcode(p, &opcode);
23292 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
23293 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
23294 struct prefix_bits prf;
23295 int i;
23296
23297 - p = (unsigned char *)ins_addr;
23298 + p = (unsigned char *)ktla_ktva(ins_addr);
23299 p += skip_prefix(p, &prf);
23300 p += get_opcode(p, &opcode);
23301 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
23302 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
23303 index 8573b83..6372501 100644
23304 --- a/arch/x86/mm/pgtable.c
23305 +++ b/arch/x86/mm/pgtable.c
23306 @@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *pgd)
23307 list_del(&page->lru);
23308 }
23309
23310 -#define UNSHARED_PTRS_PER_PGD \
23311 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
23312 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23313 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
23314
23315 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
23316 +{
23317 + while (count--)
23318 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
23319 +}
23320 +#endif
23321
23322 +#ifdef CONFIG_PAX_PER_CPU_PGD
23323 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
23324 +{
23325 + while (count--)
23326 +
23327 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23328 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
23329 +#else
23330 + *dst++ = *src++;
23331 +#endif
23332 +
23333 +}
23334 +#endif
23335 +
23336 +#ifdef CONFIG_X86_64
23337 +#define pxd_t pud_t
23338 +#define pyd_t pgd_t
23339 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
23340 +#define pxd_free(mm, pud) pud_free((mm), (pud))
23341 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
23342 +#define pyd_offset(mm ,address) pgd_offset((mm), (address))
23343 +#define PYD_SIZE PGDIR_SIZE
23344 +#else
23345 +#define pxd_t pmd_t
23346 +#define pyd_t pud_t
23347 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
23348 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
23349 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
23350 +#define pyd_offset(mm ,address) pud_offset((mm), (address))
23351 +#define PYD_SIZE PUD_SIZE
23352 +#endif
23353 +
23354 +#ifdef CONFIG_PAX_PER_CPU_PGD
23355 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
23356 +static inline void pgd_dtor(pgd_t *pgd) {}
23357 +#else
23358 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
23359 {
23360 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
23361 @@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
23362 pgd_list_del(pgd);
23363 spin_unlock(&pgd_lock);
23364 }
23365 +#endif
23366
23367 /*
23368 * List of all pgd's needed for non-PAE so it can invalidate entries
23369 @@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
23370 * -- wli
23371 */
23372
23373 -#ifdef CONFIG_X86_PAE
23374 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
23375 /*
23376 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
23377 * updating the top-level pagetable entries to guarantee the
23378 @@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
23379 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
23380 * and initialize the kernel pmds here.
23381 */
23382 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
23383 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
23384
23385 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
23386 {
23387 @@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
23388 */
23389 flush_tlb_mm(mm);
23390 }
23391 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
23392 +#define PREALLOCATED_PXDS USER_PGD_PTRS
23393 #else /* !CONFIG_X86_PAE */
23394
23395 /* No need to prepopulate any pagetable entries in non-PAE modes. */
23396 -#define PREALLOCATED_PMDS 0
23397 +#define PREALLOCATED_PXDS 0
23398
23399 #endif /* CONFIG_X86_PAE */
23400
23401 -static void free_pmds(pmd_t *pmds[])
23402 +static void free_pxds(pxd_t *pxds[])
23403 {
23404 int i;
23405
23406 - for(i = 0; i < PREALLOCATED_PMDS; i++)
23407 - if (pmds[i])
23408 - free_page((unsigned long)pmds[i]);
23409 + for(i = 0; i < PREALLOCATED_PXDS; i++)
23410 + if (pxds[i])
23411 + free_page((unsigned long)pxds[i]);
23412 }
23413
23414 -static int preallocate_pmds(pmd_t *pmds[])
23415 +static int preallocate_pxds(pxd_t *pxds[])
23416 {
23417 int i;
23418 bool failed = false;
23419
23420 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
23421 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
23422 - if (pmd == NULL)
23423 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
23424 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
23425 + if (pxd == NULL)
23426 failed = true;
23427 - pmds[i] = pmd;
23428 + pxds[i] = pxd;
23429 }
23430
23431 if (failed) {
23432 - free_pmds(pmds);
23433 + free_pxds(pxds);
23434 return -ENOMEM;
23435 }
23436
23437 @@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[])
23438 * preallocate which never got a corresponding vma will need to be
23439 * freed manually.
23440 */
23441 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
23442 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
23443 {
23444 int i;
23445
23446 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
23447 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
23448 pgd_t pgd = pgdp[i];
23449
23450 if (pgd_val(pgd) != 0) {
23451 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
23452 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
23453
23454 - pgdp[i] = native_make_pgd(0);
23455 + set_pgd(pgdp + i, native_make_pgd(0));
23456
23457 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
23458 - pmd_free(mm, pmd);
23459 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
23460 + pxd_free(mm, pxd);
23461 }
23462 }
23463 }
23464
23465 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
23466 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
23467 {
23468 - pud_t *pud;
23469 + pyd_t *pyd;
23470 unsigned long addr;
23471 int i;
23472
23473 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
23474 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
23475 return;
23476
23477 - pud = pud_offset(pgd, 0);
23478 +#ifdef CONFIG_X86_64
23479 + pyd = pyd_offset(mm, 0L);
23480 +#else
23481 + pyd = pyd_offset(pgd, 0L);
23482 +#endif
23483
23484 - for (addr = i = 0; i < PREALLOCATED_PMDS;
23485 - i++, pud++, addr += PUD_SIZE) {
23486 - pmd_t *pmd = pmds[i];
23487 + for (addr = i = 0; i < PREALLOCATED_PXDS;
23488 + i++, pyd++, addr += PYD_SIZE) {
23489 + pxd_t *pxd = pxds[i];
23490
23491 if (i >= KERNEL_PGD_BOUNDARY)
23492 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23493 - sizeof(pmd_t) * PTRS_PER_PMD);
23494 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23495 + sizeof(pxd_t) * PTRS_PER_PMD);
23496
23497 - pud_populate(mm, pud, pmd);
23498 + pyd_populate(mm, pyd, pxd);
23499 }
23500 }
23501
23502 pgd_t *pgd_alloc(struct mm_struct *mm)
23503 {
23504 pgd_t *pgd;
23505 - pmd_t *pmds[PREALLOCATED_PMDS];
23506 + pxd_t *pxds[PREALLOCATED_PXDS];
23507
23508 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
23509
23510 @@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23511
23512 mm->pgd = pgd;
23513
23514 - if (preallocate_pmds(pmds) != 0)
23515 + if (preallocate_pxds(pxds) != 0)
23516 goto out_free_pgd;
23517
23518 if (paravirt_pgd_alloc(mm) != 0)
23519 - goto out_free_pmds;
23520 + goto out_free_pxds;
23521
23522 /*
23523 * Make sure that pre-populating the pmds is atomic with
23524 @@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23525 spin_lock(&pgd_lock);
23526
23527 pgd_ctor(mm, pgd);
23528 - pgd_prepopulate_pmd(mm, pgd, pmds);
23529 + pgd_prepopulate_pxd(mm, pgd, pxds);
23530
23531 spin_unlock(&pgd_lock);
23532
23533 return pgd;
23534
23535 -out_free_pmds:
23536 - free_pmds(pmds);
23537 +out_free_pxds:
23538 + free_pxds(pxds);
23539 out_free_pgd:
23540 free_page((unsigned long)pgd);
23541 out:
23542 @@ -295,7 +344,7 @@ out:
23543
23544 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
23545 {
23546 - pgd_mop_up_pmds(mm, pgd);
23547 + pgd_mop_up_pxds(mm, pgd);
23548 pgd_dtor(pgd);
23549 paravirt_pgd_free(mm, pgd);
23550 free_page((unsigned long)pgd);
23551 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
23552 index cac7184..09a39fa 100644
23553 --- a/arch/x86/mm/pgtable_32.c
23554 +++ b/arch/x86/mm/pgtable_32.c
23555 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
23556 return;
23557 }
23558 pte = pte_offset_kernel(pmd, vaddr);
23559 +
23560 + pax_open_kernel();
23561 if (pte_val(pteval))
23562 set_pte_at(&init_mm, vaddr, pte, pteval);
23563 else
23564 pte_clear(&init_mm, vaddr, pte);
23565 + pax_close_kernel();
23566
23567 /*
23568 * It's enough to flush this one mapping.
23569 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
23570 index 410531d..0f16030 100644
23571 --- a/arch/x86/mm/setup_nx.c
23572 +++ b/arch/x86/mm/setup_nx.c
23573 @@ -5,8 +5,10 @@
23574 #include <asm/pgtable.h>
23575 #include <asm/proto.h>
23576
23577 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23578 static int disable_nx __cpuinitdata;
23579
23580 +#ifndef CONFIG_PAX_PAGEEXEC
23581 /*
23582 * noexec = on|off
23583 *
23584 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
23585 return 0;
23586 }
23587 early_param("noexec", noexec_setup);
23588 +#endif
23589 +
23590 +#endif
23591
23592 void __cpuinit x86_configure_nx(void)
23593 {
23594 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23595 if (cpu_has_nx && !disable_nx)
23596 __supported_pte_mask |= _PAGE_NX;
23597 else
23598 +#endif
23599 __supported_pte_mask &= ~_PAGE_NX;
23600 }
23601
23602 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
23603 index d6c0418..06a0ad5 100644
23604 --- a/arch/x86/mm/tlb.c
23605 +++ b/arch/x86/mm/tlb.c
23606 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
23607 BUG();
23608 cpumask_clear_cpu(cpu,
23609 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
23610 +
23611 +#ifndef CONFIG_PAX_PER_CPU_PGD
23612 load_cr3(swapper_pg_dir);
23613 +#endif
23614 +
23615 }
23616 EXPORT_SYMBOL_GPL(leave_mm);
23617
23618 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
23619 index 6687022..ceabcfa 100644
23620 --- a/arch/x86/net/bpf_jit.S
23621 +++ b/arch/x86/net/bpf_jit.S
23622 @@ -9,6 +9,7 @@
23623 */
23624 #include <linux/linkage.h>
23625 #include <asm/dwarf2.h>
23626 +#include <asm/alternative-asm.h>
23627
23628 /*
23629 * Calling convention :
23630 @@ -35,6 +36,7 @@ sk_load_word:
23631 jle bpf_slow_path_word
23632 mov (SKBDATA,%rsi),%eax
23633 bswap %eax /* ntohl() */
23634 + pax_force_retaddr
23635 ret
23636
23637
23638 @@ -53,6 +55,7 @@ sk_load_half:
23639 jle bpf_slow_path_half
23640 movzwl (SKBDATA,%rsi),%eax
23641 rol $8,%ax # ntohs()
23642 + pax_force_retaddr
23643 ret
23644
23645 sk_load_byte_ind:
23646 @@ -66,6 +69,7 @@ sk_load_byte:
23647 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
23648 jle bpf_slow_path_byte
23649 movzbl (SKBDATA,%rsi),%eax
23650 + pax_force_retaddr
23651 ret
23652
23653 /**
23654 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
23655 movzbl (SKBDATA,%rsi),%ebx
23656 and $15,%bl
23657 shl $2,%bl
23658 + pax_force_retaddr
23659 ret
23660 CFI_ENDPROC
23661 ENDPROC(sk_load_byte_msh)
23662 @@ -91,6 +96,7 @@ bpf_error:
23663 xor %eax,%eax
23664 mov -8(%rbp),%rbx
23665 leaveq
23666 + pax_force_retaddr
23667 ret
23668
23669 /* rsi contains offset and can be scratched */
23670 @@ -113,6 +119,7 @@ bpf_slow_path_word:
23671 js bpf_error
23672 mov -12(%rbp),%eax
23673 bswap %eax
23674 + pax_force_retaddr
23675 ret
23676
23677 bpf_slow_path_half:
23678 @@ -121,12 +128,14 @@ bpf_slow_path_half:
23679 mov -12(%rbp),%ax
23680 rol $8,%ax
23681 movzwl %ax,%eax
23682 + pax_force_retaddr
23683 ret
23684
23685 bpf_slow_path_byte:
23686 bpf_slow_path_common(1)
23687 js bpf_error
23688 movzbl -12(%rbp),%eax
23689 + pax_force_retaddr
23690 ret
23691
23692 bpf_slow_path_byte_msh:
23693 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
23694 and $15,%al
23695 shl $2,%al
23696 xchg %eax,%ebx
23697 + pax_force_retaddr
23698 ret
23699 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
23700 index 7b65f75..63097f6 100644
23701 --- a/arch/x86/net/bpf_jit_comp.c
23702 +++ b/arch/x86/net/bpf_jit_comp.c
23703 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
23704 set_fs(old_fs);
23705 }
23706
23707 +struct bpf_jit_work {
23708 + struct work_struct work;
23709 + void *image;
23710 +};
23711
23712 void bpf_jit_compile(struct sk_filter *fp)
23713 {
23714 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
23715 if (addrs == NULL)
23716 return;
23717
23718 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
23719 + if (!fp->work)
23720 + goto out;
23721 +
23722 /* Before first pass, make a rough estimation of addrs[]
23723 * each bpf instruction is translated to less than 64 bytes
23724 */
23725 @@ -585,11 +593,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
23726 if (image) {
23727 if (unlikely(proglen + ilen > oldproglen)) {
23728 pr_err("bpb_jit_compile fatal error\n");
23729 - kfree(addrs);
23730 - module_free(NULL, image);
23731 - return;
23732 + module_free_exec(NULL, image);
23733 + goto out;
23734 }
23735 + pax_open_kernel();
23736 memcpy(image + proglen, temp, ilen);
23737 + pax_close_kernel();
23738 }
23739 proglen += ilen;
23740 addrs[i] = proglen;
23741 @@ -609,7 +618,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
23742 break;
23743 }
23744 if (proglen == oldproglen) {
23745 - image = module_alloc(max_t(unsigned int,
23746 + image = module_alloc_exec(max_t(unsigned int,
23747 proglen,
23748 sizeof(struct work_struct)));
23749 if (!image)
23750 @@ -631,24 +640,27 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
23751 fp->bpf_func = (void *)image;
23752 }
23753 out:
23754 + kfree(fp->work);
23755 kfree(addrs);
23756 return;
23757 }
23758
23759 static void jit_free_defer(struct work_struct *arg)
23760 {
23761 - module_free(NULL, arg);
23762 + module_free_exec(NULL, ((struct bpf_jit_work*)arg)->image);
23763 + kfree(arg);
23764 }
23765
23766 /* run from softirq, we must use a work_struct to call
23767 - * module_free() from process context
23768 + * module_free_exec() from process context
23769 */
23770 void bpf_jit_free(struct sk_filter *fp)
23771 {
23772 if (fp->bpf_func != sk_run_filter) {
23773 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
23774 + struct work_struct *work = &fp->work->work;
23775
23776 INIT_WORK(work, jit_free_defer);
23777 + fp->work->image = fp->bpf_func;
23778 schedule_work(work);
23779 }
23780 }
23781 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
23782 index bff89df..377758a 100644
23783 --- a/arch/x86/oprofile/backtrace.c
23784 +++ b/arch/x86/oprofile/backtrace.c
23785 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
23786 struct stack_frame_ia32 *fp;
23787 unsigned long bytes;
23788
23789 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
23790 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
23791 if (bytes != sizeof(bufhead))
23792 return NULL;
23793
23794 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
23795 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
23796
23797 oprofile_add_trace(bufhead[0].return_address);
23798
23799 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
23800 struct stack_frame bufhead[2];
23801 unsigned long bytes;
23802
23803 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
23804 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
23805 if (bytes != sizeof(bufhead))
23806 return NULL;
23807
23808 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
23809 {
23810 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
23811
23812 - if (!user_mode_vm(regs)) {
23813 + if (!user_mode(regs)) {
23814 unsigned long stack = kernel_stack_pointer(regs);
23815 if (depth)
23816 dump_trace(NULL, regs, (unsigned long *)stack, 0,
23817 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
23818 index cb29191..036766d 100644
23819 --- a/arch/x86/pci/mrst.c
23820 +++ b/arch/x86/pci/mrst.c
23821 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
23822 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
23823 pci_mmcfg_late_init();
23824 pcibios_enable_irq = mrst_pci_irq_enable;
23825 - pci_root_ops = pci_mrst_ops;
23826 + pax_open_kernel();
23827 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
23828 + pax_close_kernel();
23829 /* Continue with standard init */
23830 return 1;
23831 }
23832 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
23833 index f685535..2b76a81 100644
23834 --- a/arch/x86/pci/pcbios.c
23835 +++ b/arch/x86/pci/pcbios.c
23836 @@ -79,50 +79,93 @@ union bios32 {
23837 static struct {
23838 unsigned long address;
23839 unsigned short segment;
23840 -} bios32_indirect = { 0, __KERNEL_CS };
23841 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
23842
23843 /*
23844 * Returns the entry point for the given service, NULL on error
23845 */
23846
23847 -static unsigned long bios32_service(unsigned long service)
23848 +static unsigned long __devinit bios32_service(unsigned long service)
23849 {
23850 unsigned char return_code; /* %al */
23851 unsigned long address; /* %ebx */
23852 unsigned long length; /* %ecx */
23853 unsigned long entry; /* %edx */
23854 unsigned long flags;
23855 + struct desc_struct d, *gdt;
23856
23857 local_irq_save(flags);
23858 - __asm__("lcall *(%%edi); cld"
23859 +
23860 + gdt = get_cpu_gdt_table(smp_processor_id());
23861 +
23862 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
23863 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23864 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
23865 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23866 +
23867 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
23868 : "=a" (return_code),
23869 "=b" (address),
23870 "=c" (length),
23871 "=d" (entry)
23872 : "0" (service),
23873 "1" (0),
23874 - "D" (&bios32_indirect));
23875 + "D" (&bios32_indirect),
23876 + "r"(__PCIBIOS_DS)
23877 + : "memory");
23878 +
23879 + pax_open_kernel();
23880 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
23881 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
23882 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
23883 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
23884 + pax_close_kernel();
23885 +
23886 local_irq_restore(flags);
23887
23888 switch (return_code) {
23889 - case 0:
23890 - return address + entry;
23891 - case 0x80: /* Not present */
23892 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23893 - return 0;
23894 - default: /* Shouldn't happen */
23895 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23896 - service, return_code);
23897 + case 0: {
23898 + int cpu;
23899 + unsigned char flags;
23900 +
23901 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
23902 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
23903 + printk(KERN_WARNING "bios32_service: not valid\n");
23904 return 0;
23905 + }
23906 + address = address + PAGE_OFFSET;
23907 + length += 16UL; /* some BIOSs underreport this... */
23908 + flags = 4;
23909 + if (length >= 64*1024*1024) {
23910 + length >>= PAGE_SHIFT;
23911 + flags |= 8;
23912 + }
23913 +
23914 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
23915 + gdt = get_cpu_gdt_table(cpu);
23916 + pack_descriptor(&d, address, length, 0x9b, flags);
23917 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23918 + pack_descriptor(&d, address, length, 0x93, flags);
23919 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23920 + }
23921 + return entry;
23922 + }
23923 + case 0x80: /* Not present */
23924 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23925 + return 0;
23926 + default: /* Shouldn't happen */
23927 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23928 + service, return_code);
23929 + return 0;
23930 }
23931 }
23932
23933 static struct {
23934 unsigned long address;
23935 unsigned short segment;
23936 -} pci_indirect = { 0, __KERNEL_CS };
23937 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
23938
23939 -static int pci_bios_present;
23940 +static int pci_bios_present __read_only;
23941
23942 static int __devinit check_pcibios(void)
23943 {
23944 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
23945 unsigned long flags, pcibios_entry;
23946
23947 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
23948 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
23949 + pci_indirect.address = pcibios_entry;
23950
23951 local_irq_save(flags);
23952 - __asm__(
23953 - "lcall *(%%edi); cld\n\t"
23954 + __asm__("movw %w6, %%ds\n\t"
23955 + "lcall *%%ss:(%%edi); cld\n\t"
23956 + "push %%ss\n\t"
23957 + "pop %%ds\n\t"
23958 "jc 1f\n\t"
23959 "xor %%ah, %%ah\n"
23960 "1:"
23961 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
23962 "=b" (ebx),
23963 "=c" (ecx)
23964 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
23965 - "D" (&pci_indirect)
23966 + "D" (&pci_indirect),
23967 + "r" (__PCIBIOS_DS)
23968 : "memory");
23969 local_irq_restore(flags);
23970
23971 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
23972
23973 switch (len) {
23974 case 1:
23975 - __asm__("lcall *(%%esi); cld\n\t"
23976 + __asm__("movw %w6, %%ds\n\t"
23977 + "lcall *%%ss:(%%esi); cld\n\t"
23978 + "push %%ss\n\t"
23979 + "pop %%ds\n\t"
23980 "jc 1f\n\t"
23981 "xor %%ah, %%ah\n"
23982 "1:"
23983 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
23984 : "1" (PCIBIOS_READ_CONFIG_BYTE),
23985 "b" (bx),
23986 "D" ((long)reg),
23987 - "S" (&pci_indirect));
23988 + "S" (&pci_indirect),
23989 + "r" (__PCIBIOS_DS));
23990 /*
23991 * Zero-extend the result beyond 8 bits, do not trust the
23992 * BIOS having done it:
23993 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
23994 *value &= 0xff;
23995 break;
23996 case 2:
23997 - __asm__("lcall *(%%esi); cld\n\t"
23998 + __asm__("movw %w6, %%ds\n\t"
23999 + "lcall *%%ss:(%%esi); cld\n\t"
24000 + "push %%ss\n\t"
24001 + "pop %%ds\n\t"
24002 "jc 1f\n\t"
24003 "xor %%ah, %%ah\n"
24004 "1:"
24005 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24006 : "1" (PCIBIOS_READ_CONFIG_WORD),
24007 "b" (bx),
24008 "D" ((long)reg),
24009 - "S" (&pci_indirect));
24010 + "S" (&pci_indirect),
24011 + "r" (__PCIBIOS_DS));
24012 /*
24013 * Zero-extend the result beyond 16 bits, do not trust the
24014 * BIOS having done it:
24015 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24016 *value &= 0xffff;
24017 break;
24018 case 4:
24019 - __asm__("lcall *(%%esi); cld\n\t"
24020 + __asm__("movw %w6, %%ds\n\t"
24021 + "lcall *%%ss:(%%esi); cld\n\t"
24022 + "push %%ss\n\t"
24023 + "pop %%ds\n\t"
24024 "jc 1f\n\t"
24025 "xor %%ah, %%ah\n"
24026 "1:"
24027 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24028 : "1" (PCIBIOS_READ_CONFIG_DWORD),
24029 "b" (bx),
24030 "D" ((long)reg),
24031 - "S" (&pci_indirect));
24032 + "S" (&pci_indirect),
24033 + "r" (__PCIBIOS_DS));
24034 break;
24035 }
24036
24037 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24038
24039 switch (len) {
24040 case 1:
24041 - __asm__("lcall *(%%esi); cld\n\t"
24042 + __asm__("movw %w6, %%ds\n\t"
24043 + "lcall *%%ss:(%%esi); cld\n\t"
24044 + "push %%ss\n\t"
24045 + "pop %%ds\n\t"
24046 "jc 1f\n\t"
24047 "xor %%ah, %%ah\n"
24048 "1:"
24049 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24050 "c" (value),
24051 "b" (bx),
24052 "D" ((long)reg),
24053 - "S" (&pci_indirect));
24054 + "S" (&pci_indirect),
24055 + "r" (__PCIBIOS_DS));
24056 break;
24057 case 2:
24058 - __asm__("lcall *(%%esi); cld\n\t"
24059 + __asm__("movw %w6, %%ds\n\t"
24060 + "lcall *%%ss:(%%esi); cld\n\t"
24061 + "push %%ss\n\t"
24062 + "pop %%ds\n\t"
24063 "jc 1f\n\t"
24064 "xor %%ah, %%ah\n"
24065 "1:"
24066 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24067 "c" (value),
24068 "b" (bx),
24069 "D" ((long)reg),
24070 - "S" (&pci_indirect));
24071 + "S" (&pci_indirect),
24072 + "r" (__PCIBIOS_DS));
24073 break;
24074 case 4:
24075 - __asm__("lcall *(%%esi); cld\n\t"
24076 + __asm__("movw %w6, %%ds\n\t"
24077 + "lcall *%%ss:(%%esi); cld\n\t"
24078 + "push %%ss\n\t"
24079 + "pop %%ds\n\t"
24080 "jc 1f\n\t"
24081 "xor %%ah, %%ah\n"
24082 "1:"
24083 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24084 "c" (value),
24085 "b" (bx),
24086 "D" ((long)reg),
24087 - "S" (&pci_indirect));
24088 + "S" (&pci_indirect),
24089 + "r" (__PCIBIOS_DS));
24090 break;
24091 }
24092
24093 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
24094
24095 DBG("PCI: Fetching IRQ routing table... ");
24096 __asm__("push %%es\n\t"
24097 + "movw %w8, %%ds\n\t"
24098 "push %%ds\n\t"
24099 "pop %%es\n\t"
24100 - "lcall *(%%esi); cld\n\t"
24101 + "lcall *%%ss:(%%esi); cld\n\t"
24102 "pop %%es\n\t"
24103 + "push %%ss\n\t"
24104 + "pop %%ds\n"
24105 "jc 1f\n\t"
24106 "xor %%ah, %%ah\n"
24107 "1:"
24108 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
24109 "1" (0),
24110 "D" ((long) &opt),
24111 "S" (&pci_indirect),
24112 - "m" (opt)
24113 + "m" (opt),
24114 + "r" (__PCIBIOS_DS)
24115 : "memory");
24116 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
24117 if (ret & 0xff00)
24118 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
24119 {
24120 int ret;
24121
24122 - __asm__("lcall *(%%esi); cld\n\t"
24123 + __asm__("movw %w5, %%ds\n\t"
24124 + "lcall *%%ss:(%%esi); cld\n\t"
24125 + "push %%ss\n\t"
24126 + "pop %%ds\n"
24127 "jc 1f\n\t"
24128 "xor %%ah, %%ah\n"
24129 "1:"
24130 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
24131 : "0" (PCIBIOS_SET_PCI_HW_INT),
24132 "b" ((dev->bus->number << 8) | dev->devfn),
24133 "c" ((irq << 8) | (pin + 10)),
24134 - "S" (&pci_indirect));
24135 + "S" (&pci_indirect),
24136 + "r" (__PCIBIOS_DS));
24137 return !(ret & 0xff00);
24138 }
24139 EXPORT_SYMBOL(pcibios_set_irq_routing);
24140 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
24141 index 5cab48e..b025f9b 100644
24142 --- a/arch/x86/platform/efi/efi_32.c
24143 +++ b/arch/x86/platform/efi/efi_32.c
24144 @@ -38,70 +38,56 @@
24145 */
24146
24147 static unsigned long efi_rt_eflags;
24148 -static pgd_t efi_bak_pg_dir_pointer[2];
24149 +static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
24150
24151 -void efi_call_phys_prelog(void)
24152 +void __init efi_call_phys_prelog(void)
24153 {
24154 - unsigned long cr4;
24155 - unsigned long temp;
24156 struct desc_ptr gdt_descr;
24157
24158 +#ifdef CONFIG_PAX_KERNEXEC
24159 + struct desc_struct d;
24160 +#endif
24161 +
24162 local_irq_save(efi_rt_eflags);
24163
24164 - /*
24165 - * If I don't have PAE, I should just duplicate two entries in page
24166 - * directory. If I have PAE, I just need to duplicate one entry in
24167 - * page directory.
24168 - */
24169 - cr4 = read_cr4_safe();
24170 -
24171 - if (cr4 & X86_CR4_PAE) {
24172 - efi_bak_pg_dir_pointer[0].pgd =
24173 - swapper_pg_dir[pgd_index(0)].pgd;
24174 - swapper_pg_dir[0].pgd =
24175 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
24176 - } else {
24177 - efi_bak_pg_dir_pointer[0].pgd =
24178 - swapper_pg_dir[pgd_index(0)].pgd;
24179 - efi_bak_pg_dir_pointer[1].pgd =
24180 - swapper_pg_dir[pgd_index(0x400000)].pgd;
24181 - swapper_pg_dir[pgd_index(0)].pgd =
24182 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
24183 - temp = PAGE_OFFSET + 0x400000;
24184 - swapper_pg_dir[pgd_index(0x400000)].pgd =
24185 - swapper_pg_dir[pgd_index(temp)].pgd;
24186 - }
24187 + clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
24188 + clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24189 + min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
24190
24191 /*
24192 * After the lock is released, the original page table is restored.
24193 */
24194 __flush_tlb_all();
24195
24196 +#ifdef CONFIG_PAX_KERNEXEC
24197 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
24198 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
24199 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
24200 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
24201 +#endif
24202 +
24203 gdt_descr.address = __pa(get_cpu_gdt_table(0));
24204 gdt_descr.size = GDT_SIZE - 1;
24205 load_gdt(&gdt_descr);
24206 }
24207
24208 -void efi_call_phys_epilog(void)
24209 +void __init efi_call_phys_epilog(void)
24210 {
24211 - unsigned long cr4;
24212 struct desc_ptr gdt_descr;
24213
24214 +#ifdef CONFIG_PAX_KERNEXEC
24215 + struct desc_struct d;
24216 +
24217 + memset(&d, 0, sizeof d);
24218 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
24219 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
24220 +#endif
24221 +
24222 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
24223 gdt_descr.size = GDT_SIZE - 1;
24224 load_gdt(&gdt_descr);
24225
24226 - cr4 = read_cr4_safe();
24227 -
24228 - if (cr4 & X86_CR4_PAE) {
24229 - swapper_pg_dir[pgd_index(0)].pgd =
24230 - efi_bak_pg_dir_pointer[0].pgd;
24231 - } else {
24232 - swapper_pg_dir[pgd_index(0)].pgd =
24233 - efi_bak_pg_dir_pointer[0].pgd;
24234 - swapper_pg_dir[pgd_index(0x400000)].pgd =
24235 - efi_bak_pg_dir_pointer[1].pgd;
24236 - }
24237 + clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
24238
24239 /*
24240 * After the lock is released, the original page table is restored.
24241 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
24242 index fbe66e6..c5c0dd2 100644
24243 --- a/arch/x86/platform/efi/efi_stub_32.S
24244 +++ b/arch/x86/platform/efi/efi_stub_32.S
24245 @@ -6,7 +6,9 @@
24246 */
24247
24248 #include <linux/linkage.h>
24249 +#include <linux/init.h>
24250 #include <asm/page_types.h>
24251 +#include <asm/segment.h>
24252
24253 /*
24254 * efi_call_phys(void *, ...) is a function with variable parameters.
24255 @@ -20,7 +22,7 @@
24256 * service functions will comply with gcc calling convention, too.
24257 */
24258
24259 -.text
24260 +__INIT
24261 ENTRY(efi_call_phys)
24262 /*
24263 * 0. The function can only be called in Linux kernel. So CS has been
24264 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
24265 * The mapping of lower virtual memory has been created in prelog and
24266 * epilog.
24267 */
24268 - movl $1f, %edx
24269 - subl $__PAGE_OFFSET, %edx
24270 - jmp *%edx
24271 + movl $(__KERNEXEC_EFI_DS), %edx
24272 + mov %edx, %ds
24273 + mov %edx, %es
24274 + mov %edx, %ss
24275 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
24276 1:
24277
24278 /*
24279 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
24280 * parameter 2, ..., param n. To make things easy, we save the return
24281 * address of efi_call_phys in a global variable.
24282 */
24283 - popl %edx
24284 - movl %edx, saved_return_addr
24285 - /* get the function pointer into ECX*/
24286 - popl %ecx
24287 - movl %ecx, efi_rt_function_ptr
24288 - movl $2f, %edx
24289 - subl $__PAGE_OFFSET, %edx
24290 - pushl %edx
24291 + popl (saved_return_addr)
24292 + popl (efi_rt_function_ptr)
24293
24294 /*
24295 * 3. Clear PG bit in %CR0.
24296 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
24297 /*
24298 * 5. Call the physical function.
24299 */
24300 - jmp *%ecx
24301 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
24302
24303 -2:
24304 /*
24305 * 6. After EFI runtime service returns, control will return to
24306 * following instruction. We'd better readjust stack pointer first.
24307 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
24308 movl %cr0, %edx
24309 orl $0x80000000, %edx
24310 movl %edx, %cr0
24311 - jmp 1f
24312 -1:
24313 +
24314 /*
24315 * 8. Now restore the virtual mode from flat mode by
24316 * adding EIP with PAGE_OFFSET.
24317 */
24318 - movl $1f, %edx
24319 - jmp *%edx
24320 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
24321 1:
24322 + movl $(__KERNEL_DS), %edx
24323 + mov %edx, %ds
24324 + mov %edx, %es
24325 + mov %edx, %ss
24326
24327 /*
24328 * 9. Balance the stack. And because EAX contain the return value,
24329 * we'd better not clobber it.
24330 */
24331 - leal efi_rt_function_ptr, %edx
24332 - movl (%edx), %ecx
24333 - pushl %ecx
24334 + pushl (efi_rt_function_ptr)
24335
24336 /*
24337 - * 10. Push the saved return address onto the stack and return.
24338 + * 10. Return to the saved return address.
24339 */
24340 - leal saved_return_addr, %edx
24341 - movl (%edx), %ecx
24342 - pushl %ecx
24343 - ret
24344 + jmpl *(saved_return_addr)
24345 ENDPROC(efi_call_phys)
24346 .previous
24347
24348 -.data
24349 +__INITDATA
24350 saved_return_addr:
24351 .long 0
24352 efi_rt_function_ptr:
24353 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
24354 index 4c07cca..2c8427d 100644
24355 --- a/arch/x86/platform/efi/efi_stub_64.S
24356 +++ b/arch/x86/platform/efi/efi_stub_64.S
24357 @@ -7,6 +7,7 @@
24358 */
24359
24360 #include <linux/linkage.h>
24361 +#include <asm/alternative-asm.h>
24362
24363 #define SAVE_XMM \
24364 mov %rsp, %rax; \
24365 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
24366 call *%rdi
24367 addq $32, %rsp
24368 RESTORE_XMM
24369 + pax_force_retaddr 0, 1
24370 ret
24371 ENDPROC(efi_call0)
24372
24373 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
24374 call *%rdi
24375 addq $32, %rsp
24376 RESTORE_XMM
24377 + pax_force_retaddr 0, 1
24378 ret
24379 ENDPROC(efi_call1)
24380
24381 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
24382 call *%rdi
24383 addq $32, %rsp
24384 RESTORE_XMM
24385 + pax_force_retaddr 0, 1
24386 ret
24387 ENDPROC(efi_call2)
24388
24389 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
24390 call *%rdi
24391 addq $32, %rsp
24392 RESTORE_XMM
24393 + pax_force_retaddr 0, 1
24394 ret
24395 ENDPROC(efi_call3)
24396
24397 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
24398 call *%rdi
24399 addq $32, %rsp
24400 RESTORE_XMM
24401 + pax_force_retaddr 0, 1
24402 ret
24403 ENDPROC(efi_call4)
24404
24405 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
24406 call *%rdi
24407 addq $48, %rsp
24408 RESTORE_XMM
24409 + pax_force_retaddr 0, 1
24410 ret
24411 ENDPROC(efi_call5)
24412
24413 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
24414 call *%rdi
24415 addq $48, %rsp
24416 RESTORE_XMM
24417 + pax_force_retaddr 0, 1
24418 ret
24419 ENDPROC(efi_call6)
24420 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
24421 index fe73276..70fe25a 100644
24422 --- a/arch/x86/platform/mrst/mrst.c
24423 +++ b/arch/x86/platform/mrst/mrst.c
24424 @@ -239,14 +239,16 @@ static int mrst_i8042_detect(void)
24425 }
24426
24427 /* Reboot and power off are handled by the SCU on a MID device */
24428 -static void mrst_power_off(void)
24429 +static __noreturn void mrst_power_off(void)
24430 {
24431 intel_scu_ipc_simple_command(0xf1, 1);
24432 + BUG();
24433 }
24434
24435 -static void mrst_reboot(void)
24436 +static __noreturn void mrst_reboot(void)
24437 {
24438 intel_scu_ipc_simple_command(0xf1, 0);
24439 + BUG();
24440 }
24441
24442 /*
24443 diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
24444 index 5b55219..b326540 100644
24445 --- a/arch/x86/platform/uv/tlb_uv.c
24446 +++ b/arch/x86/platform/uv/tlb_uv.c
24447 @@ -377,6 +377,8 @@ static void reset_with_ipi(struct pnmask *distribution, struct bau_control *bcp)
24448 struct bau_control *smaster = bcp->socket_master;
24449 struct reset_args reset_args;
24450
24451 + pax_track_stack();
24452 +
24453 reset_args.sender = sender;
24454 cpus_clear(*mask);
24455 /* find a single cpu for each uvhub in this distribution mask */
24456 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
24457 index 87bb35e..eff2da8 100644
24458 --- a/arch/x86/power/cpu.c
24459 +++ b/arch/x86/power/cpu.c
24460 @@ -130,7 +130,7 @@ static void do_fpu_end(void)
24461 static void fix_processor_context(void)
24462 {
24463 int cpu = smp_processor_id();
24464 - struct tss_struct *t = &per_cpu(init_tss, cpu);
24465 + struct tss_struct *t = init_tss + cpu;
24466
24467 set_tss_desc(cpu, t); /*
24468 * This just modifies memory; should not be
24469 @@ -140,7 +140,9 @@ static void fix_processor_context(void)
24470 */
24471
24472 #ifdef CONFIG_X86_64
24473 + pax_open_kernel();
24474 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
24475 + pax_close_kernel();
24476
24477 syscall_init(); /* This sets MSR_*STAR and related */
24478 #endif
24479 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
24480 index 5d17950..2253fc9 100644
24481 --- a/arch/x86/vdso/Makefile
24482 +++ b/arch/x86/vdso/Makefile
24483 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
24484 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
24485 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
24486
24487 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
24488 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
24489 GCOV_PROFILE := n
24490
24491 #
24492 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
24493 index 468d591..8e80a0a 100644
24494 --- a/arch/x86/vdso/vdso32-setup.c
24495 +++ b/arch/x86/vdso/vdso32-setup.c
24496 @@ -25,6 +25,7 @@
24497 #include <asm/tlbflush.h>
24498 #include <asm/vdso.h>
24499 #include <asm/proto.h>
24500 +#include <asm/mman.h>
24501
24502 enum {
24503 VDSO_DISABLED = 0,
24504 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
24505 void enable_sep_cpu(void)
24506 {
24507 int cpu = get_cpu();
24508 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
24509 + struct tss_struct *tss = init_tss + cpu;
24510
24511 if (!boot_cpu_has(X86_FEATURE_SEP)) {
24512 put_cpu();
24513 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
24514 gate_vma.vm_start = FIXADDR_USER_START;
24515 gate_vma.vm_end = FIXADDR_USER_END;
24516 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
24517 - gate_vma.vm_page_prot = __P101;
24518 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
24519 /*
24520 * Make sure the vDSO gets into every core dump.
24521 * Dumping its contents makes post-mortem fully interpretable later
24522 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24523 if (compat)
24524 addr = VDSO_HIGH_BASE;
24525 else {
24526 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
24527 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
24528 if (IS_ERR_VALUE(addr)) {
24529 ret = addr;
24530 goto up_fail;
24531 }
24532 }
24533
24534 - current->mm->context.vdso = (void *)addr;
24535 + current->mm->context.vdso = addr;
24536
24537 if (compat_uses_vma || !compat) {
24538 /*
24539 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24540 }
24541
24542 current_thread_info()->sysenter_return =
24543 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24544 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24545
24546 up_fail:
24547 if (ret)
24548 - current->mm->context.vdso = NULL;
24549 + current->mm->context.vdso = 0;
24550
24551 up_write(&mm->mmap_sem);
24552
24553 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
24554
24555 const char *arch_vma_name(struct vm_area_struct *vma)
24556 {
24557 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24558 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24559 return "[vdso]";
24560 +
24561 +#ifdef CONFIG_PAX_SEGMEXEC
24562 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
24563 + return "[vdso]";
24564 +#endif
24565 +
24566 return NULL;
24567 }
24568
24569 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24570 * Check to see if the corresponding task was created in compat vdso
24571 * mode.
24572 */
24573 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
24574 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
24575 return &gate_vma;
24576 return NULL;
24577 }
24578 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
24579 index 316fbca..4638633 100644
24580 --- a/arch/x86/vdso/vma.c
24581 +++ b/arch/x86/vdso/vma.c
24582 @@ -16,8 +16,6 @@
24583 #include <asm/vdso.h>
24584 #include <asm/page.h>
24585
24586 -unsigned int __read_mostly vdso_enabled = 1;
24587 -
24588 extern char vdso_start[], vdso_end[];
24589 extern unsigned short vdso_sync_cpuid;
24590
24591 @@ -97,13 +95,15 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
24592 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24593 {
24594 struct mm_struct *mm = current->mm;
24595 - unsigned long addr;
24596 + unsigned long addr = 0;
24597 int ret;
24598
24599 - if (!vdso_enabled)
24600 - return 0;
24601 -
24602 down_write(&mm->mmap_sem);
24603 +
24604 +#ifdef CONFIG_PAX_RANDMMAP
24605 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
24606 +#endif
24607 +
24608 addr = vdso_addr(mm->start_stack, vdso_size);
24609 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
24610 if (IS_ERR_VALUE(addr)) {
24611 @@ -111,26 +111,18 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24612 goto up_fail;
24613 }
24614
24615 - current->mm->context.vdso = (void *)addr;
24616 + mm->context.vdso = addr;
24617
24618 ret = install_special_mapping(mm, addr, vdso_size,
24619 VM_READ|VM_EXEC|
24620 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
24621 VM_ALWAYSDUMP,
24622 vdso_pages);
24623 - if (ret) {
24624 - current->mm->context.vdso = NULL;
24625 - goto up_fail;
24626 - }
24627 +
24628 + if (ret)
24629 + mm->context.vdso = 0;
24630
24631 up_fail:
24632 up_write(&mm->mmap_sem);
24633 return ret;
24634 }
24635 -
24636 -static __init int vdso_setup(char *s)
24637 -{
24638 - vdso_enabled = simple_strtoul(s, NULL, 0);
24639 - return 0;
24640 -}
24641 -__setup("vdso=", vdso_setup);
24642 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
24643 index 46c8069..6330d3c 100644
24644 --- a/arch/x86/xen/enlighten.c
24645 +++ b/arch/x86/xen/enlighten.c
24646 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
24647
24648 struct shared_info xen_dummy_shared_info;
24649
24650 -void *xen_initial_gdt;
24651 -
24652 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
24653 __read_mostly int xen_have_vector_callback;
24654 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
24655 @@ -1028,7 +1026,7 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
24656 #endif
24657 };
24658
24659 -static void xen_reboot(int reason)
24660 +static __noreturn void xen_reboot(int reason)
24661 {
24662 struct sched_shutdown r = { .reason = reason };
24663
24664 @@ -1036,17 +1034,17 @@ static void xen_reboot(int reason)
24665 BUG();
24666 }
24667
24668 -static void xen_restart(char *msg)
24669 +static __noreturn void xen_restart(char *msg)
24670 {
24671 xen_reboot(SHUTDOWN_reboot);
24672 }
24673
24674 -static void xen_emergency_restart(void)
24675 +static __noreturn void xen_emergency_restart(void)
24676 {
24677 xen_reboot(SHUTDOWN_reboot);
24678 }
24679
24680 -static void xen_machine_halt(void)
24681 +static __noreturn void xen_machine_halt(void)
24682 {
24683 xen_reboot(SHUTDOWN_poweroff);
24684 }
24685 @@ -1152,7 +1150,17 @@ asmlinkage void __init xen_start_kernel(void)
24686 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
24687
24688 /* Work out if we support NX */
24689 - x86_configure_nx();
24690 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
24691 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
24692 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
24693 + unsigned l, h;
24694 +
24695 + __supported_pte_mask |= _PAGE_NX;
24696 + rdmsr(MSR_EFER, l, h);
24697 + l |= EFER_NX;
24698 + wrmsr(MSR_EFER, l, h);
24699 + }
24700 +#endif
24701
24702 xen_setup_features();
24703
24704 @@ -1183,13 +1191,6 @@ asmlinkage void __init xen_start_kernel(void)
24705
24706 machine_ops = xen_machine_ops;
24707
24708 - /*
24709 - * The only reliable way to retain the initial address of the
24710 - * percpu gdt_page is to remember it here, so we can go and
24711 - * mark it RW later, when the initial percpu area is freed.
24712 - */
24713 - xen_initial_gdt = &per_cpu(gdt_page, 0);
24714 -
24715 xen_smp_init();
24716
24717 #ifdef CONFIG_ACPI_NUMA
24718 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
24719 index 3dd53f9..5aa5df3 100644
24720 --- a/arch/x86/xen/mmu.c
24721 +++ b/arch/x86/xen/mmu.c
24722 @@ -1768,6 +1768,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
24723 convert_pfn_mfn(init_level4_pgt);
24724 convert_pfn_mfn(level3_ident_pgt);
24725 convert_pfn_mfn(level3_kernel_pgt);
24726 + convert_pfn_mfn(level3_vmalloc_start_pgt);
24727 + convert_pfn_mfn(level3_vmalloc_end_pgt);
24728 + convert_pfn_mfn(level3_vmemmap_pgt);
24729
24730 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
24731 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
24732 @@ -1786,7 +1789,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
24733 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
24734 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
24735 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
24736 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
24737 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
24738 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
24739 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
24740 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
24741 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
24742 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
24743
24744 @@ -2000,6 +2007,7 @@ static void __init xen_post_allocator_init(void)
24745 pv_mmu_ops.set_pud = xen_set_pud;
24746 #if PAGETABLE_LEVELS == 4
24747 pv_mmu_ops.set_pgd = xen_set_pgd;
24748 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
24749 #endif
24750
24751 /* This will work as long as patching hasn't happened yet
24752 @@ -2081,6 +2089,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
24753 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
24754 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
24755 .set_pgd = xen_set_pgd_hyper,
24756 + .set_pgd_batched = xen_set_pgd_hyper,
24757
24758 .alloc_pud = xen_alloc_pmd_init,
24759 .release_pud = xen_release_pmd_init,
24760 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
24761 index 041d4fe..7666b7e 100644
24762 --- a/arch/x86/xen/smp.c
24763 +++ b/arch/x86/xen/smp.c
24764 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
24765 {
24766 BUG_ON(smp_processor_id() != 0);
24767 native_smp_prepare_boot_cpu();
24768 -
24769 - /* We've switched to the "real" per-cpu gdt, so make sure the
24770 - old memory can be recycled */
24771 - make_lowmem_page_readwrite(xen_initial_gdt);
24772 -
24773 xen_filter_cpu_maps();
24774 xen_setup_vcpu_info_placement();
24775 }
24776 @@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
24777 gdt = get_cpu_gdt_table(cpu);
24778
24779 ctxt->flags = VGCF_IN_KERNEL;
24780 - ctxt->user_regs.ds = __USER_DS;
24781 - ctxt->user_regs.es = __USER_DS;
24782 + ctxt->user_regs.ds = __KERNEL_DS;
24783 + ctxt->user_regs.es = __KERNEL_DS;
24784 ctxt->user_regs.ss = __KERNEL_DS;
24785 #ifdef CONFIG_X86_32
24786 ctxt->user_regs.fs = __KERNEL_PERCPU;
24787 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
24788 + savesegment(gs, ctxt->user_regs.gs);
24789 #else
24790 ctxt->gs_base_kernel = per_cpu_offset(cpu);
24791 #endif
24792 @@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
24793 int rc;
24794
24795 per_cpu(current_task, cpu) = idle;
24796 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
24797 #ifdef CONFIG_X86_32
24798 irq_ctx_init(cpu);
24799 #else
24800 clear_tsk_thread_flag(idle, TIF_FORK);
24801 - per_cpu(kernel_stack, cpu) =
24802 - (unsigned long)task_stack_page(idle) -
24803 - KERNEL_STACK_OFFSET + THREAD_SIZE;
24804 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
24805 #endif
24806 xen_setup_runstate_info(cpu);
24807 xen_setup_timer(cpu);
24808 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
24809 index b040b0e..8cc4fe0 100644
24810 --- a/arch/x86/xen/xen-asm_32.S
24811 +++ b/arch/x86/xen/xen-asm_32.S
24812 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
24813 ESP_OFFSET=4 # bytes pushed onto stack
24814
24815 /*
24816 - * Store vcpu_info pointer for easy access. Do it this way to
24817 - * avoid having to reload %fs
24818 + * Store vcpu_info pointer for easy access.
24819 */
24820 #ifdef CONFIG_SMP
24821 - GET_THREAD_INFO(%eax)
24822 - movl TI_cpu(%eax), %eax
24823 - movl __per_cpu_offset(,%eax,4), %eax
24824 - mov xen_vcpu(%eax), %eax
24825 + push %fs
24826 + mov $(__KERNEL_PERCPU), %eax
24827 + mov %eax, %fs
24828 + mov PER_CPU_VAR(xen_vcpu), %eax
24829 + pop %fs
24830 #else
24831 movl xen_vcpu, %eax
24832 #endif
24833 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
24834 index aaa7291..3f77960 100644
24835 --- a/arch/x86/xen/xen-head.S
24836 +++ b/arch/x86/xen/xen-head.S
24837 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
24838 #ifdef CONFIG_X86_32
24839 mov %esi,xen_start_info
24840 mov $init_thread_union+THREAD_SIZE,%esp
24841 +#ifdef CONFIG_SMP
24842 + movl $cpu_gdt_table,%edi
24843 + movl $__per_cpu_load,%eax
24844 + movw %ax,__KERNEL_PERCPU + 2(%edi)
24845 + rorl $16,%eax
24846 + movb %al,__KERNEL_PERCPU + 4(%edi)
24847 + movb %ah,__KERNEL_PERCPU + 7(%edi)
24848 + movl $__per_cpu_end - 1,%eax
24849 + subl $__per_cpu_start,%eax
24850 + movw %ax,__KERNEL_PERCPU + 0(%edi)
24851 +#endif
24852 #else
24853 mov %rsi,xen_start_info
24854 mov $init_thread_union+THREAD_SIZE,%rsp
24855 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
24856 index b095739..8c17bcd 100644
24857 --- a/arch/x86/xen/xen-ops.h
24858 +++ b/arch/x86/xen/xen-ops.h
24859 @@ -10,8 +10,6 @@
24860 extern const char xen_hypervisor_callback[];
24861 extern const char xen_failsafe_callback[];
24862
24863 -extern void *xen_initial_gdt;
24864 -
24865 struct trap_info;
24866 void xen_copy_trap_info(struct trap_info *traps);
24867
24868 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
24869 index 58916af..9cb880b 100644
24870 --- a/block/blk-iopoll.c
24871 +++ b/block/blk-iopoll.c
24872 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
24873 }
24874 EXPORT_SYMBOL(blk_iopoll_complete);
24875
24876 -static void blk_iopoll_softirq(struct softirq_action *h)
24877 +static void blk_iopoll_softirq(void)
24878 {
24879 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
24880 int rearm = 0, budget = blk_iopoll_budget;
24881 diff --git a/block/blk-map.c b/block/blk-map.c
24882 index 164cd00..6d96fc1 100644
24883 --- a/block/blk-map.c
24884 +++ b/block/blk-map.c
24885 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
24886 if (!len || !kbuf)
24887 return -EINVAL;
24888
24889 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
24890 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
24891 if (do_copy)
24892 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
24893 else
24894 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
24895 index 1366a89..e17f54b 100644
24896 --- a/block/blk-softirq.c
24897 +++ b/block/blk-softirq.c
24898 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
24899 * Softirq action handler - move entries to local list and loop over them
24900 * while passing them to the queue registered handler.
24901 */
24902 -static void blk_done_softirq(struct softirq_action *h)
24903 +static void blk_done_softirq(void)
24904 {
24905 struct list_head *cpu_list, local_list;
24906
24907 diff --git a/block/bsg.c b/block/bsg.c
24908 index 702f131..37808bf 100644
24909 --- a/block/bsg.c
24910 +++ b/block/bsg.c
24911 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
24912 struct sg_io_v4 *hdr, struct bsg_device *bd,
24913 fmode_t has_write_perm)
24914 {
24915 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24916 + unsigned char *cmdptr;
24917 +
24918 if (hdr->request_len > BLK_MAX_CDB) {
24919 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
24920 if (!rq->cmd)
24921 return -ENOMEM;
24922 - }
24923 + cmdptr = rq->cmd;
24924 + } else
24925 + cmdptr = tmpcmd;
24926
24927 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
24928 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
24929 hdr->request_len))
24930 return -EFAULT;
24931
24932 + if (cmdptr != rq->cmd)
24933 + memcpy(rq->cmd, cmdptr, hdr->request_len);
24934 +
24935 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
24936 if (blk_verify_command(rq->cmd, has_write_perm))
24937 return -EPERM;
24938 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
24939 index 7b72502..646105c 100644
24940 --- a/block/compat_ioctl.c
24941 +++ b/block/compat_ioctl.c
24942 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
24943 err |= __get_user(f->spec1, &uf->spec1);
24944 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
24945 err |= __get_user(name, &uf->name);
24946 - f->name = compat_ptr(name);
24947 + f->name = (void __force_kernel *)compat_ptr(name);
24948 if (err) {
24949 err = -EFAULT;
24950 goto out;
24951 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
24952 index 4f4230b..0feae9a 100644
24953 --- a/block/scsi_ioctl.c
24954 +++ b/block/scsi_ioctl.c
24955 @@ -222,8 +222,20 @@ EXPORT_SYMBOL(blk_verify_command);
24956 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
24957 struct sg_io_hdr *hdr, fmode_t mode)
24958 {
24959 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
24960 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24961 + unsigned char *cmdptr;
24962 +
24963 + if (rq->cmd != rq->__cmd)
24964 + cmdptr = rq->cmd;
24965 + else
24966 + cmdptr = tmpcmd;
24967 +
24968 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
24969 return -EFAULT;
24970 +
24971 + if (cmdptr != rq->cmd)
24972 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
24973 +
24974 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
24975 return -EPERM;
24976
24977 @@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
24978 int err;
24979 unsigned int in_len, out_len, bytes, opcode, cmdlen;
24980 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
24981 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24982 + unsigned char *cmdptr;
24983
24984 if (!sic)
24985 return -EINVAL;
24986 @@ -465,9 +479,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
24987 */
24988 err = -EFAULT;
24989 rq->cmd_len = cmdlen;
24990 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
24991 +
24992 + if (rq->cmd != rq->__cmd)
24993 + cmdptr = rq->cmd;
24994 + else
24995 + cmdptr = tmpcmd;
24996 +
24997 + if (copy_from_user(cmdptr, sic->data, cmdlen))
24998 goto error;
24999
25000 + if (rq->cmd != cmdptr)
25001 + memcpy(rq->cmd, cmdptr, cmdlen);
25002 +
25003 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
25004 goto error;
25005
25006 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
25007 index 671d4d6..5f24030 100644
25008 --- a/crypto/cryptd.c
25009 +++ b/crypto/cryptd.c
25010 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
25011
25012 struct cryptd_blkcipher_request_ctx {
25013 crypto_completion_t complete;
25014 -};
25015 +} __no_const;
25016
25017 struct cryptd_hash_ctx {
25018 struct crypto_shash *child;
25019 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
25020
25021 struct cryptd_aead_request_ctx {
25022 crypto_completion_t complete;
25023 -};
25024 +} __no_const;
25025
25026 static void cryptd_queue_worker(struct work_struct *work);
25027
25028 diff --git a/crypto/serpent.c b/crypto/serpent.c
25029 index b651a55..a9ddd79b 100644
25030 --- a/crypto/serpent.c
25031 +++ b/crypto/serpent.c
25032 @@ -224,6 +224,8 @@ static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key,
25033 u32 r0,r1,r2,r3,r4;
25034 int i;
25035
25036 + pax_track_stack();
25037 +
25038 /* Copy key, add padding */
25039
25040 for (i = 0; i < keylen; ++i)
25041 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
25042 index 5d41894..22021e4 100644
25043 --- a/drivers/acpi/apei/cper.c
25044 +++ b/drivers/acpi/apei/cper.c
25045 @@ -38,12 +38,12 @@
25046 */
25047 u64 cper_next_record_id(void)
25048 {
25049 - static atomic64_t seq;
25050 + static atomic64_unchecked_t seq;
25051
25052 - if (!atomic64_read(&seq))
25053 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
25054 + if (!atomic64_read_unchecked(&seq))
25055 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
25056
25057 - return atomic64_inc_return(&seq);
25058 + return atomic64_inc_return_unchecked(&seq);
25059 }
25060 EXPORT_SYMBOL_GPL(cper_next_record_id);
25061
25062 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
25063 index 22f918b..9fafb84 100644
25064 --- a/drivers/acpi/ec_sys.c
25065 +++ b/drivers/acpi/ec_sys.c
25066 @@ -11,6 +11,7 @@
25067 #include <linux/kernel.h>
25068 #include <linux/acpi.h>
25069 #include <linux/debugfs.h>
25070 +#include <asm/uaccess.h>
25071 #include "internal.h"
25072
25073 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
25074 @@ -39,7 +40,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
25075 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
25076 */
25077 unsigned int size = EC_SPACE_SIZE;
25078 - u8 *data = (u8 *) buf;
25079 + u8 data;
25080 loff_t init_off = *off;
25081 int err = 0;
25082
25083 @@ -52,9 +53,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
25084 size = count;
25085
25086 while (size) {
25087 - err = ec_read(*off, &data[*off - init_off]);
25088 + err = ec_read(*off, &data);
25089 if (err)
25090 return err;
25091 + if (put_user(data, &buf[*off - init_off]))
25092 + return -EFAULT;
25093 *off += 1;
25094 size--;
25095 }
25096 @@ -70,7 +73,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
25097
25098 unsigned int size = count;
25099 loff_t init_off = *off;
25100 - u8 *data = (u8 *) buf;
25101 int err = 0;
25102
25103 if (*off >= EC_SPACE_SIZE)
25104 @@ -81,7 +83,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
25105 }
25106
25107 while (size) {
25108 - u8 byte_write = data[*off - init_off];
25109 + u8 byte_write;
25110 + if (get_user(byte_write, &buf[*off - init_off]))
25111 + return -EFAULT;
25112 err = ec_write(*off, byte_write);
25113 if (err)
25114 return err;
25115 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
25116 index f5f9869..da87aeb 100644
25117 --- a/drivers/acpi/proc.c
25118 +++ b/drivers/acpi/proc.c
25119 @@ -342,19 +342,13 @@ acpi_system_write_wakeup_device(struct file *file,
25120 size_t count, loff_t * ppos)
25121 {
25122 struct list_head *node, *next;
25123 - char strbuf[5];
25124 - char str[5] = "";
25125 - unsigned int len = count;
25126 + char strbuf[5] = {0};
25127
25128 - if (len > 4)
25129 - len = 4;
25130 - if (len < 0)
25131 + if (count > 4)
25132 + count = 4;
25133 + if (copy_from_user(strbuf, buffer, count))
25134 return -EFAULT;
25135 -
25136 - if (copy_from_user(strbuf, buffer, len))
25137 - return -EFAULT;
25138 - strbuf[len] = '\0';
25139 - sscanf(strbuf, "%s", str);
25140 + strbuf[count] = '\0';
25141
25142 mutex_lock(&acpi_device_lock);
25143 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
25144 @@ -363,7 +357,7 @@ acpi_system_write_wakeup_device(struct file *file,
25145 if (!dev->wakeup.flags.valid)
25146 continue;
25147
25148 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
25149 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
25150 if (device_can_wakeup(&dev->dev)) {
25151 bool enable = !device_may_wakeup(&dev->dev);
25152 device_set_wakeup_enable(&dev->dev, enable);
25153 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
25154 index a4e0f1b..9793b28 100644
25155 --- a/drivers/acpi/processor_driver.c
25156 +++ b/drivers/acpi/processor_driver.c
25157 @@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
25158 return 0;
25159 #endif
25160
25161 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
25162 + BUG_ON(pr->id >= nr_cpu_ids);
25163
25164 /*
25165 * Buggy BIOS check
25166 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
25167 index 4a3a5ae..cbee192 100644
25168 --- a/drivers/ata/libata-core.c
25169 +++ b/drivers/ata/libata-core.c
25170 @@ -4733,7 +4733,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
25171 struct ata_port *ap;
25172 unsigned int tag;
25173
25174 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25175 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25176 ap = qc->ap;
25177
25178 qc->flags = 0;
25179 @@ -4749,7 +4749,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
25180 struct ata_port *ap;
25181 struct ata_link *link;
25182
25183 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25184 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25185 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
25186 ap = qc->ap;
25187 link = qc->dev->link;
25188 @@ -5754,6 +5754,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
25189 return;
25190
25191 spin_lock(&lock);
25192 + pax_open_kernel();
25193
25194 for (cur = ops->inherits; cur; cur = cur->inherits) {
25195 void **inherit = (void **)cur;
25196 @@ -5767,8 +5768,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
25197 if (IS_ERR(*pp))
25198 *pp = NULL;
25199
25200 - ops->inherits = NULL;
25201 + *(struct ata_port_operations **)&ops->inherits = NULL;
25202
25203 + pax_close_kernel();
25204 spin_unlock(&lock);
25205 }
25206
25207 diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
25208 index ed16fbe..fc92cb8 100644
25209 --- a/drivers/ata/libata-eh.c
25210 +++ b/drivers/ata/libata-eh.c
25211 @@ -2515,6 +2515,8 @@ void ata_eh_report(struct ata_port *ap)
25212 {
25213 struct ata_link *link;
25214
25215 + pax_track_stack();
25216 +
25217 ata_for_each_link(link, ap, HOST_FIRST)
25218 ata_eh_link_report(link);
25219 }
25220 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
25221 index 719bb73..79ce858 100644
25222 --- a/drivers/ata/pata_arasan_cf.c
25223 +++ b/drivers/ata/pata_arasan_cf.c
25224 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
25225 /* Handle platform specific quirks */
25226 if (pdata->quirk) {
25227 if (pdata->quirk & CF_BROKEN_PIO) {
25228 - ap->ops->set_piomode = NULL;
25229 + pax_open_kernel();
25230 + *(void **)&ap->ops->set_piomode = NULL;
25231 + pax_close_kernel();
25232 ap->pio_mask = 0;
25233 }
25234 if (pdata->quirk & CF_BROKEN_MWDMA)
25235 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
25236 index f9b983a..887b9d8 100644
25237 --- a/drivers/atm/adummy.c
25238 +++ b/drivers/atm/adummy.c
25239 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
25240 vcc->pop(vcc, skb);
25241 else
25242 dev_kfree_skb_any(skb);
25243 - atomic_inc(&vcc->stats->tx);
25244 + atomic_inc_unchecked(&vcc->stats->tx);
25245
25246 return 0;
25247 }
25248 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
25249 index f8f41e0..1f987dd 100644
25250 --- a/drivers/atm/ambassador.c
25251 +++ b/drivers/atm/ambassador.c
25252 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
25253 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
25254
25255 // VC layer stats
25256 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25257 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25258
25259 // free the descriptor
25260 kfree (tx_descr);
25261 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
25262 dump_skb ("<<<", vc, skb);
25263
25264 // VC layer stats
25265 - atomic_inc(&atm_vcc->stats->rx);
25266 + atomic_inc_unchecked(&atm_vcc->stats->rx);
25267 __net_timestamp(skb);
25268 // end of our responsibility
25269 atm_vcc->push (atm_vcc, skb);
25270 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
25271 } else {
25272 PRINTK (KERN_INFO, "dropped over-size frame");
25273 // should we count this?
25274 - atomic_inc(&atm_vcc->stats->rx_drop);
25275 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25276 }
25277
25278 } else {
25279 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
25280 }
25281
25282 if (check_area (skb->data, skb->len)) {
25283 - atomic_inc(&atm_vcc->stats->tx_err);
25284 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
25285 return -ENOMEM; // ?
25286 }
25287
25288 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
25289 index b22d71c..d6e1049 100644
25290 --- a/drivers/atm/atmtcp.c
25291 +++ b/drivers/atm/atmtcp.c
25292 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25293 if (vcc->pop) vcc->pop(vcc,skb);
25294 else dev_kfree_skb(skb);
25295 if (dev_data) return 0;
25296 - atomic_inc(&vcc->stats->tx_err);
25297 + atomic_inc_unchecked(&vcc->stats->tx_err);
25298 return -ENOLINK;
25299 }
25300 size = skb->len+sizeof(struct atmtcp_hdr);
25301 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25302 if (!new_skb) {
25303 if (vcc->pop) vcc->pop(vcc,skb);
25304 else dev_kfree_skb(skb);
25305 - atomic_inc(&vcc->stats->tx_err);
25306 + atomic_inc_unchecked(&vcc->stats->tx_err);
25307 return -ENOBUFS;
25308 }
25309 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
25310 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25311 if (vcc->pop) vcc->pop(vcc,skb);
25312 else dev_kfree_skb(skb);
25313 out_vcc->push(out_vcc,new_skb);
25314 - atomic_inc(&vcc->stats->tx);
25315 - atomic_inc(&out_vcc->stats->rx);
25316 + atomic_inc_unchecked(&vcc->stats->tx);
25317 + atomic_inc_unchecked(&out_vcc->stats->rx);
25318 return 0;
25319 }
25320
25321 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
25322 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
25323 read_unlock(&vcc_sklist_lock);
25324 if (!out_vcc) {
25325 - atomic_inc(&vcc->stats->tx_err);
25326 + atomic_inc_unchecked(&vcc->stats->tx_err);
25327 goto done;
25328 }
25329 skb_pull(skb,sizeof(struct atmtcp_hdr));
25330 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
25331 __net_timestamp(new_skb);
25332 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
25333 out_vcc->push(out_vcc,new_skb);
25334 - atomic_inc(&vcc->stats->tx);
25335 - atomic_inc(&out_vcc->stats->rx);
25336 + atomic_inc_unchecked(&vcc->stats->tx);
25337 + atomic_inc_unchecked(&out_vcc->stats->rx);
25338 done:
25339 if (vcc->pop) vcc->pop(vcc,skb);
25340 else dev_kfree_skb(skb);
25341 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
25342 index 9307141..d8521bf 100644
25343 --- a/drivers/atm/eni.c
25344 +++ b/drivers/atm/eni.c
25345 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
25346 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
25347 vcc->dev->number);
25348 length = 0;
25349 - atomic_inc(&vcc->stats->rx_err);
25350 + atomic_inc_unchecked(&vcc->stats->rx_err);
25351 }
25352 else {
25353 length = ATM_CELL_SIZE-1; /* no HEC */
25354 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25355 size);
25356 }
25357 eff = length = 0;
25358 - atomic_inc(&vcc->stats->rx_err);
25359 + atomic_inc_unchecked(&vcc->stats->rx_err);
25360 }
25361 else {
25362 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
25363 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25364 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
25365 vcc->dev->number,vcc->vci,length,size << 2,descr);
25366 length = eff = 0;
25367 - atomic_inc(&vcc->stats->rx_err);
25368 + atomic_inc_unchecked(&vcc->stats->rx_err);
25369 }
25370 }
25371 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
25372 @@ -771,7 +771,7 @@ rx_dequeued++;
25373 vcc->push(vcc,skb);
25374 pushed++;
25375 }
25376 - atomic_inc(&vcc->stats->rx);
25377 + atomic_inc_unchecked(&vcc->stats->rx);
25378 }
25379 wake_up(&eni_dev->rx_wait);
25380 }
25381 @@ -1228,7 +1228,7 @@ static void dequeue_tx(struct atm_dev *dev)
25382 PCI_DMA_TODEVICE);
25383 if (vcc->pop) vcc->pop(vcc,skb);
25384 else dev_kfree_skb_irq(skb);
25385 - atomic_inc(&vcc->stats->tx);
25386 + atomic_inc_unchecked(&vcc->stats->tx);
25387 wake_up(&eni_dev->tx_wait);
25388 dma_complete++;
25389 }
25390 @@ -1568,7 +1568,7 @@ tx_complete++;
25391 /*--------------------------------- entries ---------------------------------*/
25392
25393
25394 -static const char *media_name[] __devinitdata = {
25395 +static const char *media_name[] __devinitconst = {
25396 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
25397 "UTP", "05?", "06?", "07?", /* 4- 7 */
25398 "TAXI","09?", "10?", "11?", /* 8-11 */
25399 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
25400 index 5072f8a..fa52520 100644
25401 --- a/drivers/atm/firestream.c
25402 +++ b/drivers/atm/firestream.c
25403 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
25404 }
25405 }
25406
25407 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25408 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25409
25410 fs_dprintk (FS_DEBUG_TXMEM, "i");
25411 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
25412 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
25413 #endif
25414 skb_put (skb, qe->p1 & 0xffff);
25415 ATM_SKB(skb)->vcc = atm_vcc;
25416 - atomic_inc(&atm_vcc->stats->rx);
25417 + atomic_inc_unchecked(&atm_vcc->stats->rx);
25418 __net_timestamp(skb);
25419 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
25420 atm_vcc->push (atm_vcc, skb);
25421 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
25422 kfree (pe);
25423 }
25424 if (atm_vcc)
25425 - atomic_inc(&atm_vcc->stats->rx_drop);
25426 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25427 break;
25428 case 0x1f: /* Reassembly abort: no buffers. */
25429 /* Silently increment error counter. */
25430 if (atm_vcc)
25431 - atomic_inc(&atm_vcc->stats->rx_drop);
25432 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25433 break;
25434 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
25435 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
25436 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
25437 index 361f5ae..7fc552d 100644
25438 --- a/drivers/atm/fore200e.c
25439 +++ b/drivers/atm/fore200e.c
25440 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
25441 #endif
25442 /* check error condition */
25443 if (*entry->status & STATUS_ERROR)
25444 - atomic_inc(&vcc->stats->tx_err);
25445 + atomic_inc_unchecked(&vcc->stats->tx_err);
25446 else
25447 - atomic_inc(&vcc->stats->tx);
25448 + atomic_inc_unchecked(&vcc->stats->tx);
25449 }
25450 }
25451
25452 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
25453 if (skb == NULL) {
25454 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
25455
25456 - atomic_inc(&vcc->stats->rx_drop);
25457 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25458 return -ENOMEM;
25459 }
25460
25461 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
25462
25463 dev_kfree_skb_any(skb);
25464
25465 - atomic_inc(&vcc->stats->rx_drop);
25466 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25467 return -ENOMEM;
25468 }
25469
25470 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25471
25472 vcc->push(vcc, skb);
25473 - atomic_inc(&vcc->stats->rx);
25474 + atomic_inc_unchecked(&vcc->stats->rx);
25475
25476 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25477
25478 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
25479 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
25480 fore200e->atm_dev->number,
25481 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
25482 - atomic_inc(&vcc->stats->rx_err);
25483 + atomic_inc_unchecked(&vcc->stats->rx_err);
25484 }
25485 }
25486
25487 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
25488 goto retry_here;
25489 }
25490
25491 - atomic_inc(&vcc->stats->tx_err);
25492 + atomic_inc_unchecked(&vcc->stats->tx_err);
25493
25494 fore200e->tx_sat++;
25495 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
25496 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
25497 index 9a51df4..f3bb5f8 100644
25498 --- a/drivers/atm/he.c
25499 +++ b/drivers/atm/he.c
25500 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25501
25502 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
25503 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
25504 - atomic_inc(&vcc->stats->rx_drop);
25505 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25506 goto return_host_buffers;
25507 }
25508
25509 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25510 RBRQ_LEN_ERR(he_dev->rbrq_head)
25511 ? "LEN_ERR" : "",
25512 vcc->vpi, vcc->vci);
25513 - atomic_inc(&vcc->stats->rx_err);
25514 + atomic_inc_unchecked(&vcc->stats->rx_err);
25515 goto return_host_buffers;
25516 }
25517
25518 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25519 vcc->push(vcc, skb);
25520 spin_lock(&he_dev->global_lock);
25521
25522 - atomic_inc(&vcc->stats->rx);
25523 + atomic_inc_unchecked(&vcc->stats->rx);
25524
25525 return_host_buffers:
25526 ++pdus_assembled;
25527 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
25528 tpd->vcc->pop(tpd->vcc, tpd->skb);
25529 else
25530 dev_kfree_skb_any(tpd->skb);
25531 - atomic_inc(&tpd->vcc->stats->tx_err);
25532 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
25533 }
25534 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
25535 return;
25536 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25537 vcc->pop(vcc, skb);
25538 else
25539 dev_kfree_skb_any(skb);
25540 - atomic_inc(&vcc->stats->tx_err);
25541 + atomic_inc_unchecked(&vcc->stats->tx_err);
25542 return -EINVAL;
25543 }
25544
25545 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25546 vcc->pop(vcc, skb);
25547 else
25548 dev_kfree_skb_any(skb);
25549 - atomic_inc(&vcc->stats->tx_err);
25550 + atomic_inc_unchecked(&vcc->stats->tx_err);
25551 return -EINVAL;
25552 }
25553 #endif
25554 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25555 vcc->pop(vcc, skb);
25556 else
25557 dev_kfree_skb_any(skb);
25558 - atomic_inc(&vcc->stats->tx_err);
25559 + atomic_inc_unchecked(&vcc->stats->tx_err);
25560 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25561 return -ENOMEM;
25562 }
25563 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25564 vcc->pop(vcc, skb);
25565 else
25566 dev_kfree_skb_any(skb);
25567 - atomic_inc(&vcc->stats->tx_err);
25568 + atomic_inc_unchecked(&vcc->stats->tx_err);
25569 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25570 return -ENOMEM;
25571 }
25572 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25573 __enqueue_tpd(he_dev, tpd, cid);
25574 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25575
25576 - atomic_inc(&vcc->stats->tx);
25577 + atomic_inc_unchecked(&vcc->stats->tx);
25578
25579 return 0;
25580 }
25581 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
25582 index b812103..e391a49 100644
25583 --- a/drivers/atm/horizon.c
25584 +++ b/drivers/atm/horizon.c
25585 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
25586 {
25587 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
25588 // VC layer stats
25589 - atomic_inc(&vcc->stats->rx);
25590 + atomic_inc_unchecked(&vcc->stats->rx);
25591 __net_timestamp(skb);
25592 // end of our responsibility
25593 vcc->push (vcc, skb);
25594 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
25595 dev->tx_iovec = NULL;
25596
25597 // VC layer stats
25598 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25599 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25600
25601 // free the skb
25602 hrz_kfree_skb (skb);
25603 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
25604 index db06f34..dcebb61 100644
25605 --- a/drivers/atm/idt77252.c
25606 +++ b/drivers/atm/idt77252.c
25607 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
25608 else
25609 dev_kfree_skb(skb);
25610
25611 - atomic_inc(&vcc->stats->tx);
25612 + atomic_inc_unchecked(&vcc->stats->tx);
25613 }
25614
25615 atomic_dec(&scq->used);
25616 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25617 if ((sb = dev_alloc_skb(64)) == NULL) {
25618 printk("%s: Can't allocate buffers for aal0.\n",
25619 card->name);
25620 - atomic_add(i, &vcc->stats->rx_drop);
25621 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
25622 break;
25623 }
25624 if (!atm_charge(vcc, sb->truesize)) {
25625 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
25626 card->name);
25627 - atomic_add(i - 1, &vcc->stats->rx_drop);
25628 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
25629 dev_kfree_skb(sb);
25630 break;
25631 }
25632 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25633 ATM_SKB(sb)->vcc = vcc;
25634 __net_timestamp(sb);
25635 vcc->push(vcc, sb);
25636 - atomic_inc(&vcc->stats->rx);
25637 + atomic_inc_unchecked(&vcc->stats->rx);
25638
25639 cell += ATM_CELL_PAYLOAD;
25640 }
25641 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25642 "(CDC: %08x)\n",
25643 card->name, len, rpp->len, readl(SAR_REG_CDC));
25644 recycle_rx_pool_skb(card, rpp);
25645 - atomic_inc(&vcc->stats->rx_err);
25646 + atomic_inc_unchecked(&vcc->stats->rx_err);
25647 return;
25648 }
25649 if (stat & SAR_RSQE_CRC) {
25650 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
25651 recycle_rx_pool_skb(card, rpp);
25652 - atomic_inc(&vcc->stats->rx_err);
25653 + atomic_inc_unchecked(&vcc->stats->rx_err);
25654 return;
25655 }
25656 if (skb_queue_len(&rpp->queue) > 1) {
25657 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25658 RXPRINTK("%s: Can't alloc RX skb.\n",
25659 card->name);
25660 recycle_rx_pool_skb(card, rpp);
25661 - atomic_inc(&vcc->stats->rx_err);
25662 + atomic_inc_unchecked(&vcc->stats->rx_err);
25663 return;
25664 }
25665 if (!atm_charge(vcc, skb->truesize)) {
25666 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25667 __net_timestamp(skb);
25668
25669 vcc->push(vcc, skb);
25670 - atomic_inc(&vcc->stats->rx);
25671 + atomic_inc_unchecked(&vcc->stats->rx);
25672
25673 return;
25674 }
25675 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25676 __net_timestamp(skb);
25677
25678 vcc->push(vcc, skb);
25679 - atomic_inc(&vcc->stats->rx);
25680 + atomic_inc_unchecked(&vcc->stats->rx);
25681
25682 if (skb->truesize > SAR_FB_SIZE_3)
25683 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
25684 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
25685 if (vcc->qos.aal != ATM_AAL0) {
25686 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
25687 card->name, vpi, vci);
25688 - atomic_inc(&vcc->stats->rx_drop);
25689 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25690 goto drop;
25691 }
25692
25693 if ((sb = dev_alloc_skb(64)) == NULL) {
25694 printk("%s: Can't allocate buffers for AAL0.\n",
25695 card->name);
25696 - atomic_inc(&vcc->stats->rx_err);
25697 + atomic_inc_unchecked(&vcc->stats->rx_err);
25698 goto drop;
25699 }
25700
25701 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
25702 ATM_SKB(sb)->vcc = vcc;
25703 __net_timestamp(sb);
25704 vcc->push(vcc, sb);
25705 - atomic_inc(&vcc->stats->rx);
25706 + atomic_inc_unchecked(&vcc->stats->rx);
25707
25708 drop:
25709 skb_pull(queue, 64);
25710 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25711
25712 if (vc == NULL) {
25713 printk("%s: NULL connection in send().\n", card->name);
25714 - atomic_inc(&vcc->stats->tx_err);
25715 + atomic_inc_unchecked(&vcc->stats->tx_err);
25716 dev_kfree_skb(skb);
25717 return -EINVAL;
25718 }
25719 if (!test_bit(VCF_TX, &vc->flags)) {
25720 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
25721 - atomic_inc(&vcc->stats->tx_err);
25722 + atomic_inc_unchecked(&vcc->stats->tx_err);
25723 dev_kfree_skb(skb);
25724 return -EINVAL;
25725 }
25726 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25727 break;
25728 default:
25729 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
25730 - atomic_inc(&vcc->stats->tx_err);
25731 + atomic_inc_unchecked(&vcc->stats->tx_err);
25732 dev_kfree_skb(skb);
25733 return -EINVAL;
25734 }
25735
25736 if (skb_shinfo(skb)->nr_frags != 0) {
25737 printk("%s: No scatter-gather yet.\n", card->name);
25738 - atomic_inc(&vcc->stats->tx_err);
25739 + atomic_inc_unchecked(&vcc->stats->tx_err);
25740 dev_kfree_skb(skb);
25741 return -EINVAL;
25742 }
25743 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25744
25745 err = queue_skb(card, vc, skb, oam);
25746 if (err) {
25747 - atomic_inc(&vcc->stats->tx_err);
25748 + atomic_inc_unchecked(&vcc->stats->tx_err);
25749 dev_kfree_skb(skb);
25750 return err;
25751 }
25752 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
25753 skb = dev_alloc_skb(64);
25754 if (!skb) {
25755 printk("%s: Out of memory in send_oam().\n", card->name);
25756 - atomic_inc(&vcc->stats->tx_err);
25757 + atomic_inc_unchecked(&vcc->stats->tx_err);
25758 return -ENOMEM;
25759 }
25760 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
25761 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
25762 index cb90f7a..bd33566 100644
25763 --- a/drivers/atm/iphase.c
25764 +++ b/drivers/atm/iphase.c
25765 @@ -1121,7 +1121,7 @@ static int rx_pkt(struct atm_dev *dev)
25766 status = (u_short) (buf_desc_ptr->desc_mode);
25767 if (status & (RX_CER | RX_PTE | RX_OFL))
25768 {
25769 - atomic_inc(&vcc->stats->rx_err);
25770 + atomic_inc_unchecked(&vcc->stats->rx_err);
25771 IF_ERR(printk("IA: bad packet, dropping it");)
25772 if (status & RX_CER) {
25773 IF_ERR(printk(" cause: packet CRC error\n");)
25774 @@ -1144,7 +1144,7 @@ static int rx_pkt(struct atm_dev *dev)
25775 len = dma_addr - buf_addr;
25776 if (len > iadev->rx_buf_sz) {
25777 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
25778 - atomic_inc(&vcc->stats->rx_err);
25779 + atomic_inc_unchecked(&vcc->stats->rx_err);
25780 goto out_free_desc;
25781 }
25782
25783 @@ -1294,7 +1294,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25784 ia_vcc = INPH_IA_VCC(vcc);
25785 if (ia_vcc == NULL)
25786 {
25787 - atomic_inc(&vcc->stats->rx_err);
25788 + atomic_inc_unchecked(&vcc->stats->rx_err);
25789 dev_kfree_skb_any(skb);
25790 atm_return(vcc, atm_guess_pdu2truesize(len));
25791 goto INCR_DLE;
25792 @@ -1306,7 +1306,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25793 if ((length > iadev->rx_buf_sz) || (length >
25794 (skb->len - sizeof(struct cpcs_trailer))))
25795 {
25796 - atomic_inc(&vcc->stats->rx_err);
25797 + atomic_inc_unchecked(&vcc->stats->rx_err);
25798 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
25799 length, skb->len);)
25800 dev_kfree_skb_any(skb);
25801 @@ -1322,7 +1322,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25802
25803 IF_RX(printk("rx_dle_intr: skb push");)
25804 vcc->push(vcc,skb);
25805 - atomic_inc(&vcc->stats->rx);
25806 + atomic_inc_unchecked(&vcc->stats->rx);
25807 iadev->rx_pkt_cnt++;
25808 }
25809 INCR_DLE:
25810 @@ -2802,15 +2802,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
25811 {
25812 struct k_sonet_stats *stats;
25813 stats = &PRIV(_ia_dev[board])->sonet_stats;
25814 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
25815 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
25816 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
25817 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
25818 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
25819 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
25820 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
25821 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
25822 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
25823 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
25824 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
25825 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
25826 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
25827 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
25828 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
25829 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
25830 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
25831 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
25832 }
25833 ia_cmds.status = 0;
25834 break;
25835 @@ -2915,7 +2915,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
25836 if ((desc == 0) || (desc > iadev->num_tx_desc))
25837 {
25838 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
25839 - atomic_inc(&vcc->stats->tx);
25840 + atomic_inc_unchecked(&vcc->stats->tx);
25841 if (vcc->pop)
25842 vcc->pop(vcc, skb);
25843 else
25844 @@ -3020,14 +3020,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
25845 ATM_DESC(skb) = vcc->vci;
25846 skb_queue_tail(&iadev->tx_dma_q, skb);
25847
25848 - atomic_inc(&vcc->stats->tx);
25849 + atomic_inc_unchecked(&vcc->stats->tx);
25850 iadev->tx_pkt_cnt++;
25851 /* Increment transaction counter */
25852 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
25853
25854 #if 0
25855 /* add flow control logic */
25856 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
25857 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
25858 if (iavcc->vc_desc_cnt > 10) {
25859 vcc->tx_quota = vcc->tx_quota * 3 / 4;
25860 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
25861 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
25862 index e828c54..ae83976 100644
25863 --- a/drivers/atm/lanai.c
25864 +++ b/drivers/atm/lanai.c
25865 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
25866 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
25867 lanai_endtx(lanai, lvcc);
25868 lanai_free_skb(lvcc->tx.atmvcc, skb);
25869 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
25870 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
25871 }
25872
25873 /* Try to fill the buffer - don't call unless there is backlog */
25874 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
25875 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
25876 __net_timestamp(skb);
25877 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
25878 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
25879 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
25880 out:
25881 lvcc->rx.buf.ptr = end;
25882 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
25883 @@ -1668,7 +1668,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25884 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
25885 "vcc %d\n", lanai->number, (unsigned int) s, vci);
25886 lanai->stats.service_rxnotaal5++;
25887 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25888 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25889 return 0;
25890 }
25891 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
25892 @@ -1680,7 +1680,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25893 int bytes;
25894 read_unlock(&vcc_sklist_lock);
25895 DPRINTK("got trashed rx pdu on vci %d\n", vci);
25896 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25897 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25898 lvcc->stats.x.aal5.service_trash++;
25899 bytes = (SERVICE_GET_END(s) * 16) -
25900 (((unsigned long) lvcc->rx.buf.ptr) -
25901 @@ -1692,7 +1692,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25902 }
25903 if (s & SERVICE_STREAM) {
25904 read_unlock(&vcc_sklist_lock);
25905 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25906 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25907 lvcc->stats.x.aal5.service_stream++;
25908 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
25909 "PDU on VCI %d!\n", lanai->number, vci);
25910 @@ -1700,7 +1700,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25911 return 0;
25912 }
25913 DPRINTK("got rx crc error on vci %d\n", vci);
25914 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25915 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25916 lvcc->stats.x.aal5.service_rxcrc++;
25917 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
25918 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
25919 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
25920 index 1c70c45..300718d 100644
25921 --- a/drivers/atm/nicstar.c
25922 +++ b/drivers/atm/nicstar.c
25923 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25924 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
25925 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
25926 card->index);
25927 - atomic_inc(&vcc->stats->tx_err);
25928 + atomic_inc_unchecked(&vcc->stats->tx_err);
25929 dev_kfree_skb_any(skb);
25930 return -EINVAL;
25931 }
25932 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25933 if (!vc->tx) {
25934 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
25935 card->index);
25936 - atomic_inc(&vcc->stats->tx_err);
25937 + atomic_inc_unchecked(&vcc->stats->tx_err);
25938 dev_kfree_skb_any(skb);
25939 return -EINVAL;
25940 }
25941 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25942 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
25943 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
25944 card->index);
25945 - atomic_inc(&vcc->stats->tx_err);
25946 + atomic_inc_unchecked(&vcc->stats->tx_err);
25947 dev_kfree_skb_any(skb);
25948 return -EINVAL;
25949 }
25950
25951 if (skb_shinfo(skb)->nr_frags != 0) {
25952 printk("nicstar%d: No scatter-gather yet.\n", card->index);
25953 - atomic_inc(&vcc->stats->tx_err);
25954 + atomic_inc_unchecked(&vcc->stats->tx_err);
25955 dev_kfree_skb_any(skb);
25956 return -EINVAL;
25957 }
25958 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25959 }
25960
25961 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
25962 - atomic_inc(&vcc->stats->tx_err);
25963 + atomic_inc_unchecked(&vcc->stats->tx_err);
25964 dev_kfree_skb_any(skb);
25965 return -EIO;
25966 }
25967 - atomic_inc(&vcc->stats->tx);
25968 + atomic_inc_unchecked(&vcc->stats->tx);
25969
25970 return 0;
25971 }
25972 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
25973 printk
25974 ("nicstar%d: Can't allocate buffers for aal0.\n",
25975 card->index);
25976 - atomic_add(i, &vcc->stats->rx_drop);
25977 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
25978 break;
25979 }
25980 if (!atm_charge(vcc, sb->truesize)) {
25981 RXPRINTK
25982 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
25983 card->index);
25984 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
25985 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
25986 dev_kfree_skb_any(sb);
25987 break;
25988 }
25989 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
25990 ATM_SKB(sb)->vcc = vcc;
25991 __net_timestamp(sb);
25992 vcc->push(vcc, sb);
25993 - atomic_inc(&vcc->stats->rx);
25994 + atomic_inc_unchecked(&vcc->stats->rx);
25995 cell += ATM_CELL_PAYLOAD;
25996 }
25997
25998 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
25999 if (iovb == NULL) {
26000 printk("nicstar%d: Out of iovec buffers.\n",
26001 card->index);
26002 - atomic_inc(&vcc->stats->rx_drop);
26003 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26004 recycle_rx_buf(card, skb);
26005 return;
26006 }
26007 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26008 small or large buffer itself. */
26009 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
26010 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
26011 - atomic_inc(&vcc->stats->rx_err);
26012 + atomic_inc_unchecked(&vcc->stats->rx_err);
26013 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26014 NS_MAX_IOVECS);
26015 NS_PRV_IOVCNT(iovb) = 0;
26016 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26017 ("nicstar%d: Expected a small buffer, and this is not one.\n",
26018 card->index);
26019 which_list(card, skb);
26020 - atomic_inc(&vcc->stats->rx_err);
26021 + atomic_inc_unchecked(&vcc->stats->rx_err);
26022 recycle_rx_buf(card, skb);
26023 vc->rx_iov = NULL;
26024 recycle_iov_buf(card, iovb);
26025 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26026 ("nicstar%d: Expected a large buffer, and this is not one.\n",
26027 card->index);
26028 which_list(card, skb);
26029 - atomic_inc(&vcc->stats->rx_err);
26030 + atomic_inc_unchecked(&vcc->stats->rx_err);
26031 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26032 NS_PRV_IOVCNT(iovb));
26033 vc->rx_iov = NULL;
26034 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26035 printk(" - PDU size mismatch.\n");
26036 else
26037 printk(".\n");
26038 - atomic_inc(&vcc->stats->rx_err);
26039 + atomic_inc_unchecked(&vcc->stats->rx_err);
26040 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26041 NS_PRV_IOVCNT(iovb));
26042 vc->rx_iov = NULL;
26043 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26044 /* skb points to a small buffer */
26045 if (!atm_charge(vcc, skb->truesize)) {
26046 push_rxbufs(card, skb);
26047 - atomic_inc(&vcc->stats->rx_drop);
26048 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26049 } else {
26050 skb_put(skb, len);
26051 dequeue_sm_buf(card, skb);
26052 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26053 ATM_SKB(skb)->vcc = vcc;
26054 __net_timestamp(skb);
26055 vcc->push(vcc, skb);
26056 - atomic_inc(&vcc->stats->rx);
26057 + atomic_inc_unchecked(&vcc->stats->rx);
26058 }
26059 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
26060 struct sk_buff *sb;
26061 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26062 if (len <= NS_SMBUFSIZE) {
26063 if (!atm_charge(vcc, sb->truesize)) {
26064 push_rxbufs(card, sb);
26065 - atomic_inc(&vcc->stats->rx_drop);
26066 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26067 } else {
26068 skb_put(sb, len);
26069 dequeue_sm_buf(card, sb);
26070 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26071 ATM_SKB(sb)->vcc = vcc;
26072 __net_timestamp(sb);
26073 vcc->push(vcc, sb);
26074 - atomic_inc(&vcc->stats->rx);
26075 + atomic_inc_unchecked(&vcc->stats->rx);
26076 }
26077
26078 push_rxbufs(card, skb);
26079 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26080
26081 if (!atm_charge(vcc, skb->truesize)) {
26082 push_rxbufs(card, skb);
26083 - atomic_inc(&vcc->stats->rx_drop);
26084 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26085 } else {
26086 dequeue_lg_buf(card, skb);
26087 #ifdef NS_USE_DESTRUCTORS
26088 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26089 ATM_SKB(skb)->vcc = vcc;
26090 __net_timestamp(skb);
26091 vcc->push(vcc, skb);
26092 - atomic_inc(&vcc->stats->rx);
26093 + atomic_inc_unchecked(&vcc->stats->rx);
26094 }
26095
26096 push_rxbufs(card, sb);
26097 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26098 printk
26099 ("nicstar%d: Out of huge buffers.\n",
26100 card->index);
26101 - atomic_inc(&vcc->stats->rx_drop);
26102 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26103 recycle_iovec_rx_bufs(card,
26104 (struct iovec *)
26105 iovb->data,
26106 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26107 card->hbpool.count++;
26108 } else
26109 dev_kfree_skb_any(hb);
26110 - atomic_inc(&vcc->stats->rx_drop);
26111 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26112 } else {
26113 /* Copy the small buffer to the huge buffer */
26114 sb = (struct sk_buff *)iov->iov_base;
26115 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26116 #endif /* NS_USE_DESTRUCTORS */
26117 __net_timestamp(hb);
26118 vcc->push(vcc, hb);
26119 - atomic_inc(&vcc->stats->rx);
26120 + atomic_inc_unchecked(&vcc->stats->rx);
26121 }
26122 }
26123
26124 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
26125 index 5d1d076..4f31f42 100644
26126 --- a/drivers/atm/solos-pci.c
26127 +++ b/drivers/atm/solos-pci.c
26128 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
26129 }
26130 atm_charge(vcc, skb->truesize);
26131 vcc->push(vcc, skb);
26132 - atomic_inc(&vcc->stats->rx);
26133 + atomic_inc_unchecked(&vcc->stats->rx);
26134 break;
26135
26136 case PKT_STATUS:
26137 @@ -899,6 +899,8 @@ static int print_buffer(struct sk_buff *buf)
26138 char msg[500];
26139 char item[10];
26140
26141 + pax_track_stack();
26142 +
26143 len = buf->len;
26144 for (i = 0; i < len; i++){
26145 if(i % 8 == 0)
26146 @@ -1008,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_card *card)
26147 vcc = SKB_CB(oldskb)->vcc;
26148
26149 if (vcc) {
26150 - atomic_inc(&vcc->stats->tx);
26151 + atomic_inc_unchecked(&vcc->stats->tx);
26152 solos_pop(vcc, oldskb);
26153 } else
26154 dev_kfree_skb_irq(oldskb);
26155 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
26156 index 90f1ccc..04c4a1e 100644
26157 --- a/drivers/atm/suni.c
26158 +++ b/drivers/atm/suni.c
26159 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
26160
26161
26162 #define ADD_LIMITED(s,v) \
26163 - atomic_add((v),&stats->s); \
26164 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
26165 + atomic_add_unchecked((v),&stats->s); \
26166 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
26167
26168
26169 static void suni_hz(unsigned long from_timer)
26170 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
26171 index 5120a96..e2572bd 100644
26172 --- a/drivers/atm/uPD98402.c
26173 +++ b/drivers/atm/uPD98402.c
26174 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
26175 struct sonet_stats tmp;
26176 int error = 0;
26177
26178 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26179 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26180 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
26181 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
26182 if (zero && !error) {
26183 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
26184
26185
26186 #define ADD_LIMITED(s,v) \
26187 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
26188 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
26189 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26190 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
26191 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
26192 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26193
26194
26195 static void stat_event(struct atm_dev *dev)
26196 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
26197 if (reason & uPD98402_INT_PFM) stat_event(dev);
26198 if (reason & uPD98402_INT_PCO) {
26199 (void) GET(PCOCR); /* clear interrupt cause */
26200 - atomic_add(GET(HECCT),
26201 + atomic_add_unchecked(GET(HECCT),
26202 &PRIV(dev)->sonet_stats.uncorr_hcs);
26203 }
26204 if ((reason & uPD98402_INT_RFO) &&
26205 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
26206 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
26207 uPD98402_INT_LOS),PIMR); /* enable them */
26208 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
26209 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26210 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
26211 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
26212 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26213 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
26214 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
26215 return 0;
26216 }
26217
26218 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
26219 index d889f56..17eb71e 100644
26220 --- a/drivers/atm/zatm.c
26221 +++ b/drivers/atm/zatm.c
26222 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
26223 }
26224 if (!size) {
26225 dev_kfree_skb_irq(skb);
26226 - if (vcc) atomic_inc(&vcc->stats->rx_err);
26227 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
26228 continue;
26229 }
26230 if (!atm_charge(vcc,skb->truesize)) {
26231 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
26232 skb->len = size;
26233 ATM_SKB(skb)->vcc = vcc;
26234 vcc->push(vcc,skb);
26235 - atomic_inc(&vcc->stats->rx);
26236 + atomic_inc_unchecked(&vcc->stats->rx);
26237 }
26238 zout(pos & 0xffff,MTA(mbx));
26239 #if 0 /* probably a stupid idea */
26240 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
26241 skb_queue_head(&zatm_vcc->backlog,skb);
26242 break;
26243 }
26244 - atomic_inc(&vcc->stats->tx);
26245 + atomic_inc_unchecked(&vcc->stats->tx);
26246 wake_up(&zatm_vcc->tx_wait);
26247 }
26248
26249 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
26250 index a4760e0..51283cf 100644
26251 --- a/drivers/base/devtmpfs.c
26252 +++ b/drivers/base/devtmpfs.c
26253 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
26254 if (!thread)
26255 return 0;
26256
26257 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
26258 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
26259 if (err)
26260 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
26261 else
26262 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
26263 index 84f7c7d..37cfd87 100644
26264 --- a/drivers/base/power/wakeup.c
26265 +++ b/drivers/base/power/wakeup.c
26266 @@ -29,14 +29,14 @@ bool events_check_enabled;
26267 * They need to be modified together atomically, so it's better to use one
26268 * atomic variable to hold them both.
26269 */
26270 -static atomic_t combined_event_count = ATOMIC_INIT(0);
26271 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
26272
26273 #define IN_PROGRESS_BITS (sizeof(int) * 4)
26274 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
26275
26276 static void split_counters(unsigned int *cnt, unsigned int *inpr)
26277 {
26278 - unsigned int comb = atomic_read(&combined_event_count);
26279 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
26280
26281 *cnt = (comb >> IN_PROGRESS_BITS);
26282 *inpr = comb & MAX_IN_PROGRESS;
26283 @@ -350,7 +350,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
26284 ws->last_time = ktime_get();
26285
26286 /* Increment the counter of events in progress. */
26287 - atomic_inc(&combined_event_count);
26288 + atomic_inc_unchecked(&combined_event_count);
26289 }
26290
26291 /**
26292 @@ -440,7 +440,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
26293 * Increment the counter of registered wakeup events and decrement the
26294 * couter of wakeup events in progress simultaneously.
26295 */
26296 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
26297 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
26298 }
26299
26300 /**
26301 diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
26302 index e086fbb..398e1fe 100644
26303 --- a/drivers/block/DAC960.c
26304 +++ b/drivers/block/DAC960.c
26305 @@ -1980,6 +1980,8 @@ static bool DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
26306 unsigned long flags;
26307 int Channel, TargetID;
26308
26309 + pax_track_stack();
26310 +
26311 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
26312 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
26313 sizeof(DAC960_SCSI_Inquiry_T) +
26314 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
26315 index c2f9b3e..5911988 100644
26316 --- a/drivers/block/cciss.c
26317 +++ b/drivers/block/cciss.c
26318 @@ -1179,6 +1179,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
26319 int err;
26320 u32 cp;
26321
26322 + memset(&arg64, 0, sizeof(arg64));
26323 +
26324 err = 0;
26325 err |=
26326 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
26327 @@ -2986,7 +2988,7 @@ static void start_io(ctlr_info_t *h)
26328 while (!list_empty(&h->reqQ)) {
26329 c = list_entry(h->reqQ.next, CommandList_struct, list);
26330 /* can't do anything if fifo is full */
26331 - if ((h->access.fifo_full(h))) {
26332 + if ((h->access->fifo_full(h))) {
26333 dev_warn(&h->pdev->dev, "fifo full\n");
26334 break;
26335 }
26336 @@ -2996,7 +2998,7 @@ static void start_io(ctlr_info_t *h)
26337 h->Qdepth--;
26338
26339 /* Tell the controller execute command */
26340 - h->access.submit_command(h, c);
26341 + h->access->submit_command(h, c);
26342
26343 /* Put job onto the completed Q */
26344 addQ(&h->cmpQ, c);
26345 @@ -3422,17 +3424,17 @@ startio:
26346
26347 static inline unsigned long get_next_completion(ctlr_info_t *h)
26348 {
26349 - return h->access.command_completed(h);
26350 + return h->access->command_completed(h);
26351 }
26352
26353 static inline int interrupt_pending(ctlr_info_t *h)
26354 {
26355 - return h->access.intr_pending(h);
26356 + return h->access->intr_pending(h);
26357 }
26358
26359 static inline long interrupt_not_for_us(ctlr_info_t *h)
26360 {
26361 - return ((h->access.intr_pending(h) == 0) ||
26362 + return ((h->access->intr_pending(h) == 0) ||
26363 (h->interrupts_enabled == 0));
26364 }
26365
26366 @@ -3465,7 +3467,7 @@ static inline u32 next_command(ctlr_info_t *h)
26367 u32 a;
26368
26369 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
26370 - return h->access.command_completed(h);
26371 + return h->access->command_completed(h);
26372
26373 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
26374 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
26375 @@ -4020,7 +4022,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
26376 trans_support & CFGTBL_Trans_use_short_tags);
26377
26378 /* Change the access methods to the performant access methods */
26379 - h->access = SA5_performant_access;
26380 + h->access = &SA5_performant_access;
26381 h->transMethod = CFGTBL_Trans_Performant;
26382
26383 return;
26384 @@ -4292,7 +4294,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
26385 if (prod_index < 0)
26386 return -ENODEV;
26387 h->product_name = products[prod_index].product_name;
26388 - h->access = *(products[prod_index].access);
26389 + h->access = products[prod_index].access;
26390
26391 if (cciss_board_disabled(h)) {
26392 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
26393 @@ -5009,7 +5011,7 @@ reinit_after_soft_reset:
26394 }
26395
26396 /* make sure the board interrupts are off */
26397 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26398 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26399 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
26400 if (rc)
26401 goto clean2;
26402 @@ -5061,7 +5063,7 @@ reinit_after_soft_reset:
26403 * fake ones to scoop up any residual completions.
26404 */
26405 spin_lock_irqsave(&h->lock, flags);
26406 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26407 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26408 spin_unlock_irqrestore(&h->lock, flags);
26409 free_irq(h->intr[PERF_MODE_INT], h);
26410 rc = cciss_request_irq(h, cciss_msix_discard_completions,
26411 @@ -5081,9 +5083,9 @@ reinit_after_soft_reset:
26412 dev_info(&h->pdev->dev, "Board READY.\n");
26413 dev_info(&h->pdev->dev,
26414 "Waiting for stale completions to drain.\n");
26415 - h->access.set_intr_mask(h, CCISS_INTR_ON);
26416 + h->access->set_intr_mask(h, CCISS_INTR_ON);
26417 msleep(10000);
26418 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26419 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26420
26421 rc = controller_reset_failed(h->cfgtable);
26422 if (rc)
26423 @@ -5106,7 +5108,7 @@ reinit_after_soft_reset:
26424 cciss_scsi_setup(h);
26425
26426 /* Turn the interrupts on so we can service requests */
26427 - h->access.set_intr_mask(h, CCISS_INTR_ON);
26428 + h->access->set_intr_mask(h, CCISS_INTR_ON);
26429
26430 /* Get the firmware version */
26431 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
26432 @@ -5178,7 +5180,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
26433 kfree(flush_buf);
26434 if (return_code != IO_OK)
26435 dev_warn(&h->pdev->dev, "Error flushing cache\n");
26436 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26437 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26438 free_irq(h->intr[PERF_MODE_INT], h);
26439 }
26440
26441 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
26442 index c049548..a09cb6e 100644
26443 --- a/drivers/block/cciss.h
26444 +++ b/drivers/block/cciss.h
26445 @@ -100,7 +100,7 @@ struct ctlr_info
26446 /* information about each logical volume */
26447 drive_info_struct *drv[CISS_MAX_LUN];
26448
26449 - struct access_method access;
26450 + struct access_method *access;
26451
26452 /* queue and queue Info */
26453 struct list_head reqQ;
26454 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
26455 index b2fceb5..87fec83 100644
26456 --- a/drivers/block/cpqarray.c
26457 +++ b/drivers/block/cpqarray.c
26458 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
26459 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
26460 goto Enomem4;
26461 }
26462 - hba[i]->access.set_intr_mask(hba[i], 0);
26463 + hba[i]->access->set_intr_mask(hba[i], 0);
26464 if (request_irq(hba[i]->intr, do_ida_intr,
26465 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
26466 {
26467 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
26468 add_timer(&hba[i]->timer);
26469
26470 /* Enable IRQ now that spinlock and rate limit timer are set up */
26471 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
26472 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
26473
26474 for(j=0; j<NWD; j++) {
26475 struct gendisk *disk = ida_gendisk[i][j];
26476 @@ -694,7 +694,7 @@ DBGINFO(
26477 for(i=0; i<NR_PRODUCTS; i++) {
26478 if (board_id == products[i].board_id) {
26479 c->product_name = products[i].product_name;
26480 - c->access = *(products[i].access);
26481 + c->access = products[i].access;
26482 break;
26483 }
26484 }
26485 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
26486 hba[ctlr]->intr = intr;
26487 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
26488 hba[ctlr]->product_name = products[j].product_name;
26489 - hba[ctlr]->access = *(products[j].access);
26490 + hba[ctlr]->access = products[j].access;
26491 hba[ctlr]->ctlr = ctlr;
26492 hba[ctlr]->board_id = board_id;
26493 hba[ctlr]->pci_dev = NULL; /* not PCI */
26494 @@ -911,6 +911,8 @@ static void do_ida_request(struct request_queue *q)
26495 struct scatterlist tmp_sg[SG_MAX];
26496 int i, dir, seg;
26497
26498 + pax_track_stack();
26499 +
26500 queue_next:
26501 creq = blk_peek_request(q);
26502 if (!creq)
26503 @@ -980,7 +982,7 @@ static void start_io(ctlr_info_t *h)
26504
26505 while((c = h->reqQ) != NULL) {
26506 /* Can't do anything if we're busy */
26507 - if (h->access.fifo_full(h) == 0)
26508 + if (h->access->fifo_full(h) == 0)
26509 return;
26510
26511 /* Get the first entry from the request Q */
26512 @@ -988,7 +990,7 @@ static void start_io(ctlr_info_t *h)
26513 h->Qdepth--;
26514
26515 /* Tell the controller to do our bidding */
26516 - h->access.submit_command(h, c);
26517 + h->access->submit_command(h, c);
26518
26519 /* Get onto the completion Q */
26520 addQ(&h->cmpQ, c);
26521 @@ -1050,7 +1052,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
26522 unsigned long flags;
26523 __u32 a,a1;
26524
26525 - istat = h->access.intr_pending(h);
26526 + istat = h->access->intr_pending(h);
26527 /* Is this interrupt for us? */
26528 if (istat == 0)
26529 return IRQ_NONE;
26530 @@ -1061,7 +1063,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
26531 */
26532 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
26533 if (istat & FIFO_NOT_EMPTY) {
26534 - while((a = h->access.command_completed(h))) {
26535 + while((a = h->access->command_completed(h))) {
26536 a1 = a; a &= ~3;
26537 if ((c = h->cmpQ) == NULL)
26538 {
26539 @@ -1449,11 +1451,11 @@ static int sendcmd(
26540 /*
26541 * Disable interrupt
26542 */
26543 - info_p->access.set_intr_mask(info_p, 0);
26544 + info_p->access->set_intr_mask(info_p, 0);
26545 /* Make sure there is room in the command FIFO */
26546 /* Actually it should be completely empty at this time. */
26547 for (i = 200000; i > 0; i--) {
26548 - temp = info_p->access.fifo_full(info_p);
26549 + temp = info_p->access->fifo_full(info_p);
26550 if (temp != 0) {
26551 break;
26552 }
26553 @@ -1466,7 +1468,7 @@ DBG(
26554 /*
26555 * Send the cmd
26556 */
26557 - info_p->access.submit_command(info_p, c);
26558 + info_p->access->submit_command(info_p, c);
26559 complete = pollcomplete(ctlr);
26560
26561 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
26562 @@ -1549,9 +1551,9 @@ static int revalidate_allvol(ctlr_info_t *host)
26563 * we check the new geometry. Then turn interrupts back on when
26564 * we're done.
26565 */
26566 - host->access.set_intr_mask(host, 0);
26567 + host->access->set_intr_mask(host, 0);
26568 getgeometry(ctlr);
26569 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
26570 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
26571
26572 for(i=0; i<NWD; i++) {
26573 struct gendisk *disk = ida_gendisk[ctlr][i];
26574 @@ -1591,7 +1593,7 @@ static int pollcomplete(int ctlr)
26575 /* Wait (up to 2 seconds) for a command to complete */
26576
26577 for (i = 200000; i > 0; i--) {
26578 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
26579 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
26580 if (done == 0) {
26581 udelay(10); /* a short fixed delay */
26582 } else
26583 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
26584 index be73e9d..7fbf140 100644
26585 --- a/drivers/block/cpqarray.h
26586 +++ b/drivers/block/cpqarray.h
26587 @@ -99,7 +99,7 @@ struct ctlr_info {
26588 drv_info_t drv[NWD];
26589 struct proc_dir_entry *proc;
26590
26591 - struct access_method access;
26592 + struct access_method *access;
26593
26594 cmdlist_t *reqQ;
26595 cmdlist_t *cmpQ;
26596 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
26597 index ef2ceed..c9cb18e 100644
26598 --- a/drivers/block/drbd/drbd_int.h
26599 +++ b/drivers/block/drbd/drbd_int.h
26600 @@ -737,7 +737,7 @@ struct drbd_request;
26601 struct drbd_epoch {
26602 struct list_head list;
26603 unsigned int barrier_nr;
26604 - atomic_t epoch_size; /* increased on every request added. */
26605 + atomic_unchecked_t epoch_size; /* increased on every request added. */
26606 atomic_t active; /* increased on every req. added, and dec on every finished. */
26607 unsigned long flags;
26608 };
26609 @@ -1109,7 +1109,7 @@ struct drbd_conf {
26610 void *int_dig_in;
26611 void *int_dig_vv;
26612 wait_queue_head_t seq_wait;
26613 - atomic_t packet_seq;
26614 + atomic_unchecked_t packet_seq;
26615 unsigned int peer_seq;
26616 spinlock_t peer_seq_lock;
26617 unsigned int minor;
26618 @@ -1618,30 +1618,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
26619
26620 static inline void drbd_tcp_cork(struct socket *sock)
26621 {
26622 - int __user val = 1;
26623 + int val = 1;
26624 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
26625 - (char __user *)&val, sizeof(val));
26626 + (char __force_user *)&val, sizeof(val));
26627 }
26628
26629 static inline void drbd_tcp_uncork(struct socket *sock)
26630 {
26631 - int __user val = 0;
26632 + int val = 0;
26633 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
26634 - (char __user *)&val, sizeof(val));
26635 + (char __force_user *)&val, sizeof(val));
26636 }
26637
26638 static inline void drbd_tcp_nodelay(struct socket *sock)
26639 {
26640 - int __user val = 1;
26641 + int val = 1;
26642 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
26643 - (char __user *)&val, sizeof(val));
26644 + (char __force_user *)&val, sizeof(val));
26645 }
26646
26647 static inline void drbd_tcp_quickack(struct socket *sock)
26648 {
26649 - int __user val = 2;
26650 + int val = 2;
26651 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
26652 - (char __user *)&val, sizeof(val));
26653 + (char __force_user *)&val, sizeof(val));
26654 }
26655
26656 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
26657 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
26658 index 0358e55..bc33689 100644
26659 --- a/drivers/block/drbd/drbd_main.c
26660 +++ b/drivers/block/drbd/drbd_main.c
26661 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
26662 p.sector = sector;
26663 p.block_id = block_id;
26664 p.blksize = blksize;
26665 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
26666 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
26667
26668 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
26669 return false;
26670 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
26671 p.sector = cpu_to_be64(req->sector);
26672 p.block_id = (unsigned long)req;
26673 p.seq_num = cpu_to_be32(req->seq_num =
26674 - atomic_add_return(1, &mdev->packet_seq));
26675 + atomic_add_return_unchecked(1, &mdev->packet_seq));
26676
26677 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
26678
26679 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
26680 atomic_set(&mdev->unacked_cnt, 0);
26681 atomic_set(&mdev->local_cnt, 0);
26682 atomic_set(&mdev->net_cnt, 0);
26683 - atomic_set(&mdev->packet_seq, 0);
26684 + atomic_set_unchecked(&mdev->packet_seq, 0);
26685 atomic_set(&mdev->pp_in_use, 0);
26686 atomic_set(&mdev->pp_in_use_by_net, 0);
26687 atomic_set(&mdev->rs_sect_in, 0);
26688 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
26689 mdev->receiver.t_state);
26690
26691 /* no need to lock it, I'm the only thread alive */
26692 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
26693 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
26694 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
26695 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
26696 mdev->al_writ_cnt =
26697 mdev->bm_writ_cnt =
26698 mdev->read_cnt =
26699 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
26700 index 0feab26..5d9b3dd 100644
26701 --- a/drivers/block/drbd/drbd_nl.c
26702 +++ b/drivers/block/drbd/drbd_nl.c
26703 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
26704 module_put(THIS_MODULE);
26705 }
26706
26707 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
26708 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
26709
26710 static unsigned short *
26711 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
26712 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
26713 cn_reply->id.idx = CN_IDX_DRBD;
26714 cn_reply->id.val = CN_VAL_DRBD;
26715
26716 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26717 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26718 cn_reply->ack = 0; /* not used here. */
26719 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26720 (int)((char *)tl - (char *)reply->tag_list);
26721 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
26722 cn_reply->id.idx = CN_IDX_DRBD;
26723 cn_reply->id.val = CN_VAL_DRBD;
26724
26725 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26726 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26727 cn_reply->ack = 0; /* not used here. */
26728 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26729 (int)((char *)tl - (char *)reply->tag_list);
26730 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
26731 cn_reply->id.idx = CN_IDX_DRBD;
26732 cn_reply->id.val = CN_VAL_DRBD;
26733
26734 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
26735 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
26736 cn_reply->ack = 0; // not used here.
26737 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26738 (int)((char*)tl - (char*)reply->tag_list);
26739 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
26740 cn_reply->id.idx = CN_IDX_DRBD;
26741 cn_reply->id.val = CN_VAL_DRBD;
26742
26743 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26744 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26745 cn_reply->ack = 0; /* not used here. */
26746 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26747 (int)((char *)tl - (char *)reply->tag_list);
26748 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
26749 index 43beaca..4a5b1dd 100644
26750 --- a/drivers/block/drbd/drbd_receiver.c
26751 +++ b/drivers/block/drbd/drbd_receiver.c
26752 @@ -894,7 +894,7 @@ retry:
26753 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
26754 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
26755
26756 - atomic_set(&mdev->packet_seq, 0);
26757 + atomic_set_unchecked(&mdev->packet_seq, 0);
26758 mdev->peer_seq = 0;
26759
26760 drbd_thread_start(&mdev->asender);
26761 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
26762 do {
26763 next_epoch = NULL;
26764
26765 - epoch_size = atomic_read(&epoch->epoch_size);
26766 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
26767
26768 switch (ev & ~EV_CLEANUP) {
26769 case EV_PUT:
26770 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
26771 rv = FE_DESTROYED;
26772 } else {
26773 epoch->flags = 0;
26774 - atomic_set(&epoch->epoch_size, 0);
26775 + atomic_set_unchecked(&epoch->epoch_size, 0);
26776 /* atomic_set(&epoch->active, 0); is already zero */
26777 if (rv == FE_STILL_LIVE)
26778 rv = FE_RECYCLED;
26779 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
26780 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
26781 drbd_flush(mdev);
26782
26783 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
26784 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
26785 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
26786 if (epoch)
26787 break;
26788 }
26789
26790 epoch = mdev->current_epoch;
26791 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
26792 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
26793
26794 D_ASSERT(atomic_read(&epoch->active) == 0);
26795 D_ASSERT(epoch->flags == 0);
26796 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
26797 }
26798
26799 epoch->flags = 0;
26800 - atomic_set(&epoch->epoch_size, 0);
26801 + atomic_set_unchecked(&epoch->epoch_size, 0);
26802 atomic_set(&epoch->active, 0);
26803
26804 spin_lock(&mdev->epoch_lock);
26805 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
26806 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
26807 list_add(&epoch->list, &mdev->current_epoch->list);
26808 mdev->current_epoch = epoch;
26809 mdev->epochs++;
26810 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
26811 spin_unlock(&mdev->peer_seq_lock);
26812
26813 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
26814 - atomic_inc(&mdev->current_epoch->epoch_size);
26815 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
26816 return drbd_drain_block(mdev, data_size);
26817 }
26818
26819 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
26820
26821 spin_lock(&mdev->epoch_lock);
26822 e->epoch = mdev->current_epoch;
26823 - atomic_inc(&e->epoch->epoch_size);
26824 + atomic_inc_unchecked(&e->epoch->epoch_size);
26825 atomic_inc(&e->epoch->active);
26826 spin_unlock(&mdev->epoch_lock);
26827
26828 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
26829 D_ASSERT(list_empty(&mdev->done_ee));
26830
26831 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
26832 - atomic_set(&mdev->current_epoch->epoch_size, 0);
26833 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
26834 D_ASSERT(list_empty(&mdev->current_epoch->list));
26835 }
26836
26837 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
26838 index 4720c7a..2c49af1 100644
26839 --- a/drivers/block/loop.c
26840 +++ b/drivers/block/loop.c
26841 @@ -283,7 +283,7 @@ static int __do_lo_send_write(struct file *file,
26842 mm_segment_t old_fs = get_fs();
26843
26844 set_fs(get_ds());
26845 - bw = file->f_op->write(file, buf, len, &pos);
26846 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
26847 set_fs(old_fs);
26848 if (likely(bw == len))
26849 return 0;
26850 diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
26851 index f533f33..6177bcb 100644
26852 --- a/drivers/block/nbd.c
26853 +++ b/drivers/block/nbd.c
26854 @@ -157,6 +157,8 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size,
26855 struct kvec iov;
26856 sigset_t blocked, oldset;
26857
26858 + pax_track_stack();
26859 +
26860 if (unlikely(!sock)) {
26861 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
26862 lo->disk->disk_name, (send ? "send" : "recv"));
26863 @@ -572,6 +574,8 @@ static void do_nbd_request(struct request_queue *q)
26864 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
26865 unsigned int cmd, unsigned long arg)
26866 {
26867 + pax_track_stack();
26868 +
26869 switch (cmd) {
26870 case NBD_DISCONNECT: {
26871 struct request sreq;
26872 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
26873 index 423fd56..06d3be0 100644
26874 --- a/drivers/char/Kconfig
26875 +++ b/drivers/char/Kconfig
26876 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
26877
26878 config DEVKMEM
26879 bool "/dev/kmem virtual device support"
26880 - default y
26881 + default n
26882 + depends on !GRKERNSEC_KMEM
26883 help
26884 Say Y here if you want to support the /dev/kmem device. The
26885 /dev/kmem device is rarely used, but can be used for certain
26886 @@ -596,6 +597,7 @@ config DEVPORT
26887 bool
26888 depends on !M68K
26889 depends on ISA || PCI
26890 + depends on !GRKERNSEC_KMEM
26891 default y
26892
26893 source "drivers/s390/char/Kconfig"
26894 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
26895 index 2e04433..22afc64 100644
26896 --- a/drivers/char/agp/frontend.c
26897 +++ b/drivers/char/agp/frontend.c
26898 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
26899 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
26900 return -EFAULT;
26901
26902 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
26903 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
26904 return -EFAULT;
26905
26906 client = agp_find_client_by_pid(reserve.pid);
26907 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
26908 index 095ab90..afad0a4 100644
26909 --- a/drivers/char/briq_panel.c
26910 +++ b/drivers/char/briq_panel.c
26911 @@ -9,6 +9,7 @@
26912 #include <linux/types.h>
26913 #include <linux/errno.h>
26914 #include <linux/tty.h>
26915 +#include <linux/mutex.h>
26916 #include <linux/timer.h>
26917 #include <linux/kernel.h>
26918 #include <linux/wait.h>
26919 @@ -34,6 +35,7 @@ static int vfd_is_open;
26920 static unsigned char vfd[40];
26921 static int vfd_cursor;
26922 static unsigned char ledpb, led;
26923 +static DEFINE_MUTEX(vfd_mutex);
26924
26925 static void update_vfd(void)
26926 {
26927 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
26928 if (!vfd_is_open)
26929 return -EBUSY;
26930
26931 + mutex_lock(&vfd_mutex);
26932 for (;;) {
26933 char c;
26934 if (!indx)
26935 break;
26936 - if (get_user(c, buf))
26937 + if (get_user(c, buf)) {
26938 + mutex_unlock(&vfd_mutex);
26939 return -EFAULT;
26940 + }
26941 if (esc) {
26942 set_led(c);
26943 esc = 0;
26944 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
26945 buf++;
26946 }
26947 update_vfd();
26948 + mutex_unlock(&vfd_mutex);
26949
26950 return len;
26951 }
26952 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
26953 index f773a9d..65cd683 100644
26954 --- a/drivers/char/genrtc.c
26955 +++ b/drivers/char/genrtc.c
26956 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
26957 switch (cmd) {
26958
26959 case RTC_PLL_GET:
26960 + memset(&pll, 0, sizeof(pll));
26961 if (get_rtc_pll(&pll))
26962 return -EINVAL;
26963 else
26964 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
26965 index 0833896..cccce52 100644
26966 --- a/drivers/char/hpet.c
26967 +++ b/drivers/char/hpet.c
26968 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
26969 }
26970
26971 static int
26972 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
26973 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
26974 struct hpet_info *info)
26975 {
26976 struct hpet_timer __iomem *timer;
26977 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
26978 index 58c0e63..25aed94 100644
26979 --- a/drivers/char/ipmi/ipmi_msghandler.c
26980 +++ b/drivers/char/ipmi/ipmi_msghandler.c
26981 @@ -415,7 +415,7 @@ struct ipmi_smi {
26982 struct proc_dir_entry *proc_dir;
26983 char proc_dir_name[10];
26984
26985 - atomic_t stats[IPMI_NUM_STATS];
26986 + atomic_unchecked_t stats[IPMI_NUM_STATS];
26987
26988 /*
26989 * run_to_completion duplicate of smb_info, smi_info
26990 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
26991
26992
26993 #define ipmi_inc_stat(intf, stat) \
26994 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
26995 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
26996 #define ipmi_get_stat(intf, stat) \
26997 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
26998 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
26999
27000 static int is_lan_addr(struct ipmi_addr *addr)
27001 {
27002 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
27003 INIT_LIST_HEAD(&intf->cmd_rcvrs);
27004 init_waitqueue_head(&intf->waitq);
27005 for (i = 0; i < IPMI_NUM_STATS; i++)
27006 - atomic_set(&intf->stats[i], 0);
27007 + atomic_set_unchecked(&intf->stats[i], 0);
27008
27009 intf->proc_dir = NULL;
27010
27011 @@ -4220,6 +4220,8 @@ static void send_panic_events(char *str)
27012 struct ipmi_smi_msg smi_msg;
27013 struct ipmi_recv_msg recv_msg;
27014
27015 + pax_track_stack();
27016 +
27017 si = (struct ipmi_system_interface_addr *) &addr;
27018 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
27019 si->channel = IPMI_BMC_CHANNEL;
27020 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
27021 index 9397ab4..d01bee1 100644
27022 --- a/drivers/char/ipmi/ipmi_si_intf.c
27023 +++ b/drivers/char/ipmi/ipmi_si_intf.c
27024 @@ -277,7 +277,7 @@ struct smi_info {
27025 unsigned char slave_addr;
27026
27027 /* Counters and things for the proc filesystem. */
27028 - atomic_t stats[SI_NUM_STATS];
27029 + atomic_unchecked_t stats[SI_NUM_STATS];
27030
27031 struct task_struct *thread;
27032
27033 @@ -286,9 +286,9 @@ struct smi_info {
27034 };
27035
27036 #define smi_inc_stat(smi, stat) \
27037 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
27038 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
27039 #define smi_get_stat(smi, stat) \
27040 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
27041 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
27042
27043 #define SI_MAX_PARMS 4
27044
27045 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
27046 atomic_set(&new_smi->req_events, 0);
27047 new_smi->run_to_completion = 0;
27048 for (i = 0; i < SI_NUM_STATS; i++)
27049 - atomic_set(&new_smi->stats[i], 0);
27050 + atomic_set_unchecked(&new_smi->stats[i], 0);
27051
27052 new_smi->interrupt_disabled = 1;
27053 atomic_set(&new_smi->stop_operation, 0);
27054 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
27055 index 1aeaaba..e018570 100644
27056 --- a/drivers/char/mbcs.c
27057 +++ b/drivers/char/mbcs.c
27058 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
27059 return 0;
27060 }
27061
27062 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
27063 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
27064 {
27065 .part_num = MBCS_PART_NUM,
27066 .mfg_num = MBCS_MFG_NUM,
27067 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
27068 index 8fc04b4..cebdeec 100644
27069 --- a/drivers/char/mem.c
27070 +++ b/drivers/char/mem.c
27071 @@ -18,6 +18,7 @@
27072 #include <linux/raw.h>
27073 #include <linux/tty.h>
27074 #include <linux/capability.h>
27075 +#include <linux/security.h>
27076 #include <linux/ptrace.h>
27077 #include <linux/device.h>
27078 #include <linux/highmem.h>
27079 @@ -34,6 +35,10 @@
27080 # include <linux/efi.h>
27081 #endif
27082
27083 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27084 +extern const struct file_operations grsec_fops;
27085 +#endif
27086 +
27087 static inline unsigned long size_inside_page(unsigned long start,
27088 unsigned long size)
27089 {
27090 @@ -65,9 +70,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27091
27092 while (cursor < to) {
27093 if (!devmem_is_allowed(pfn)) {
27094 +#ifdef CONFIG_GRKERNSEC_KMEM
27095 + gr_handle_mem_readwrite(from, to);
27096 +#else
27097 printk(KERN_INFO
27098 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
27099 current->comm, from, to);
27100 +#endif
27101 return 0;
27102 }
27103 cursor += PAGE_SIZE;
27104 @@ -75,6 +84,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27105 }
27106 return 1;
27107 }
27108 +#elif defined(CONFIG_GRKERNSEC_KMEM)
27109 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27110 +{
27111 + return 0;
27112 +}
27113 #else
27114 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27115 {
27116 @@ -117,6 +131,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
27117
27118 while (count > 0) {
27119 unsigned long remaining;
27120 + char *temp;
27121
27122 sz = size_inside_page(p, count);
27123
27124 @@ -132,7 +147,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
27125 if (!ptr)
27126 return -EFAULT;
27127
27128 - remaining = copy_to_user(buf, ptr, sz);
27129 +#ifdef CONFIG_PAX_USERCOPY
27130 + temp = kmalloc(sz, GFP_KERNEL);
27131 + if (!temp) {
27132 + unxlate_dev_mem_ptr(p, ptr);
27133 + return -ENOMEM;
27134 + }
27135 + memcpy(temp, ptr, sz);
27136 +#else
27137 + temp = ptr;
27138 +#endif
27139 +
27140 + remaining = copy_to_user(buf, temp, sz);
27141 +
27142 +#ifdef CONFIG_PAX_USERCOPY
27143 + kfree(temp);
27144 +#endif
27145 +
27146 unxlate_dev_mem_ptr(p, ptr);
27147 if (remaining)
27148 return -EFAULT;
27149 @@ -395,9 +426,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27150 size_t count, loff_t *ppos)
27151 {
27152 unsigned long p = *ppos;
27153 - ssize_t low_count, read, sz;
27154 + ssize_t low_count, read, sz, err = 0;
27155 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
27156 - int err = 0;
27157
27158 read = 0;
27159 if (p < (unsigned long) high_memory) {
27160 @@ -419,6 +449,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27161 }
27162 #endif
27163 while (low_count > 0) {
27164 + char *temp;
27165 +
27166 sz = size_inside_page(p, low_count);
27167
27168 /*
27169 @@ -428,7 +460,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27170 */
27171 kbuf = xlate_dev_kmem_ptr((char *)p);
27172
27173 - if (copy_to_user(buf, kbuf, sz))
27174 +#ifdef CONFIG_PAX_USERCOPY
27175 + temp = kmalloc(sz, GFP_KERNEL);
27176 + if (!temp)
27177 + return -ENOMEM;
27178 + memcpy(temp, kbuf, sz);
27179 +#else
27180 + temp = kbuf;
27181 +#endif
27182 +
27183 + err = copy_to_user(buf, temp, sz);
27184 +
27185 +#ifdef CONFIG_PAX_USERCOPY
27186 + kfree(temp);
27187 +#endif
27188 +
27189 + if (err)
27190 return -EFAULT;
27191 buf += sz;
27192 p += sz;
27193 @@ -866,6 +913,9 @@ static const struct memdev {
27194 #ifdef CONFIG_CRASH_DUMP
27195 [12] = { "oldmem", 0, &oldmem_fops, NULL },
27196 #endif
27197 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27198 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
27199 +#endif
27200 };
27201
27202 static int memory_open(struct inode *inode, struct file *filp)
27203 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
27204 index da3cfee..a5a6606 100644
27205 --- a/drivers/char/nvram.c
27206 +++ b/drivers/char/nvram.c
27207 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
27208
27209 spin_unlock_irq(&rtc_lock);
27210
27211 - if (copy_to_user(buf, contents, tmp - contents))
27212 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
27213 return -EFAULT;
27214
27215 *ppos = i;
27216 diff --git a/drivers/char/random.c b/drivers/char/random.c
27217 index c35a785..6d82202 100644
27218 --- a/drivers/char/random.c
27219 +++ b/drivers/char/random.c
27220 @@ -261,8 +261,13 @@
27221 /*
27222 * Configuration information
27223 */
27224 +#ifdef CONFIG_GRKERNSEC_RANDNET
27225 +#define INPUT_POOL_WORDS 512
27226 +#define OUTPUT_POOL_WORDS 128
27227 +#else
27228 #define INPUT_POOL_WORDS 128
27229 #define OUTPUT_POOL_WORDS 32
27230 +#endif
27231 #define SEC_XFER_SIZE 512
27232 #define EXTRACT_SIZE 10
27233
27234 @@ -300,10 +305,17 @@ static struct poolinfo {
27235 int poolwords;
27236 int tap1, tap2, tap3, tap4, tap5;
27237 } poolinfo_table[] = {
27238 +#ifdef CONFIG_GRKERNSEC_RANDNET
27239 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
27240 + { 512, 411, 308, 208, 104, 1 },
27241 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
27242 + { 128, 103, 76, 51, 25, 1 },
27243 +#else
27244 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
27245 { 128, 103, 76, 51, 25, 1 },
27246 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
27247 { 32, 26, 20, 14, 7, 1 },
27248 +#endif
27249 #if 0
27250 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
27251 { 2048, 1638, 1231, 819, 411, 1 },
27252 @@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
27253
27254 extract_buf(r, tmp);
27255 i = min_t(int, nbytes, EXTRACT_SIZE);
27256 - if (copy_to_user(buf, tmp, i)) {
27257 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
27258 ret = -EFAULT;
27259 break;
27260 }
27261 @@ -1214,7 +1226,7 @@ EXPORT_SYMBOL(generate_random_uuid);
27262 #include <linux/sysctl.h>
27263
27264 static int min_read_thresh = 8, min_write_thresh;
27265 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
27266 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
27267 static int max_write_thresh = INPUT_POOL_WORDS * 32;
27268 static char sysctl_bootid[16];
27269
27270 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
27271 index 1ee8ce7..b778bef 100644
27272 --- a/drivers/char/sonypi.c
27273 +++ b/drivers/char/sonypi.c
27274 @@ -55,6 +55,7 @@
27275 #include <asm/uaccess.h>
27276 #include <asm/io.h>
27277 #include <asm/system.h>
27278 +#include <asm/local.h>
27279
27280 #include <linux/sonypi.h>
27281
27282 @@ -491,7 +492,7 @@ static struct sonypi_device {
27283 spinlock_t fifo_lock;
27284 wait_queue_head_t fifo_proc_list;
27285 struct fasync_struct *fifo_async;
27286 - int open_count;
27287 + local_t open_count;
27288 int model;
27289 struct input_dev *input_jog_dev;
27290 struct input_dev *input_key_dev;
27291 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
27292 static int sonypi_misc_release(struct inode *inode, struct file *file)
27293 {
27294 mutex_lock(&sonypi_device.lock);
27295 - sonypi_device.open_count--;
27296 + local_dec(&sonypi_device.open_count);
27297 mutex_unlock(&sonypi_device.lock);
27298 return 0;
27299 }
27300 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
27301 {
27302 mutex_lock(&sonypi_device.lock);
27303 /* Flush input queue on first open */
27304 - if (!sonypi_device.open_count)
27305 + if (!local_read(&sonypi_device.open_count))
27306 kfifo_reset(&sonypi_device.fifo);
27307 - sonypi_device.open_count++;
27308 + local_inc(&sonypi_device.open_count);
27309 mutex_unlock(&sonypi_device.lock);
27310
27311 return 0;
27312 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
27313 index 9ca5c02..7ce352c 100644
27314 --- a/drivers/char/tpm/tpm.c
27315 +++ b/drivers/char/tpm/tpm.c
27316 @@ -414,7 +414,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
27317 chip->vendor.req_complete_val)
27318 goto out_recv;
27319
27320 - if ((status == chip->vendor.req_canceled)) {
27321 + if (status == chip->vendor.req_canceled) {
27322 dev_err(chip->dev, "Operation Canceled\n");
27323 rc = -ECANCELED;
27324 goto out;
27325 @@ -862,6 +862,8 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
27326
27327 struct tpm_chip *chip = dev_get_drvdata(dev);
27328
27329 + pax_track_stack();
27330 +
27331 tpm_cmd.header.in = tpm_readpubek_header;
27332 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
27333 "attempting to read the PUBEK");
27334 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
27335 index 0636520..169c1d0 100644
27336 --- a/drivers/char/tpm/tpm_bios.c
27337 +++ b/drivers/char/tpm/tpm_bios.c
27338 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
27339 event = addr;
27340
27341 if ((event->event_type == 0 && event->event_size == 0) ||
27342 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
27343 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
27344 return NULL;
27345
27346 return addr;
27347 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
27348 return NULL;
27349
27350 if ((event->event_type == 0 && event->event_size == 0) ||
27351 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
27352 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
27353 return NULL;
27354
27355 (*pos)++;
27356 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
27357 int i;
27358
27359 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
27360 - seq_putc(m, data[i]);
27361 + if (!seq_putc(m, data[i]))
27362 + return -EFAULT;
27363
27364 return 0;
27365 }
27366 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
27367 log->bios_event_log_end = log->bios_event_log + len;
27368
27369 virt = acpi_os_map_memory(start, len);
27370 + if (!virt) {
27371 + kfree(log->bios_event_log);
27372 + log->bios_event_log = NULL;
27373 + return -EFAULT;
27374 + }
27375
27376 - memcpy(log->bios_event_log, virt, len);
27377 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
27378
27379 acpi_os_unmap_memory(virt, len);
27380 return 0;
27381 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
27382 index fb68b12..0f6c6ca 100644
27383 --- a/drivers/char/virtio_console.c
27384 +++ b/drivers/char/virtio_console.c
27385 @@ -555,7 +555,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
27386 if (to_user) {
27387 ssize_t ret;
27388
27389 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
27390 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
27391 if (ret)
27392 return -EFAULT;
27393 } else {
27394 @@ -654,7 +654,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
27395 if (!port_has_data(port) && !port->host_connected)
27396 return 0;
27397
27398 - return fill_readbuf(port, ubuf, count, true);
27399 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
27400 }
27401
27402 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
27403 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
27404 index a84250a..68c725e 100644
27405 --- a/drivers/crypto/hifn_795x.c
27406 +++ b/drivers/crypto/hifn_795x.c
27407 @@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device *dev, int encdec, u8 snum)
27408 0xCA, 0x34, 0x2B, 0x2E};
27409 struct scatterlist sg;
27410
27411 + pax_track_stack();
27412 +
27413 memset(src, 0, sizeof(src));
27414 memset(ctx.key, 0, sizeof(ctx.key));
27415
27416 diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
27417 index db33d30..7823369 100644
27418 --- a/drivers/crypto/padlock-aes.c
27419 +++ b/drivers/crypto/padlock-aes.c
27420 @@ -109,6 +109,8 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
27421 struct crypto_aes_ctx gen_aes;
27422 int cpu;
27423
27424 + pax_track_stack();
27425 +
27426 if (key_len % 8) {
27427 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
27428 return -EINVAL;
27429 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
27430 index 9a8bebc..b1e4989 100644
27431 --- a/drivers/edac/amd64_edac.c
27432 +++ b/drivers/edac/amd64_edac.c
27433 @@ -2670,7 +2670,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
27434 * PCI core identifies what devices are on a system during boot, and then
27435 * inquiry this table to see if this driver is for a given device found.
27436 */
27437 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
27438 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
27439 {
27440 .vendor = PCI_VENDOR_ID_AMD,
27441 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
27442 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
27443 index e47e73b..348e0bd 100644
27444 --- a/drivers/edac/amd76x_edac.c
27445 +++ b/drivers/edac/amd76x_edac.c
27446 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
27447 edac_mc_free(mci);
27448 }
27449
27450 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
27451 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
27452 {
27453 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27454 AMD762},
27455 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
27456 index 1af531a..3a8ff27 100644
27457 --- a/drivers/edac/e752x_edac.c
27458 +++ b/drivers/edac/e752x_edac.c
27459 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
27460 edac_mc_free(mci);
27461 }
27462
27463 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
27464 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
27465 {
27466 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27467 E7520},
27468 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
27469 index 6ffb6d2..383d8d7 100644
27470 --- a/drivers/edac/e7xxx_edac.c
27471 +++ b/drivers/edac/e7xxx_edac.c
27472 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
27473 edac_mc_free(mci);
27474 }
27475
27476 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
27477 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
27478 {
27479 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27480 E7205},
27481 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
27482 index 495198a..ac08c85 100644
27483 --- a/drivers/edac/edac_pci_sysfs.c
27484 +++ b/drivers/edac/edac_pci_sysfs.c
27485 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
27486 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
27487 static int edac_pci_poll_msec = 1000; /* one second workq period */
27488
27489 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
27490 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
27491 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
27492 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
27493
27494 static struct kobject *edac_pci_top_main_kobj;
27495 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
27496 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27497 edac_printk(KERN_CRIT, EDAC_PCI,
27498 "Signaled System Error on %s\n",
27499 pci_name(dev));
27500 - atomic_inc(&pci_nonparity_count);
27501 + atomic_inc_unchecked(&pci_nonparity_count);
27502 }
27503
27504 if (status & (PCI_STATUS_PARITY)) {
27505 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27506 "Master Data Parity Error on %s\n",
27507 pci_name(dev));
27508
27509 - atomic_inc(&pci_parity_count);
27510 + atomic_inc_unchecked(&pci_parity_count);
27511 }
27512
27513 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27514 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27515 "Detected Parity Error on %s\n",
27516 pci_name(dev));
27517
27518 - atomic_inc(&pci_parity_count);
27519 + atomic_inc_unchecked(&pci_parity_count);
27520 }
27521 }
27522
27523 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27524 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
27525 "Signaled System Error on %s\n",
27526 pci_name(dev));
27527 - atomic_inc(&pci_nonparity_count);
27528 + atomic_inc_unchecked(&pci_nonparity_count);
27529 }
27530
27531 if (status & (PCI_STATUS_PARITY)) {
27532 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27533 "Master Data Parity Error on "
27534 "%s\n", pci_name(dev));
27535
27536 - atomic_inc(&pci_parity_count);
27537 + atomic_inc_unchecked(&pci_parity_count);
27538 }
27539
27540 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27541 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27542 "Detected Parity Error on %s\n",
27543 pci_name(dev));
27544
27545 - atomic_inc(&pci_parity_count);
27546 + atomic_inc_unchecked(&pci_parity_count);
27547 }
27548 }
27549 }
27550 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
27551 if (!check_pci_errors)
27552 return;
27553
27554 - before_count = atomic_read(&pci_parity_count);
27555 + before_count = atomic_read_unchecked(&pci_parity_count);
27556
27557 /* scan all PCI devices looking for a Parity Error on devices and
27558 * bridges.
27559 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
27560 /* Only if operator has selected panic on PCI Error */
27561 if (edac_pci_get_panic_on_pe()) {
27562 /* If the count is different 'after' from 'before' */
27563 - if (before_count != atomic_read(&pci_parity_count))
27564 + if (before_count != atomic_read_unchecked(&pci_parity_count))
27565 panic("EDAC: PCI Parity Error");
27566 }
27567 }
27568 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
27569 index c0510b3..6e2a954 100644
27570 --- a/drivers/edac/i3000_edac.c
27571 +++ b/drivers/edac/i3000_edac.c
27572 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
27573 edac_mc_free(mci);
27574 }
27575
27576 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
27577 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
27578 {
27579 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27580 I3000},
27581 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
27582 index aa08497..7e6822a 100644
27583 --- a/drivers/edac/i3200_edac.c
27584 +++ b/drivers/edac/i3200_edac.c
27585 @@ -456,7 +456,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
27586 edac_mc_free(mci);
27587 }
27588
27589 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
27590 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
27591 {
27592 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27593 I3200},
27594 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
27595 index 4dc3ac2..67d05a6 100644
27596 --- a/drivers/edac/i5000_edac.c
27597 +++ b/drivers/edac/i5000_edac.c
27598 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
27599 *
27600 * The "E500P" device is the first device supported.
27601 */
27602 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
27603 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
27604 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
27605 .driver_data = I5000P},
27606
27607 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
27608 index bcbdeec..9886d16 100644
27609 --- a/drivers/edac/i5100_edac.c
27610 +++ b/drivers/edac/i5100_edac.c
27611 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
27612 edac_mc_free(mci);
27613 }
27614
27615 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
27616 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
27617 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
27618 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
27619 { 0, }
27620 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
27621 index 74d6ec34..baff517 100644
27622 --- a/drivers/edac/i5400_edac.c
27623 +++ b/drivers/edac/i5400_edac.c
27624 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
27625 *
27626 * The "E500P" device is the first device supported.
27627 */
27628 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
27629 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
27630 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
27631 {0,} /* 0 terminated list. */
27632 };
27633 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
27634 index a76fe83..15479e6 100644
27635 --- a/drivers/edac/i7300_edac.c
27636 +++ b/drivers/edac/i7300_edac.c
27637 @@ -1191,7 +1191,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
27638 *
27639 * Has only 8086:360c PCI ID
27640 */
27641 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
27642 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
27643 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
27644 {0,} /* 0 terminated list. */
27645 };
27646 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
27647 index f6cf448..3f612e9 100644
27648 --- a/drivers/edac/i7core_edac.c
27649 +++ b/drivers/edac/i7core_edac.c
27650 @@ -359,7 +359,7 @@ static const struct pci_id_table pci_dev_table[] = {
27651 /*
27652 * pci_device_id table for which devices we are looking for
27653 */
27654 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
27655 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
27656 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
27657 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
27658 {0,} /* 0 terminated list. */
27659 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
27660 index 4329d39..f3022ef 100644
27661 --- a/drivers/edac/i82443bxgx_edac.c
27662 +++ b/drivers/edac/i82443bxgx_edac.c
27663 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
27664
27665 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
27666
27667 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
27668 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
27669 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
27670 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
27671 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
27672 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
27673 index 931a057..fd28340 100644
27674 --- a/drivers/edac/i82860_edac.c
27675 +++ b/drivers/edac/i82860_edac.c
27676 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
27677 edac_mc_free(mci);
27678 }
27679
27680 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
27681 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
27682 {
27683 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27684 I82860},
27685 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
27686 index 33864c6..01edc61 100644
27687 --- a/drivers/edac/i82875p_edac.c
27688 +++ b/drivers/edac/i82875p_edac.c
27689 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
27690 edac_mc_free(mci);
27691 }
27692
27693 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
27694 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
27695 {
27696 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27697 I82875P},
27698 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
27699 index a5da732..983363b 100644
27700 --- a/drivers/edac/i82975x_edac.c
27701 +++ b/drivers/edac/i82975x_edac.c
27702 @@ -604,7 +604,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
27703 edac_mc_free(mci);
27704 }
27705
27706 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
27707 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
27708 {
27709 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27710 I82975X
27711 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
27712 index 795a320..3bbc3d3 100644
27713 --- a/drivers/edac/mce_amd.h
27714 +++ b/drivers/edac/mce_amd.h
27715 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
27716 bool (*dc_mce)(u16, u8);
27717 bool (*ic_mce)(u16, u8);
27718 bool (*nb_mce)(u16, u8);
27719 -};
27720 +} __no_const;
27721
27722 void amd_report_gart_errors(bool);
27723 void amd_register_ecc_decoder(void (*f)(int, struct mce *, u32));
27724 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
27725 index b153674..ad2ba9b 100644
27726 --- a/drivers/edac/r82600_edac.c
27727 +++ b/drivers/edac/r82600_edac.c
27728 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
27729 edac_mc_free(mci);
27730 }
27731
27732 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
27733 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
27734 {
27735 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
27736 },
27737 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
27738 index b6f47de..c5acf3a 100644
27739 --- a/drivers/edac/x38_edac.c
27740 +++ b/drivers/edac/x38_edac.c
27741 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
27742 edac_mc_free(mci);
27743 }
27744
27745 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
27746 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
27747 {
27748 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27749 X38},
27750 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
27751 index 85661b0..c784559a 100644
27752 --- a/drivers/firewire/core-card.c
27753 +++ b/drivers/firewire/core-card.c
27754 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
27755
27756 void fw_core_remove_card(struct fw_card *card)
27757 {
27758 - struct fw_card_driver dummy_driver = dummy_driver_template;
27759 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
27760
27761 card->driver->update_phy_reg(card, 4,
27762 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
27763 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
27764 index 4799393..37bd3ab 100644
27765 --- a/drivers/firewire/core-cdev.c
27766 +++ b/drivers/firewire/core-cdev.c
27767 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
27768 int ret;
27769
27770 if ((request->channels == 0 && request->bandwidth == 0) ||
27771 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
27772 - request->bandwidth < 0)
27773 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
27774 return -EINVAL;
27775
27776 r = kmalloc(sizeof(*r), GFP_KERNEL);
27777 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
27778 index 334b82a..ea5261d 100644
27779 --- a/drivers/firewire/core-transaction.c
27780 +++ b/drivers/firewire/core-transaction.c
27781 @@ -37,6 +37,7 @@
27782 #include <linux/timer.h>
27783 #include <linux/types.h>
27784 #include <linux/workqueue.h>
27785 +#include <linux/sched.h>
27786
27787 #include <asm/byteorder.h>
27788
27789 @@ -422,6 +423,8 @@ int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
27790 struct transaction_callback_data d;
27791 struct fw_transaction t;
27792
27793 + pax_track_stack();
27794 +
27795 init_timer_on_stack(&t.split_timeout_timer);
27796 init_completion(&d.done);
27797 d.payload = payload;
27798 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
27799 index b45be57..5fad18b 100644
27800 --- a/drivers/firewire/core.h
27801 +++ b/drivers/firewire/core.h
27802 @@ -101,6 +101,7 @@ struct fw_card_driver {
27803
27804 int (*stop_iso)(struct fw_iso_context *ctx);
27805 };
27806 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
27807
27808 void fw_card_initialize(struct fw_card *card,
27809 const struct fw_card_driver *driver, struct device *device);
27810 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
27811 index bcb1126..2cc2121 100644
27812 --- a/drivers/firmware/dmi_scan.c
27813 +++ b/drivers/firmware/dmi_scan.c
27814 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
27815 }
27816 }
27817 else {
27818 - /*
27819 - * no iounmap() for that ioremap(); it would be a no-op, but
27820 - * it's so early in setup that sucker gets confused into doing
27821 - * what it shouldn't if we actually call it.
27822 - */
27823 p = dmi_ioremap(0xF0000, 0x10000);
27824 if (p == NULL)
27825 goto error;
27826 @@ -725,7 +720,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
27827 if (buf == NULL)
27828 return -1;
27829
27830 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
27831 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
27832
27833 iounmap(buf);
27834 return 0;
27835 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
27836 index 98723cb..10ca85b 100644
27837 --- a/drivers/gpio/gpio-vr41xx.c
27838 +++ b/drivers/gpio/gpio-vr41xx.c
27839 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
27840 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
27841 maskl, pendl, maskh, pendh);
27842
27843 - atomic_inc(&irq_err_count);
27844 + atomic_inc_unchecked(&irq_err_count);
27845
27846 return -EINVAL;
27847 }
27848 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
27849 index 2410c40..2d03563 100644
27850 --- a/drivers/gpu/drm/drm_crtc.c
27851 +++ b/drivers/gpu/drm/drm_crtc.c
27852 @@ -1374,7 +1374,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27853 */
27854 if ((out_resp->count_modes >= mode_count) && mode_count) {
27855 copied = 0;
27856 - mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
27857 + mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
27858 list_for_each_entry(mode, &connector->modes, head) {
27859 drm_crtc_convert_to_umode(&u_mode, mode);
27860 if (copy_to_user(mode_ptr + copied,
27861 @@ -1389,8 +1389,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27862
27863 if ((out_resp->count_props >= props_count) && props_count) {
27864 copied = 0;
27865 - prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
27866 - prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
27867 + prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
27868 + prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
27869 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
27870 if (connector->property_ids[i] != 0) {
27871 if (put_user(connector->property_ids[i],
27872 @@ -1412,7 +1412,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27873
27874 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
27875 copied = 0;
27876 - encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
27877 + encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
27878 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
27879 if (connector->encoder_ids[i] != 0) {
27880 if (put_user(connector->encoder_ids[i],
27881 @@ -1571,7 +1571,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
27882 }
27883
27884 for (i = 0; i < crtc_req->count_connectors; i++) {
27885 - set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
27886 + set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
27887 if (get_user(out_id, &set_connectors_ptr[i])) {
27888 ret = -EFAULT;
27889 goto out;
27890 @@ -1852,7 +1852,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
27891 fb = obj_to_fb(obj);
27892
27893 num_clips = r->num_clips;
27894 - clips_ptr = (struct drm_clip_rect *)(unsigned long)r->clips_ptr;
27895 + clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
27896
27897 if (!num_clips != !clips_ptr) {
27898 ret = -EINVAL;
27899 @@ -2276,7 +2276,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
27900 out_resp->flags = property->flags;
27901
27902 if ((out_resp->count_values >= value_count) && value_count) {
27903 - values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
27904 + values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
27905 for (i = 0; i < value_count; i++) {
27906 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
27907 ret = -EFAULT;
27908 @@ -2289,7 +2289,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
27909 if (property->flags & DRM_MODE_PROP_ENUM) {
27910 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
27911 copied = 0;
27912 - enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
27913 + enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
27914 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
27915
27916 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
27917 @@ -2312,7 +2312,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
27918 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
27919 copied = 0;
27920 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
27921 - blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
27922 + blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
27923
27924 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
27925 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
27926 @@ -2373,7 +2373,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
27927 struct drm_mode_get_blob *out_resp = data;
27928 struct drm_property_blob *blob;
27929 int ret = 0;
27930 - void *blob_ptr;
27931 + void __user *blob_ptr;
27932
27933 if (!drm_core_check_feature(dev, DRIVER_MODESET))
27934 return -EINVAL;
27935 @@ -2387,7 +2387,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
27936 blob = obj_to_blob(obj);
27937
27938 if (out_resp->length == blob->length) {
27939 - blob_ptr = (void *)(unsigned long)out_resp->data;
27940 + blob_ptr = (void __user *)(unsigned long)out_resp->data;
27941 if (copy_to_user(blob_ptr, blob->data, blob->length)){
27942 ret = -EFAULT;
27943 goto done;
27944 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
27945 index f88a9b2..8f4078f 100644
27946 --- a/drivers/gpu/drm/drm_crtc_helper.c
27947 +++ b/drivers/gpu/drm/drm_crtc_helper.c
27948 @@ -276,7 +276,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
27949 struct drm_crtc *tmp;
27950 int crtc_mask = 1;
27951
27952 - WARN(!crtc, "checking null crtc?\n");
27953 + BUG_ON(!crtc);
27954
27955 dev = crtc->dev;
27956
27957 @@ -343,6 +343,8 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
27958 struct drm_encoder *encoder;
27959 bool ret = true;
27960
27961 + pax_track_stack();
27962 +
27963 crtc->enabled = drm_helper_crtc_in_use(crtc);
27964 if (!crtc->enabled)
27965 return true;
27966 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
27967 index 93a112d..c8b065d 100644
27968 --- a/drivers/gpu/drm/drm_drv.c
27969 +++ b/drivers/gpu/drm/drm_drv.c
27970 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
27971 /**
27972 * Copy and IOCTL return string to user space
27973 */
27974 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
27975 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
27976 {
27977 int len;
27978
27979 @@ -386,7 +386,7 @@ long drm_ioctl(struct file *filp,
27980
27981 dev = file_priv->minor->dev;
27982 atomic_inc(&dev->ioctl_count);
27983 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
27984 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
27985 ++file_priv->ioctl_count;
27986
27987 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
27988 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
27989 index 2ec7d48..be14bb1 100644
27990 --- a/drivers/gpu/drm/drm_fops.c
27991 +++ b/drivers/gpu/drm/drm_fops.c
27992 @@ -70,7 +70,7 @@ static int drm_setup(struct drm_device * dev)
27993 }
27994
27995 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
27996 - atomic_set(&dev->counts[i], 0);
27997 + atomic_set_unchecked(&dev->counts[i], 0);
27998
27999 dev->sigdata.lock = NULL;
28000
28001 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct file *filp)
28002
28003 retcode = drm_open_helper(inode, filp, dev);
28004 if (!retcode) {
28005 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
28006 - if (!dev->open_count++)
28007 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
28008 + if (local_inc_return(&dev->open_count) == 1)
28009 retcode = drm_setup(dev);
28010 }
28011 if (!retcode) {
28012 @@ -472,7 +472,7 @@ int drm_release(struct inode *inode, struct file *filp)
28013
28014 mutex_lock(&drm_global_mutex);
28015
28016 - DRM_DEBUG("open_count = %d\n", dev->open_count);
28017 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
28018
28019 if (dev->driver->preclose)
28020 dev->driver->preclose(dev, file_priv);
28021 @@ -484,7 +484,7 @@ int drm_release(struct inode *inode, struct file *filp)
28022 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
28023 task_pid_nr(current),
28024 (long)old_encode_dev(file_priv->minor->device),
28025 - dev->open_count);
28026 + local_read(&dev->open_count));
28027
28028 /* if the master has gone away we can't do anything with the lock */
28029 if (file_priv->minor->master)
28030 @@ -565,8 +565,8 @@ int drm_release(struct inode *inode, struct file *filp)
28031 * End inline drm_release
28032 */
28033
28034 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
28035 - if (!--dev->open_count) {
28036 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
28037 + if (local_dec_and_test(&dev->open_count)) {
28038 if (atomic_read(&dev->ioctl_count)) {
28039 DRM_ERROR("Device busy: %d\n",
28040 atomic_read(&dev->ioctl_count));
28041 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
28042 index c87dc96..326055d 100644
28043 --- a/drivers/gpu/drm/drm_global.c
28044 +++ b/drivers/gpu/drm/drm_global.c
28045 @@ -36,7 +36,7 @@
28046 struct drm_global_item {
28047 struct mutex mutex;
28048 void *object;
28049 - int refcount;
28050 + atomic_t refcount;
28051 };
28052
28053 static struct drm_global_item glob[DRM_GLOBAL_NUM];
28054 @@ -49,7 +49,7 @@ void drm_global_init(void)
28055 struct drm_global_item *item = &glob[i];
28056 mutex_init(&item->mutex);
28057 item->object = NULL;
28058 - item->refcount = 0;
28059 + atomic_set(&item->refcount, 0);
28060 }
28061 }
28062
28063 @@ -59,7 +59,7 @@ void drm_global_release(void)
28064 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
28065 struct drm_global_item *item = &glob[i];
28066 BUG_ON(item->object != NULL);
28067 - BUG_ON(item->refcount != 0);
28068 + BUG_ON(atomic_read(&item->refcount) != 0);
28069 }
28070 }
28071
28072 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
28073 void *object;
28074
28075 mutex_lock(&item->mutex);
28076 - if (item->refcount == 0) {
28077 + if (atomic_read(&item->refcount) == 0) {
28078 item->object = kzalloc(ref->size, GFP_KERNEL);
28079 if (unlikely(item->object == NULL)) {
28080 ret = -ENOMEM;
28081 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
28082 goto out_err;
28083
28084 }
28085 - ++item->refcount;
28086 + atomic_inc(&item->refcount);
28087 ref->object = item->object;
28088 object = item->object;
28089 mutex_unlock(&item->mutex);
28090 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
28091 struct drm_global_item *item = &glob[ref->global_type];
28092
28093 mutex_lock(&item->mutex);
28094 - BUG_ON(item->refcount == 0);
28095 + BUG_ON(atomic_read(&item->refcount) == 0);
28096 BUG_ON(ref->object != item->object);
28097 - if (--item->refcount == 0) {
28098 + if (atomic_dec_and_test(&item->refcount)) {
28099 ref->release(ref);
28100 item->object = NULL;
28101 }
28102 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
28103 index ab1162d..42587b2 100644
28104 --- a/drivers/gpu/drm/drm_info.c
28105 +++ b/drivers/gpu/drm/drm_info.c
28106 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
28107 struct drm_local_map *map;
28108 struct drm_map_list *r_list;
28109
28110 - /* Hardcoded from _DRM_FRAME_BUFFER,
28111 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
28112 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
28113 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
28114 + static const char * const types[] = {
28115 + [_DRM_FRAME_BUFFER] = "FB",
28116 + [_DRM_REGISTERS] = "REG",
28117 + [_DRM_SHM] = "SHM",
28118 + [_DRM_AGP] = "AGP",
28119 + [_DRM_SCATTER_GATHER] = "SG",
28120 + [_DRM_CONSISTENT] = "PCI",
28121 + [_DRM_GEM] = "GEM" };
28122 const char *type;
28123 int i;
28124
28125 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
28126 map = r_list->map;
28127 if (!map)
28128 continue;
28129 - if (map->type < 0 || map->type > 5)
28130 + if (map->type >= ARRAY_SIZE(types))
28131 type = "??";
28132 else
28133 type = types[map->type];
28134 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
28135 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
28136 vma->vm_flags & VM_LOCKED ? 'l' : '-',
28137 vma->vm_flags & VM_IO ? 'i' : '-',
28138 +#ifdef CONFIG_GRKERNSEC_HIDESYM
28139 + 0);
28140 +#else
28141 vma->vm_pgoff);
28142 +#endif
28143
28144 #if defined(__i386__)
28145 pgprot = pgprot_val(vma->vm_page_prot);
28146 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
28147 index 4a058c7..b42cd92 100644
28148 --- a/drivers/gpu/drm/drm_ioc32.c
28149 +++ b/drivers/gpu/drm/drm_ioc32.c
28150 @@ -455,7 +455,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
28151 request = compat_alloc_user_space(nbytes);
28152 if (!access_ok(VERIFY_WRITE, request, nbytes))
28153 return -EFAULT;
28154 - list = (struct drm_buf_desc *) (request + 1);
28155 + list = (struct drm_buf_desc __user *) (request + 1);
28156
28157 if (__put_user(count, &request->count)
28158 || __put_user(list, &request->list))
28159 @@ -516,7 +516,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
28160 request = compat_alloc_user_space(nbytes);
28161 if (!access_ok(VERIFY_WRITE, request, nbytes))
28162 return -EFAULT;
28163 - list = (struct drm_buf_pub *) (request + 1);
28164 + list = (struct drm_buf_pub __user *) (request + 1);
28165
28166 if (__put_user(count, &request->count)
28167 || __put_user(list, &request->list))
28168 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
28169 index 904d7e9..ab88581 100644
28170 --- a/drivers/gpu/drm/drm_ioctl.c
28171 +++ b/drivers/gpu/drm/drm_ioctl.c
28172 @@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev, void *data,
28173 stats->data[i].value =
28174 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
28175 else
28176 - stats->data[i].value = atomic_read(&dev->counts[i]);
28177 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
28178 stats->data[i].type = dev->types[i];
28179 }
28180
28181 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
28182 index 632ae24..244cf4a 100644
28183 --- a/drivers/gpu/drm/drm_lock.c
28184 +++ b/drivers/gpu/drm/drm_lock.c
28185 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
28186 if (drm_lock_take(&master->lock, lock->context)) {
28187 master->lock.file_priv = file_priv;
28188 master->lock.lock_time = jiffies;
28189 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
28190 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
28191 break; /* Got lock */
28192 }
28193
28194 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
28195 return -EINVAL;
28196 }
28197
28198 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
28199 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
28200
28201 if (drm_lock_free(&master->lock, lock->context)) {
28202 /* FIXME: Should really bail out here. */
28203 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
28204 index 8f371e8..9f85d52 100644
28205 --- a/drivers/gpu/drm/i810/i810_dma.c
28206 +++ b/drivers/gpu/drm/i810/i810_dma.c
28207 @@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
28208 dma->buflist[vertex->idx],
28209 vertex->discard, vertex->used);
28210
28211 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28212 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28213 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28214 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28215 sarea_priv->last_enqueue = dev_priv->counter - 1;
28216 sarea_priv->last_dispatch = (int)hw_status[5];
28217
28218 @@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
28219 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
28220 mc->last_render);
28221
28222 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28223 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28224 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28225 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28226 sarea_priv->last_enqueue = dev_priv->counter - 1;
28227 sarea_priv->last_dispatch = (int)hw_status[5];
28228
28229 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
28230 index c9339f4..f5e1b9d 100644
28231 --- a/drivers/gpu/drm/i810/i810_drv.h
28232 +++ b/drivers/gpu/drm/i810/i810_drv.h
28233 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
28234 int page_flipping;
28235
28236 wait_queue_head_t irq_queue;
28237 - atomic_t irq_received;
28238 - atomic_t irq_emitted;
28239 + atomic_unchecked_t irq_received;
28240 + atomic_unchecked_t irq_emitted;
28241
28242 int front_offset;
28243 } drm_i810_private_t;
28244 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
28245 index 3c395a5..02889c2 100644
28246 --- a/drivers/gpu/drm/i915/i915_debugfs.c
28247 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
28248 @@ -497,7 +497,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
28249 I915_READ(GTIMR));
28250 }
28251 seq_printf(m, "Interrupts received: %d\n",
28252 - atomic_read(&dev_priv->irq_received));
28253 + atomic_read_unchecked(&dev_priv->irq_received));
28254 for (i = 0; i < I915_NUM_RINGS; i++) {
28255 if (IS_GEN6(dev) || IS_GEN7(dev)) {
28256 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
28257 @@ -1185,7 +1185,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
28258 return ret;
28259
28260 if (opregion->header)
28261 - seq_write(m, opregion->header, OPREGION_SIZE);
28262 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
28263
28264 mutex_unlock(&dev->struct_mutex);
28265
28266 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
28267 index c72b590..aa86f0a 100644
28268 --- a/drivers/gpu/drm/i915/i915_dma.c
28269 +++ b/drivers/gpu/drm/i915/i915_dma.c
28270 @@ -1171,7 +1171,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
28271 bool can_switch;
28272
28273 spin_lock(&dev->count_lock);
28274 - can_switch = (dev->open_count == 0);
28275 + can_switch = (local_read(&dev->open_count) == 0);
28276 spin_unlock(&dev->count_lock);
28277 return can_switch;
28278 }
28279 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
28280 index 1a2a2d1..f280182 100644
28281 --- a/drivers/gpu/drm/i915/i915_drv.h
28282 +++ b/drivers/gpu/drm/i915/i915_drv.h
28283 @@ -222,7 +222,7 @@ struct drm_i915_display_funcs {
28284 /* render clock increase/decrease */
28285 /* display clock increase/decrease */
28286 /* pll clock increase/decrease */
28287 -};
28288 +} __no_const;
28289
28290 struct intel_device_info {
28291 u8 gen;
28292 @@ -305,7 +305,7 @@ typedef struct drm_i915_private {
28293 int current_page;
28294 int page_flipping;
28295
28296 - atomic_t irq_received;
28297 + atomic_unchecked_t irq_received;
28298
28299 /* protects the irq masks */
28300 spinlock_t irq_lock;
28301 @@ -883,7 +883,7 @@ struct drm_i915_gem_object {
28302 * will be page flipped away on the next vblank. When it
28303 * reaches 0, dev_priv->pending_flip_queue will be woken up.
28304 */
28305 - atomic_t pending_flip;
28306 + atomic_unchecked_t pending_flip;
28307 };
28308
28309 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
28310 @@ -1263,7 +1263,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
28311 extern void intel_teardown_gmbus(struct drm_device *dev);
28312 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
28313 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
28314 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
28315 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
28316 {
28317 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
28318 }
28319 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28320 index 4934cf8..1da9c84 100644
28321 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28322 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28323 @@ -188,7 +188,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
28324 i915_gem_clflush_object(obj);
28325
28326 if (obj->base.pending_write_domain)
28327 - cd->flips |= atomic_read(&obj->pending_flip);
28328 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
28329
28330 /* The actual obj->write_domain will be updated with
28331 * pending_write_domain after we emit the accumulated flush for all
28332 @@ -864,9 +864,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
28333
28334 static int
28335 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
28336 - int count)
28337 + unsigned int count)
28338 {
28339 - int i;
28340 + unsigned int i;
28341
28342 for (i = 0; i < count; i++) {
28343 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
28344 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
28345 index 73248d0..f7bac29 100644
28346 --- a/drivers/gpu/drm/i915/i915_irq.c
28347 +++ b/drivers/gpu/drm/i915/i915_irq.c
28348 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
28349 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
28350 struct drm_i915_master_private *master_priv;
28351
28352 - atomic_inc(&dev_priv->irq_received);
28353 + atomic_inc_unchecked(&dev_priv->irq_received);
28354
28355 /* disable master interrupt before clearing iir */
28356 de_ier = I915_READ(DEIER);
28357 @@ -565,7 +565,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
28358 struct drm_i915_master_private *master_priv;
28359 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
28360
28361 - atomic_inc(&dev_priv->irq_received);
28362 + atomic_inc_unchecked(&dev_priv->irq_received);
28363
28364 if (IS_GEN6(dev))
28365 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
28366 @@ -1229,7 +1229,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
28367 int ret = IRQ_NONE, pipe;
28368 bool blc_event = false;
28369
28370 - atomic_inc(&dev_priv->irq_received);
28371 + atomic_inc_unchecked(&dev_priv->irq_received);
28372
28373 iir = I915_READ(IIR);
28374
28375 @@ -1741,7 +1741,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
28376 {
28377 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28378
28379 - atomic_set(&dev_priv->irq_received, 0);
28380 + atomic_set_unchecked(&dev_priv->irq_received, 0);
28381
28382 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28383 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28384 @@ -1905,7 +1905,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
28385 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28386 int pipe;
28387
28388 - atomic_set(&dev_priv->irq_received, 0);
28389 + atomic_set_unchecked(&dev_priv->irq_received, 0);
28390
28391 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28392 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28393 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
28394 index 07e7cf3..c75f312 100644
28395 --- a/drivers/gpu/drm/i915/intel_display.c
28396 +++ b/drivers/gpu/drm/i915/intel_display.c
28397 @@ -2205,7 +2205,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
28398
28399 wait_event(dev_priv->pending_flip_queue,
28400 atomic_read(&dev_priv->mm.wedged) ||
28401 - atomic_read(&obj->pending_flip) == 0);
28402 + atomic_read_unchecked(&obj->pending_flip) == 0);
28403
28404 /* Big Hammer, we also need to ensure that any pending
28405 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
28406 @@ -2826,7 +2826,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
28407 obj = to_intel_framebuffer(crtc->fb)->obj;
28408 dev_priv = crtc->dev->dev_private;
28409 wait_event(dev_priv->pending_flip_queue,
28410 - atomic_read(&obj->pending_flip) == 0);
28411 + atomic_read_unchecked(&obj->pending_flip) == 0);
28412 }
28413
28414 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
28415 @@ -6676,7 +6676,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
28416
28417 atomic_clear_mask(1 << intel_crtc->plane,
28418 &obj->pending_flip.counter);
28419 - if (atomic_read(&obj->pending_flip) == 0)
28420 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
28421 wake_up(&dev_priv->pending_flip_queue);
28422
28423 schedule_work(&work->work);
28424 @@ -6965,7 +6965,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
28425 /* Block clients from rendering to the new back buffer until
28426 * the flip occurs and the object is no longer visible.
28427 */
28428 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28429 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28430
28431 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
28432 if (ret)
28433 @@ -6979,7 +6979,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
28434 return 0;
28435
28436 cleanup_pending:
28437 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28438 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28439 cleanup_objs:
28440 drm_gem_object_unreference(&work->old_fb_obj->base);
28441 drm_gem_object_unreference(&obj->base);
28442 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
28443 index 54558a0..2d97005 100644
28444 --- a/drivers/gpu/drm/mga/mga_drv.h
28445 +++ b/drivers/gpu/drm/mga/mga_drv.h
28446 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
28447 u32 clear_cmd;
28448 u32 maccess;
28449
28450 - atomic_t vbl_received; /**< Number of vblanks received. */
28451 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
28452 wait_queue_head_t fence_queue;
28453 - atomic_t last_fence_retired;
28454 + atomic_unchecked_t last_fence_retired;
28455 u32 next_fence_to_post;
28456
28457 unsigned int fb_cpp;
28458 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
28459 index 2581202..f230a8d9 100644
28460 --- a/drivers/gpu/drm/mga/mga_irq.c
28461 +++ b/drivers/gpu/drm/mga/mga_irq.c
28462 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
28463 if (crtc != 0)
28464 return 0;
28465
28466 - return atomic_read(&dev_priv->vbl_received);
28467 + return atomic_read_unchecked(&dev_priv->vbl_received);
28468 }
28469
28470
28471 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
28472 /* VBLANK interrupt */
28473 if (status & MGA_VLINEPEN) {
28474 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
28475 - atomic_inc(&dev_priv->vbl_received);
28476 + atomic_inc_unchecked(&dev_priv->vbl_received);
28477 drm_handle_vblank(dev, 0);
28478 handled = 1;
28479 }
28480 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
28481 if ((prim_start & ~0x03) != (prim_end & ~0x03))
28482 MGA_WRITE(MGA_PRIMEND, prim_end);
28483
28484 - atomic_inc(&dev_priv->last_fence_retired);
28485 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
28486 DRM_WAKEUP(&dev_priv->fence_queue);
28487 handled = 1;
28488 }
28489 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
28490 * using fences.
28491 */
28492 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
28493 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
28494 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
28495 - *sequence) <= (1 << 23)));
28496
28497 *sequence = cur_fence;
28498 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
28499 index b311fab..dc11d6a 100644
28500 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
28501 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
28502 @@ -201,7 +201,7 @@ struct methods {
28503 const char desc[8];
28504 void (*loadbios)(struct drm_device *, uint8_t *);
28505 const bool rw;
28506 -};
28507 +} __do_const;
28508
28509 static struct methods shadow_methods[] = {
28510 { "PRAMIN", load_vbios_pramin, true },
28511 @@ -5489,7 +5489,7 @@ parse_bit_displayport_tbl_entry(struct drm_device *dev, struct nvbios *bios,
28512 struct bit_table {
28513 const char id;
28514 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
28515 -};
28516 +} __no_const;
28517
28518 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
28519
28520 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
28521 index d7d51de..7c6a7f1 100644
28522 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
28523 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
28524 @@ -238,7 +238,7 @@ struct nouveau_channel {
28525 struct list_head pending;
28526 uint32_t sequence;
28527 uint32_t sequence_ack;
28528 - atomic_t last_sequence_irq;
28529 + atomic_unchecked_t last_sequence_irq;
28530 struct nouveau_vma vma;
28531 } fence;
28532
28533 @@ -319,7 +319,7 @@ struct nouveau_exec_engine {
28534 u32 handle, u16 class);
28535 void (*set_tile_region)(struct drm_device *dev, int i);
28536 void (*tlb_flush)(struct drm_device *, int engine);
28537 -};
28538 +} __no_const;
28539
28540 struct nouveau_instmem_engine {
28541 void *priv;
28542 @@ -341,13 +341,13 @@ struct nouveau_instmem_engine {
28543 struct nouveau_mc_engine {
28544 int (*init)(struct drm_device *dev);
28545 void (*takedown)(struct drm_device *dev);
28546 -};
28547 +} __no_const;
28548
28549 struct nouveau_timer_engine {
28550 int (*init)(struct drm_device *dev);
28551 void (*takedown)(struct drm_device *dev);
28552 uint64_t (*read)(struct drm_device *dev);
28553 -};
28554 +} __no_const;
28555
28556 struct nouveau_fb_engine {
28557 int num_tiles;
28558 @@ -513,7 +513,7 @@ struct nouveau_vram_engine {
28559 void (*put)(struct drm_device *, struct nouveau_mem **);
28560
28561 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
28562 -};
28563 +} __no_const;
28564
28565 struct nouveau_engine {
28566 struct nouveau_instmem_engine instmem;
28567 @@ -660,7 +660,7 @@ struct drm_nouveau_private {
28568 struct drm_global_reference mem_global_ref;
28569 struct ttm_bo_global_ref bo_global_ref;
28570 struct ttm_bo_device bdev;
28571 - atomic_t validate_sequence;
28572 + atomic_unchecked_t validate_sequence;
28573 } ttm;
28574
28575 struct {
28576 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
28577 index ae22dfa..4f09960 100644
28578 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
28579 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
28580 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
28581 if (USE_REFCNT(dev))
28582 sequence = nvchan_rd32(chan, 0x48);
28583 else
28584 - sequence = atomic_read(&chan->fence.last_sequence_irq);
28585 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
28586
28587 if (chan->fence.sequence_ack == sequence)
28588 goto out;
28589 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
28590 return ret;
28591 }
28592
28593 - atomic_set(&chan->fence.last_sequence_irq, 0);
28594 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
28595 return 0;
28596 }
28597
28598 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
28599 index 5f0bc57..eb9fac8 100644
28600 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
28601 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
28602 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
28603 int trycnt = 0;
28604 int ret, i;
28605
28606 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
28607 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
28608 retry:
28609 if (++trycnt > 100000) {
28610 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
28611 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
28612 index 10656e4..59bf2a4 100644
28613 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
28614 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
28615 @@ -496,7 +496,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
28616 bool can_switch;
28617
28618 spin_lock(&dev->count_lock);
28619 - can_switch = (dev->open_count == 0);
28620 + can_switch = (local_read(&dev->open_count) == 0);
28621 spin_unlock(&dev->count_lock);
28622 return can_switch;
28623 }
28624 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
28625 index dbdea8e..cd6eeeb 100644
28626 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
28627 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
28628 @@ -554,7 +554,7 @@ static int
28629 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
28630 u32 class, u32 mthd, u32 data)
28631 {
28632 - atomic_set(&chan->fence.last_sequence_irq, data);
28633 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
28634 return 0;
28635 }
28636
28637 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
28638 index 570e190..084a31a 100644
28639 --- a/drivers/gpu/drm/r128/r128_cce.c
28640 +++ b/drivers/gpu/drm/r128/r128_cce.c
28641 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
28642
28643 /* GH: Simple idle check.
28644 */
28645 - atomic_set(&dev_priv->idle_count, 0);
28646 + atomic_set_unchecked(&dev_priv->idle_count, 0);
28647
28648 /* We don't support anything other than bus-mastering ring mode,
28649 * but the ring can be in either AGP or PCI space for the ring
28650 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
28651 index 930c71b..499aded 100644
28652 --- a/drivers/gpu/drm/r128/r128_drv.h
28653 +++ b/drivers/gpu/drm/r128/r128_drv.h
28654 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
28655 int is_pci;
28656 unsigned long cce_buffers_offset;
28657
28658 - atomic_t idle_count;
28659 + atomic_unchecked_t idle_count;
28660
28661 int page_flipping;
28662 int current_page;
28663 u32 crtc_offset;
28664 u32 crtc_offset_cntl;
28665
28666 - atomic_t vbl_received;
28667 + atomic_unchecked_t vbl_received;
28668
28669 u32 color_fmt;
28670 unsigned int front_offset;
28671 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
28672 index 429d5a0..7e899ed 100644
28673 --- a/drivers/gpu/drm/r128/r128_irq.c
28674 +++ b/drivers/gpu/drm/r128/r128_irq.c
28675 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
28676 if (crtc != 0)
28677 return 0;
28678
28679 - return atomic_read(&dev_priv->vbl_received);
28680 + return atomic_read_unchecked(&dev_priv->vbl_received);
28681 }
28682
28683 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28684 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28685 /* VBLANK interrupt */
28686 if (status & R128_CRTC_VBLANK_INT) {
28687 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
28688 - atomic_inc(&dev_priv->vbl_received);
28689 + atomic_inc_unchecked(&dev_priv->vbl_received);
28690 drm_handle_vblank(dev, 0);
28691 return IRQ_HANDLED;
28692 }
28693 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
28694 index a9e33ce..09edd4b 100644
28695 --- a/drivers/gpu/drm/r128/r128_state.c
28696 +++ b/drivers/gpu/drm/r128/r128_state.c
28697 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
28698
28699 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
28700 {
28701 - if (atomic_read(&dev_priv->idle_count) == 0)
28702 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
28703 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
28704 else
28705 - atomic_set(&dev_priv->idle_count, 0);
28706 + atomic_set_unchecked(&dev_priv->idle_count, 0);
28707 }
28708
28709 #endif
28710 diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
28711 index 14cc88a..cc7b3a5 100644
28712 --- a/drivers/gpu/drm/radeon/atom.c
28713 +++ b/drivers/gpu/drm/radeon/atom.c
28714 @@ -1254,6 +1254,8 @@ struct atom_context *atom_parse(struct card_info *card, void *bios)
28715 char name[512];
28716 int i;
28717
28718 + pax_track_stack();
28719 +
28720 if (!ctx)
28721 return NULL;
28722
28723 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
28724 index 5a82b6b..9e69c73 100644
28725 --- a/drivers/gpu/drm/radeon/mkregtable.c
28726 +++ b/drivers/gpu/drm/radeon/mkregtable.c
28727 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
28728 regex_t mask_rex;
28729 regmatch_t match[4];
28730 char buf[1024];
28731 - size_t end;
28732 + long end;
28733 int len;
28734 int done = 0;
28735 int r;
28736 unsigned o;
28737 struct offset *offset;
28738 char last_reg_s[10];
28739 - int last_reg;
28740 + unsigned long last_reg;
28741
28742 if (regcomp
28743 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
28744 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
28745 index 184628c..30e1725 100644
28746 --- a/drivers/gpu/drm/radeon/radeon.h
28747 +++ b/drivers/gpu/drm/radeon/radeon.h
28748 @@ -192,7 +192,7 @@ extern int sumo_get_temp(struct radeon_device *rdev);
28749 */
28750 struct radeon_fence_driver {
28751 uint32_t scratch_reg;
28752 - atomic_t seq;
28753 + atomic_unchecked_t seq;
28754 uint32_t last_seq;
28755 unsigned long last_jiffies;
28756 unsigned long last_timeout;
28757 @@ -962,7 +962,7 @@ struct radeon_asic {
28758 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
28759 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
28760 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
28761 -};
28762 +} __no_const;
28763
28764 /*
28765 * Asic structures
28766 diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
28767 index a098edc..d001c09 100644
28768 --- a/drivers/gpu/drm/radeon/radeon_atombios.c
28769 +++ b/drivers/gpu/drm/radeon/radeon_atombios.c
28770 @@ -569,6 +569,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
28771 struct radeon_gpio_rec gpio;
28772 struct radeon_hpd hpd;
28773
28774 + pax_track_stack();
28775 +
28776 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
28777 return false;
28778
28779 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
28780 index b51e157..8f14fb9 100644
28781 --- a/drivers/gpu/drm/radeon/radeon_device.c
28782 +++ b/drivers/gpu/drm/radeon/radeon_device.c
28783 @@ -684,7 +684,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
28784 bool can_switch;
28785
28786 spin_lock(&dev->count_lock);
28787 - can_switch = (dev->open_count == 0);
28788 + can_switch = (local_read(&dev->open_count) == 0);
28789 spin_unlock(&dev->count_lock);
28790 return can_switch;
28791 }
28792 diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
28793 index 07ac481..41cb437 100644
28794 --- a/drivers/gpu/drm/radeon/radeon_display.c
28795 +++ b/drivers/gpu/drm/radeon/radeon_display.c
28796 @@ -926,6 +926,8 @@ void radeon_compute_pll_legacy(struct radeon_pll *pll,
28797 uint32_t post_div;
28798 u32 pll_out_min, pll_out_max;
28799
28800 + pax_track_stack();
28801 +
28802 DRM_DEBUG_KMS("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div);
28803 freq = freq * 1000;
28804
28805 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
28806 index a1b59ca..86f2d44 100644
28807 --- a/drivers/gpu/drm/radeon/radeon_drv.h
28808 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
28809 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
28810
28811 /* SW interrupt */
28812 wait_queue_head_t swi_queue;
28813 - atomic_t swi_emitted;
28814 + atomic_unchecked_t swi_emitted;
28815 int vblank_crtc;
28816 uint32_t irq_enable_reg;
28817 uint32_t r500_disp_irq_reg;
28818 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
28819 index 7fd4e3e..9748ab5 100644
28820 --- a/drivers/gpu/drm/radeon/radeon_fence.c
28821 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
28822 @@ -78,7 +78,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
28823 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
28824 return 0;
28825 }
28826 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
28827 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
28828 if (!rdev->cp.ready)
28829 /* FIXME: cp is not running assume everythings is done right
28830 * away
28831 @@ -373,7 +373,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
28832 return r;
28833 }
28834 radeon_fence_write(rdev, 0);
28835 - atomic_set(&rdev->fence_drv.seq, 0);
28836 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
28837 INIT_LIST_HEAD(&rdev->fence_drv.created);
28838 INIT_LIST_HEAD(&rdev->fence_drv.emited);
28839 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
28840 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
28841 index 48b7cea..342236f 100644
28842 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
28843 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
28844 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
28845 request = compat_alloc_user_space(sizeof(*request));
28846 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
28847 || __put_user(req32.param, &request->param)
28848 - || __put_user((void __user *)(unsigned long)req32.value,
28849 + || __put_user((unsigned long)req32.value,
28850 &request->value))
28851 return -EFAULT;
28852
28853 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
28854 index 465746b..cb2b055 100644
28855 --- a/drivers/gpu/drm/radeon/radeon_irq.c
28856 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
28857 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
28858 unsigned int ret;
28859 RING_LOCALS;
28860
28861 - atomic_inc(&dev_priv->swi_emitted);
28862 - ret = atomic_read(&dev_priv->swi_emitted);
28863 + atomic_inc_unchecked(&dev_priv->swi_emitted);
28864 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
28865
28866 BEGIN_RING(4);
28867 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
28868 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
28869 drm_radeon_private_t *dev_priv =
28870 (drm_radeon_private_t *) dev->dev_private;
28871
28872 - atomic_set(&dev_priv->swi_emitted, 0);
28873 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
28874 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
28875
28876 dev->max_vblank_count = 0x001fffff;
28877 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
28878 index 92e7ea7..147ffad 100644
28879 --- a/drivers/gpu/drm/radeon/radeon_state.c
28880 +++ b/drivers/gpu/drm/radeon/radeon_state.c
28881 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
28882 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
28883 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
28884
28885 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
28886 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
28887 sarea_priv->nbox * sizeof(depth_boxes[0])))
28888 return -EFAULT;
28889
28890 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
28891 {
28892 drm_radeon_private_t *dev_priv = dev->dev_private;
28893 drm_radeon_getparam_t *param = data;
28894 - int value;
28895 + int value = 0;
28896
28897 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
28898
28899 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
28900 index 0b5468b..9c4b308 100644
28901 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
28902 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
28903 @@ -672,8 +672,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
28904 }
28905 if (unlikely(ttm_vm_ops == NULL)) {
28906 ttm_vm_ops = vma->vm_ops;
28907 - radeon_ttm_vm_ops = *ttm_vm_ops;
28908 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
28909 + pax_open_kernel();
28910 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
28911 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
28912 + pax_close_kernel();
28913 }
28914 vma->vm_ops = &radeon_ttm_vm_ops;
28915 return 0;
28916 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
28917 index a9049ed..501f284 100644
28918 --- a/drivers/gpu/drm/radeon/rs690.c
28919 +++ b/drivers/gpu/drm/radeon/rs690.c
28920 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
28921 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
28922 rdev->pm.sideport_bandwidth.full)
28923 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
28924 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
28925 + read_delay_latency.full = dfixed_const(800 * 1000);
28926 read_delay_latency.full = dfixed_div(read_delay_latency,
28927 rdev->pm.igp_sideport_mclk);
28928 + a.full = dfixed_const(370);
28929 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
28930 } else {
28931 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
28932 rdev->pm.k8_bandwidth.full)
28933 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
28934 index 727e93d..1565650 100644
28935 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
28936 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
28937 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
28938 static int ttm_pool_mm_shrink(struct shrinker *shrink,
28939 struct shrink_control *sc)
28940 {
28941 - static atomic_t start_pool = ATOMIC_INIT(0);
28942 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
28943 unsigned i;
28944 - unsigned pool_offset = atomic_add_return(1, &start_pool);
28945 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
28946 struct ttm_page_pool *pool;
28947 int shrink_pages = sc->nr_to_scan;
28948
28949 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
28950 index 9cf87d9..2000b7d 100644
28951 --- a/drivers/gpu/drm/via/via_drv.h
28952 +++ b/drivers/gpu/drm/via/via_drv.h
28953 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
28954 typedef uint32_t maskarray_t[5];
28955
28956 typedef struct drm_via_irq {
28957 - atomic_t irq_received;
28958 + atomic_unchecked_t irq_received;
28959 uint32_t pending_mask;
28960 uint32_t enable_mask;
28961 wait_queue_head_t irq_queue;
28962 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
28963 struct timeval last_vblank;
28964 int last_vblank_valid;
28965 unsigned usec_per_vblank;
28966 - atomic_t vbl_received;
28967 + atomic_unchecked_t vbl_received;
28968 drm_via_state_t hc_state;
28969 char pci_buf[VIA_PCI_BUF_SIZE];
28970 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
28971 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
28972 index d391f48..10c8ca3 100644
28973 --- a/drivers/gpu/drm/via/via_irq.c
28974 +++ b/drivers/gpu/drm/via/via_irq.c
28975 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
28976 if (crtc != 0)
28977 return 0;
28978
28979 - return atomic_read(&dev_priv->vbl_received);
28980 + return atomic_read_unchecked(&dev_priv->vbl_received);
28981 }
28982
28983 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
28984 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
28985
28986 status = VIA_READ(VIA_REG_INTERRUPT);
28987 if (status & VIA_IRQ_VBLANK_PENDING) {
28988 - atomic_inc(&dev_priv->vbl_received);
28989 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
28990 + atomic_inc_unchecked(&dev_priv->vbl_received);
28991 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
28992 do_gettimeofday(&cur_vblank);
28993 if (dev_priv->last_vblank_valid) {
28994 dev_priv->usec_per_vblank =
28995 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
28996 dev_priv->last_vblank = cur_vblank;
28997 dev_priv->last_vblank_valid = 1;
28998 }
28999 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
29000 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
29001 DRM_DEBUG("US per vblank is: %u\n",
29002 dev_priv->usec_per_vblank);
29003 }
29004 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29005
29006 for (i = 0; i < dev_priv->num_irqs; ++i) {
29007 if (status & cur_irq->pending_mask) {
29008 - atomic_inc(&cur_irq->irq_received);
29009 + atomic_inc_unchecked(&cur_irq->irq_received);
29010 DRM_WAKEUP(&cur_irq->irq_queue);
29011 handled = 1;
29012 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
29013 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
29014 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29015 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
29016 masks[irq][4]));
29017 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
29018 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
29019 } else {
29020 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29021 (((cur_irq_sequence =
29022 - atomic_read(&cur_irq->irq_received)) -
29023 + atomic_read_unchecked(&cur_irq->irq_received)) -
29024 *sequence) <= (1 << 23)));
29025 }
29026 *sequence = cur_irq_sequence;
29027 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
29028 }
29029
29030 for (i = 0; i < dev_priv->num_irqs; ++i) {
29031 - atomic_set(&cur_irq->irq_received, 0);
29032 + atomic_set_unchecked(&cur_irq->irq_received, 0);
29033 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
29034 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
29035 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
29036 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
29037 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
29038 case VIA_IRQ_RELATIVE:
29039 irqwait->request.sequence +=
29040 - atomic_read(&cur_irq->irq_received);
29041 + atomic_read_unchecked(&cur_irq->irq_received);
29042 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
29043 case VIA_IRQ_ABSOLUTE:
29044 break;
29045 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29046 index 10fc01f..b4e9822 100644
29047 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29048 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29049 @@ -240,7 +240,7 @@ struct vmw_private {
29050 * Fencing and IRQs.
29051 */
29052
29053 - atomic_t fence_seq;
29054 + atomic_unchecked_t fence_seq;
29055 wait_queue_head_t fence_queue;
29056 wait_queue_head_t fifo_queue;
29057 atomic_t fence_queue_waiters;
29058 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
29059 index 41b95ed..69ea504 100644
29060 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
29061 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
29062 @@ -610,7 +610,7 @@ int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
29063 struct drm_vmw_fence_rep fence_rep;
29064 struct drm_vmw_fence_rep __user *user_fence_rep;
29065 int ret;
29066 - void *user_cmd;
29067 + void __user *user_cmd;
29068 void *cmd;
29069 uint32_t sequence;
29070 struct vmw_sw_context *sw_context = &dev_priv->ctx;
29071 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
29072 index 61eacc1..ee38ce8 100644
29073 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
29074 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
29075 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
29076 while (!vmw_lag_lt(queue, us)) {
29077 spin_lock(&queue->lock);
29078 if (list_empty(&queue->head))
29079 - sequence = atomic_read(&dev_priv->fence_seq);
29080 + sequence = atomic_read_unchecked(&dev_priv->fence_seq);
29081 else {
29082 fence = list_first_entry(&queue->head,
29083 struct vmw_fence, head);
29084 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29085 index 635c0ff..2641bbb 100644
29086 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29087 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29088 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
29089 (unsigned int) min,
29090 (unsigned int) fifo->capabilities);
29091
29092 - atomic_set(&dev_priv->fence_seq, dev_priv->last_read_sequence);
29093 + atomic_set_unchecked(&dev_priv->fence_seq, dev_priv->last_read_sequence);
29094 iowrite32(dev_priv->last_read_sequence, fifo_mem + SVGA_FIFO_FENCE);
29095 vmw_fence_queue_init(&fifo->fence_queue);
29096 return vmw_fifo_send_fence(dev_priv, &dummy);
29097 @@ -356,7 +356,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
29098 if (reserveable)
29099 iowrite32(bytes, fifo_mem +
29100 SVGA_FIFO_RESERVED);
29101 - return fifo_mem + (next_cmd >> 2);
29102 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
29103 } else {
29104 need_bounce = true;
29105 }
29106 @@ -476,7 +476,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *sequence)
29107
29108 fm = vmw_fifo_reserve(dev_priv, bytes);
29109 if (unlikely(fm == NULL)) {
29110 - *sequence = atomic_read(&dev_priv->fence_seq);
29111 + *sequence = atomic_read_unchecked(&dev_priv->fence_seq);
29112 ret = -ENOMEM;
29113 (void)vmw_fallback_wait(dev_priv, false, true, *sequence,
29114 false, 3*HZ);
29115 @@ -484,7 +484,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *sequence)
29116 }
29117
29118 do {
29119 - *sequence = atomic_add_return(1, &dev_priv->fence_seq);
29120 + *sequence = atomic_add_return_unchecked(1, &dev_priv->fence_seq);
29121 } while (*sequence == 0);
29122
29123 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
29124 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29125 index e92298a..f68f2d6 100644
29126 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29127 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29128 @@ -100,7 +100,7 @@ bool vmw_fence_signaled(struct vmw_private *dev_priv,
29129 * emitted. Then the fence is stale and signaled.
29130 */
29131
29132 - ret = ((atomic_read(&dev_priv->fence_seq) - sequence)
29133 + ret = ((atomic_read_unchecked(&dev_priv->fence_seq) - sequence)
29134 > VMW_FENCE_WRAP);
29135
29136 return ret;
29137 @@ -131,7 +131,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
29138
29139 if (fifo_idle)
29140 down_read(&fifo_state->rwsem);
29141 - signal_seq = atomic_read(&dev_priv->fence_seq);
29142 + signal_seq = atomic_read_unchecked(&dev_priv->fence_seq);
29143 ret = 0;
29144
29145 for (;;) {
29146 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
29147 index dfe32e6..dd18a00 100644
29148 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
29149 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
29150 @@ -843,7 +843,6 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
29151 struct vmw_framebuffer *vfb = NULL;
29152 struct vmw_surface *surface = NULL;
29153 struct vmw_dma_buffer *bo = NULL;
29154 - u64 required_size;
29155 int ret;
29156
29157 /**
29158 @@ -852,8 +851,9 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
29159 * requested framebuffer.
29160 */
29161
29162 - required_size = mode_cmd->pitch * mode_cmd->height;
29163 - if (unlikely(required_size > (u64) dev_priv->vram_size)) {
29164 + if (!vmw_kms_validate_mode_vram(dev_priv,
29165 + mode_cmd->pitch,
29166 + mode_cmd->height)) {
29167 DRM_ERROR("VRAM size is too small for requested mode.\n");
29168 return NULL;
29169 }
29170 diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
29171 index c72f1c0..18376f1 100644
29172 --- a/drivers/gpu/vga/vgaarb.c
29173 +++ b/drivers/gpu/vga/vgaarb.c
29174 @@ -993,14 +993,20 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
29175 uc = &priv->cards[i];
29176 }
29177
29178 - if (!uc)
29179 - return -EINVAL;
29180 + if (!uc) {
29181 + ret_val = -EINVAL;
29182 + goto done;
29183 + }
29184
29185 - if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0)
29186 - return -EINVAL;
29187 + if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0) {
29188 + ret_val = -EINVAL;
29189 + goto done;
29190 + }
29191
29192 - if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0)
29193 - return -EINVAL;
29194 + if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0) {
29195 + ret_val = -EINVAL;
29196 + goto done;
29197 + }
29198
29199 vga_put(pdev, io_state);
29200
29201 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
29202 index f26ae31..721fe1b 100644
29203 --- a/drivers/hid/hid-core.c
29204 +++ b/drivers/hid/hid-core.c
29205 @@ -1951,7 +1951,7 @@ static bool hid_ignore(struct hid_device *hdev)
29206
29207 int hid_add_device(struct hid_device *hdev)
29208 {
29209 - static atomic_t id = ATOMIC_INIT(0);
29210 + static atomic_unchecked_t id = ATOMIC_INIT(0);
29211 int ret;
29212
29213 if (WARN_ON(hdev->status & HID_STAT_ADDED))
29214 @@ -1966,7 +1966,7 @@ int hid_add_device(struct hid_device *hdev)
29215 /* XXX hack, any other cleaner solution after the driver core
29216 * is converted to allow more than 20 bytes as the device name? */
29217 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
29218 - hdev->vendor, hdev->product, atomic_inc_return(&id));
29219 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
29220
29221 hid_debug_register(hdev, dev_name(&hdev->dev));
29222 ret = device_add(&hdev->dev);
29223 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
29224 index 7c1188b..5a64357 100644
29225 --- a/drivers/hid/usbhid/hiddev.c
29226 +++ b/drivers/hid/usbhid/hiddev.c
29227 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29228 break;
29229
29230 case HIDIOCAPPLICATION:
29231 - if (arg < 0 || arg >= hid->maxapplication)
29232 + if (arg >= hid->maxapplication)
29233 break;
29234
29235 for (i = 0; i < hid->maxcollection; i++)
29236 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
29237 index 66f6729..2d6de0a 100644
29238 --- a/drivers/hwmon/acpi_power_meter.c
29239 +++ b/drivers/hwmon/acpi_power_meter.c
29240 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
29241 return res;
29242
29243 temp /= 1000;
29244 - if (temp < 0)
29245 - return -EINVAL;
29246
29247 mutex_lock(&resource->lock);
29248 resource->trip[attr->index - 7] = temp;
29249 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
29250 index fe4104c..346febb 100644
29251 --- a/drivers/hwmon/sht15.c
29252 +++ b/drivers/hwmon/sht15.c
29253 @@ -166,7 +166,7 @@ struct sht15_data {
29254 int supply_uV;
29255 bool supply_uV_valid;
29256 struct work_struct update_supply_work;
29257 - atomic_t interrupt_handled;
29258 + atomic_unchecked_t interrupt_handled;
29259 };
29260
29261 /**
29262 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
29263 return ret;
29264
29265 gpio_direction_input(data->pdata->gpio_data);
29266 - atomic_set(&data->interrupt_handled, 0);
29267 + atomic_set_unchecked(&data->interrupt_handled, 0);
29268
29269 enable_irq(gpio_to_irq(data->pdata->gpio_data));
29270 if (gpio_get_value(data->pdata->gpio_data) == 0) {
29271 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
29272 /* Only relevant if the interrupt hasn't occurred. */
29273 - if (!atomic_read(&data->interrupt_handled))
29274 + if (!atomic_read_unchecked(&data->interrupt_handled))
29275 schedule_work(&data->read_work);
29276 }
29277 ret = wait_event_timeout(data->wait_queue,
29278 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
29279
29280 /* First disable the interrupt */
29281 disable_irq_nosync(irq);
29282 - atomic_inc(&data->interrupt_handled);
29283 + atomic_inc_unchecked(&data->interrupt_handled);
29284 /* Then schedule a reading work struct */
29285 if (data->state != SHT15_READING_NOTHING)
29286 schedule_work(&data->read_work);
29287 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
29288 * If not, then start the interrupt again - care here as could
29289 * have gone low in meantime so verify it hasn't!
29290 */
29291 - atomic_set(&data->interrupt_handled, 0);
29292 + atomic_set_unchecked(&data->interrupt_handled, 0);
29293 enable_irq(gpio_to_irq(data->pdata->gpio_data));
29294 /* If still not occurred or another handler has been scheduled */
29295 if (gpio_get_value(data->pdata->gpio_data)
29296 - || atomic_read(&data->interrupt_handled))
29297 + || atomic_read_unchecked(&data->interrupt_handled))
29298 return;
29299 }
29300
29301 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
29302 index 378fcb5..5e91fa8 100644
29303 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
29304 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
29305 @@ -43,7 +43,7 @@
29306 extern struct i2c_adapter amd756_smbus;
29307
29308 static struct i2c_adapter *s4882_adapter;
29309 -static struct i2c_algorithm *s4882_algo;
29310 +static i2c_algorithm_no_const *s4882_algo;
29311
29312 /* Wrapper access functions for multiplexed SMBus */
29313 static DEFINE_MUTEX(amd756_lock);
29314 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
29315 index 29015eb..af2d8e9 100644
29316 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
29317 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
29318 @@ -41,7 +41,7 @@
29319 extern struct i2c_adapter *nforce2_smbus;
29320
29321 static struct i2c_adapter *s4985_adapter;
29322 -static struct i2c_algorithm *s4985_algo;
29323 +static i2c_algorithm_no_const *s4985_algo;
29324
29325 /* Wrapper access functions for multiplexed SMBus */
29326 static DEFINE_MUTEX(nforce2_lock);
29327 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
29328 index d7a4833..7fae376 100644
29329 --- a/drivers/i2c/i2c-mux.c
29330 +++ b/drivers/i2c/i2c-mux.c
29331 @@ -28,7 +28,7 @@
29332 /* multiplexer per channel data */
29333 struct i2c_mux_priv {
29334 struct i2c_adapter adap;
29335 - struct i2c_algorithm algo;
29336 + i2c_algorithm_no_const algo;
29337
29338 struct i2c_adapter *parent;
29339 void *mux_dev; /* the mux chip/device */
29340 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
29341 index 57d00ca..0145194 100644
29342 --- a/drivers/ide/aec62xx.c
29343 +++ b/drivers/ide/aec62xx.c
29344 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
29345 .cable_detect = atp86x_cable_detect,
29346 };
29347
29348 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
29349 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
29350 { /* 0: AEC6210 */
29351 .name = DRV_NAME,
29352 .init_chipset = init_chipset_aec62xx,
29353 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
29354 index 2c8016a..911a27c 100644
29355 --- a/drivers/ide/alim15x3.c
29356 +++ b/drivers/ide/alim15x3.c
29357 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
29358 .dma_sff_read_status = ide_dma_sff_read_status,
29359 };
29360
29361 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
29362 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
29363 .name = DRV_NAME,
29364 .init_chipset = init_chipset_ali15x3,
29365 .init_hwif = init_hwif_ali15x3,
29366 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
29367 index 3747b25..56fc995 100644
29368 --- a/drivers/ide/amd74xx.c
29369 +++ b/drivers/ide/amd74xx.c
29370 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
29371 .udma_mask = udma, \
29372 }
29373
29374 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
29375 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
29376 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
29377 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
29378 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
29379 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
29380 index 15f0ead..cb43480 100644
29381 --- a/drivers/ide/atiixp.c
29382 +++ b/drivers/ide/atiixp.c
29383 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
29384 .cable_detect = atiixp_cable_detect,
29385 };
29386
29387 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
29388 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
29389 { /* 0: IXP200/300/400/700 */
29390 .name = DRV_NAME,
29391 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
29392 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
29393 index 5f80312..d1fc438 100644
29394 --- a/drivers/ide/cmd64x.c
29395 +++ b/drivers/ide/cmd64x.c
29396 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
29397 .dma_sff_read_status = ide_dma_sff_read_status,
29398 };
29399
29400 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
29401 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
29402 { /* 0: CMD643 */
29403 .name = DRV_NAME,
29404 .init_chipset = init_chipset_cmd64x,
29405 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
29406 index 2c1e5f7..1444762 100644
29407 --- a/drivers/ide/cs5520.c
29408 +++ b/drivers/ide/cs5520.c
29409 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
29410 .set_dma_mode = cs5520_set_dma_mode,
29411 };
29412
29413 -static const struct ide_port_info cyrix_chipset __devinitdata = {
29414 +static const struct ide_port_info cyrix_chipset __devinitconst = {
29415 .name = DRV_NAME,
29416 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
29417 .port_ops = &cs5520_port_ops,
29418 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
29419 index 4dc4eb9..49b40ad 100644
29420 --- a/drivers/ide/cs5530.c
29421 +++ b/drivers/ide/cs5530.c
29422 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
29423 .udma_filter = cs5530_udma_filter,
29424 };
29425
29426 -static const struct ide_port_info cs5530_chipset __devinitdata = {
29427 +static const struct ide_port_info cs5530_chipset __devinitconst = {
29428 .name = DRV_NAME,
29429 .init_chipset = init_chipset_cs5530,
29430 .init_hwif = init_hwif_cs5530,
29431 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
29432 index 5059faf..18d4c85 100644
29433 --- a/drivers/ide/cs5535.c
29434 +++ b/drivers/ide/cs5535.c
29435 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
29436 .cable_detect = cs5535_cable_detect,
29437 };
29438
29439 -static const struct ide_port_info cs5535_chipset __devinitdata = {
29440 +static const struct ide_port_info cs5535_chipset __devinitconst = {
29441 .name = DRV_NAME,
29442 .port_ops = &cs5535_port_ops,
29443 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
29444 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
29445 index 67cbcfa..37ea151 100644
29446 --- a/drivers/ide/cy82c693.c
29447 +++ b/drivers/ide/cy82c693.c
29448 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
29449 .set_dma_mode = cy82c693_set_dma_mode,
29450 };
29451
29452 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
29453 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
29454 .name = DRV_NAME,
29455 .init_iops = init_iops_cy82c693,
29456 .port_ops = &cy82c693_port_ops,
29457 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
29458 index 58c51cd..4aec3b8 100644
29459 --- a/drivers/ide/hpt366.c
29460 +++ b/drivers/ide/hpt366.c
29461 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
29462 }
29463 };
29464
29465 -static const struct hpt_info hpt36x __devinitdata = {
29466 +static const struct hpt_info hpt36x __devinitconst = {
29467 .chip_name = "HPT36x",
29468 .chip_type = HPT36x,
29469 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
29470 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
29471 .timings = &hpt36x_timings
29472 };
29473
29474 -static const struct hpt_info hpt370 __devinitdata = {
29475 +static const struct hpt_info hpt370 __devinitconst = {
29476 .chip_name = "HPT370",
29477 .chip_type = HPT370,
29478 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
29479 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
29480 .timings = &hpt37x_timings
29481 };
29482
29483 -static const struct hpt_info hpt370a __devinitdata = {
29484 +static const struct hpt_info hpt370a __devinitconst = {
29485 .chip_name = "HPT370A",
29486 .chip_type = HPT370A,
29487 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
29488 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
29489 .timings = &hpt37x_timings
29490 };
29491
29492 -static const struct hpt_info hpt374 __devinitdata = {
29493 +static const struct hpt_info hpt374 __devinitconst = {
29494 .chip_name = "HPT374",
29495 .chip_type = HPT374,
29496 .udma_mask = ATA_UDMA5,
29497 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
29498 .timings = &hpt37x_timings
29499 };
29500
29501 -static const struct hpt_info hpt372 __devinitdata = {
29502 +static const struct hpt_info hpt372 __devinitconst = {
29503 .chip_name = "HPT372",
29504 .chip_type = HPT372,
29505 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29506 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
29507 .timings = &hpt37x_timings
29508 };
29509
29510 -static const struct hpt_info hpt372a __devinitdata = {
29511 +static const struct hpt_info hpt372a __devinitconst = {
29512 .chip_name = "HPT372A",
29513 .chip_type = HPT372A,
29514 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29515 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
29516 .timings = &hpt37x_timings
29517 };
29518
29519 -static const struct hpt_info hpt302 __devinitdata = {
29520 +static const struct hpt_info hpt302 __devinitconst = {
29521 .chip_name = "HPT302",
29522 .chip_type = HPT302,
29523 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29524 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
29525 .timings = &hpt37x_timings
29526 };
29527
29528 -static const struct hpt_info hpt371 __devinitdata = {
29529 +static const struct hpt_info hpt371 __devinitconst = {
29530 .chip_name = "HPT371",
29531 .chip_type = HPT371,
29532 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29533 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
29534 .timings = &hpt37x_timings
29535 };
29536
29537 -static const struct hpt_info hpt372n __devinitdata = {
29538 +static const struct hpt_info hpt372n __devinitconst = {
29539 .chip_name = "HPT372N",
29540 .chip_type = HPT372N,
29541 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29542 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
29543 .timings = &hpt37x_timings
29544 };
29545
29546 -static const struct hpt_info hpt302n __devinitdata = {
29547 +static const struct hpt_info hpt302n __devinitconst = {
29548 .chip_name = "HPT302N",
29549 .chip_type = HPT302N,
29550 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29551 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
29552 .timings = &hpt37x_timings
29553 };
29554
29555 -static const struct hpt_info hpt371n __devinitdata = {
29556 +static const struct hpt_info hpt371n __devinitconst = {
29557 .chip_name = "HPT371N",
29558 .chip_type = HPT371N,
29559 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29560 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
29561 .dma_sff_read_status = ide_dma_sff_read_status,
29562 };
29563
29564 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
29565 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
29566 { /* 0: HPT36x */
29567 .name = DRV_NAME,
29568 .init_chipset = init_chipset_hpt366,
29569 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
29570 index 04b0956..f5b47dc 100644
29571 --- a/drivers/ide/ide-cd.c
29572 +++ b/drivers/ide/ide-cd.c
29573 @@ -769,7 +769,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
29574 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
29575 if ((unsigned long)buf & alignment
29576 || blk_rq_bytes(rq) & q->dma_pad_mask
29577 - || object_is_on_stack(buf))
29578 + || object_starts_on_stack(buf))
29579 drive->dma = 0;
29580 }
29581 }
29582 diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
29583 index 61fdf54..2834ea6 100644
29584 --- a/drivers/ide/ide-floppy.c
29585 +++ b/drivers/ide/ide-floppy.c
29586 @@ -379,6 +379,8 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
29587 u8 pc_buf[256], header_len, desc_cnt;
29588 int i, rc = 1, blocks, length;
29589
29590 + pax_track_stack();
29591 +
29592 ide_debug_log(IDE_DBG_FUNC, "enter");
29593
29594 drive->bios_cyl = 0;
29595 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
29596 index a743e68..1cfd674 100644
29597 --- a/drivers/ide/ide-pci-generic.c
29598 +++ b/drivers/ide/ide-pci-generic.c
29599 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
29600 .udma_mask = ATA_UDMA6, \
29601 }
29602
29603 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
29604 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
29605 /* 0: Unknown */
29606 DECLARE_GENERIC_PCI_DEV(0),
29607
29608 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
29609 index 560e66d..d5dd180 100644
29610 --- a/drivers/ide/it8172.c
29611 +++ b/drivers/ide/it8172.c
29612 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
29613 .set_dma_mode = it8172_set_dma_mode,
29614 };
29615
29616 -static const struct ide_port_info it8172_port_info __devinitdata = {
29617 +static const struct ide_port_info it8172_port_info __devinitconst = {
29618 .name = DRV_NAME,
29619 .port_ops = &it8172_port_ops,
29620 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
29621 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
29622 index 46816ba..1847aeb 100644
29623 --- a/drivers/ide/it8213.c
29624 +++ b/drivers/ide/it8213.c
29625 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
29626 .cable_detect = it8213_cable_detect,
29627 };
29628
29629 -static const struct ide_port_info it8213_chipset __devinitdata = {
29630 +static const struct ide_port_info it8213_chipset __devinitconst = {
29631 .name = DRV_NAME,
29632 .enablebits = { {0x41, 0x80, 0x80} },
29633 .port_ops = &it8213_port_ops,
29634 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
29635 index 2e3169f..c5611db 100644
29636 --- a/drivers/ide/it821x.c
29637 +++ b/drivers/ide/it821x.c
29638 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
29639 .cable_detect = it821x_cable_detect,
29640 };
29641
29642 -static const struct ide_port_info it821x_chipset __devinitdata = {
29643 +static const struct ide_port_info it821x_chipset __devinitconst = {
29644 .name = DRV_NAME,
29645 .init_chipset = init_chipset_it821x,
29646 .init_hwif = init_hwif_it821x,
29647 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
29648 index 74c2c4a..efddd7d 100644
29649 --- a/drivers/ide/jmicron.c
29650 +++ b/drivers/ide/jmicron.c
29651 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
29652 .cable_detect = jmicron_cable_detect,
29653 };
29654
29655 -static const struct ide_port_info jmicron_chipset __devinitdata = {
29656 +static const struct ide_port_info jmicron_chipset __devinitconst = {
29657 .name = DRV_NAME,
29658 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
29659 .port_ops = &jmicron_port_ops,
29660 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
29661 index 95327a2..73f78d8 100644
29662 --- a/drivers/ide/ns87415.c
29663 +++ b/drivers/ide/ns87415.c
29664 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
29665 .dma_sff_read_status = superio_dma_sff_read_status,
29666 };
29667
29668 -static const struct ide_port_info ns87415_chipset __devinitdata = {
29669 +static const struct ide_port_info ns87415_chipset __devinitconst = {
29670 .name = DRV_NAME,
29671 .init_hwif = init_hwif_ns87415,
29672 .tp_ops = &ns87415_tp_ops,
29673 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
29674 index 1a53a4c..39edc66 100644
29675 --- a/drivers/ide/opti621.c
29676 +++ b/drivers/ide/opti621.c
29677 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
29678 .set_pio_mode = opti621_set_pio_mode,
29679 };
29680
29681 -static const struct ide_port_info opti621_chipset __devinitdata = {
29682 +static const struct ide_port_info opti621_chipset __devinitconst = {
29683 .name = DRV_NAME,
29684 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
29685 .port_ops = &opti621_port_ops,
29686 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
29687 index 9546fe2..2e5ceb6 100644
29688 --- a/drivers/ide/pdc202xx_new.c
29689 +++ b/drivers/ide/pdc202xx_new.c
29690 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
29691 .udma_mask = udma, \
29692 }
29693
29694 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
29695 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
29696 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
29697 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
29698 };
29699 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
29700 index 3a35ec6..5634510 100644
29701 --- a/drivers/ide/pdc202xx_old.c
29702 +++ b/drivers/ide/pdc202xx_old.c
29703 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
29704 .max_sectors = sectors, \
29705 }
29706
29707 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
29708 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
29709 { /* 0: PDC20246 */
29710 .name = DRV_NAME,
29711 .init_chipset = init_chipset_pdc202xx,
29712 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
29713 index b59d04c..368c2a7 100644
29714 --- a/drivers/ide/piix.c
29715 +++ b/drivers/ide/piix.c
29716 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
29717 .udma_mask = udma, \
29718 }
29719
29720 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
29721 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
29722 /* 0: MPIIX */
29723 { /*
29724 * MPIIX actually has only a single IDE channel mapped to
29725 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
29726 index a6414a8..c04173e 100644
29727 --- a/drivers/ide/rz1000.c
29728 +++ b/drivers/ide/rz1000.c
29729 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
29730 }
29731 }
29732
29733 -static const struct ide_port_info rz1000_chipset __devinitdata = {
29734 +static const struct ide_port_info rz1000_chipset __devinitconst = {
29735 .name = DRV_NAME,
29736 .host_flags = IDE_HFLAG_NO_DMA,
29737 };
29738 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
29739 index 356b9b5..d4758eb 100644
29740 --- a/drivers/ide/sc1200.c
29741 +++ b/drivers/ide/sc1200.c
29742 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
29743 .dma_sff_read_status = ide_dma_sff_read_status,
29744 };
29745
29746 -static const struct ide_port_info sc1200_chipset __devinitdata = {
29747 +static const struct ide_port_info sc1200_chipset __devinitconst = {
29748 .name = DRV_NAME,
29749 .port_ops = &sc1200_port_ops,
29750 .dma_ops = &sc1200_dma_ops,
29751 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
29752 index b7f5b0c..9701038 100644
29753 --- a/drivers/ide/scc_pata.c
29754 +++ b/drivers/ide/scc_pata.c
29755 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
29756 .dma_sff_read_status = scc_dma_sff_read_status,
29757 };
29758
29759 -static const struct ide_port_info scc_chipset __devinitdata = {
29760 +static const struct ide_port_info scc_chipset __devinitconst = {
29761 .name = "sccIDE",
29762 .init_iops = init_iops_scc,
29763 .init_dma = scc_init_dma,
29764 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
29765 index 35fb8da..24d72ef 100644
29766 --- a/drivers/ide/serverworks.c
29767 +++ b/drivers/ide/serverworks.c
29768 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
29769 .cable_detect = svwks_cable_detect,
29770 };
29771
29772 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
29773 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
29774 { /* 0: OSB4 */
29775 .name = DRV_NAME,
29776 .init_chipset = init_chipset_svwks,
29777 diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
29778 index ab3db61..afed580 100644
29779 --- a/drivers/ide/setup-pci.c
29780 +++ b/drivers/ide/setup-pci.c
29781 @@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
29782 int ret, i, n_ports = dev2 ? 4 : 2;
29783 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
29784
29785 + pax_track_stack();
29786 +
29787 for (i = 0; i < n_ports / 2; i++) {
29788 ret = ide_setup_pci_controller(pdev[i], d, !i);
29789 if (ret < 0)
29790 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
29791 index ddeda44..46f7e30 100644
29792 --- a/drivers/ide/siimage.c
29793 +++ b/drivers/ide/siimage.c
29794 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
29795 .udma_mask = ATA_UDMA6, \
29796 }
29797
29798 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
29799 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
29800 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
29801 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
29802 };
29803 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
29804 index 4a00225..09e61b4 100644
29805 --- a/drivers/ide/sis5513.c
29806 +++ b/drivers/ide/sis5513.c
29807 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
29808 .cable_detect = sis_cable_detect,
29809 };
29810
29811 -static const struct ide_port_info sis5513_chipset __devinitdata = {
29812 +static const struct ide_port_info sis5513_chipset __devinitconst = {
29813 .name = DRV_NAME,
29814 .init_chipset = init_chipset_sis5513,
29815 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
29816 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
29817 index f21dc2a..d051cd2 100644
29818 --- a/drivers/ide/sl82c105.c
29819 +++ b/drivers/ide/sl82c105.c
29820 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
29821 .dma_sff_read_status = ide_dma_sff_read_status,
29822 };
29823
29824 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
29825 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
29826 .name = DRV_NAME,
29827 .init_chipset = init_chipset_sl82c105,
29828 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
29829 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
29830 index 864ffe0..863a5e9 100644
29831 --- a/drivers/ide/slc90e66.c
29832 +++ b/drivers/ide/slc90e66.c
29833 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
29834 .cable_detect = slc90e66_cable_detect,
29835 };
29836
29837 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
29838 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
29839 .name = DRV_NAME,
29840 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
29841 .port_ops = &slc90e66_port_ops,
29842 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
29843 index e444d24..ba577de 100644
29844 --- a/drivers/ide/tc86c001.c
29845 +++ b/drivers/ide/tc86c001.c
29846 @@ -191,7 +191,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
29847 .dma_sff_read_status = ide_dma_sff_read_status,
29848 };
29849
29850 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
29851 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
29852 .name = DRV_NAME,
29853 .init_hwif = init_hwif_tc86c001,
29854 .port_ops = &tc86c001_port_ops,
29855 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
29856 index e53a1b7..d11aff7 100644
29857 --- a/drivers/ide/triflex.c
29858 +++ b/drivers/ide/triflex.c
29859 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
29860 .set_dma_mode = triflex_set_mode,
29861 };
29862
29863 -static const struct ide_port_info triflex_device __devinitdata = {
29864 +static const struct ide_port_info triflex_device __devinitconst = {
29865 .name = DRV_NAME,
29866 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
29867 .port_ops = &triflex_port_ops,
29868 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
29869 index 4b42ca0..e494a98 100644
29870 --- a/drivers/ide/trm290.c
29871 +++ b/drivers/ide/trm290.c
29872 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
29873 .dma_check = trm290_dma_check,
29874 };
29875
29876 -static const struct ide_port_info trm290_chipset __devinitdata = {
29877 +static const struct ide_port_info trm290_chipset __devinitconst = {
29878 .name = DRV_NAME,
29879 .init_hwif = init_hwif_trm290,
29880 .tp_ops = &trm290_tp_ops,
29881 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
29882 index f46f49c..eb77678 100644
29883 --- a/drivers/ide/via82cxxx.c
29884 +++ b/drivers/ide/via82cxxx.c
29885 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
29886 .cable_detect = via82cxxx_cable_detect,
29887 };
29888
29889 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
29890 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
29891 .name = DRV_NAME,
29892 .init_chipset = init_chipset_via82cxxx,
29893 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
29894 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
29895 index fc0f2bd..ac2f8a5 100644
29896 --- a/drivers/infiniband/core/cm.c
29897 +++ b/drivers/infiniband/core/cm.c
29898 @@ -113,7 +113,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
29899
29900 struct cm_counter_group {
29901 struct kobject obj;
29902 - atomic_long_t counter[CM_ATTR_COUNT];
29903 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
29904 };
29905
29906 struct cm_counter_attribute {
29907 @@ -1387,7 +1387,7 @@ static void cm_dup_req_handler(struct cm_work *work,
29908 struct ib_mad_send_buf *msg = NULL;
29909 int ret;
29910
29911 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29912 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29913 counter[CM_REQ_COUNTER]);
29914
29915 /* Quick state check to discard duplicate REQs. */
29916 @@ -1765,7 +1765,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
29917 if (!cm_id_priv)
29918 return;
29919
29920 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29921 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29922 counter[CM_REP_COUNTER]);
29923 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
29924 if (ret)
29925 @@ -1932,7 +1932,7 @@ static int cm_rtu_handler(struct cm_work *work)
29926 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
29927 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
29928 spin_unlock_irq(&cm_id_priv->lock);
29929 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29930 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29931 counter[CM_RTU_COUNTER]);
29932 goto out;
29933 }
29934 @@ -2115,7 +2115,7 @@ static int cm_dreq_handler(struct cm_work *work)
29935 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
29936 dreq_msg->local_comm_id);
29937 if (!cm_id_priv) {
29938 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29939 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29940 counter[CM_DREQ_COUNTER]);
29941 cm_issue_drep(work->port, work->mad_recv_wc);
29942 return -EINVAL;
29943 @@ -2140,7 +2140,7 @@ static int cm_dreq_handler(struct cm_work *work)
29944 case IB_CM_MRA_REP_RCVD:
29945 break;
29946 case IB_CM_TIMEWAIT:
29947 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29948 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29949 counter[CM_DREQ_COUNTER]);
29950 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
29951 goto unlock;
29952 @@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
29953 cm_free_msg(msg);
29954 goto deref;
29955 case IB_CM_DREQ_RCVD:
29956 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29957 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29958 counter[CM_DREQ_COUNTER]);
29959 goto unlock;
29960 default:
29961 @@ -2521,7 +2521,7 @@ static int cm_mra_handler(struct cm_work *work)
29962 ib_modify_mad(cm_id_priv->av.port->mad_agent,
29963 cm_id_priv->msg, timeout)) {
29964 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
29965 - atomic_long_inc(&work->port->
29966 + atomic_long_inc_unchecked(&work->port->
29967 counter_group[CM_RECV_DUPLICATES].
29968 counter[CM_MRA_COUNTER]);
29969 goto out;
29970 @@ -2530,7 +2530,7 @@ static int cm_mra_handler(struct cm_work *work)
29971 break;
29972 case IB_CM_MRA_REQ_RCVD:
29973 case IB_CM_MRA_REP_RCVD:
29974 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29975 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29976 counter[CM_MRA_COUNTER]);
29977 /* fall through */
29978 default:
29979 @@ -2692,7 +2692,7 @@ static int cm_lap_handler(struct cm_work *work)
29980 case IB_CM_LAP_IDLE:
29981 break;
29982 case IB_CM_MRA_LAP_SENT:
29983 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29984 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29985 counter[CM_LAP_COUNTER]);
29986 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
29987 goto unlock;
29988 @@ -2708,7 +2708,7 @@ static int cm_lap_handler(struct cm_work *work)
29989 cm_free_msg(msg);
29990 goto deref;
29991 case IB_CM_LAP_RCVD:
29992 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29993 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29994 counter[CM_LAP_COUNTER]);
29995 goto unlock;
29996 default:
29997 @@ -2992,7 +2992,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
29998 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
29999 if (cur_cm_id_priv) {
30000 spin_unlock_irq(&cm.lock);
30001 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30002 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30003 counter[CM_SIDR_REQ_COUNTER]);
30004 goto out; /* Duplicate message. */
30005 }
30006 @@ -3204,10 +3204,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
30007 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
30008 msg->retries = 1;
30009
30010 - atomic_long_add(1 + msg->retries,
30011 + atomic_long_add_unchecked(1 + msg->retries,
30012 &port->counter_group[CM_XMIT].counter[attr_index]);
30013 if (msg->retries)
30014 - atomic_long_add(msg->retries,
30015 + atomic_long_add_unchecked(msg->retries,
30016 &port->counter_group[CM_XMIT_RETRIES].
30017 counter[attr_index]);
30018
30019 @@ -3417,7 +3417,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
30020 }
30021
30022 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
30023 - atomic_long_inc(&port->counter_group[CM_RECV].
30024 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
30025 counter[attr_id - CM_ATTR_ID_OFFSET]);
30026
30027 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
30028 @@ -3615,7 +3615,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
30029 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
30030
30031 return sprintf(buf, "%ld\n",
30032 - atomic_long_read(&group->counter[cm_attr->index]));
30033 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
30034 }
30035
30036 static const struct sysfs_ops cm_counter_ops = {
30037 diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
30038 index ca4c5dc..572d1ae 100644
30039 --- a/drivers/infiniband/core/cma.c
30040 +++ b/drivers/infiniband/core/cma.c
30041 @@ -2492,6 +2492,9 @@ static int cma_resolve_ib_udp(struct rdma_id_private *id_priv,
30042
30043 req.private_data_len = sizeof(struct cma_hdr) +
30044 conn_param->private_data_len;
30045 + if (req.private_data_len < conn_param->private_data_len)
30046 + return -EINVAL;
30047 +
30048 req.private_data = kzalloc(req.private_data_len, GFP_ATOMIC);
30049 if (!req.private_data)
30050 return -ENOMEM;
30051 @@ -2541,6 +2544,9 @@ static int cma_connect_ib(struct rdma_id_private *id_priv,
30052 memset(&req, 0, sizeof req);
30053 offset = cma_user_data_offset(id_priv->id.ps);
30054 req.private_data_len = offset + conn_param->private_data_len;
30055 + if (req.private_data_len < conn_param->private_data_len)
30056 + return -EINVAL;
30057 +
30058 private_data = kzalloc(req.private_data_len, GFP_ATOMIC);
30059 if (!private_data)
30060 return -ENOMEM;
30061 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
30062 index 4507043..14ad522 100644
30063 --- a/drivers/infiniband/core/fmr_pool.c
30064 +++ b/drivers/infiniband/core/fmr_pool.c
30065 @@ -97,8 +97,8 @@ struct ib_fmr_pool {
30066
30067 struct task_struct *thread;
30068
30069 - atomic_t req_ser;
30070 - atomic_t flush_ser;
30071 + atomic_unchecked_t req_ser;
30072 + atomic_unchecked_t flush_ser;
30073
30074 wait_queue_head_t force_wait;
30075 };
30076 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
30077 struct ib_fmr_pool *pool = pool_ptr;
30078
30079 do {
30080 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
30081 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
30082 ib_fmr_batch_release(pool);
30083
30084 - atomic_inc(&pool->flush_ser);
30085 + atomic_inc_unchecked(&pool->flush_ser);
30086 wake_up_interruptible(&pool->force_wait);
30087
30088 if (pool->flush_function)
30089 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
30090 }
30091
30092 set_current_state(TASK_INTERRUPTIBLE);
30093 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
30094 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
30095 !kthread_should_stop())
30096 schedule();
30097 __set_current_state(TASK_RUNNING);
30098 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
30099 pool->dirty_watermark = params->dirty_watermark;
30100 pool->dirty_len = 0;
30101 spin_lock_init(&pool->pool_lock);
30102 - atomic_set(&pool->req_ser, 0);
30103 - atomic_set(&pool->flush_ser, 0);
30104 + atomic_set_unchecked(&pool->req_ser, 0);
30105 + atomic_set_unchecked(&pool->flush_ser, 0);
30106 init_waitqueue_head(&pool->force_wait);
30107
30108 pool->thread = kthread_run(ib_fmr_cleanup_thread,
30109 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
30110 }
30111 spin_unlock_irq(&pool->pool_lock);
30112
30113 - serial = atomic_inc_return(&pool->req_ser);
30114 + serial = atomic_inc_return_unchecked(&pool->req_ser);
30115 wake_up_process(pool->thread);
30116
30117 if (wait_event_interruptible(pool->force_wait,
30118 - atomic_read(&pool->flush_ser) - serial >= 0))
30119 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
30120 return -EINTR;
30121
30122 return 0;
30123 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
30124 } else {
30125 list_add_tail(&fmr->list, &pool->dirty_list);
30126 if (++pool->dirty_len >= pool->dirty_watermark) {
30127 - atomic_inc(&pool->req_ser);
30128 + atomic_inc_unchecked(&pool->req_ser);
30129 wake_up_process(pool->thread);
30130 }
30131 }
30132 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
30133 index 40c8353..946b0e4 100644
30134 --- a/drivers/infiniband/hw/cxgb4/mem.c
30135 +++ b/drivers/infiniband/hw/cxgb4/mem.c
30136 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
30137 int err;
30138 struct fw_ri_tpte tpt;
30139 u32 stag_idx;
30140 - static atomic_t key;
30141 + static atomic_unchecked_t key;
30142
30143 if (c4iw_fatal_error(rdev))
30144 return -EIO;
30145 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
30146 &rdev->resource.tpt_fifo_lock);
30147 if (!stag_idx)
30148 return -ENOMEM;
30149 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
30150 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
30151 }
30152 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
30153 __func__, stag_state, type, pdid, stag_idx);
30154 diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
30155 index 31ae1b1..2f5b038 100644
30156 --- a/drivers/infiniband/hw/ipath/ipath_fs.c
30157 +++ b/drivers/infiniband/hw/ipath/ipath_fs.c
30158 @@ -113,6 +113,8 @@ static ssize_t atomic_counters_read(struct file *file, char __user *buf,
30159 struct infinipath_counters counters;
30160 struct ipath_devdata *dd;
30161
30162 + pax_track_stack();
30163 +
30164 dd = file->f_path.dentry->d_inode->i_private;
30165 dd->ipath_f_read_counters(dd, &counters);
30166
30167 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
30168 index 79b3dbc..96e5fcc 100644
30169 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
30170 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
30171 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
30172 struct ib_atomic_eth *ateth;
30173 struct ipath_ack_entry *e;
30174 u64 vaddr;
30175 - atomic64_t *maddr;
30176 + atomic64_unchecked_t *maddr;
30177 u64 sdata;
30178 u32 rkey;
30179 u8 next;
30180 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
30181 IB_ACCESS_REMOTE_ATOMIC)))
30182 goto nack_acc_unlck;
30183 /* Perform atomic OP and save result. */
30184 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30185 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30186 sdata = be64_to_cpu(ateth->swap_data);
30187 e = &qp->s_ack_queue[qp->r_head_ack_queue];
30188 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
30189 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30190 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30191 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30192 be64_to_cpu(ateth->compare_data),
30193 sdata);
30194 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
30195 index 1f95bba..9530f87 100644
30196 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
30197 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
30198 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
30199 unsigned long flags;
30200 struct ib_wc wc;
30201 u64 sdata;
30202 - atomic64_t *maddr;
30203 + atomic64_unchecked_t *maddr;
30204 enum ib_wc_status send_status;
30205
30206 /*
30207 @@ -382,11 +382,11 @@ again:
30208 IB_ACCESS_REMOTE_ATOMIC)))
30209 goto acc_err;
30210 /* Perform atomic OP and save result. */
30211 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30212 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30213 sdata = wqe->wr.wr.atomic.compare_add;
30214 *(u64 *) sqp->s_sge.sge.vaddr =
30215 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
30216 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30217 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30218 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30219 sdata, wqe->wr.wr.atomic.swap);
30220 goto send_comp;
30221 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
30222 index 2d668c6..3312bb7 100644
30223 --- a/drivers/infiniband/hw/nes/nes.c
30224 +++ b/drivers/infiniband/hw/nes/nes.c
30225 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
30226 LIST_HEAD(nes_adapter_list);
30227 static LIST_HEAD(nes_dev_list);
30228
30229 -atomic_t qps_destroyed;
30230 +atomic_unchecked_t qps_destroyed;
30231
30232 static unsigned int ee_flsh_adapter;
30233 static unsigned int sysfs_nonidx_addr;
30234 @@ -275,7 +275,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
30235 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
30236 struct nes_adapter *nesadapter = nesdev->nesadapter;
30237
30238 - atomic_inc(&qps_destroyed);
30239 + atomic_inc_unchecked(&qps_destroyed);
30240
30241 /* Free the control structures */
30242
30243 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
30244 index 6fe7987..68637b5 100644
30245 --- a/drivers/infiniband/hw/nes/nes.h
30246 +++ b/drivers/infiniband/hw/nes/nes.h
30247 @@ -175,17 +175,17 @@ extern unsigned int nes_debug_level;
30248 extern unsigned int wqm_quanta;
30249 extern struct list_head nes_adapter_list;
30250
30251 -extern atomic_t cm_connects;
30252 -extern atomic_t cm_accepts;
30253 -extern atomic_t cm_disconnects;
30254 -extern atomic_t cm_closes;
30255 -extern atomic_t cm_connecteds;
30256 -extern atomic_t cm_connect_reqs;
30257 -extern atomic_t cm_rejects;
30258 -extern atomic_t mod_qp_timouts;
30259 -extern atomic_t qps_created;
30260 -extern atomic_t qps_destroyed;
30261 -extern atomic_t sw_qps_destroyed;
30262 +extern atomic_unchecked_t cm_connects;
30263 +extern atomic_unchecked_t cm_accepts;
30264 +extern atomic_unchecked_t cm_disconnects;
30265 +extern atomic_unchecked_t cm_closes;
30266 +extern atomic_unchecked_t cm_connecteds;
30267 +extern atomic_unchecked_t cm_connect_reqs;
30268 +extern atomic_unchecked_t cm_rejects;
30269 +extern atomic_unchecked_t mod_qp_timouts;
30270 +extern atomic_unchecked_t qps_created;
30271 +extern atomic_unchecked_t qps_destroyed;
30272 +extern atomic_unchecked_t sw_qps_destroyed;
30273 extern u32 mh_detected;
30274 extern u32 mh_pauses_sent;
30275 extern u32 cm_packets_sent;
30276 @@ -194,14 +194,14 @@ extern u32 cm_packets_created;
30277 extern u32 cm_packets_received;
30278 extern u32 cm_packets_dropped;
30279 extern u32 cm_packets_retrans;
30280 -extern atomic_t cm_listens_created;
30281 -extern atomic_t cm_listens_destroyed;
30282 +extern atomic_unchecked_t cm_listens_created;
30283 +extern atomic_unchecked_t cm_listens_destroyed;
30284 extern u32 cm_backlog_drops;
30285 -extern atomic_t cm_loopbacks;
30286 -extern atomic_t cm_nodes_created;
30287 -extern atomic_t cm_nodes_destroyed;
30288 -extern atomic_t cm_accel_dropped_pkts;
30289 -extern atomic_t cm_resets_recvd;
30290 +extern atomic_unchecked_t cm_loopbacks;
30291 +extern atomic_unchecked_t cm_nodes_created;
30292 +extern atomic_unchecked_t cm_nodes_destroyed;
30293 +extern atomic_unchecked_t cm_accel_dropped_pkts;
30294 +extern atomic_unchecked_t cm_resets_recvd;
30295
30296 extern u32 int_mod_timer_init;
30297 extern u32 int_mod_cq_depth_256;
30298 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
30299 index a237547..28a9819 100644
30300 --- a/drivers/infiniband/hw/nes/nes_cm.c
30301 +++ b/drivers/infiniband/hw/nes/nes_cm.c
30302 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
30303 u32 cm_packets_retrans;
30304 u32 cm_packets_created;
30305 u32 cm_packets_received;
30306 -atomic_t cm_listens_created;
30307 -atomic_t cm_listens_destroyed;
30308 +atomic_unchecked_t cm_listens_created;
30309 +atomic_unchecked_t cm_listens_destroyed;
30310 u32 cm_backlog_drops;
30311 -atomic_t cm_loopbacks;
30312 -atomic_t cm_nodes_created;
30313 -atomic_t cm_nodes_destroyed;
30314 -atomic_t cm_accel_dropped_pkts;
30315 -atomic_t cm_resets_recvd;
30316 +atomic_unchecked_t cm_loopbacks;
30317 +atomic_unchecked_t cm_nodes_created;
30318 +atomic_unchecked_t cm_nodes_destroyed;
30319 +atomic_unchecked_t cm_accel_dropped_pkts;
30320 +atomic_unchecked_t cm_resets_recvd;
30321
30322 static inline int mini_cm_accelerated(struct nes_cm_core *,
30323 struct nes_cm_node *);
30324 @@ -151,13 +151,13 @@ static struct nes_cm_ops nes_cm_api = {
30325
30326 static struct nes_cm_core *g_cm_core;
30327
30328 -atomic_t cm_connects;
30329 -atomic_t cm_accepts;
30330 -atomic_t cm_disconnects;
30331 -atomic_t cm_closes;
30332 -atomic_t cm_connecteds;
30333 -atomic_t cm_connect_reqs;
30334 -atomic_t cm_rejects;
30335 +atomic_unchecked_t cm_connects;
30336 +atomic_unchecked_t cm_accepts;
30337 +atomic_unchecked_t cm_disconnects;
30338 +atomic_unchecked_t cm_closes;
30339 +atomic_unchecked_t cm_connecteds;
30340 +atomic_unchecked_t cm_connect_reqs;
30341 +atomic_unchecked_t cm_rejects;
30342
30343
30344 /**
30345 @@ -1045,7 +1045,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
30346 kfree(listener);
30347 listener = NULL;
30348 ret = 0;
30349 - atomic_inc(&cm_listens_destroyed);
30350 + atomic_inc_unchecked(&cm_listens_destroyed);
30351 } else {
30352 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
30353 }
30354 @@ -1242,7 +1242,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
30355 cm_node->rem_mac);
30356
30357 add_hte_node(cm_core, cm_node);
30358 - atomic_inc(&cm_nodes_created);
30359 + atomic_inc_unchecked(&cm_nodes_created);
30360
30361 return cm_node;
30362 }
30363 @@ -1300,7 +1300,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
30364 }
30365
30366 atomic_dec(&cm_core->node_cnt);
30367 - atomic_inc(&cm_nodes_destroyed);
30368 + atomic_inc_unchecked(&cm_nodes_destroyed);
30369 nesqp = cm_node->nesqp;
30370 if (nesqp) {
30371 nesqp->cm_node = NULL;
30372 @@ -1367,7 +1367,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
30373
30374 static void drop_packet(struct sk_buff *skb)
30375 {
30376 - atomic_inc(&cm_accel_dropped_pkts);
30377 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30378 dev_kfree_skb_any(skb);
30379 }
30380
30381 @@ -1430,7 +1430,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
30382 {
30383
30384 int reset = 0; /* whether to send reset in case of err.. */
30385 - atomic_inc(&cm_resets_recvd);
30386 + atomic_inc_unchecked(&cm_resets_recvd);
30387 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
30388 " refcnt=%d\n", cm_node, cm_node->state,
30389 atomic_read(&cm_node->ref_count));
30390 @@ -2059,7 +2059,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
30391 rem_ref_cm_node(cm_node->cm_core, cm_node);
30392 return NULL;
30393 }
30394 - atomic_inc(&cm_loopbacks);
30395 + atomic_inc_unchecked(&cm_loopbacks);
30396 loopbackremotenode->loopbackpartner = cm_node;
30397 loopbackremotenode->tcp_cntxt.rcv_wscale =
30398 NES_CM_DEFAULT_RCV_WND_SCALE;
30399 @@ -2334,7 +2334,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
30400 add_ref_cm_node(cm_node);
30401 } else if (cm_node->state == NES_CM_STATE_TSA) {
30402 rem_ref_cm_node(cm_core, cm_node);
30403 - atomic_inc(&cm_accel_dropped_pkts);
30404 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30405 dev_kfree_skb_any(skb);
30406 break;
30407 }
30408 @@ -2640,7 +2640,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
30409
30410 if ((cm_id) && (cm_id->event_handler)) {
30411 if (issue_disconn) {
30412 - atomic_inc(&cm_disconnects);
30413 + atomic_inc_unchecked(&cm_disconnects);
30414 cm_event.event = IW_CM_EVENT_DISCONNECT;
30415 cm_event.status = disconn_status;
30416 cm_event.local_addr = cm_id->local_addr;
30417 @@ -2662,7 +2662,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
30418 }
30419
30420 if (issue_close) {
30421 - atomic_inc(&cm_closes);
30422 + atomic_inc_unchecked(&cm_closes);
30423 nes_disconnect(nesqp, 1);
30424
30425 cm_id->provider_data = nesqp;
30426 @@ -2793,7 +2793,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
30427
30428 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
30429 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
30430 - atomic_inc(&cm_accepts);
30431 + atomic_inc_unchecked(&cm_accepts);
30432
30433 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
30434 netdev_refcnt_read(nesvnic->netdev));
30435 @@ -3003,7 +3003,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
30436
30437 struct nes_cm_core *cm_core;
30438
30439 - atomic_inc(&cm_rejects);
30440 + atomic_inc_unchecked(&cm_rejects);
30441 cm_node = (struct nes_cm_node *) cm_id->provider_data;
30442 loopback = cm_node->loopbackpartner;
30443 cm_core = cm_node->cm_core;
30444 @@ -3069,7 +3069,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
30445 ntohl(cm_id->local_addr.sin_addr.s_addr),
30446 ntohs(cm_id->local_addr.sin_port));
30447
30448 - atomic_inc(&cm_connects);
30449 + atomic_inc_unchecked(&cm_connects);
30450 nesqp->active_conn = 1;
30451
30452 /* cache the cm_id in the qp */
30453 @@ -3175,7 +3175,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
30454 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
30455 return err;
30456 }
30457 - atomic_inc(&cm_listens_created);
30458 + atomic_inc_unchecked(&cm_listens_created);
30459 }
30460
30461 cm_id->add_ref(cm_id);
30462 @@ -3280,7 +3280,7 @@ static void cm_event_connected(struct nes_cm_event *event)
30463 if (nesqp->destroyed) {
30464 return;
30465 }
30466 - atomic_inc(&cm_connecteds);
30467 + atomic_inc_unchecked(&cm_connecteds);
30468 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
30469 " local port 0x%04X. jiffies = %lu.\n",
30470 nesqp->hwqp.qp_id,
30471 @@ -3495,7 +3495,7 @@ static void cm_event_reset(struct nes_cm_event *event)
30472
30473 cm_id->add_ref(cm_id);
30474 ret = cm_id->event_handler(cm_id, &cm_event);
30475 - atomic_inc(&cm_closes);
30476 + atomic_inc_unchecked(&cm_closes);
30477 cm_event.event = IW_CM_EVENT_CLOSE;
30478 cm_event.status = 0;
30479 cm_event.provider_data = cm_id->provider_data;
30480 @@ -3531,7 +3531,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
30481 return;
30482 cm_id = cm_node->cm_id;
30483
30484 - atomic_inc(&cm_connect_reqs);
30485 + atomic_inc_unchecked(&cm_connect_reqs);
30486 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30487 cm_node, cm_id, jiffies);
30488
30489 @@ -3569,7 +3569,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
30490 return;
30491 cm_id = cm_node->cm_id;
30492
30493 - atomic_inc(&cm_connect_reqs);
30494 + atomic_inc_unchecked(&cm_connect_reqs);
30495 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30496 cm_node, cm_id, jiffies);
30497
30498 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
30499 index 9d7ffeb..a95dd7d 100644
30500 --- a/drivers/infiniband/hw/nes/nes_nic.c
30501 +++ b/drivers/infiniband/hw/nes/nes_nic.c
30502 @@ -1274,31 +1274,31 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
30503 target_stat_values[++index] = mh_detected;
30504 target_stat_values[++index] = mh_pauses_sent;
30505 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
30506 - target_stat_values[++index] = atomic_read(&cm_connects);
30507 - target_stat_values[++index] = atomic_read(&cm_accepts);
30508 - target_stat_values[++index] = atomic_read(&cm_disconnects);
30509 - target_stat_values[++index] = atomic_read(&cm_connecteds);
30510 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
30511 - target_stat_values[++index] = atomic_read(&cm_rejects);
30512 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
30513 - target_stat_values[++index] = atomic_read(&qps_created);
30514 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
30515 - target_stat_values[++index] = atomic_read(&qps_destroyed);
30516 - target_stat_values[++index] = atomic_read(&cm_closes);
30517 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
30518 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
30519 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
30520 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
30521 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
30522 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
30523 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
30524 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
30525 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
30526 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
30527 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
30528 target_stat_values[++index] = cm_packets_sent;
30529 target_stat_values[++index] = cm_packets_bounced;
30530 target_stat_values[++index] = cm_packets_created;
30531 target_stat_values[++index] = cm_packets_received;
30532 target_stat_values[++index] = cm_packets_dropped;
30533 target_stat_values[++index] = cm_packets_retrans;
30534 - target_stat_values[++index] = atomic_read(&cm_listens_created);
30535 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
30536 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
30537 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
30538 target_stat_values[++index] = cm_backlog_drops;
30539 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
30540 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
30541 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
30542 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
30543 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
30544 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
30545 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
30546 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
30547 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
30548 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
30549 target_stat_values[++index] = nesadapter->free_4kpbl;
30550 target_stat_values[++index] = nesadapter->free_256pbl;
30551 target_stat_values[++index] = int_mod_timer_init;
30552 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
30553 index 9f2f7d4..6d2fee2 100644
30554 --- a/drivers/infiniband/hw/nes/nes_verbs.c
30555 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
30556 @@ -46,9 +46,9 @@
30557
30558 #include <rdma/ib_umem.h>
30559
30560 -atomic_t mod_qp_timouts;
30561 -atomic_t qps_created;
30562 -atomic_t sw_qps_destroyed;
30563 +atomic_unchecked_t mod_qp_timouts;
30564 +atomic_unchecked_t qps_created;
30565 +atomic_unchecked_t sw_qps_destroyed;
30566
30567 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
30568
30569 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
30570 if (init_attr->create_flags)
30571 return ERR_PTR(-EINVAL);
30572
30573 - atomic_inc(&qps_created);
30574 + atomic_inc_unchecked(&qps_created);
30575 switch (init_attr->qp_type) {
30576 case IB_QPT_RC:
30577 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
30578 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
30579 struct iw_cm_event cm_event;
30580 int ret;
30581
30582 - atomic_inc(&sw_qps_destroyed);
30583 + atomic_inc_unchecked(&sw_qps_destroyed);
30584 nesqp->destroyed = 1;
30585
30586 /* Blow away the connection if it exists. */
30587 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
30588 index c9624ea..e025b66 100644
30589 --- a/drivers/infiniband/hw/qib/qib.h
30590 +++ b/drivers/infiniband/hw/qib/qib.h
30591 @@ -51,6 +51,7 @@
30592 #include <linux/completion.h>
30593 #include <linux/kref.h>
30594 #include <linux/sched.h>
30595 +#include <linux/slab.h>
30596
30597 #include "qib_common.h"
30598 #include "qib_verbs.h"
30599 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
30600 index c351aa4..e6967c2 100644
30601 --- a/drivers/input/gameport/gameport.c
30602 +++ b/drivers/input/gameport/gameport.c
30603 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
30604 */
30605 static void gameport_init_port(struct gameport *gameport)
30606 {
30607 - static atomic_t gameport_no = ATOMIC_INIT(0);
30608 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
30609
30610 __module_get(THIS_MODULE);
30611
30612 mutex_init(&gameport->drv_mutex);
30613 device_initialize(&gameport->dev);
30614 dev_set_name(&gameport->dev, "gameport%lu",
30615 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
30616 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
30617 gameport->dev.bus = &gameport_bus;
30618 gameport->dev.release = gameport_release_port;
30619 if (gameport->parent)
30620 diff --git a/drivers/input/input.c b/drivers/input/input.c
30621 index da38d97..2aa0b79 100644
30622 --- a/drivers/input/input.c
30623 +++ b/drivers/input/input.c
30624 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
30625 */
30626 int input_register_device(struct input_dev *dev)
30627 {
30628 - static atomic_t input_no = ATOMIC_INIT(0);
30629 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
30630 struct input_handler *handler;
30631 const char *path;
30632 int error;
30633 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
30634 dev->setkeycode = input_default_setkeycode;
30635
30636 dev_set_name(&dev->dev, "input%ld",
30637 - (unsigned long) atomic_inc_return(&input_no) - 1);
30638 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
30639
30640 error = device_add(&dev->dev);
30641 if (error)
30642 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
30643 index b8d8611..15f8d2c 100644
30644 --- a/drivers/input/joystick/sidewinder.c
30645 +++ b/drivers/input/joystick/sidewinder.c
30646 @@ -30,6 +30,7 @@
30647 #include <linux/kernel.h>
30648 #include <linux/module.h>
30649 #include <linux/slab.h>
30650 +#include <linux/sched.h>
30651 #include <linux/init.h>
30652 #include <linux/input.h>
30653 #include <linux/gameport.h>
30654 @@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
30655 unsigned char buf[SW_LENGTH];
30656 int i;
30657
30658 + pax_track_stack();
30659 +
30660 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
30661
30662 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
30663 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
30664 index d728875..844c89b 100644
30665 --- a/drivers/input/joystick/xpad.c
30666 +++ b/drivers/input/joystick/xpad.c
30667 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
30668
30669 static int xpad_led_probe(struct usb_xpad *xpad)
30670 {
30671 - static atomic_t led_seq = ATOMIC_INIT(0);
30672 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
30673 long led_no;
30674 struct xpad_led *led;
30675 struct led_classdev *led_cdev;
30676 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
30677 if (!led)
30678 return -ENOMEM;
30679
30680 - led_no = (long)atomic_inc_return(&led_seq) - 1;
30681 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
30682
30683 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
30684 led->xpad = xpad;
30685 diff --git a/drivers/input/misc/cma3000_d0x.c b/drivers/input/misc/cma3000_d0x.c
30686 index 1633b63..09f8f20 100644
30687 --- a/drivers/input/misc/cma3000_d0x.c
30688 +++ b/drivers/input/misc/cma3000_d0x.c
30689 @@ -114,8 +114,8 @@ static void decode_mg(struct cma3000_accl_data *data, int *datax,
30690 static irqreturn_t cma3000_thread_irq(int irq, void *dev_id)
30691 {
30692 struct cma3000_accl_data *data = dev_id;
30693 - int datax, datay, dataz;
30694 - u8 ctrl, mode, range, intr_status;
30695 + int datax, datay, dataz, intr_status;
30696 + u8 ctrl, mode, range;
30697
30698 intr_status = CMA3000_READ(data, CMA3000_INTSTATUS, "interrupt status");
30699 if (intr_status < 0)
30700 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
30701 index 0110b5a..d3ad144 100644
30702 --- a/drivers/input/mousedev.c
30703 +++ b/drivers/input/mousedev.c
30704 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
30705
30706 spin_unlock_irq(&client->packet_lock);
30707
30708 - if (copy_to_user(buffer, data, count))
30709 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
30710 return -EFAULT;
30711
30712 return count;
30713 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
30714 index ba70058..571d25d 100644
30715 --- a/drivers/input/serio/serio.c
30716 +++ b/drivers/input/serio/serio.c
30717 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
30718 */
30719 static void serio_init_port(struct serio *serio)
30720 {
30721 - static atomic_t serio_no = ATOMIC_INIT(0);
30722 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
30723
30724 __module_get(THIS_MODULE);
30725
30726 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
30727 mutex_init(&serio->drv_mutex);
30728 device_initialize(&serio->dev);
30729 dev_set_name(&serio->dev, "serio%ld",
30730 - (long)atomic_inc_return(&serio_no) - 1);
30731 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
30732 serio->dev.bus = &serio_bus;
30733 serio->dev.release = serio_release_port;
30734 serio->dev.groups = serio_device_attr_groups;
30735 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
30736 index e44933d..9ba484a 100644
30737 --- a/drivers/isdn/capi/capi.c
30738 +++ b/drivers/isdn/capi/capi.c
30739 @@ -83,8 +83,8 @@ struct capiminor {
30740
30741 struct capi20_appl *ap;
30742 u32 ncci;
30743 - atomic_t datahandle;
30744 - atomic_t msgid;
30745 + atomic_unchecked_t datahandle;
30746 + atomic_unchecked_t msgid;
30747
30748 struct tty_port port;
30749 int ttyinstop;
30750 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
30751 capimsg_setu16(s, 2, mp->ap->applid);
30752 capimsg_setu8 (s, 4, CAPI_DATA_B3);
30753 capimsg_setu8 (s, 5, CAPI_RESP);
30754 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
30755 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
30756 capimsg_setu32(s, 8, mp->ncci);
30757 capimsg_setu16(s, 12, datahandle);
30758 }
30759 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
30760 mp->outbytes -= len;
30761 spin_unlock_bh(&mp->outlock);
30762
30763 - datahandle = atomic_inc_return(&mp->datahandle);
30764 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
30765 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
30766 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
30767 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
30768 capimsg_setu16(skb->data, 2, mp->ap->applid);
30769 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
30770 capimsg_setu8 (skb->data, 5, CAPI_REQ);
30771 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
30772 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
30773 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
30774 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
30775 capimsg_setu16(skb->data, 16, len); /* Data length */
30776 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
30777 index db621db..825ea1a 100644
30778 --- a/drivers/isdn/gigaset/common.c
30779 +++ b/drivers/isdn/gigaset/common.c
30780 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
30781 cs->commands_pending = 0;
30782 cs->cur_at_seq = 0;
30783 cs->gotfwver = -1;
30784 - cs->open_count = 0;
30785 + local_set(&cs->open_count, 0);
30786 cs->dev = NULL;
30787 cs->tty = NULL;
30788 cs->tty_dev = NULL;
30789 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
30790 index 212efaf..f187c6b 100644
30791 --- a/drivers/isdn/gigaset/gigaset.h
30792 +++ b/drivers/isdn/gigaset/gigaset.h
30793 @@ -35,6 +35,7 @@
30794 #include <linux/tty_driver.h>
30795 #include <linux/list.h>
30796 #include <linux/atomic.h>
30797 +#include <asm/local.h>
30798
30799 #define GIG_VERSION {0, 5, 0, 0}
30800 #define GIG_COMPAT {0, 4, 0, 0}
30801 @@ -433,7 +434,7 @@ struct cardstate {
30802 spinlock_t cmdlock;
30803 unsigned curlen, cmdbytes;
30804
30805 - unsigned open_count;
30806 + local_t open_count;
30807 struct tty_struct *tty;
30808 struct tasklet_struct if_wake_tasklet;
30809 unsigned control_state;
30810 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
30811 index e35058b..5898a8b 100644
30812 --- a/drivers/isdn/gigaset/interface.c
30813 +++ b/drivers/isdn/gigaset/interface.c
30814 @@ -162,9 +162,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
30815 }
30816 tty->driver_data = cs;
30817
30818 - ++cs->open_count;
30819 -
30820 - if (cs->open_count == 1) {
30821 + if (local_inc_return(&cs->open_count) == 1) {
30822 spin_lock_irqsave(&cs->lock, flags);
30823 cs->tty = tty;
30824 spin_unlock_irqrestore(&cs->lock, flags);
30825 @@ -192,10 +190,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
30826
30827 if (!cs->connected)
30828 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30829 - else if (!cs->open_count)
30830 + else if (!local_read(&cs->open_count))
30831 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30832 else {
30833 - if (!--cs->open_count) {
30834 + if (!local_dec_return(&cs->open_count)) {
30835 spin_lock_irqsave(&cs->lock, flags);
30836 cs->tty = NULL;
30837 spin_unlock_irqrestore(&cs->lock, flags);
30838 @@ -230,7 +228,7 @@ static int if_ioctl(struct tty_struct *tty,
30839 if (!cs->connected) {
30840 gig_dbg(DEBUG_IF, "not connected");
30841 retval = -ENODEV;
30842 - } else if (!cs->open_count)
30843 + } else if (!local_read(&cs->open_count))
30844 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30845 else {
30846 retval = 0;
30847 @@ -360,7 +358,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
30848 retval = -ENODEV;
30849 goto done;
30850 }
30851 - if (!cs->open_count) {
30852 + if (!local_read(&cs->open_count)) {
30853 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30854 retval = -ENODEV;
30855 goto done;
30856 @@ -413,7 +411,7 @@ static int if_write_room(struct tty_struct *tty)
30857 if (!cs->connected) {
30858 gig_dbg(DEBUG_IF, "not connected");
30859 retval = -ENODEV;
30860 - } else if (!cs->open_count)
30861 + } else if (!local_read(&cs->open_count))
30862 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30863 else if (cs->mstate != MS_LOCKED) {
30864 dev_warn(cs->dev, "can't write to unlocked device\n");
30865 @@ -443,7 +441,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
30866
30867 if (!cs->connected)
30868 gig_dbg(DEBUG_IF, "not connected");
30869 - else if (!cs->open_count)
30870 + else if (!local_read(&cs->open_count))
30871 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30872 else if (cs->mstate != MS_LOCKED)
30873 dev_warn(cs->dev, "can't write to unlocked device\n");
30874 @@ -471,7 +469,7 @@ static void if_throttle(struct tty_struct *tty)
30875
30876 if (!cs->connected)
30877 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30878 - else if (!cs->open_count)
30879 + else if (!local_read(&cs->open_count))
30880 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30881 else
30882 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
30883 @@ -495,7 +493,7 @@ static void if_unthrottle(struct tty_struct *tty)
30884
30885 if (!cs->connected)
30886 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30887 - else if (!cs->open_count)
30888 + else if (!local_read(&cs->open_count))
30889 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30890 else
30891 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
30892 @@ -526,7 +524,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
30893 goto out;
30894 }
30895
30896 - if (!cs->open_count) {
30897 + if (!local_read(&cs->open_count)) {
30898 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30899 goto out;
30900 }
30901 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
30902 index 2a57da59..e7a12ed 100644
30903 --- a/drivers/isdn/hardware/avm/b1.c
30904 +++ b/drivers/isdn/hardware/avm/b1.c
30905 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
30906 }
30907 if (left) {
30908 if (t4file->user) {
30909 - if (copy_from_user(buf, dp, left))
30910 + if (left > sizeof buf || copy_from_user(buf, dp, left))
30911 return -EFAULT;
30912 } else {
30913 memcpy(buf, dp, left);
30914 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
30915 }
30916 if (left) {
30917 if (config->user) {
30918 - if (copy_from_user(buf, dp, left))
30919 + if (left > sizeof buf || copy_from_user(buf, dp, left))
30920 return -EFAULT;
30921 } else {
30922 memcpy(buf, dp, left);
30923 diff --git a/drivers/isdn/hardware/eicon/capidtmf.c b/drivers/isdn/hardware/eicon/capidtmf.c
30924 index f130724..c373c68 100644
30925 --- a/drivers/isdn/hardware/eicon/capidtmf.c
30926 +++ b/drivers/isdn/hardware/eicon/capidtmf.c
30927 @@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_state *p_state, byte *buffer, word leng
30928 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
30929 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
30930
30931 + pax_track_stack();
30932
30933 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
30934 {
30935 diff --git a/drivers/isdn/hardware/eicon/capifunc.c b/drivers/isdn/hardware/eicon/capifunc.c
30936 index 4d425c6..a9be6c4 100644
30937 --- a/drivers/isdn/hardware/eicon/capifunc.c
30938 +++ b/drivers/isdn/hardware/eicon/capifunc.c
30939 @@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
30940 IDI_SYNC_REQ req;
30941 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
30942
30943 + pax_track_stack();
30944 +
30945 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
30946
30947 for (x = 0; x < MAX_DESCRIPTORS; x++) {
30948 diff --git a/drivers/isdn/hardware/eicon/diddfunc.c b/drivers/isdn/hardware/eicon/diddfunc.c
30949 index 3029234..ef0d9e2 100644
30950 --- a/drivers/isdn/hardware/eicon/diddfunc.c
30951 +++ b/drivers/isdn/hardware/eicon/diddfunc.c
30952 @@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
30953 IDI_SYNC_REQ req;
30954 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
30955
30956 + pax_track_stack();
30957 +
30958 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
30959
30960 for (x = 0; x < MAX_DESCRIPTORS; x++) {
30961 diff --git a/drivers/isdn/hardware/eicon/divasfunc.c b/drivers/isdn/hardware/eicon/divasfunc.c
30962 index 0bbee78..a0d0a01 100644
30963 --- a/drivers/isdn/hardware/eicon/divasfunc.c
30964 +++ b/drivers/isdn/hardware/eicon/divasfunc.c
30965 @@ -160,6 +160,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
30966 IDI_SYNC_REQ req;
30967 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
30968
30969 + pax_track_stack();
30970 +
30971 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
30972
30973 for (x = 0; x < MAX_DESCRIPTORS; x++) {
30974 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
30975 index 85784a7..a19ca98 100644
30976 --- a/drivers/isdn/hardware/eicon/divasync.h
30977 +++ b/drivers/isdn/hardware/eicon/divasync.h
30978 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
30979 } diva_didd_add_adapter_t;
30980 typedef struct _diva_didd_remove_adapter {
30981 IDI_CALL p_request;
30982 -} diva_didd_remove_adapter_t;
30983 +} __no_const diva_didd_remove_adapter_t;
30984 typedef struct _diva_didd_read_adapter_array {
30985 void * buffer;
30986 dword length;
30987 diff --git a/drivers/isdn/hardware/eicon/idifunc.c b/drivers/isdn/hardware/eicon/idifunc.c
30988 index db87d51..7d09acf 100644
30989 --- a/drivers/isdn/hardware/eicon/idifunc.c
30990 +++ b/drivers/isdn/hardware/eicon/idifunc.c
30991 @@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
30992 IDI_SYNC_REQ req;
30993 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
30994
30995 + pax_track_stack();
30996 +
30997 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
30998
30999 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31000 diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
31001 index a339598..b6a8bfc 100644
31002 --- a/drivers/isdn/hardware/eicon/message.c
31003 +++ b/drivers/isdn/hardware/eicon/message.c
31004 @@ -4886,6 +4886,8 @@ static void sig_ind(PLCI *plci)
31005 dword d;
31006 word w;
31007
31008 + pax_track_stack();
31009 +
31010 a = plci->adapter;
31011 Id = ((word)plci->Id<<8)|a->Id;
31012 PUT_WORD(&SS_Ind[4],0x0000);
31013 @@ -7480,6 +7482,8 @@ static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
31014 word j, n, w;
31015 dword d;
31016
31017 + pax_track_stack();
31018 +
31019
31020 for(i=0;i<8;i++) bp_parms[i].length = 0;
31021 for(i=0;i<2;i++) global_config[i].length = 0;
31022 @@ -7954,6 +7958,8 @@ static word add_b23(PLCI *plci, API_PARSE *bp)
31023 const byte llc3[] = {4,3,2,2,6,6,0};
31024 const byte header[] = {0,2,3,3,0,0,0};
31025
31026 + pax_track_stack();
31027 +
31028 for(i=0;i<8;i++) bp_parms[i].length = 0;
31029 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
31030 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
31031 @@ -14741,6 +14747,8 @@ static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
31032 word appl_number_group_type[MAX_APPL];
31033 PLCI *auxplci;
31034
31035 + pax_track_stack();
31036 +
31037 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
31038
31039 if(!a->group_optimization_enabled)
31040 diff --git a/drivers/isdn/hardware/eicon/mntfunc.c b/drivers/isdn/hardware/eicon/mntfunc.c
31041 index a564b75..f3cf8b5 100644
31042 --- a/drivers/isdn/hardware/eicon/mntfunc.c
31043 +++ b/drivers/isdn/hardware/eicon/mntfunc.c
31044 @@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
31045 IDI_SYNC_REQ req;
31046 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31047
31048 + pax_track_stack();
31049 +
31050 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31051
31052 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31053 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
31054 index a3bd163..8956575 100644
31055 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
31056 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
31057 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
31058 typedef struct _diva_os_idi_adapter_interface {
31059 diva_init_card_proc_t cleanup_adapter_proc;
31060 diva_cmd_card_proc_t cmd_proc;
31061 -} diva_os_idi_adapter_interface_t;
31062 +} __no_const diva_os_idi_adapter_interface_t;
31063
31064 typedef struct _diva_os_xdi_adapter {
31065 struct list_head link;
31066 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
31067 index 6ed82ad..b05ac05 100644
31068 --- a/drivers/isdn/i4l/isdn_common.c
31069 +++ b/drivers/isdn/i4l/isdn_common.c
31070 @@ -1286,6 +1286,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
31071 } iocpar;
31072 void __user *argp = (void __user *)arg;
31073
31074 + pax_track_stack();
31075 +
31076 #define name iocpar.name
31077 #define bname iocpar.bname
31078 #define iocts iocpar.iocts
31079 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
31080 index 1f355bb..43f1fea 100644
31081 --- a/drivers/isdn/icn/icn.c
31082 +++ b/drivers/isdn/icn/icn.c
31083 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
31084 if (count > len)
31085 count = len;
31086 if (user) {
31087 - if (copy_from_user(msg, buf, count))
31088 + if (count > sizeof msg || copy_from_user(msg, buf, count))
31089 return -EFAULT;
31090 } else
31091 memcpy(msg, buf, count);
31092 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
31093 index 2535933..09a8e86 100644
31094 --- a/drivers/lguest/core.c
31095 +++ b/drivers/lguest/core.c
31096 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
31097 * it's worked so far. The end address needs +1 because __get_vm_area
31098 * allocates an extra guard page, so we need space for that.
31099 */
31100 +
31101 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31102 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31103 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
31104 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31105 +#else
31106 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31107 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
31108 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31109 +#endif
31110 +
31111 if (!switcher_vma) {
31112 err = -ENOMEM;
31113 printk("lguest: could not map switcher pages high\n");
31114 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
31115 * Now the Switcher is mapped at the right address, we can't fail!
31116 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
31117 */
31118 - memcpy(switcher_vma->addr, start_switcher_text,
31119 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
31120 end_switcher_text - start_switcher_text);
31121
31122 printk(KERN_INFO "lguest: mapped switcher at %p\n",
31123 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
31124 index 65af42f..530c87a 100644
31125 --- a/drivers/lguest/x86/core.c
31126 +++ b/drivers/lguest/x86/core.c
31127 @@ -59,7 +59,7 @@ static struct {
31128 /* Offset from where switcher.S was compiled to where we've copied it */
31129 static unsigned long switcher_offset(void)
31130 {
31131 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
31132 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
31133 }
31134
31135 /* This cpu's struct lguest_pages. */
31136 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
31137 * These copies are pretty cheap, so we do them unconditionally: */
31138 /* Save the current Host top-level page directory.
31139 */
31140 +
31141 +#ifdef CONFIG_PAX_PER_CPU_PGD
31142 + pages->state.host_cr3 = read_cr3();
31143 +#else
31144 pages->state.host_cr3 = __pa(current->mm->pgd);
31145 +#endif
31146 +
31147 /*
31148 * Set up the Guest's page tables to see this CPU's pages (and no
31149 * other CPU's pages).
31150 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
31151 * compiled-in switcher code and the high-mapped copy we just made.
31152 */
31153 for (i = 0; i < IDT_ENTRIES; i++)
31154 - default_idt_entries[i] += switcher_offset();
31155 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
31156
31157 /*
31158 * Set up the Switcher's per-cpu areas.
31159 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
31160 * it will be undisturbed when we switch. To change %cs and jump we
31161 * need this structure to feed to Intel's "lcall" instruction.
31162 */
31163 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
31164 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
31165 lguest_entry.segment = LGUEST_CS;
31166
31167 /*
31168 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
31169 index 40634b0..4f5855e 100644
31170 --- a/drivers/lguest/x86/switcher_32.S
31171 +++ b/drivers/lguest/x86/switcher_32.S
31172 @@ -87,6 +87,7 @@
31173 #include <asm/page.h>
31174 #include <asm/segment.h>
31175 #include <asm/lguest.h>
31176 +#include <asm/processor-flags.h>
31177
31178 // We mark the start of the code to copy
31179 // It's placed in .text tho it's never run here
31180 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
31181 // Changes type when we load it: damn Intel!
31182 // For after we switch over our page tables
31183 // That entry will be read-only: we'd crash.
31184 +
31185 +#ifdef CONFIG_PAX_KERNEXEC
31186 + mov %cr0, %edx
31187 + xor $X86_CR0_WP, %edx
31188 + mov %edx, %cr0
31189 +#endif
31190 +
31191 movl $(GDT_ENTRY_TSS*8), %edx
31192 ltr %dx
31193
31194 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
31195 // Let's clear it again for our return.
31196 // The GDT descriptor of the Host
31197 // Points to the table after two "size" bytes
31198 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
31199 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
31200 // Clear "used" from type field (byte 5, bit 2)
31201 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
31202 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
31203 +
31204 +#ifdef CONFIG_PAX_KERNEXEC
31205 + mov %cr0, %eax
31206 + xor $X86_CR0_WP, %eax
31207 + mov %eax, %cr0
31208 +#endif
31209
31210 // Once our page table's switched, the Guest is live!
31211 // The Host fades as we run this final step.
31212 @@ -295,13 +309,12 @@ deliver_to_host:
31213 // I consulted gcc, and it gave
31214 // These instructions, which I gladly credit:
31215 leal (%edx,%ebx,8), %eax
31216 - movzwl (%eax),%edx
31217 - movl 4(%eax), %eax
31218 - xorw %ax, %ax
31219 - orl %eax, %edx
31220 + movl 4(%eax), %edx
31221 + movw (%eax), %dx
31222 // Now the address of the handler's in %edx
31223 // We call it now: its "iret" drops us home.
31224 - jmp *%edx
31225 + ljmp $__KERNEL_CS, $1f
31226 +1: jmp *%edx
31227
31228 // Every interrupt can come to us here
31229 // But we must truly tell each apart.
31230 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
31231 index 4daf9e5..b8d1d0f 100644
31232 --- a/drivers/macintosh/macio_asic.c
31233 +++ b/drivers/macintosh/macio_asic.c
31234 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
31235 * MacIO is matched against any Apple ID, it's probe() function
31236 * will then decide wether it applies or not
31237 */
31238 -static const struct pci_device_id __devinitdata pci_ids [] = { {
31239 +static const struct pci_device_id __devinitconst pci_ids [] = { {
31240 .vendor = PCI_VENDOR_ID_APPLE,
31241 .device = PCI_ANY_ID,
31242 .subvendor = PCI_ANY_ID,
31243 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
31244 index 2e9a3ca..c2fb229 100644
31245 --- a/drivers/md/dm-ioctl.c
31246 +++ b/drivers/md/dm-ioctl.c
31247 @@ -1578,7 +1578,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
31248 cmd == DM_LIST_VERSIONS_CMD)
31249 return 0;
31250
31251 - if ((cmd == DM_DEV_CREATE_CMD)) {
31252 + if (cmd == DM_DEV_CREATE_CMD) {
31253 if (!*param->name) {
31254 DMWARN("name not supplied when creating device");
31255 return -EINVAL;
31256 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
31257 index 9bfd057..01180bc 100644
31258 --- a/drivers/md/dm-raid1.c
31259 +++ b/drivers/md/dm-raid1.c
31260 @@ -40,7 +40,7 @@ enum dm_raid1_error {
31261
31262 struct mirror {
31263 struct mirror_set *ms;
31264 - atomic_t error_count;
31265 + atomic_unchecked_t error_count;
31266 unsigned long error_type;
31267 struct dm_dev *dev;
31268 sector_t offset;
31269 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
31270 struct mirror *m;
31271
31272 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
31273 - if (!atomic_read(&m->error_count))
31274 + if (!atomic_read_unchecked(&m->error_count))
31275 return m;
31276
31277 return NULL;
31278 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
31279 * simple way to tell if a device has encountered
31280 * errors.
31281 */
31282 - atomic_inc(&m->error_count);
31283 + atomic_inc_unchecked(&m->error_count);
31284
31285 if (test_and_set_bit(error_type, &m->error_type))
31286 return;
31287 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
31288 struct mirror *m = get_default_mirror(ms);
31289
31290 do {
31291 - if (likely(!atomic_read(&m->error_count)))
31292 + if (likely(!atomic_read_unchecked(&m->error_count)))
31293 return m;
31294
31295 if (m-- == ms->mirror)
31296 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
31297 {
31298 struct mirror *default_mirror = get_default_mirror(m->ms);
31299
31300 - return !atomic_read(&default_mirror->error_count);
31301 + return !atomic_read_unchecked(&default_mirror->error_count);
31302 }
31303
31304 static int mirror_available(struct mirror_set *ms, struct bio *bio)
31305 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
31306 */
31307 if (likely(region_in_sync(ms, region, 1)))
31308 m = choose_mirror(ms, bio->bi_sector);
31309 - else if (m && atomic_read(&m->error_count))
31310 + else if (m && atomic_read_unchecked(&m->error_count))
31311 m = NULL;
31312
31313 if (likely(m))
31314 @@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
31315 }
31316
31317 ms->mirror[mirror].ms = ms;
31318 - atomic_set(&(ms->mirror[mirror].error_count), 0);
31319 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
31320 ms->mirror[mirror].error_type = 0;
31321 ms->mirror[mirror].offset = offset;
31322
31323 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
31324 */
31325 static char device_status_char(struct mirror *m)
31326 {
31327 - if (!atomic_read(&(m->error_count)))
31328 + if (!atomic_read_unchecked(&(m->error_count)))
31329 return 'A';
31330
31331 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
31332 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
31333 index 3d80cf0..b77cc47 100644
31334 --- a/drivers/md/dm-stripe.c
31335 +++ b/drivers/md/dm-stripe.c
31336 @@ -20,7 +20,7 @@ struct stripe {
31337 struct dm_dev *dev;
31338 sector_t physical_start;
31339
31340 - atomic_t error_count;
31341 + atomic_unchecked_t error_count;
31342 };
31343
31344 struct stripe_c {
31345 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
31346 kfree(sc);
31347 return r;
31348 }
31349 - atomic_set(&(sc->stripe[i].error_count), 0);
31350 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
31351 }
31352
31353 ti->private = sc;
31354 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
31355 DMEMIT("%d ", sc->stripes);
31356 for (i = 0; i < sc->stripes; i++) {
31357 DMEMIT("%s ", sc->stripe[i].dev->name);
31358 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
31359 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
31360 'D' : 'A';
31361 }
31362 buffer[i] = '\0';
31363 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
31364 */
31365 for (i = 0; i < sc->stripes; i++)
31366 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
31367 - atomic_inc(&(sc->stripe[i].error_count));
31368 - if (atomic_read(&(sc->stripe[i].error_count)) <
31369 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
31370 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
31371 DM_IO_ERROR_THRESHOLD)
31372 schedule_work(&sc->trigger_event);
31373 }
31374 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
31375 index bc04518..7a83b81 100644
31376 --- a/drivers/md/dm-table.c
31377 +++ b/drivers/md/dm-table.c
31378 @@ -389,7 +389,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
31379 if (!dev_size)
31380 return 0;
31381
31382 - if ((start >= dev_size) || (start + len > dev_size)) {
31383 + if ((start >= dev_size) || (len > dev_size - start)) {
31384 DMWARN("%s: %s too small for target: "
31385 "start=%llu, len=%llu, dev_size=%llu",
31386 dm_device_name(ti->table->md), bdevname(bdev, b),
31387 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
31388 index 52b39f3..83a8b6b 100644
31389 --- a/drivers/md/dm.c
31390 +++ b/drivers/md/dm.c
31391 @@ -165,9 +165,9 @@ struct mapped_device {
31392 /*
31393 * Event handling.
31394 */
31395 - atomic_t event_nr;
31396 + atomic_unchecked_t event_nr;
31397 wait_queue_head_t eventq;
31398 - atomic_t uevent_seq;
31399 + atomic_unchecked_t uevent_seq;
31400 struct list_head uevent_list;
31401 spinlock_t uevent_lock; /* Protect access to uevent_list */
31402
31403 @@ -1843,8 +1843,8 @@ static struct mapped_device *alloc_dev(int minor)
31404 rwlock_init(&md->map_lock);
31405 atomic_set(&md->holders, 1);
31406 atomic_set(&md->open_count, 0);
31407 - atomic_set(&md->event_nr, 0);
31408 - atomic_set(&md->uevent_seq, 0);
31409 + atomic_set_unchecked(&md->event_nr, 0);
31410 + atomic_set_unchecked(&md->uevent_seq, 0);
31411 INIT_LIST_HEAD(&md->uevent_list);
31412 spin_lock_init(&md->uevent_lock);
31413
31414 @@ -1978,7 +1978,7 @@ static void event_callback(void *context)
31415
31416 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
31417
31418 - atomic_inc(&md->event_nr);
31419 + atomic_inc_unchecked(&md->event_nr);
31420 wake_up(&md->eventq);
31421 }
31422
31423 @@ -2614,18 +2614,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
31424
31425 uint32_t dm_next_uevent_seq(struct mapped_device *md)
31426 {
31427 - return atomic_add_return(1, &md->uevent_seq);
31428 + return atomic_add_return_unchecked(1, &md->uevent_seq);
31429 }
31430
31431 uint32_t dm_get_event_nr(struct mapped_device *md)
31432 {
31433 - return atomic_read(&md->event_nr);
31434 + return atomic_read_unchecked(&md->event_nr);
31435 }
31436
31437 int dm_wait_event(struct mapped_device *md, int event_nr)
31438 {
31439 return wait_event_interruptible(md->eventq,
31440 - (event_nr != atomic_read(&md->event_nr)));
31441 + (event_nr != atomic_read_unchecked(&md->event_nr)));
31442 }
31443
31444 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
31445 diff --git a/drivers/md/md.c b/drivers/md/md.c
31446 index 5c95ccb..217fa57 100644
31447 --- a/drivers/md/md.c
31448 +++ b/drivers/md/md.c
31449 @@ -280,10 +280,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
31450 * start build, activate spare
31451 */
31452 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
31453 -static atomic_t md_event_count;
31454 +static atomic_unchecked_t md_event_count;
31455 void md_new_event(mddev_t *mddev)
31456 {
31457 - atomic_inc(&md_event_count);
31458 + atomic_inc_unchecked(&md_event_count);
31459 wake_up(&md_event_waiters);
31460 }
31461 EXPORT_SYMBOL_GPL(md_new_event);
31462 @@ -293,7 +293,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
31463 */
31464 static void md_new_event_inintr(mddev_t *mddev)
31465 {
31466 - atomic_inc(&md_event_count);
31467 + atomic_inc_unchecked(&md_event_count);
31468 wake_up(&md_event_waiters);
31469 }
31470
31471 @@ -1531,7 +1531,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
31472
31473 rdev->preferred_minor = 0xffff;
31474 rdev->data_offset = le64_to_cpu(sb->data_offset);
31475 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31476 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31477
31478 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
31479 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
31480 @@ -1748,7 +1748,7 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
31481 else
31482 sb->resync_offset = cpu_to_le64(0);
31483
31484 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
31485 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
31486
31487 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
31488 sb->size = cpu_to_le64(mddev->dev_sectors);
31489 @@ -2643,7 +2643,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
31490 static ssize_t
31491 errors_show(mdk_rdev_t *rdev, char *page)
31492 {
31493 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
31494 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
31495 }
31496
31497 static ssize_t
31498 @@ -2652,7 +2652,7 @@ errors_store(mdk_rdev_t *rdev, const char *buf, size_t len)
31499 char *e;
31500 unsigned long n = simple_strtoul(buf, &e, 10);
31501 if (*buf && (*e == 0 || *e == '\n')) {
31502 - atomic_set(&rdev->corrected_errors, n);
31503 + atomic_set_unchecked(&rdev->corrected_errors, n);
31504 return len;
31505 }
31506 return -EINVAL;
31507 @@ -3042,8 +3042,8 @@ int md_rdev_init(mdk_rdev_t *rdev)
31508 rdev->sb_loaded = 0;
31509 rdev->bb_page = NULL;
31510 atomic_set(&rdev->nr_pending, 0);
31511 - atomic_set(&rdev->read_errors, 0);
31512 - atomic_set(&rdev->corrected_errors, 0);
31513 + atomic_set_unchecked(&rdev->read_errors, 0);
31514 + atomic_set_unchecked(&rdev->corrected_errors, 0);
31515
31516 INIT_LIST_HEAD(&rdev->same_set);
31517 init_waitqueue_head(&rdev->blocked_wait);
31518 @@ -6667,7 +6667,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
31519
31520 spin_unlock(&pers_lock);
31521 seq_printf(seq, "\n");
31522 - seq->poll_event = atomic_read(&md_event_count);
31523 + seq->poll_event = atomic_read_unchecked(&md_event_count);
31524 return 0;
31525 }
31526 if (v == (void*)2) {
31527 @@ -6756,7 +6756,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
31528 chunk_kb ? "KB" : "B");
31529 if (bitmap->file) {
31530 seq_printf(seq, ", file: ");
31531 - seq_path(seq, &bitmap->file->f_path, " \t\n");
31532 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
31533 }
31534
31535 seq_printf(seq, "\n");
31536 @@ -6787,7 +6787,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
31537 return error;
31538
31539 seq = file->private_data;
31540 - seq->poll_event = atomic_read(&md_event_count);
31541 + seq->poll_event = atomic_read_unchecked(&md_event_count);
31542 return error;
31543 }
31544
31545 @@ -6801,7 +6801,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
31546 /* always allow read */
31547 mask = POLLIN | POLLRDNORM;
31548
31549 - if (seq->poll_event != atomic_read(&md_event_count))
31550 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
31551 mask |= POLLERR | POLLPRI;
31552 return mask;
31553 }
31554 @@ -6845,7 +6845,7 @@ static int is_mddev_idle(mddev_t *mddev, int init)
31555 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
31556 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
31557 (int)part_stat_read(&disk->part0, sectors[1]) -
31558 - atomic_read(&disk->sync_io);
31559 + atomic_read_unchecked(&disk->sync_io);
31560 /* sync IO will cause sync_io to increase before the disk_stats
31561 * as sync_io is counted when a request starts, and
31562 * disk_stats is counted when it completes.
31563 diff --git a/drivers/md/md.h b/drivers/md/md.h
31564 index 0a309dc..7e01d7f 100644
31565 --- a/drivers/md/md.h
31566 +++ b/drivers/md/md.h
31567 @@ -124,13 +124,13 @@ struct mdk_rdev_s
31568 * only maintained for arrays that
31569 * support hot removal
31570 */
31571 - atomic_t read_errors; /* number of consecutive read errors that
31572 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
31573 * we have tried to ignore.
31574 */
31575 struct timespec last_read_error; /* monotonic time since our
31576 * last read error
31577 */
31578 - atomic_t corrected_errors; /* number of corrected read errors,
31579 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
31580 * for reporting to userspace and storing
31581 * in superblock.
31582 */
31583 @@ -415,7 +415,7 @@ static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
31584
31585 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
31586 {
31587 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31588 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31589 }
31590
31591 struct mdk_personality
31592 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
31593 index d9587df..83a0dc3 100644
31594 --- a/drivers/md/raid1.c
31595 +++ b/drivers/md/raid1.c
31596 @@ -1541,7 +1541,7 @@ static int fix_sync_read_error(r1bio_t *r1_bio)
31597 if (r1_sync_page_io(rdev, sect, s,
31598 bio->bi_io_vec[idx].bv_page,
31599 READ) != 0)
31600 - atomic_add(s, &rdev->corrected_errors);
31601 + atomic_add_unchecked(s, &rdev->corrected_errors);
31602 }
31603 sectors -= s;
31604 sect += s;
31605 @@ -1754,7 +1754,7 @@ static void fix_read_error(conf_t *conf, int read_disk,
31606 test_bit(In_sync, &rdev->flags)) {
31607 if (r1_sync_page_io(rdev, sect, s,
31608 conf->tmppage, READ)) {
31609 - atomic_add(s, &rdev->corrected_errors);
31610 + atomic_add_unchecked(s, &rdev->corrected_errors);
31611 printk(KERN_INFO
31612 "md/raid1:%s: read error corrected "
31613 "(%d sectors at %llu on %s)\n",
31614 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
31615 index 1d44228..98db57d 100644
31616 --- a/drivers/md/raid10.c
31617 +++ b/drivers/md/raid10.c
31618 @@ -1423,7 +1423,7 @@ static void end_sync_read(struct bio *bio, int error)
31619 /* The write handler will notice the lack of
31620 * R10BIO_Uptodate and record any errors etc
31621 */
31622 - atomic_add(r10_bio->sectors,
31623 + atomic_add_unchecked(r10_bio->sectors,
31624 &conf->mirrors[d].rdev->corrected_errors);
31625
31626 /* for reconstruct, we always reschedule after a read.
31627 @@ -1723,7 +1723,7 @@ static void check_decay_read_errors(mddev_t *mddev, mdk_rdev_t *rdev)
31628 {
31629 struct timespec cur_time_mon;
31630 unsigned long hours_since_last;
31631 - unsigned int read_errors = atomic_read(&rdev->read_errors);
31632 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
31633
31634 ktime_get_ts(&cur_time_mon);
31635
31636 @@ -1745,9 +1745,9 @@ static void check_decay_read_errors(mddev_t *mddev, mdk_rdev_t *rdev)
31637 * overflowing the shift of read_errors by hours_since_last.
31638 */
31639 if (hours_since_last >= 8 * sizeof(read_errors))
31640 - atomic_set(&rdev->read_errors, 0);
31641 + atomic_set_unchecked(&rdev->read_errors, 0);
31642 else
31643 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
31644 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
31645 }
31646
31647 static int r10_sync_page_io(mdk_rdev_t *rdev, sector_t sector,
31648 @@ -1797,8 +1797,8 @@ static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio)
31649 return;
31650
31651 check_decay_read_errors(mddev, rdev);
31652 - atomic_inc(&rdev->read_errors);
31653 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
31654 + atomic_inc_unchecked(&rdev->read_errors);
31655 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
31656 char b[BDEVNAME_SIZE];
31657 bdevname(rdev->bdev, b);
31658
31659 @@ -1806,7 +1806,7 @@ static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio)
31660 "md/raid10:%s: %s: Raid device exceeded "
31661 "read_error threshold [cur %d:max %d]\n",
31662 mdname(mddev), b,
31663 - atomic_read(&rdev->read_errors), max_read_errors);
31664 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
31665 printk(KERN_NOTICE
31666 "md/raid10:%s: %s: Failing raid device\n",
31667 mdname(mddev), b);
31668 @@ -1951,7 +1951,7 @@ static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio)
31669 (unsigned long long)(
31670 sect + rdev->data_offset),
31671 bdevname(rdev->bdev, b));
31672 - atomic_add(s, &rdev->corrected_errors);
31673 + atomic_add_unchecked(s, &rdev->corrected_errors);
31674 }
31675
31676 rdev_dec_pending(rdev, mddev);
31677 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
31678 index b6200c3..02e8702 100644
31679 --- a/drivers/md/raid5.c
31680 +++ b/drivers/md/raid5.c
31681 @@ -1616,19 +1616,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
31682 (unsigned long long)(sh->sector
31683 + rdev->data_offset),
31684 bdevname(rdev->bdev, b));
31685 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
31686 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
31687 clear_bit(R5_ReadError, &sh->dev[i].flags);
31688 clear_bit(R5_ReWrite, &sh->dev[i].flags);
31689 }
31690 - if (atomic_read(&conf->disks[i].rdev->read_errors))
31691 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
31692 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
31693 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
31694 } else {
31695 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
31696 int retry = 0;
31697 rdev = conf->disks[i].rdev;
31698
31699 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
31700 - atomic_inc(&rdev->read_errors);
31701 + atomic_inc_unchecked(&rdev->read_errors);
31702 if (conf->mddev->degraded >= conf->max_degraded)
31703 printk_ratelimited(
31704 KERN_WARNING
31705 @@ -1648,7 +1648,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
31706 (unsigned long long)(sh->sector
31707 + rdev->data_offset),
31708 bdn);
31709 - else if (atomic_read(&rdev->read_errors)
31710 + else if (atomic_read_unchecked(&rdev->read_errors)
31711 > conf->max_nr_stripes)
31712 printk(KERN_WARNING
31713 "md/raid:%s: Too many read errors, failing device %s.\n",
31714 @@ -1978,6 +1978,7 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous)
31715 sector_t r_sector;
31716 struct stripe_head sh2;
31717
31718 + pax_track_stack();
31719
31720 chunk_offset = sector_div(new_sector, sectors_per_chunk);
31721 stripe = new_sector;
31722 diff --git a/drivers/media/common/saa7146_hlp.c b/drivers/media/common/saa7146_hlp.c
31723 index 1d1d8d2..6c6837a 100644
31724 --- a/drivers/media/common/saa7146_hlp.c
31725 +++ b/drivers/media/common/saa7146_hlp.c
31726 @@ -353,6 +353,8 @@ static void calculate_clipping_registers_rect(struct saa7146_dev *dev, struct sa
31727
31728 int x[32], y[32], w[32], h[32];
31729
31730 + pax_track_stack();
31731 +
31732 /* clear out memory */
31733 memset(&line_list[0], 0x00, sizeof(u32)*32);
31734 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
31735 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
31736 index 573d540..16f78f3 100644
31737 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
31738 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
31739 @@ -1675,7 +1675,7 @@ static struct ddb_info ddb_v6 = {
31740 .subvendor = _subvend, .subdevice = _subdev, \
31741 .driver_data = (unsigned long)&_driverdata }
31742
31743 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
31744 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
31745 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
31746 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
31747 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
31748 diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
31749 index 7ea517b..252fe54 100644
31750 --- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
31751 +++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
31752 @@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, u8 * eb
31753 u8 buf[HOST_LINK_BUF_SIZE];
31754 int i;
31755
31756 + pax_track_stack();
31757 +
31758 dprintk("%s\n", __func__);
31759
31760 /* check if we have space for a link buf in the rx_buffer */
31761 @@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
31762 unsigned long timeout;
31763 int written;
31764
31765 + pax_track_stack();
31766 +
31767 dprintk("%s\n", __func__);
31768
31769 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
31770 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
31771 index a7d876f..8c21b61 100644
31772 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
31773 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
31774 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
31775 union {
31776 dmx_ts_cb ts;
31777 dmx_section_cb sec;
31778 - } cb;
31779 + } __no_const cb;
31780
31781 struct dvb_demux *demux;
31782 void *priv;
31783 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
31784 index f732877..d38c35a 100644
31785 --- a/drivers/media/dvb/dvb-core/dvbdev.c
31786 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
31787 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
31788 const struct dvb_device *template, void *priv, int type)
31789 {
31790 struct dvb_device *dvbdev;
31791 - struct file_operations *dvbdevfops;
31792 + file_operations_no_const *dvbdevfops;
31793 struct device *clsdev;
31794 int minor;
31795 int id;
31796 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
31797 index acb5fb2..2413f1d 100644
31798 --- a/drivers/media/dvb/dvb-usb/cxusb.c
31799 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
31800 @@ -1059,7 +1059,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
31801 struct dib0700_adapter_state {
31802 int (*set_param_save) (struct dvb_frontend *,
31803 struct dvb_frontend_parameters *);
31804 -};
31805 +} __no_const;
31806
31807 static int dib7070_set_param_override(struct dvb_frontend *fe,
31808 struct dvb_frontend_parameters *fep)
31809 diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
31810 index a224e94..503b76a 100644
31811 --- a/drivers/media/dvb/dvb-usb/dib0700_core.c
31812 +++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
31813 @@ -478,6 +478,8 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
31814 if (!buf)
31815 return -ENOMEM;
31816
31817 + pax_track_stack();
31818 +
31819 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
31820 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",
31821 hx.addr, hx.len, hx.chk);
31822 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
31823 index 058b231..183d2b3 100644
31824 --- a/drivers/media/dvb/dvb-usb/dw2102.c
31825 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
31826 @@ -95,7 +95,7 @@ struct su3000_state {
31827
31828 struct s6x0_state {
31829 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
31830 -};
31831 +} __no_const;
31832
31833 /* debug */
31834 static int dvb_usb_dw2102_debug;
31835 diff --git a/drivers/media/dvb/dvb-usb/lmedm04.c b/drivers/media/dvb/dvb-usb/lmedm04.c
31836 index 37b1469..28a6f6f 100644
31837 --- a/drivers/media/dvb/dvb-usb/lmedm04.c
31838 +++ b/drivers/media/dvb/dvb-usb/lmedm04.c
31839 @@ -742,6 +742,7 @@ static int lme2510_download_firmware(struct usb_device *dev,
31840 usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
31841 0x06, 0x80, 0x0200, 0x00, data, 0x0109, 1000);
31842
31843 + pax_track_stack();
31844
31845 data[0] = 0x8a;
31846 len_in = 1;
31847 @@ -764,6 +765,8 @@ static void lme_coldreset(struct usb_device *dev)
31848 int ret = 0, len_in;
31849 u8 data[512] = {0};
31850
31851 + pax_track_stack();
31852 +
31853 data[0] = 0x0a;
31854 len_in = 1;
31855 info("FRM Firmware Cold Reset");
31856 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
31857 index ba91735..4261d84 100644
31858 --- a/drivers/media/dvb/frontends/dib3000.h
31859 +++ b/drivers/media/dvb/frontends/dib3000.h
31860 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
31861 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
31862 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
31863 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
31864 -};
31865 +} __no_const;
31866
31867 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
31868 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
31869 diff --git a/drivers/media/dvb/frontends/mb86a16.c b/drivers/media/dvb/frontends/mb86a16.c
31870 index c283112..7f367a7 100644
31871 --- a/drivers/media/dvb/frontends/mb86a16.c
31872 +++ b/drivers/media/dvb/frontends/mb86a16.c
31873 @@ -1060,6 +1060,8 @@ static int mb86a16_set_fe(struct mb86a16_state *state)
31874 int ret = -1;
31875 int sync;
31876
31877 + pax_track_stack();
31878 +
31879 dprintk(verbose, MB86A16_INFO, 1, "freq=%d Mhz, symbrt=%d Ksps", state->frequency, state->srate);
31880
31881 fcp = 3000;
31882 diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
31883 index c709ce6..b3fe620 100644
31884 --- a/drivers/media/dvb/frontends/or51211.c
31885 +++ b/drivers/media/dvb/frontends/or51211.c
31886 @@ -113,6 +113,8 @@ static int or51211_load_firmware (struct dvb_frontend* fe,
31887 u8 tudata[585];
31888 int i;
31889
31890 + pax_track_stack();
31891 +
31892 dprintk("Firmware is %zd bytes\n",fw->size);
31893
31894 /* Get eprom data */
31895 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
31896 index 0564192..75b16f5 100644
31897 --- a/drivers/media/dvb/ngene/ngene-cards.c
31898 +++ b/drivers/media/dvb/ngene/ngene-cards.c
31899 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
31900
31901 /****************************************************************************/
31902
31903 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
31904 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
31905 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
31906 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
31907 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
31908 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
31909 index 16a089f..ab1667d 100644
31910 --- a/drivers/media/radio/radio-cadet.c
31911 +++ b/drivers/media/radio/radio-cadet.c
31912 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
31913 unsigned char readbuf[RDS_BUFFER];
31914 int i = 0;
31915
31916 + if (count > RDS_BUFFER)
31917 + return -EFAULT;
31918 mutex_lock(&dev->lock);
31919 if (dev->rdsstat == 0) {
31920 dev->rdsstat = 1;
31921 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
31922 index 9cde353..8c6a1c3 100644
31923 --- a/drivers/media/video/au0828/au0828.h
31924 +++ b/drivers/media/video/au0828/au0828.h
31925 @@ -191,7 +191,7 @@ struct au0828_dev {
31926
31927 /* I2C */
31928 struct i2c_adapter i2c_adap;
31929 - struct i2c_algorithm i2c_algo;
31930 + i2c_algorithm_no_const i2c_algo;
31931 struct i2c_client i2c_client;
31932 u32 i2c_rc;
31933
31934 diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
31935 index 9e2f870..22e3a08 100644
31936 --- a/drivers/media/video/cx18/cx18-driver.c
31937 +++ b/drivers/media/video/cx18/cx18-driver.c
31938 @@ -327,6 +327,8 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
31939 struct i2c_client c;
31940 u8 eedata[256];
31941
31942 + pax_track_stack();
31943 +
31944 memset(&c, 0, sizeof(c));
31945 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
31946 c.adapter = &cx->i2c_adap[0];
31947 diff --git a/drivers/media/video/cx23885/cx23885-input.c b/drivers/media/video/cx23885/cx23885-input.c
31948 index ce765e3..f9e1b04 100644
31949 --- a/drivers/media/video/cx23885/cx23885-input.c
31950 +++ b/drivers/media/video/cx23885/cx23885-input.c
31951 @@ -53,6 +53,8 @@ static void cx23885_input_process_measurements(struct cx23885_dev *dev,
31952 bool handle = false;
31953 struct ir_raw_event ir_core_event[64];
31954
31955 + pax_track_stack();
31956 +
31957 do {
31958 num = 0;
31959 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event,
31960 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
31961 index 68d1240..46b32eb 100644
31962 --- a/drivers/media/video/cx88/cx88-alsa.c
31963 +++ b/drivers/media/video/cx88/cx88-alsa.c
31964 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
31965 * Only boards with eeprom and byte 1 at eeprom=1 have it
31966 */
31967
31968 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
31969 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
31970 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
31971 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
31972 {0, }
31973 diff --git a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
31974 index 9515f3a..c9ecb85 100644
31975 --- a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
31976 +++ b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
31977 @@ -120,6 +120,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw *hdw)
31978 u8 *eeprom;
31979 struct tveeprom tvdata;
31980
31981 + pax_track_stack();
31982 +
31983 memset(&tvdata,0,sizeof(tvdata));
31984
31985 eeprom = pvr2_eeprom_fetch(hdw);
31986 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31987 index 305e6aa..0143317 100644
31988 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31989 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31990 @@ -196,7 +196,7 @@ struct pvr2_hdw {
31991
31992 /* I2C stuff */
31993 struct i2c_adapter i2c_adap;
31994 - struct i2c_algorithm i2c_algo;
31995 + i2c_algorithm_no_const i2c_algo;
31996 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
31997 int i2c_cx25840_hack_state;
31998 int i2c_linked;
31999 diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
32000 index f9f29cc..5a2e330 100644
32001 --- a/drivers/media/video/saa7134/saa6752hs.c
32002 +++ b/drivers/media/video/saa7134/saa6752hs.c
32003 @@ -682,6 +682,8 @@ static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes)
32004 unsigned char localPAT[256];
32005 unsigned char localPMT[256];
32006
32007 + pax_track_stack();
32008 +
32009 /* Set video format - must be done first as it resets other settings */
32010 set_reg8(client, 0x41, h->video_format);
32011
32012 diff --git a/drivers/media/video/saa7164/saa7164-cmd.c b/drivers/media/video/saa7164/saa7164-cmd.c
32013 index 62fac7f..f29e0b9 100644
32014 --- a/drivers/media/video/saa7164/saa7164-cmd.c
32015 +++ b/drivers/media/video/saa7164/saa7164-cmd.c
32016 @@ -88,6 +88,8 @@ int saa7164_irq_dequeue(struct saa7164_dev *dev)
32017 u8 tmp[512];
32018 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32019
32020 + pax_track_stack();
32021 +
32022 /* While any outstand message on the bus exists... */
32023 do {
32024
32025 @@ -141,6 +143,8 @@ int saa7164_cmd_dequeue(struct saa7164_dev *dev)
32026 u8 tmp[512];
32027 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32028
32029 + pax_track_stack();
32030 +
32031 while (loop) {
32032
32033 struct tmComResInfo tRsp = { 0, 0, 0, 0, 0, 0 };
32034 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
32035 index 84cd1b6..f741e07 100644
32036 --- a/drivers/media/video/timblogiw.c
32037 +++ b/drivers/media/video/timblogiw.c
32038 @@ -744,7 +744,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
32039
32040 /* Platform device functions */
32041
32042 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
32043 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
32044 .vidioc_querycap = timblogiw_querycap,
32045 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
32046 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
32047 @@ -766,7 +766,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
32048 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
32049 };
32050
32051 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
32052 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
32053 .owner = THIS_MODULE,
32054 .open = timblogiw_open,
32055 .release = timblogiw_close,
32056 diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
32057 index f344411..6ae9974 100644
32058 --- a/drivers/media/video/usbvision/usbvision-core.c
32059 +++ b/drivers/media/video/usbvision/usbvision-core.c
32060 @@ -707,6 +707,8 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
32061 unsigned char rv, gv, bv;
32062 static unsigned char *Y, *U, *V;
32063
32064 + pax_track_stack();
32065 +
32066 frame = usbvision->cur_frame;
32067 image_size = frame->frmwidth * frame->frmheight;
32068 if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
32069 diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
32070 index f300dea..04834ba 100644
32071 --- a/drivers/media/video/videobuf-dma-sg.c
32072 +++ b/drivers/media/video/videobuf-dma-sg.c
32073 @@ -607,6 +607,8 @@ void *videobuf_sg_alloc(size_t size)
32074 {
32075 struct videobuf_queue q;
32076
32077 + pax_track_stack();
32078 +
32079 /* Required to make generic handler to call __videobuf_alloc */
32080 q.int_ops = &sg_ops;
32081
32082 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
32083 index 7956a10..f39232f 100644
32084 --- a/drivers/message/fusion/mptbase.c
32085 +++ b/drivers/message/fusion/mptbase.c
32086 @@ -6681,8 +6681,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
32087 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
32088 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
32089
32090 +#ifdef CONFIG_GRKERNSEC_HIDESYM
32091 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
32092 +#else
32093 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
32094 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
32095 +#endif
32096 +
32097 /*
32098 * Rounding UP to nearest 4-kB boundary here...
32099 */
32100 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
32101 index 7596aec..f7ae9aa 100644
32102 --- a/drivers/message/fusion/mptsas.c
32103 +++ b/drivers/message/fusion/mptsas.c
32104 @@ -439,6 +439,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
32105 return 0;
32106 }
32107
32108 +static inline void
32109 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
32110 +{
32111 + if (phy_info->port_details) {
32112 + phy_info->port_details->rphy = rphy;
32113 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
32114 + ioc->name, rphy));
32115 + }
32116 +
32117 + if (rphy) {
32118 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
32119 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
32120 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
32121 + ioc->name, rphy, rphy->dev.release));
32122 + }
32123 +}
32124 +
32125 /* no mutex */
32126 static void
32127 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
32128 @@ -477,23 +494,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
32129 return NULL;
32130 }
32131
32132 -static inline void
32133 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
32134 -{
32135 - if (phy_info->port_details) {
32136 - phy_info->port_details->rphy = rphy;
32137 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
32138 - ioc->name, rphy));
32139 - }
32140 -
32141 - if (rphy) {
32142 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
32143 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
32144 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
32145 - ioc->name, rphy, rphy->dev.release));
32146 - }
32147 -}
32148 -
32149 static inline struct sas_port *
32150 mptsas_get_port(struct mptsas_phyinfo *phy_info)
32151 {
32152 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
32153 index ce61a57..3da8862 100644
32154 --- a/drivers/message/fusion/mptscsih.c
32155 +++ b/drivers/message/fusion/mptscsih.c
32156 @@ -1268,15 +1268,16 @@ mptscsih_info(struct Scsi_Host *SChost)
32157
32158 h = shost_priv(SChost);
32159
32160 - if (h) {
32161 - if (h->info_kbuf == NULL)
32162 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
32163 - return h->info_kbuf;
32164 - h->info_kbuf[0] = '\0';
32165 + if (!h)
32166 + return NULL;
32167
32168 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
32169 - h->info_kbuf[size-1] = '\0';
32170 - }
32171 + if (h->info_kbuf == NULL)
32172 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
32173 + return h->info_kbuf;
32174 + h->info_kbuf[0] = '\0';
32175 +
32176 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
32177 + h->info_kbuf[size-1] = '\0';
32178
32179 return h->info_kbuf;
32180 }
32181 diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
32182 index 098de2b..fbb922c 100644
32183 --- a/drivers/message/i2o/i2o_config.c
32184 +++ b/drivers/message/i2o/i2o_config.c
32185 @@ -781,6 +781,8 @@ static int i2o_cfg_passthru(unsigned long arg)
32186 struct i2o_message *msg;
32187 unsigned int iop;
32188
32189 + pax_track_stack();
32190 +
32191 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
32192 return -EFAULT;
32193
32194 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
32195 index 07dbeaf..5533142 100644
32196 --- a/drivers/message/i2o/i2o_proc.c
32197 +++ b/drivers/message/i2o/i2o_proc.c
32198 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
32199 "Array Controller Device"
32200 };
32201
32202 -static char *chtostr(u8 * chars, int n)
32203 -{
32204 - char tmp[256];
32205 - tmp[0] = 0;
32206 - return strncat(tmp, (char *)chars, n);
32207 -}
32208 -
32209 static int i2o_report_query_status(struct seq_file *seq, int block_status,
32210 char *group)
32211 {
32212 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
32213
32214 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
32215 seq_printf(seq, "%-#8x", ddm_table.module_id);
32216 - seq_printf(seq, "%-29s",
32217 - chtostr(ddm_table.module_name_version, 28));
32218 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
32219 seq_printf(seq, "%9d ", ddm_table.data_size);
32220 seq_printf(seq, "%8d", ddm_table.code_size);
32221
32222 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
32223
32224 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
32225 seq_printf(seq, "%-#8x", dst->module_id);
32226 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
32227 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
32228 + seq_printf(seq, "%-.28s", dst->module_name_version);
32229 + seq_printf(seq, "%-.8s", dst->date);
32230 seq_printf(seq, "%8d ", dst->module_size);
32231 seq_printf(seq, "%8d ", dst->mpb_size);
32232 seq_printf(seq, "0x%04x", dst->module_flags);
32233 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
32234 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
32235 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
32236 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
32237 - seq_printf(seq, "Vendor info : %s\n",
32238 - chtostr((u8 *) (work32 + 2), 16));
32239 - seq_printf(seq, "Product info : %s\n",
32240 - chtostr((u8 *) (work32 + 6), 16));
32241 - seq_printf(seq, "Description : %s\n",
32242 - chtostr((u8 *) (work32 + 10), 16));
32243 - seq_printf(seq, "Product rev. : %s\n",
32244 - chtostr((u8 *) (work32 + 14), 8));
32245 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
32246 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
32247 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
32248 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
32249
32250 seq_printf(seq, "Serial number : ");
32251 print_serial_number(seq, (u8 *) (work32 + 16),
32252 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
32253 }
32254
32255 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
32256 - seq_printf(seq, "Module name : %s\n",
32257 - chtostr(result.module_name, 24));
32258 - seq_printf(seq, "Module revision : %s\n",
32259 - chtostr(result.module_rev, 8));
32260 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
32261 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
32262
32263 seq_printf(seq, "Serial number : ");
32264 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
32265 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
32266 return 0;
32267 }
32268
32269 - seq_printf(seq, "Device name : %s\n",
32270 - chtostr(result.device_name, 64));
32271 - seq_printf(seq, "Service name : %s\n",
32272 - chtostr(result.service_name, 64));
32273 - seq_printf(seq, "Physical name : %s\n",
32274 - chtostr(result.physical_location, 64));
32275 - seq_printf(seq, "Instance number : %s\n",
32276 - chtostr(result.instance_number, 4));
32277 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
32278 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
32279 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
32280 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
32281
32282 return 0;
32283 }
32284 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
32285 index a8c08f3..155fe3d 100644
32286 --- a/drivers/message/i2o/iop.c
32287 +++ b/drivers/message/i2o/iop.c
32288 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
32289
32290 spin_lock_irqsave(&c->context_list_lock, flags);
32291
32292 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
32293 - atomic_inc(&c->context_list_counter);
32294 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
32295 + atomic_inc_unchecked(&c->context_list_counter);
32296
32297 - entry->context = atomic_read(&c->context_list_counter);
32298 + entry->context = atomic_read_unchecked(&c->context_list_counter);
32299
32300 list_add(&entry->list, &c->context_list);
32301
32302 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
32303
32304 #if BITS_PER_LONG == 64
32305 spin_lock_init(&c->context_list_lock);
32306 - atomic_set(&c->context_list_counter, 0);
32307 + atomic_set_unchecked(&c->context_list_counter, 0);
32308 INIT_LIST_HEAD(&c->context_list);
32309 #endif
32310
32311 diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
32312 index a20e1c4..4f57255 100644
32313 --- a/drivers/mfd/ab3100-core.c
32314 +++ b/drivers/mfd/ab3100-core.c
32315 @@ -809,7 +809,7 @@ struct ab_family_id {
32316 char *name;
32317 };
32318
32319 -static const struct ab_family_id ids[] __devinitdata = {
32320 +static const struct ab_family_id ids[] __devinitconst = {
32321 /* AB3100 */
32322 {
32323 .id = 0xc0,
32324 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
32325 index f12720d..3c251fd 100644
32326 --- a/drivers/mfd/abx500-core.c
32327 +++ b/drivers/mfd/abx500-core.c
32328 @@ -14,7 +14,7 @@ static LIST_HEAD(abx500_list);
32329
32330 struct abx500_device_entry {
32331 struct list_head list;
32332 - struct abx500_ops ops;
32333 + abx500_ops_no_const ops;
32334 struct device *dev;
32335 };
32336
32337 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
32338 index 5c2a06a..8fa077c 100644
32339 --- a/drivers/mfd/janz-cmodio.c
32340 +++ b/drivers/mfd/janz-cmodio.c
32341 @@ -13,6 +13,7 @@
32342
32343 #include <linux/kernel.h>
32344 #include <linux/module.h>
32345 +#include <linux/slab.h>
32346 #include <linux/init.h>
32347 #include <linux/pci.h>
32348 #include <linux/interrupt.h>
32349 diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c
32350 index 5fe5de1..af64f53 100644
32351 --- a/drivers/mfd/wm8350-i2c.c
32352 +++ b/drivers/mfd/wm8350-i2c.c
32353 @@ -44,6 +44,8 @@ static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg,
32354 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
32355 int ret;
32356
32357 + pax_track_stack();
32358 +
32359 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
32360 return -EINVAL;
32361
32362 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
32363 index 8b51cd6..f628f8d 100644
32364 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
32365 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
32366 @@ -437,7 +437,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
32367 * the lid is closed. This leads to interrupts as soon as a little move
32368 * is done.
32369 */
32370 - atomic_inc(&lis3_dev.count);
32371 + atomic_inc_unchecked(&lis3_dev.count);
32372
32373 wake_up_interruptible(&lis3_dev.misc_wait);
32374 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
32375 @@ -520,7 +520,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
32376 if (lis3_dev.pm_dev)
32377 pm_runtime_get_sync(lis3_dev.pm_dev);
32378
32379 - atomic_set(&lis3_dev.count, 0);
32380 + atomic_set_unchecked(&lis3_dev.count, 0);
32381 return 0;
32382 }
32383
32384 @@ -547,7 +547,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
32385 add_wait_queue(&lis3_dev.misc_wait, &wait);
32386 while (true) {
32387 set_current_state(TASK_INTERRUPTIBLE);
32388 - data = atomic_xchg(&lis3_dev.count, 0);
32389 + data = atomic_xchg_unchecked(&lis3_dev.count, 0);
32390 if (data)
32391 break;
32392
32393 @@ -585,7 +585,7 @@ out:
32394 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
32395 {
32396 poll_wait(file, &lis3_dev.misc_wait, wait);
32397 - if (atomic_read(&lis3_dev.count))
32398 + if (atomic_read_unchecked(&lis3_dev.count))
32399 return POLLIN | POLLRDNORM;
32400 return 0;
32401 }
32402 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
32403 index a193958..4d7ecd2 100644
32404 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
32405 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
32406 @@ -265,7 +265,7 @@ struct lis3lv02d {
32407 struct input_polled_dev *idev; /* input device */
32408 struct platform_device *pdev; /* platform device */
32409 struct regulator_bulk_data regulators[2];
32410 - atomic_t count; /* interrupt count after last read */
32411 + atomic_unchecked_t count; /* interrupt count after last read */
32412 union axis_conversion ac; /* hw -> logical axis */
32413 int mapped_btns[3];
32414
32415 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
32416 index 2f30bad..c4c13d0 100644
32417 --- a/drivers/misc/sgi-gru/gruhandles.c
32418 +++ b/drivers/misc/sgi-gru/gruhandles.c
32419 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
32420 unsigned long nsec;
32421
32422 nsec = CLKS2NSEC(clks);
32423 - atomic_long_inc(&mcs_op_statistics[op].count);
32424 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
32425 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
32426 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
32427 if (mcs_op_statistics[op].max < nsec)
32428 mcs_op_statistics[op].max = nsec;
32429 }
32430 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
32431 index 7768b87..f8aac38 100644
32432 --- a/drivers/misc/sgi-gru/gruprocfs.c
32433 +++ b/drivers/misc/sgi-gru/gruprocfs.c
32434 @@ -32,9 +32,9 @@
32435
32436 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
32437
32438 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
32439 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
32440 {
32441 - unsigned long val = atomic_long_read(v);
32442 + unsigned long val = atomic_long_read_unchecked(v);
32443
32444 seq_printf(s, "%16lu %s\n", val, id);
32445 }
32446 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
32447
32448 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
32449 for (op = 0; op < mcsop_last; op++) {
32450 - count = atomic_long_read(&mcs_op_statistics[op].count);
32451 - total = atomic_long_read(&mcs_op_statistics[op].total);
32452 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
32453 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
32454 max = mcs_op_statistics[op].max;
32455 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
32456 count ? total / count : 0, max);
32457 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
32458 index 5c3ce24..4915ccb 100644
32459 --- a/drivers/misc/sgi-gru/grutables.h
32460 +++ b/drivers/misc/sgi-gru/grutables.h
32461 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
32462 * GRU statistics.
32463 */
32464 struct gru_stats_s {
32465 - atomic_long_t vdata_alloc;
32466 - atomic_long_t vdata_free;
32467 - atomic_long_t gts_alloc;
32468 - atomic_long_t gts_free;
32469 - atomic_long_t gms_alloc;
32470 - atomic_long_t gms_free;
32471 - atomic_long_t gts_double_allocate;
32472 - atomic_long_t assign_context;
32473 - atomic_long_t assign_context_failed;
32474 - atomic_long_t free_context;
32475 - atomic_long_t load_user_context;
32476 - atomic_long_t load_kernel_context;
32477 - atomic_long_t lock_kernel_context;
32478 - atomic_long_t unlock_kernel_context;
32479 - atomic_long_t steal_user_context;
32480 - atomic_long_t steal_kernel_context;
32481 - atomic_long_t steal_context_failed;
32482 - atomic_long_t nopfn;
32483 - atomic_long_t asid_new;
32484 - atomic_long_t asid_next;
32485 - atomic_long_t asid_wrap;
32486 - atomic_long_t asid_reuse;
32487 - atomic_long_t intr;
32488 - atomic_long_t intr_cbr;
32489 - atomic_long_t intr_tfh;
32490 - atomic_long_t intr_spurious;
32491 - atomic_long_t intr_mm_lock_failed;
32492 - atomic_long_t call_os;
32493 - atomic_long_t call_os_wait_queue;
32494 - atomic_long_t user_flush_tlb;
32495 - atomic_long_t user_unload_context;
32496 - atomic_long_t user_exception;
32497 - atomic_long_t set_context_option;
32498 - atomic_long_t check_context_retarget_intr;
32499 - atomic_long_t check_context_unload;
32500 - atomic_long_t tlb_dropin;
32501 - atomic_long_t tlb_preload_page;
32502 - atomic_long_t tlb_dropin_fail_no_asid;
32503 - atomic_long_t tlb_dropin_fail_upm;
32504 - atomic_long_t tlb_dropin_fail_invalid;
32505 - atomic_long_t tlb_dropin_fail_range_active;
32506 - atomic_long_t tlb_dropin_fail_idle;
32507 - atomic_long_t tlb_dropin_fail_fmm;
32508 - atomic_long_t tlb_dropin_fail_no_exception;
32509 - atomic_long_t tfh_stale_on_fault;
32510 - atomic_long_t mmu_invalidate_range;
32511 - atomic_long_t mmu_invalidate_page;
32512 - atomic_long_t flush_tlb;
32513 - atomic_long_t flush_tlb_gru;
32514 - atomic_long_t flush_tlb_gru_tgh;
32515 - atomic_long_t flush_tlb_gru_zero_asid;
32516 + atomic_long_unchecked_t vdata_alloc;
32517 + atomic_long_unchecked_t vdata_free;
32518 + atomic_long_unchecked_t gts_alloc;
32519 + atomic_long_unchecked_t gts_free;
32520 + atomic_long_unchecked_t gms_alloc;
32521 + atomic_long_unchecked_t gms_free;
32522 + atomic_long_unchecked_t gts_double_allocate;
32523 + atomic_long_unchecked_t assign_context;
32524 + atomic_long_unchecked_t assign_context_failed;
32525 + atomic_long_unchecked_t free_context;
32526 + atomic_long_unchecked_t load_user_context;
32527 + atomic_long_unchecked_t load_kernel_context;
32528 + atomic_long_unchecked_t lock_kernel_context;
32529 + atomic_long_unchecked_t unlock_kernel_context;
32530 + atomic_long_unchecked_t steal_user_context;
32531 + atomic_long_unchecked_t steal_kernel_context;
32532 + atomic_long_unchecked_t steal_context_failed;
32533 + atomic_long_unchecked_t nopfn;
32534 + atomic_long_unchecked_t asid_new;
32535 + atomic_long_unchecked_t asid_next;
32536 + atomic_long_unchecked_t asid_wrap;
32537 + atomic_long_unchecked_t asid_reuse;
32538 + atomic_long_unchecked_t intr;
32539 + atomic_long_unchecked_t intr_cbr;
32540 + atomic_long_unchecked_t intr_tfh;
32541 + atomic_long_unchecked_t intr_spurious;
32542 + atomic_long_unchecked_t intr_mm_lock_failed;
32543 + atomic_long_unchecked_t call_os;
32544 + atomic_long_unchecked_t call_os_wait_queue;
32545 + atomic_long_unchecked_t user_flush_tlb;
32546 + atomic_long_unchecked_t user_unload_context;
32547 + atomic_long_unchecked_t user_exception;
32548 + atomic_long_unchecked_t set_context_option;
32549 + atomic_long_unchecked_t check_context_retarget_intr;
32550 + atomic_long_unchecked_t check_context_unload;
32551 + atomic_long_unchecked_t tlb_dropin;
32552 + atomic_long_unchecked_t tlb_preload_page;
32553 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
32554 + atomic_long_unchecked_t tlb_dropin_fail_upm;
32555 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
32556 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
32557 + atomic_long_unchecked_t tlb_dropin_fail_idle;
32558 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
32559 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
32560 + atomic_long_unchecked_t tfh_stale_on_fault;
32561 + atomic_long_unchecked_t mmu_invalidate_range;
32562 + atomic_long_unchecked_t mmu_invalidate_page;
32563 + atomic_long_unchecked_t flush_tlb;
32564 + atomic_long_unchecked_t flush_tlb_gru;
32565 + atomic_long_unchecked_t flush_tlb_gru_tgh;
32566 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
32567
32568 - atomic_long_t copy_gpa;
32569 - atomic_long_t read_gpa;
32570 + atomic_long_unchecked_t copy_gpa;
32571 + atomic_long_unchecked_t read_gpa;
32572
32573 - atomic_long_t mesq_receive;
32574 - atomic_long_t mesq_receive_none;
32575 - atomic_long_t mesq_send;
32576 - atomic_long_t mesq_send_failed;
32577 - atomic_long_t mesq_noop;
32578 - atomic_long_t mesq_send_unexpected_error;
32579 - atomic_long_t mesq_send_lb_overflow;
32580 - atomic_long_t mesq_send_qlimit_reached;
32581 - atomic_long_t mesq_send_amo_nacked;
32582 - atomic_long_t mesq_send_put_nacked;
32583 - atomic_long_t mesq_page_overflow;
32584 - atomic_long_t mesq_qf_locked;
32585 - atomic_long_t mesq_qf_noop_not_full;
32586 - atomic_long_t mesq_qf_switch_head_failed;
32587 - atomic_long_t mesq_qf_unexpected_error;
32588 - atomic_long_t mesq_noop_unexpected_error;
32589 - atomic_long_t mesq_noop_lb_overflow;
32590 - atomic_long_t mesq_noop_qlimit_reached;
32591 - atomic_long_t mesq_noop_amo_nacked;
32592 - atomic_long_t mesq_noop_put_nacked;
32593 - atomic_long_t mesq_noop_page_overflow;
32594 + atomic_long_unchecked_t mesq_receive;
32595 + atomic_long_unchecked_t mesq_receive_none;
32596 + atomic_long_unchecked_t mesq_send;
32597 + atomic_long_unchecked_t mesq_send_failed;
32598 + atomic_long_unchecked_t mesq_noop;
32599 + atomic_long_unchecked_t mesq_send_unexpected_error;
32600 + atomic_long_unchecked_t mesq_send_lb_overflow;
32601 + atomic_long_unchecked_t mesq_send_qlimit_reached;
32602 + atomic_long_unchecked_t mesq_send_amo_nacked;
32603 + atomic_long_unchecked_t mesq_send_put_nacked;
32604 + atomic_long_unchecked_t mesq_page_overflow;
32605 + atomic_long_unchecked_t mesq_qf_locked;
32606 + atomic_long_unchecked_t mesq_qf_noop_not_full;
32607 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
32608 + atomic_long_unchecked_t mesq_qf_unexpected_error;
32609 + atomic_long_unchecked_t mesq_noop_unexpected_error;
32610 + atomic_long_unchecked_t mesq_noop_lb_overflow;
32611 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
32612 + atomic_long_unchecked_t mesq_noop_amo_nacked;
32613 + atomic_long_unchecked_t mesq_noop_put_nacked;
32614 + atomic_long_unchecked_t mesq_noop_page_overflow;
32615
32616 };
32617
32618 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
32619 tghop_invalidate, mcsop_last};
32620
32621 struct mcs_op_statistic {
32622 - atomic_long_t count;
32623 - atomic_long_t total;
32624 + atomic_long_unchecked_t count;
32625 + atomic_long_unchecked_t total;
32626 unsigned long max;
32627 };
32628
32629 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
32630
32631 #define STAT(id) do { \
32632 if (gru_options & OPT_STATS) \
32633 - atomic_long_inc(&gru_stats.id); \
32634 + atomic_long_inc_unchecked(&gru_stats.id); \
32635 } while (0)
32636
32637 #ifdef CONFIG_SGI_GRU_DEBUG
32638 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
32639 index 851b2f2..a4ec097 100644
32640 --- a/drivers/misc/sgi-xp/xp.h
32641 +++ b/drivers/misc/sgi-xp/xp.h
32642 @@ -289,7 +289,7 @@ struct xpc_interface {
32643 xpc_notify_func, void *);
32644 void (*received) (short, int, void *);
32645 enum xp_retval (*partid_to_nasids) (short, void *);
32646 -};
32647 +} __no_const;
32648
32649 extern struct xpc_interface xpc_interface;
32650
32651 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
32652 index b94d5f7..7f494c5 100644
32653 --- a/drivers/misc/sgi-xp/xpc.h
32654 +++ b/drivers/misc/sgi-xp/xpc.h
32655 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
32656 void (*received_payload) (struct xpc_channel *, void *);
32657 void (*notify_senders_of_disconnect) (struct xpc_channel *);
32658 };
32659 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
32660
32661 /* struct xpc_partition act_state values (for XPC HB) */
32662
32663 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
32664 /* found in xpc_main.c */
32665 extern struct device *xpc_part;
32666 extern struct device *xpc_chan;
32667 -extern struct xpc_arch_operations xpc_arch_ops;
32668 +extern xpc_arch_operations_no_const xpc_arch_ops;
32669 extern int xpc_disengage_timelimit;
32670 extern int xpc_disengage_timedout;
32671 extern int xpc_activate_IRQ_rcvd;
32672 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
32673 index 8d082b4..aa749ae 100644
32674 --- a/drivers/misc/sgi-xp/xpc_main.c
32675 +++ b/drivers/misc/sgi-xp/xpc_main.c
32676 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
32677 .notifier_call = xpc_system_die,
32678 };
32679
32680 -struct xpc_arch_operations xpc_arch_ops;
32681 +xpc_arch_operations_no_const xpc_arch_ops;
32682
32683 /*
32684 * Timer function to enforce the timelimit on the partition disengage.
32685 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
32686 index 26c5286..292d261 100644
32687 --- a/drivers/mmc/host/sdhci-pci.c
32688 +++ b/drivers/mmc/host/sdhci-pci.c
32689 @@ -542,7 +542,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
32690 .probe = via_probe,
32691 };
32692
32693 -static const struct pci_device_id pci_ids[] __devinitdata = {
32694 +static const struct pci_device_id pci_ids[] __devinitconst = {
32695 {
32696 .vendor = PCI_VENDOR_ID_RICOH,
32697 .device = PCI_DEVICE_ID_RICOH_R5C822,
32698 diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
32699 index e1e122f..d99a6ea 100644
32700 --- a/drivers/mtd/chips/cfi_cmdset_0001.c
32701 +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
32702 @@ -757,6 +757,8 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
32703 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
32704 unsigned long timeo = jiffies + HZ;
32705
32706 + pax_track_stack();
32707 +
32708 /* Prevent setting state FL_SYNCING for chip in suspended state. */
32709 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
32710 goto sleep;
32711 @@ -1653,6 +1655,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
32712 unsigned long initial_adr;
32713 int initial_len = len;
32714
32715 + pax_track_stack();
32716 +
32717 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
32718 adr += chip->start;
32719 initial_adr = adr;
32720 @@ -1871,6 +1875,8 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
32721 int retries = 3;
32722 int ret;
32723
32724 + pax_track_stack();
32725 +
32726 adr += chip->start;
32727
32728 retry:
32729 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
32730 index 179814a..abe9d60 100644
32731 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
32732 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
32733 @@ -255,6 +255,8 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
32734 unsigned long cmd_addr;
32735 struct cfi_private *cfi = map->fldrv_priv;
32736
32737 + pax_track_stack();
32738 +
32739 adr += chip->start;
32740
32741 /* Ensure cmd read/writes are aligned. */
32742 @@ -429,6 +431,8 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
32743 DECLARE_WAITQUEUE(wait, current);
32744 int wbufsize, z;
32745
32746 + pax_track_stack();
32747 +
32748 /* M58LW064A requires bus alignment for buffer wriets -- saw */
32749 if (adr & (map_bankwidth(map)-1))
32750 return -EINVAL;
32751 @@ -743,6 +747,8 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
32752 DECLARE_WAITQUEUE(wait, current);
32753 int ret = 0;
32754
32755 + pax_track_stack();
32756 +
32757 adr += chip->start;
32758
32759 /* Let's determine this according to the interleave only once */
32760 @@ -1048,6 +1054,8 @@ static inline int do_lock_oneblock(struct map_info *map, struct flchip *chip, un
32761 unsigned long timeo = jiffies + HZ;
32762 DECLARE_WAITQUEUE(wait, current);
32763
32764 + pax_track_stack();
32765 +
32766 adr += chip->start;
32767
32768 /* Let's determine this according to the interleave only once */
32769 @@ -1197,6 +1205,8 @@ static inline int do_unlock_oneblock(struct map_info *map, struct flchip *chip,
32770 unsigned long timeo = jiffies + HZ;
32771 DECLARE_WAITQUEUE(wait, current);
32772
32773 + pax_track_stack();
32774 +
32775 adr += chip->start;
32776
32777 /* Let's determine this according to the interleave only once */
32778 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
32779 index f7fbf60..9866457 100644
32780 --- a/drivers/mtd/devices/doc2000.c
32781 +++ b/drivers/mtd/devices/doc2000.c
32782 @@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
32783
32784 /* The ECC will not be calculated correctly if less than 512 is written */
32785 /* DBB-
32786 - if (len != 0x200 && eccbuf)
32787 + if (len != 0x200)
32788 printk(KERN_WARNING
32789 "ECC needs a full sector write (adr: %lx size %lx)\n",
32790 (long) to, (long) len);
32791 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
32792 index 241192f..d0c35a3 100644
32793 --- a/drivers/mtd/devices/doc2001.c
32794 +++ b/drivers/mtd/devices/doc2001.c
32795 @@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
32796 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
32797
32798 /* Don't allow read past end of device */
32799 - if (from >= this->totlen)
32800 + if (from >= this->totlen || !len)
32801 return -EINVAL;
32802
32803 /* Don't allow a single read to cross a 512-byte block boundary */
32804 diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
32805 index 037b399..225a71d 100644
32806 --- a/drivers/mtd/ftl.c
32807 +++ b/drivers/mtd/ftl.c
32808 @@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit,
32809 loff_t offset;
32810 uint16_t srcunitswap = cpu_to_le16(srcunit);
32811
32812 + pax_track_stack();
32813 +
32814 eun = &part->EUNInfo[srcunit];
32815 xfer = &part->XferInfo[xferunit];
32816 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
32817 diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
32818 index d7592e6..31c505c 100644
32819 --- a/drivers/mtd/inftlcore.c
32820 +++ b/drivers/mtd/inftlcore.c
32821 @@ -259,6 +259,8 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
32822 struct inftl_oob oob;
32823 size_t retlen;
32824
32825 + pax_track_stack();
32826 +
32827 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
32828 "pending=%d)\n", inftl, thisVUC, pendingblock);
32829
32830 diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
32831 index 104052e..6232be5 100644
32832 --- a/drivers/mtd/inftlmount.c
32833 +++ b/drivers/mtd/inftlmount.c
32834 @@ -53,6 +53,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
32835 struct INFTLPartition *ip;
32836 size_t retlen;
32837
32838 + pax_track_stack();
32839 +
32840 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
32841
32842 /*
32843 diff --git a/drivers/mtd/lpddr/qinfo_probe.c b/drivers/mtd/lpddr/qinfo_probe.c
32844 index dbfe17b..c7b0918 100644
32845 --- a/drivers/mtd/lpddr/qinfo_probe.c
32846 +++ b/drivers/mtd/lpddr/qinfo_probe.c
32847 @@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map_info *map, struct lpddr_private *lpddr)
32848 {
32849 map_word pfow_val[4];
32850
32851 + pax_track_stack();
32852 +
32853 /* Check identification string */
32854 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
32855 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
32856 diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
32857 index 49e20a4..60fbfa5 100644
32858 --- a/drivers/mtd/mtdchar.c
32859 +++ b/drivers/mtd/mtdchar.c
32860 @@ -554,6 +554,8 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
32861 u_long size;
32862 struct mtd_info_user info;
32863
32864 + pax_track_stack();
32865 +
32866 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
32867
32868 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
32869 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
32870 index d527621..2491fab 100644
32871 --- a/drivers/mtd/nand/denali.c
32872 +++ b/drivers/mtd/nand/denali.c
32873 @@ -26,6 +26,7 @@
32874 #include <linux/pci.h>
32875 #include <linux/mtd/mtd.h>
32876 #include <linux/module.h>
32877 +#include <linux/slab.h>
32878
32879 #include "denali.h"
32880
32881 diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
32882 index b155666..611b801 100644
32883 --- a/drivers/mtd/nftlcore.c
32884 +++ b/drivers/mtd/nftlcore.c
32885 @@ -264,6 +264,8 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
32886 int inplace = 1;
32887 size_t retlen;
32888
32889 + pax_track_stack();
32890 +
32891 memset(BlockMap, 0xff, sizeof(BlockMap));
32892 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
32893
32894 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
32895 index e3cd1ff..0ea79a3 100644
32896 --- a/drivers/mtd/nftlmount.c
32897 +++ b/drivers/mtd/nftlmount.c
32898 @@ -24,6 +24,7 @@
32899 #include <asm/errno.h>
32900 #include <linux/delay.h>
32901 #include <linux/slab.h>
32902 +#include <linux/sched.h>
32903 #include <linux/mtd/mtd.h>
32904 #include <linux/mtd/nand.h>
32905 #include <linux/mtd/nftl.h>
32906 @@ -45,6 +46,8 @@ static int find_boot_record(struct NFTLrecord *nftl)
32907 struct mtd_info *mtd = nftl->mbd.mtd;
32908 unsigned int i;
32909
32910 + pax_track_stack();
32911 +
32912 /* Assume logical EraseSize == physical erasesize for starting the scan.
32913 We'll sort it out later if we find a MediaHeader which says otherwise */
32914 /* Actually, we won't. The new DiskOnChip driver has already scanned
32915 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
32916 index 6c3fb5a..c542a81 100644
32917 --- a/drivers/mtd/ubi/build.c
32918 +++ b/drivers/mtd/ubi/build.c
32919 @@ -1311,7 +1311,7 @@ module_exit(ubi_exit);
32920 static int __init bytes_str_to_int(const char *str)
32921 {
32922 char *endp;
32923 - unsigned long result;
32924 + unsigned long result, scale = 1;
32925
32926 result = simple_strtoul(str, &endp, 0);
32927 if (str == endp || result >= INT_MAX) {
32928 @@ -1322,11 +1322,11 @@ static int __init bytes_str_to_int(const char *str)
32929
32930 switch (*endp) {
32931 case 'G':
32932 - result *= 1024;
32933 + scale *= 1024;
32934 case 'M':
32935 - result *= 1024;
32936 + scale *= 1024;
32937 case 'K':
32938 - result *= 1024;
32939 + scale *= 1024;
32940 if (endp[1] == 'i' && endp[2] == 'B')
32941 endp += 2;
32942 case '\0':
32943 @@ -1337,7 +1337,13 @@ static int __init bytes_str_to_int(const char *str)
32944 return -EINVAL;
32945 }
32946
32947 - return result;
32948 + if ((intoverflow_t)result*scale >= INT_MAX) {
32949 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
32950 + str);
32951 + return -EINVAL;
32952 + }
32953 +
32954 + return result*scale;
32955 }
32956
32957 /**
32958 diff --git a/drivers/net/atlx/atl2.c b/drivers/net/atlx/atl2.c
32959 index d4f7dda..d627d46 100644
32960 --- a/drivers/net/atlx/atl2.c
32961 +++ b/drivers/net/atlx/atl2.c
32962 @@ -2857,7 +2857,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
32963 */
32964
32965 #define ATL2_PARAM(X, desc) \
32966 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
32967 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
32968 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
32969 MODULE_PARM_DESC(X, desc);
32970 #else
32971 diff --git a/drivers/net/bna/bfa_ioc_ct.c b/drivers/net/bna/bfa_ioc_ct.c
32972 index 87aecdf..ec23470 100644
32973 --- a/drivers/net/bna/bfa_ioc_ct.c
32974 +++ b/drivers/net/bna/bfa_ioc_ct.c
32975 @@ -48,7 +48,21 @@ static void bfa_ioc_ct_sync_ack(struct bfa_ioc *ioc);
32976 static bool bfa_ioc_ct_sync_complete(struct bfa_ioc *ioc);
32977 static enum bfa_status bfa_ioc_ct_pll_init(void __iomem *rb, bool fcmode);
32978
32979 -static struct bfa_ioc_hwif nw_hwif_ct;
32980 +static struct bfa_ioc_hwif nw_hwif_ct = {
32981 + .ioc_pll_init = bfa_ioc_ct_pll_init,
32982 + .ioc_firmware_lock = bfa_ioc_ct_firmware_lock,
32983 + .ioc_firmware_unlock = bfa_ioc_ct_firmware_unlock,
32984 + .ioc_reg_init = bfa_ioc_ct_reg_init,
32985 + .ioc_map_port = bfa_ioc_ct_map_port,
32986 + .ioc_isr_mode_set = bfa_ioc_ct_isr_mode_set,
32987 + .ioc_notify_fail = bfa_ioc_ct_notify_fail,
32988 + .ioc_ownership_reset = bfa_ioc_ct_ownership_reset,
32989 + .ioc_sync_start = bfa_ioc_ct_sync_start,
32990 + .ioc_sync_join = bfa_ioc_ct_sync_join,
32991 + .ioc_sync_leave = bfa_ioc_ct_sync_leave,
32992 + .ioc_sync_ack = bfa_ioc_ct_sync_ack,
32993 + .ioc_sync_complete = bfa_ioc_ct_sync_complete
32994 +};
32995
32996 /**
32997 * Called from bfa_ioc_attach() to map asic specific calls.
32998 @@ -56,20 +70,6 @@ static struct bfa_ioc_hwif nw_hwif_ct;
32999 void
33000 bfa_nw_ioc_set_ct_hwif(struct bfa_ioc *ioc)
33001 {
33002 - nw_hwif_ct.ioc_pll_init = bfa_ioc_ct_pll_init;
33003 - nw_hwif_ct.ioc_firmware_lock = bfa_ioc_ct_firmware_lock;
33004 - nw_hwif_ct.ioc_firmware_unlock = bfa_ioc_ct_firmware_unlock;
33005 - nw_hwif_ct.ioc_reg_init = bfa_ioc_ct_reg_init;
33006 - nw_hwif_ct.ioc_map_port = bfa_ioc_ct_map_port;
33007 - nw_hwif_ct.ioc_isr_mode_set = bfa_ioc_ct_isr_mode_set;
33008 - nw_hwif_ct.ioc_notify_fail = bfa_ioc_ct_notify_fail;
33009 - nw_hwif_ct.ioc_ownership_reset = bfa_ioc_ct_ownership_reset;
33010 - nw_hwif_ct.ioc_sync_start = bfa_ioc_ct_sync_start;
33011 - nw_hwif_ct.ioc_sync_join = bfa_ioc_ct_sync_join;
33012 - nw_hwif_ct.ioc_sync_leave = bfa_ioc_ct_sync_leave;
33013 - nw_hwif_ct.ioc_sync_ack = bfa_ioc_ct_sync_ack;
33014 - nw_hwif_ct.ioc_sync_complete = bfa_ioc_ct_sync_complete;
33015 -
33016 ioc->ioc_hwif = &nw_hwif_ct;
33017 }
33018
33019 diff --git a/drivers/net/bna/bnad.c b/drivers/net/bna/bnad.c
33020 index 8e35b25..c39f205 100644
33021 --- a/drivers/net/bna/bnad.c
33022 +++ b/drivers/net/bna/bnad.c
33023 @@ -1673,7 +1673,14 @@ bnad_setup_tx(struct bnad *bnad, uint tx_id)
33024 struct bna_intr_info *intr_info =
33025 &res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info;
33026 struct bna_tx_config *tx_config = &bnad->tx_config[tx_id];
33027 - struct bna_tx_event_cbfn tx_cbfn;
33028 + static struct bna_tx_event_cbfn tx_cbfn = {
33029 + /* Initialize the tx event handlers */
33030 + .tcb_setup_cbfn = bnad_cb_tcb_setup,
33031 + .tcb_destroy_cbfn = bnad_cb_tcb_destroy,
33032 + .tx_stall_cbfn = bnad_cb_tx_stall,
33033 + .tx_resume_cbfn = bnad_cb_tx_resume,
33034 + .tx_cleanup_cbfn = bnad_cb_tx_cleanup
33035 + };
33036 struct bna_tx *tx;
33037 unsigned long flags;
33038
33039 @@ -1682,13 +1689,6 @@ bnad_setup_tx(struct bnad *bnad, uint tx_id)
33040 tx_config->txq_depth = bnad->txq_depth;
33041 tx_config->tx_type = BNA_TX_T_REGULAR;
33042
33043 - /* Initialize the tx event handlers */
33044 - tx_cbfn.tcb_setup_cbfn = bnad_cb_tcb_setup;
33045 - tx_cbfn.tcb_destroy_cbfn = bnad_cb_tcb_destroy;
33046 - tx_cbfn.tx_stall_cbfn = bnad_cb_tx_stall;
33047 - tx_cbfn.tx_resume_cbfn = bnad_cb_tx_resume;
33048 - tx_cbfn.tx_cleanup_cbfn = bnad_cb_tx_cleanup;
33049 -
33050 /* Get BNA's resource requirement for one tx object */
33051 spin_lock_irqsave(&bnad->bna_lock, flags);
33052 bna_tx_res_req(bnad->num_txq_per_tx,
33053 @@ -1819,21 +1819,21 @@ bnad_setup_rx(struct bnad *bnad, uint rx_id)
33054 struct bna_intr_info *intr_info =
33055 &res_info[BNA_RX_RES_T_INTR].res_u.intr_info;
33056 struct bna_rx_config *rx_config = &bnad->rx_config[rx_id];
33057 - struct bna_rx_event_cbfn rx_cbfn;
33058 + static struct bna_rx_event_cbfn rx_cbfn = {
33059 + /* Initialize the Rx event handlers */
33060 + .rcb_setup_cbfn = bnad_cb_rcb_setup,
33061 + .rcb_destroy_cbfn = bnad_cb_rcb_destroy,
33062 + .ccb_setup_cbfn = bnad_cb_ccb_setup,
33063 + .ccb_destroy_cbfn = bnad_cb_ccb_destroy,
33064 + .rx_cleanup_cbfn = bnad_cb_rx_cleanup,
33065 + .rx_post_cbfn = bnad_cb_rx_post
33066 + };
33067 struct bna_rx *rx;
33068 unsigned long flags;
33069
33070 /* Initialize the Rx object configuration */
33071 bnad_init_rx_config(bnad, rx_config);
33072
33073 - /* Initialize the Rx event handlers */
33074 - rx_cbfn.rcb_setup_cbfn = bnad_cb_rcb_setup;
33075 - rx_cbfn.rcb_destroy_cbfn = bnad_cb_rcb_destroy;
33076 - rx_cbfn.ccb_setup_cbfn = bnad_cb_ccb_setup;
33077 - rx_cbfn.ccb_destroy_cbfn = bnad_cb_ccb_destroy;
33078 - rx_cbfn.rx_cleanup_cbfn = bnad_cb_rx_cleanup;
33079 - rx_cbfn.rx_post_cbfn = bnad_cb_rx_post;
33080 -
33081 /* Get BNA's resource requirement for one Rx object */
33082 spin_lock_irqsave(&bnad->bna_lock, flags);
33083 bna_rx_res_req(rx_config, res_info);
33084 diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
33085 index 4b2b570..31033f4 100644
33086 --- a/drivers/net/bnx2.c
33087 +++ b/drivers/net/bnx2.c
33088 @@ -5877,6 +5877,8 @@ bnx2_test_nvram(struct bnx2 *bp)
33089 int rc = 0;
33090 u32 magic, csum;
33091
33092 + pax_track_stack();
33093 +
33094 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
33095 goto test_nvram_done;
33096
33097 diff --git a/drivers/net/bnx2x/bnx2x_ethtool.c b/drivers/net/bnx2x/bnx2x_ethtool.c
33098 index cf3e479..5dc0ecc 100644
33099 --- a/drivers/net/bnx2x/bnx2x_ethtool.c
33100 +++ b/drivers/net/bnx2x/bnx2x_ethtool.c
33101 @@ -1943,6 +1943,8 @@ static int bnx2x_test_nvram(struct bnx2x *bp)
33102 int i, rc;
33103 u32 magic, crc;
33104
33105 + pax_track_stack();
33106 +
33107 if (BP_NOMCP(bp))
33108 return 0;
33109
33110 diff --git a/drivers/net/bnx2x/bnx2x_sp.h b/drivers/net/bnx2x/bnx2x_sp.h
33111 index 9a517c2..a50cfcb 100644
33112 --- a/drivers/net/bnx2x/bnx2x_sp.h
33113 +++ b/drivers/net/bnx2x/bnx2x_sp.h
33114 @@ -449,7 +449,7 @@ struct bnx2x_rx_mode_obj {
33115
33116 int (*wait_comp)(struct bnx2x *bp,
33117 struct bnx2x_rx_mode_ramrod_params *p);
33118 -};
33119 +} __no_const;
33120
33121 /********************** Set multicast group ***********************************/
33122
33123 diff --git a/drivers/net/cxgb3/l2t.h b/drivers/net/cxgb3/l2t.h
33124 index c5f5479..2e8c260 100644
33125 --- a/drivers/net/cxgb3/l2t.h
33126 +++ b/drivers/net/cxgb3/l2t.h
33127 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
33128 */
33129 struct l2t_skb_cb {
33130 arp_failure_handler_func arp_failure_handler;
33131 -};
33132 +} __no_const;
33133
33134 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
33135
33136 diff --git a/drivers/net/cxgb4/cxgb4_main.c b/drivers/net/cxgb4/cxgb4_main.c
33137 index b4efa29..c5f2703 100644
33138 --- a/drivers/net/cxgb4/cxgb4_main.c
33139 +++ b/drivers/net/cxgb4/cxgb4_main.c
33140 @@ -3396,6 +3396,8 @@ static int __devinit enable_msix(struct adapter *adap)
33141 unsigned int nchan = adap->params.nports;
33142 struct msix_entry entries[MAX_INGQ + 1];
33143
33144 + pax_track_stack();
33145 +
33146 for (i = 0; i < ARRAY_SIZE(entries); ++i)
33147 entries[i].entry = i;
33148
33149 diff --git a/drivers/net/cxgb4/t4_hw.c b/drivers/net/cxgb4/t4_hw.c
33150 index d1ec111..12735bc 100644
33151 --- a/drivers/net/cxgb4/t4_hw.c
33152 +++ b/drivers/net/cxgb4/t4_hw.c
33153 @@ -362,6 +362,8 @@ static int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
33154 u8 vpd[VPD_LEN], csum;
33155 unsigned int vpdr_len, kw_offset, id_len;
33156
33157 + pax_track_stack();
33158 +
33159 ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(vpd), vpd);
33160 if (ret < 0)
33161 return ret;
33162 diff --git a/drivers/net/e1000e/82571.c b/drivers/net/e1000e/82571.c
33163 index 536b3a5..e6f8dcc 100644
33164 --- a/drivers/net/e1000e/82571.c
33165 +++ b/drivers/net/e1000e/82571.c
33166 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
33167 {
33168 struct e1000_hw *hw = &adapter->hw;
33169 struct e1000_mac_info *mac = &hw->mac;
33170 - struct e1000_mac_operations *func = &mac->ops;
33171 + e1000_mac_operations_no_const *func = &mac->ops;
33172 u32 swsm = 0;
33173 u32 swsm2 = 0;
33174 bool force_clear_smbi = false;
33175 diff --git a/drivers/net/e1000e/es2lan.c b/drivers/net/e1000e/es2lan.c
33176 index e4f4225..24da2ea 100644
33177 --- a/drivers/net/e1000e/es2lan.c
33178 +++ b/drivers/net/e1000e/es2lan.c
33179 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
33180 {
33181 struct e1000_hw *hw = &adapter->hw;
33182 struct e1000_mac_info *mac = &hw->mac;
33183 - struct e1000_mac_operations *func = &mac->ops;
33184 + e1000_mac_operations_no_const *func = &mac->ops;
33185
33186 /* Set media type */
33187 switch (adapter->pdev->device) {
33188 diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
33189 index 2967039..ca8c40c 100644
33190 --- a/drivers/net/e1000e/hw.h
33191 +++ b/drivers/net/e1000e/hw.h
33192 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
33193 void (*write_vfta)(struct e1000_hw *, u32, u32);
33194 s32 (*read_mac_addr)(struct e1000_hw *);
33195 };
33196 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
33197
33198 /*
33199 * When to use various PHY register access functions:
33200 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
33201 void (*power_up)(struct e1000_hw *);
33202 void (*power_down)(struct e1000_hw *);
33203 };
33204 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
33205
33206 /* Function pointers for the NVM. */
33207 struct e1000_nvm_operations {
33208 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
33209 s32 (*validate)(struct e1000_hw *);
33210 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
33211 };
33212 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
33213
33214 struct e1000_mac_info {
33215 - struct e1000_mac_operations ops;
33216 + e1000_mac_operations_no_const ops;
33217 u8 addr[ETH_ALEN];
33218 u8 perm_addr[ETH_ALEN];
33219
33220 @@ -872,7 +875,7 @@ struct e1000_mac_info {
33221 };
33222
33223 struct e1000_phy_info {
33224 - struct e1000_phy_operations ops;
33225 + e1000_phy_operations_no_const ops;
33226
33227 enum e1000_phy_type type;
33228
33229 @@ -906,7 +909,7 @@ struct e1000_phy_info {
33230 };
33231
33232 struct e1000_nvm_info {
33233 - struct e1000_nvm_operations ops;
33234 + e1000_nvm_operations_no_const ops;
33235
33236 enum e1000_nvm_type type;
33237 enum e1000_nvm_override override;
33238 diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
33239 index fa8677c..196356f 100644
33240 --- a/drivers/net/fealnx.c
33241 +++ b/drivers/net/fealnx.c
33242 @@ -150,7 +150,7 @@ struct chip_info {
33243 int flags;
33244 };
33245
33246 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
33247 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
33248 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
33249 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
33250 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
33251 diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
33252 index 2a5a34d..be871cc 100644
33253 --- a/drivers/net/hamradio/6pack.c
33254 +++ b/drivers/net/hamradio/6pack.c
33255 @@ -463,6 +463,8 @@ static void sixpack_receive_buf(struct tty_struct *tty,
33256 unsigned char buf[512];
33257 int count1;
33258
33259 + pax_track_stack();
33260 +
33261 if (!count)
33262 return;
33263
33264 diff --git a/drivers/net/igb/e1000_hw.h b/drivers/net/igb/e1000_hw.h
33265 index 4519a13..f97fcd0 100644
33266 --- a/drivers/net/igb/e1000_hw.h
33267 +++ b/drivers/net/igb/e1000_hw.h
33268 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
33269 s32 (*read_mac_addr)(struct e1000_hw *);
33270 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
33271 };
33272 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
33273
33274 struct e1000_phy_operations {
33275 s32 (*acquire)(struct e1000_hw *);
33276 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
33277 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
33278 s32 (*write_reg)(struct e1000_hw *, u32, u16);
33279 };
33280 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
33281
33282 struct e1000_nvm_operations {
33283 s32 (*acquire)(struct e1000_hw *);
33284 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
33285 s32 (*update)(struct e1000_hw *);
33286 s32 (*validate)(struct e1000_hw *);
33287 };
33288 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
33289
33290 struct e1000_info {
33291 s32 (*get_invariants)(struct e1000_hw *);
33292 @@ -350,7 +353,7 @@ struct e1000_info {
33293 extern const struct e1000_info e1000_82575_info;
33294
33295 struct e1000_mac_info {
33296 - struct e1000_mac_operations ops;
33297 + e1000_mac_operations_no_const ops;
33298
33299 u8 addr[6];
33300 u8 perm_addr[6];
33301 @@ -388,7 +391,7 @@ struct e1000_mac_info {
33302 };
33303
33304 struct e1000_phy_info {
33305 - struct e1000_phy_operations ops;
33306 + e1000_phy_operations_no_const ops;
33307
33308 enum e1000_phy_type type;
33309
33310 @@ -423,7 +426,7 @@ struct e1000_phy_info {
33311 };
33312
33313 struct e1000_nvm_info {
33314 - struct e1000_nvm_operations ops;
33315 + e1000_nvm_operations_no_const ops;
33316 enum e1000_nvm_type type;
33317 enum e1000_nvm_override override;
33318
33319 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
33320 s32 (*check_for_ack)(struct e1000_hw *, u16);
33321 s32 (*check_for_rst)(struct e1000_hw *, u16);
33322 };
33323 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
33324
33325 struct e1000_mbx_stats {
33326 u32 msgs_tx;
33327 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
33328 };
33329
33330 struct e1000_mbx_info {
33331 - struct e1000_mbx_operations ops;
33332 + e1000_mbx_operations_no_const ops;
33333 struct e1000_mbx_stats stats;
33334 u32 timeout;
33335 u32 usec_delay;
33336 diff --git a/drivers/net/igbvf/vf.h b/drivers/net/igbvf/vf.h
33337 index d7ed58f..64cde36 100644
33338 --- a/drivers/net/igbvf/vf.h
33339 +++ b/drivers/net/igbvf/vf.h
33340 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
33341 s32 (*read_mac_addr)(struct e1000_hw *);
33342 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
33343 };
33344 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
33345
33346 struct e1000_mac_info {
33347 - struct e1000_mac_operations ops;
33348 + e1000_mac_operations_no_const ops;
33349 u8 addr[6];
33350 u8 perm_addr[6];
33351
33352 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
33353 s32 (*check_for_ack)(struct e1000_hw *);
33354 s32 (*check_for_rst)(struct e1000_hw *);
33355 };
33356 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
33357
33358 struct e1000_mbx_stats {
33359 u32 msgs_tx;
33360 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
33361 };
33362
33363 struct e1000_mbx_info {
33364 - struct e1000_mbx_operations ops;
33365 + e1000_mbx_operations_no_const ops;
33366 struct e1000_mbx_stats stats;
33367 u32 timeout;
33368 u32 usec_delay;
33369 diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
33370 index 6a130eb..1aeb9e4 100644
33371 --- a/drivers/net/ixgb/ixgb_main.c
33372 +++ b/drivers/net/ixgb/ixgb_main.c
33373 @@ -1070,6 +1070,8 @@ ixgb_set_multi(struct net_device *netdev)
33374 u32 rctl;
33375 int i;
33376
33377 + pax_track_stack();
33378 +
33379 /* Check for Promiscuous and All Multicast modes */
33380
33381 rctl = IXGB_READ_REG(hw, RCTL);
33382 diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
33383 index dd7fbeb..44b9bbf 100644
33384 --- a/drivers/net/ixgb/ixgb_param.c
33385 +++ b/drivers/net/ixgb/ixgb_param.c
33386 @@ -261,6 +261,9 @@ void __devinit
33387 ixgb_check_options(struct ixgb_adapter *adapter)
33388 {
33389 int bd = adapter->bd_number;
33390 +
33391 + pax_track_stack();
33392 +
33393 if (bd >= IXGB_MAX_NIC) {
33394 pr_notice("Warning: no configuration for board #%i\n", bd);
33395 pr_notice("Using defaults for all values\n");
33396 diff --git a/drivers/net/ixgbe/ixgbe_type.h b/drivers/net/ixgbe/ixgbe_type.h
33397 index e0d970e..1cfdea5 100644
33398 --- a/drivers/net/ixgbe/ixgbe_type.h
33399 +++ b/drivers/net/ixgbe/ixgbe_type.h
33400 @@ -2642,6 +2642,7 @@ struct ixgbe_eeprom_operations {
33401 s32 (*update_checksum)(struct ixgbe_hw *);
33402 u16 (*calc_checksum)(struct ixgbe_hw *);
33403 };
33404 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
33405
33406 struct ixgbe_mac_operations {
33407 s32 (*init_hw)(struct ixgbe_hw *);
33408 @@ -2703,6 +2704,7 @@ struct ixgbe_mac_operations {
33409 /* Manageability interface */
33410 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
33411 };
33412 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
33413
33414 struct ixgbe_phy_operations {
33415 s32 (*identify)(struct ixgbe_hw *);
33416 @@ -2722,9 +2724,10 @@ struct ixgbe_phy_operations {
33417 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
33418 s32 (*check_overtemp)(struct ixgbe_hw *);
33419 };
33420 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
33421
33422 struct ixgbe_eeprom_info {
33423 - struct ixgbe_eeprom_operations ops;
33424 + ixgbe_eeprom_operations_no_const ops;
33425 enum ixgbe_eeprom_type type;
33426 u32 semaphore_delay;
33427 u16 word_size;
33428 @@ -2734,7 +2737,7 @@ struct ixgbe_eeprom_info {
33429
33430 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
33431 struct ixgbe_mac_info {
33432 - struct ixgbe_mac_operations ops;
33433 + ixgbe_mac_operations_no_const ops;
33434 enum ixgbe_mac_type type;
33435 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
33436 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
33437 @@ -2762,7 +2765,7 @@ struct ixgbe_mac_info {
33438 };
33439
33440 struct ixgbe_phy_info {
33441 - struct ixgbe_phy_operations ops;
33442 + ixgbe_phy_operations_no_const ops;
33443 struct mdio_if_info mdio;
33444 enum ixgbe_phy_type type;
33445 u32 id;
33446 @@ -2790,6 +2793,7 @@ struct ixgbe_mbx_operations {
33447 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
33448 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
33449 };
33450 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
33451
33452 struct ixgbe_mbx_stats {
33453 u32 msgs_tx;
33454 @@ -2801,7 +2805,7 @@ struct ixgbe_mbx_stats {
33455 };
33456
33457 struct ixgbe_mbx_info {
33458 - struct ixgbe_mbx_operations ops;
33459 + ixgbe_mbx_operations_no_const ops;
33460 struct ixgbe_mbx_stats stats;
33461 u32 timeout;
33462 u32 usec_delay;
33463 diff --git a/drivers/net/ixgbevf/vf.h b/drivers/net/ixgbevf/vf.h
33464 index 10306b4..28df758 100644
33465 --- a/drivers/net/ixgbevf/vf.h
33466 +++ b/drivers/net/ixgbevf/vf.h
33467 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
33468 s32 (*clear_vfta)(struct ixgbe_hw *);
33469 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
33470 };
33471 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
33472
33473 enum ixgbe_mac_type {
33474 ixgbe_mac_unknown = 0,
33475 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
33476 };
33477
33478 struct ixgbe_mac_info {
33479 - struct ixgbe_mac_operations ops;
33480 + ixgbe_mac_operations_no_const ops;
33481 u8 addr[6];
33482 u8 perm_addr[6];
33483
33484 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
33485 s32 (*check_for_ack)(struct ixgbe_hw *);
33486 s32 (*check_for_rst)(struct ixgbe_hw *);
33487 };
33488 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
33489
33490 struct ixgbe_mbx_stats {
33491 u32 msgs_tx;
33492 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
33493 };
33494
33495 struct ixgbe_mbx_info {
33496 - struct ixgbe_mbx_operations ops;
33497 + ixgbe_mbx_operations_no_const ops;
33498 struct ixgbe_mbx_stats stats;
33499 u32 timeout;
33500 u32 udelay;
33501 diff --git a/drivers/net/ksz884x.c b/drivers/net/ksz884x.c
33502 index 27418d3..adf15bb 100644
33503 --- a/drivers/net/ksz884x.c
33504 +++ b/drivers/net/ksz884x.c
33505 @@ -6533,6 +6533,8 @@ static void netdev_get_ethtool_stats(struct net_device *dev,
33506 int rc;
33507 u64 counter[TOTAL_PORT_COUNTER_NUM];
33508
33509 + pax_track_stack();
33510 +
33511 mutex_lock(&hw_priv->lock);
33512 n = SWITCH_PORT_NUM;
33513 for (i = 0, p = port->first_port; i < port->mib_port_cnt; i++, p++) {
33514 diff --git a/drivers/net/mlx4/main.c b/drivers/net/mlx4/main.c
33515 index f0ee35d..3831c8a 100644
33516 --- a/drivers/net/mlx4/main.c
33517 +++ b/drivers/net/mlx4/main.c
33518 @@ -40,6 +40,7 @@
33519 #include <linux/dma-mapping.h>
33520 #include <linux/slab.h>
33521 #include <linux/io-mapping.h>
33522 +#include <linux/sched.h>
33523
33524 #include <linux/mlx4/device.h>
33525 #include <linux/mlx4/doorbell.h>
33526 @@ -762,6 +763,8 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
33527 u64 icm_size;
33528 int err;
33529
33530 + pax_track_stack();
33531 +
33532 err = mlx4_QUERY_FW(dev);
33533 if (err) {
33534 if (err == -EACCES)
33535 diff --git a/drivers/net/niu.c b/drivers/net/niu.c
33536 index ed47585..5e5be8f 100644
33537 --- a/drivers/net/niu.c
33538 +++ b/drivers/net/niu.c
33539 @@ -9061,6 +9061,8 @@ static void __devinit niu_try_msix(struct niu *np, u8 *ldg_num_map)
33540 int i, num_irqs, err;
33541 u8 first_ldg;
33542
33543 + pax_track_stack();
33544 +
33545 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
33546 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
33547 ldg_num_map[i] = first_ldg + i;
33548 diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
33549 index 80b6f36..5cd8938 100644
33550 --- a/drivers/net/pcnet32.c
33551 +++ b/drivers/net/pcnet32.c
33552 @@ -270,7 +270,7 @@ struct pcnet32_private {
33553 struct sk_buff **rx_skbuff;
33554 dma_addr_t *tx_dma_addr;
33555 dma_addr_t *rx_dma_addr;
33556 - struct pcnet32_access a;
33557 + struct pcnet32_access *a;
33558 spinlock_t lock; /* Guard lock */
33559 unsigned int cur_rx, cur_tx; /* The next free ring entry */
33560 unsigned int rx_ring_size; /* current rx ring size */
33561 @@ -460,9 +460,9 @@ static void pcnet32_netif_start(struct net_device *dev)
33562 u16 val;
33563
33564 netif_wake_queue(dev);
33565 - val = lp->a.read_csr(ioaddr, CSR3);
33566 + val = lp->a->read_csr(ioaddr, CSR3);
33567 val &= 0x00ff;
33568 - lp->a.write_csr(ioaddr, CSR3, val);
33569 + lp->a->write_csr(ioaddr, CSR3, val);
33570 napi_enable(&lp->napi);
33571 }
33572
33573 @@ -730,7 +730,7 @@ static u32 pcnet32_get_link(struct net_device *dev)
33574 r = mii_link_ok(&lp->mii_if);
33575 } else if (lp->chip_version >= PCNET32_79C970A) {
33576 ulong ioaddr = dev->base_addr; /* card base I/O address */
33577 - r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
33578 + r = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
33579 } else { /* can not detect link on really old chips */
33580 r = 1;
33581 }
33582 @@ -792,7 +792,7 @@ static int pcnet32_set_ringparam(struct net_device *dev,
33583 pcnet32_netif_stop(dev);
33584
33585 spin_lock_irqsave(&lp->lock, flags);
33586 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
33587 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
33588
33589 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
33590
33591 @@ -868,7 +868,7 @@ static void pcnet32_ethtool_test(struct net_device *dev,
33592 static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
33593 {
33594 struct pcnet32_private *lp = netdev_priv(dev);
33595 - struct pcnet32_access *a = &lp->a; /* access to registers */
33596 + struct pcnet32_access *a = lp->a; /* access to registers */
33597 ulong ioaddr = dev->base_addr; /* card base I/O address */
33598 struct sk_buff *skb; /* sk buff */
33599 int x, i; /* counters */
33600 @@ -888,21 +888,21 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
33601 pcnet32_netif_stop(dev);
33602
33603 spin_lock_irqsave(&lp->lock, flags);
33604 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
33605 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
33606
33607 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
33608
33609 /* Reset the PCNET32 */
33610 - lp->a.reset(ioaddr);
33611 - lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
33612 + lp->a->reset(ioaddr);
33613 + lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
33614
33615 /* switch pcnet32 to 32bit mode */
33616 - lp->a.write_bcr(ioaddr, 20, 2);
33617 + lp->a->write_bcr(ioaddr, 20, 2);
33618
33619 /* purge & init rings but don't actually restart */
33620 pcnet32_restart(dev, 0x0000);
33621
33622 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
33623 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
33624
33625 /* Initialize Transmit buffers. */
33626 size = data_len + 15;
33627 @@ -947,10 +947,10 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
33628
33629 /* set int loopback in CSR15 */
33630 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
33631 - lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
33632 + lp->a->write_csr(ioaddr, CSR15, x | 0x0044);
33633
33634 teststatus = cpu_to_le16(0x8000);
33635 - lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
33636 + lp->a->write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
33637
33638 /* Check status of descriptors */
33639 for (x = 0; x < numbuffs; x++) {
33640 @@ -969,7 +969,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
33641 }
33642 }
33643
33644 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
33645 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
33646 wmb();
33647 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
33648 netdev_printk(KERN_DEBUG, dev, "RX loopback packets:\n");
33649 @@ -1015,7 +1015,7 @@ clean_up:
33650 pcnet32_restart(dev, CSR0_NORMAL);
33651 } else {
33652 pcnet32_purge_rx_ring(dev);
33653 - lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
33654 + lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
33655 }
33656 spin_unlock_irqrestore(&lp->lock, flags);
33657
33658 @@ -1026,7 +1026,7 @@ static int pcnet32_set_phys_id(struct net_device *dev,
33659 enum ethtool_phys_id_state state)
33660 {
33661 struct pcnet32_private *lp = netdev_priv(dev);
33662 - struct pcnet32_access *a = &lp->a;
33663 + struct pcnet32_access *a = lp->a;
33664 ulong ioaddr = dev->base_addr;
33665 unsigned long flags;
33666 int i;
33667 @@ -1067,7 +1067,7 @@ static int pcnet32_suspend(struct net_device *dev, unsigned long *flags,
33668 {
33669 int csr5;
33670 struct pcnet32_private *lp = netdev_priv(dev);
33671 - struct pcnet32_access *a = &lp->a;
33672 + struct pcnet32_access *a = lp->a;
33673 ulong ioaddr = dev->base_addr;
33674 int ticks;
33675
33676 @@ -1324,8 +1324,8 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
33677 spin_lock_irqsave(&lp->lock, flags);
33678 if (pcnet32_tx(dev)) {
33679 /* reset the chip to clear the error condition, then restart */
33680 - lp->a.reset(ioaddr);
33681 - lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
33682 + lp->a->reset(ioaddr);
33683 + lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
33684 pcnet32_restart(dev, CSR0_START);
33685 netif_wake_queue(dev);
33686 }
33687 @@ -1337,12 +1337,12 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
33688 __napi_complete(napi);
33689
33690 /* clear interrupt masks */
33691 - val = lp->a.read_csr(ioaddr, CSR3);
33692 + val = lp->a->read_csr(ioaddr, CSR3);
33693 val &= 0x00ff;
33694 - lp->a.write_csr(ioaddr, CSR3, val);
33695 + lp->a->write_csr(ioaddr, CSR3, val);
33696
33697 /* Set interrupt enable. */
33698 - lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
33699 + lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN);
33700
33701 spin_unlock_irqrestore(&lp->lock, flags);
33702 }
33703 @@ -1365,7 +1365,7 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
33704 int i, csr0;
33705 u16 *buff = ptr;
33706 struct pcnet32_private *lp = netdev_priv(dev);
33707 - struct pcnet32_access *a = &lp->a;
33708 + struct pcnet32_access *a = lp->a;
33709 ulong ioaddr = dev->base_addr;
33710 unsigned long flags;
33711
33712 @@ -1401,9 +1401,9 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
33713 for (j = 0; j < PCNET32_MAX_PHYS; j++) {
33714 if (lp->phymask & (1 << j)) {
33715 for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
33716 - lp->a.write_bcr(ioaddr, 33,
33717 + lp->a->write_bcr(ioaddr, 33,
33718 (j << 5) | i);
33719 - *buff++ = lp->a.read_bcr(ioaddr, 34);
33720 + *buff++ = lp->a->read_bcr(ioaddr, 34);
33721 }
33722 }
33723 }
33724 @@ -1785,7 +1785,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
33725 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
33726 lp->options |= PCNET32_PORT_FD;
33727
33728 - lp->a = *a;
33729 + lp->a = a;
33730
33731 /* prior to register_netdev, dev->name is not yet correct */
33732 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
33733 @@ -1844,7 +1844,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
33734 if (lp->mii) {
33735 /* lp->phycount and lp->phymask are set to 0 by memset above */
33736
33737 - lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
33738 + lp->mii_if.phy_id = ((lp->a->read_bcr(ioaddr, 33)) >> 5) & 0x1f;
33739 /* scan for PHYs */
33740 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
33741 unsigned short id1, id2;
33742 @@ -1864,7 +1864,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
33743 pr_info("Found PHY %04x:%04x at address %d\n",
33744 id1, id2, i);
33745 }
33746 - lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
33747 + lp->a->write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
33748 if (lp->phycount > 1)
33749 lp->options |= PCNET32_PORT_MII;
33750 }
33751 @@ -2020,10 +2020,10 @@ static int pcnet32_open(struct net_device *dev)
33752 }
33753
33754 /* Reset the PCNET32 */
33755 - lp->a.reset(ioaddr);
33756 + lp->a->reset(ioaddr);
33757
33758 /* switch pcnet32 to 32bit mode */
33759 - lp->a.write_bcr(ioaddr, 20, 2);
33760 + lp->a->write_bcr(ioaddr, 20, 2);
33761
33762 netif_printk(lp, ifup, KERN_DEBUG, dev,
33763 "%s() irq %d tx/rx rings %#x/%#x init %#x\n",
33764 @@ -2032,14 +2032,14 @@ static int pcnet32_open(struct net_device *dev)
33765 (u32) (lp->init_dma_addr));
33766
33767 /* set/reset autoselect bit */
33768 - val = lp->a.read_bcr(ioaddr, 2) & ~2;
33769 + val = lp->a->read_bcr(ioaddr, 2) & ~2;
33770 if (lp->options & PCNET32_PORT_ASEL)
33771 val |= 2;
33772 - lp->a.write_bcr(ioaddr, 2, val);
33773 + lp->a->write_bcr(ioaddr, 2, val);
33774
33775 /* handle full duplex setting */
33776 if (lp->mii_if.full_duplex) {
33777 - val = lp->a.read_bcr(ioaddr, 9) & ~3;
33778 + val = lp->a->read_bcr(ioaddr, 9) & ~3;
33779 if (lp->options & PCNET32_PORT_FD) {
33780 val |= 1;
33781 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
33782 @@ -2049,14 +2049,14 @@ static int pcnet32_open(struct net_device *dev)
33783 if (lp->chip_version == 0x2627)
33784 val |= 3;
33785 }
33786 - lp->a.write_bcr(ioaddr, 9, val);
33787 + lp->a->write_bcr(ioaddr, 9, val);
33788 }
33789
33790 /* set/reset GPSI bit in test register */
33791 - val = lp->a.read_csr(ioaddr, 124) & ~0x10;
33792 + val = lp->a->read_csr(ioaddr, 124) & ~0x10;
33793 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
33794 val |= 0x10;
33795 - lp->a.write_csr(ioaddr, 124, val);
33796 + lp->a->write_csr(ioaddr, 124, val);
33797
33798 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
33799 if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT &&
33800 @@ -2075,24 +2075,24 @@ static int pcnet32_open(struct net_device *dev)
33801 * duplex, and/or enable auto negotiation, and clear DANAS
33802 */
33803 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
33804 - lp->a.write_bcr(ioaddr, 32,
33805 - lp->a.read_bcr(ioaddr, 32) | 0x0080);
33806 + lp->a->write_bcr(ioaddr, 32,
33807 + lp->a->read_bcr(ioaddr, 32) | 0x0080);
33808 /* disable Auto Negotiation, set 10Mpbs, HD */
33809 - val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
33810 + val = lp->a->read_bcr(ioaddr, 32) & ~0xb8;
33811 if (lp->options & PCNET32_PORT_FD)
33812 val |= 0x10;
33813 if (lp->options & PCNET32_PORT_100)
33814 val |= 0x08;
33815 - lp->a.write_bcr(ioaddr, 32, val);
33816 + lp->a->write_bcr(ioaddr, 32, val);
33817 } else {
33818 if (lp->options & PCNET32_PORT_ASEL) {
33819 - lp->a.write_bcr(ioaddr, 32,
33820 - lp->a.read_bcr(ioaddr,
33821 + lp->a->write_bcr(ioaddr, 32,
33822 + lp->a->read_bcr(ioaddr,
33823 32) | 0x0080);
33824 /* enable auto negotiate, setup, disable fd */
33825 - val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
33826 + val = lp->a->read_bcr(ioaddr, 32) & ~0x98;
33827 val |= 0x20;
33828 - lp->a.write_bcr(ioaddr, 32, val);
33829 + lp->a->write_bcr(ioaddr, 32, val);
33830 }
33831 }
33832 } else {
33833 @@ -2105,10 +2105,10 @@ static int pcnet32_open(struct net_device *dev)
33834 * There is really no good other way to handle multiple PHYs
33835 * other than turning off all automatics
33836 */
33837 - val = lp->a.read_bcr(ioaddr, 2);
33838 - lp->a.write_bcr(ioaddr, 2, val & ~2);
33839 - val = lp->a.read_bcr(ioaddr, 32);
33840 - lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
33841 + val = lp->a->read_bcr(ioaddr, 2);
33842 + lp->a->write_bcr(ioaddr, 2, val & ~2);
33843 + val = lp->a->read_bcr(ioaddr, 32);
33844 + lp->a->write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
33845
33846 if (!(lp->options & PCNET32_PORT_ASEL)) {
33847 /* setup ecmd */
33848 @@ -2118,7 +2118,7 @@ static int pcnet32_open(struct net_device *dev)
33849 ethtool_cmd_speed_set(&ecmd,
33850 (lp->options & PCNET32_PORT_100) ?
33851 SPEED_100 : SPEED_10);
33852 - bcr9 = lp->a.read_bcr(ioaddr, 9);
33853 + bcr9 = lp->a->read_bcr(ioaddr, 9);
33854
33855 if (lp->options & PCNET32_PORT_FD) {
33856 ecmd.duplex = DUPLEX_FULL;
33857 @@ -2127,7 +2127,7 @@ static int pcnet32_open(struct net_device *dev)
33858 ecmd.duplex = DUPLEX_HALF;
33859 bcr9 |= ~(1 << 0);
33860 }
33861 - lp->a.write_bcr(ioaddr, 9, bcr9);
33862 + lp->a->write_bcr(ioaddr, 9, bcr9);
33863 }
33864
33865 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
33866 @@ -2158,9 +2158,9 @@ static int pcnet32_open(struct net_device *dev)
33867
33868 #ifdef DO_DXSUFLO
33869 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
33870 - val = lp->a.read_csr(ioaddr, CSR3);
33871 + val = lp->a->read_csr(ioaddr, CSR3);
33872 val |= 0x40;
33873 - lp->a.write_csr(ioaddr, CSR3, val);
33874 + lp->a->write_csr(ioaddr, CSR3, val);
33875 }
33876 #endif
33877
33878 @@ -2176,11 +2176,11 @@ static int pcnet32_open(struct net_device *dev)
33879 napi_enable(&lp->napi);
33880
33881 /* Re-initialize the PCNET32, and start it when done. */
33882 - lp->a.write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
33883 - lp->a.write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
33884 + lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
33885 + lp->a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
33886
33887 - lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
33888 - lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
33889 + lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
33890 + lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
33891
33892 netif_start_queue(dev);
33893
33894 @@ -2192,19 +2192,19 @@ static int pcnet32_open(struct net_device *dev)
33895
33896 i = 0;
33897 while (i++ < 100)
33898 - if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
33899 + if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
33900 break;
33901 /*
33902 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
33903 * reports that doing so triggers a bug in the '974.
33904 */
33905 - lp->a.write_csr(ioaddr, CSR0, CSR0_NORMAL);
33906 + lp->a->write_csr(ioaddr, CSR0, CSR0_NORMAL);
33907
33908 netif_printk(lp, ifup, KERN_DEBUG, dev,
33909 "pcnet32 open after %d ticks, init block %#x csr0 %4.4x\n",
33910 i,
33911 (u32) (lp->init_dma_addr),
33912 - lp->a.read_csr(ioaddr, CSR0));
33913 + lp->a->read_csr(ioaddr, CSR0));
33914
33915 spin_unlock_irqrestore(&lp->lock, flags);
33916
33917 @@ -2218,7 +2218,7 @@ err_free_ring:
33918 * Switch back to 16bit mode to avoid problems with dumb
33919 * DOS packet driver after a warm reboot
33920 */
33921 - lp->a.write_bcr(ioaddr, 20, 4);
33922 + lp->a->write_bcr(ioaddr, 20, 4);
33923
33924 err_free_irq:
33925 spin_unlock_irqrestore(&lp->lock, flags);
33926 @@ -2323,7 +2323,7 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
33927
33928 /* wait for stop */
33929 for (i = 0; i < 100; i++)
33930 - if (lp->a.read_csr(ioaddr, CSR0) & CSR0_STOP)
33931 + if (lp->a->read_csr(ioaddr, CSR0) & CSR0_STOP)
33932 break;
33933
33934 if (i >= 100)
33935 @@ -2335,13 +2335,13 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
33936 return;
33937
33938 /* ReInit Ring */
33939 - lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
33940 + lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
33941 i = 0;
33942 while (i++ < 1000)
33943 - if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
33944 + if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
33945 break;
33946
33947 - lp->a.write_csr(ioaddr, CSR0, csr0_bits);
33948 + lp->a->write_csr(ioaddr, CSR0, csr0_bits);
33949 }
33950
33951 static void pcnet32_tx_timeout(struct net_device *dev)
33952 @@ -2353,8 +2353,8 @@ static void pcnet32_tx_timeout(struct net_device *dev)
33953 /* Transmitter timeout, serious problems. */
33954 if (pcnet32_debug & NETIF_MSG_DRV)
33955 pr_err("%s: transmit timed out, status %4.4x, resetting\n",
33956 - dev->name, lp->a.read_csr(ioaddr, CSR0));
33957 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
33958 + dev->name, lp->a->read_csr(ioaddr, CSR0));
33959 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
33960 dev->stats.tx_errors++;
33961 if (netif_msg_tx_err(lp)) {
33962 int i;
33963 @@ -2397,7 +2397,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
33964
33965 netif_printk(lp, tx_queued, KERN_DEBUG, dev,
33966 "%s() called, csr0 %4.4x\n",
33967 - __func__, lp->a.read_csr(ioaddr, CSR0));
33968 + __func__, lp->a->read_csr(ioaddr, CSR0));
33969
33970 /* Default status -- will not enable Successful-TxDone
33971 * interrupt when that option is available to us.
33972 @@ -2427,7 +2427,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
33973 dev->stats.tx_bytes += skb->len;
33974
33975 /* Trigger an immediate send poll. */
33976 - lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
33977 + lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
33978
33979 if (lp->tx_ring[(entry + 1) & lp->tx_mod_mask].base != 0) {
33980 lp->tx_full = 1;
33981 @@ -2452,16 +2452,16 @@ pcnet32_interrupt(int irq, void *dev_id)
33982
33983 spin_lock(&lp->lock);
33984
33985 - csr0 = lp->a.read_csr(ioaddr, CSR0);
33986 + csr0 = lp->a->read_csr(ioaddr, CSR0);
33987 while ((csr0 & 0x8f00) && --boguscnt >= 0) {
33988 if (csr0 == 0xffff)
33989 break; /* PCMCIA remove happened */
33990 /* Acknowledge all of the current interrupt sources ASAP. */
33991 - lp->a.write_csr(ioaddr, CSR0, csr0 & ~0x004f);
33992 + lp->a->write_csr(ioaddr, CSR0, csr0 & ~0x004f);
33993
33994 netif_printk(lp, intr, KERN_DEBUG, dev,
33995 "interrupt csr0=%#2.2x new csr=%#2.2x\n",
33996 - csr0, lp->a.read_csr(ioaddr, CSR0));
33997 + csr0, lp->a->read_csr(ioaddr, CSR0));
33998
33999 /* Log misc errors. */
34000 if (csr0 & 0x4000)
34001 @@ -2488,19 +2488,19 @@ pcnet32_interrupt(int irq, void *dev_id)
34002 if (napi_schedule_prep(&lp->napi)) {
34003 u16 val;
34004 /* set interrupt masks */
34005 - val = lp->a.read_csr(ioaddr, CSR3);
34006 + val = lp->a->read_csr(ioaddr, CSR3);
34007 val |= 0x5f00;
34008 - lp->a.write_csr(ioaddr, CSR3, val);
34009 + lp->a->write_csr(ioaddr, CSR3, val);
34010
34011 __napi_schedule(&lp->napi);
34012 break;
34013 }
34014 - csr0 = lp->a.read_csr(ioaddr, CSR0);
34015 + csr0 = lp->a->read_csr(ioaddr, CSR0);
34016 }
34017
34018 netif_printk(lp, intr, KERN_DEBUG, dev,
34019 "exiting interrupt, csr0=%#4.4x\n",
34020 - lp->a.read_csr(ioaddr, CSR0));
34021 + lp->a->read_csr(ioaddr, CSR0));
34022
34023 spin_unlock(&lp->lock);
34024
34025 @@ -2520,20 +2520,20 @@ static int pcnet32_close(struct net_device *dev)
34026
34027 spin_lock_irqsave(&lp->lock, flags);
34028
34029 - dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
34030 + dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
34031
34032 netif_printk(lp, ifdown, KERN_DEBUG, dev,
34033 "Shutting down ethercard, status was %2.2x\n",
34034 - lp->a.read_csr(ioaddr, CSR0));
34035 + lp->a->read_csr(ioaddr, CSR0));
34036
34037 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
34038 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
34039 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
34040
34041 /*
34042 * Switch back to 16bit mode to avoid problems with dumb
34043 * DOS packet driver after a warm reboot
34044 */
34045 - lp->a.write_bcr(ioaddr, 20, 4);
34046 + lp->a->write_bcr(ioaddr, 20, 4);
34047
34048 spin_unlock_irqrestore(&lp->lock, flags);
34049
34050 @@ -2556,7 +2556,7 @@ static struct net_device_stats *pcnet32_get_stats(struct net_device *dev)
34051 unsigned long flags;
34052
34053 spin_lock_irqsave(&lp->lock, flags);
34054 - dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
34055 + dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
34056 spin_unlock_irqrestore(&lp->lock, flags);
34057
34058 return &dev->stats;
34059 @@ -2577,10 +2577,10 @@ static void pcnet32_load_multicast(struct net_device *dev)
34060 if (dev->flags & IFF_ALLMULTI) {
34061 ib->filter[0] = cpu_to_le32(~0U);
34062 ib->filter[1] = cpu_to_le32(~0U);
34063 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
34064 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
34065 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
34066 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
34067 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
34068 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
34069 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
34070 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
34071 return;
34072 }
34073 /* clear the multicast filter */
34074 @@ -2594,7 +2594,7 @@ static void pcnet32_load_multicast(struct net_device *dev)
34075 mcast_table[crc >> 4] |= cpu_to_le16(1 << (crc & 0xf));
34076 }
34077 for (i = 0; i < 4; i++)
34078 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
34079 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER + i,
34080 le16_to_cpu(mcast_table[i]));
34081 }
34082
34083 @@ -2609,28 +2609,28 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
34084
34085 spin_lock_irqsave(&lp->lock, flags);
34086 suspended = pcnet32_suspend(dev, &flags, 0);
34087 - csr15 = lp->a.read_csr(ioaddr, CSR15);
34088 + csr15 = lp->a->read_csr(ioaddr, CSR15);
34089 if (dev->flags & IFF_PROMISC) {
34090 /* Log any net taps. */
34091 netif_info(lp, hw, dev, "Promiscuous mode enabled\n");
34092 lp->init_block->mode =
34093 cpu_to_le16(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
34094 7);
34095 - lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
34096 + lp->a->write_csr(ioaddr, CSR15, csr15 | 0x8000);
34097 } else {
34098 lp->init_block->mode =
34099 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7);
34100 - lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
34101 + lp->a->write_csr(ioaddr, CSR15, csr15 & 0x7fff);
34102 pcnet32_load_multicast(dev);
34103 }
34104
34105 if (suspended) {
34106 int csr5;
34107 /* clear SUSPEND (SPND) - CSR5 bit 0 */
34108 - csr5 = lp->a.read_csr(ioaddr, CSR5);
34109 - lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
34110 + csr5 = lp->a->read_csr(ioaddr, CSR5);
34111 + lp->a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
34112 } else {
34113 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
34114 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
34115 pcnet32_restart(dev, CSR0_NORMAL);
34116 netif_wake_queue(dev);
34117 }
34118 @@ -2648,8 +2648,8 @@ static int mdio_read(struct net_device *dev, int phy_id, int reg_num)
34119 if (!lp->mii)
34120 return 0;
34121
34122 - lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
34123 - val_out = lp->a.read_bcr(ioaddr, 34);
34124 + lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
34125 + val_out = lp->a->read_bcr(ioaddr, 34);
34126
34127 return val_out;
34128 }
34129 @@ -2663,8 +2663,8 @@ static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val)
34130 if (!lp->mii)
34131 return;
34132
34133 - lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
34134 - lp->a.write_bcr(ioaddr, 34, val);
34135 + lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
34136 + lp->a->write_bcr(ioaddr, 34, val);
34137 }
34138
34139 static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34140 @@ -2741,7 +2741,7 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
34141 curr_link = mii_link_ok(&lp->mii_if);
34142 } else {
34143 ulong ioaddr = dev->base_addr; /* card base I/O address */
34144 - curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
34145 + curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
34146 }
34147 if (!curr_link) {
34148 if (prev_link || verbose) {
34149 @@ -2764,13 +2764,13 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
34150 (ecmd.duplex == DUPLEX_FULL)
34151 ? "full" : "half");
34152 }
34153 - bcr9 = lp->a.read_bcr(dev->base_addr, 9);
34154 + bcr9 = lp->a->read_bcr(dev->base_addr, 9);
34155 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
34156 if (lp->mii_if.full_duplex)
34157 bcr9 |= (1 << 0);
34158 else
34159 bcr9 &= ~(1 << 0);
34160 - lp->a.write_bcr(dev->base_addr, 9, bcr9);
34161 + lp->a->write_bcr(dev->base_addr, 9, bcr9);
34162 }
34163 } else {
34164 netif_info(lp, link, dev, "link up\n");
34165 diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
34166 index edfa15d..002bfa9 100644
34167 --- a/drivers/net/ppp_generic.c
34168 +++ b/drivers/net/ppp_generic.c
34169 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34170 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
34171 struct ppp_stats stats;
34172 struct ppp_comp_stats cstats;
34173 - char *vers;
34174
34175 switch (cmd) {
34176 case SIOCGPPPSTATS:
34177 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34178 break;
34179
34180 case SIOCGPPPVER:
34181 - vers = PPP_VERSION;
34182 - if (copy_to_user(addr, vers, strlen(vers) + 1))
34183 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
34184 break;
34185 err = 0;
34186 break;
34187 diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
34188 index 6d657ca..d1be94b 100644
34189 --- a/drivers/net/r8169.c
34190 +++ b/drivers/net/r8169.c
34191 @@ -663,12 +663,12 @@ struct rtl8169_private {
34192 struct mdio_ops {
34193 void (*write)(void __iomem *, int, int);
34194 int (*read)(void __iomem *, int);
34195 - } mdio_ops;
34196 + } __no_const mdio_ops;
34197
34198 struct pll_power_ops {
34199 void (*down)(struct rtl8169_private *);
34200 void (*up)(struct rtl8169_private *);
34201 - } pll_power_ops;
34202 + } __no_const pll_power_ops;
34203
34204 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
34205 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
34206 diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
34207 index 3c0f131..17f8b02 100644
34208 --- a/drivers/net/sis190.c
34209 +++ b/drivers/net/sis190.c
34210 @@ -1624,7 +1624,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
34211 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
34212 struct net_device *dev)
34213 {
34214 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
34215 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
34216 struct sis190_private *tp = netdev_priv(dev);
34217 struct pci_dev *isa_bridge;
34218 u8 reg, tmp8;
34219 diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
34220 index 4793df8..44c9849 100644
34221 --- a/drivers/net/sundance.c
34222 +++ b/drivers/net/sundance.c
34223 @@ -218,7 +218,7 @@ enum {
34224 struct pci_id_info {
34225 const char *name;
34226 };
34227 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34228 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34229 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34230 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34231 {"D-Link DFE-580TX 4 port Server Adapter"},
34232 diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
34233 index 2ea456d..3ad9523 100644
34234 --- a/drivers/net/tg3.h
34235 +++ b/drivers/net/tg3.h
34236 @@ -134,6 +134,7 @@
34237 #define CHIPREV_ID_5750_A0 0x4000
34238 #define CHIPREV_ID_5750_A1 0x4001
34239 #define CHIPREV_ID_5750_A3 0x4003
34240 +#define CHIPREV_ID_5750_C1 0x4201
34241 #define CHIPREV_ID_5750_C2 0x4202
34242 #define CHIPREV_ID_5752_A0_HW 0x5000
34243 #define CHIPREV_ID_5752_A0 0x6000
34244 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
34245 index 515f122..41dd273 100644
34246 --- a/drivers/net/tokenring/abyss.c
34247 +++ b/drivers/net/tokenring/abyss.c
34248 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
34249
34250 static int __init abyss_init (void)
34251 {
34252 - abyss_netdev_ops = tms380tr_netdev_ops;
34253 + pax_open_kernel();
34254 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34255
34256 - abyss_netdev_ops.ndo_open = abyss_open;
34257 - abyss_netdev_ops.ndo_stop = abyss_close;
34258 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
34259 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
34260 + pax_close_kernel();
34261
34262 return pci_register_driver(&abyss_driver);
34263 }
34264 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
34265 index 6153cfd..cf69c1c 100644
34266 --- a/drivers/net/tokenring/madgemc.c
34267 +++ b/drivers/net/tokenring/madgemc.c
34268 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
34269
34270 static int __init madgemc_init (void)
34271 {
34272 - madgemc_netdev_ops = tms380tr_netdev_ops;
34273 - madgemc_netdev_ops.ndo_open = madgemc_open;
34274 - madgemc_netdev_ops.ndo_stop = madgemc_close;
34275 + pax_open_kernel();
34276 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34277 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
34278 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
34279 + pax_close_kernel();
34280
34281 return mca_register_driver (&madgemc_driver);
34282 }
34283 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
34284 index 8d362e6..f91cc52 100644
34285 --- a/drivers/net/tokenring/proteon.c
34286 +++ b/drivers/net/tokenring/proteon.c
34287 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
34288 struct platform_device *pdev;
34289 int i, num = 0, err = 0;
34290
34291 - proteon_netdev_ops = tms380tr_netdev_ops;
34292 - proteon_netdev_ops.ndo_open = proteon_open;
34293 - proteon_netdev_ops.ndo_stop = tms380tr_close;
34294 + pax_open_kernel();
34295 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34296 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
34297 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
34298 + pax_close_kernel();
34299
34300 err = platform_driver_register(&proteon_driver);
34301 if (err)
34302 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
34303 index 46db5c5..37c1536 100644
34304 --- a/drivers/net/tokenring/skisa.c
34305 +++ b/drivers/net/tokenring/skisa.c
34306 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
34307 struct platform_device *pdev;
34308 int i, num = 0, err = 0;
34309
34310 - sk_isa_netdev_ops = tms380tr_netdev_ops;
34311 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
34312 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34313 + pax_open_kernel();
34314 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34315 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
34316 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34317 + pax_close_kernel();
34318
34319 err = platform_driver_register(&sk_isa_driver);
34320 if (err)
34321 diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
34322 index ce90efc..2676f89 100644
34323 --- a/drivers/net/tulip/de2104x.c
34324 +++ b/drivers/net/tulip/de2104x.c
34325 @@ -1795,6 +1795,8 @@ static void __devinit de21041_get_srom_info (struct de_private *de)
34326 struct de_srom_info_leaf *il;
34327 void *bufp;
34328
34329 + pax_track_stack();
34330 +
34331 /* download entire eeprom */
34332 for (i = 0; i < DE_EEPROM_WORDS; i++)
34333 ((__le16 *)ee_data)[i] =
34334 diff --git a/drivers/net/tulip/de4x5.c b/drivers/net/tulip/de4x5.c
34335 index 959b410..c97fac2 100644
34336 --- a/drivers/net/tulip/de4x5.c
34337 +++ b/drivers/net/tulip/de4x5.c
34338 @@ -5397,7 +5397,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34339 for (i=0; i<ETH_ALEN; i++) {
34340 tmp.addr[i] = dev->dev_addr[i];
34341 }
34342 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34343 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34344 break;
34345
34346 case DE4X5_SET_HWADDR: /* Set the hardware address */
34347 @@ -5437,7 +5437,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34348 spin_lock_irqsave(&lp->lock, flags);
34349 memcpy(&statbuf, &lp->pktStats, ioc->len);
34350 spin_unlock_irqrestore(&lp->lock, flags);
34351 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34352 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34353 return -EFAULT;
34354 break;
34355 }
34356 diff --git a/drivers/net/tulip/eeprom.c b/drivers/net/tulip/eeprom.c
34357 index fa5eee9..e074432 100644
34358 --- a/drivers/net/tulip/eeprom.c
34359 +++ b/drivers/net/tulip/eeprom.c
34360 @@ -81,7 +81,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34361 {NULL}};
34362
34363
34364 -static const char *block_name[] __devinitdata = {
34365 +static const char *block_name[] __devinitconst = {
34366 "21140 non-MII",
34367 "21140 MII PHY",
34368 "21142 Serial PHY",
34369 diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
34370 index 862eadf..3eee1e6 100644
34371 --- a/drivers/net/tulip/winbond-840.c
34372 +++ b/drivers/net/tulip/winbond-840.c
34373 @@ -236,7 +236,7 @@ struct pci_id_info {
34374 int drv_flags; /* Driver use, intended as capability flags. */
34375 };
34376
34377 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34378 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34379 { /* Sometime a Level-One switch card. */
34380 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34381 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34382 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
34383 index 304fe78..db112fa 100644
34384 --- a/drivers/net/usb/hso.c
34385 +++ b/drivers/net/usb/hso.c
34386 @@ -71,7 +71,7 @@
34387 #include <asm/byteorder.h>
34388 #include <linux/serial_core.h>
34389 #include <linux/serial.h>
34390 -
34391 +#include <asm/local.h>
34392
34393 #define MOD_AUTHOR "Option Wireless"
34394 #define MOD_DESCRIPTION "USB High Speed Option driver"
34395 @@ -257,7 +257,7 @@ struct hso_serial {
34396
34397 /* from usb_serial_port */
34398 struct tty_struct *tty;
34399 - int open_count;
34400 + local_t open_count;
34401 spinlock_t serial_lock;
34402
34403 int (*write_data) (struct hso_serial *serial);
34404 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
34405 struct urb *urb;
34406
34407 urb = serial->rx_urb[0];
34408 - if (serial->open_count > 0) {
34409 + if (local_read(&serial->open_count) > 0) {
34410 count = put_rxbuf_data(urb, serial);
34411 if (count == -1)
34412 return;
34413 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
34414 DUMP1(urb->transfer_buffer, urb->actual_length);
34415
34416 /* Anyone listening? */
34417 - if (serial->open_count == 0)
34418 + if (local_read(&serial->open_count) == 0)
34419 return;
34420
34421 if (status == 0) {
34422 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
34423 spin_unlock_irq(&serial->serial_lock);
34424
34425 /* check for port already opened, if not set the termios */
34426 - serial->open_count++;
34427 - if (serial->open_count == 1) {
34428 + if (local_inc_return(&serial->open_count) == 1) {
34429 serial->rx_state = RX_IDLE;
34430 /* Force default termio settings */
34431 _hso_serial_set_termios(tty, NULL);
34432 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
34433 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
34434 if (result) {
34435 hso_stop_serial_device(serial->parent);
34436 - serial->open_count--;
34437 + local_dec(&serial->open_count);
34438 kref_put(&serial->parent->ref, hso_serial_ref_free);
34439 }
34440 } else {
34441 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
34442
34443 /* reset the rts and dtr */
34444 /* do the actual close */
34445 - serial->open_count--;
34446 + local_dec(&serial->open_count);
34447
34448 - if (serial->open_count <= 0) {
34449 - serial->open_count = 0;
34450 + if (local_read(&serial->open_count) <= 0) {
34451 + local_set(&serial->open_count, 0);
34452 spin_lock_irq(&serial->serial_lock);
34453 if (serial->tty == tty) {
34454 serial->tty->driver_data = NULL;
34455 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
34456
34457 /* the actual setup */
34458 spin_lock_irqsave(&serial->serial_lock, flags);
34459 - if (serial->open_count)
34460 + if (local_read(&serial->open_count))
34461 _hso_serial_set_termios(tty, old);
34462 else
34463 tty->termios = old;
34464 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
34465 D1("Pending read interrupt on port %d\n", i);
34466 spin_lock(&serial->serial_lock);
34467 if (serial->rx_state == RX_IDLE &&
34468 - serial->open_count > 0) {
34469 + local_read(&serial->open_count) > 0) {
34470 /* Setup and send a ctrl req read on
34471 * port i */
34472 if (!serial->rx_urb_filled[0]) {
34473 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
34474 /* Start all serial ports */
34475 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
34476 if (serial_table[i] && (serial_table[i]->interface == iface)) {
34477 - if (dev2ser(serial_table[i])->open_count) {
34478 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
34479 result =
34480 hso_start_serial_device(serial_table[i], GFP_NOIO);
34481 hso_kick_transmit(dev2ser(serial_table[i]));
34482 diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
34483 index 27400ed..c796e05 100644
34484 --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
34485 +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
34486 @@ -601,8 +601,7 @@ vmxnet3_set_rss_indir(struct net_device *netdev,
34487 * Return with error code if any of the queue indices
34488 * is out of range
34489 */
34490 - if (p->ring_index[i] < 0 ||
34491 - p->ring_index[i] >= adapter->num_rx_queues)
34492 + if (p->ring_index[i] >= adapter->num_rx_queues)
34493 return -EINVAL;
34494 }
34495
34496 diff --git a/drivers/net/vxge/vxge-config.h b/drivers/net/vxge/vxge-config.h
34497 index dd36258..e47fd31 100644
34498 --- a/drivers/net/vxge/vxge-config.h
34499 +++ b/drivers/net/vxge/vxge-config.h
34500 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34501 void (*link_down)(struct __vxge_hw_device *devh);
34502 void (*crit_err)(struct __vxge_hw_device *devh,
34503 enum vxge_hw_event type, u64 ext_data);
34504 -};
34505 +} __no_const;
34506
34507 /*
34508 * struct __vxge_hw_blockpool_entry - Block private data structure
34509 diff --git a/drivers/net/vxge/vxge-main.c b/drivers/net/vxge/vxge-main.c
34510 index 178348a2..18bb433 100644
34511 --- a/drivers/net/vxge/vxge-main.c
34512 +++ b/drivers/net/vxge/vxge-main.c
34513 @@ -100,6 +100,8 @@ static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
34514 struct sk_buff *completed[NR_SKB_COMPLETED];
34515 int more;
34516
34517 + pax_track_stack();
34518 +
34519 do {
34520 more = 0;
34521 skb_ptr = completed;
34522 @@ -1915,6 +1917,8 @@ static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
34523 u8 mtable[256] = {0}; /* CPU to vpath mapping */
34524 int index;
34525
34526 + pax_track_stack();
34527 +
34528 /*
34529 * Filling
34530 * - itable with bucket numbers
34531 diff --git a/drivers/net/vxge/vxge-traffic.h b/drivers/net/vxge/vxge-traffic.h
34532 index 4a518a3..936b334 100644
34533 --- a/drivers/net/vxge/vxge-traffic.h
34534 +++ b/drivers/net/vxge/vxge-traffic.h
34535 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34536 struct vxge_hw_mempool_dma *dma_object,
34537 u32 index,
34538 u32 is_last);
34539 -};
34540 +} __no_const;
34541
34542 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34543 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34544 diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c
34545 index 56aeb01..547f71f 100644
34546 --- a/drivers/net/wan/hdlc_x25.c
34547 +++ b/drivers/net/wan/hdlc_x25.c
34548 @@ -134,16 +134,16 @@ static netdev_tx_t x25_xmit(struct sk_buff *skb, struct net_device *dev)
34549
34550 static int x25_open(struct net_device *dev)
34551 {
34552 - struct lapb_register_struct cb;
34553 + static struct lapb_register_struct cb = {
34554 + .connect_confirmation = x25_connected,
34555 + .connect_indication = x25_connected,
34556 + .disconnect_confirmation = x25_disconnected,
34557 + .disconnect_indication = x25_disconnected,
34558 + .data_indication = x25_data_indication,
34559 + .data_transmit = x25_data_transmit
34560 + };
34561 int result;
34562
34563 - cb.connect_confirmation = x25_connected;
34564 - cb.connect_indication = x25_connected;
34565 - cb.disconnect_confirmation = x25_disconnected;
34566 - cb.disconnect_indication = x25_disconnected;
34567 - cb.data_indication = x25_data_indication;
34568 - cb.data_transmit = x25_data_transmit;
34569 -
34570 result = lapb_register(dev, &cb);
34571 if (result != LAPB_OK)
34572 return result;
34573 diff --git a/drivers/net/wimax/i2400m/usb-fw.c b/drivers/net/wimax/i2400m/usb-fw.c
34574 index 1fda46c..f2858f2 100644
34575 --- a/drivers/net/wimax/i2400m/usb-fw.c
34576 +++ b/drivers/net/wimax/i2400m/usb-fw.c
34577 @@ -287,6 +287,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(struct i2400m *i2400m,
34578 int do_autopm = 1;
34579 DECLARE_COMPLETION_ONSTACK(notif_completion);
34580
34581 + pax_track_stack();
34582 +
34583 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
34584 i2400m, ack, ack_size);
34585 BUG_ON(_ack == i2400m->bm_ack_buf);
34586 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
34587 index e1b3e3c..e413f18 100644
34588 --- a/drivers/net/wireless/airo.c
34589 +++ b/drivers/net/wireless/airo.c
34590 @@ -3003,6 +3003,8 @@ static void airo_process_scan_results (struct airo_info *ai) {
34591 BSSListElement * loop_net;
34592 BSSListElement * tmp_net;
34593
34594 + pax_track_stack();
34595 +
34596 /* Blow away current list of scan results */
34597 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
34598 list_move_tail (&loop_net->list, &ai->network_free_list);
34599 @@ -3794,6 +3796,8 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
34600 WepKeyRid wkr;
34601 int rc;
34602
34603 + pax_track_stack();
34604 +
34605 memset( &mySsid, 0, sizeof( mySsid ) );
34606 kfree (ai->flash);
34607 ai->flash = NULL;
34608 @@ -4753,6 +4757,8 @@ static int proc_stats_rid_open( struct inode *inode,
34609 __le32 *vals = stats.vals;
34610 int len;
34611
34612 + pax_track_stack();
34613 +
34614 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
34615 return -ENOMEM;
34616 data = file->private_data;
34617 @@ -5476,6 +5482,8 @@ static int proc_BSSList_open( struct inode *inode, struct file *file ) {
34618 /* If doLoseSync is not 1, we won't do a Lose Sync */
34619 int doLoseSync = -1;
34620
34621 + pax_track_stack();
34622 +
34623 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
34624 return -ENOMEM;
34625 data = file->private_data;
34626 @@ -7181,6 +7189,8 @@ static int airo_get_aplist(struct net_device *dev,
34627 int i;
34628 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
34629
34630 + pax_track_stack();
34631 +
34632 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
34633 if (!qual)
34634 return -ENOMEM;
34635 @@ -7741,6 +7751,8 @@ static void airo_read_wireless_stats(struct airo_info *local)
34636 CapabilityRid cap_rid;
34637 __le32 *vals = stats_rid.vals;
34638
34639 + pax_track_stack();
34640 +
34641 /* Get stats out of the card */
34642 clear_bit(JOB_WSTATS, &local->jobs);
34643 if (local->power.event) {
34644 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
34645 index 17c4b56..00d836f 100644
34646 --- a/drivers/net/wireless/ath/ath.h
34647 +++ b/drivers/net/wireless/ath/ath.h
34648 @@ -121,6 +121,7 @@ struct ath_ops {
34649 void (*write_flush) (void *);
34650 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
34651 };
34652 +typedef struct ath_ops __no_const ath_ops_no_const;
34653
34654 struct ath_common;
34655 struct ath_bus_ops;
34656 diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
34657 index ccca724..7afbadc 100644
34658 --- a/drivers/net/wireless/ath/ath5k/debug.c
34659 +++ b/drivers/net/wireless/ath/ath5k/debug.c
34660 @@ -203,6 +203,8 @@ static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
34661 unsigned int v;
34662 u64 tsf;
34663
34664 + pax_track_stack();
34665 +
34666 v = ath5k_hw_reg_read(ah, AR5K_BEACON);
34667 len += snprintf(buf + len, sizeof(buf) - len,
34668 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
34669 @@ -321,6 +323,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
34670 unsigned int len = 0;
34671 unsigned int i;
34672
34673 + pax_track_stack();
34674 +
34675 len += snprintf(buf + len, sizeof(buf) - len,
34676 "DEBUG LEVEL: 0x%08x\n\n", ah->debug.level);
34677
34678 @@ -492,6 +496,8 @@ static ssize_t read_file_misc(struct file *file, char __user *user_buf,
34679 unsigned int len = 0;
34680 u32 filt = ath5k_hw_get_rx_filter(ah);
34681
34682 + pax_track_stack();
34683 +
34684 len += snprintf(buf + len, sizeof(buf) - len, "bssid-mask: %pM\n",
34685 ah->bssidmask);
34686 len += snprintf(buf + len, sizeof(buf) - len, "filter-flags: 0x%x ",
34687 @@ -548,6 +554,8 @@ static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
34688 unsigned int len = 0;
34689 int i;
34690
34691 + pax_track_stack();
34692 +
34693 len += snprintf(buf + len, sizeof(buf) - len,
34694 "RX\n---------------------\n");
34695 len += snprintf(buf + len, sizeof(buf) - len, "CRC\t%u\t(%u%%)\n",
34696 @@ -665,6 +673,8 @@ static ssize_t read_file_ani(struct file *file, char __user *user_buf,
34697 char buf[700];
34698 unsigned int len = 0;
34699
34700 + pax_track_stack();
34701 +
34702 len += snprintf(buf + len, sizeof(buf) - len,
34703 "HW has PHY error counters:\t%s\n",
34704 ah->ah_capabilities.cap_has_phyerr_counters ?
34705 @@ -829,6 +839,8 @@ static ssize_t read_file_queue(struct file *file, char __user *user_buf,
34706 struct ath5k_buf *bf, *bf0;
34707 int i, n;
34708
34709 + pax_track_stack();
34710 +
34711 len += snprintf(buf + len, sizeof(buf) - len,
34712 "available txbuffers: %d\n", ah->txbuf_len);
34713
34714 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
34715 index 7c2aaad..ad14dee 100644
34716 --- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
34717 +++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
34718 @@ -758,6 +758,8 @@ static void ar9003_hw_tx_iq_cal_post_proc(struct ath_hw *ah)
34719 int i, im, j;
34720 int nmeasurement;
34721
34722 + pax_track_stack();
34723 +
34724 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
34725 if (ah->txchainmask & (1 << i))
34726 num_chains++;
34727 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
34728 index f80d1d6..08b773d 100644
34729 --- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
34730 +++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
34731 @@ -406,6 +406,8 @@ static bool create_pa_curve(u32 *data_L, u32 *data_U, u32 *pa_table, u16 *gain)
34732 int theta_low_bin = 0;
34733 int i;
34734
34735 + pax_track_stack();
34736 +
34737 /* disregard any bin that contains <= 16 samples */
34738 thresh_accum_cnt = 16;
34739 scale_factor = 5;
34740 diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
34741 index d1eb896..8b67cd4 100644
34742 --- a/drivers/net/wireless/ath/ath9k/debug.c
34743 +++ b/drivers/net/wireless/ath/ath9k/debug.c
34744 @@ -387,6 +387,8 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
34745 char buf[512];
34746 unsigned int len = 0;
34747
34748 + pax_track_stack();
34749 +
34750 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
34751 len += snprintf(buf + len, sizeof(buf) - len,
34752 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
34753 @@ -477,6 +479,8 @@ static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
34754 u8 addr[ETH_ALEN];
34755 u32 tmp;
34756
34757 + pax_track_stack();
34758 +
34759 len += snprintf(buf + len, sizeof(buf) - len,
34760 "%s (chan=%d center-freq: %d MHz channel-type: %d (%s))\n",
34761 wiphy_name(sc->hw->wiphy),
34762 diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
34763 index d3ff33c..309398e 100644
34764 --- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
34765 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
34766 @@ -31,6 +31,8 @@ static ssize_t read_file_tgt_int_stats(struct file *file, char __user *user_buf,
34767 unsigned int len = 0;
34768 int ret = 0;
34769
34770 + pax_track_stack();
34771 +
34772 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
34773
34774 ath9k_htc_ps_wakeup(priv);
34775 @@ -89,6 +91,8 @@ static ssize_t read_file_tgt_tx_stats(struct file *file, char __user *user_buf,
34776 unsigned int len = 0;
34777 int ret = 0;
34778
34779 + pax_track_stack();
34780 +
34781 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
34782
34783 ath9k_htc_ps_wakeup(priv);
34784 @@ -159,6 +163,8 @@ static ssize_t read_file_tgt_rx_stats(struct file *file, char __user *user_buf,
34785 unsigned int len = 0;
34786 int ret = 0;
34787
34788 + pax_track_stack();
34789 +
34790 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
34791
34792 ath9k_htc_ps_wakeup(priv);
34793 @@ -203,6 +209,8 @@ static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
34794 char buf[512];
34795 unsigned int len = 0;
34796
34797 + pax_track_stack();
34798 +
34799 len += snprintf(buf + len, sizeof(buf) - len,
34800 "%20s : %10u\n", "Buffers queued",
34801 priv->debug.tx_stats.buf_queued);
34802 @@ -376,6 +384,8 @@ static ssize_t read_file_slot(struct file *file, char __user *user_buf,
34803 char buf[512];
34804 unsigned int len = 0;
34805
34806 + pax_track_stack();
34807 +
34808 spin_lock_bh(&priv->tx.tx_lock);
34809
34810 len += snprintf(buf + len, sizeof(buf) - len, "TX slot bitmap : ");
34811 @@ -411,6 +421,8 @@ static ssize_t read_file_queue(struct file *file, char __user *user_buf,
34812 char buf[512];
34813 unsigned int len = 0;
34814
34815 + pax_track_stack();
34816 +
34817 len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
34818 "Mgmt endpoint", skb_queue_len(&priv->tx.mgmt_ep_queue));
34819
34820 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
34821 index c798890..c19a8fb 100644
34822 --- a/drivers/net/wireless/ath/ath9k/hw.h
34823 +++ b/drivers/net/wireless/ath/ath9k/hw.h
34824 @@ -588,7 +588,7 @@ struct ath_hw_private_ops {
34825
34826 /* ANI */
34827 void (*ani_cache_ini_regs)(struct ath_hw *ah);
34828 -};
34829 +} __no_const;
34830
34831 /**
34832 * struct ath_hw_ops - callbacks used by hardware code and driver code
34833 @@ -639,7 +639,7 @@ struct ath_hw_ops {
34834 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
34835 struct ath_hw_antcomb_conf *antconf);
34836
34837 -};
34838 +} __no_const;
34839
34840 struct ath_nf_limits {
34841 s16 max;
34842 @@ -652,7 +652,7 @@ struct ath_nf_limits {
34843 #define AH_UNPLUGGED 0x2 /* The card has been physically removed. */
34844
34845 struct ath_hw {
34846 - struct ath_ops reg_ops;
34847 + ath_ops_no_const reg_ops;
34848
34849 struct ieee80211_hw *hw;
34850 struct ath_common common;
34851 diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c
34852 index ef9ad79..f5f8d80 100644
34853 --- a/drivers/net/wireless/ipw2x00/ipw2100.c
34854 +++ b/drivers/net/wireless/ipw2x00/ipw2100.c
34855 @@ -2102,6 +2102,8 @@ static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
34856 int err;
34857 DECLARE_SSID_BUF(ssid);
34858
34859 + pax_track_stack();
34860 +
34861 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
34862
34863 if (ssid_len)
34864 @@ -5451,6 +5453,8 @@ static int ipw2100_set_key(struct ipw2100_priv *priv,
34865 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
34866 int err;
34867
34868 + pax_track_stack();
34869 +
34870 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
34871 idx, keylen, len);
34872
34873 diff --git a/drivers/net/wireless/ipw2x00/libipw_rx.c b/drivers/net/wireless/ipw2x00/libipw_rx.c
34874 index 32a9966..de69787 100644
34875 --- a/drivers/net/wireless/ipw2x00/libipw_rx.c
34876 +++ b/drivers/net/wireless/ipw2x00/libipw_rx.c
34877 @@ -1565,6 +1565,8 @@ static void libipw_process_probe_response(struct libipw_device
34878 unsigned long flags;
34879 DECLARE_SSID_BUF(ssid);
34880
34881 + pax_track_stack();
34882 +
34883 LIBIPW_DEBUG_SCAN("'%s' (%pM"
34884 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
34885 print_ssid(ssid, info_element->data, info_element->len),
34886 diff --git a/drivers/net/wireless/iwlegacy/iwl3945-base.c b/drivers/net/wireless/iwlegacy/iwl3945-base.c
34887 index 66ee1562..b90412b 100644
34888 --- a/drivers/net/wireless/iwlegacy/iwl3945-base.c
34889 +++ b/drivers/net/wireless/iwlegacy/iwl3945-base.c
34890 @@ -3687,7 +3687,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
34891 */
34892 if (iwl3945_mod_params.disable_hw_scan) {
34893 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
34894 - iwl3945_hw_ops.hw_scan = NULL;
34895 + pax_open_kernel();
34896 + *(void **)&iwl3945_hw_ops.hw_scan = NULL;
34897 + pax_close_kernel();
34898 }
34899
34900 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
34901 diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
34902 index 3789ff4..22ab151 100644
34903 --- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
34904 +++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
34905 @@ -920,6 +920,8 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
34906 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
34907 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
34908
34909 + pax_track_stack();
34910 +
34911 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
34912
34913 /* Treat uninitialized rate scaling data same as non-existing. */
34914 @@ -2931,6 +2933,8 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
34915 container_of(lq_sta, struct iwl_station_priv, lq_sta);
34916 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
34917
34918 + pax_track_stack();
34919 +
34920 /* Override starting rate (index 0) if needed for debug purposes */
34921 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
34922
34923 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
34924 index f9a407e..a6f2bb7 100644
34925 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
34926 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
34927 @@ -68,8 +68,8 @@ do { \
34928 } while (0)
34929
34930 #else
34931 -#define IWL_DEBUG(__priv, level, fmt, args...)
34932 -#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
34933 +#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
34934 +#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
34935 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
34936 const void *p, u32 len)
34937 {}
34938 diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
34939 index ec1485b..900c3bd 100644
34940 --- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
34941 +++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
34942 @@ -561,6 +561,8 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
34943 int pos = 0;
34944 const size_t bufsz = sizeof(buf);
34945
34946 + pax_track_stack();
34947 +
34948 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
34949 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
34950 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
34951 @@ -693,6 +695,8 @@ static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
34952 char buf[256 * NUM_IWL_RXON_CTX];
34953 const size_t bufsz = sizeof(buf);
34954
34955 + pax_track_stack();
34956 +
34957 for_each_context(priv, ctx) {
34958 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
34959 ctx->ctxid);
34960 diff --git a/drivers/net/wireless/iwmc3200wifi/debugfs.c b/drivers/net/wireless/iwmc3200wifi/debugfs.c
34961 index 0a0cc96..fd49ad8 100644
34962 --- a/drivers/net/wireless/iwmc3200wifi/debugfs.c
34963 +++ b/drivers/net/wireless/iwmc3200wifi/debugfs.c
34964 @@ -327,6 +327,8 @@ static ssize_t iwm_debugfs_fw_err_read(struct file *filp,
34965 int buf_len = 512;
34966 size_t len = 0;
34967
34968 + pax_track_stack();
34969 +
34970 if (*ppos != 0)
34971 return 0;
34972 if (count < sizeof(buf))
34973 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
34974 index 031cd89..bdc8435 100644
34975 --- a/drivers/net/wireless/mac80211_hwsim.c
34976 +++ b/drivers/net/wireless/mac80211_hwsim.c
34977 @@ -1670,9 +1670,11 @@ static int __init init_mac80211_hwsim(void)
34978 return -EINVAL;
34979
34980 if (fake_hw_scan) {
34981 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
34982 - mac80211_hwsim_ops.sw_scan_start = NULL;
34983 - mac80211_hwsim_ops.sw_scan_complete = NULL;
34984 + pax_open_kernel();
34985 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
34986 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
34987 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
34988 + pax_close_kernel();
34989 }
34990
34991 spin_lock_init(&hwsim_radio_lock);
34992 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
34993 index 2215c3c..64e6a47 100644
34994 --- a/drivers/net/wireless/mwifiex/main.h
34995 +++ b/drivers/net/wireless/mwifiex/main.h
34996 @@ -560,7 +560,7 @@ struct mwifiex_if_ops {
34997
34998 void (*update_mp_end_port) (struct mwifiex_adapter *, u16);
34999 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35000 -};
35001 +} __no_const;
35002
35003 struct mwifiex_adapter {
35004 struct mwifiex_private *priv[MWIFIEX_MAX_BSS_NUM];
35005 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35006 index 29f9389..f6d2ce0 100644
35007 --- a/drivers/net/wireless/rndis_wlan.c
35008 +++ b/drivers/net/wireless/rndis_wlan.c
35009 @@ -1277,7 +1277,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35010
35011 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35012
35013 - if (rts_threshold < 0 || rts_threshold > 2347)
35014 + if (rts_threshold > 2347)
35015 rts_threshold = 2347;
35016
35017 tmp = cpu_to_le32(rts_threshold);
35018 diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
35019 index 3b11642..d6bb049 100644
35020 --- a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
35021 +++ b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
35022 @@ -837,6 +837,8 @@ bool _rtl92c_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw,
35023 u8 rfpath;
35024 u8 num_total_rfpath = rtlphy->num_total_rfpath;
35025
35026 + pax_track_stack();
35027 +
35028 precommoncmdcnt = 0;
35029 _rtl92c_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
35030 MAX_PRECMD_CNT,
35031 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35032 index a77f1bb..c608b2b 100644
35033 --- a/drivers/net/wireless/wl1251/wl1251.h
35034 +++ b/drivers/net/wireless/wl1251/wl1251.h
35035 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35036 void (*reset)(struct wl1251 *wl);
35037 void (*enable_irq)(struct wl1251 *wl);
35038 void (*disable_irq)(struct wl1251 *wl);
35039 -};
35040 +} __no_const;
35041
35042 struct wl1251 {
35043 struct ieee80211_hw *hw;
35044 diff --git a/drivers/net/wireless/wl12xx/spi.c b/drivers/net/wireless/wl12xx/spi.c
35045 index e0b3736..4b466e6 100644
35046 --- a/drivers/net/wireless/wl12xx/spi.c
35047 +++ b/drivers/net/wireless/wl12xx/spi.c
35048 @@ -281,6 +281,8 @@ static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
35049 u32 chunk_len;
35050 int i;
35051
35052 + pax_track_stack();
35053 +
35054 WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
35055
35056 spi_message_init(&m);
35057 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35058 index f34b5b2..b5abb9f 100644
35059 --- a/drivers/oprofile/buffer_sync.c
35060 +++ b/drivers/oprofile/buffer_sync.c
35061 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35062 if (cookie == NO_COOKIE)
35063 offset = pc;
35064 if (cookie == INVALID_COOKIE) {
35065 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35066 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35067 offset = pc;
35068 }
35069 if (cookie != last_cookie) {
35070 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35071 /* add userspace sample */
35072
35073 if (!mm) {
35074 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35075 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35076 return 0;
35077 }
35078
35079 cookie = lookup_dcookie(mm, s->eip, &offset);
35080
35081 if (cookie == INVALID_COOKIE) {
35082 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35083 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35084 return 0;
35085 }
35086
35087 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35088 /* ignore backtraces if failed to add a sample */
35089 if (state == sb_bt_start) {
35090 state = sb_bt_ignore;
35091 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35092 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35093 }
35094 }
35095 release_mm(mm);
35096 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35097 index dd87e86..bc0148c 100644
35098 --- a/drivers/oprofile/event_buffer.c
35099 +++ b/drivers/oprofile/event_buffer.c
35100 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35101 }
35102
35103 if (buffer_pos == buffer_size) {
35104 - atomic_inc(&oprofile_stats.event_lost_overflow);
35105 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35106 return;
35107 }
35108
35109 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35110 index f8c752e..28bf4fc 100644
35111 --- a/drivers/oprofile/oprof.c
35112 +++ b/drivers/oprofile/oprof.c
35113 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35114 if (oprofile_ops.switch_events())
35115 return;
35116
35117 - atomic_inc(&oprofile_stats.multiplex_counter);
35118 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35119 start_switch_worker();
35120 }
35121
35122 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35123 index 917d28e..d62d981 100644
35124 --- a/drivers/oprofile/oprofile_stats.c
35125 +++ b/drivers/oprofile/oprofile_stats.c
35126 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35127 cpu_buf->sample_invalid_eip = 0;
35128 }
35129
35130 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35131 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35132 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35133 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35134 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35135 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35136 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35137 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35138 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35139 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35140 }
35141
35142
35143 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35144 index 38b6fc0..b5cbfce 100644
35145 --- a/drivers/oprofile/oprofile_stats.h
35146 +++ b/drivers/oprofile/oprofile_stats.h
35147 @@ -13,11 +13,11 @@
35148 #include <linux/atomic.h>
35149
35150 struct oprofile_stat_struct {
35151 - atomic_t sample_lost_no_mm;
35152 - atomic_t sample_lost_no_mapping;
35153 - atomic_t bt_lost_no_mapping;
35154 - atomic_t event_lost_overflow;
35155 - atomic_t multiplex_counter;
35156 + atomic_unchecked_t sample_lost_no_mm;
35157 + atomic_unchecked_t sample_lost_no_mapping;
35158 + atomic_unchecked_t bt_lost_no_mapping;
35159 + atomic_unchecked_t event_lost_overflow;
35160 + atomic_unchecked_t multiplex_counter;
35161 };
35162
35163 extern struct oprofile_stat_struct oprofile_stats;
35164 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35165 index 1c0b799..c11b2d2 100644
35166 --- a/drivers/oprofile/oprofilefs.c
35167 +++ b/drivers/oprofile/oprofilefs.c
35168 @@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
35169
35170
35171 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35172 - char const *name, atomic_t *val)
35173 + char const *name, atomic_unchecked_t *val)
35174 {
35175 return __oprofilefs_create_file(sb, root, name,
35176 &atomic_ro_fops, 0444, val);
35177 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35178 index 3f56bc0..707d642 100644
35179 --- a/drivers/parport/procfs.c
35180 +++ b/drivers/parport/procfs.c
35181 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35182
35183 *ppos += len;
35184
35185 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35186 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35187 }
35188
35189 #ifdef CONFIG_PARPORT_1284
35190 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35191
35192 *ppos += len;
35193
35194 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35195 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35196 }
35197 #endif /* IEEE1284.3 support. */
35198
35199 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35200 index 9fff878..ad0ad53 100644
35201 --- a/drivers/pci/hotplug/cpci_hotplug.h
35202 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35203 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35204 int (*hardware_test) (struct slot* slot, u32 value);
35205 u8 (*get_power) (struct slot* slot);
35206 int (*set_power) (struct slot* slot, int value);
35207 -};
35208 +} __no_const;
35209
35210 struct cpci_hp_controller {
35211 unsigned int irq;
35212 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35213 index 76ba8a1..20ca857 100644
35214 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35215 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35216 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35217
35218 void compaq_nvram_init (void __iomem *rom_start)
35219 {
35220 +
35221 +#ifndef CONFIG_PAX_KERNEXEC
35222 if (rom_start) {
35223 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35224 }
35225 +#endif
35226 +
35227 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35228
35229 /* initialize our int15 lock */
35230 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35231 index cbfbab1..6a9fced 100644
35232 --- a/drivers/pci/pcie/aspm.c
35233 +++ b/drivers/pci/pcie/aspm.c
35234 @@ -27,9 +27,9 @@
35235 #define MODULE_PARAM_PREFIX "pcie_aspm."
35236
35237 /* Note: those are not register definitions */
35238 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35239 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35240 -#define ASPM_STATE_L1 (4) /* L1 state */
35241 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35242 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35243 +#define ASPM_STATE_L1 (4U) /* L1 state */
35244 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35245 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35246
35247 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35248 index 6ab6bd3..72bdc69 100644
35249 --- a/drivers/pci/probe.c
35250 +++ b/drivers/pci/probe.c
35251 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35252 u32 l, sz, mask;
35253 u16 orig_cmd;
35254
35255 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35256 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35257
35258 if (!dev->mmio_always_on) {
35259 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35260 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35261 index 27911b5..5b6db88 100644
35262 --- a/drivers/pci/proc.c
35263 +++ b/drivers/pci/proc.c
35264 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35265 static int __init pci_proc_init(void)
35266 {
35267 struct pci_dev *dev = NULL;
35268 +
35269 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
35270 +#ifdef CONFIG_GRKERNSEC_PROC_USER
35271 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35272 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35273 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35274 +#endif
35275 +#else
35276 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35277 +#endif
35278 proc_create("devices", 0, proc_bus_pci_dir,
35279 &proc_bus_pci_dev_operations);
35280 proc_initialized = 1;
35281 diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
35282 index 90832a9..419089a 100644
35283 --- a/drivers/pci/xen-pcifront.c
35284 +++ b/drivers/pci/xen-pcifront.c
35285 @@ -187,6 +187,8 @@ static int pcifront_bus_read(struct pci_bus *bus, unsigned int devfn,
35286 struct pcifront_sd *sd = bus->sysdata;
35287 struct pcifront_device *pdev = pcifront_get_pdev(sd);
35288
35289 + pax_track_stack();
35290 +
35291 if (verbose_request)
35292 dev_info(&pdev->xdev->dev,
35293 "read dev=%04x:%02x:%02x.%01x - offset %x size %d\n",
35294 @@ -226,6 +228,8 @@ static int pcifront_bus_write(struct pci_bus *bus, unsigned int devfn,
35295 struct pcifront_sd *sd = bus->sysdata;
35296 struct pcifront_device *pdev = pcifront_get_pdev(sd);
35297
35298 + pax_track_stack();
35299 +
35300 if (verbose_request)
35301 dev_info(&pdev->xdev->dev,
35302 "write dev=%04x:%02x:%02x.%01x - "
35303 @@ -258,6 +262,8 @@ static int pci_frontend_enable_msix(struct pci_dev *dev,
35304 struct pcifront_device *pdev = pcifront_get_pdev(sd);
35305 struct msi_desc *entry;
35306
35307 + pax_track_stack();
35308 +
35309 if (nvec > SH_INFO_MAX_VEC) {
35310 dev_err(&dev->dev, "too much vector for pci frontend: %x."
35311 " Increase SH_INFO_MAX_VEC.\n", nvec);
35312 @@ -309,6 +315,8 @@ static void pci_frontend_disable_msix(struct pci_dev *dev)
35313 struct pcifront_sd *sd = dev->bus->sysdata;
35314 struct pcifront_device *pdev = pcifront_get_pdev(sd);
35315
35316 + pax_track_stack();
35317 +
35318 err = do_pci_op(pdev, &op);
35319
35320 /* What should do for error ? */
35321 @@ -328,6 +336,8 @@ static int pci_frontend_enable_msi(struct pci_dev *dev, int vector[])
35322 struct pcifront_sd *sd = dev->bus->sysdata;
35323 struct pcifront_device *pdev = pcifront_get_pdev(sd);
35324
35325 + pax_track_stack();
35326 +
35327 err = do_pci_op(pdev, &op);
35328 if (likely(!err)) {
35329 vector[0] = op.value;
35330 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35331 index 7bd829f..a3237ad 100644
35332 --- a/drivers/platform/x86/thinkpad_acpi.c
35333 +++ b/drivers/platform/x86/thinkpad_acpi.c
35334 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35335 return 0;
35336 }
35337
35338 -void static hotkey_mask_warn_incomplete_mask(void)
35339 +static void hotkey_mask_warn_incomplete_mask(void)
35340 {
35341 /* log only what the user can fix... */
35342 const u32 wantedmask = hotkey_driver_mask &
35343 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35344 }
35345 }
35346
35347 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35348 - struct tp_nvram_state *newn,
35349 - const u32 event_mask)
35350 -{
35351 -
35352 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35353 do { \
35354 if ((event_mask & (1 << __scancode)) && \
35355 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35356 tpacpi_hotkey_send_key(__scancode); \
35357 } while (0)
35358
35359 - void issue_volchange(const unsigned int oldvol,
35360 - const unsigned int newvol)
35361 - {
35362 - unsigned int i = oldvol;
35363 +static void issue_volchange(const unsigned int oldvol,
35364 + const unsigned int newvol,
35365 + const u32 event_mask)
35366 +{
35367 + unsigned int i = oldvol;
35368
35369 - while (i > newvol) {
35370 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35371 - i--;
35372 - }
35373 - while (i < newvol) {
35374 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35375 - i++;
35376 - }
35377 + while (i > newvol) {
35378 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35379 + i--;
35380 }
35381 + while (i < newvol) {
35382 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35383 + i++;
35384 + }
35385 +}
35386
35387 - void issue_brightnesschange(const unsigned int oldbrt,
35388 - const unsigned int newbrt)
35389 - {
35390 - unsigned int i = oldbrt;
35391 +static void issue_brightnesschange(const unsigned int oldbrt,
35392 + const unsigned int newbrt,
35393 + const u32 event_mask)
35394 +{
35395 + unsigned int i = oldbrt;
35396
35397 - while (i > newbrt) {
35398 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35399 - i--;
35400 - }
35401 - while (i < newbrt) {
35402 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35403 - i++;
35404 - }
35405 + while (i > newbrt) {
35406 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35407 + i--;
35408 + }
35409 + while (i < newbrt) {
35410 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35411 + i++;
35412 }
35413 +}
35414
35415 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35416 + struct tp_nvram_state *newn,
35417 + const u32 event_mask)
35418 +{
35419 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35420 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35421 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35422 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35423 oldn->volume_level != newn->volume_level) {
35424 /* recently muted, or repeated mute keypress, or
35425 * multiple presses ending in mute */
35426 - issue_volchange(oldn->volume_level, newn->volume_level);
35427 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35428 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35429 }
35430 } else {
35431 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35432 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35433 }
35434 if (oldn->volume_level != newn->volume_level) {
35435 - issue_volchange(oldn->volume_level, newn->volume_level);
35436 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35437 } else if (oldn->volume_toggle != newn->volume_toggle) {
35438 /* repeated vol up/down keypress at end of scale ? */
35439 if (newn->volume_level == 0)
35440 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35441 /* handle brightness */
35442 if (oldn->brightness_level != newn->brightness_level) {
35443 issue_brightnesschange(oldn->brightness_level,
35444 - newn->brightness_level);
35445 + newn->brightness_level,
35446 + event_mask);
35447 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35448 /* repeated key presses that didn't change state */
35449 if (newn->brightness_level == 0)
35450 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35451 && !tp_features.bright_unkfw)
35452 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35453 }
35454 +}
35455
35456 #undef TPACPI_COMPARE_KEY
35457 #undef TPACPI_MAY_SEND_KEY
35458 -}
35459
35460 /*
35461 * Polling driver
35462 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35463 index b859d16..5cc6b1a 100644
35464 --- a/drivers/pnp/pnpbios/bioscalls.c
35465 +++ b/drivers/pnp/pnpbios/bioscalls.c
35466 @@ -59,7 +59,7 @@ do { \
35467 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35468 } while(0)
35469
35470 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35471 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35472 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35473
35474 /*
35475 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35476
35477 cpu = get_cpu();
35478 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35479 +
35480 + pax_open_kernel();
35481 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35482 + pax_close_kernel();
35483
35484 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35485 spin_lock_irqsave(&pnp_bios_lock, flags);
35486 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35487 :"memory");
35488 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35489
35490 + pax_open_kernel();
35491 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35492 + pax_close_kernel();
35493 +
35494 put_cpu();
35495
35496 /* If we get here and this is set then the PnP BIOS faulted on us. */
35497 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35498 return status;
35499 }
35500
35501 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
35502 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35503 {
35504 int i;
35505
35506 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35507 pnp_bios_callpoint.offset = header->fields.pm16offset;
35508 pnp_bios_callpoint.segment = PNP_CS16;
35509
35510 + pax_open_kernel();
35511 +
35512 for_each_possible_cpu(i) {
35513 struct desc_struct *gdt = get_cpu_gdt_table(i);
35514 if (!gdt)
35515 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35516 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
35517 (unsigned long)__va(header->fields.pm16dseg));
35518 }
35519 +
35520 + pax_close_kernel();
35521 }
35522 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
35523 index b0ecacb..7c9da2e 100644
35524 --- a/drivers/pnp/resource.c
35525 +++ b/drivers/pnp/resource.c
35526 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
35527 return 1;
35528
35529 /* check if the resource is valid */
35530 - if (*irq < 0 || *irq > 15)
35531 + if (*irq > 15)
35532 return 0;
35533
35534 /* check if the resource is reserved */
35535 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
35536 return 1;
35537
35538 /* check if the resource is valid */
35539 - if (*dma < 0 || *dma == 4 || *dma > 7)
35540 + if (*dma == 4 || *dma > 7)
35541 return 0;
35542
35543 /* check if the resource is reserved */
35544 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
35545 index bb16f5b..c751eef 100644
35546 --- a/drivers/power/bq27x00_battery.c
35547 +++ b/drivers/power/bq27x00_battery.c
35548 @@ -67,7 +67,7 @@
35549 struct bq27x00_device_info;
35550 struct bq27x00_access_methods {
35551 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
35552 -};
35553 +} __no_const;
35554
35555 enum bq27x00_chip { BQ27000, BQ27500 };
35556
35557 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
35558 index 33f5d9a..d957d3f 100644
35559 --- a/drivers/regulator/max8660.c
35560 +++ b/drivers/regulator/max8660.c
35561 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
35562 max8660->shadow_regs[MAX8660_OVER1] = 5;
35563 } else {
35564 /* Otherwise devices can be toggled via software */
35565 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
35566 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
35567 + pax_open_kernel();
35568 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
35569 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
35570 + pax_close_kernel();
35571 }
35572
35573 /*
35574 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
35575 index 3285d41..ab7c22a 100644
35576 --- a/drivers/regulator/mc13892-regulator.c
35577 +++ b/drivers/regulator/mc13892-regulator.c
35578 @@ -564,10 +564,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
35579 }
35580 mc13xxx_unlock(mc13892);
35581
35582 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
35583 + pax_open_kernel();
35584 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
35585 = mc13892_vcam_set_mode;
35586 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
35587 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
35588 = mc13892_vcam_get_mode;
35589 + pax_close_kernel();
35590 for (i = 0; i < pdata->num_regulators; i++) {
35591 init_data = &pdata->regulators[i];
35592 priv->regulators[i] = regulator_register(
35593 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
35594 index cace6d3..f623fda 100644
35595 --- a/drivers/rtc/rtc-dev.c
35596 +++ b/drivers/rtc/rtc-dev.c
35597 @@ -14,6 +14,7 @@
35598 #include <linux/module.h>
35599 #include <linux/rtc.h>
35600 #include <linux/sched.h>
35601 +#include <linux/grsecurity.h>
35602 #include "rtc-core.h"
35603
35604 static dev_t rtc_devt;
35605 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
35606 if (copy_from_user(&tm, uarg, sizeof(tm)))
35607 return -EFAULT;
35608
35609 + gr_log_timechange();
35610 +
35611 return rtc_set_time(rtc, &tm);
35612
35613 case RTC_PIE_ON:
35614 diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
35615 index f66c33b..7ae5823 100644
35616 --- a/drivers/scsi/BusLogic.c
35617 +++ b/drivers/scsi/BusLogic.c
35618 @@ -962,6 +962,8 @@ static int __init BusLogic_InitializeFlashPointProbeInfo(struct BusLogic_HostAda
35619 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
35620 *PrototypeHostAdapter)
35621 {
35622 + pax_track_stack();
35623 +
35624 /*
35625 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
35626 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
35627 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
35628 index ffb5878..e6d785c 100644
35629 --- a/drivers/scsi/aacraid/aacraid.h
35630 +++ b/drivers/scsi/aacraid/aacraid.h
35631 @@ -492,7 +492,7 @@ struct adapter_ops
35632 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
35633 /* Administrative operations */
35634 int (*adapter_comm)(struct aac_dev * dev, int comm);
35635 -};
35636 +} __no_const;
35637
35638 /*
35639 * Define which interrupt handler needs to be installed
35640 diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
35641 index 8a0b330..b4286de 100644
35642 --- a/drivers/scsi/aacraid/commctrl.c
35643 +++ b/drivers/scsi/aacraid/commctrl.c
35644 @@ -482,6 +482,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
35645 u32 actual_fibsize64, actual_fibsize = 0;
35646 int i;
35647
35648 + pax_track_stack();
35649
35650 if (dev->in_reset) {
35651 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
35652 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
35653 index c7b6fed..4db0569 100644
35654 --- a/drivers/scsi/aacraid/linit.c
35655 +++ b/drivers/scsi/aacraid/linit.c
35656 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
35657 #elif defined(__devinitconst)
35658 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
35659 #else
35660 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
35661 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
35662 #endif
35663 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
35664 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
35665 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
35666 index d5ff142..49c0ebb 100644
35667 --- a/drivers/scsi/aic94xx/aic94xx_init.c
35668 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
35669 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
35670 .lldd_control_phy = asd_control_phy,
35671 };
35672
35673 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
35674 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
35675 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
35676 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
35677 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
35678 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
35679 index a796de9..1ef20e1 100644
35680 --- a/drivers/scsi/bfa/bfa.h
35681 +++ b/drivers/scsi/bfa/bfa.h
35682 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
35683 u32 *end);
35684 int cpe_vec_q0;
35685 int rme_vec_q0;
35686 -};
35687 +} __no_const;
35688 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
35689
35690 struct bfa_faa_cbfn_s {
35691 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
35692 index e07bd47..dbd260a 100644
35693 --- a/drivers/scsi/bfa/bfa_fcpim.c
35694 +++ b/drivers/scsi/bfa/bfa_fcpim.c
35695 @@ -4179,7 +4179,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
35696 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
35697 {
35698 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
35699 - struct bfa_itn_s *itn;
35700 + bfa_itn_s_no_const *itn;
35701
35702 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
35703 itn->isr = isr;
35704 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
35705 index 1080bcb..a3b39e3 100644
35706 --- a/drivers/scsi/bfa/bfa_fcpim.h
35707 +++ b/drivers/scsi/bfa/bfa_fcpim.h
35708 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
35709 struct bfa_itn_s {
35710 bfa_isr_func_t isr;
35711 };
35712 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
35713
35714 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
35715 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
35716 @@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
35717 struct list_head iotag_tio_free_q; /* free IO resources */
35718 struct list_head iotag_unused_q; /* unused IO resources*/
35719 struct bfa_iotag_s *iotag_arr;
35720 - struct bfa_itn_s *itn_arr;
35721 + bfa_itn_s_no_const *itn_arr;
35722 int num_ioim_reqs;
35723 int num_fwtio_reqs;
35724 int num_itns;
35725 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
35726 index d4f951f..197c350 100644
35727 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
35728 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
35729 @@ -1700,6 +1700,8 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
35730 u16 len, count;
35731 u16 templen;
35732
35733 + pax_track_stack();
35734 +
35735 /*
35736 * get hba attributes
35737 */
35738 @@ -1977,6 +1979,8 @@ bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
35739 u8 count = 0;
35740 u16 templen;
35741
35742 + pax_track_stack();
35743 +
35744 /*
35745 * get port attributes
35746 */
35747 diff --git a/drivers/scsi/bfa/bfa_fcs_rport.c b/drivers/scsi/bfa/bfa_fcs_rport.c
35748 index 52628d5..f89d033 100644
35749 --- a/drivers/scsi/bfa/bfa_fcs_rport.c
35750 +++ b/drivers/scsi/bfa/bfa_fcs_rport.c
35751 @@ -1871,6 +1871,8 @@ bfa_fcs_rport_process_rpsc(struct bfa_fcs_rport_s *rport,
35752 struct fc_rpsc_speed_info_s speeds;
35753 struct bfa_port_attr_s pport_attr;
35754
35755 + pax_track_stack();
35756 +
35757 bfa_trc(port->fcs, rx_fchs->s_id);
35758 bfa_trc(port->fcs, rx_fchs->d_id);
35759
35760 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
35761 index 546d46b..642fa5b 100644
35762 --- a/drivers/scsi/bfa/bfa_ioc.h
35763 +++ b/drivers/scsi/bfa/bfa_ioc.h
35764 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
35765 bfa_ioc_disable_cbfn_t disable_cbfn;
35766 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
35767 bfa_ioc_reset_cbfn_t reset_cbfn;
35768 -};
35769 +} __no_const;
35770
35771 /*
35772 * IOC event notification mechanism.
35773 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
35774 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
35775 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
35776 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
35777 -};
35778 +} __no_const;
35779
35780 /*
35781 * Queue element to wait for room in request queue. FIFO order is
35782 diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
35783 index 66fb725..0fe05ab 100644
35784 --- a/drivers/scsi/bfa/bfad.c
35785 +++ b/drivers/scsi/bfa/bfad.c
35786 @@ -1019,6 +1019,8 @@ bfad_start_ops(struct bfad_s *bfad) {
35787 struct bfad_vport_s *vport, *vport_new;
35788 struct bfa_fcs_driver_info_s driver_info;
35789
35790 + pax_track_stack();
35791 +
35792 /* Limit min/max. xfer size to [64k-32MB] */
35793 if (max_xfer_size < BFAD_MIN_SECTORS >> 1)
35794 max_xfer_size = BFAD_MIN_SECTORS >> 1;
35795 diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
35796 index b4f6c9a..0eb1938 100644
35797 --- a/drivers/scsi/dpt_i2o.c
35798 +++ b/drivers/scsi/dpt_i2o.c
35799 @@ -1811,6 +1811,8 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
35800 dma_addr_t addr;
35801 ulong flags = 0;
35802
35803 + pax_track_stack();
35804 +
35805 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
35806 // get user msg size in u32s
35807 if(get_user(size, &user_msg[0])){
35808 @@ -2317,6 +2319,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
35809 s32 rcode;
35810 dma_addr_t addr;
35811
35812 + pax_track_stack();
35813 +
35814 memset(msg, 0 , sizeof(msg));
35815 len = scsi_bufflen(cmd);
35816 direction = 0x00000000;
35817 diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
35818 index 94de889..ca4f0cf 100644
35819 --- a/drivers/scsi/eata.c
35820 +++ b/drivers/scsi/eata.c
35821 @@ -1087,6 +1087,8 @@ static int port_detect(unsigned long port_base, unsigned int j,
35822 struct hostdata *ha;
35823 char name[16];
35824
35825 + pax_track_stack();
35826 +
35827 sprintf(name, "%s%d", driver_name, j);
35828
35829 if (!request_region(port_base, REGION_SIZE, driver_name)) {
35830 diff --git a/drivers/scsi/fcoe/fcoe_ctlr.c b/drivers/scsi/fcoe/fcoe_ctlr.c
35831 index c74c4b8..c41ca3f 100644
35832 --- a/drivers/scsi/fcoe/fcoe_ctlr.c
35833 +++ b/drivers/scsi/fcoe/fcoe_ctlr.c
35834 @@ -2503,6 +2503,8 @@ static int fcoe_ctlr_vn_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
35835 } buf;
35836 int rc;
35837
35838 + pax_track_stack();
35839 +
35840 fiph = (struct fip_header *)skb->data;
35841 sub = fiph->fip_subcode;
35842
35843 diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
35844 index 3242bca..45a83e7 100644
35845 --- a/drivers/scsi/gdth.c
35846 +++ b/drivers/scsi/gdth.c
35847 @@ -4107,6 +4107,8 @@ static int ioc_lockdrv(void __user *arg)
35848 unsigned long flags;
35849 gdth_ha_str *ha;
35850
35851 + pax_track_stack();
35852 +
35853 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
35854 return -EFAULT;
35855 ha = gdth_find_ha(ldrv.ionode);
35856 @@ -4139,6 +4141,8 @@ static int ioc_resetdrv(void __user *arg, char *cmnd)
35857 gdth_ha_str *ha;
35858 int rval;
35859
35860 + pax_track_stack();
35861 +
35862 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
35863 res.number >= MAX_HDRIVES)
35864 return -EFAULT;
35865 @@ -4174,6 +4178,8 @@ static int ioc_general(void __user *arg, char *cmnd)
35866 gdth_ha_str *ha;
35867 int rval;
35868
35869 + pax_track_stack();
35870 +
35871 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
35872 return -EFAULT;
35873 ha = gdth_find_ha(gen.ionode);
35874 @@ -4642,6 +4648,9 @@ static void gdth_flush(gdth_ha_str *ha)
35875 int i;
35876 gdth_cmd_str gdtcmd;
35877 char cmnd[MAX_COMMAND_SIZE];
35878 +
35879 + pax_track_stack();
35880 +
35881 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
35882
35883 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
35884 diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
35885 index 6527543..81e4fe2 100644
35886 --- a/drivers/scsi/gdth_proc.c
35887 +++ b/drivers/scsi/gdth_proc.c
35888 @@ -47,6 +47,9 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
35889 u64 paddr;
35890
35891 char cmnd[MAX_COMMAND_SIZE];
35892 +
35893 + pax_track_stack();
35894 +
35895 memset(cmnd, 0xff, 12);
35896 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
35897
35898 @@ -175,6 +178,8 @@ static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
35899 gdth_hget_str *phg;
35900 char cmnd[MAX_COMMAND_SIZE];
35901
35902 + pax_track_stack();
35903 +
35904 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
35905 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
35906 if (!gdtcmd || !estr)
35907 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
35908 index 351dc0b..951dc32 100644
35909 --- a/drivers/scsi/hosts.c
35910 +++ b/drivers/scsi/hosts.c
35911 @@ -42,7 +42,7 @@
35912 #include "scsi_logging.h"
35913
35914
35915 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
35916 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
35917
35918
35919 static void scsi_host_cls_release(struct device *dev)
35920 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
35921 * subtract one because we increment first then return, but we need to
35922 * know what the next host number was before increment
35923 */
35924 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
35925 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
35926 shost->dma_channel = 0xff;
35927
35928 /* These three are default values which can be overridden */
35929 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
35930 index 418ce83..7ee1225 100644
35931 --- a/drivers/scsi/hpsa.c
35932 +++ b/drivers/scsi/hpsa.c
35933 @@ -499,7 +499,7 @@ static inline u32 next_command(struct ctlr_info *h)
35934 u32 a;
35935
35936 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
35937 - return h->access.command_completed(h);
35938 + return h->access->command_completed(h);
35939
35940 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
35941 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
35942 @@ -2956,7 +2956,7 @@ static void start_io(struct ctlr_info *h)
35943 while (!list_empty(&h->reqQ)) {
35944 c = list_entry(h->reqQ.next, struct CommandList, list);
35945 /* can't do anything if fifo is full */
35946 - if ((h->access.fifo_full(h))) {
35947 + if ((h->access->fifo_full(h))) {
35948 dev_warn(&h->pdev->dev, "fifo full\n");
35949 break;
35950 }
35951 @@ -2966,7 +2966,7 @@ static void start_io(struct ctlr_info *h)
35952 h->Qdepth--;
35953
35954 /* Tell the controller execute command */
35955 - h->access.submit_command(h, c);
35956 + h->access->submit_command(h, c);
35957
35958 /* Put job onto the completed Q */
35959 addQ(&h->cmpQ, c);
35960 @@ -2975,17 +2975,17 @@ static void start_io(struct ctlr_info *h)
35961
35962 static inline unsigned long get_next_completion(struct ctlr_info *h)
35963 {
35964 - return h->access.command_completed(h);
35965 + return h->access->command_completed(h);
35966 }
35967
35968 static inline bool interrupt_pending(struct ctlr_info *h)
35969 {
35970 - return h->access.intr_pending(h);
35971 + return h->access->intr_pending(h);
35972 }
35973
35974 static inline long interrupt_not_for_us(struct ctlr_info *h)
35975 {
35976 - return (h->access.intr_pending(h) == 0) ||
35977 + return (h->access->intr_pending(h) == 0) ||
35978 (h->interrupts_enabled == 0);
35979 }
35980
35981 @@ -3882,7 +3882,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
35982 if (prod_index < 0)
35983 return -ENODEV;
35984 h->product_name = products[prod_index].product_name;
35985 - h->access = *(products[prod_index].access);
35986 + h->access = products[prod_index].access;
35987
35988 if (hpsa_board_disabled(h->pdev)) {
35989 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
35990 @@ -4163,7 +4163,7 @@ reinit_after_soft_reset:
35991 }
35992
35993 /* make sure the board interrupts are off */
35994 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35995 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35996
35997 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
35998 goto clean2;
35999 @@ -4197,7 +4197,7 @@ reinit_after_soft_reset:
36000 * fake ones to scoop up any residual completions.
36001 */
36002 spin_lock_irqsave(&h->lock, flags);
36003 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36004 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36005 spin_unlock_irqrestore(&h->lock, flags);
36006 free_irq(h->intr[h->intr_mode], h);
36007 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36008 @@ -4216,9 +4216,9 @@ reinit_after_soft_reset:
36009 dev_info(&h->pdev->dev, "Board READY.\n");
36010 dev_info(&h->pdev->dev,
36011 "Waiting for stale completions to drain.\n");
36012 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36013 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36014 msleep(10000);
36015 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36016 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36017
36018 rc = controller_reset_failed(h->cfgtable);
36019 if (rc)
36020 @@ -4239,7 +4239,7 @@ reinit_after_soft_reset:
36021 }
36022
36023 /* Turn the interrupts on so we can service requests */
36024 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36025 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36026
36027 hpsa_hba_inquiry(h);
36028 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36029 @@ -4292,7 +4292,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36030 * To write all data in the battery backed cache to disks
36031 */
36032 hpsa_flush_cache(h);
36033 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36034 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36035 free_irq(h->intr[h->intr_mode], h);
36036 #ifdef CONFIG_PCI_MSI
36037 if (h->msix_vector)
36038 @@ -4455,7 +4455,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36039 return;
36040 }
36041 /* Change the access methods to the performant access methods */
36042 - h->access = SA5_performant_access;
36043 + h->access = &SA5_performant_access;
36044 h->transMethod = CFGTBL_Trans_Performant;
36045 }
36046
36047 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36048 index 7f53cea..a8c7188 100644
36049 --- a/drivers/scsi/hpsa.h
36050 +++ b/drivers/scsi/hpsa.h
36051 @@ -73,7 +73,7 @@ struct ctlr_info {
36052 unsigned int msix_vector;
36053 unsigned int msi_vector;
36054 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36055 - struct access_method access;
36056 + struct access_method *access;
36057
36058 /* queue and queue Info */
36059 struct list_head reqQ;
36060 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36061 index f2df059..a3a9930 100644
36062 --- a/drivers/scsi/ips.h
36063 +++ b/drivers/scsi/ips.h
36064 @@ -1027,7 +1027,7 @@ typedef struct {
36065 int (*intr)(struct ips_ha *);
36066 void (*enableint)(struct ips_ha *);
36067 uint32_t (*statupd)(struct ips_ha *);
36068 -} ips_hw_func_t;
36069 +} __no_const ips_hw_func_t;
36070
36071 typedef struct ips_ha {
36072 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36073 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36074 index d261e98..1e00f35 100644
36075 --- a/drivers/scsi/libfc/fc_exch.c
36076 +++ b/drivers/scsi/libfc/fc_exch.c
36077 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36078 * all together if not used XXX
36079 */
36080 struct {
36081 - atomic_t no_free_exch;
36082 - atomic_t no_free_exch_xid;
36083 - atomic_t xid_not_found;
36084 - atomic_t xid_busy;
36085 - atomic_t seq_not_found;
36086 - atomic_t non_bls_resp;
36087 + atomic_unchecked_t no_free_exch;
36088 + atomic_unchecked_t no_free_exch_xid;
36089 + atomic_unchecked_t xid_not_found;
36090 + atomic_unchecked_t xid_busy;
36091 + atomic_unchecked_t seq_not_found;
36092 + atomic_unchecked_t non_bls_resp;
36093 } stats;
36094 };
36095
36096 @@ -718,7 +718,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36097 /* allocate memory for exchange */
36098 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36099 if (!ep) {
36100 - atomic_inc(&mp->stats.no_free_exch);
36101 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36102 goto out;
36103 }
36104 memset(ep, 0, sizeof(*ep));
36105 @@ -779,7 +779,7 @@ out:
36106 return ep;
36107 err:
36108 spin_unlock_bh(&pool->lock);
36109 - atomic_inc(&mp->stats.no_free_exch_xid);
36110 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36111 mempool_free(ep, mp->ep_pool);
36112 return NULL;
36113 }
36114 @@ -922,7 +922,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36115 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36116 ep = fc_exch_find(mp, xid);
36117 if (!ep) {
36118 - atomic_inc(&mp->stats.xid_not_found);
36119 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36120 reject = FC_RJT_OX_ID;
36121 goto out;
36122 }
36123 @@ -952,7 +952,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36124 ep = fc_exch_find(mp, xid);
36125 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36126 if (ep) {
36127 - atomic_inc(&mp->stats.xid_busy);
36128 + atomic_inc_unchecked(&mp->stats.xid_busy);
36129 reject = FC_RJT_RX_ID;
36130 goto rel;
36131 }
36132 @@ -963,7 +963,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36133 }
36134 xid = ep->xid; /* get our XID */
36135 } else if (!ep) {
36136 - atomic_inc(&mp->stats.xid_not_found);
36137 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36138 reject = FC_RJT_RX_ID; /* XID not found */
36139 goto out;
36140 }
36141 @@ -980,7 +980,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36142 } else {
36143 sp = &ep->seq;
36144 if (sp->id != fh->fh_seq_id) {
36145 - atomic_inc(&mp->stats.seq_not_found);
36146 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36147 if (f_ctl & FC_FC_END_SEQ) {
36148 /*
36149 * Update sequence_id based on incoming last
36150 @@ -1430,22 +1430,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36151
36152 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36153 if (!ep) {
36154 - atomic_inc(&mp->stats.xid_not_found);
36155 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36156 goto out;
36157 }
36158 if (ep->esb_stat & ESB_ST_COMPLETE) {
36159 - atomic_inc(&mp->stats.xid_not_found);
36160 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36161 goto rel;
36162 }
36163 if (ep->rxid == FC_XID_UNKNOWN)
36164 ep->rxid = ntohs(fh->fh_rx_id);
36165 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36166 - atomic_inc(&mp->stats.xid_not_found);
36167 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36168 goto rel;
36169 }
36170 if (ep->did != ntoh24(fh->fh_s_id) &&
36171 ep->did != FC_FID_FLOGI) {
36172 - atomic_inc(&mp->stats.xid_not_found);
36173 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36174 goto rel;
36175 }
36176 sof = fr_sof(fp);
36177 @@ -1454,7 +1454,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36178 sp->ssb_stat |= SSB_ST_RESP;
36179 sp->id = fh->fh_seq_id;
36180 } else if (sp->id != fh->fh_seq_id) {
36181 - atomic_inc(&mp->stats.seq_not_found);
36182 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36183 goto rel;
36184 }
36185
36186 @@ -1518,9 +1518,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36187 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36188
36189 if (!sp)
36190 - atomic_inc(&mp->stats.xid_not_found);
36191 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36192 else
36193 - atomic_inc(&mp->stats.non_bls_resp);
36194 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36195
36196 fc_frame_free(fp);
36197 }
36198 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36199 index db9238f..4378ed2 100644
36200 --- a/drivers/scsi/libsas/sas_ata.c
36201 +++ b/drivers/scsi/libsas/sas_ata.c
36202 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
36203 .postreset = ata_std_postreset,
36204 .error_handler = ata_std_error_handler,
36205 .post_internal_cmd = sas_ata_post_internal,
36206 - .qc_defer = ata_std_qc_defer,
36207 + .qc_defer = ata_std_qc_defer,
36208 .qc_prep = ata_noop_qc_prep,
36209 .qc_issue = sas_ata_qc_issue,
36210 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36211 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36212 index c088a36..01c73b0 100644
36213 --- a/drivers/scsi/lpfc/lpfc.h
36214 +++ b/drivers/scsi/lpfc/lpfc.h
36215 @@ -425,7 +425,7 @@ struct lpfc_vport {
36216 struct dentry *debug_nodelist;
36217 struct dentry *vport_debugfs_root;
36218 struct lpfc_debugfs_trc *disc_trc;
36219 - atomic_t disc_trc_cnt;
36220 + atomic_unchecked_t disc_trc_cnt;
36221 #endif
36222 uint8_t stat_data_enabled;
36223 uint8_t stat_data_blocked;
36224 @@ -835,8 +835,8 @@ struct lpfc_hba {
36225 struct timer_list fabric_block_timer;
36226 unsigned long bit_flags;
36227 #define FABRIC_COMANDS_BLOCKED 0
36228 - atomic_t num_rsrc_err;
36229 - atomic_t num_cmd_success;
36230 + atomic_unchecked_t num_rsrc_err;
36231 + atomic_unchecked_t num_cmd_success;
36232 unsigned long last_rsrc_error_time;
36233 unsigned long last_ramp_down_time;
36234 unsigned long last_ramp_up_time;
36235 @@ -850,7 +850,7 @@ struct lpfc_hba {
36236 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
36237 struct dentry *debug_slow_ring_trc;
36238 struct lpfc_debugfs_trc *slow_ring_trc;
36239 - atomic_t slow_ring_trc_cnt;
36240 + atomic_unchecked_t slow_ring_trc_cnt;
36241 /* iDiag debugfs sub-directory */
36242 struct dentry *idiag_root;
36243 struct dentry *idiag_pci_cfg;
36244 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36245 index a0424dd..2499b6b 100644
36246 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36247 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36248 @@ -105,7 +105,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36249
36250 #include <linux/debugfs.h>
36251
36252 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36253 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36254 static unsigned long lpfc_debugfs_start_time = 0L;
36255
36256 /* iDiag */
36257 @@ -146,7 +146,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36258 lpfc_debugfs_enable = 0;
36259
36260 len = 0;
36261 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36262 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36263 (lpfc_debugfs_max_disc_trc - 1);
36264 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36265 dtp = vport->disc_trc + i;
36266 @@ -212,7 +212,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36267 lpfc_debugfs_enable = 0;
36268
36269 len = 0;
36270 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36271 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36272 (lpfc_debugfs_max_slow_ring_trc - 1);
36273 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36274 dtp = phba->slow_ring_trc + i;
36275 @@ -635,14 +635,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36276 !vport || !vport->disc_trc)
36277 return;
36278
36279 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36280 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36281 (lpfc_debugfs_max_disc_trc - 1);
36282 dtp = vport->disc_trc + index;
36283 dtp->fmt = fmt;
36284 dtp->data1 = data1;
36285 dtp->data2 = data2;
36286 dtp->data3 = data3;
36287 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36288 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36289 dtp->jif = jiffies;
36290 #endif
36291 return;
36292 @@ -673,14 +673,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36293 !phba || !phba->slow_ring_trc)
36294 return;
36295
36296 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36297 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36298 (lpfc_debugfs_max_slow_ring_trc - 1);
36299 dtp = phba->slow_ring_trc + index;
36300 dtp->fmt = fmt;
36301 dtp->data1 = data1;
36302 dtp->data2 = data2;
36303 dtp->data3 = data3;
36304 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36305 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36306 dtp->jif = jiffies;
36307 #endif
36308 return;
36309 @@ -3828,7 +3828,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36310 "slow_ring buffer\n");
36311 goto debug_failed;
36312 }
36313 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36314 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36315 memset(phba->slow_ring_trc, 0,
36316 (sizeof(struct lpfc_debugfs_trc) *
36317 lpfc_debugfs_max_slow_ring_trc));
36318 @@ -3874,7 +3874,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36319 "buffer\n");
36320 goto debug_failed;
36321 }
36322 - atomic_set(&vport->disc_trc_cnt, 0);
36323 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36324
36325 snprintf(name, sizeof(name), "discovery_trace");
36326 vport->debug_disc_trc =
36327 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36328 index a3c8200..31e562e 100644
36329 --- a/drivers/scsi/lpfc/lpfc_init.c
36330 +++ b/drivers/scsi/lpfc/lpfc_init.c
36331 @@ -9969,8 +9969,10 @@ lpfc_init(void)
36332 printk(LPFC_COPYRIGHT "\n");
36333
36334 if (lpfc_enable_npiv) {
36335 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36336 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36337 + pax_open_kernel();
36338 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36339 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36340 + pax_close_kernel();
36341 }
36342 lpfc_transport_template =
36343 fc_attach_transport(&lpfc_transport_functions);
36344 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36345 index eadd241..26c8e0f 100644
36346 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36347 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36348 @@ -297,7 +297,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36349 uint32_t evt_posted;
36350
36351 spin_lock_irqsave(&phba->hbalock, flags);
36352 - atomic_inc(&phba->num_rsrc_err);
36353 + atomic_inc_unchecked(&phba->num_rsrc_err);
36354 phba->last_rsrc_error_time = jiffies;
36355
36356 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36357 @@ -338,7 +338,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36358 unsigned long flags;
36359 struct lpfc_hba *phba = vport->phba;
36360 uint32_t evt_posted;
36361 - atomic_inc(&phba->num_cmd_success);
36362 + atomic_inc_unchecked(&phba->num_cmd_success);
36363
36364 if (vport->cfg_lun_queue_depth <= queue_depth)
36365 return;
36366 @@ -382,8 +382,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36367 unsigned long num_rsrc_err, num_cmd_success;
36368 int i;
36369
36370 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36371 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36372 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36373 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36374
36375 vports = lpfc_create_vport_work_array(phba);
36376 if (vports != NULL)
36377 @@ -403,8 +403,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36378 }
36379 }
36380 lpfc_destroy_vport_work_array(phba, vports);
36381 - atomic_set(&phba->num_rsrc_err, 0);
36382 - atomic_set(&phba->num_cmd_success, 0);
36383 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36384 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36385 }
36386
36387 /**
36388 @@ -438,8 +438,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36389 }
36390 }
36391 lpfc_destroy_vport_work_array(phba, vports);
36392 - atomic_set(&phba->num_rsrc_err, 0);
36393 - atomic_set(&phba->num_cmd_success, 0);
36394 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36395 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36396 }
36397
36398 /**
36399 diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
36400 index 2e6619e..fa64494 100644
36401 --- a/drivers/scsi/megaraid/megaraid_mbox.c
36402 +++ b/drivers/scsi/megaraid/megaraid_mbox.c
36403 @@ -3503,6 +3503,8 @@ megaraid_cmm_register(adapter_t *adapter)
36404 int rval;
36405 int i;
36406
36407 + pax_track_stack();
36408 +
36409 // Allocate memory for the base list of scb for management module.
36410 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
36411
36412 diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
36413 index 86afb13f..c912398 100644
36414 --- a/drivers/scsi/osd/osd_initiator.c
36415 +++ b/drivers/scsi/osd/osd_initiator.c
36416 @@ -97,6 +97,8 @@ static int _osd_get_print_system_info(struct osd_dev *od,
36417 int nelem = ARRAY_SIZE(get_attrs), a = 0;
36418 int ret;
36419
36420 + pax_track_stack();
36421 +
36422 or = osd_start_request(od, GFP_KERNEL);
36423 if (!or)
36424 return -ENOMEM;
36425 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36426 index d079f9a..d26072c 100644
36427 --- a/drivers/scsi/pmcraid.c
36428 +++ b/drivers/scsi/pmcraid.c
36429 @@ -201,8 +201,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36430 res->scsi_dev = scsi_dev;
36431 scsi_dev->hostdata = res;
36432 res->change_detected = 0;
36433 - atomic_set(&res->read_failures, 0);
36434 - atomic_set(&res->write_failures, 0);
36435 + atomic_set_unchecked(&res->read_failures, 0);
36436 + atomic_set_unchecked(&res->write_failures, 0);
36437 rc = 0;
36438 }
36439 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36440 @@ -2677,9 +2677,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36441
36442 /* If this was a SCSI read/write command keep count of errors */
36443 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36444 - atomic_inc(&res->read_failures);
36445 + atomic_inc_unchecked(&res->read_failures);
36446 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36447 - atomic_inc(&res->write_failures);
36448 + atomic_inc_unchecked(&res->write_failures);
36449
36450 if (!RES_IS_GSCSI(res->cfg_entry) &&
36451 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36452 @@ -3535,7 +3535,7 @@ static int pmcraid_queuecommand_lck(
36453 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36454 * hrrq_id assigned here in queuecommand
36455 */
36456 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36457 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36458 pinstance->num_hrrq;
36459 cmd->cmd_done = pmcraid_io_done;
36460
36461 @@ -3860,7 +3860,7 @@ static long pmcraid_ioctl_passthrough(
36462 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36463 * hrrq_id assigned here in queuecommand
36464 */
36465 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36466 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36467 pinstance->num_hrrq;
36468
36469 if (request_size) {
36470 @@ -4498,7 +4498,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36471
36472 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36473 /* add resources only after host is added into system */
36474 - if (!atomic_read(&pinstance->expose_resources))
36475 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36476 return;
36477
36478 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36479 @@ -5332,8 +5332,8 @@ static int __devinit pmcraid_init_instance(
36480 init_waitqueue_head(&pinstance->reset_wait_q);
36481
36482 atomic_set(&pinstance->outstanding_cmds, 0);
36483 - atomic_set(&pinstance->last_message_id, 0);
36484 - atomic_set(&pinstance->expose_resources, 0);
36485 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36486 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36487
36488 INIT_LIST_HEAD(&pinstance->free_res_q);
36489 INIT_LIST_HEAD(&pinstance->used_res_q);
36490 @@ -6048,7 +6048,7 @@ static int __devinit pmcraid_probe(
36491 /* Schedule worker thread to handle CCN and take care of adding and
36492 * removing devices to OS
36493 */
36494 - atomic_set(&pinstance->expose_resources, 1);
36495 + atomic_set_unchecked(&pinstance->expose_resources, 1);
36496 schedule_work(&pinstance->worker_q);
36497 return rc;
36498
36499 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36500 index f920baf..4417389 100644
36501 --- a/drivers/scsi/pmcraid.h
36502 +++ b/drivers/scsi/pmcraid.h
36503 @@ -749,7 +749,7 @@ struct pmcraid_instance {
36504 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36505
36506 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36507 - atomic_t last_message_id;
36508 + atomic_unchecked_t last_message_id;
36509
36510 /* configuration table */
36511 struct pmcraid_config_table *cfg_table;
36512 @@ -778,7 +778,7 @@ struct pmcraid_instance {
36513 atomic_t outstanding_cmds;
36514
36515 /* should add/delete resources to mid-layer now ?*/
36516 - atomic_t expose_resources;
36517 + atomic_unchecked_t expose_resources;
36518
36519
36520
36521 @@ -814,8 +814,8 @@ struct pmcraid_resource_entry {
36522 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36523 };
36524 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36525 - atomic_t read_failures; /* count of failed READ commands */
36526 - atomic_t write_failures; /* count of failed WRITE commands */
36527 + atomic_unchecked_t read_failures; /* count of failed READ commands */
36528 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36529
36530 /* To indicate add/delete/modify during CCN */
36531 u8 change_detected;
36532 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36533 index a03eaf4..a6b3fd9 100644
36534 --- a/drivers/scsi/qla2xxx/qla_def.h
36535 +++ b/drivers/scsi/qla2xxx/qla_def.h
36536 @@ -2244,7 +2244,7 @@ struct isp_operations {
36537 int (*get_flash_version) (struct scsi_qla_host *, void *);
36538 int (*start_scsi) (srb_t *);
36539 int (*abort_isp) (struct scsi_qla_host *);
36540 -};
36541 +} __no_const;
36542
36543 /* MSI-X Support *************************************************************/
36544
36545 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36546 index 473c5c8..4e2f24a 100644
36547 --- a/drivers/scsi/qla4xxx/ql4_def.h
36548 +++ b/drivers/scsi/qla4xxx/ql4_def.h
36549 @@ -256,7 +256,7 @@ struct ddb_entry {
36550 atomic_t retry_relogin_timer; /* Min Time between relogins
36551 * (4000 only) */
36552 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
36553 - atomic_t relogin_retry_count; /* Num of times relogin has been
36554 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36555 * retried */
36556
36557 uint16_t port;
36558 diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c
36559 index 42ed5db..0262f9e 100644
36560 --- a/drivers/scsi/qla4xxx/ql4_init.c
36561 +++ b/drivers/scsi/qla4xxx/ql4_init.c
36562 @@ -680,7 +680,7 @@ static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
36563 ddb_entry->fw_ddb_index = fw_ddb_index;
36564 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36565 atomic_set(&ddb_entry->relogin_timer, 0);
36566 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36567 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36568 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
36569 list_add_tail(&ddb_entry->list, &ha->ddb_list);
36570 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
36571 @@ -1433,7 +1433,7 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, uint32_t fw_ddb_index,
36572 if ((ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) &&
36573 (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)) {
36574 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
36575 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36576 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36577 atomic_set(&ddb_entry->relogin_timer, 0);
36578 clear_bit(DF_RELOGIN, &ddb_entry->flags);
36579 iscsi_unblock_session(ddb_entry->sess);
36580 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36581 index f2364ec..44c42b1 100644
36582 --- a/drivers/scsi/qla4xxx/ql4_os.c
36583 +++ b/drivers/scsi/qla4xxx/ql4_os.c
36584 @@ -811,13 +811,13 @@ static void qla4xxx_timer(struct scsi_qla_host *ha)
36585 ddb_entry->fw_ddb_device_state ==
36586 DDB_DS_SESSION_FAILED) {
36587 /* Reset retry relogin timer */
36588 - atomic_inc(&ddb_entry->relogin_retry_count);
36589 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36590 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
36591 " timed out-retrying"
36592 " relogin (%d)\n",
36593 ha->host_no,
36594 ddb_entry->fw_ddb_index,
36595 - atomic_read(&ddb_entry->
36596 + atomic_read_unchecked(&ddb_entry->
36597 relogin_retry_count))
36598 );
36599 start_dpc++;
36600 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36601 index 2aeb2e9..46e3925 100644
36602 --- a/drivers/scsi/scsi.c
36603 +++ b/drivers/scsi/scsi.c
36604 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36605 unsigned long timeout;
36606 int rtn = 0;
36607
36608 - atomic_inc(&cmd->device->iorequest_cnt);
36609 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36610
36611 /* check if the device is still usable */
36612 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36613 diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
36614 index 6888b2c..45befa1 100644
36615 --- a/drivers/scsi/scsi_debug.c
36616 +++ b/drivers/scsi/scsi_debug.c
36617 @@ -1493,6 +1493,8 @@ static int resp_mode_select(struct scsi_cmnd * scp, int mselect6,
36618 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
36619 unsigned char *cmd = (unsigned char *)scp->cmnd;
36620
36621 + pax_track_stack();
36622 +
36623 if ((errsts = check_readiness(scp, 1, devip)))
36624 return errsts;
36625 memset(arr, 0, sizeof(arr));
36626 @@ -1590,6 +1592,8 @@ static int resp_log_sense(struct scsi_cmnd * scp,
36627 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
36628 unsigned char *cmd = (unsigned char *)scp->cmnd;
36629
36630 + pax_track_stack();
36631 +
36632 if ((errsts = check_readiness(scp, 1, devip)))
36633 return errsts;
36634 memset(arr, 0, sizeof(arr));
36635 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36636 index 6d219e4..eb3ded3 100644
36637 --- a/drivers/scsi/scsi_lib.c
36638 +++ b/drivers/scsi/scsi_lib.c
36639 @@ -1415,7 +1415,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36640 shost = sdev->host;
36641 scsi_init_cmd_errh(cmd);
36642 cmd->result = DID_NO_CONNECT << 16;
36643 - atomic_inc(&cmd->device->iorequest_cnt);
36644 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36645
36646 /*
36647 * SCSI request completion path will do scsi_device_unbusy(),
36648 @@ -1441,9 +1441,9 @@ static void scsi_softirq_done(struct request *rq)
36649
36650 INIT_LIST_HEAD(&cmd->eh_entry);
36651
36652 - atomic_inc(&cmd->device->iodone_cnt);
36653 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
36654 if (cmd->result)
36655 - atomic_inc(&cmd->device->ioerr_cnt);
36656 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36657
36658 disposition = scsi_decide_disposition(cmd);
36659 if (disposition != SUCCESS &&
36660 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36661 index e0bd3f7..816b8a6 100644
36662 --- a/drivers/scsi/scsi_sysfs.c
36663 +++ b/drivers/scsi/scsi_sysfs.c
36664 @@ -622,7 +622,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36665 char *buf) \
36666 { \
36667 struct scsi_device *sdev = to_scsi_device(dev); \
36668 - unsigned long long count = atomic_read(&sdev->field); \
36669 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
36670 return snprintf(buf, 20, "0x%llx\n", count); \
36671 } \
36672 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36673 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36674 index 84a1fdf..693b0d6 100644
36675 --- a/drivers/scsi/scsi_tgt_lib.c
36676 +++ b/drivers/scsi/scsi_tgt_lib.c
36677 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36678 int err;
36679
36680 dprintk("%lx %u\n", uaddr, len);
36681 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36682 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36683 if (err) {
36684 /*
36685 * TODO: need to fixup sg_tablesize, max_segment_size,
36686 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36687 index 1b21491..1b7f60e 100644
36688 --- a/drivers/scsi/scsi_transport_fc.c
36689 +++ b/drivers/scsi/scsi_transport_fc.c
36690 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36691 * Netlink Infrastructure
36692 */
36693
36694 -static atomic_t fc_event_seq;
36695 +static atomic_unchecked_t fc_event_seq;
36696
36697 /**
36698 * fc_get_event_number - Obtain the next sequential FC event number
36699 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
36700 u32
36701 fc_get_event_number(void)
36702 {
36703 - return atomic_add_return(1, &fc_event_seq);
36704 + return atomic_add_return_unchecked(1, &fc_event_seq);
36705 }
36706 EXPORT_SYMBOL(fc_get_event_number);
36707
36708 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
36709 {
36710 int error;
36711
36712 - atomic_set(&fc_event_seq, 0);
36713 + atomic_set_unchecked(&fc_event_seq, 0);
36714
36715 error = transport_class_register(&fc_host_class);
36716 if (error)
36717 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
36718 char *cp;
36719
36720 *val = simple_strtoul(buf, &cp, 0);
36721 - if ((*cp && (*cp != '\n')) || (*val < 0))
36722 + if (*cp && (*cp != '\n'))
36723 return -EINVAL;
36724 /*
36725 * Check for overflow; dev_loss_tmo is u32
36726 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
36727 index 3fd16d7..ba0871f 100644
36728 --- a/drivers/scsi/scsi_transport_iscsi.c
36729 +++ b/drivers/scsi/scsi_transport_iscsi.c
36730 @@ -83,7 +83,7 @@ struct iscsi_internal {
36731 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
36732 };
36733
36734 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
36735 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
36736 static struct workqueue_struct *iscsi_eh_timer_workq;
36737
36738 /*
36739 @@ -761,7 +761,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
36740 int err;
36741
36742 ihost = shost->shost_data;
36743 - session->sid = atomic_add_return(1, &iscsi_session_nr);
36744 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
36745
36746 if (id == ISCSI_MAX_TARGET) {
36747 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
36748 @@ -2200,7 +2200,7 @@ static __init int iscsi_transport_init(void)
36749 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
36750 ISCSI_TRANSPORT_VERSION);
36751
36752 - atomic_set(&iscsi_session_nr, 0);
36753 + atomic_set_unchecked(&iscsi_session_nr, 0);
36754
36755 err = class_register(&iscsi_transport_class);
36756 if (err)
36757 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
36758 index 21a045e..ec89e03 100644
36759 --- a/drivers/scsi/scsi_transport_srp.c
36760 +++ b/drivers/scsi/scsi_transport_srp.c
36761 @@ -33,7 +33,7 @@
36762 #include "scsi_transport_srp_internal.h"
36763
36764 struct srp_host_attrs {
36765 - atomic_t next_port_id;
36766 + atomic_unchecked_t next_port_id;
36767 };
36768 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
36769
36770 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
36771 struct Scsi_Host *shost = dev_to_shost(dev);
36772 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
36773
36774 - atomic_set(&srp_host->next_port_id, 0);
36775 + atomic_set_unchecked(&srp_host->next_port_id, 0);
36776 return 0;
36777 }
36778
36779 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
36780 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
36781 rport->roles = ids->roles;
36782
36783 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
36784 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
36785 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
36786
36787 transport_setup_device(&rport->dev);
36788 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
36789 index 909ed9e..1ae290a 100644
36790 --- a/drivers/scsi/sg.c
36791 +++ b/drivers/scsi/sg.c
36792 @@ -1075,7 +1075,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
36793 sdp->disk->disk_name,
36794 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
36795 NULL,
36796 - (char *)arg);
36797 + (char __user *)arg);
36798 case BLKTRACESTART:
36799 return blk_trace_startstop(sdp->device->request_queue, 1);
36800 case BLKTRACESTOP:
36801 @@ -2310,7 +2310,7 @@ struct sg_proc_leaf {
36802 const struct file_operations * fops;
36803 };
36804
36805 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
36806 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
36807 {"allow_dio", &adio_fops},
36808 {"debug", &debug_fops},
36809 {"def_reserved_size", &dressz_fops},
36810 @@ -2325,7 +2325,7 @@ sg_proc_init(void)
36811 {
36812 int k, mask;
36813 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
36814 - struct sg_proc_leaf * leaf;
36815 + const struct sg_proc_leaf * leaf;
36816
36817 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
36818 if (!sg_proc_sgp)
36819 diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
36820 index b4543f5..e1b34b8 100644
36821 --- a/drivers/scsi/sym53c8xx_2/sym_glue.c
36822 +++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
36823 @@ -1756,6 +1756,8 @@ static int __devinit sym2_probe(struct pci_dev *pdev,
36824 int do_iounmap = 0;
36825 int do_disable_device = 1;
36826
36827 + pax_track_stack();
36828 +
36829 memset(&sym_dev, 0, sizeof(sym_dev));
36830 memset(&nvram, 0, sizeof(nvram));
36831 sym_dev.pdev = pdev;
36832 diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
36833 index a18996d..fe993cb 100644
36834 --- a/drivers/scsi/vmw_pvscsi.c
36835 +++ b/drivers/scsi/vmw_pvscsi.c
36836 @@ -447,6 +447,8 @@ static void pvscsi_setup_all_rings(const struct pvscsi_adapter *adapter)
36837 dma_addr_t base;
36838 unsigned i;
36839
36840 + pax_track_stack();
36841 +
36842 cmd.ringsStatePPN = adapter->ringStatePA >> PAGE_SHIFT;
36843 cmd.reqRingNumPages = adapter->req_pages;
36844 cmd.cmpRingNumPages = adapter->cmp_pages;
36845 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
36846 index c5f37f0..898d202 100644
36847 --- a/drivers/spi/spi-dw-pci.c
36848 +++ b/drivers/spi/spi-dw-pci.c
36849 @@ -148,7 +148,7 @@ static int spi_resume(struct pci_dev *pdev)
36850 #define spi_resume NULL
36851 #endif
36852
36853 -static const struct pci_device_id pci_ids[] __devinitdata = {
36854 +static const struct pci_device_id pci_ids[] __devinitconst = {
36855 /* Intel MID platform SPI controller 0 */
36856 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
36857 {},
36858 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
36859 index 4d1b9f5..8408fe3 100644
36860 --- a/drivers/spi/spi.c
36861 +++ b/drivers/spi/spi.c
36862 @@ -1023,7 +1023,7 @@ int spi_bus_unlock(struct spi_master *master)
36863 EXPORT_SYMBOL_GPL(spi_bus_unlock);
36864
36865 /* portable code must never pass more than 32 bytes */
36866 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
36867 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
36868
36869 static u8 *buf;
36870
36871 diff --git a/drivers/staging/ath6kl/os/linux/ar6000_drv.c b/drivers/staging/ath6kl/os/linux/ar6000_drv.c
36872 index 32ee39a..3004c3d 100644
36873 --- a/drivers/staging/ath6kl/os/linux/ar6000_drv.c
36874 +++ b/drivers/staging/ath6kl/os/linux/ar6000_drv.c
36875 @@ -362,7 +362,7 @@ static struct ar_cookie s_ar_cookie_mem[MAX_COOKIE_NUM];
36876 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_HOST_INTEREST_ITEM_ADDRESS(item) : 0))
36877
36878
36879 -static struct net_device_ops ar6000_netdev_ops = {
36880 +static net_device_ops_no_const ar6000_netdev_ops = {
36881 .ndo_init = NULL,
36882 .ndo_open = ar6000_open,
36883 .ndo_stop = ar6000_close,
36884 diff --git a/drivers/staging/ath6kl/os/linux/include/ar6k_pal.h b/drivers/staging/ath6kl/os/linux/include/ar6k_pal.h
36885 index 39e0873..0925710 100644
36886 --- a/drivers/staging/ath6kl/os/linux/include/ar6k_pal.h
36887 +++ b/drivers/staging/ath6kl/os/linux/include/ar6k_pal.h
36888 @@ -30,7 +30,7 @@ typedef bool (*ar6k_pal_recv_pkt_t)(void *pHciPalInfo, void *skb);
36889 typedef struct ar6k_pal_config_s
36890 {
36891 ar6k_pal_recv_pkt_t fpar6k_pal_recv_pkt;
36892 -}ar6k_pal_config_t;
36893 +} __no_const ar6k_pal_config_t;
36894
36895 void register_pal_cb(ar6k_pal_config_t *palConfig_p);
36896 #endif /* _AR6K_PAL_H_ */
36897 diff --git a/drivers/staging/brcm80211/brcmfmac/dhd_linux.c b/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
36898 index 05dada9..96171c6 100644
36899 --- a/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
36900 +++ b/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
36901 @@ -451,14 +451,14 @@ static void brcmf_op_if(struct brcmf_if *ifp)
36902 free_netdev(ifp->net);
36903 }
36904 /* Allocate etherdev, including space for private structure */
36905 - ifp->net = alloc_etherdev(sizeof(drvr_priv));
36906 + ifp->net = alloc_etherdev(sizeof(*drvr_priv));
36907 if (!ifp->net) {
36908 BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
36909 ret = -ENOMEM;
36910 }
36911 if (ret == 0) {
36912 strcpy(ifp->net->name, ifp->name);
36913 - memcpy(netdev_priv(ifp->net), &drvr_priv, sizeof(drvr_priv));
36914 + memcpy(netdev_priv(ifp->net), &drvr_priv, sizeof(*drvr_priv));
36915 err = brcmf_net_attach(&drvr_priv->pub, ifp->idx);
36916 if (err != 0) {
36917 BRCMF_ERROR(("%s: brcmf_net_attach failed, "
36918 @@ -1279,7 +1279,7 @@ struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen)
36919 BRCMF_TRACE(("%s: Enter\n", __func__));
36920
36921 /* Allocate etherdev, including space for private structure */
36922 - net = alloc_etherdev(sizeof(drvr_priv));
36923 + net = alloc_etherdev(sizeof(*drvr_priv));
36924 if (!net) {
36925 BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
36926 goto fail;
36927 @@ -1295,7 +1295,7 @@ struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen)
36928 /*
36929 * Save the brcmf_info into the priv
36930 */
36931 - memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
36932 + memcpy(netdev_priv(net), &drvr_priv, sizeof(*drvr_priv));
36933
36934 /* Set network interface name if it was provided as module parameter */
36935 if (iface_name[0]) {
36936 @@ -1352,7 +1352,7 @@ struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen)
36937 /*
36938 * Save the brcmf_info into the priv
36939 */
36940 - memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
36941 + memcpy(netdev_priv(net), &drvr_priv, sizeof(*drvr_priv));
36942
36943 #if defined(CONFIG_PM_SLEEP)
36944 atomic_set(&brcmf_mmc_suspend, false);
36945 diff --git a/drivers/staging/brcm80211/brcmfmac/sdio_host.h b/drivers/staging/brcm80211/brcmfmac/sdio_host.h
36946 index d345472..cedb19e 100644
36947 --- a/drivers/staging/brcm80211/brcmfmac/sdio_host.h
36948 +++ b/drivers/staging/brcm80211/brcmfmac/sdio_host.h
36949 @@ -263,7 +263,7 @@ struct brcmf_sdioh_driver {
36950 u16 func, uint bustype, u32 regsva, void *param);
36951 /* detach from device */
36952 void (*detach) (void *ch);
36953 -};
36954 +} __no_const;
36955
36956 struct sdioh_info;
36957
36958 diff --git a/drivers/staging/brcm80211/brcmsmac/phy/phy_int.h b/drivers/staging/brcm80211/brcmsmac/phy/phy_int.h
36959 index a01b01c..b3f721c 100644
36960 --- a/drivers/staging/brcm80211/brcmsmac/phy/phy_int.h
36961 +++ b/drivers/staging/brcm80211/brcmsmac/phy/phy_int.h
36962 @@ -591,7 +591,7 @@ struct phy_func_ptr {
36963 initfn_t carrsuppr;
36964 rxsigpwrfn_t rxsigpwr;
36965 detachfn_t detach;
36966 -};
36967 +} __no_const;
36968
36969 struct brcms_phy {
36970 struct brcms_phy_pub pubpi_ro;
36971 diff --git a/drivers/staging/et131x/et1310_tx.c b/drivers/staging/et131x/et1310_tx.c
36972 index 8fb3051..a8b6c67 100644
36973 --- a/drivers/staging/et131x/et1310_tx.c
36974 +++ b/drivers/staging/et131x/et1310_tx.c
36975 @@ -635,11 +635,11 @@ inline void et131x_free_send_packet(struct et131x_adapter *etdev,
36976 struct net_device_stats *stats = &etdev->net_stats;
36977
36978 if (tcb->flags & fMP_DEST_BROAD)
36979 - atomic_inc(&etdev->stats.brdcstxmt);
36980 + atomic_inc_unchecked(&etdev->stats.brdcstxmt);
36981 else if (tcb->flags & fMP_DEST_MULTI)
36982 - atomic_inc(&etdev->stats.multixmt);
36983 + atomic_inc_unchecked(&etdev->stats.multixmt);
36984 else
36985 - atomic_inc(&etdev->stats.unixmt);
36986 + atomic_inc_unchecked(&etdev->stats.unixmt);
36987
36988 if (tcb->skb) {
36989 stats->tx_bytes += tcb->skb->len;
36990 diff --git a/drivers/staging/et131x/et131x_adapter.h b/drivers/staging/et131x/et131x_adapter.h
36991 index 408c50b..fd65e9f 100644
36992 --- a/drivers/staging/et131x/et131x_adapter.h
36993 +++ b/drivers/staging/et131x/et131x_adapter.h
36994 @@ -106,11 +106,11 @@ struct ce_stats {
36995 * operations
36996 */
36997 u32 unircv; /* # multicast packets received */
36998 - atomic_t unixmt; /* # multicast packets for Tx */
36999 + atomic_unchecked_t unixmt; /* # multicast packets for Tx */
37000 u32 multircv; /* # multicast packets received */
37001 - atomic_t multixmt; /* # multicast packets for Tx */
37002 + atomic_unchecked_t multixmt; /* # multicast packets for Tx */
37003 u32 brdcstrcv; /* # broadcast packets received */
37004 - atomic_t brdcstxmt; /* # broadcast packets for Tx */
37005 + atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
37006 u32 norcvbuf; /* # Rx packets discarded */
37007 u32 noxmtbuf; /* # Tx packets discarded */
37008
37009 diff --git a/drivers/staging/hv/channel.c b/drivers/staging/hv/channel.c
37010 index 455f47a..86205ff 100644
37011 --- a/drivers/staging/hv/channel.c
37012 +++ b/drivers/staging/hv/channel.c
37013 @@ -447,8 +447,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
37014 int ret = 0;
37015 int t;
37016
37017 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
37018 - atomic_inc(&vmbus_connection.next_gpadl_handle);
37019 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
37020 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
37021
37022 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
37023 if (ret)
37024 diff --git a/drivers/staging/hv/hv.c b/drivers/staging/hv/hv.c
37025 index 824f816..a800af7 100644
37026 --- a/drivers/staging/hv/hv.c
37027 +++ b/drivers/staging/hv/hv.c
37028 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
37029 u64 output_address = (output) ? virt_to_phys(output) : 0;
37030 u32 output_address_hi = output_address >> 32;
37031 u32 output_address_lo = output_address & 0xFFFFFFFF;
37032 - volatile void *hypercall_page = hv_context.hypercall_page;
37033 + volatile void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
37034
37035 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
37036 "=a"(hv_status_lo) : "d" (control_hi),
37037 diff --git a/drivers/staging/hv/hv_mouse.c b/drivers/staging/hv/hv_mouse.c
37038 index d957fc2..43cedd9 100644
37039 --- a/drivers/staging/hv/hv_mouse.c
37040 +++ b/drivers/staging/hv/hv_mouse.c
37041 @@ -878,8 +878,10 @@ static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
37042 if (hid_dev) {
37043 DPRINT_INFO(INPUTVSC_DRV, "hid_device created");
37044
37045 - hid_dev->ll_driver->open = mousevsc_hid_open;
37046 - hid_dev->ll_driver->close = mousevsc_hid_close;
37047 + pax_open_kernel();
37048 + *(void **)&hid_dev->ll_driver->open = mousevsc_hid_open;
37049 + *(void **)&hid_dev->ll_driver->close = mousevsc_hid_close;
37050 + pax_close_kernel();
37051
37052 hid_dev->bus = BUS_VIRTUAL;
37053 hid_dev->vendor = input_device_ctx->device_info.vendor;
37054 diff --git a/drivers/staging/hv/hyperv_vmbus.h b/drivers/staging/hv/hyperv_vmbus.h
37055 index 349ad80..3f75719 100644
37056 --- a/drivers/staging/hv/hyperv_vmbus.h
37057 +++ b/drivers/staging/hv/hyperv_vmbus.h
37058 @@ -559,7 +559,7 @@ enum vmbus_connect_state {
37059 struct vmbus_connection {
37060 enum vmbus_connect_state conn_state;
37061
37062 - atomic_t next_gpadl_handle;
37063 + atomic_unchecked_t next_gpadl_handle;
37064
37065 /*
37066 * Represents channel interrupts. Each bit position represents a
37067 diff --git a/drivers/staging/hv/rndis_filter.c b/drivers/staging/hv/rndis_filter.c
37068 index dbb5201..d6047c6 100644
37069 --- a/drivers/staging/hv/rndis_filter.c
37070 +++ b/drivers/staging/hv/rndis_filter.c
37071 @@ -43,7 +43,7 @@ struct rndis_device {
37072
37073 enum rndis_device_state state;
37074 u32 link_stat;
37075 - atomic_t new_req_id;
37076 + atomic_unchecked_t new_req_id;
37077
37078 spinlock_t request_lock;
37079 struct list_head req_list;
37080 @@ -117,7 +117,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
37081 * template
37082 */
37083 set = &rndis_msg->msg.set_req;
37084 - set->req_id = atomic_inc_return(&dev->new_req_id);
37085 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37086
37087 /* Add to the request list */
37088 spin_lock_irqsave(&dev->request_lock, flags);
37089 @@ -622,7 +622,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
37090
37091 /* Setup the rndis set */
37092 halt = &request->request_msg.msg.halt_req;
37093 - halt->req_id = atomic_inc_return(&dev->new_req_id);
37094 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37095
37096 /* Ignore return since this msg is optional. */
37097 rndis_filter_send_request(dev, request);
37098 diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c
37099 index 1c949f5..7a8b104 100644
37100 --- a/drivers/staging/hv/vmbus_drv.c
37101 +++ b/drivers/staging/hv/vmbus_drv.c
37102 @@ -660,11 +660,11 @@ int vmbus_child_device_register(struct hv_device *child_device_obj)
37103 {
37104 int ret = 0;
37105
37106 - static atomic_t device_num = ATOMIC_INIT(0);
37107 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
37108
37109 /* Set the device name. Otherwise, device_register() will fail. */
37110 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
37111 - atomic_inc_return(&device_num));
37112 + atomic_inc_return_unchecked(&device_num));
37113
37114 /* The new device belongs to this bus */
37115 child_device_obj->device.bus = &hv_bus; /* device->dev.bus; */
37116 diff --git a/drivers/staging/iio/ring_generic.h b/drivers/staging/iio/ring_generic.h
37117 index 3f26f71..fb5c787 100644
37118 --- a/drivers/staging/iio/ring_generic.h
37119 +++ b/drivers/staging/iio/ring_generic.h
37120 @@ -62,7 +62,7 @@ struct iio_ring_access_funcs {
37121
37122 int (*is_enabled)(struct iio_ring_buffer *ring);
37123 int (*enable)(struct iio_ring_buffer *ring);
37124 -};
37125 +} __no_const;
37126
37127 struct iio_ring_setup_ops {
37128 int (*preenable)(struct iio_dev *);
37129 diff --git a/drivers/staging/mei/interface.c b/drivers/staging/mei/interface.c
37130 index cfec92d..a65dacf 100644
37131 --- a/drivers/staging/mei/interface.c
37132 +++ b/drivers/staging/mei/interface.c
37133 @@ -332,7 +332,7 @@ int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl)
37134 mei_hdr->reserved = 0;
37135
37136 mei_flow_control = (struct hbm_flow_control *) &dev->wr_msg_buf[1];
37137 - memset(mei_flow_control, 0, sizeof(mei_flow_control));
37138 + memset(mei_flow_control, 0, sizeof(*mei_flow_control));
37139 mei_flow_control->host_addr = cl->host_client_id;
37140 mei_flow_control->me_addr = cl->me_client_id;
37141 mei_flow_control->cmd.cmd = MEI_FLOW_CONTROL_CMD;
37142 @@ -396,7 +396,7 @@ int mei_disconnect(struct mei_device *dev, struct mei_cl *cl)
37143
37144 mei_cli_disconnect =
37145 (struct hbm_client_disconnect_request *) &dev->wr_msg_buf[1];
37146 - memset(mei_cli_disconnect, 0, sizeof(mei_cli_disconnect));
37147 + memset(mei_cli_disconnect, 0, sizeof(*mei_cli_disconnect));
37148 mei_cli_disconnect->host_addr = cl->host_client_id;
37149 mei_cli_disconnect->me_addr = cl->me_client_id;
37150 mei_cli_disconnect->cmd.cmd = CLIENT_DISCONNECT_REQ_CMD;
37151 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37152 index 8b307b4..a97ac91 100644
37153 --- a/drivers/staging/octeon/ethernet-rx.c
37154 +++ b/drivers/staging/octeon/ethernet-rx.c
37155 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37156 /* Increment RX stats for virtual ports */
37157 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37158 #ifdef CONFIG_64BIT
37159 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37160 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37161 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37162 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37163 #else
37164 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37165 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37166 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37167 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37168 #endif
37169 }
37170 netif_receive_skb(skb);
37171 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37172 dev->name);
37173 */
37174 #ifdef CONFIG_64BIT
37175 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37176 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37177 #else
37178 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37179 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37180 #endif
37181 dev_kfree_skb_irq(skb);
37182 }
37183 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37184 index a8f780e..aef1098 100644
37185 --- a/drivers/staging/octeon/ethernet.c
37186 +++ b/drivers/staging/octeon/ethernet.c
37187 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37188 * since the RX tasklet also increments it.
37189 */
37190 #ifdef CONFIG_64BIT
37191 - atomic64_add(rx_status.dropped_packets,
37192 - (atomic64_t *)&priv->stats.rx_dropped);
37193 + atomic64_add_unchecked(rx_status.dropped_packets,
37194 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37195 #else
37196 - atomic_add(rx_status.dropped_packets,
37197 - (atomic_t *)&priv->stats.rx_dropped);
37198 + atomic_add_unchecked(rx_status.dropped_packets,
37199 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37200 #endif
37201 }
37202
37203 diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
37204 index f3c6060..56bf826 100644
37205 --- a/drivers/staging/pohmelfs/inode.c
37206 +++ b/drivers/staging/pohmelfs/inode.c
37207 @@ -1861,7 +1861,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
37208 mutex_init(&psb->mcache_lock);
37209 psb->mcache_root = RB_ROOT;
37210 psb->mcache_timeout = msecs_to_jiffies(5000);
37211 - atomic_long_set(&psb->mcache_gen, 0);
37212 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
37213
37214 psb->trans_max_pages = 100;
37215
37216 @@ -1876,7 +1876,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
37217 INIT_LIST_HEAD(&psb->crypto_ready_list);
37218 INIT_LIST_HEAD(&psb->crypto_active_list);
37219
37220 - atomic_set(&psb->trans_gen, 1);
37221 + atomic_set_unchecked(&psb->trans_gen, 1);
37222 atomic_long_set(&psb->total_inodes, 0);
37223
37224 mutex_init(&psb->state_lock);
37225 diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
37226 index e22665c..a2a9390 100644
37227 --- a/drivers/staging/pohmelfs/mcache.c
37228 +++ b/drivers/staging/pohmelfs/mcache.c
37229 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
37230 m->data = data;
37231 m->start = start;
37232 m->size = size;
37233 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
37234 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
37235
37236 mutex_lock(&psb->mcache_lock);
37237 err = pohmelfs_mcache_insert(psb, m);
37238 diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
37239 index 985b6b7..7699e05 100644
37240 --- a/drivers/staging/pohmelfs/netfs.h
37241 +++ b/drivers/staging/pohmelfs/netfs.h
37242 @@ -571,14 +571,14 @@ struct pohmelfs_config;
37243 struct pohmelfs_sb {
37244 struct rb_root mcache_root;
37245 struct mutex mcache_lock;
37246 - atomic_long_t mcache_gen;
37247 + atomic_long_unchecked_t mcache_gen;
37248 unsigned long mcache_timeout;
37249
37250 unsigned int idx;
37251
37252 unsigned int trans_retries;
37253
37254 - atomic_t trans_gen;
37255 + atomic_unchecked_t trans_gen;
37256
37257 unsigned int crypto_attached_size;
37258 unsigned int crypto_align_size;
37259 diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
37260 index 36a2535..0591bf4 100644
37261 --- a/drivers/staging/pohmelfs/trans.c
37262 +++ b/drivers/staging/pohmelfs/trans.c
37263 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
37264 int err;
37265 struct netfs_cmd *cmd = t->iovec.iov_base;
37266
37267 - t->gen = atomic_inc_return(&psb->trans_gen);
37268 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
37269
37270 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
37271 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
37272 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37273 index b70cb2b..4db41a7 100644
37274 --- a/drivers/staging/rtl8712/rtl871x_io.h
37275 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37276 @@ -83,7 +83,7 @@ struct _io_ops {
37277 u8 *pmem);
37278 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37279 u8 *pmem);
37280 -};
37281 +} __no_const;
37282
37283 struct io_req {
37284 struct list_head list;
37285 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37286 index c7b5e8b..783d6cb 100644
37287 --- a/drivers/staging/sbe-2t3e3/netdev.c
37288 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37289 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37290 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37291
37292 if (rlen)
37293 - if (copy_to_user(data, &resp, rlen))
37294 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37295 return -EFAULT;
37296
37297 return 0;
37298 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37299 index be21617..0954e45 100644
37300 --- a/drivers/staging/usbip/usbip_common.h
37301 +++ b/drivers/staging/usbip/usbip_common.h
37302 @@ -289,7 +289,7 @@ struct usbip_device {
37303 void (*shutdown)(struct usbip_device *);
37304 void (*reset)(struct usbip_device *);
37305 void (*unusable)(struct usbip_device *);
37306 - } eh_ops;
37307 + } __no_const eh_ops;
37308 };
37309
37310 #if 0
37311 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37312 index 71a586e..4d8a91a 100644
37313 --- a/drivers/staging/usbip/vhci.h
37314 +++ b/drivers/staging/usbip/vhci.h
37315 @@ -85,7 +85,7 @@ struct vhci_hcd {
37316 unsigned resuming:1;
37317 unsigned long re_timeout;
37318
37319 - atomic_t seqnum;
37320 + atomic_unchecked_t seqnum;
37321
37322 /*
37323 * NOTE:
37324 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37325 index 2ee97e2..0420b86 100644
37326 --- a/drivers/staging/usbip/vhci_hcd.c
37327 +++ b/drivers/staging/usbip/vhci_hcd.c
37328 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
37329 return;
37330 }
37331
37332 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37333 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37334 if (priv->seqnum == 0xffff)
37335 dev_info(&urb->dev->dev, "seqnum max\n");
37336
37337 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37338 return -ENOMEM;
37339 }
37340
37341 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37342 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37343 if (unlink->seqnum == 0xffff)
37344 pr_info("seqnum max\n");
37345
37346 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
37347 vdev->rhport = rhport;
37348 }
37349
37350 - atomic_set(&vhci->seqnum, 0);
37351 + atomic_set_unchecked(&vhci->seqnum, 0);
37352 spin_lock_init(&vhci->lock);
37353
37354 hcd->power_budget = 0; /* no limit */
37355 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37356 index 3872b8c..fe6d2f4 100644
37357 --- a/drivers/staging/usbip/vhci_rx.c
37358 +++ b/drivers/staging/usbip/vhci_rx.c
37359 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37360 if (!urb) {
37361 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37362 pr_info("max seqnum %d\n",
37363 - atomic_read(&the_controller->seqnum));
37364 + atomic_read_unchecked(&the_controller->seqnum));
37365 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37366 return;
37367 }
37368 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37369 index 7735027..30eed13 100644
37370 --- a/drivers/staging/vt6655/hostap.c
37371 +++ b/drivers/staging/vt6655/hostap.c
37372 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37373 *
37374 */
37375
37376 +static net_device_ops_no_const apdev_netdev_ops;
37377 +
37378 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37379 {
37380 PSDevice apdev_priv;
37381 struct net_device *dev = pDevice->dev;
37382 int ret;
37383 - const struct net_device_ops apdev_netdev_ops = {
37384 - .ndo_start_xmit = pDevice->tx_80211,
37385 - };
37386
37387 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37388
37389 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37390 *apdev_priv = *pDevice;
37391 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37392
37393 + /* only half broken now */
37394 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37395 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37396
37397 pDevice->apdev->type = ARPHRD_IEEE80211;
37398 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37399 index 51b5adf..098e320 100644
37400 --- a/drivers/staging/vt6656/hostap.c
37401 +++ b/drivers/staging/vt6656/hostap.c
37402 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37403 *
37404 */
37405
37406 +static net_device_ops_no_const apdev_netdev_ops;
37407 +
37408 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37409 {
37410 PSDevice apdev_priv;
37411 struct net_device *dev = pDevice->dev;
37412 int ret;
37413 - const struct net_device_ops apdev_netdev_ops = {
37414 - .ndo_start_xmit = pDevice->tx_80211,
37415 - };
37416
37417 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37418
37419 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37420 *apdev_priv = *pDevice;
37421 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37422
37423 + /* only half broken now */
37424 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37425 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37426
37427 pDevice->apdev->type = ARPHRD_IEEE80211;
37428 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37429 index 7843dfd..3db105f 100644
37430 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37431 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37432 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37433
37434 struct usbctlx_completor {
37435 int (*complete) (struct usbctlx_completor *);
37436 -};
37437 +} __no_const;
37438
37439 static int
37440 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37441 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37442 index 1ca66ea..76f1343 100644
37443 --- a/drivers/staging/zcache/tmem.c
37444 +++ b/drivers/staging/zcache/tmem.c
37445 @@ -39,7 +39,7 @@
37446 * A tmem host implementation must use this function to register callbacks
37447 * for memory allocation.
37448 */
37449 -static struct tmem_hostops tmem_hostops;
37450 +static tmem_hostops_no_const tmem_hostops;
37451
37452 static void tmem_objnode_tree_init(void);
37453
37454 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37455 * A tmem host implementation must use this function to register
37456 * callbacks for a page-accessible memory (PAM) implementation
37457 */
37458 -static struct tmem_pamops tmem_pamops;
37459 +static tmem_pamops_no_const tmem_pamops;
37460
37461 void tmem_register_pamops(struct tmem_pamops *m)
37462 {
37463 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37464 index ed147c4..94fc3c6 100644
37465 --- a/drivers/staging/zcache/tmem.h
37466 +++ b/drivers/staging/zcache/tmem.h
37467 @@ -180,6 +180,7 @@ struct tmem_pamops {
37468 void (*new_obj)(struct tmem_obj *);
37469 int (*replace_in_obj)(void *, struct tmem_obj *);
37470 };
37471 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37472 extern void tmem_register_pamops(struct tmem_pamops *m);
37473
37474 /* memory allocation methods provided by the host implementation */
37475 @@ -189,6 +190,7 @@ struct tmem_hostops {
37476 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37477 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37478 };
37479 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37480 extern void tmem_register_hostops(struct tmem_hostops *m);
37481
37482 /* core tmem accessor functions */
37483 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
37484 index c4ac6f6..4f90f53 100644
37485 --- a/drivers/target/iscsi/iscsi_target.c
37486 +++ b/drivers/target/iscsi/iscsi_target.c
37487 @@ -1370,7 +1370,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
37488 * outstanding_r2ts reaches zero, go ahead and send the delayed
37489 * TASK_ABORTED status.
37490 */
37491 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
37492 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
37493 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
37494 if (--cmd->outstanding_r2ts < 1) {
37495 iscsit_stop_dataout_timer(cmd);
37496 diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
37497 index 8badcb4..94c9ac6 100644
37498 --- a/drivers/target/target_core_alua.c
37499 +++ b/drivers/target/target_core_alua.c
37500 @@ -723,6 +723,8 @@ static int core_alua_update_tpg_primary_metadata(
37501 char path[ALUA_METADATA_PATH_LEN];
37502 int len;
37503
37504 + pax_track_stack();
37505 +
37506 memset(path, 0, ALUA_METADATA_PATH_LEN);
37507
37508 len = snprintf(md_buf, tg_pt_gp->tg_pt_gp_md_buf_len,
37509 @@ -986,6 +988,8 @@ static int core_alua_update_tpg_secondary_metadata(
37510 char path[ALUA_METADATA_PATH_LEN], wwn[ALUA_SECONDARY_METADATA_WWN_LEN];
37511 int len;
37512
37513 + pax_track_stack();
37514 +
37515 memset(path, 0, ALUA_METADATA_PATH_LEN);
37516 memset(wwn, 0, ALUA_SECONDARY_METADATA_WWN_LEN);
37517
37518 diff --git a/drivers/target/target_core_cdb.c b/drivers/target/target_core_cdb.c
37519 index 5f91397..dcc2d25 100644
37520 --- a/drivers/target/target_core_cdb.c
37521 +++ b/drivers/target/target_core_cdb.c
37522 @@ -933,6 +933,8 @@ target_emulate_modesense(struct se_cmd *cmd, int ten)
37523 int length = 0;
37524 unsigned char buf[SE_MODE_PAGE_BUF];
37525
37526 + pax_track_stack();
37527 +
37528 memset(buf, 0, SE_MODE_PAGE_BUF);
37529
37530 switch (cdb[2] & 0x3f) {
37531 diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
37532 index b2575d8..b6b28fd 100644
37533 --- a/drivers/target/target_core_configfs.c
37534 +++ b/drivers/target/target_core_configfs.c
37535 @@ -1267,6 +1267,8 @@ static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts(
37536 ssize_t len = 0;
37537 int reg_count = 0, prf_isid;
37538
37539 + pax_track_stack();
37540 +
37541 if (!su_dev->se_dev_ptr)
37542 return -ENODEV;
37543
37544 diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
37545 index 7fd3a16..bc2fb3e 100644
37546 --- a/drivers/target/target_core_pr.c
37547 +++ b/drivers/target/target_core_pr.c
37548 @@ -918,6 +918,8 @@ static int __core_scsi3_check_aptpl_registration(
37549 unsigned char t_port[PR_APTPL_MAX_TPORT_LEN];
37550 u16 tpgt;
37551
37552 + pax_track_stack();
37553 +
37554 memset(i_port, 0, PR_APTPL_MAX_IPORT_LEN);
37555 memset(t_port, 0, PR_APTPL_MAX_TPORT_LEN);
37556 /*
37557 @@ -1867,6 +1869,8 @@ static int __core_scsi3_update_aptpl_buf(
37558 ssize_t len = 0;
37559 int reg_count = 0;
37560
37561 + pax_track_stack();
37562 +
37563 memset(buf, 0, pr_aptpl_buf_len);
37564 /*
37565 * Called to clear metadata once APTPL has been deactivated.
37566 @@ -1989,6 +1993,8 @@ static int __core_scsi3_write_aptpl_to_file(
37567 char path[512];
37568 int ret;
37569
37570 + pax_track_stack();
37571 +
37572 memset(iov, 0, sizeof(struct iovec));
37573 memset(path, 0, 512);
37574
37575 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37576 index 5c1b8c5..0cb7d0e 100644
37577 --- a/drivers/target/target_core_tmr.c
37578 +++ b/drivers/target/target_core_tmr.c
37579 @@ -255,7 +255,7 @@ static void core_tmr_drain_task_list(
37580 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37581 cmd->t_task_list_num,
37582 atomic_read(&cmd->t_task_cdbs_left),
37583 - atomic_read(&cmd->t_task_cdbs_sent),
37584 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37585 atomic_read(&cmd->t_transport_active),
37586 atomic_read(&cmd->t_transport_stop),
37587 atomic_read(&cmd->t_transport_sent));
37588 @@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
37589 pr_debug("LUN_RESET: got t_transport_active = 1 for"
37590 " task: %p, t_fe_count: %d dev: %p\n", task,
37591 fe_count, dev);
37592 - atomic_set(&cmd->t_transport_aborted, 1);
37593 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37594 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37595
37596 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37597 @@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
37598 }
37599 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
37600 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
37601 - atomic_set(&cmd->t_transport_aborted, 1);
37602 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37603 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37604
37605 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37606 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37607 index e2added..ccb5251 100644
37608 --- a/drivers/target/target_core_transport.c
37609 +++ b/drivers/target/target_core_transport.c
37610 @@ -1445,7 +1445,7 @@ struct se_device *transport_add_device_to_core_hba(
37611
37612 dev->queue_depth = dev_limits->queue_depth;
37613 atomic_set(&dev->depth_left, dev->queue_depth);
37614 - atomic_set(&dev->dev_ordered_id, 0);
37615 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37616
37617 se_dev_set_default_attribs(dev, dev_limits);
37618
37619 @@ -1633,7 +1633,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37620 * Used to determine when ORDERED commands should go from
37621 * Dormant to Active status.
37622 */
37623 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37624 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37625 smp_mb__after_atomic_inc();
37626 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37627 cmd->se_ordered_id, cmd->sam_task_attr,
37628 @@ -1960,7 +1960,7 @@ static void transport_generic_request_failure(
37629 " t_transport_active: %d t_transport_stop: %d"
37630 " t_transport_sent: %d\n", cmd->t_task_list_num,
37631 atomic_read(&cmd->t_task_cdbs_left),
37632 - atomic_read(&cmd->t_task_cdbs_sent),
37633 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37634 atomic_read(&cmd->t_task_cdbs_ex_left),
37635 atomic_read(&cmd->t_transport_active),
37636 atomic_read(&cmd->t_transport_stop),
37637 @@ -2460,9 +2460,9 @@ check_depth:
37638 spin_lock_irqsave(&cmd->t_state_lock, flags);
37639 atomic_set(&task->task_active, 1);
37640 atomic_set(&task->task_sent, 1);
37641 - atomic_inc(&cmd->t_task_cdbs_sent);
37642 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37643
37644 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
37645 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37646 cmd->t_task_list_num)
37647 atomic_set(&cmd->transport_sent, 1);
37648
37649 @@ -4682,7 +4682,7 @@ static void transport_generic_wait_for_tasks(
37650 atomic_set(&cmd->transport_lun_stop, 0);
37651 }
37652 if (!atomic_read(&cmd->t_transport_active) ||
37653 - atomic_read(&cmd->t_transport_aborted))
37654 + atomic_read_unchecked(&cmd->t_transport_aborted))
37655 goto remove;
37656
37657 atomic_set(&cmd->t_transport_stop, 1);
37658 @@ -4917,7 +4917,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
37659 {
37660 int ret = 0;
37661
37662 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
37663 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
37664 if (!send_status ||
37665 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
37666 return 1;
37667 @@ -4954,7 +4954,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
37668 */
37669 if (cmd->data_direction == DMA_TO_DEVICE) {
37670 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
37671 - atomic_inc(&cmd->t_transport_aborted);
37672 + atomic_inc_unchecked(&cmd->t_transport_aborted);
37673 smp_mb__after_atomic_inc();
37674 cmd->scsi_status = SAM_STAT_TASK_ABORTED;
37675 transport_new_cmd_failure(cmd);
37676 @@ -5068,7 +5068,7 @@ static void transport_processing_shutdown(struct se_device *dev)
37677 cmd->se_tfo->get_task_tag(cmd),
37678 cmd->t_task_list_num,
37679 atomic_read(&cmd->t_task_cdbs_left),
37680 - atomic_read(&cmd->t_task_cdbs_sent),
37681 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37682 atomic_read(&cmd->t_transport_active),
37683 atomic_read(&cmd->t_transport_stop),
37684 atomic_read(&cmd->t_transport_sent));
37685 diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
37686 index d5f923b..9c78228 100644
37687 --- a/drivers/telephony/ixj.c
37688 +++ b/drivers/telephony/ixj.c
37689 @@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
37690 bool mContinue;
37691 char *pIn, *pOut;
37692
37693 + pax_track_stack();
37694 +
37695 if (!SCI_Prepare(j))
37696 return 0;
37697
37698 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37699 index 4c8b665..1d931eb 100644
37700 --- a/drivers/tty/hvc/hvcs.c
37701 +++ b/drivers/tty/hvc/hvcs.c
37702 @@ -83,6 +83,7 @@
37703 #include <asm/hvcserver.h>
37704 #include <asm/uaccess.h>
37705 #include <asm/vio.h>
37706 +#include <asm/local.h>
37707
37708 /*
37709 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37710 @@ -270,7 +271,7 @@ struct hvcs_struct {
37711 unsigned int index;
37712
37713 struct tty_struct *tty;
37714 - int open_count;
37715 + local_t open_count;
37716
37717 /*
37718 * Used to tell the driver kernel_thread what operations need to take
37719 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37720
37721 spin_lock_irqsave(&hvcsd->lock, flags);
37722
37723 - if (hvcsd->open_count > 0) {
37724 + if (local_read(&hvcsd->open_count) > 0) {
37725 spin_unlock_irqrestore(&hvcsd->lock, flags);
37726 printk(KERN_INFO "HVCS: vterm state unchanged. "
37727 "The hvcs device node is still in use.\n");
37728 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37729 if ((retval = hvcs_partner_connect(hvcsd)))
37730 goto error_release;
37731
37732 - hvcsd->open_count = 1;
37733 + local_set(&hvcsd->open_count, 1);
37734 hvcsd->tty = tty;
37735 tty->driver_data = hvcsd;
37736
37737 @@ -1179,7 +1180,7 @@ fast_open:
37738
37739 spin_lock_irqsave(&hvcsd->lock, flags);
37740 kref_get(&hvcsd->kref);
37741 - hvcsd->open_count++;
37742 + local_inc(&hvcsd->open_count);
37743 hvcsd->todo_mask |= HVCS_SCHED_READ;
37744 spin_unlock_irqrestore(&hvcsd->lock, flags);
37745
37746 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37747 hvcsd = tty->driver_data;
37748
37749 spin_lock_irqsave(&hvcsd->lock, flags);
37750 - if (--hvcsd->open_count == 0) {
37751 + if (local_dec_and_test(&hvcsd->open_count)) {
37752
37753 vio_disable_interrupts(hvcsd->vdev);
37754
37755 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37756 free_irq(irq, hvcsd);
37757 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37758 return;
37759 - } else if (hvcsd->open_count < 0) {
37760 + } else if (local_read(&hvcsd->open_count) < 0) {
37761 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37762 " is missmanaged.\n",
37763 - hvcsd->vdev->unit_address, hvcsd->open_count);
37764 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37765 }
37766
37767 spin_unlock_irqrestore(&hvcsd->lock, flags);
37768 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37769
37770 spin_lock_irqsave(&hvcsd->lock, flags);
37771 /* Preserve this so that we know how many kref refs to put */
37772 - temp_open_count = hvcsd->open_count;
37773 + temp_open_count = local_read(&hvcsd->open_count);
37774
37775 /*
37776 * Don't kref put inside the spinlock because the destruction
37777 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37778 hvcsd->tty->driver_data = NULL;
37779 hvcsd->tty = NULL;
37780
37781 - hvcsd->open_count = 0;
37782 + local_set(&hvcsd->open_count, 0);
37783
37784 /* This will drop any buffered data on the floor which is OK in a hangup
37785 * scenario. */
37786 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
37787 * the middle of a write operation? This is a crummy place to do this
37788 * but we want to keep it all in the spinlock.
37789 */
37790 - if (hvcsd->open_count <= 0) {
37791 + if (local_read(&hvcsd->open_count) <= 0) {
37792 spin_unlock_irqrestore(&hvcsd->lock, flags);
37793 return -ENODEV;
37794 }
37795 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37796 {
37797 struct hvcs_struct *hvcsd = tty->driver_data;
37798
37799 - if (!hvcsd || hvcsd->open_count <= 0)
37800 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37801 return 0;
37802
37803 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37804 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37805 index ef92869..f4ebd88 100644
37806 --- a/drivers/tty/ipwireless/tty.c
37807 +++ b/drivers/tty/ipwireless/tty.c
37808 @@ -29,6 +29,7 @@
37809 #include <linux/tty_driver.h>
37810 #include <linux/tty_flip.h>
37811 #include <linux/uaccess.h>
37812 +#include <asm/local.h>
37813
37814 #include "tty.h"
37815 #include "network.h"
37816 @@ -51,7 +52,7 @@ struct ipw_tty {
37817 int tty_type;
37818 struct ipw_network *network;
37819 struct tty_struct *linux_tty;
37820 - int open_count;
37821 + local_t open_count;
37822 unsigned int control_lines;
37823 struct mutex ipw_tty_mutex;
37824 int tx_bytes_queued;
37825 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37826 mutex_unlock(&tty->ipw_tty_mutex);
37827 return -ENODEV;
37828 }
37829 - if (tty->open_count == 0)
37830 + if (local_read(&tty->open_count) == 0)
37831 tty->tx_bytes_queued = 0;
37832
37833 - tty->open_count++;
37834 + local_inc(&tty->open_count);
37835
37836 tty->linux_tty = linux_tty;
37837 linux_tty->driver_data = tty;
37838 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37839
37840 static void do_ipw_close(struct ipw_tty *tty)
37841 {
37842 - tty->open_count--;
37843 -
37844 - if (tty->open_count == 0) {
37845 + if (local_dec_return(&tty->open_count) == 0) {
37846 struct tty_struct *linux_tty = tty->linux_tty;
37847
37848 if (linux_tty != NULL) {
37849 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37850 return;
37851
37852 mutex_lock(&tty->ipw_tty_mutex);
37853 - if (tty->open_count == 0) {
37854 + if (local_read(&tty->open_count) == 0) {
37855 mutex_unlock(&tty->ipw_tty_mutex);
37856 return;
37857 }
37858 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37859 return;
37860 }
37861
37862 - if (!tty->open_count) {
37863 + if (!local_read(&tty->open_count)) {
37864 mutex_unlock(&tty->ipw_tty_mutex);
37865 return;
37866 }
37867 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37868 return -ENODEV;
37869
37870 mutex_lock(&tty->ipw_tty_mutex);
37871 - if (!tty->open_count) {
37872 + if (!local_read(&tty->open_count)) {
37873 mutex_unlock(&tty->ipw_tty_mutex);
37874 return -EINVAL;
37875 }
37876 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37877 if (!tty)
37878 return -ENODEV;
37879
37880 - if (!tty->open_count)
37881 + if (!local_read(&tty->open_count))
37882 return -EINVAL;
37883
37884 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37885 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37886 if (!tty)
37887 return 0;
37888
37889 - if (!tty->open_count)
37890 + if (!local_read(&tty->open_count))
37891 return 0;
37892
37893 return tty->tx_bytes_queued;
37894 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37895 if (!tty)
37896 return -ENODEV;
37897
37898 - if (!tty->open_count)
37899 + if (!local_read(&tty->open_count))
37900 return -EINVAL;
37901
37902 return get_control_lines(tty);
37903 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37904 if (!tty)
37905 return -ENODEV;
37906
37907 - if (!tty->open_count)
37908 + if (!local_read(&tty->open_count))
37909 return -EINVAL;
37910
37911 return set_control_lines(tty, set, clear);
37912 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37913 if (!tty)
37914 return -ENODEV;
37915
37916 - if (!tty->open_count)
37917 + if (!local_read(&tty->open_count))
37918 return -EINVAL;
37919
37920 /* FIXME: Exactly how is the tty object locked here .. */
37921 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37922 against a parallel ioctl etc */
37923 mutex_lock(&ttyj->ipw_tty_mutex);
37924 }
37925 - while (ttyj->open_count)
37926 + while (local_read(&ttyj->open_count))
37927 do_ipw_close(ttyj);
37928 ipwireless_disassociate_network_ttys(network,
37929 ttyj->channel_idx);
37930 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37931 index 8a50e4e..7d9ca3d 100644
37932 --- a/drivers/tty/n_gsm.c
37933 +++ b/drivers/tty/n_gsm.c
37934 @@ -1625,7 +1625,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37935 kref_init(&dlci->ref);
37936 mutex_init(&dlci->mutex);
37937 dlci->fifo = &dlci->_fifo;
37938 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37939 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37940 kfree(dlci);
37941 return NULL;
37942 }
37943 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37944 index 39d6ab6..eb97f41 100644
37945 --- a/drivers/tty/n_tty.c
37946 +++ b/drivers/tty/n_tty.c
37947 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37948 {
37949 *ops = tty_ldisc_N_TTY;
37950 ops->owner = NULL;
37951 - ops->refcount = ops->flags = 0;
37952 + atomic_set(&ops->refcount, 0);
37953 + ops->flags = 0;
37954 }
37955 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37956 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37957 index e18604b..a7d5a11 100644
37958 --- a/drivers/tty/pty.c
37959 +++ b/drivers/tty/pty.c
37960 @@ -773,8 +773,10 @@ static void __init unix98_pty_init(void)
37961 register_sysctl_table(pty_root_table);
37962
37963 /* Now create the /dev/ptmx special device */
37964 + pax_open_kernel();
37965 tty_default_fops(&ptmx_fops);
37966 - ptmx_fops.open = ptmx_open;
37967 + *(void **)&ptmx_fops.open = ptmx_open;
37968 + pax_close_kernel();
37969
37970 cdev_init(&ptmx_cdev, &ptmx_fops);
37971 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37972 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
37973 index 6a1241c..d04ab0d 100644
37974 --- a/drivers/tty/rocket.c
37975 +++ b/drivers/tty/rocket.c
37976 @@ -1277,6 +1277,8 @@ static int get_ports(struct r_port *info, struct rocket_ports __user *retports)
37977 struct rocket_ports tmp;
37978 int board;
37979
37980 + pax_track_stack();
37981 +
37982 if (!retports)
37983 return -EFAULT;
37984 memset(&tmp, 0, sizeof (tmp));
37985 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37986 index 87e7e6c..89744e0 100644
37987 --- a/drivers/tty/serial/kgdboc.c
37988 +++ b/drivers/tty/serial/kgdboc.c
37989 @@ -23,8 +23,9 @@
37990 #define MAX_CONFIG_LEN 40
37991
37992 static struct kgdb_io kgdboc_io_ops;
37993 +static struct kgdb_io kgdboc_io_ops_console;
37994
37995 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37996 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37997 static int configured = -1;
37998
37999 static char config[MAX_CONFIG_LEN];
38000 @@ -147,6 +148,8 @@ static void cleanup_kgdboc(void)
38001 kgdboc_unregister_kbd();
38002 if (configured == 1)
38003 kgdb_unregister_io_module(&kgdboc_io_ops);
38004 + else if (configured == 2)
38005 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38006 }
38007
38008 static int configure_kgdboc(void)
38009 @@ -156,13 +159,13 @@ static int configure_kgdboc(void)
38010 int err;
38011 char *cptr = config;
38012 struct console *cons;
38013 + int is_console = 0;
38014
38015 err = kgdboc_option_setup(config);
38016 if (err || !strlen(config) || isspace(config[0]))
38017 goto noconfig;
38018
38019 err = -ENODEV;
38020 - kgdboc_io_ops.is_console = 0;
38021 kgdb_tty_driver = NULL;
38022
38023 kgdboc_use_kms = 0;
38024 @@ -183,7 +186,7 @@ static int configure_kgdboc(void)
38025 int idx;
38026 if (cons->device && cons->device(cons, &idx) == p &&
38027 idx == tty_line) {
38028 - kgdboc_io_ops.is_console = 1;
38029 + is_console = 1;
38030 break;
38031 }
38032 cons = cons->next;
38033 @@ -193,12 +196,16 @@ static int configure_kgdboc(void)
38034 kgdb_tty_line = tty_line;
38035
38036 do_register:
38037 - err = kgdb_register_io_module(&kgdboc_io_ops);
38038 + if (is_console) {
38039 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38040 + configured = 2;
38041 + } else {
38042 + err = kgdb_register_io_module(&kgdboc_io_ops);
38043 + configured = 1;
38044 + }
38045 if (err)
38046 goto noconfig;
38047
38048 - configured = 1;
38049 -
38050 return 0;
38051
38052 noconfig:
38053 @@ -212,7 +219,7 @@ noconfig:
38054 static int __init init_kgdboc(void)
38055 {
38056 /* Already configured? */
38057 - if (configured == 1)
38058 + if (configured >= 1)
38059 return 0;
38060
38061 return configure_kgdboc();
38062 @@ -261,7 +268,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38063 if (config[len - 1] == '\n')
38064 config[len - 1] = '\0';
38065
38066 - if (configured == 1)
38067 + if (configured >= 1)
38068 cleanup_kgdboc();
38069
38070 /* Go and configure with the new params. */
38071 @@ -301,6 +308,15 @@ static struct kgdb_io kgdboc_io_ops = {
38072 .post_exception = kgdboc_post_exp_handler,
38073 };
38074
38075 +static struct kgdb_io kgdboc_io_ops_console = {
38076 + .name = "kgdboc",
38077 + .read_char = kgdboc_get_char,
38078 + .write_char = kgdboc_put_char,
38079 + .pre_exception = kgdboc_pre_exp_handler,
38080 + .post_exception = kgdboc_post_exp_handler,
38081 + .is_console = 1
38082 +};
38083 +
38084 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38085 /* This is only available if kgdboc is a built in for early debugging */
38086 static int __init kgdboc_early_init(char *opt)
38087 diff --git a/drivers/tty/serial/mfd.c b/drivers/tty/serial/mfd.c
38088 index cab52f4..29fc6aa 100644
38089 --- a/drivers/tty/serial/mfd.c
38090 +++ b/drivers/tty/serial/mfd.c
38091 @@ -1423,7 +1423,7 @@ static void serial_hsu_remove(struct pci_dev *pdev)
38092 }
38093
38094 /* First 3 are UART ports, and the 4th is the DMA */
38095 -static const struct pci_device_id pci_ids[] __devinitdata = {
38096 +static const struct pci_device_id pci_ids[] __devinitconst = {
38097 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081B) },
38098 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081C) },
38099 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081D) },
38100 diff --git a/drivers/tty/serial/mrst_max3110.c b/drivers/tty/serial/mrst_max3110.c
38101 index 23bc743..d425c07 100644
38102 --- a/drivers/tty/serial/mrst_max3110.c
38103 +++ b/drivers/tty/serial/mrst_max3110.c
38104 @@ -393,6 +393,8 @@ static void max3110_con_receive(struct uart_max3110 *max)
38105 int loop = 1, num, total = 0;
38106 u8 recv_buf[512], *pbuf;
38107
38108 + pax_track_stack();
38109 +
38110 pbuf = recv_buf;
38111 do {
38112 num = max3110_read_multi(max, pbuf);
38113 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38114 index 1a890e2..1d8139c 100644
38115 --- a/drivers/tty/tty_io.c
38116 +++ b/drivers/tty/tty_io.c
38117 @@ -3238,7 +3238,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38118
38119 void tty_default_fops(struct file_operations *fops)
38120 {
38121 - *fops = tty_fops;
38122 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38123 }
38124
38125 /*
38126 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38127 index a76c808..ecbc743 100644
38128 --- a/drivers/tty/tty_ldisc.c
38129 +++ b/drivers/tty/tty_ldisc.c
38130 @@ -75,7 +75,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38131 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38132 struct tty_ldisc_ops *ldo = ld->ops;
38133
38134 - ldo->refcount--;
38135 + atomic_dec(&ldo->refcount);
38136 module_put(ldo->owner);
38137 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38138
38139 @@ -110,7 +110,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38140 spin_lock_irqsave(&tty_ldisc_lock, flags);
38141 tty_ldiscs[disc] = new_ldisc;
38142 new_ldisc->num = disc;
38143 - new_ldisc->refcount = 0;
38144 + atomic_set(&new_ldisc->refcount, 0);
38145 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38146
38147 return ret;
38148 @@ -138,7 +138,7 @@ int tty_unregister_ldisc(int disc)
38149 return -EINVAL;
38150
38151 spin_lock_irqsave(&tty_ldisc_lock, flags);
38152 - if (tty_ldiscs[disc]->refcount)
38153 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38154 ret = -EBUSY;
38155 else
38156 tty_ldiscs[disc] = NULL;
38157 @@ -159,7 +159,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38158 if (ldops) {
38159 ret = ERR_PTR(-EAGAIN);
38160 if (try_module_get(ldops->owner)) {
38161 - ldops->refcount++;
38162 + atomic_inc(&ldops->refcount);
38163 ret = ldops;
38164 }
38165 }
38166 @@ -172,7 +172,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38167 unsigned long flags;
38168
38169 spin_lock_irqsave(&tty_ldisc_lock, flags);
38170 - ldops->refcount--;
38171 + atomic_dec(&ldops->refcount);
38172 module_put(ldops->owner);
38173 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38174 }
38175 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38176 index 3761ccf..2c613b3 100644
38177 --- a/drivers/tty/vt/keyboard.c
38178 +++ b/drivers/tty/vt/keyboard.c
38179 @@ -656,6 +656,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38180 kbd->kbdmode == VC_OFF) &&
38181 value != KVAL(K_SAK))
38182 return; /* SAK is allowed even in raw mode */
38183 +
38184 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38185 + {
38186 + void *func = fn_handler[value];
38187 + if (func == fn_show_state || func == fn_show_ptregs ||
38188 + func == fn_show_mem)
38189 + return;
38190 + }
38191 +#endif
38192 +
38193 fn_handler[value](vc);
38194 }
38195
38196 diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
38197 index b3915b7..e716839 100644
38198 --- a/drivers/tty/vt/vt.c
38199 +++ b/drivers/tty/vt/vt.c
38200 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier);
38201
38202 static void notify_write(struct vc_data *vc, unsigned int unicode)
38203 {
38204 - struct vt_notifier_param param = { .vc = vc, unicode = unicode };
38205 + struct vt_notifier_param param = { .vc = vc, .c = unicode };
38206 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
38207 }
38208
38209 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
38210 index 5e096f4..0da1363 100644
38211 --- a/drivers/tty/vt/vt_ioctl.c
38212 +++ b/drivers/tty/vt/vt_ioctl.c
38213 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38214 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38215 return -EFAULT;
38216
38217 - if (!capable(CAP_SYS_TTY_CONFIG))
38218 - perm = 0;
38219 -
38220 switch (cmd) {
38221 case KDGKBENT:
38222 key_map = key_maps[s];
38223 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38224 val = (i ? K_HOLE : K_NOSUCHMAP);
38225 return put_user(val, &user_kbe->kb_value);
38226 case KDSKBENT:
38227 + if (!capable(CAP_SYS_TTY_CONFIG))
38228 + perm = 0;
38229 +
38230 if (!perm)
38231 return -EPERM;
38232 if (!i && v == K_NOSUCHMAP) {
38233 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38234 int i, j, k;
38235 int ret;
38236
38237 - if (!capable(CAP_SYS_TTY_CONFIG))
38238 - perm = 0;
38239 -
38240 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38241 if (!kbs) {
38242 ret = -ENOMEM;
38243 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38244 kfree(kbs);
38245 return ((p && *p) ? -EOVERFLOW : 0);
38246 case KDSKBSENT:
38247 + if (!capable(CAP_SYS_TTY_CONFIG))
38248 + perm = 0;
38249 +
38250 if (!perm) {
38251 ret = -EPERM;
38252 goto reterr;
38253 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38254 index d2efe82..9440ab6 100644
38255 --- a/drivers/uio/uio.c
38256 +++ b/drivers/uio/uio.c
38257 @@ -25,6 +25,7 @@
38258 #include <linux/kobject.h>
38259 #include <linux/cdev.h>
38260 #include <linux/uio_driver.h>
38261 +#include <asm/local.h>
38262
38263 #define UIO_MAX_DEVICES (1U << MINORBITS)
38264
38265 @@ -32,10 +33,10 @@ struct uio_device {
38266 struct module *owner;
38267 struct device *dev;
38268 int minor;
38269 - atomic_t event;
38270 + atomic_unchecked_t event;
38271 struct fasync_struct *async_queue;
38272 wait_queue_head_t wait;
38273 - int vma_count;
38274 + local_t vma_count;
38275 struct uio_info *info;
38276 struct kobject *map_dir;
38277 struct kobject *portio_dir;
38278 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38279 struct device_attribute *attr, char *buf)
38280 {
38281 struct uio_device *idev = dev_get_drvdata(dev);
38282 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38283 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38284 }
38285
38286 static struct device_attribute uio_class_attributes[] = {
38287 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38288 {
38289 struct uio_device *idev = info->uio_dev;
38290
38291 - atomic_inc(&idev->event);
38292 + atomic_inc_unchecked(&idev->event);
38293 wake_up_interruptible(&idev->wait);
38294 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38295 }
38296 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38297 }
38298
38299 listener->dev = idev;
38300 - listener->event_count = atomic_read(&idev->event);
38301 + listener->event_count = atomic_read_unchecked(&idev->event);
38302 filep->private_data = listener;
38303
38304 if (idev->info->open) {
38305 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38306 return -EIO;
38307
38308 poll_wait(filep, &idev->wait, wait);
38309 - if (listener->event_count != atomic_read(&idev->event))
38310 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38311 return POLLIN | POLLRDNORM;
38312 return 0;
38313 }
38314 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38315 do {
38316 set_current_state(TASK_INTERRUPTIBLE);
38317
38318 - event_count = atomic_read(&idev->event);
38319 + event_count = atomic_read_unchecked(&idev->event);
38320 if (event_count != listener->event_count) {
38321 if (copy_to_user(buf, &event_count, count))
38322 retval = -EFAULT;
38323 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38324 static void uio_vma_open(struct vm_area_struct *vma)
38325 {
38326 struct uio_device *idev = vma->vm_private_data;
38327 - idev->vma_count++;
38328 + local_inc(&idev->vma_count);
38329 }
38330
38331 static void uio_vma_close(struct vm_area_struct *vma)
38332 {
38333 struct uio_device *idev = vma->vm_private_data;
38334 - idev->vma_count--;
38335 + local_dec(&idev->vma_count);
38336 }
38337
38338 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38339 @@ -823,7 +824,7 @@ int __uio_register_device(struct module *owner,
38340 idev->owner = owner;
38341 idev->info = info;
38342 init_waitqueue_head(&idev->wait);
38343 - atomic_set(&idev->event, 0);
38344 + atomic_set_unchecked(&idev->event, 0);
38345
38346 ret = uio_get_minor(idev);
38347 if (ret)
38348 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38349 index a845f8b..4f54072 100644
38350 --- a/drivers/usb/atm/cxacru.c
38351 +++ b/drivers/usb/atm/cxacru.c
38352 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38353 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38354 if (ret < 2)
38355 return -EINVAL;
38356 - if (index < 0 || index > 0x7f)
38357 + if (index > 0x7f)
38358 return -EINVAL;
38359 pos += tmp;
38360
38361 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38362 index d3448ca..d2864ca 100644
38363 --- a/drivers/usb/atm/usbatm.c
38364 +++ b/drivers/usb/atm/usbatm.c
38365 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38366 if (printk_ratelimit())
38367 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38368 __func__, vpi, vci);
38369 - atomic_inc(&vcc->stats->rx_err);
38370 + atomic_inc_unchecked(&vcc->stats->rx_err);
38371 return;
38372 }
38373
38374 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38375 if (length > ATM_MAX_AAL5_PDU) {
38376 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38377 __func__, length, vcc);
38378 - atomic_inc(&vcc->stats->rx_err);
38379 + atomic_inc_unchecked(&vcc->stats->rx_err);
38380 goto out;
38381 }
38382
38383 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38384 if (sarb->len < pdu_length) {
38385 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38386 __func__, pdu_length, sarb->len, vcc);
38387 - atomic_inc(&vcc->stats->rx_err);
38388 + atomic_inc_unchecked(&vcc->stats->rx_err);
38389 goto out;
38390 }
38391
38392 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38393 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38394 __func__, vcc);
38395 - atomic_inc(&vcc->stats->rx_err);
38396 + atomic_inc_unchecked(&vcc->stats->rx_err);
38397 goto out;
38398 }
38399
38400 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38401 if (printk_ratelimit())
38402 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38403 __func__, length);
38404 - atomic_inc(&vcc->stats->rx_drop);
38405 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38406 goto out;
38407 }
38408
38409 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38410
38411 vcc->push(vcc, skb);
38412
38413 - atomic_inc(&vcc->stats->rx);
38414 + atomic_inc_unchecked(&vcc->stats->rx);
38415 out:
38416 skb_trim(sarb, 0);
38417 }
38418 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38419 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38420
38421 usbatm_pop(vcc, skb);
38422 - atomic_inc(&vcc->stats->tx);
38423 + atomic_inc_unchecked(&vcc->stats->tx);
38424
38425 skb = skb_dequeue(&instance->sndqueue);
38426 }
38427 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38428 if (!left--)
38429 return sprintf(page,
38430 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38431 - atomic_read(&atm_dev->stats.aal5.tx),
38432 - atomic_read(&atm_dev->stats.aal5.tx_err),
38433 - atomic_read(&atm_dev->stats.aal5.rx),
38434 - atomic_read(&atm_dev->stats.aal5.rx_err),
38435 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38436 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38437 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38438 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38439 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38440 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38441
38442 if (!left--) {
38443 if (instance->disconnected)
38444 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38445 index 0149c09..f108812 100644
38446 --- a/drivers/usb/core/devices.c
38447 +++ b/drivers/usb/core/devices.c
38448 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38449 * time it gets called.
38450 */
38451 static struct device_connect_event {
38452 - atomic_t count;
38453 + atomic_unchecked_t count;
38454 wait_queue_head_t wait;
38455 } device_event = {
38456 .count = ATOMIC_INIT(1),
38457 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38458
38459 void usbfs_conn_disc_event(void)
38460 {
38461 - atomic_add(2, &device_event.count);
38462 + atomic_add_unchecked(2, &device_event.count);
38463 wake_up(&device_event.wait);
38464 }
38465
38466 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38467
38468 poll_wait(file, &device_event.wait, wait);
38469
38470 - event_count = atomic_read(&device_event.count);
38471 + event_count = atomic_read_unchecked(&device_event.count);
38472 if (file->f_version != event_count) {
38473 file->f_version = event_count;
38474 return POLLIN | POLLRDNORM;
38475 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
38476 index 0b5ec23..0da3d76 100644
38477 --- a/drivers/usb/core/message.c
38478 +++ b/drivers/usb/core/message.c
38479 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
38480 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
38481 if (buf) {
38482 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
38483 - if (len > 0) {
38484 - smallbuf = kmalloc(++len, GFP_NOIO);
38485 + if (len++ > 0) {
38486 + smallbuf = kmalloc(len, GFP_NOIO);
38487 if (!smallbuf)
38488 return buf;
38489 memcpy(smallbuf, buf, len);
38490 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38491 index 1fc8f12..20647c1 100644
38492 --- a/drivers/usb/early/ehci-dbgp.c
38493 +++ b/drivers/usb/early/ehci-dbgp.c
38494 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38495
38496 #ifdef CONFIG_KGDB
38497 static struct kgdb_io kgdbdbgp_io_ops;
38498 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38499 +static struct kgdb_io kgdbdbgp_io_ops_console;
38500 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38501 #else
38502 #define dbgp_kgdb_mode (0)
38503 #endif
38504 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38505 .write_char = kgdbdbgp_write_char,
38506 };
38507
38508 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38509 + .name = "kgdbdbgp",
38510 + .read_char = kgdbdbgp_read_char,
38511 + .write_char = kgdbdbgp_write_char,
38512 + .is_console = 1
38513 +};
38514 +
38515 static int kgdbdbgp_wait_time;
38516
38517 static int __init kgdbdbgp_parse_config(char *str)
38518 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38519 ptr++;
38520 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38521 }
38522 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38523 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38524 + if (early_dbgp_console.index != -1)
38525 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38526 + else
38527 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38528
38529 return 0;
38530 }
38531 diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
38532 index d718033..6075579 100644
38533 --- a/drivers/usb/host/xhci-mem.c
38534 +++ b/drivers/usb/host/xhci-mem.c
38535 @@ -1685,6 +1685,8 @@ static int xhci_check_trb_in_td_math(struct xhci_hcd *xhci, gfp_t mem_flags)
38536 unsigned int num_tests;
38537 int i, ret;
38538
38539 + pax_track_stack();
38540 +
38541 num_tests = ARRAY_SIZE(simple_test_vector);
38542 for (i = 0; i < num_tests; i++) {
38543 ret = xhci_test_trb_in_td(xhci,
38544 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38545 index d6bea3e..60b250e 100644
38546 --- a/drivers/usb/wusbcore/wa-hc.h
38547 +++ b/drivers/usb/wusbcore/wa-hc.h
38548 @@ -192,7 +192,7 @@ struct wahc {
38549 struct list_head xfer_delayed_list;
38550 spinlock_t xfer_list_lock;
38551 struct work_struct xfer_work;
38552 - atomic_t xfer_id_count;
38553 + atomic_unchecked_t xfer_id_count;
38554 };
38555
38556
38557 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38558 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38559 spin_lock_init(&wa->xfer_list_lock);
38560 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38561 - atomic_set(&wa->xfer_id_count, 1);
38562 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38563 }
38564
38565 /**
38566 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38567 index 4193345..49ae93d 100644
38568 --- a/drivers/usb/wusbcore/wa-xfer.c
38569 +++ b/drivers/usb/wusbcore/wa-xfer.c
38570 @@ -295,7 +295,7 @@ out:
38571 */
38572 static void wa_xfer_id_init(struct wa_xfer *xfer)
38573 {
38574 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38575 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38576 }
38577
38578 /*
38579 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38580 index c14c42b..f955cc2 100644
38581 --- a/drivers/vhost/vhost.c
38582 +++ b/drivers/vhost/vhost.c
38583 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38584 return 0;
38585 }
38586
38587 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38588 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38589 {
38590 struct file *eventfp, *filep = NULL,
38591 *pollstart = NULL, *pollstop = NULL;
38592 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38593 index b0b2ac3..89a4399 100644
38594 --- a/drivers/video/aty/aty128fb.c
38595 +++ b/drivers/video/aty/aty128fb.c
38596 @@ -148,7 +148,7 @@ enum {
38597 };
38598
38599 /* Must match above enum */
38600 -static const char *r128_family[] __devinitdata = {
38601 +static const char *r128_family[] __devinitconst = {
38602 "AGP",
38603 "PCI",
38604 "PRO AGP",
38605 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38606 index 5c3960d..15cf8fc 100644
38607 --- a/drivers/video/fbcmap.c
38608 +++ b/drivers/video/fbcmap.c
38609 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38610 rc = -ENODEV;
38611 goto out;
38612 }
38613 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38614 - !info->fbops->fb_setcmap)) {
38615 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38616 rc = -EINVAL;
38617 goto out1;
38618 }
38619 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38620 index ad93629..ca6a218 100644
38621 --- a/drivers/video/fbmem.c
38622 +++ b/drivers/video/fbmem.c
38623 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38624 image->dx += image->width + 8;
38625 }
38626 } else if (rotate == FB_ROTATE_UD) {
38627 - for (x = 0; x < num && image->dx >= 0; x++) {
38628 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38629 info->fbops->fb_imageblit(info, image);
38630 image->dx -= image->width + 8;
38631 }
38632 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38633 image->dy += image->height + 8;
38634 }
38635 } else if (rotate == FB_ROTATE_CCW) {
38636 - for (x = 0; x < num && image->dy >= 0; x++) {
38637 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38638 info->fbops->fb_imageblit(info, image);
38639 image->dy -= image->height + 8;
38640 }
38641 @@ -939,6 +939,8 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
38642 int flags = info->flags;
38643 int ret = 0;
38644
38645 + pax_track_stack();
38646 +
38647 if (var->activate & FB_ACTIVATE_INV_MODE) {
38648 struct fb_videomode mode1, mode2;
38649
38650 @@ -1064,6 +1066,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38651 void __user *argp = (void __user *)arg;
38652 long ret = 0;
38653
38654 + pax_track_stack();
38655 +
38656 switch (cmd) {
38657 case FBIOGET_VSCREENINFO:
38658 if (!lock_fb_info(info))
38659 @@ -1143,7 +1147,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38660 return -EFAULT;
38661 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38662 return -EINVAL;
38663 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38664 + if (con2fb.framebuffer >= FB_MAX)
38665 return -EINVAL;
38666 if (!registered_fb[con2fb.framebuffer])
38667 request_module("fb%d", con2fb.framebuffer);
38668 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38669 index 5a5d092..265c5ed 100644
38670 --- a/drivers/video/geode/gx1fb_core.c
38671 +++ b/drivers/video/geode/gx1fb_core.c
38672 @@ -29,7 +29,7 @@ static int crt_option = 1;
38673 static char panel_option[32] = "";
38674
38675 /* Modes relevant to the GX1 (taken from modedb.c) */
38676 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
38677 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
38678 /* 640x480-60 VESA */
38679 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38680 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38681 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38682 index 896e53d..4d87d0b 100644
38683 --- a/drivers/video/gxt4500.c
38684 +++ b/drivers/video/gxt4500.c
38685 @@ -156,7 +156,7 @@ struct gxt4500_par {
38686 static char *mode_option;
38687
38688 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38689 -static const struct fb_videomode defaultmode __devinitdata = {
38690 +static const struct fb_videomode defaultmode __devinitconst = {
38691 .refresh = 60,
38692 .xres = 1280,
38693 .yres = 1024,
38694 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38695 return 0;
38696 }
38697
38698 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38699 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38700 .id = "IBM GXT4500P",
38701 .type = FB_TYPE_PACKED_PIXELS,
38702 .visual = FB_VISUAL_PSEUDOCOLOR,
38703 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38704 index 7672d2e..b56437f 100644
38705 --- a/drivers/video/i810/i810_accel.c
38706 +++ b/drivers/video/i810/i810_accel.c
38707 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38708 }
38709 }
38710 printk("ringbuffer lockup!!!\n");
38711 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38712 i810_report_error(mmio);
38713 par->dev_flags |= LOCKUP;
38714 info->pixmap.scan_align = 1;
38715 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38716 index 318f6fb..9a389c1 100644
38717 --- a/drivers/video/i810/i810_main.c
38718 +++ b/drivers/video/i810/i810_main.c
38719 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38720 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38721
38722 /* PCI */
38723 -static const char *i810_pci_list[] __devinitdata = {
38724 +static const char *i810_pci_list[] __devinitconst = {
38725 "Intel(R) 810 Framebuffer Device" ,
38726 "Intel(R) 810-DC100 Framebuffer Device" ,
38727 "Intel(R) 810E Framebuffer Device" ,
38728 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38729 index de36693..3c63fc2 100644
38730 --- a/drivers/video/jz4740_fb.c
38731 +++ b/drivers/video/jz4740_fb.c
38732 @@ -136,7 +136,7 @@ struct jzfb {
38733 uint32_t pseudo_palette[16];
38734 };
38735
38736 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38737 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38738 .id = "JZ4740 FB",
38739 .type = FB_TYPE_PACKED_PIXELS,
38740 .visual = FB_VISUAL_TRUECOLOR,
38741 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38742 index 3c14e43..eafa544 100644
38743 --- a/drivers/video/logo/logo_linux_clut224.ppm
38744 +++ b/drivers/video/logo/logo_linux_clut224.ppm
38745 @@ -1,1604 +1,1123 @@
38746 P3
38747 -# Standard 224-color Linux logo
38748 80 80
38749 255
38750 - 0 0 0 0 0 0 0 0 0 0 0 0
38751 - 0 0 0 0 0 0 0 0 0 0 0 0
38752 - 0 0 0 0 0 0 0 0 0 0 0 0
38753 - 0 0 0 0 0 0 0 0 0 0 0 0
38754 - 0 0 0 0 0 0 0 0 0 0 0 0
38755 - 0 0 0 0 0 0 0 0 0 0 0 0
38756 - 0 0 0 0 0 0 0 0 0 0 0 0
38757 - 0 0 0 0 0 0 0 0 0 0 0 0
38758 - 0 0 0 0 0 0 0 0 0 0 0 0
38759 - 6 6 6 6 6 6 10 10 10 10 10 10
38760 - 10 10 10 6 6 6 6 6 6 6 6 6
38761 - 0 0 0 0 0 0 0 0 0 0 0 0
38762 - 0 0 0 0 0 0 0 0 0 0 0 0
38763 - 0 0 0 0 0 0 0 0 0 0 0 0
38764 - 0 0 0 0 0 0 0 0 0 0 0 0
38765 - 0 0 0 0 0 0 0 0 0 0 0 0
38766 - 0 0 0 0 0 0 0 0 0 0 0 0
38767 - 0 0 0 0 0 0 0 0 0 0 0 0
38768 - 0 0 0 0 0 0 0 0 0 0 0 0
38769 - 0 0 0 0 0 0 0 0 0 0 0 0
38770 - 0 0 0 0 0 0 0 0 0 0 0 0
38771 - 0 0 0 0 0 0 0 0 0 0 0 0
38772 - 0 0 0 0 0 0 0 0 0 0 0 0
38773 - 0 0 0 0 0 0 0 0 0 0 0 0
38774 - 0 0 0 0 0 0 0 0 0 0 0 0
38775 - 0 0 0 0 0 0 0 0 0 0 0 0
38776 - 0 0 0 0 0 0 0 0 0 0 0 0
38777 - 0 0 0 0 0 0 0 0 0 0 0 0
38778 - 0 0 0 6 6 6 10 10 10 14 14 14
38779 - 22 22 22 26 26 26 30 30 30 34 34 34
38780 - 30 30 30 30 30 30 26 26 26 18 18 18
38781 - 14 14 14 10 10 10 6 6 6 0 0 0
38782 - 0 0 0 0 0 0 0 0 0 0 0 0
38783 - 0 0 0 0 0 0 0 0 0 0 0 0
38784 - 0 0 0 0 0 0 0 0 0 0 0 0
38785 - 0 0 0 0 0 0 0 0 0 0 0 0
38786 - 0 0 0 0 0 0 0 0 0 0 0 0
38787 - 0 0 0 0 0 0 0 0 0 0 0 0
38788 - 0 0 0 0 0 0 0 0 0 0 0 0
38789 - 0 0 0 0 0 0 0 0 0 0 0 0
38790 - 0 0 0 0 0 0 0 0 0 0 0 0
38791 - 0 0 0 0 0 1 0 0 1 0 0 0
38792 - 0 0 0 0 0 0 0 0 0 0 0 0
38793 - 0 0 0 0 0 0 0 0 0 0 0 0
38794 - 0 0 0 0 0 0 0 0 0 0 0 0
38795 - 0 0 0 0 0 0 0 0 0 0 0 0
38796 - 0 0 0 0 0 0 0 0 0 0 0 0
38797 - 0 0 0 0 0 0 0 0 0 0 0 0
38798 - 6 6 6 14 14 14 26 26 26 42 42 42
38799 - 54 54 54 66 66 66 78 78 78 78 78 78
38800 - 78 78 78 74 74 74 66 66 66 54 54 54
38801 - 42 42 42 26 26 26 18 18 18 10 10 10
38802 - 6 6 6 0 0 0 0 0 0 0 0 0
38803 - 0 0 0 0 0 0 0 0 0 0 0 0
38804 - 0 0 0 0 0 0 0 0 0 0 0 0
38805 - 0 0 0 0 0 0 0 0 0 0 0 0
38806 - 0 0 0 0 0 0 0 0 0 0 0 0
38807 - 0 0 0 0 0 0 0 0 0 0 0 0
38808 - 0 0 0 0 0 0 0 0 0 0 0 0
38809 - 0 0 0 0 0 0 0 0 0 0 0 0
38810 - 0 0 0 0 0 0 0 0 0 0 0 0
38811 - 0 0 1 0 0 0 0 0 0 0 0 0
38812 - 0 0 0 0 0 0 0 0 0 0 0 0
38813 - 0 0 0 0 0 0 0 0 0 0 0 0
38814 - 0 0 0 0 0 0 0 0 0 0 0 0
38815 - 0 0 0 0 0 0 0 0 0 0 0 0
38816 - 0 0 0 0 0 0 0 0 0 0 0 0
38817 - 0 0 0 0 0 0 0 0 0 10 10 10
38818 - 22 22 22 42 42 42 66 66 66 86 86 86
38819 - 66 66 66 38 38 38 38 38 38 22 22 22
38820 - 26 26 26 34 34 34 54 54 54 66 66 66
38821 - 86 86 86 70 70 70 46 46 46 26 26 26
38822 - 14 14 14 6 6 6 0 0 0 0 0 0
38823 - 0 0 0 0 0 0 0 0 0 0 0 0
38824 - 0 0 0 0 0 0 0 0 0 0 0 0
38825 - 0 0 0 0 0 0 0 0 0 0 0 0
38826 - 0 0 0 0 0 0 0 0 0 0 0 0
38827 - 0 0 0 0 0 0 0 0 0 0 0 0
38828 - 0 0 0 0 0 0 0 0 0 0 0 0
38829 - 0 0 0 0 0 0 0 0 0 0 0 0
38830 - 0 0 0 0 0 0 0 0 0 0 0 0
38831 - 0 0 1 0 0 1 0 0 1 0 0 0
38832 - 0 0 0 0 0 0 0 0 0 0 0 0
38833 - 0 0 0 0 0 0 0 0 0 0 0 0
38834 - 0 0 0 0 0 0 0 0 0 0 0 0
38835 - 0 0 0 0 0 0 0 0 0 0 0 0
38836 - 0 0 0 0 0 0 0 0 0 0 0 0
38837 - 0 0 0 0 0 0 10 10 10 26 26 26
38838 - 50 50 50 82 82 82 58 58 58 6 6 6
38839 - 2 2 6 2 2 6 2 2 6 2 2 6
38840 - 2 2 6 2 2 6 2 2 6 2 2 6
38841 - 6 6 6 54 54 54 86 86 86 66 66 66
38842 - 38 38 38 18 18 18 6 6 6 0 0 0
38843 - 0 0 0 0 0 0 0 0 0 0 0 0
38844 - 0 0 0 0 0 0 0 0 0 0 0 0
38845 - 0 0 0 0 0 0 0 0 0 0 0 0
38846 - 0 0 0 0 0 0 0 0 0 0 0 0
38847 - 0 0 0 0 0 0 0 0 0 0 0 0
38848 - 0 0 0 0 0 0 0 0 0 0 0 0
38849 - 0 0 0 0 0 0 0 0 0 0 0 0
38850 - 0 0 0 0 0 0 0 0 0 0 0 0
38851 - 0 0 0 0 0 0 0 0 0 0 0 0
38852 - 0 0 0 0 0 0 0 0 0 0 0 0
38853 - 0 0 0 0 0 0 0 0 0 0 0 0
38854 - 0 0 0 0 0 0 0 0 0 0 0 0
38855 - 0 0 0 0 0 0 0 0 0 0 0 0
38856 - 0 0 0 0 0 0 0 0 0 0 0 0
38857 - 0 0 0 6 6 6 22 22 22 50 50 50
38858 - 78 78 78 34 34 34 2 2 6 2 2 6
38859 - 2 2 6 2 2 6 2 2 6 2 2 6
38860 - 2 2 6 2 2 6 2 2 6 2 2 6
38861 - 2 2 6 2 2 6 6 6 6 70 70 70
38862 - 78 78 78 46 46 46 22 22 22 6 6 6
38863 - 0 0 0 0 0 0 0 0 0 0 0 0
38864 - 0 0 0 0 0 0 0 0 0 0 0 0
38865 - 0 0 0 0 0 0 0 0 0 0 0 0
38866 - 0 0 0 0 0 0 0 0 0 0 0 0
38867 - 0 0 0 0 0 0 0 0 0 0 0 0
38868 - 0 0 0 0 0 0 0 0 0 0 0 0
38869 - 0 0 0 0 0 0 0 0 0 0 0 0
38870 - 0 0 0 0 0 0 0 0 0 0 0 0
38871 - 0 0 1 0 0 1 0 0 1 0 0 0
38872 - 0 0 0 0 0 0 0 0 0 0 0 0
38873 - 0 0 0 0 0 0 0 0 0 0 0 0
38874 - 0 0 0 0 0 0 0 0 0 0 0 0
38875 - 0 0 0 0 0 0 0 0 0 0 0 0
38876 - 0 0 0 0 0 0 0 0 0 0 0 0
38877 - 6 6 6 18 18 18 42 42 42 82 82 82
38878 - 26 26 26 2 2 6 2 2 6 2 2 6
38879 - 2 2 6 2 2 6 2 2 6 2 2 6
38880 - 2 2 6 2 2 6 2 2 6 14 14 14
38881 - 46 46 46 34 34 34 6 6 6 2 2 6
38882 - 42 42 42 78 78 78 42 42 42 18 18 18
38883 - 6 6 6 0 0 0 0 0 0 0 0 0
38884 - 0 0 0 0 0 0 0 0 0 0 0 0
38885 - 0 0 0 0 0 0 0 0 0 0 0 0
38886 - 0 0 0 0 0 0 0 0 0 0 0 0
38887 - 0 0 0 0 0 0 0 0 0 0 0 0
38888 - 0 0 0 0 0 0 0 0 0 0 0 0
38889 - 0 0 0 0 0 0 0 0 0 0 0 0
38890 - 0 0 0 0 0 0 0 0 0 0 0 0
38891 - 0 0 1 0 0 0 0 0 1 0 0 0
38892 - 0 0 0 0 0 0 0 0 0 0 0 0
38893 - 0 0 0 0 0 0 0 0 0 0 0 0
38894 - 0 0 0 0 0 0 0 0 0 0 0 0
38895 - 0 0 0 0 0 0 0 0 0 0 0 0
38896 - 0 0 0 0 0 0 0 0 0 0 0 0
38897 - 10 10 10 30 30 30 66 66 66 58 58 58
38898 - 2 2 6 2 2 6 2 2 6 2 2 6
38899 - 2 2 6 2 2 6 2 2 6 2 2 6
38900 - 2 2 6 2 2 6 2 2 6 26 26 26
38901 - 86 86 86 101 101 101 46 46 46 10 10 10
38902 - 2 2 6 58 58 58 70 70 70 34 34 34
38903 - 10 10 10 0 0 0 0 0 0 0 0 0
38904 - 0 0 0 0 0 0 0 0 0 0 0 0
38905 - 0 0 0 0 0 0 0 0 0 0 0 0
38906 - 0 0 0 0 0 0 0 0 0 0 0 0
38907 - 0 0 0 0 0 0 0 0 0 0 0 0
38908 - 0 0 0 0 0 0 0 0 0 0 0 0
38909 - 0 0 0 0 0 0 0 0 0 0 0 0
38910 - 0 0 0 0 0 0 0 0 0 0 0 0
38911 - 0 0 1 0 0 1 0 0 1 0 0 0
38912 - 0 0 0 0 0 0 0 0 0 0 0 0
38913 - 0 0 0 0 0 0 0 0 0 0 0 0
38914 - 0 0 0 0 0 0 0 0 0 0 0 0
38915 - 0 0 0 0 0 0 0 0 0 0 0 0
38916 - 0 0 0 0 0 0 0 0 0 0 0 0
38917 - 14 14 14 42 42 42 86 86 86 10 10 10
38918 - 2 2 6 2 2 6 2 2 6 2 2 6
38919 - 2 2 6 2 2 6 2 2 6 2 2 6
38920 - 2 2 6 2 2 6 2 2 6 30 30 30
38921 - 94 94 94 94 94 94 58 58 58 26 26 26
38922 - 2 2 6 6 6 6 78 78 78 54 54 54
38923 - 22 22 22 6 6 6 0 0 0 0 0 0
38924 - 0 0 0 0 0 0 0 0 0 0 0 0
38925 - 0 0 0 0 0 0 0 0 0 0 0 0
38926 - 0 0 0 0 0 0 0 0 0 0 0 0
38927 - 0 0 0 0 0 0 0 0 0 0 0 0
38928 - 0 0 0 0 0 0 0 0 0 0 0 0
38929 - 0 0 0 0 0 0 0 0 0 0 0 0
38930 - 0 0 0 0 0 0 0 0 0 0 0 0
38931 - 0 0 0 0 0 0 0 0 0 0 0 0
38932 - 0 0 0 0 0 0 0 0 0 0 0 0
38933 - 0 0 0 0 0 0 0 0 0 0 0 0
38934 - 0 0 0 0 0 0 0 0 0 0 0 0
38935 - 0 0 0 0 0 0 0 0 0 0 0 0
38936 - 0 0 0 0 0 0 0 0 0 6 6 6
38937 - 22 22 22 62 62 62 62 62 62 2 2 6
38938 - 2 2 6 2 2 6 2 2 6 2 2 6
38939 - 2 2 6 2 2 6 2 2 6 2 2 6
38940 - 2 2 6 2 2 6 2 2 6 26 26 26
38941 - 54 54 54 38 38 38 18 18 18 10 10 10
38942 - 2 2 6 2 2 6 34 34 34 82 82 82
38943 - 38 38 38 14 14 14 0 0 0 0 0 0
38944 - 0 0 0 0 0 0 0 0 0 0 0 0
38945 - 0 0 0 0 0 0 0 0 0 0 0 0
38946 - 0 0 0 0 0 0 0 0 0 0 0 0
38947 - 0 0 0 0 0 0 0 0 0 0 0 0
38948 - 0 0 0 0 0 0 0 0 0 0 0 0
38949 - 0 0 0 0 0 0 0 0 0 0 0 0
38950 - 0 0 0 0 0 0 0 0 0 0 0 0
38951 - 0 0 0 0 0 1 0 0 1 0 0 0
38952 - 0 0 0 0 0 0 0 0 0 0 0 0
38953 - 0 0 0 0 0 0 0 0 0 0 0 0
38954 - 0 0 0 0 0 0 0 0 0 0 0 0
38955 - 0 0 0 0 0 0 0 0 0 0 0 0
38956 - 0 0 0 0 0 0 0 0 0 6 6 6
38957 - 30 30 30 78 78 78 30 30 30 2 2 6
38958 - 2 2 6 2 2 6 2 2 6 2 2 6
38959 - 2 2 6 2 2 6 2 2 6 2 2 6
38960 - 2 2 6 2 2 6 2 2 6 10 10 10
38961 - 10 10 10 2 2 6 2 2 6 2 2 6
38962 - 2 2 6 2 2 6 2 2 6 78 78 78
38963 - 50 50 50 18 18 18 6 6 6 0 0 0
38964 - 0 0 0 0 0 0 0 0 0 0 0 0
38965 - 0 0 0 0 0 0 0 0 0 0 0 0
38966 - 0 0 0 0 0 0 0 0 0 0 0 0
38967 - 0 0 0 0 0 0 0 0 0 0 0 0
38968 - 0 0 0 0 0 0 0 0 0 0 0 0
38969 - 0 0 0 0 0 0 0 0 0 0 0 0
38970 - 0 0 0 0 0 0 0 0 0 0 0 0
38971 - 0 0 1 0 0 0 0 0 0 0 0 0
38972 - 0 0 0 0 0 0 0 0 0 0 0 0
38973 - 0 0 0 0 0 0 0 0 0 0 0 0
38974 - 0 0 0 0 0 0 0 0 0 0 0 0
38975 - 0 0 0 0 0 0 0 0 0 0 0 0
38976 - 0 0 0 0 0 0 0 0 0 10 10 10
38977 - 38 38 38 86 86 86 14 14 14 2 2 6
38978 - 2 2 6 2 2 6 2 2 6 2 2 6
38979 - 2 2 6 2 2 6 2 2 6 2 2 6
38980 - 2 2 6 2 2 6 2 2 6 2 2 6
38981 - 2 2 6 2 2 6 2 2 6 2 2 6
38982 - 2 2 6 2 2 6 2 2 6 54 54 54
38983 - 66 66 66 26 26 26 6 6 6 0 0 0
38984 - 0 0 0 0 0 0 0 0 0 0 0 0
38985 - 0 0 0 0 0 0 0 0 0 0 0 0
38986 - 0 0 0 0 0 0 0 0 0 0 0 0
38987 - 0 0 0 0 0 0 0 0 0 0 0 0
38988 - 0 0 0 0 0 0 0 0 0 0 0 0
38989 - 0 0 0 0 0 0 0 0 0 0 0 0
38990 - 0 0 0 0 0 0 0 0 0 0 0 0
38991 - 0 0 0 0 0 1 0 0 1 0 0 0
38992 - 0 0 0 0 0 0 0 0 0 0 0 0
38993 - 0 0 0 0 0 0 0 0 0 0 0 0
38994 - 0 0 0 0 0 0 0 0 0 0 0 0
38995 - 0 0 0 0 0 0 0 0 0 0 0 0
38996 - 0 0 0 0 0 0 0 0 0 14 14 14
38997 - 42 42 42 82 82 82 2 2 6 2 2 6
38998 - 2 2 6 6 6 6 10 10 10 2 2 6
38999 - 2 2 6 2 2 6 2 2 6 2 2 6
39000 - 2 2 6 2 2 6 2 2 6 6 6 6
39001 - 14 14 14 10 10 10 2 2 6 2 2 6
39002 - 2 2 6 2 2 6 2 2 6 18 18 18
39003 - 82 82 82 34 34 34 10 10 10 0 0 0
39004 - 0 0 0 0 0 0 0 0 0 0 0 0
39005 - 0 0 0 0 0 0 0 0 0 0 0 0
39006 - 0 0 0 0 0 0 0 0 0 0 0 0
39007 - 0 0 0 0 0 0 0 0 0 0 0 0
39008 - 0 0 0 0 0 0 0 0 0 0 0 0
39009 - 0 0 0 0 0 0 0 0 0 0 0 0
39010 - 0 0 0 0 0 0 0 0 0 0 0 0
39011 - 0 0 1 0 0 0 0 0 0 0 0 0
39012 - 0 0 0 0 0 0 0 0 0 0 0 0
39013 - 0 0 0 0 0 0 0 0 0 0 0 0
39014 - 0 0 0 0 0 0 0 0 0 0 0 0
39015 - 0 0 0 0 0 0 0 0 0 0 0 0
39016 - 0 0 0 0 0 0 0 0 0 14 14 14
39017 - 46 46 46 86 86 86 2 2 6 2 2 6
39018 - 6 6 6 6 6 6 22 22 22 34 34 34
39019 - 6 6 6 2 2 6 2 2 6 2 2 6
39020 - 2 2 6 2 2 6 18 18 18 34 34 34
39021 - 10 10 10 50 50 50 22 22 22 2 2 6
39022 - 2 2 6 2 2 6 2 2 6 10 10 10
39023 - 86 86 86 42 42 42 14 14 14 0 0 0
39024 - 0 0 0 0 0 0 0 0 0 0 0 0
39025 - 0 0 0 0 0 0 0 0 0 0 0 0
39026 - 0 0 0 0 0 0 0 0 0 0 0 0
39027 - 0 0 0 0 0 0 0 0 0 0 0 0
39028 - 0 0 0 0 0 0 0 0 0 0 0 0
39029 - 0 0 0 0 0 0 0 0 0 0 0 0
39030 - 0 0 0 0 0 0 0 0 0 0 0 0
39031 - 0 0 1 0 0 1 0 0 1 0 0 0
39032 - 0 0 0 0 0 0 0 0 0 0 0 0
39033 - 0 0 0 0 0 0 0 0 0 0 0 0
39034 - 0 0 0 0 0 0 0 0 0 0 0 0
39035 - 0 0 0 0 0 0 0 0 0 0 0 0
39036 - 0 0 0 0 0 0 0 0 0 14 14 14
39037 - 46 46 46 86 86 86 2 2 6 2 2 6
39038 - 38 38 38 116 116 116 94 94 94 22 22 22
39039 - 22 22 22 2 2 6 2 2 6 2 2 6
39040 - 14 14 14 86 86 86 138 138 138 162 162 162
39041 -154 154 154 38 38 38 26 26 26 6 6 6
39042 - 2 2 6 2 2 6 2 2 6 2 2 6
39043 - 86 86 86 46 46 46 14 14 14 0 0 0
39044 - 0 0 0 0 0 0 0 0 0 0 0 0
39045 - 0 0 0 0 0 0 0 0 0 0 0 0
39046 - 0 0 0 0 0 0 0 0 0 0 0 0
39047 - 0 0 0 0 0 0 0 0 0 0 0 0
39048 - 0 0 0 0 0 0 0 0 0 0 0 0
39049 - 0 0 0 0 0 0 0 0 0 0 0 0
39050 - 0 0 0 0 0 0 0 0 0 0 0 0
39051 - 0 0 0 0 0 0 0 0 0 0 0 0
39052 - 0 0 0 0 0 0 0 0 0 0 0 0
39053 - 0 0 0 0 0 0 0 0 0 0 0 0
39054 - 0 0 0 0 0 0 0 0 0 0 0 0
39055 - 0 0 0 0 0 0 0 0 0 0 0 0
39056 - 0 0 0 0 0 0 0 0 0 14 14 14
39057 - 46 46 46 86 86 86 2 2 6 14 14 14
39058 -134 134 134 198 198 198 195 195 195 116 116 116
39059 - 10 10 10 2 2 6 2 2 6 6 6 6
39060 -101 98 89 187 187 187 210 210 210 218 218 218
39061 -214 214 214 134 134 134 14 14 14 6 6 6
39062 - 2 2 6 2 2 6 2 2 6 2 2 6
39063 - 86 86 86 50 50 50 18 18 18 6 6 6
39064 - 0 0 0 0 0 0 0 0 0 0 0 0
39065 - 0 0 0 0 0 0 0 0 0 0 0 0
39066 - 0 0 0 0 0 0 0 0 0 0 0 0
39067 - 0 0 0 0 0 0 0 0 0 0 0 0
39068 - 0 0 0 0 0 0 0 0 0 0 0 0
39069 - 0 0 0 0 0 0 0 0 0 0 0 0
39070 - 0 0 0 0 0 0 0 0 1 0 0 0
39071 - 0 0 1 0 0 1 0 0 1 0 0 0
39072 - 0 0 0 0 0 0 0 0 0 0 0 0
39073 - 0 0 0 0 0 0 0 0 0 0 0 0
39074 - 0 0 0 0 0 0 0 0 0 0 0 0
39075 - 0 0 0 0 0 0 0 0 0 0 0 0
39076 - 0 0 0 0 0 0 0 0 0 14 14 14
39077 - 46 46 46 86 86 86 2 2 6 54 54 54
39078 -218 218 218 195 195 195 226 226 226 246 246 246
39079 - 58 58 58 2 2 6 2 2 6 30 30 30
39080 -210 210 210 253 253 253 174 174 174 123 123 123
39081 -221 221 221 234 234 234 74 74 74 2 2 6
39082 - 2 2 6 2 2 6 2 2 6 2 2 6
39083 - 70 70 70 58 58 58 22 22 22 6 6 6
39084 - 0 0 0 0 0 0 0 0 0 0 0 0
39085 - 0 0 0 0 0 0 0 0 0 0 0 0
39086 - 0 0 0 0 0 0 0 0 0 0 0 0
39087 - 0 0 0 0 0 0 0 0 0 0 0 0
39088 - 0 0 0 0 0 0 0 0 0 0 0 0
39089 - 0 0 0 0 0 0 0 0 0 0 0 0
39090 - 0 0 0 0 0 0 0 0 0 0 0 0
39091 - 0 0 0 0 0 0 0 0 0 0 0 0
39092 - 0 0 0 0 0 0 0 0 0 0 0 0
39093 - 0 0 0 0 0 0 0 0 0 0 0 0
39094 - 0 0 0 0 0 0 0 0 0 0 0 0
39095 - 0 0 0 0 0 0 0 0 0 0 0 0
39096 - 0 0 0 0 0 0 0 0 0 14 14 14
39097 - 46 46 46 82 82 82 2 2 6 106 106 106
39098 -170 170 170 26 26 26 86 86 86 226 226 226
39099 -123 123 123 10 10 10 14 14 14 46 46 46
39100 -231 231 231 190 190 190 6 6 6 70 70 70
39101 - 90 90 90 238 238 238 158 158 158 2 2 6
39102 - 2 2 6 2 2 6 2 2 6 2 2 6
39103 - 70 70 70 58 58 58 22 22 22 6 6 6
39104 - 0 0 0 0 0 0 0 0 0 0 0 0
39105 - 0 0 0 0 0 0 0 0 0 0 0 0
39106 - 0 0 0 0 0 0 0 0 0 0 0 0
39107 - 0 0 0 0 0 0 0 0 0 0 0 0
39108 - 0 0 0 0 0 0 0 0 0 0 0 0
39109 - 0 0 0 0 0 0 0 0 0 0 0 0
39110 - 0 0 0 0 0 0 0 0 1 0 0 0
39111 - 0 0 1 0 0 1 0 0 1 0 0 0
39112 - 0 0 0 0 0 0 0 0 0 0 0 0
39113 - 0 0 0 0 0 0 0 0 0 0 0 0
39114 - 0 0 0 0 0 0 0 0 0 0 0 0
39115 - 0 0 0 0 0 0 0 0 0 0 0 0
39116 - 0 0 0 0 0 0 0 0 0 14 14 14
39117 - 42 42 42 86 86 86 6 6 6 116 116 116
39118 -106 106 106 6 6 6 70 70 70 149 149 149
39119 -128 128 128 18 18 18 38 38 38 54 54 54
39120 -221 221 221 106 106 106 2 2 6 14 14 14
39121 - 46 46 46 190 190 190 198 198 198 2 2 6
39122 - 2 2 6 2 2 6 2 2 6 2 2 6
39123 - 74 74 74 62 62 62 22 22 22 6 6 6
39124 - 0 0 0 0 0 0 0 0 0 0 0 0
39125 - 0 0 0 0 0 0 0 0 0 0 0 0
39126 - 0 0 0 0 0 0 0 0 0 0 0 0
39127 - 0 0 0 0 0 0 0 0 0 0 0 0
39128 - 0 0 0 0 0 0 0 0 0 0 0 0
39129 - 0 0 0 0 0 0 0 0 0 0 0 0
39130 - 0 0 0 0 0 0 0 0 1 0 0 0
39131 - 0 0 1 0 0 0 0 0 1 0 0 0
39132 - 0 0 0 0 0 0 0 0 0 0 0 0
39133 - 0 0 0 0 0 0 0 0 0 0 0 0
39134 - 0 0 0 0 0 0 0 0 0 0 0 0
39135 - 0 0 0 0 0 0 0 0 0 0 0 0
39136 - 0 0 0 0 0 0 0 0 0 14 14 14
39137 - 42 42 42 94 94 94 14 14 14 101 101 101
39138 -128 128 128 2 2 6 18 18 18 116 116 116
39139 -118 98 46 121 92 8 121 92 8 98 78 10
39140 -162 162 162 106 106 106 2 2 6 2 2 6
39141 - 2 2 6 195 195 195 195 195 195 6 6 6
39142 - 2 2 6 2 2 6 2 2 6 2 2 6
39143 - 74 74 74 62 62 62 22 22 22 6 6 6
39144 - 0 0 0 0 0 0 0 0 0 0 0 0
39145 - 0 0 0 0 0 0 0 0 0 0 0 0
39146 - 0 0 0 0 0 0 0 0 0 0 0 0
39147 - 0 0 0 0 0 0 0 0 0 0 0 0
39148 - 0 0 0 0 0 0 0 0 0 0 0 0
39149 - 0 0 0 0 0 0 0 0 0 0 0 0
39150 - 0 0 0 0 0 0 0 0 1 0 0 1
39151 - 0 0 1 0 0 0 0 0 1 0 0 0
39152 - 0 0 0 0 0 0 0 0 0 0 0 0
39153 - 0 0 0 0 0 0 0 0 0 0 0 0
39154 - 0 0 0 0 0 0 0 0 0 0 0 0
39155 - 0 0 0 0 0 0 0 0 0 0 0 0
39156 - 0 0 0 0 0 0 0 0 0 10 10 10
39157 - 38 38 38 90 90 90 14 14 14 58 58 58
39158 -210 210 210 26 26 26 54 38 6 154 114 10
39159 -226 170 11 236 186 11 225 175 15 184 144 12
39160 -215 174 15 175 146 61 37 26 9 2 2 6
39161 - 70 70 70 246 246 246 138 138 138 2 2 6
39162 - 2 2 6 2 2 6 2 2 6 2 2 6
39163 - 70 70 70 66 66 66 26 26 26 6 6 6
39164 - 0 0 0 0 0 0 0 0 0 0 0 0
39165 - 0 0 0 0 0 0 0 0 0 0 0 0
39166 - 0 0 0 0 0 0 0 0 0 0 0 0
39167 - 0 0 0 0 0 0 0 0 0 0 0 0
39168 - 0 0 0 0 0 0 0 0 0 0 0 0
39169 - 0 0 0 0 0 0 0 0 0 0 0 0
39170 - 0 0 0 0 0 0 0 0 0 0 0 0
39171 - 0 0 0 0 0 0 0 0 0 0 0 0
39172 - 0 0 0 0 0 0 0 0 0 0 0 0
39173 - 0 0 0 0 0 0 0 0 0 0 0 0
39174 - 0 0 0 0 0 0 0 0 0 0 0 0
39175 - 0 0 0 0 0 0 0 0 0 0 0 0
39176 - 0 0 0 0 0 0 0 0 0 10 10 10
39177 - 38 38 38 86 86 86 14 14 14 10 10 10
39178 -195 195 195 188 164 115 192 133 9 225 175 15
39179 -239 182 13 234 190 10 232 195 16 232 200 30
39180 -245 207 45 241 208 19 232 195 16 184 144 12
39181 -218 194 134 211 206 186 42 42 42 2 2 6
39182 - 2 2 6 2 2 6 2 2 6 2 2 6
39183 - 50 50 50 74 74 74 30 30 30 6 6 6
39184 - 0 0 0 0 0 0 0 0 0 0 0 0
39185 - 0 0 0 0 0 0 0 0 0 0 0 0
39186 - 0 0 0 0 0 0 0 0 0 0 0 0
39187 - 0 0 0 0 0 0 0 0 0 0 0 0
39188 - 0 0 0 0 0 0 0 0 0 0 0 0
39189 - 0 0 0 0 0 0 0 0 0 0 0 0
39190 - 0 0 0 0 0 0 0 0 0 0 0 0
39191 - 0 0 0 0 0 0 0 0 0 0 0 0
39192 - 0 0 0 0 0 0 0 0 0 0 0 0
39193 - 0 0 0 0 0 0 0 0 0 0 0 0
39194 - 0 0 0 0 0 0 0 0 0 0 0 0
39195 - 0 0 0 0 0 0 0 0 0 0 0 0
39196 - 0 0 0 0 0 0 0 0 0 10 10 10
39197 - 34 34 34 86 86 86 14 14 14 2 2 6
39198 -121 87 25 192 133 9 219 162 10 239 182 13
39199 -236 186 11 232 195 16 241 208 19 244 214 54
39200 -246 218 60 246 218 38 246 215 20 241 208 19
39201 -241 208 19 226 184 13 121 87 25 2 2 6
39202 - 2 2 6 2 2 6 2 2 6 2 2 6
39203 - 50 50 50 82 82 82 34 34 34 10 10 10
39204 - 0 0 0 0 0 0 0 0 0 0 0 0
39205 - 0 0 0 0 0 0 0 0 0 0 0 0
39206 - 0 0 0 0 0 0 0 0 0 0 0 0
39207 - 0 0 0 0 0 0 0 0 0 0 0 0
39208 - 0 0 0 0 0 0 0 0 0 0 0 0
39209 - 0 0 0 0 0 0 0 0 0 0 0 0
39210 - 0 0 0 0 0 0 0 0 0 0 0 0
39211 - 0 0 0 0 0 0 0 0 0 0 0 0
39212 - 0 0 0 0 0 0 0 0 0 0 0 0
39213 - 0 0 0 0 0 0 0 0 0 0 0 0
39214 - 0 0 0 0 0 0 0 0 0 0 0 0
39215 - 0 0 0 0 0 0 0 0 0 0 0 0
39216 - 0 0 0 0 0 0 0 0 0 10 10 10
39217 - 34 34 34 82 82 82 30 30 30 61 42 6
39218 -180 123 7 206 145 10 230 174 11 239 182 13
39219 -234 190 10 238 202 15 241 208 19 246 218 74
39220 -246 218 38 246 215 20 246 215 20 246 215 20
39221 -226 184 13 215 174 15 184 144 12 6 6 6
39222 - 2 2 6 2 2 6 2 2 6 2 2 6
39223 - 26 26 26 94 94 94 42 42 42 14 14 14
39224 - 0 0 0 0 0 0 0 0 0 0 0 0
39225 - 0 0 0 0 0 0 0 0 0 0 0 0
39226 - 0 0 0 0 0 0 0 0 0 0 0 0
39227 - 0 0 0 0 0 0 0 0 0 0 0 0
39228 - 0 0 0 0 0 0 0 0 0 0 0 0
39229 - 0 0 0 0 0 0 0 0 0 0 0 0
39230 - 0 0 0 0 0 0 0 0 0 0 0 0
39231 - 0 0 0 0 0 0 0 0 0 0 0 0
39232 - 0 0 0 0 0 0 0 0 0 0 0 0
39233 - 0 0 0 0 0 0 0 0 0 0 0 0
39234 - 0 0 0 0 0 0 0 0 0 0 0 0
39235 - 0 0 0 0 0 0 0 0 0 0 0 0
39236 - 0 0 0 0 0 0 0 0 0 10 10 10
39237 - 30 30 30 78 78 78 50 50 50 104 69 6
39238 -192 133 9 216 158 10 236 178 12 236 186 11
39239 -232 195 16 241 208 19 244 214 54 245 215 43
39240 -246 215 20 246 215 20 241 208 19 198 155 10
39241 -200 144 11 216 158 10 156 118 10 2 2 6
39242 - 2 2 6 2 2 6 2 2 6 2 2 6
39243 - 6 6 6 90 90 90 54 54 54 18 18 18
39244 - 6 6 6 0 0 0 0 0 0 0 0 0
39245 - 0 0 0 0 0 0 0 0 0 0 0 0
39246 - 0 0 0 0 0 0 0 0 0 0 0 0
39247 - 0 0 0 0 0 0 0 0 0 0 0 0
39248 - 0 0 0 0 0 0 0 0 0 0 0 0
39249 - 0 0 0 0 0 0 0 0 0 0 0 0
39250 - 0 0 0 0 0 0 0 0 0 0 0 0
39251 - 0 0 0 0 0 0 0 0 0 0 0 0
39252 - 0 0 0 0 0 0 0 0 0 0 0 0
39253 - 0 0 0 0 0 0 0 0 0 0 0 0
39254 - 0 0 0 0 0 0 0 0 0 0 0 0
39255 - 0 0 0 0 0 0 0 0 0 0 0 0
39256 - 0 0 0 0 0 0 0 0 0 10 10 10
39257 - 30 30 30 78 78 78 46 46 46 22 22 22
39258 -137 92 6 210 162 10 239 182 13 238 190 10
39259 -238 202 15 241 208 19 246 215 20 246 215 20
39260 -241 208 19 203 166 17 185 133 11 210 150 10
39261 -216 158 10 210 150 10 102 78 10 2 2 6
39262 - 6 6 6 54 54 54 14 14 14 2 2 6
39263 - 2 2 6 62 62 62 74 74 74 30 30 30
39264 - 10 10 10 0 0 0 0 0 0 0 0 0
39265 - 0 0 0 0 0 0 0 0 0 0 0 0
39266 - 0 0 0 0 0 0 0 0 0 0 0 0
39267 - 0 0 0 0 0 0 0 0 0 0 0 0
39268 - 0 0 0 0 0 0 0 0 0 0 0 0
39269 - 0 0 0 0 0 0 0 0 0 0 0 0
39270 - 0 0 0 0 0 0 0 0 0 0 0 0
39271 - 0 0 0 0 0 0 0 0 0 0 0 0
39272 - 0 0 0 0 0 0 0 0 0 0 0 0
39273 - 0 0 0 0 0 0 0 0 0 0 0 0
39274 - 0 0 0 0 0 0 0 0 0 0 0 0
39275 - 0 0 0 0 0 0 0 0 0 0 0 0
39276 - 0 0 0 0 0 0 0 0 0 10 10 10
39277 - 34 34 34 78 78 78 50 50 50 6 6 6
39278 - 94 70 30 139 102 15 190 146 13 226 184 13
39279 -232 200 30 232 195 16 215 174 15 190 146 13
39280 -168 122 10 192 133 9 210 150 10 213 154 11
39281 -202 150 34 182 157 106 101 98 89 2 2 6
39282 - 2 2 6 78 78 78 116 116 116 58 58 58
39283 - 2 2 6 22 22 22 90 90 90 46 46 46
39284 - 18 18 18 6 6 6 0 0 0 0 0 0
39285 - 0 0 0 0 0 0 0 0 0 0 0 0
39286 - 0 0 0 0 0 0 0 0 0 0 0 0
39287 - 0 0 0 0 0 0 0 0 0 0 0 0
39288 - 0 0 0 0 0 0 0 0 0 0 0 0
39289 - 0 0 0 0 0 0 0 0 0 0 0 0
39290 - 0 0 0 0 0 0 0 0 0 0 0 0
39291 - 0 0 0 0 0 0 0 0 0 0 0 0
39292 - 0 0 0 0 0 0 0 0 0 0 0 0
39293 - 0 0 0 0 0 0 0 0 0 0 0 0
39294 - 0 0 0 0 0 0 0 0 0 0 0 0
39295 - 0 0 0 0 0 0 0 0 0 0 0 0
39296 - 0 0 0 0 0 0 0 0 0 10 10 10
39297 - 38 38 38 86 86 86 50 50 50 6 6 6
39298 -128 128 128 174 154 114 156 107 11 168 122 10
39299 -198 155 10 184 144 12 197 138 11 200 144 11
39300 -206 145 10 206 145 10 197 138 11 188 164 115
39301 -195 195 195 198 198 198 174 174 174 14 14 14
39302 - 2 2 6 22 22 22 116 116 116 116 116 116
39303 - 22 22 22 2 2 6 74 74 74 70 70 70
39304 - 30 30 30 10 10 10 0 0 0 0 0 0
39305 - 0 0 0 0 0 0 0 0 0 0 0 0
39306 - 0 0 0 0 0 0 0 0 0 0 0 0
39307 - 0 0 0 0 0 0 0 0 0 0 0 0
39308 - 0 0 0 0 0 0 0 0 0 0 0 0
39309 - 0 0 0 0 0 0 0 0 0 0 0 0
39310 - 0 0 0 0 0 0 0 0 0 0 0 0
39311 - 0 0 0 0 0 0 0 0 0 0 0 0
39312 - 0 0 0 0 0 0 0 0 0 0 0 0
39313 - 0 0 0 0 0 0 0 0 0 0 0 0
39314 - 0 0 0 0 0 0 0 0 0 0 0 0
39315 - 0 0 0 0 0 0 0 0 0 0 0 0
39316 - 0 0 0 0 0 0 6 6 6 18 18 18
39317 - 50 50 50 101 101 101 26 26 26 10 10 10
39318 -138 138 138 190 190 190 174 154 114 156 107 11
39319 -197 138 11 200 144 11 197 138 11 192 133 9
39320 -180 123 7 190 142 34 190 178 144 187 187 187
39321 -202 202 202 221 221 221 214 214 214 66 66 66
39322 - 2 2 6 2 2 6 50 50 50 62 62 62
39323 - 6 6 6 2 2 6 10 10 10 90 90 90
39324 - 50 50 50 18 18 18 6 6 6 0 0 0
39325 - 0 0 0 0 0 0 0 0 0 0 0 0
39326 - 0 0 0 0 0 0 0 0 0 0 0 0
39327 - 0 0 0 0 0 0 0 0 0 0 0 0
39328 - 0 0 0 0 0 0 0 0 0 0 0 0
39329 - 0 0 0 0 0 0 0 0 0 0 0 0
39330 - 0 0 0 0 0 0 0 0 0 0 0 0
39331 - 0 0 0 0 0 0 0 0 0 0 0 0
39332 - 0 0 0 0 0 0 0 0 0 0 0 0
39333 - 0 0 0 0 0 0 0 0 0 0 0 0
39334 - 0 0 0 0 0 0 0 0 0 0 0 0
39335 - 0 0 0 0 0 0 0 0 0 0 0 0
39336 - 0 0 0 0 0 0 10 10 10 34 34 34
39337 - 74 74 74 74 74 74 2 2 6 6 6 6
39338 -144 144 144 198 198 198 190 190 190 178 166 146
39339 -154 121 60 156 107 11 156 107 11 168 124 44
39340 -174 154 114 187 187 187 190 190 190 210 210 210
39341 -246 246 246 253 253 253 253 253 253 182 182 182
39342 - 6 6 6 2 2 6 2 2 6 2 2 6
39343 - 2 2 6 2 2 6 2 2 6 62 62 62
39344 - 74 74 74 34 34 34 14 14 14 0 0 0
39345 - 0 0 0 0 0 0 0 0 0 0 0 0
39346 - 0 0 0 0 0 0 0 0 0 0 0 0
39347 - 0 0 0 0 0 0 0 0 0 0 0 0
39348 - 0 0 0 0 0 0 0 0 0 0 0 0
39349 - 0 0 0 0 0 0 0 0 0 0 0 0
39350 - 0 0 0 0 0 0 0 0 0 0 0 0
39351 - 0 0 0 0 0 0 0 0 0 0 0 0
39352 - 0 0 0 0 0 0 0 0 0 0 0 0
39353 - 0 0 0 0 0 0 0 0 0 0 0 0
39354 - 0 0 0 0 0 0 0 0 0 0 0 0
39355 - 0 0 0 0 0 0 0 0 0 0 0 0
39356 - 0 0 0 10 10 10 22 22 22 54 54 54
39357 - 94 94 94 18 18 18 2 2 6 46 46 46
39358 -234 234 234 221 221 221 190 190 190 190 190 190
39359 -190 190 190 187 187 187 187 187 187 190 190 190
39360 -190 190 190 195 195 195 214 214 214 242 242 242
39361 -253 253 253 253 253 253 253 253 253 253 253 253
39362 - 82 82 82 2 2 6 2 2 6 2 2 6
39363 - 2 2 6 2 2 6 2 2 6 14 14 14
39364 - 86 86 86 54 54 54 22 22 22 6 6 6
39365 - 0 0 0 0 0 0 0 0 0 0 0 0
39366 - 0 0 0 0 0 0 0 0 0 0 0 0
39367 - 0 0 0 0 0 0 0 0 0 0 0 0
39368 - 0 0 0 0 0 0 0 0 0 0 0 0
39369 - 0 0 0 0 0 0 0 0 0 0 0 0
39370 - 0 0 0 0 0 0 0 0 0 0 0 0
39371 - 0 0 0 0 0 0 0 0 0 0 0 0
39372 - 0 0 0 0 0 0 0 0 0 0 0 0
39373 - 0 0 0 0 0 0 0 0 0 0 0 0
39374 - 0 0 0 0 0 0 0 0 0 0 0 0
39375 - 0 0 0 0 0 0 0 0 0 0 0 0
39376 - 6 6 6 18 18 18 46 46 46 90 90 90
39377 - 46 46 46 18 18 18 6 6 6 182 182 182
39378 -253 253 253 246 246 246 206 206 206 190 190 190
39379 -190 190 190 190 190 190 190 190 190 190 190 190
39380 -206 206 206 231 231 231 250 250 250 253 253 253
39381 -253 253 253 253 253 253 253 253 253 253 253 253
39382 -202 202 202 14 14 14 2 2 6 2 2 6
39383 - 2 2 6 2 2 6 2 2 6 2 2 6
39384 - 42 42 42 86 86 86 42 42 42 18 18 18
39385 - 6 6 6 0 0 0 0 0 0 0 0 0
39386 - 0 0 0 0 0 0 0 0 0 0 0 0
39387 - 0 0 0 0 0 0 0 0 0 0 0 0
39388 - 0 0 0 0 0 0 0 0 0 0 0 0
39389 - 0 0 0 0 0 0 0 0 0 0 0 0
39390 - 0 0 0 0 0 0 0 0 0 0 0 0
39391 - 0 0 0 0 0 0 0 0 0 0 0 0
39392 - 0 0 0 0 0 0 0 0 0 0 0 0
39393 - 0 0 0 0 0 0 0 0 0 0 0 0
39394 - 0 0 0 0 0 0 0 0 0 0 0 0
39395 - 0 0 0 0 0 0 0 0 0 6 6 6
39396 - 14 14 14 38 38 38 74 74 74 66 66 66
39397 - 2 2 6 6 6 6 90 90 90 250 250 250
39398 -253 253 253 253 253 253 238 238 238 198 198 198
39399 -190 190 190 190 190 190 195 195 195 221 221 221
39400 -246 246 246 253 253 253 253 253 253 253 253 253
39401 -253 253 253 253 253 253 253 253 253 253 253 253
39402 -253 253 253 82 82 82 2 2 6 2 2 6
39403 - 2 2 6 2 2 6 2 2 6 2 2 6
39404 - 2 2 6 78 78 78 70 70 70 34 34 34
39405 - 14 14 14 6 6 6 0 0 0 0 0 0
39406 - 0 0 0 0 0 0 0 0 0 0 0 0
39407 - 0 0 0 0 0 0 0 0 0 0 0 0
39408 - 0 0 0 0 0 0 0 0 0 0 0 0
39409 - 0 0 0 0 0 0 0 0 0 0 0 0
39410 - 0 0 0 0 0 0 0 0 0 0 0 0
39411 - 0 0 0 0 0 0 0 0 0 0 0 0
39412 - 0 0 0 0 0 0 0 0 0 0 0 0
39413 - 0 0 0 0 0 0 0 0 0 0 0 0
39414 - 0 0 0 0 0 0 0 0 0 0 0 0
39415 - 0 0 0 0 0 0 0 0 0 14 14 14
39416 - 34 34 34 66 66 66 78 78 78 6 6 6
39417 - 2 2 6 18 18 18 218 218 218 253 253 253
39418 -253 253 253 253 253 253 253 253 253 246 246 246
39419 -226 226 226 231 231 231 246 246 246 253 253 253
39420 -253 253 253 253 253 253 253 253 253 253 253 253
39421 -253 253 253 253 253 253 253 253 253 253 253 253
39422 -253 253 253 178 178 178 2 2 6 2 2 6
39423 - 2 2 6 2 2 6 2 2 6 2 2 6
39424 - 2 2 6 18 18 18 90 90 90 62 62 62
39425 - 30 30 30 10 10 10 0 0 0 0 0 0
39426 - 0 0 0 0 0 0 0 0 0 0 0 0
39427 - 0 0 0 0 0 0 0 0 0 0 0 0
39428 - 0 0 0 0 0 0 0 0 0 0 0 0
39429 - 0 0 0 0 0 0 0 0 0 0 0 0
39430 - 0 0 0 0 0 0 0 0 0 0 0 0
39431 - 0 0 0 0 0 0 0 0 0 0 0 0
39432 - 0 0 0 0 0 0 0 0 0 0 0 0
39433 - 0 0 0 0 0 0 0 0 0 0 0 0
39434 - 0 0 0 0 0 0 0 0 0 0 0 0
39435 - 0 0 0 0 0 0 10 10 10 26 26 26
39436 - 58 58 58 90 90 90 18 18 18 2 2 6
39437 - 2 2 6 110 110 110 253 253 253 253 253 253
39438 -253 253 253 253 253 253 253 253 253 253 253 253
39439 -250 250 250 253 253 253 253 253 253 253 253 253
39440 -253 253 253 253 253 253 253 253 253 253 253 253
39441 -253 253 253 253 253 253 253 253 253 253 253 253
39442 -253 253 253 231 231 231 18 18 18 2 2 6
39443 - 2 2 6 2 2 6 2 2 6 2 2 6
39444 - 2 2 6 2 2 6 18 18 18 94 94 94
39445 - 54 54 54 26 26 26 10 10 10 0 0 0
39446 - 0 0 0 0 0 0 0 0 0 0 0 0
39447 - 0 0 0 0 0 0 0 0 0 0 0 0
39448 - 0 0 0 0 0 0 0 0 0 0 0 0
39449 - 0 0 0 0 0 0 0 0 0 0 0 0
39450 - 0 0 0 0 0 0 0 0 0 0 0 0
39451 - 0 0 0 0 0 0 0 0 0 0 0 0
39452 - 0 0 0 0 0 0 0 0 0 0 0 0
39453 - 0 0 0 0 0 0 0 0 0 0 0 0
39454 - 0 0 0 0 0 0 0 0 0 0 0 0
39455 - 0 0 0 6 6 6 22 22 22 50 50 50
39456 - 90 90 90 26 26 26 2 2 6 2 2 6
39457 - 14 14 14 195 195 195 250 250 250 253 253 253
39458 -253 253 253 253 253 253 253 253 253 253 253 253
39459 -253 253 253 253 253 253 253 253 253 253 253 253
39460 -253 253 253 253 253 253 253 253 253 253 253 253
39461 -253 253 253 253 253 253 253 253 253 253 253 253
39462 -250 250 250 242 242 242 54 54 54 2 2 6
39463 - 2 2 6 2 2 6 2 2 6 2 2 6
39464 - 2 2 6 2 2 6 2 2 6 38 38 38
39465 - 86 86 86 50 50 50 22 22 22 6 6 6
39466 - 0 0 0 0 0 0 0 0 0 0 0 0
39467 - 0 0 0 0 0 0 0 0 0 0 0 0
39468 - 0 0 0 0 0 0 0 0 0 0 0 0
39469 - 0 0 0 0 0 0 0 0 0 0 0 0
39470 - 0 0 0 0 0 0 0 0 0 0 0 0
39471 - 0 0 0 0 0 0 0 0 0 0 0 0
39472 - 0 0 0 0 0 0 0 0 0 0 0 0
39473 - 0 0 0 0 0 0 0 0 0 0 0 0
39474 - 0 0 0 0 0 0 0 0 0 0 0 0
39475 - 6 6 6 14 14 14 38 38 38 82 82 82
39476 - 34 34 34 2 2 6 2 2 6 2 2 6
39477 - 42 42 42 195 195 195 246 246 246 253 253 253
39478 -253 253 253 253 253 253 253 253 253 250 250 250
39479 -242 242 242 242 242 242 250 250 250 253 253 253
39480 -253 253 253 253 253 253 253 253 253 253 253 253
39481 -253 253 253 250 250 250 246 246 246 238 238 238
39482 -226 226 226 231 231 231 101 101 101 6 6 6
39483 - 2 2 6 2 2 6 2 2 6 2 2 6
39484 - 2 2 6 2 2 6 2 2 6 2 2 6
39485 - 38 38 38 82 82 82 42 42 42 14 14 14
39486 - 6 6 6 0 0 0 0 0 0 0 0 0
39487 - 0 0 0 0 0 0 0 0 0 0 0 0
39488 - 0 0 0 0 0 0 0 0 0 0 0 0
39489 - 0 0 0 0 0 0 0 0 0 0 0 0
39490 - 0 0 0 0 0 0 0 0 0 0 0 0
39491 - 0 0 0 0 0 0 0 0 0 0 0 0
39492 - 0 0 0 0 0 0 0 0 0 0 0 0
39493 - 0 0 0 0 0 0 0 0 0 0 0 0
39494 - 0 0 0 0 0 0 0 0 0 0 0 0
39495 - 10 10 10 26 26 26 62 62 62 66 66 66
39496 - 2 2 6 2 2 6 2 2 6 6 6 6
39497 - 70 70 70 170 170 170 206 206 206 234 234 234
39498 -246 246 246 250 250 250 250 250 250 238 238 238
39499 -226 226 226 231 231 231 238 238 238 250 250 250
39500 -250 250 250 250 250 250 246 246 246 231 231 231
39501 -214 214 214 206 206 206 202 202 202 202 202 202
39502 -198 198 198 202 202 202 182 182 182 18 18 18
39503 - 2 2 6 2 2 6 2 2 6 2 2 6
39504 - 2 2 6 2 2 6 2 2 6 2 2 6
39505 - 2 2 6 62 62 62 66 66 66 30 30 30
39506 - 10 10 10 0 0 0 0 0 0 0 0 0
39507 - 0 0 0 0 0 0 0 0 0 0 0 0
39508 - 0 0 0 0 0 0 0 0 0 0 0 0
39509 - 0 0 0 0 0 0 0 0 0 0 0 0
39510 - 0 0 0 0 0 0 0 0 0 0 0 0
39511 - 0 0 0 0 0 0 0 0 0 0 0 0
39512 - 0 0 0 0 0 0 0 0 0 0 0 0
39513 - 0 0 0 0 0 0 0 0 0 0 0 0
39514 - 0 0 0 0 0 0 0 0 0 0 0 0
39515 - 14 14 14 42 42 42 82 82 82 18 18 18
39516 - 2 2 6 2 2 6 2 2 6 10 10 10
39517 - 94 94 94 182 182 182 218 218 218 242 242 242
39518 -250 250 250 253 253 253 253 253 253 250 250 250
39519 -234 234 234 253 253 253 253 253 253 253 253 253
39520 -253 253 253 253 253 253 253 253 253 246 246 246
39521 -238 238 238 226 226 226 210 210 210 202 202 202
39522 -195 195 195 195 195 195 210 210 210 158 158 158
39523 - 6 6 6 14 14 14 50 50 50 14 14 14
39524 - 2 2 6 2 2 6 2 2 6 2 2 6
39525 - 2 2 6 6 6 6 86 86 86 46 46 46
39526 - 18 18 18 6 6 6 0 0 0 0 0 0
39527 - 0 0 0 0 0 0 0 0 0 0 0 0
39528 - 0 0 0 0 0 0 0 0 0 0 0 0
39529 - 0 0 0 0 0 0 0 0 0 0 0 0
39530 - 0 0 0 0 0 0 0 0 0 0 0 0
39531 - 0 0 0 0 0 0 0 0 0 0 0 0
39532 - 0 0 0 0 0 0 0 0 0 0 0 0
39533 - 0 0 0 0 0 0 0 0 0 0 0 0
39534 - 0 0 0 0 0 0 0 0 0 6 6 6
39535 - 22 22 22 54 54 54 70 70 70 2 2 6
39536 - 2 2 6 10 10 10 2 2 6 22 22 22
39537 -166 166 166 231 231 231 250 250 250 253 253 253
39538 -253 253 253 253 253 253 253 253 253 250 250 250
39539 -242 242 242 253 253 253 253 253 253 253 253 253
39540 -253 253 253 253 253 253 253 253 253 253 253 253
39541 -253 253 253 253 253 253 253 253 253 246 246 246
39542 -231 231 231 206 206 206 198 198 198 226 226 226
39543 - 94 94 94 2 2 6 6 6 6 38 38 38
39544 - 30 30 30 2 2 6 2 2 6 2 2 6
39545 - 2 2 6 2 2 6 62 62 62 66 66 66
39546 - 26 26 26 10 10 10 0 0 0 0 0 0
39547 - 0 0 0 0 0 0 0 0 0 0 0 0
39548 - 0 0 0 0 0 0 0 0 0 0 0 0
39549 - 0 0 0 0 0 0 0 0 0 0 0 0
39550 - 0 0 0 0 0 0 0 0 0 0 0 0
39551 - 0 0 0 0 0 0 0 0 0 0 0 0
39552 - 0 0 0 0 0 0 0 0 0 0 0 0
39553 - 0 0 0 0 0 0 0 0 0 0 0 0
39554 - 0 0 0 0 0 0 0 0 0 10 10 10
39555 - 30 30 30 74 74 74 50 50 50 2 2 6
39556 - 26 26 26 26 26 26 2 2 6 106 106 106
39557 -238 238 238 253 253 253 253 253 253 253 253 253
39558 -253 253 253 253 253 253 253 253 253 253 253 253
39559 -253 253 253 253 253 253 253 253 253 253 253 253
39560 -253 253 253 253 253 253 253 253 253 253 253 253
39561 -253 253 253 253 253 253 253 253 253 253 253 253
39562 -253 253 253 246 246 246 218 218 218 202 202 202
39563 -210 210 210 14 14 14 2 2 6 2 2 6
39564 - 30 30 30 22 22 22 2 2 6 2 2 6
39565 - 2 2 6 2 2 6 18 18 18 86 86 86
39566 - 42 42 42 14 14 14 0 0 0 0 0 0
39567 - 0 0 0 0 0 0 0 0 0 0 0 0
39568 - 0 0 0 0 0 0 0 0 0 0 0 0
39569 - 0 0 0 0 0 0 0 0 0 0 0 0
39570 - 0 0 0 0 0 0 0 0 0 0 0 0
39571 - 0 0 0 0 0 0 0 0 0 0 0 0
39572 - 0 0 0 0 0 0 0 0 0 0 0 0
39573 - 0 0 0 0 0 0 0 0 0 0 0 0
39574 - 0 0 0 0 0 0 0 0 0 14 14 14
39575 - 42 42 42 90 90 90 22 22 22 2 2 6
39576 - 42 42 42 2 2 6 18 18 18 218 218 218
39577 -253 253 253 253 253 253 253 253 253 253 253 253
39578 -253 253 253 253 253 253 253 253 253 253 253 253
39579 -253 253 253 253 253 253 253 253 253 253 253 253
39580 -253 253 253 253 253 253 253 253 253 253 253 253
39581 -253 253 253 253 253 253 253 253 253 253 253 253
39582 -253 253 253 253 253 253 250 250 250 221 221 221
39583 -218 218 218 101 101 101 2 2 6 14 14 14
39584 - 18 18 18 38 38 38 10 10 10 2 2 6
39585 - 2 2 6 2 2 6 2 2 6 78 78 78
39586 - 58 58 58 22 22 22 6 6 6 0 0 0
39587 - 0 0 0 0 0 0 0 0 0 0 0 0
39588 - 0 0 0 0 0 0 0 0 0 0 0 0
39589 - 0 0 0 0 0 0 0 0 0 0 0 0
39590 - 0 0 0 0 0 0 0 0 0 0 0 0
39591 - 0 0 0 0 0 0 0 0 0 0 0 0
39592 - 0 0 0 0 0 0 0 0 0 0 0 0
39593 - 0 0 0 0 0 0 0 0 0 0 0 0
39594 - 0 0 0 0 0 0 6 6 6 18 18 18
39595 - 54 54 54 82 82 82 2 2 6 26 26 26
39596 - 22 22 22 2 2 6 123 123 123 253 253 253
39597 -253 253 253 253 253 253 253 253 253 253 253 253
39598 -253 253 253 253 253 253 253 253 253 253 253 253
39599 -253 253 253 253 253 253 253 253 253 253 253 253
39600 -253 253 253 253 253 253 253 253 253 253 253 253
39601 -253 253 253 253 253 253 253 253 253 253 253 253
39602 -253 253 253 253 253 253 253 253 253 250 250 250
39603 -238 238 238 198 198 198 6 6 6 38 38 38
39604 - 58 58 58 26 26 26 38 38 38 2 2 6
39605 - 2 2 6 2 2 6 2 2 6 46 46 46
39606 - 78 78 78 30 30 30 10 10 10 0 0 0
39607 - 0 0 0 0 0 0 0 0 0 0 0 0
39608 - 0 0 0 0 0 0 0 0 0 0 0 0
39609 - 0 0 0 0 0 0 0 0 0 0 0 0
39610 - 0 0 0 0 0 0 0 0 0 0 0 0
39611 - 0 0 0 0 0 0 0 0 0 0 0 0
39612 - 0 0 0 0 0 0 0 0 0 0 0 0
39613 - 0 0 0 0 0 0 0 0 0 0 0 0
39614 - 0 0 0 0 0 0 10 10 10 30 30 30
39615 - 74 74 74 58 58 58 2 2 6 42 42 42
39616 - 2 2 6 22 22 22 231 231 231 253 253 253
39617 -253 253 253 253 253 253 253 253 253 253 253 253
39618 -253 253 253 253 253 253 253 253 253 250 250 250
39619 -253 253 253 253 253 253 253 253 253 253 253 253
39620 -253 253 253 253 253 253 253 253 253 253 253 253
39621 -253 253 253 253 253 253 253 253 253 253 253 253
39622 -253 253 253 253 253 253 253 253 253 253 253 253
39623 -253 253 253 246 246 246 46 46 46 38 38 38
39624 - 42 42 42 14 14 14 38 38 38 14 14 14
39625 - 2 2 6 2 2 6 2 2 6 6 6 6
39626 - 86 86 86 46 46 46 14 14 14 0 0 0
39627 - 0 0 0 0 0 0 0 0 0 0 0 0
39628 - 0 0 0 0 0 0 0 0 0 0 0 0
39629 - 0 0 0 0 0 0 0 0 0 0 0 0
39630 - 0 0 0 0 0 0 0 0 0 0 0 0
39631 - 0 0 0 0 0 0 0 0 0 0 0 0
39632 - 0 0 0 0 0 0 0 0 0 0 0 0
39633 - 0 0 0 0 0 0 0 0 0 0 0 0
39634 - 0 0 0 6 6 6 14 14 14 42 42 42
39635 - 90 90 90 18 18 18 18 18 18 26 26 26
39636 - 2 2 6 116 116 116 253 253 253 253 253 253
39637 -253 253 253 253 253 253 253 253 253 253 253 253
39638 -253 253 253 253 253 253 250 250 250 238 238 238
39639 -253 253 253 253 253 253 253 253 253 253 253 253
39640 -253 253 253 253 253 253 253 253 253 253 253 253
39641 -253 253 253 253 253 253 253 253 253 253 253 253
39642 -253 253 253 253 253 253 253 253 253 253 253 253
39643 -253 253 253 253 253 253 94 94 94 6 6 6
39644 - 2 2 6 2 2 6 10 10 10 34 34 34
39645 - 2 2 6 2 2 6 2 2 6 2 2 6
39646 - 74 74 74 58 58 58 22 22 22 6 6 6
39647 - 0 0 0 0 0 0 0 0 0 0 0 0
39648 - 0 0 0 0 0 0 0 0 0 0 0 0
39649 - 0 0 0 0 0 0 0 0 0 0 0 0
39650 - 0 0 0 0 0 0 0 0 0 0 0 0
39651 - 0 0 0 0 0 0 0 0 0 0 0 0
39652 - 0 0 0 0 0 0 0 0 0 0 0 0
39653 - 0 0 0 0 0 0 0 0 0 0 0 0
39654 - 0 0 0 10 10 10 26 26 26 66 66 66
39655 - 82 82 82 2 2 6 38 38 38 6 6 6
39656 - 14 14 14 210 210 210 253 253 253 253 253 253
39657 -253 253 253 253 253 253 253 253 253 253 253 253
39658 -253 253 253 253 253 253 246 246 246 242 242 242
39659 -253 253 253 253 253 253 253 253 253 253 253 253
39660 -253 253 253 253 253 253 253 253 253 253 253 253
39661 -253 253 253 253 253 253 253 253 253 253 253 253
39662 -253 253 253 253 253 253 253 253 253 253 253 253
39663 -253 253 253 253 253 253 144 144 144 2 2 6
39664 - 2 2 6 2 2 6 2 2 6 46 46 46
39665 - 2 2 6 2 2 6 2 2 6 2 2 6
39666 - 42 42 42 74 74 74 30 30 30 10 10 10
39667 - 0 0 0 0 0 0 0 0 0 0 0 0
39668 - 0 0 0 0 0 0 0 0 0 0 0 0
39669 - 0 0 0 0 0 0 0 0 0 0 0 0
39670 - 0 0 0 0 0 0 0 0 0 0 0 0
39671 - 0 0 0 0 0 0 0 0 0 0 0 0
39672 - 0 0 0 0 0 0 0 0 0 0 0 0
39673 - 0 0 0 0 0 0 0 0 0 0 0 0
39674 - 6 6 6 14 14 14 42 42 42 90 90 90
39675 - 26 26 26 6 6 6 42 42 42 2 2 6
39676 - 74 74 74 250 250 250 253 253 253 253 253 253
39677 -253 253 253 253 253 253 253 253 253 253 253 253
39678 -253 253 253 253 253 253 242 242 242 242 242 242
39679 -253 253 253 253 253 253 253 253 253 253 253 253
39680 -253 253 253 253 253 253 253 253 253 253 253 253
39681 -253 253 253 253 253 253 253 253 253 253 253 253
39682 -253 253 253 253 253 253 253 253 253 253 253 253
39683 -253 253 253 253 253 253 182 182 182 2 2 6
39684 - 2 2 6 2 2 6 2 2 6 46 46 46
39685 - 2 2 6 2 2 6 2 2 6 2 2 6
39686 - 10 10 10 86 86 86 38 38 38 10 10 10
39687 - 0 0 0 0 0 0 0 0 0 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 0 0 0 0 0 0 0 0 0 0 0 0
39691 - 0 0 0 0 0 0 0 0 0 0 0 0
39692 - 0 0 0 0 0 0 0 0 0 0 0 0
39693 - 0 0 0 0 0 0 0 0 0 0 0 0
39694 - 10 10 10 26 26 26 66 66 66 82 82 82
39695 - 2 2 6 22 22 22 18 18 18 2 2 6
39696 -149 149 149 253 253 253 253 253 253 253 253 253
39697 -253 253 253 253 253 253 253 253 253 253 253 253
39698 -253 253 253 253 253 253 234 234 234 242 242 242
39699 -253 253 253 253 253 253 253 253 253 253 253 253
39700 -253 253 253 253 253 253 253 253 253 253 253 253
39701 -253 253 253 253 253 253 253 253 253 253 253 253
39702 -253 253 253 253 253 253 253 253 253 253 253 253
39703 -253 253 253 253 253 253 206 206 206 2 2 6
39704 - 2 2 6 2 2 6 2 2 6 38 38 38
39705 - 2 2 6 2 2 6 2 2 6 2 2 6
39706 - 6 6 6 86 86 86 46 46 46 14 14 14
39707 - 0 0 0 0 0 0 0 0 0 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 0 0 0
39709 - 0 0 0 0 0 0 0 0 0 0 0 0
39710 - 0 0 0 0 0 0 0 0 0 0 0 0
39711 - 0 0 0 0 0 0 0 0 0 0 0 0
39712 - 0 0 0 0 0 0 0 0 0 0 0 0
39713 - 0 0 0 0 0 0 0 0 0 6 6 6
39714 - 18 18 18 46 46 46 86 86 86 18 18 18
39715 - 2 2 6 34 34 34 10 10 10 6 6 6
39716 -210 210 210 253 253 253 253 253 253 253 253 253
39717 -253 253 253 253 253 253 253 253 253 253 253 253
39718 -253 253 253 253 253 253 234 234 234 242 242 242
39719 -253 253 253 253 253 253 253 253 253 253 253 253
39720 -253 253 253 253 253 253 253 253 253 253 253 253
39721 -253 253 253 253 253 253 253 253 253 253 253 253
39722 -253 253 253 253 253 253 253 253 253 253 253 253
39723 -253 253 253 253 253 253 221 221 221 6 6 6
39724 - 2 2 6 2 2 6 6 6 6 30 30 30
39725 - 2 2 6 2 2 6 2 2 6 2 2 6
39726 - 2 2 6 82 82 82 54 54 54 18 18 18
39727 - 6 6 6 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 0 0 0 0 0 0 0 0 0 0 0 0
39731 - 0 0 0 0 0 0 0 0 0 0 0 0
39732 - 0 0 0 0 0 0 0 0 0 0 0 0
39733 - 0 0 0 0 0 0 0 0 0 10 10 10
39734 - 26 26 26 66 66 66 62 62 62 2 2 6
39735 - 2 2 6 38 38 38 10 10 10 26 26 26
39736 -238 238 238 253 253 253 253 253 253 253 253 253
39737 -253 253 253 253 253 253 253 253 253 253 253 253
39738 -253 253 253 253 253 253 231 231 231 238 238 238
39739 -253 253 253 253 253 253 253 253 253 253 253 253
39740 -253 253 253 253 253 253 253 253 253 253 253 253
39741 -253 253 253 253 253 253 253 253 253 253 253 253
39742 -253 253 253 253 253 253 253 253 253 253 253 253
39743 -253 253 253 253 253 253 231 231 231 6 6 6
39744 - 2 2 6 2 2 6 10 10 10 30 30 30
39745 - 2 2 6 2 2 6 2 2 6 2 2 6
39746 - 2 2 6 66 66 66 58 58 58 22 22 22
39747 - 6 6 6 0 0 0 0 0 0 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 0 0 0
39749 - 0 0 0 0 0 0 0 0 0 0 0 0
39750 - 0 0 0 0 0 0 0 0 0 0 0 0
39751 - 0 0 0 0 0 0 0 0 0 0 0 0
39752 - 0 0 0 0 0 0 0 0 0 0 0 0
39753 - 0 0 0 0 0 0 0 0 0 10 10 10
39754 - 38 38 38 78 78 78 6 6 6 2 2 6
39755 - 2 2 6 46 46 46 14 14 14 42 42 42
39756 -246 246 246 253 253 253 253 253 253 253 253 253
39757 -253 253 253 253 253 253 253 253 253 253 253 253
39758 -253 253 253 253 253 253 231 231 231 242 242 242
39759 -253 253 253 253 253 253 253 253 253 253 253 253
39760 -253 253 253 253 253 253 253 253 253 253 253 253
39761 -253 253 253 253 253 253 253 253 253 253 253 253
39762 -253 253 253 253 253 253 253 253 253 253 253 253
39763 -253 253 253 253 253 253 234 234 234 10 10 10
39764 - 2 2 6 2 2 6 22 22 22 14 14 14
39765 - 2 2 6 2 2 6 2 2 6 2 2 6
39766 - 2 2 6 66 66 66 62 62 62 22 22 22
39767 - 6 6 6 0 0 0 0 0 0 0 0 0
39768 - 0 0 0 0 0 0 0 0 0 0 0 0
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 0 0 0
39772 - 0 0 0 0 0 0 0 0 0 0 0 0
39773 - 0 0 0 0 0 0 6 6 6 18 18 18
39774 - 50 50 50 74 74 74 2 2 6 2 2 6
39775 - 14 14 14 70 70 70 34 34 34 62 62 62
39776 -250 250 250 253 253 253 253 253 253 253 253 253
39777 -253 253 253 253 253 253 253 253 253 253 253 253
39778 -253 253 253 253 253 253 231 231 231 246 246 246
39779 -253 253 253 253 253 253 253 253 253 253 253 253
39780 -253 253 253 253 253 253 253 253 253 253 253 253
39781 -253 253 253 253 253 253 253 253 253 253 253 253
39782 -253 253 253 253 253 253 253 253 253 253 253 253
39783 -253 253 253 253 253 253 234 234 234 14 14 14
39784 - 2 2 6 2 2 6 30 30 30 2 2 6
39785 - 2 2 6 2 2 6 2 2 6 2 2 6
39786 - 2 2 6 66 66 66 62 62 62 22 22 22
39787 - 6 6 6 0 0 0 0 0 0 0 0 0
39788 - 0 0 0 0 0 0 0 0 0 0 0 0
39789 - 0 0 0 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 0 0 0 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 0 0 0
39792 - 0 0 0 0 0 0 0 0 0 0 0 0
39793 - 0 0 0 0 0 0 6 6 6 18 18 18
39794 - 54 54 54 62 62 62 2 2 6 2 2 6
39795 - 2 2 6 30 30 30 46 46 46 70 70 70
39796 -250 250 250 253 253 253 253 253 253 253 253 253
39797 -253 253 253 253 253 253 253 253 253 253 253 253
39798 -253 253 253 253 253 253 231 231 231 246 246 246
39799 -253 253 253 253 253 253 253 253 253 253 253 253
39800 -253 253 253 253 253 253 253 253 253 253 253 253
39801 -253 253 253 253 253 253 253 253 253 253 253 253
39802 -253 253 253 253 253 253 253 253 253 253 253 253
39803 -253 253 253 253 253 253 226 226 226 10 10 10
39804 - 2 2 6 6 6 6 30 30 30 2 2 6
39805 - 2 2 6 2 2 6 2 2 6 2 2 6
39806 - 2 2 6 66 66 66 58 58 58 22 22 22
39807 - 6 6 6 0 0 0 0 0 0 0 0 0
39808 - 0 0 0 0 0 0 0 0 0 0 0 0
39809 - 0 0 0 0 0 0 0 0 0 0 0 0
39810 - 0 0 0 0 0 0 0 0 0 0 0 0
39811 - 0 0 0 0 0 0 0 0 0 0 0 0
39812 - 0 0 0 0 0 0 0 0 0 0 0 0
39813 - 0 0 0 0 0 0 6 6 6 22 22 22
39814 - 58 58 58 62 62 62 2 2 6 2 2 6
39815 - 2 2 6 2 2 6 30 30 30 78 78 78
39816 -250 250 250 253 253 253 253 253 253 253 253 253
39817 -253 253 253 253 253 253 253 253 253 253 253 253
39818 -253 253 253 253 253 253 231 231 231 246 246 246
39819 -253 253 253 253 253 253 253 253 253 253 253 253
39820 -253 253 253 253 253 253 253 253 253 253 253 253
39821 -253 253 253 253 253 253 253 253 253 253 253 253
39822 -253 253 253 253 253 253 253 253 253 253 253 253
39823 -253 253 253 253 253 253 206 206 206 2 2 6
39824 - 22 22 22 34 34 34 18 14 6 22 22 22
39825 - 26 26 26 18 18 18 6 6 6 2 2 6
39826 - 2 2 6 82 82 82 54 54 54 18 18 18
39827 - 6 6 6 0 0 0 0 0 0 0 0 0
39828 - 0 0 0 0 0 0 0 0 0 0 0 0
39829 - 0 0 0 0 0 0 0 0 0 0 0 0
39830 - 0 0 0 0 0 0 0 0 0 0 0 0
39831 - 0 0 0 0 0 0 0 0 0 0 0 0
39832 - 0 0 0 0 0 0 0 0 0 0 0 0
39833 - 0 0 0 0 0 0 6 6 6 26 26 26
39834 - 62 62 62 106 106 106 74 54 14 185 133 11
39835 -210 162 10 121 92 8 6 6 6 62 62 62
39836 -238 238 238 253 253 253 253 253 253 253 253 253
39837 -253 253 253 253 253 253 253 253 253 253 253 253
39838 -253 253 253 253 253 253 231 231 231 246 246 246
39839 -253 253 253 253 253 253 253 253 253 253 253 253
39840 -253 253 253 253 253 253 253 253 253 253 253 253
39841 -253 253 253 253 253 253 253 253 253 253 253 253
39842 -253 253 253 253 253 253 253 253 253 253 253 253
39843 -253 253 253 253 253 253 158 158 158 18 18 18
39844 - 14 14 14 2 2 6 2 2 6 2 2 6
39845 - 6 6 6 18 18 18 66 66 66 38 38 38
39846 - 6 6 6 94 94 94 50 50 50 18 18 18
39847 - 6 6 6 0 0 0 0 0 0 0 0 0
39848 - 0 0 0 0 0 0 0 0 0 0 0 0
39849 - 0 0 0 0 0 0 0 0 0 0 0 0
39850 - 0 0 0 0 0 0 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 0 0 0 0 0 0
39852 - 0 0 0 0 0 0 0 0 0 6 6 6
39853 - 10 10 10 10 10 10 18 18 18 38 38 38
39854 - 78 78 78 142 134 106 216 158 10 242 186 14
39855 -246 190 14 246 190 14 156 118 10 10 10 10
39856 - 90 90 90 238 238 238 253 253 253 253 253 253
39857 -253 253 253 253 253 253 253 253 253 253 253 253
39858 -253 253 253 253 253 253 231 231 231 250 250 250
39859 -253 253 253 253 253 253 253 253 253 253 253 253
39860 -253 253 253 253 253 253 253 253 253 253 253 253
39861 -253 253 253 253 253 253 253 253 253 253 253 253
39862 -253 253 253 253 253 253 253 253 253 246 230 190
39863 -238 204 91 238 204 91 181 142 44 37 26 9
39864 - 2 2 6 2 2 6 2 2 6 2 2 6
39865 - 2 2 6 2 2 6 38 38 38 46 46 46
39866 - 26 26 26 106 106 106 54 54 54 18 18 18
39867 - 6 6 6 0 0 0 0 0 0 0 0 0
39868 - 0 0 0 0 0 0 0 0 0 0 0 0
39869 - 0 0 0 0 0 0 0 0 0 0 0 0
39870 - 0 0 0 0 0 0 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 0 0 0 0 0 0
39872 - 0 0 0 6 6 6 14 14 14 22 22 22
39873 - 30 30 30 38 38 38 50 50 50 70 70 70
39874 -106 106 106 190 142 34 226 170 11 242 186 14
39875 -246 190 14 246 190 14 246 190 14 154 114 10
39876 - 6 6 6 74 74 74 226 226 226 253 253 253
39877 -253 253 253 253 253 253 253 253 253 253 253 253
39878 -253 253 253 253 253 253 231 231 231 250 250 250
39879 -253 253 253 253 253 253 253 253 253 253 253 253
39880 -253 253 253 253 253 253 253 253 253 253 253 253
39881 -253 253 253 253 253 253 253 253 253 253 253 253
39882 -253 253 253 253 253 253 253 253 253 228 184 62
39883 -241 196 14 241 208 19 232 195 16 38 30 10
39884 - 2 2 6 2 2 6 2 2 6 2 2 6
39885 - 2 2 6 6 6 6 30 30 30 26 26 26
39886 -203 166 17 154 142 90 66 66 66 26 26 26
39887 - 6 6 6 0 0 0 0 0 0 0 0 0
39888 - 0 0 0 0 0 0 0 0 0 0 0 0
39889 - 0 0 0 0 0 0 0 0 0 0 0 0
39890 - 0 0 0 0 0 0 0 0 0 0 0 0
39891 - 0 0 0 0 0 0 0 0 0 0 0 0
39892 - 6 6 6 18 18 18 38 38 38 58 58 58
39893 - 78 78 78 86 86 86 101 101 101 123 123 123
39894 -175 146 61 210 150 10 234 174 13 246 186 14
39895 -246 190 14 246 190 14 246 190 14 238 190 10
39896 -102 78 10 2 2 6 46 46 46 198 198 198
39897 -253 253 253 253 253 253 253 253 253 253 253 253
39898 -253 253 253 253 253 253 234 234 234 242 242 242
39899 -253 253 253 253 253 253 253 253 253 253 253 253
39900 -253 253 253 253 253 253 253 253 253 253 253 253
39901 -253 253 253 253 253 253 253 253 253 253 253 253
39902 -253 253 253 253 253 253 253 253 253 224 178 62
39903 -242 186 14 241 196 14 210 166 10 22 18 6
39904 - 2 2 6 2 2 6 2 2 6 2 2 6
39905 - 2 2 6 2 2 6 6 6 6 121 92 8
39906 -238 202 15 232 195 16 82 82 82 34 34 34
39907 - 10 10 10 0 0 0 0 0 0 0 0 0
39908 - 0 0 0 0 0 0 0 0 0 0 0 0
39909 - 0 0 0 0 0 0 0 0 0 0 0 0
39910 - 0 0 0 0 0 0 0 0 0 0 0 0
39911 - 0 0 0 0 0 0 0 0 0 0 0 0
39912 - 14 14 14 38 38 38 70 70 70 154 122 46
39913 -190 142 34 200 144 11 197 138 11 197 138 11
39914 -213 154 11 226 170 11 242 186 14 246 190 14
39915 -246 190 14 246 190 14 246 190 14 246 190 14
39916 -225 175 15 46 32 6 2 2 6 22 22 22
39917 -158 158 158 250 250 250 253 253 253 253 253 253
39918 -253 253 253 253 253 253 253 253 253 253 253 253
39919 -253 253 253 253 253 253 253 253 253 253 253 253
39920 -253 253 253 253 253 253 253 253 253 253 253 253
39921 -253 253 253 253 253 253 253 253 253 253 253 253
39922 -253 253 253 250 250 250 242 242 242 224 178 62
39923 -239 182 13 236 186 11 213 154 11 46 32 6
39924 - 2 2 6 2 2 6 2 2 6 2 2 6
39925 - 2 2 6 2 2 6 61 42 6 225 175 15
39926 -238 190 10 236 186 11 112 100 78 42 42 42
39927 - 14 14 14 0 0 0 0 0 0 0 0 0
39928 - 0 0 0 0 0 0 0 0 0 0 0 0
39929 - 0 0 0 0 0 0 0 0 0 0 0 0
39930 - 0 0 0 0 0 0 0 0 0 0 0 0
39931 - 0 0 0 0 0 0 0 0 0 6 6 6
39932 - 22 22 22 54 54 54 154 122 46 213 154 11
39933 -226 170 11 230 174 11 226 170 11 226 170 11
39934 -236 178 12 242 186 14 246 190 14 246 190 14
39935 -246 190 14 246 190 14 246 190 14 246 190 14
39936 -241 196 14 184 144 12 10 10 10 2 2 6
39937 - 6 6 6 116 116 116 242 242 242 253 253 253
39938 -253 253 253 253 253 253 253 253 253 253 253 253
39939 -253 253 253 253 253 253 253 253 253 253 253 253
39940 -253 253 253 253 253 253 253 253 253 253 253 253
39941 -253 253 253 253 253 253 253 253 253 253 253 253
39942 -253 253 253 231 231 231 198 198 198 214 170 54
39943 -236 178 12 236 178 12 210 150 10 137 92 6
39944 - 18 14 6 2 2 6 2 2 6 2 2 6
39945 - 6 6 6 70 47 6 200 144 11 236 178 12
39946 -239 182 13 239 182 13 124 112 88 58 58 58
39947 - 22 22 22 6 6 6 0 0 0 0 0 0
39948 - 0 0 0 0 0 0 0 0 0 0 0 0
39949 - 0 0 0 0 0 0 0 0 0 0 0 0
39950 - 0 0 0 0 0 0 0 0 0 0 0 0
39951 - 0 0 0 0 0 0 0 0 0 10 10 10
39952 - 30 30 30 70 70 70 180 133 36 226 170 11
39953 -239 182 13 242 186 14 242 186 14 246 186 14
39954 -246 190 14 246 190 14 246 190 14 246 190 14
39955 -246 190 14 246 190 14 246 190 14 246 190 14
39956 -246 190 14 232 195 16 98 70 6 2 2 6
39957 - 2 2 6 2 2 6 66 66 66 221 221 221
39958 -253 253 253 253 253 253 253 253 253 253 253 253
39959 -253 253 253 253 253 253 253 253 253 253 253 253
39960 -253 253 253 253 253 253 253 253 253 253 253 253
39961 -253 253 253 253 253 253 253 253 253 253 253 253
39962 -253 253 253 206 206 206 198 198 198 214 166 58
39963 -230 174 11 230 174 11 216 158 10 192 133 9
39964 -163 110 8 116 81 8 102 78 10 116 81 8
39965 -167 114 7 197 138 11 226 170 11 239 182 13
39966 -242 186 14 242 186 14 162 146 94 78 78 78
39967 - 34 34 34 14 14 14 6 6 6 0 0 0
39968 - 0 0 0 0 0 0 0 0 0 0 0 0
39969 - 0 0 0 0 0 0 0 0 0 0 0 0
39970 - 0 0 0 0 0 0 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 6 6 6
39972 - 30 30 30 78 78 78 190 142 34 226 170 11
39973 -239 182 13 246 190 14 246 190 14 246 190 14
39974 -246 190 14 246 190 14 246 190 14 246 190 14
39975 -246 190 14 246 190 14 246 190 14 246 190 14
39976 -246 190 14 241 196 14 203 166 17 22 18 6
39977 - 2 2 6 2 2 6 2 2 6 38 38 38
39978 -218 218 218 253 253 253 253 253 253 253 253 253
39979 -253 253 253 253 253 253 253 253 253 253 253 253
39980 -253 253 253 253 253 253 253 253 253 253 253 253
39981 -253 253 253 253 253 253 253 253 253 253 253 253
39982 -250 250 250 206 206 206 198 198 198 202 162 69
39983 -226 170 11 236 178 12 224 166 10 210 150 10
39984 -200 144 11 197 138 11 192 133 9 197 138 11
39985 -210 150 10 226 170 11 242 186 14 246 190 14
39986 -246 190 14 246 186 14 225 175 15 124 112 88
39987 - 62 62 62 30 30 30 14 14 14 6 6 6
39988 - 0 0 0 0 0 0 0 0 0 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 10 10 10
39992 - 30 30 30 78 78 78 174 135 50 224 166 10
39993 -239 182 13 246 190 14 246 190 14 246 190 14
39994 -246 190 14 246 190 14 246 190 14 246 190 14
39995 -246 190 14 246 190 14 246 190 14 246 190 14
39996 -246 190 14 246 190 14 241 196 14 139 102 15
39997 - 2 2 6 2 2 6 2 2 6 2 2 6
39998 - 78 78 78 250 250 250 253 253 253 253 253 253
39999 -253 253 253 253 253 253 253 253 253 253 253 253
40000 -253 253 253 253 253 253 253 253 253 253 253 253
40001 -253 253 253 253 253 253 253 253 253 253 253 253
40002 -250 250 250 214 214 214 198 198 198 190 150 46
40003 -219 162 10 236 178 12 234 174 13 224 166 10
40004 -216 158 10 213 154 11 213 154 11 216 158 10
40005 -226 170 11 239 182 13 246 190 14 246 190 14
40006 -246 190 14 246 190 14 242 186 14 206 162 42
40007 -101 101 101 58 58 58 30 30 30 14 14 14
40008 - 6 6 6 0 0 0 0 0 0 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 10 10 10
40012 - 30 30 30 74 74 74 174 135 50 216 158 10
40013 -236 178 12 246 190 14 246 190 14 246 190 14
40014 -246 190 14 246 190 14 246 190 14 246 190 14
40015 -246 190 14 246 190 14 246 190 14 246 190 14
40016 -246 190 14 246 190 14 241 196 14 226 184 13
40017 - 61 42 6 2 2 6 2 2 6 2 2 6
40018 - 22 22 22 238 238 238 253 253 253 253 253 253
40019 -253 253 253 253 253 253 253 253 253 253 253 253
40020 -253 253 253 253 253 253 253 253 253 253 253 253
40021 -253 253 253 253 253 253 253 253 253 253 253 253
40022 -253 253 253 226 226 226 187 187 187 180 133 36
40023 -216 158 10 236 178 12 239 182 13 236 178 12
40024 -230 174 11 226 170 11 226 170 11 230 174 11
40025 -236 178 12 242 186 14 246 190 14 246 190 14
40026 -246 190 14 246 190 14 246 186 14 239 182 13
40027 -206 162 42 106 106 106 66 66 66 34 34 34
40028 - 14 14 14 6 6 6 0 0 0 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 6 6 6
40032 - 26 26 26 70 70 70 163 133 67 213 154 11
40033 -236 178 12 246 190 14 246 190 14 246 190 14
40034 -246 190 14 246 190 14 246 190 14 246 190 14
40035 -246 190 14 246 190 14 246 190 14 246 190 14
40036 -246 190 14 246 190 14 246 190 14 241 196 14
40037 -190 146 13 18 14 6 2 2 6 2 2 6
40038 - 46 46 46 246 246 246 253 253 253 253 253 253
40039 -253 253 253 253 253 253 253 253 253 253 253 253
40040 -253 253 253 253 253 253 253 253 253 253 253 253
40041 -253 253 253 253 253 253 253 253 253 253 253 253
40042 -253 253 253 221 221 221 86 86 86 156 107 11
40043 -216 158 10 236 178 12 242 186 14 246 186 14
40044 -242 186 14 239 182 13 239 182 13 242 186 14
40045 -242 186 14 246 186 14 246 190 14 246 190 14
40046 -246 190 14 246 190 14 246 190 14 246 190 14
40047 -242 186 14 225 175 15 142 122 72 66 66 66
40048 - 30 30 30 10 10 10 0 0 0 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 6 6 6
40052 - 26 26 26 70 70 70 163 133 67 210 150 10
40053 -236 178 12 246 190 14 246 190 14 246 190 14
40054 -246 190 14 246 190 14 246 190 14 246 190 14
40055 -246 190 14 246 190 14 246 190 14 246 190 14
40056 -246 190 14 246 190 14 246 190 14 246 190 14
40057 -232 195 16 121 92 8 34 34 34 106 106 106
40058 -221 221 221 253 253 253 253 253 253 253 253 253
40059 -253 253 253 253 253 253 253 253 253 253 253 253
40060 -253 253 253 253 253 253 253 253 253 253 253 253
40061 -253 253 253 253 253 253 253 253 253 253 253 253
40062 -242 242 242 82 82 82 18 14 6 163 110 8
40063 -216 158 10 236 178 12 242 186 14 246 190 14
40064 -246 190 14 246 190 14 246 190 14 246 190 14
40065 -246 190 14 246 190 14 246 190 14 246 190 14
40066 -246 190 14 246 190 14 246 190 14 246 190 14
40067 -246 190 14 246 190 14 242 186 14 163 133 67
40068 - 46 46 46 18 18 18 6 6 6 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 10 10 10
40072 - 30 30 30 78 78 78 163 133 67 210 150 10
40073 -236 178 12 246 186 14 246 190 14 246 190 14
40074 -246 190 14 246 190 14 246 190 14 246 190 14
40075 -246 190 14 246 190 14 246 190 14 246 190 14
40076 -246 190 14 246 190 14 246 190 14 246 190 14
40077 -241 196 14 215 174 15 190 178 144 253 253 253
40078 -253 253 253 253 253 253 253 253 253 253 253 253
40079 -253 253 253 253 253 253 253 253 253 253 253 253
40080 -253 253 253 253 253 253 253 253 253 253 253 253
40081 -253 253 253 253 253 253 253 253 253 218 218 218
40082 - 58 58 58 2 2 6 22 18 6 167 114 7
40083 -216 158 10 236 178 12 246 186 14 246 190 14
40084 -246 190 14 246 190 14 246 190 14 246 190 14
40085 -246 190 14 246 190 14 246 190 14 246 190 14
40086 -246 190 14 246 190 14 246 190 14 246 190 14
40087 -246 190 14 246 186 14 242 186 14 190 150 46
40088 - 54 54 54 22 22 22 6 6 6 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 14 14 14
40092 - 38 38 38 86 86 86 180 133 36 213 154 11
40093 -236 178 12 246 186 14 246 190 14 246 190 14
40094 -246 190 14 246 190 14 246 190 14 246 190 14
40095 -246 190 14 246 190 14 246 190 14 246 190 14
40096 -246 190 14 246 190 14 246 190 14 246 190 14
40097 -246 190 14 232 195 16 190 146 13 214 214 214
40098 -253 253 253 253 253 253 253 253 253 253 253 253
40099 -253 253 253 253 253 253 253 253 253 253 253 253
40100 -253 253 253 253 253 253 253 253 253 253 253 253
40101 -253 253 253 250 250 250 170 170 170 26 26 26
40102 - 2 2 6 2 2 6 37 26 9 163 110 8
40103 -219 162 10 239 182 13 246 186 14 246 190 14
40104 -246 190 14 246 190 14 246 190 14 246 190 14
40105 -246 190 14 246 190 14 246 190 14 246 190 14
40106 -246 190 14 246 190 14 246 190 14 246 190 14
40107 -246 186 14 236 178 12 224 166 10 142 122 72
40108 - 46 46 46 18 18 18 6 6 6 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 6 6 6 18 18 18
40112 - 50 50 50 109 106 95 192 133 9 224 166 10
40113 -242 186 14 246 190 14 246 190 14 246 190 14
40114 -246 190 14 246 190 14 246 190 14 246 190 14
40115 -246 190 14 246 190 14 246 190 14 246 190 14
40116 -246 190 14 246 190 14 246 190 14 246 190 14
40117 -242 186 14 226 184 13 210 162 10 142 110 46
40118 -226 226 226 253 253 253 253 253 253 253 253 253
40119 -253 253 253 253 253 253 253 253 253 253 253 253
40120 -253 253 253 253 253 253 253 253 253 253 253 253
40121 -198 198 198 66 66 66 2 2 6 2 2 6
40122 - 2 2 6 2 2 6 50 34 6 156 107 11
40123 -219 162 10 239 182 13 246 186 14 246 190 14
40124 -246 190 14 246 190 14 246 190 14 246 190 14
40125 -246 190 14 246 190 14 246 190 14 246 190 14
40126 -246 190 14 246 190 14 246 190 14 242 186 14
40127 -234 174 13 213 154 11 154 122 46 66 66 66
40128 - 30 30 30 10 10 10 0 0 0 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 6 6 6 22 22 22
40132 - 58 58 58 154 121 60 206 145 10 234 174 13
40133 -242 186 14 246 186 14 246 190 14 246 190 14
40134 -246 190 14 246 190 14 246 190 14 246 190 14
40135 -246 190 14 246 190 14 246 190 14 246 190 14
40136 -246 190 14 246 190 14 246 190 14 246 190 14
40137 -246 186 14 236 178 12 210 162 10 163 110 8
40138 - 61 42 6 138 138 138 218 218 218 250 250 250
40139 -253 253 253 253 253 253 253 253 253 250 250 250
40140 -242 242 242 210 210 210 144 144 144 66 66 66
40141 - 6 6 6 2 2 6 2 2 6 2 2 6
40142 - 2 2 6 2 2 6 61 42 6 163 110 8
40143 -216 158 10 236 178 12 246 190 14 246 190 14
40144 -246 190 14 246 190 14 246 190 14 246 190 14
40145 -246 190 14 246 190 14 246 190 14 246 190 14
40146 -246 190 14 239 182 13 230 174 11 216 158 10
40147 -190 142 34 124 112 88 70 70 70 38 38 38
40148 - 18 18 18 6 6 6 0 0 0 0 0 0
40149 - 0 0 0 0 0 0 0 0 0 0 0 0
40150 - 0 0 0 0 0 0 0 0 0 0 0 0
40151 - 0 0 0 0 0 0 6 6 6 22 22 22
40152 - 62 62 62 168 124 44 206 145 10 224 166 10
40153 -236 178 12 239 182 13 242 186 14 242 186 14
40154 -246 186 14 246 190 14 246 190 14 246 190 14
40155 -246 190 14 246 190 14 246 190 14 246 190 14
40156 -246 190 14 246 190 14 246 190 14 246 190 14
40157 -246 190 14 236 178 12 216 158 10 175 118 6
40158 - 80 54 7 2 2 6 6 6 6 30 30 30
40159 - 54 54 54 62 62 62 50 50 50 38 38 38
40160 - 14 14 14 2 2 6 2 2 6 2 2 6
40161 - 2 2 6 2 2 6 2 2 6 2 2 6
40162 - 2 2 6 6 6 6 80 54 7 167 114 7
40163 -213 154 11 236 178 12 246 190 14 246 190 14
40164 -246 190 14 246 190 14 246 190 14 246 190 14
40165 -246 190 14 242 186 14 239 182 13 239 182 13
40166 -230 174 11 210 150 10 174 135 50 124 112 88
40167 - 82 82 82 54 54 54 34 34 34 18 18 18
40168 - 6 6 6 0 0 0 0 0 0 0 0 0
40169 - 0 0 0 0 0 0 0 0 0 0 0 0
40170 - 0 0 0 0 0 0 0 0 0 0 0 0
40171 - 0 0 0 0 0 0 6 6 6 18 18 18
40172 - 50 50 50 158 118 36 192 133 9 200 144 11
40173 -216 158 10 219 162 10 224 166 10 226 170 11
40174 -230 174 11 236 178 12 239 182 13 239 182 13
40175 -242 186 14 246 186 14 246 190 14 246 190 14
40176 -246 190 14 246 190 14 246 190 14 246 190 14
40177 -246 186 14 230 174 11 210 150 10 163 110 8
40178 -104 69 6 10 10 10 2 2 6 2 2 6
40179 - 2 2 6 2 2 6 2 2 6 2 2 6
40180 - 2 2 6 2 2 6 2 2 6 2 2 6
40181 - 2 2 6 2 2 6 2 2 6 2 2 6
40182 - 2 2 6 6 6 6 91 60 6 167 114 7
40183 -206 145 10 230 174 11 242 186 14 246 190 14
40184 -246 190 14 246 190 14 246 186 14 242 186 14
40185 -239 182 13 230 174 11 224 166 10 213 154 11
40186 -180 133 36 124 112 88 86 86 86 58 58 58
40187 - 38 38 38 22 22 22 10 10 10 6 6 6
40188 - 0 0 0 0 0 0 0 0 0 0 0 0
40189 - 0 0 0 0 0 0 0 0 0 0 0 0
40190 - 0 0 0 0 0 0 0 0 0 0 0 0
40191 - 0 0 0 0 0 0 0 0 0 14 14 14
40192 - 34 34 34 70 70 70 138 110 50 158 118 36
40193 -167 114 7 180 123 7 192 133 9 197 138 11
40194 -200 144 11 206 145 10 213 154 11 219 162 10
40195 -224 166 10 230 174 11 239 182 13 242 186 14
40196 -246 186 14 246 186 14 246 186 14 246 186 14
40197 -239 182 13 216 158 10 185 133 11 152 99 6
40198 -104 69 6 18 14 6 2 2 6 2 2 6
40199 - 2 2 6 2 2 6 2 2 6 2 2 6
40200 - 2 2 6 2 2 6 2 2 6 2 2 6
40201 - 2 2 6 2 2 6 2 2 6 2 2 6
40202 - 2 2 6 6 6 6 80 54 7 152 99 6
40203 -192 133 9 219 162 10 236 178 12 239 182 13
40204 -246 186 14 242 186 14 239 182 13 236 178 12
40205 -224 166 10 206 145 10 192 133 9 154 121 60
40206 - 94 94 94 62 62 62 42 42 42 22 22 22
40207 - 14 14 14 6 6 6 0 0 0 0 0 0
40208 - 0 0 0 0 0 0 0 0 0 0 0 0
40209 - 0 0 0 0 0 0 0 0 0 0 0 0
40210 - 0 0 0 0 0 0 0 0 0 0 0 0
40211 - 0 0 0 0 0 0 0 0 0 6 6 6
40212 - 18 18 18 34 34 34 58 58 58 78 78 78
40213 -101 98 89 124 112 88 142 110 46 156 107 11
40214 -163 110 8 167 114 7 175 118 6 180 123 7
40215 -185 133 11 197 138 11 210 150 10 219 162 10
40216 -226 170 11 236 178 12 236 178 12 234 174 13
40217 -219 162 10 197 138 11 163 110 8 130 83 6
40218 - 91 60 6 10 10 10 2 2 6 2 2 6
40219 - 18 18 18 38 38 38 38 38 38 38 38 38
40220 - 38 38 38 38 38 38 38 38 38 38 38 38
40221 - 38 38 38 38 38 38 26 26 26 2 2 6
40222 - 2 2 6 6 6 6 70 47 6 137 92 6
40223 -175 118 6 200 144 11 219 162 10 230 174 11
40224 -234 174 13 230 174 11 219 162 10 210 150 10
40225 -192 133 9 163 110 8 124 112 88 82 82 82
40226 - 50 50 50 30 30 30 14 14 14 6 6 6
40227 - 0 0 0 0 0 0 0 0 0 0 0 0
40228 - 0 0 0 0 0 0 0 0 0 0 0 0
40229 - 0 0 0 0 0 0 0 0 0 0 0 0
40230 - 0 0 0 0 0 0 0 0 0 0 0 0
40231 - 0 0 0 0 0 0 0 0 0 0 0 0
40232 - 6 6 6 14 14 14 22 22 22 34 34 34
40233 - 42 42 42 58 58 58 74 74 74 86 86 86
40234 -101 98 89 122 102 70 130 98 46 121 87 25
40235 -137 92 6 152 99 6 163 110 8 180 123 7
40236 -185 133 11 197 138 11 206 145 10 200 144 11
40237 -180 123 7 156 107 11 130 83 6 104 69 6
40238 - 50 34 6 54 54 54 110 110 110 101 98 89
40239 - 86 86 86 82 82 82 78 78 78 78 78 78
40240 - 78 78 78 78 78 78 78 78 78 78 78 78
40241 - 78 78 78 82 82 82 86 86 86 94 94 94
40242 -106 106 106 101 101 101 86 66 34 124 80 6
40243 -156 107 11 180 123 7 192 133 9 200 144 11
40244 -206 145 10 200 144 11 192 133 9 175 118 6
40245 -139 102 15 109 106 95 70 70 70 42 42 42
40246 - 22 22 22 10 10 10 0 0 0 0 0 0
40247 - 0 0 0 0 0 0 0 0 0 0 0 0
40248 - 0 0 0 0 0 0 0 0 0 0 0 0
40249 - 0 0 0 0 0 0 0 0 0 0 0 0
40250 - 0 0 0 0 0 0 0 0 0 0 0 0
40251 - 0 0 0 0 0 0 0 0 0 0 0 0
40252 - 0 0 0 0 0 0 6 6 6 10 10 10
40253 - 14 14 14 22 22 22 30 30 30 38 38 38
40254 - 50 50 50 62 62 62 74 74 74 90 90 90
40255 -101 98 89 112 100 78 121 87 25 124 80 6
40256 -137 92 6 152 99 6 152 99 6 152 99 6
40257 -138 86 6 124 80 6 98 70 6 86 66 30
40258 -101 98 89 82 82 82 58 58 58 46 46 46
40259 - 38 38 38 34 34 34 34 34 34 34 34 34
40260 - 34 34 34 34 34 34 34 34 34 34 34 34
40261 - 34 34 34 34 34 34 38 38 38 42 42 42
40262 - 54 54 54 82 82 82 94 86 76 91 60 6
40263 -134 86 6 156 107 11 167 114 7 175 118 6
40264 -175 118 6 167 114 7 152 99 6 121 87 25
40265 -101 98 89 62 62 62 34 34 34 18 18 18
40266 - 6 6 6 0 0 0 0 0 0 0 0 0
40267 - 0 0 0 0 0 0 0 0 0 0 0 0
40268 - 0 0 0 0 0 0 0 0 0 0 0 0
40269 - 0 0 0 0 0 0 0 0 0 0 0 0
40270 - 0 0 0 0 0 0 0 0 0 0 0 0
40271 - 0 0 0 0 0 0 0 0 0 0 0 0
40272 - 0 0 0 0 0 0 0 0 0 0 0 0
40273 - 0 0 0 6 6 6 6 6 6 10 10 10
40274 - 18 18 18 22 22 22 30 30 30 42 42 42
40275 - 50 50 50 66 66 66 86 86 86 101 98 89
40276 -106 86 58 98 70 6 104 69 6 104 69 6
40277 -104 69 6 91 60 6 82 62 34 90 90 90
40278 - 62 62 62 38 38 38 22 22 22 14 14 14
40279 - 10 10 10 10 10 10 10 10 10 10 10 10
40280 - 10 10 10 10 10 10 6 6 6 10 10 10
40281 - 10 10 10 10 10 10 10 10 10 14 14 14
40282 - 22 22 22 42 42 42 70 70 70 89 81 66
40283 - 80 54 7 104 69 6 124 80 6 137 92 6
40284 -134 86 6 116 81 8 100 82 52 86 86 86
40285 - 58 58 58 30 30 30 14 14 14 6 6 6
40286 - 0 0 0 0 0 0 0 0 0 0 0 0
40287 - 0 0 0 0 0 0 0 0 0 0 0 0
40288 - 0 0 0 0 0 0 0 0 0 0 0 0
40289 - 0 0 0 0 0 0 0 0 0 0 0 0
40290 - 0 0 0 0 0 0 0 0 0 0 0 0
40291 - 0 0 0 0 0 0 0 0 0 0 0 0
40292 - 0 0 0 0 0 0 0 0 0 0 0 0
40293 - 0 0 0 0 0 0 0 0 0 0 0 0
40294 - 0 0 0 6 6 6 10 10 10 14 14 14
40295 - 18 18 18 26 26 26 38 38 38 54 54 54
40296 - 70 70 70 86 86 86 94 86 76 89 81 66
40297 - 89 81 66 86 86 86 74 74 74 50 50 50
40298 - 30 30 30 14 14 14 6 6 6 0 0 0
40299 - 0 0 0 0 0 0 0 0 0 0 0 0
40300 - 0 0 0 0 0 0 0 0 0 0 0 0
40301 - 0 0 0 0 0 0 0 0 0 0 0 0
40302 - 6 6 6 18 18 18 34 34 34 58 58 58
40303 - 82 82 82 89 81 66 89 81 66 89 81 66
40304 - 94 86 66 94 86 76 74 74 74 50 50 50
40305 - 26 26 26 14 14 14 6 6 6 0 0 0
40306 - 0 0 0 0 0 0 0 0 0 0 0 0
40307 - 0 0 0 0 0 0 0 0 0 0 0 0
40308 - 0 0 0 0 0 0 0 0 0 0 0 0
40309 - 0 0 0 0 0 0 0 0 0 0 0 0
40310 - 0 0 0 0 0 0 0 0 0 0 0 0
40311 - 0 0 0 0 0 0 0 0 0 0 0 0
40312 - 0 0 0 0 0 0 0 0 0 0 0 0
40313 - 0 0 0 0 0 0 0 0 0 0 0 0
40314 - 0 0 0 0 0 0 0 0 0 0 0 0
40315 - 6 6 6 6 6 6 14 14 14 18 18 18
40316 - 30 30 30 38 38 38 46 46 46 54 54 54
40317 - 50 50 50 42 42 42 30 30 30 18 18 18
40318 - 10 10 10 0 0 0 0 0 0 0 0 0
40319 - 0 0 0 0 0 0 0 0 0 0 0 0
40320 - 0 0 0 0 0 0 0 0 0 0 0 0
40321 - 0 0 0 0 0 0 0 0 0 0 0 0
40322 - 0 0 0 6 6 6 14 14 14 26 26 26
40323 - 38 38 38 50 50 50 58 58 58 58 58 58
40324 - 54 54 54 42 42 42 30 30 30 18 18 18
40325 - 10 10 10 0 0 0 0 0 0 0 0 0
40326 - 0 0 0 0 0 0 0 0 0 0 0 0
40327 - 0 0 0 0 0 0 0 0 0 0 0 0
40328 - 0 0 0 0 0 0 0 0 0 0 0 0
40329 - 0 0 0 0 0 0 0 0 0 0 0 0
40330 - 0 0 0 0 0 0 0 0 0 0 0 0
40331 - 0 0 0 0 0 0 0 0 0 0 0 0
40332 - 0 0 0 0 0 0 0 0 0 0 0 0
40333 - 0 0 0 0 0 0 0 0 0 0 0 0
40334 - 0 0 0 0 0 0 0 0 0 0 0 0
40335 - 0 0 0 0 0 0 0 0 0 6 6 6
40336 - 6 6 6 10 10 10 14 14 14 18 18 18
40337 - 18 18 18 14 14 14 10 10 10 6 6 6
40338 - 0 0 0 0 0 0 0 0 0 0 0 0
40339 - 0 0 0 0 0 0 0 0 0 0 0 0
40340 - 0 0 0 0 0 0 0 0 0 0 0 0
40341 - 0 0 0 0 0 0 0 0 0 0 0 0
40342 - 0 0 0 0 0 0 0 0 0 6 6 6
40343 - 14 14 14 18 18 18 22 22 22 22 22 22
40344 - 18 18 18 14 14 14 10 10 10 6 6 6
40345 - 0 0 0 0 0 0 0 0 0 0 0 0
40346 - 0 0 0 0 0 0 0 0 0 0 0 0
40347 - 0 0 0 0 0 0 0 0 0 0 0 0
40348 - 0 0 0 0 0 0 0 0 0 0 0 0
40349 - 0 0 0 0 0 0 0 0 0 0 0 0
40350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40363 +4 4 4 4 4 4
40364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40377 +4 4 4 4 4 4
40378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40391 +4 4 4 4 4 4
40392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40405 +4 4 4 4 4 4
40406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40419 +4 4 4 4 4 4
40420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40433 +4 4 4 4 4 4
40434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40438 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40439 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40443 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40444 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40445 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40447 +4 4 4 4 4 4
40448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40452 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40453 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40454 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40457 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40458 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40459 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40460 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40461 +4 4 4 4 4 4
40462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40466 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40467 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40468 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40471 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40472 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40473 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40474 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40475 +4 4 4 4 4 4
40476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40479 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40480 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40481 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40482 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40484 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40485 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40486 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40487 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40488 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40489 +4 4 4 4 4 4
40490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40493 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40494 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40495 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40496 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40497 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40498 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40499 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40500 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40501 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40502 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40503 +4 4 4 4 4 4
40504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40507 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40508 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40509 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40510 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40511 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40512 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40513 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40514 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40515 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40516 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40517 +4 4 4 4 4 4
40518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40520 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40521 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40522 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40523 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40524 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40525 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40526 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40527 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40528 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40529 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40530 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40531 +4 4 4 4 4 4
40532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40534 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40535 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40536 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40537 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40538 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40539 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40540 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40541 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40542 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40543 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40544 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40545 +4 4 4 4 4 4
40546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40548 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40549 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40550 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40551 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40552 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40553 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40554 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40555 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40556 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40557 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40558 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40559 +4 4 4 4 4 4
40560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40562 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40563 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40564 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40565 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40566 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40567 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40568 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40569 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40570 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40571 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40572 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40573 +4 4 4 4 4 4
40574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40575 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40576 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40577 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40578 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40579 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40580 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40581 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40582 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40583 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40584 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40585 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40586 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40587 +4 4 4 4 4 4
40588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40589 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40590 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40591 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40592 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40593 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40594 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40595 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40596 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40597 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40598 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40599 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40600 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40601 +0 0 0 4 4 4
40602 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40603 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40604 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40605 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40606 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40607 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40608 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40609 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40610 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40611 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40612 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40613 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40614 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40615 +2 0 0 0 0 0
40616 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40617 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40618 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40619 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40620 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40621 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40622 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40623 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40624 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40625 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40626 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40627 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40628 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40629 +37 38 37 0 0 0
40630 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40631 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40632 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40633 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40634 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40635 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40636 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40637 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40638 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40639 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40640 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40641 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40642 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40643 +85 115 134 4 0 0
40644 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40645 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40646 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40647 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40648 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40649 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40650 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40651 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40652 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40653 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40654 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40655 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40656 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40657 +60 73 81 4 0 0
40658 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40659 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40660 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40661 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40662 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40663 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40664 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40665 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40666 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40667 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40668 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40669 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40670 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40671 +16 19 21 4 0 0
40672 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40673 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40674 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40675 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40676 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40677 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40678 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40679 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40680 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40681 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40682 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40683 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40684 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40685 +4 0 0 4 3 3
40686 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40687 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40688 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40690 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40691 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40692 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40693 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40694 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40695 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40696 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40697 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40698 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40699 +3 2 2 4 4 4
40700 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40701 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40702 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40703 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40704 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40705 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40706 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40707 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40708 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40709 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40710 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40711 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40712 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40713 +4 4 4 4 4 4
40714 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40715 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40716 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40717 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40718 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40719 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40720 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40721 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40722 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40723 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40724 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40725 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40726 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40727 +4 4 4 4 4 4
40728 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40729 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40730 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40731 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40732 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40733 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40734 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40735 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40736 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40737 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40738 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40739 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40740 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40741 +5 5 5 5 5 5
40742 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40743 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40744 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40745 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40746 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40747 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40748 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40749 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40750 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40751 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40752 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40753 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40754 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40755 +5 5 5 4 4 4
40756 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40757 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40758 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40759 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40760 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40761 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40762 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40763 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40764 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40765 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40766 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40767 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40769 +4 4 4 4 4 4
40770 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40771 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40772 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40773 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40774 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40775 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40776 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40777 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40778 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40779 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40780 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40781 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40783 +4 4 4 4 4 4
40784 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40785 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40786 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40787 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40788 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40789 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40790 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40791 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40792 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40793 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40794 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40797 +4 4 4 4 4 4
40798 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40799 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40800 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40801 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40802 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40803 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40804 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40805 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40806 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40807 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40808 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40811 +4 4 4 4 4 4
40812 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40813 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40814 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40815 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40816 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40817 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40818 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40819 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40820 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40821 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40822 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40825 +4 4 4 4 4 4
40826 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40827 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40828 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40829 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40830 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40831 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40832 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40833 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40834 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40835 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40836 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40839 +4 4 4 4 4 4
40840 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40841 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40842 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40843 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40844 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40845 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40846 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40847 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40848 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40849 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40850 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40853 +4 4 4 4 4 4
40854 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40855 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40856 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40857 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40858 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40859 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40860 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40861 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40862 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40863 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40864 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40867 +4 4 4 4 4 4
40868 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40869 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40870 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40871 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40872 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40873 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40874 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40875 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40876 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40877 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40878 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40881 +4 4 4 4 4 4
40882 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40883 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40884 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40885 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40886 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40887 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40888 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40889 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40890 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40891 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40892 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40895 +4 4 4 4 4 4
40896 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
40897 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40898 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40899 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40900 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40901 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40902 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40903 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40904 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40905 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40906 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40909 +4 4 4 4 4 4
40910 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40911 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40912 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40913 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40914 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40915 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
40916 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
40917 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
40918 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40919 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40920 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40923 +4 4 4 4 4 4
40924 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40925 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
40926 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40927 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
40928 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40929 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
40930 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
40931 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
40932 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40933 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40934 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40937 +4 4 4 4 4 4
40938 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
40939 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
40940 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40941 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40942 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40943 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40944 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40945 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40946 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40947 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40948 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40951 +4 4 4 4 4 4
40952 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
40953 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
40954 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40955 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
40956 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
40957 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
40958 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
40959 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
40960 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40961 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40962 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40965 +4 4 4 4 4 4
40966 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40967 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
40968 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40969 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
40970 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
40971 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
40972 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
40973 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
40974 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40975 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40976 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40979 +4 4 4 4 4 4
40980 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
40981 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
40982 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40983 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
40984 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
40985 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
40986 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
40987 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
40988 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
40989 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40990 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40993 +4 4 4 4 4 4
40994 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40995 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
40996 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
40997 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
40998 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
40999 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41000 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41001 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41002 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41003 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41004 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41007 +4 4 4 4 4 4
41008 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41009 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41010 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41011 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41012 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41013 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41014 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41015 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41016 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41017 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41018 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41021 +4 4 4 4 4 4
41022 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41023 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41024 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41025 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41026 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41027 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41028 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41029 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41030 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41031 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41032 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41035 +4 4 4 4 4 4
41036 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41037 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41038 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41039 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41040 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41041 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41042 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41043 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41044 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41045 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41046 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41049 +4 4 4 4 4 4
41050 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41051 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41052 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41053 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41054 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41055 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41056 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41057 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41058 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41059 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41060 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41063 +4 4 4 4 4 4
41064 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41065 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41066 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41067 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41068 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41069 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41070 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41071 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41072 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41073 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41074 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41077 +4 4 4 4 4 4
41078 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41079 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41080 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41081 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41082 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41083 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41084 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41085 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41086 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41087 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41088 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41091 +4 4 4 4 4 4
41092 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41093 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41094 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41095 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41096 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41097 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41098 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41099 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41100 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41101 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41102 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41105 +4 4 4 4 4 4
41106 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41107 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41108 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41109 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41110 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41111 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41112 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41113 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41114 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41115 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41116 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41119 +4 4 4 4 4 4
41120 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41121 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41122 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41123 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41124 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41125 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41126 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41127 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41128 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41129 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41130 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41133 +4 4 4 4 4 4
41134 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41135 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41136 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41137 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41138 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41139 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41140 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41141 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41142 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41143 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41144 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41147 +4 4 4 4 4 4
41148 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41149 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41150 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41151 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41152 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41153 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41154 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41155 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41156 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41157 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41158 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41161 +4 4 4 4 4 4
41162 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41163 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41164 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41165 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41166 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41167 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41168 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41169 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41170 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41171 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41175 +4 4 4 4 4 4
41176 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41177 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41178 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41179 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41180 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41181 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41182 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41183 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41184 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41185 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41189 +4 4 4 4 4 4
41190 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41191 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41192 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41193 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41194 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41195 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41196 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41197 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41198 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41199 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41203 +4 4 4 4 4 4
41204 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41205 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41206 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41207 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41208 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41209 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41210 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41211 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41212 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41213 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41217 +4 4 4 4 4 4
41218 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41219 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41220 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41221 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41222 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41223 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41224 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41225 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41226 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41231 +4 4 4 4 4 4
41232 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41233 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41234 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41235 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41236 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41237 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41238 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41239 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41240 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41245 +4 4 4 4 4 4
41246 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41247 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41248 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41249 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41250 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41251 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41252 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41253 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41254 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41259 +4 4 4 4 4 4
41260 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41261 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41262 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41263 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41264 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41265 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41266 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41267 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41273 +4 4 4 4 4 4
41274 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41275 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41276 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41277 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41278 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41279 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41280 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41281 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287 +4 4 4 4 4 4
41288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41289 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41290 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41291 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41292 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41293 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41294 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41295 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301 +4 4 4 4 4 4
41302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41303 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41304 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41305 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41306 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41307 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41308 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41309 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315 +4 4 4 4 4 4
41316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41317 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41318 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41319 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41320 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41321 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41322 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41323 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329 +4 4 4 4 4 4
41330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41332 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41333 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41334 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41335 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41336 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41337 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +4 4 4 4 4 4
41344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41347 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41348 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41349 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41350 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 4 4 4
41358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41361 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41362 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41363 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41364 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371 +4 4 4 4 4 4
41372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41375 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41376 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41377 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41378 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41385 +4 4 4 4 4 4
41386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41389 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41390 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41391 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41392 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41399 +4 4 4 4 4 4
41400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41404 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41405 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41406 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41413 +4 4 4 4 4 4
41414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41418 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41419 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41420 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41427 +4 4 4 4 4 4
41428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41432 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41433 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41434 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41441 +4 4 4 4 4 4
41442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41446 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41447 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41455 +4 4 4 4 4 4
41456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41460 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41461 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41469 +4 4 4 4 4 4
41470 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41471 index 087fc99..f85ed76 100644
41472 --- a/drivers/video/udlfb.c
41473 +++ b/drivers/video/udlfb.c
41474 @@ -585,11 +585,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41475 dlfb_urb_completion(urb);
41476
41477 error:
41478 - atomic_add(bytes_sent, &dev->bytes_sent);
41479 - atomic_add(bytes_identical, &dev->bytes_identical);
41480 - atomic_add(width*height*2, &dev->bytes_rendered);
41481 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41482 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41483 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41484 end_cycles = get_cycles();
41485 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41486 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41487 >> 10)), /* Kcycles */
41488 &dev->cpu_kcycles_used);
41489
41490 @@ -710,11 +710,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41491 dlfb_urb_completion(urb);
41492
41493 error:
41494 - atomic_add(bytes_sent, &dev->bytes_sent);
41495 - atomic_add(bytes_identical, &dev->bytes_identical);
41496 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41497 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41498 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41499 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41500 end_cycles = get_cycles();
41501 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41502 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41503 >> 10)), /* Kcycles */
41504 &dev->cpu_kcycles_used);
41505 }
41506 @@ -1306,7 +1306,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41507 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41508 struct dlfb_data *dev = fb_info->par;
41509 return snprintf(buf, PAGE_SIZE, "%u\n",
41510 - atomic_read(&dev->bytes_rendered));
41511 + atomic_read_unchecked(&dev->bytes_rendered));
41512 }
41513
41514 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41515 @@ -1314,7 +1314,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41516 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41517 struct dlfb_data *dev = fb_info->par;
41518 return snprintf(buf, PAGE_SIZE, "%u\n",
41519 - atomic_read(&dev->bytes_identical));
41520 + atomic_read_unchecked(&dev->bytes_identical));
41521 }
41522
41523 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41524 @@ -1322,7 +1322,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41525 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41526 struct dlfb_data *dev = fb_info->par;
41527 return snprintf(buf, PAGE_SIZE, "%u\n",
41528 - atomic_read(&dev->bytes_sent));
41529 + atomic_read_unchecked(&dev->bytes_sent));
41530 }
41531
41532 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41533 @@ -1330,7 +1330,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41534 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41535 struct dlfb_data *dev = fb_info->par;
41536 return snprintf(buf, PAGE_SIZE, "%u\n",
41537 - atomic_read(&dev->cpu_kcycles_used));
41538 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41539 }
41540
41541 static ssize_t edid_show(
41542 @@ -1387,10 +1387,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41543 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41544 struct dlfb_data *dev = fb_info->par;
41545
41546 - atomic_set(&dev->bytes_rendered, 0);
41547 - atomic_set(&dev->bytes_identical, 0);
41548 - atomic_set(&dev->bytes_sent, 0);
41549 - atomic_set(&dev->cpu_kcycles_used, 0);
41550 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41551 + atomic_set_unchecked(&dev->bytes_identical, 0);
41552 + atomic_set_unchecked(&dev->bytes_sent, 0);
41553 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41554
41555 return count;
41556 }
41557 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41558 index 7f8472c..9842e87 100644
41559 --- a/drivers/video/uvesafb.c
41560 +++ b/drivers/video/uvesafb.c
41561 @@ -19,6 +19,7 @@
41562 #include <linux/io.h>
41563 #include <linux/mutex.h>
41564 #include <linux/slab.h>
41565 +#include <linux/moduleloader.h>
41566 #include <video/edid.h>
41567 #include <video/uvesafb.h>
41568 #ifdef CONFIG_X86
41569 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
41570 NULL,
41571 };
41572
41573 - return call_usermodehelper(v86d_path, argv, envp, 1);
41574 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
41575 }
41576
41577 /*
41578 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41579 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41580 par->pmi_setpal = par->ypan = 0;
41581 } else {
41582 +
41583 +#ifdef CONFIG_PAX_KERNEXEC
41584 +#ifdef CONFIG_MODULES
41585 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41586 +#endif
41587 + if (!par->pmi_code) {
41588 + par->pmi_setpal = par->ypan = 0;
41589 + return 0;
41590 + }
41591 +#endif
41592 +
41593 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41594 + task->t.regs.edi);
41595 +
41596 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41597 + pax_open_kernel();
41598 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41599 + pax_close_kernel();
41600 +
41601 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41602 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41603 +#else
41604 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41605 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41606 +#endif
41607 +
41608 printk(KERN_INFO "uvesafb: protected mode interface info at "
41609 "%04x:%04x\n",
41610 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41611 @@ -1821,6 +1844,11 @@ out:
41612 if (par->vbe_modes)
41613 kfree(par->vbe_modes);
41614
41615 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41616 + if (par->pmi_code)
41617 + module_free_exec(NULL, par->pmi_code);
41618 +#endif
41619 +
41620 framebuffer_release(info);
41621 return err;
41622 }
41623 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
41624 kfree(par->vbe_state_orig);
41625 if (par->vbe_state_saved)
41626 kfree(par->vbe_state_saved);
41627 +
41628 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41629 + if (par->pmi_code)
41630 + module_free_exec(NULL, par->pmi_code);
41631 +#endif
41632 +
41633 }
41634
41635 framebuffer_release(info);
41636 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41637 index 501b340..86bd4cf 100644
41638 --- a/drivers/video/vesafb.c
41639 +++ b/drivers/video/vesafb.c
41640 @@ -9,6 +9,7 @@
41641 */
41642
41643 #include <linux/module.h>
41644 +#include <linux/moduleloader.h>
41645 #include <linux/kernel.h>
41646 #include <linux/errno.h>
41647 #include <linux/string.h>
41648 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41649 static int vram_total __initdata; /* Set total amount of memory */
41650 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41651 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41652 -static void (*pmi_start)(void) __read_mostly;
41653 -static void (*pmi_pal) (void) __read_mostly;
41654 +static void (*pmi_start)(void) __read_only;
41655 +static void (*pmi_pal) (void) __read_only;
41656 static int depth __read_mostly;
41657 static int vga_compat __read_mostly;
41658 /* --------------------------------------------------------------------- */
41659 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41660 unsigned int size_vmode;
41661 unsigned int size_remap;
41662 unsigned int size_total;
41663 + void *pmi_code = NULL;
41664
41665 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41666 return -ENODEV;
41667 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41668 size_remap = size_total;
41669 vesafb_fix.smem_len = size_remap;
41670
41671 -#ifndef __i386__
41672 - screen_info.vesapm_seg = 0;
41673 -#endif
41674 -
41675 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41676 printk(KERN_WARNING
41677 "vesafb: cannot reserve video memory at 0x%lx\n",
41678 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41679 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41680 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41681
41682 +#ifdef __i386__
41683 +
41684 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41685 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
41686 + if (!pmi_code)
41687 +#elif !defined(CONFIG_PAX_KERNEXEC)
41688 + if (0)
41689 +#endif
41690 +
41691 +#endif
41692 + screen_info.vesapm_seg = 0;
41693 +
41694 if (screen_info.vesapm_seg) {
41695 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41696 - screen_info.vesapm_seg,screen_info.vesapm_off);
41697 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41698 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41699 }
41700
41701 if (screen_info.vesapm_seg < 0xc000)
41702 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41703
41704 if (ypan || pmi_setpal) {
41705 unsigned short *pmi_base;
41706 +
41707 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41708 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41709 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41710 +
41711 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41712 + pax_open_kernel();
41713 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41714 +#else
41715 + pmi_code = pmi_base;
41716 +#endif
41717 +
41718 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41719 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41720 +
41721 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41722 + pmi_start = ktva_ktla(pmi_start);
41723 + pmi_pal = ktva_ktla(pmi_pal);
41724 + pax_close_kernel();
41725 +#endif
41726 +
41727 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41728 if (pmi_base[3]) {
41729 printk(KERN_INFO "vesafb: pmi: ports = ");
41730 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41731 info->node, info->fix.id);
41732 return 0;
41733 err:
41734 +
41735 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41736 + module_free_exec(NULL, pmi_code);
41737 +#endif
41738 +
41739 if (info->screen_base)
41740 iounmap(info->screen_base);
41741 framebuffer_release(info);
41742 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41743 index 88714ae..16c2e11 100644
41744 --- a/drivers/video/via/via_clock.h
41745 +++ b/drivers/video/via/via_clock.h
41746 @@ -56,7 +56,7 @@ struct via_clock {
41747
41748 void (*set_engine_pll_state)(u8 state);
41749 void (*set_engine_pll)(struct via_pll_config config);
41750 -};
41751 +} __no_const;
41752
41753
41754 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41755 diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
41756 index e058ace..2424d93 100644
41757 --- a/drivers/virtio/virtio_balloon.c
41758 +++ b/drivers/virtio/virtio_balloon.c
41759 @@ -174,6 +174,8 @@ static void update_balloon_stats(struct virtio_balloon *vb)
41760 struct sysinfo i;
41761 int idx = 0;
41762
41763 + pax_track_stack();
41764 +
41765 all_vm_events(events);
41766 si_meminfo(&i);
41767
41768 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41769 index e56c934..fc22f4b 100644
41770 --- a/drivers/xen/xen-pciback/conf_space.h
41771 +++ b/drivers/xen/xen-pciback/conf_space.h
41772 @@ -44,15 +44,15 @@ struct config_field {
41773 struct {
41774 conf_dword_write write;
41775 conf_dword_read read;
41776 - } dw;
41777 + } __no_const dw;
41778 struct {
41779 conf_word_write write;
41780 conf_word_read read;
41781 - } w;
41782 + } __no_const w;
41783 struct {
41784 conf_byte_write write;
41785 conf_byte_read read;
41786 - } b;
41787 + } __no_const b;
41788 } u;
41789 struct list_head list;
41790 };
41791 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41792 index e3c03db..93b0172 100644
41793 --- a/fs/9p/vfs_inode.c
41794 +++ b/fs/9p/vfs_inode.c
41795 @@ -1288,7 +1288,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41796 void
41797 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41798 {
41799 - char *s = nd_get_link(nd);
41800 + const char *s = nd_get_link(nd);
41801
41802 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
41803 IS_ERR(s) ? "<error>" : s);
41804 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41805 index 79e2ca7..5828ad1 100644
41806 --- a/fs/Kconfig.binfmt
41807 +++ b/fs/Kconfig.binfmt
41808 @@ -86,7 +86,7 @@ config HAVE_AOUT
41809
41810 config BINFMT_AOUT
41811 tristate "Kernel support for a.out and ECOFF binaries"
41812 - depends on HAVE_AOUT
41813 + depends on HAVE_AOUT && BROKEN
41814 ---help---
41815 A.out (Assembler.OUTput) is a set of formats for libraries and
41816 executables used in the earliest versions of UNIX. Linux used
41817 diff --git a/fs/aio.c b/fs/aio.c
41818 index e29ec48..f083e5e 100644
41819 --- a/fs/aio.c
41820 +++ b/fs/aio.c
41821 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41822 size += sizeof(struct io_event) * nr_events;
41823 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41824
41825 - if (nr_pages < 0)
41826 + if (nr_pages <= 0)
41827 return -EINVAL;
41828
41829 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41830 @@ -1088,6 +1088,8 @@ static int read_events(struct kioctx *ctx,
41831 struct aio_timeout to;
41832 int retry = 0;
41833
41834 + pax_track_stack();
41835 +
41836 /* needed to zero any padding within an entry (there shouldn't be
41837 * any, but C is fun!
41838 */
41839 @@ -1381,22 +1383,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41840 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41841 {
41842 ssize_t ret;
41843 + struct iovec iovstack;
41844
41845 #ifdef CONFIG_COMPAT
41846 if (compat)
41847 ret = compat_rw_copy_check_uvector(type,
41848 (struct compat_iovec __user *)kiocb->ki_buf,
41849 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41850 + kiocb->ki_nbytes, 1, &iovstack,
41851 &kiocb->ki_iovec);
41852 else
41853 #endif
41854 ret = rw_copy_check_uvector(type,
41855 (struct iovec __user *)kiocb->ki_buf,
41856 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41857 + kiocb->ki_nbytes, 1, &iovstack,
41858 &kiocb->ki_iovec);
41859 if (ret < 0)
41860 goto out;
41861
41862 + if (kiocb->ki_iovec == &iovstack) {
41863 + kiocb->ki_inline_vec = iovstack;
41864 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
41865 + }
41866 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41867 kiocb->ki_cur_seg = 0;
41868 /* ki_nbytes/left now reflect bytes instead of segs */
41869 diff --git a/fs/attr.c b/fs/attr.c
41870 index 538e279..046cc6d 100644
41871 --- a/fs/attr.c
41872 +++ b/fs/attr.c
41873 @@ -98,6 +98,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41874 unsigned long limit;
41875
41876 limit = rlimit(RLIMIT_FSIZE);
41877 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41878 if (limit != RLIM_INFINITY && offset > limit)
41879 goto out_sig;
41880 if (offset > inode->i_sb->s_maxbytes)
41881 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41882 index e1fbdee..cd5ea56 100644
41883 --- a/fs/autofs4/waitq.c
41884 +++ b/fs/autofs4/waitq.c
41885 @@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
41886 {
41887 unsigned long sigpipe, flags;
41888 mm_segment_t fs;
41889 - const char *data = (const char *)addr;
41890 + const char __user *data = (const char __force_user *)addr;
41891 ssize_t wr = 0;
41892
41893 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
41894 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41895 index 720d885..012e7f0 100644
41896 --- a/fs/befs/linuxvfs.c
41897 +++ b/fs/befs/linuxvfs.c
41898 @@ -503,7 +503,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41899 {
41900 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41901 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41902 - char *link = nd_get_link(nd);
41903 + const char *link = nd_get_link(nd);
41904 if (!IS_ERR(link))
41905 kfree(link);
41906 }
41907 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41908 index a6395bd..a5b24c4 100644
41909 --- a/fs/binfmt_aout.c
41910 +++ b/fs/binfmt_aout.c
41911 @@ -16,6 +16,7 @@
41912 #include <linux/string.h>
41913 #include <linux/fs.h>
41914 #include <linux/file.h>
41915 +#include <linux/security.h>
41916 #include <linux/stat.h>
41917 #include <linux/fcntl.h>
41918 #include <linux/ptrace.h>
41919 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
41920 #endif
41921 # define START_STACK(u) ((void __user *)u.start_stack)
41922
41923 + memset(&dump, 0, sizeof(dump));
41924 +
41925 fs = get_fs();
41926 set_fs(KERNEL_DS);
41927 has_dumped = 1;
41928 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
41929
41930 /* If the size of the dump file exceeds the rlimit, then see what would happen
41931 if we wrote the stack, but not the data area. */
41932 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
41933 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
41934 dump.u_dsize = 0;
41935
41936 /* Make sure we have enough room to write the stack and data areas. */
41937 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
41938 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
41939 dump.u_ssize = 0;
41940
41941 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41942 rlim = rlimit(RLIMIT_DATA);
41943 if (rlim >= RLIM_INFINITY)
41944 rlim = ~0;
41945 +
41946 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
41947 if (ex.a_data + ex.a_bss > rlim)
41948 return -ENOMEM;
41949
41950 @@ -262,6 +269,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41951 install_exec_creds(bprm);
41952 current->flags &= ~PF_FORKNOEXEC;
41953
41954 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41955 + current->mm->pax_flags = 0UL;
41956 +#endif
41957 +
41958 +#ifdef CONFIG_PAX_PAGEEXEC
41959 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
41960 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
41961 +
41962 +#ifdef CONFIG_PAX_EMUTRAMP
41963 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41964 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
41965 +#endif
41966 +
41967 +#ifdef CONFIG_PAX_MPROTECT
41968 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
41969 + current->mm->pax_flags |= MF_PAX_MPROTECT;
41970 +#endif
41971 +
41972 + }
41973 +#endif
41974 +
41975 if (N_MAGIC(ex) == OMAGIC) {
41976 unsigned long text_addr, map_size;
41977 loff_t pos;
41978 @@ -334,7 +362,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41979
41980 down_write(&current->mm->mmap_sem);
41981 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
41982 - PROT_READ | PROT_WRITE | PROT_EXEC,
41983 + PROT_READ | PROT_WRITE,
41984 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
41985 fd_offset + ex.a_text);
41986 up_write(&current->mm->mmap_sem);
41987 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
41988 index 21ac5ee..f54fdd0 100644
41989 --- a/fs/binfmt_elf.c
41990 +++ b/fs/binfmt_elf.c
41991 @@ -32,6 +32,7 @@
41992 #include <linux/elf.h>
41993 #include <linux/utsname.h>
41994 #include <linux/coredump.h>
41995 +#include <linux/xattr.h>
41996 #include <asm/uaccess.h>
41997 #include <asm/param.h>
41998 #include <asm/page.h>
41999 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42000 #define elf_core_dump NULL
42001 #endif
42002
42003 +#ifdef CONFIG_PAX_MPROTECT
42004 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42005 +#endif
42006 +
42007 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42008 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42009 #else
42010 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
42011 .load_binary = load_elf_binary,
42012 .load_shlib = load_elf_library,
42013 .core_dump = elf_core_dump,
42014 +
42015 +#ifdef CONFIG_PAX_MPROTECT
42016 + .handle_mprotect= elf_handle_mprotect,
42017 +#endif
42018 +
42019 .min_coredump = ELF_EXEC_PAGESIZE,
42020 };
42021
42022 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
42023
42024 static int set_brk(unsigned long start, unsigned long end)
42025 {
42026 + unsigned long e = end;
42027 +
42028 start = ELF_PAGEALIGN(start);
42029 end = ELF_PAGEALIGN(end);
42030 if (end > start) {
42031 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
42032 if (BAD_ADDR(addr))
42033 return addr;
42034 }
42035 - current->mm->start_brk = current->mm->brk = end;
42036 + current->mm->start_brk = current->mm->brk = e;
42037 return 0;
42038 }
42039
42040 @@ -148,12 +160,15 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42041 elf_addr_t __user *u_rand_bytes;
42042 const char *k_platform = ELF_PLATFORM;
42043 const char *k_base_platform = ELF_BASE_PLATFORM;
42044 - unsigned char k_rand_bytes[16];
42045 + u32 k_rand_bytes[4];
42046 int items;
42047 elf_addr_t *elf_info;
42048 int ei_index = 0;
42049 const struct cred *cred = current_cred();
42050 struct vm_area_struct *vma;
42051 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42052 +
42053 + pax_track_stack();
42054
42055 /*
42056 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42057 @@ -195,8 +210,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42058 * Generate 16 random bytes for userspace PRNG seeding.
42059 */
42060 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42061 - u_rand_bytes = (elf_addr_t __user *)
42062 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42063 + srandom32(k_rand_bytes[0] ^ random32());
42064 + srandom32(k_rand_bytes[1] ^ random32());
42065 + srandom32(k_rand_bytes[2] ^ random32());
42066 + srandom32(k_rand_bytes[3] ^ random32());
42067 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42068 + u_rand_bytes = (elf_addr_t __user *) p;
42069 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42070 return -EFAULT;
42071
42072 @@ -308,9 +327,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42073 return -EFAULT;
42074 current->mm->env_end = p;
42075
42076 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42077 +
42078 /* Put the elf_info on the stack in the right place. */
42079 sp = (elf_addr_t __user *)envp + 1;
42080 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42081 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42082 return -EFAULT;
42083 return 0;
42084 }
42085 @@ -381,10 +402,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42086 {
42087 struct elf_phdr *elf_phdata;
42088 struct elf_phdr *eppnt;
42089 - unsigned long load_addr = 0;
42090 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42091 int load_addr_set = 0;
42092 unsigned long last_bss = 0, elf_bss = 0;
42093 - unsigned long error = ~0UL;
42094 + unsigned long error = -EINVAL;
42095 unsigned long total_size;
42096 int retval, i, size;
42097
42098 @@ -430,6 +451,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42099 goto out_close;
42100 }
42101
42102 +#ifdef CONFIG_PAX_SEGMEXEC
42103 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42104 + pax_task_size = SEGMEXEC_TASK_SIZE;
42105 +#endif
42106 +
42107 eppnt = elf_phdata;
42108 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42109 if (eppnt->p_type == PT_LOAD) {
42110 @@ -473,8 +499,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42111 k = load_addr + eppnt->p_vaddr;
42112 if (BAD_ADDR(k) ||
42113 eppnt->p_filesz > eppnt->p_memsz ||
42114 - eppnt->p_memsz > TASK_SIZE ||
42115 - TASK_SIZE - eppnt->p_memsz < k) {
42116 + eppnt->p_memsz > pax_task_size ||
42117 + pax_task_size - eppnt->p_memsz < k) {
42118 error = -ENOMEM;
42119 goto out_close;
42120 }
42121 @@ -528,6 +554,348 @@ out:
42122 return error;
42123 }
42124
42125 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42126 +{
42127 + unsigned long pax_flags = 0UL;
42128 +
42129 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42130 +
42131 +#ifdef CONFIG_PAX_PAGEEXEC
42132 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42133 + pax_flags |= MF_PAX_PAGEEXEC;
42134 +#endif
42135 +
42136 +#ifdef CONFIG_PAX_SEGMEXEC
42137 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42138 + pax_flags |= MF_PAX_SEGMEXEC;
42139 +#endif
42140 +
42141 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42142 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42143 + if ((__supported_pte_mask & _PAGE_NX))
42144 + pax_flags &= ~MF_PAX_SEGMEXEC;
42145 + else
42146 + pax_flags &= ~MF_PAX_PAGEEXEC;
42147 + }
42148 +#endif
42149 +
42150 +#ifdef CONFIG_PAX_EMUTRAMP
42151 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42152 + pax_flags |= MF_PAX_EMUTRAMP;
42153 +#endif
42154 +
42155 +#ifdef CONFIG_PAX_MPROTECT
42156 + if (elf_phdata->p_flags & PF_MPROTECT)
42157 + pax_flags |= MF_PAX_MPROTECT;
42158 +#endif
42159 +
42160 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42161 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42162 + pax_flags |= MF_PAX_RANDMMAP;
42163 +#endif
42164 +
42165 +#endif
42166 +
42167 + return pax_flags;
42168 +}
42169 +
42170 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42171 +{
42172 + unsigned long pax_flags = 0UL;
42173 +
42174 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42175 +
42176 +#ifdef CONFIG_PAX_PAGEEXEC
42177 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42178 + pax_flags |= MF_PAX_PAGEEXEC;
42179 +#endif
42180 +
42181 +#ifdef CONFIG_PAX_SEGMEXEC
42182 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42183 + pax_flags |= MF_PAX_SEGMEXEC;
42184 +#endif
42185 +
42186 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42187 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42188 + if ((__supported_pte_mask & _PAGE_NX))
42189 + pax_flags &= ~MF_PAX_SEGMEXEC;
42190 + else
42191 + pax_flags &= ~MF_PAX_PAGEEXEC;
42192 + }
42193 +#endif
42194 +
42195 +#ifdef CONFIG_PAX_EMUTRAMP
42196 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42197 + pax_flags |= MF_PAX_EMUTRAMP;
42198 +#endif
42199 +
42200 +#ifdef CONFIG_PAX_MPROTECT
42201 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42202 + pax_flags |= MF_PAX_MPROTECT;
42203 +#endif
42204 +
42205 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42206 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42207 + pax_flags |= MF_PAX_RANDMMAP;
42208 +#endif
42209 +
42210 +#endif
42211 +
42212 + return pax_flags;
42213 +}
42214 +
42215 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42216 +{
42217 + unsigned long pax_flags = 0UL;
42218 +
42219 +#ifdef CONFIG_PAX_EI_PAX
42220 +
42221 +#ifdef CONFIG_PAX_PAGEEXEC
42222 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42223 + pax_flags |= MF_PAX_PAGEEXEC;
42224 +#endif
42225 +
42226 +#ifdef CONFIG_PAX_SEGMEXEC
42227 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42228 + pax_flags |= MF_PAX_SEGMEXEC;
42229 +#endif
42230 +
42231 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42232 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42233 + if ((__supported_pte_mask & _PAGE_NX))
42234 + pax_flags &= ~MF_PAX_SEGMEXEC;
42235 + else
42236 + pax_flags &= ~MF_PAX_PAGEEXEC;
42237 + }
42238 +#endif
42239 +
42240 +#ifdef CONFIG_PAX_EMUTRAMP
42241 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42242 + pax_flags |= MF_PAX_EMUTRAMP;
42243 +#endif
42244 +
42245 +#ifdef CONFIG_PAX_MPROTECT
42246 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42247 + pax_flags |= MF_PAX_MPROTECT;
42248 +#endif
42249 +
42250 +#ifdef CONFIG_PAX_ASLR
42251 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42252 + pax_flags |= MF_PAX_RANDMMAP;
42253 +#endif
42254 +
42255 +#else
42256 +
42257 +#ifdef CONFIG_PAX_PAGEEXEC
42258 + pax_flags |= MF_PAX_PAGEEXEC;
42259 +#endif
42260 +
42261 +#ifdef CONFIG_PAX_MPROTECT
42262 + pax_flags |= MF_PAX_MPROTECT;
42263 +#endif
42264 +
42265 +#ifdef CONFIG_PAX_RANDMMAP
42266 + pax_flags |= MF_PAX_RANDMMAP;
42267 +#endif
42268 +
42269 +#ifdef CONFIG_PAX_SEGMEXEC
42270 + if (!(__supported_pte_mask & _PAGE_NX)) {
42271 + pax_flags &= ~MF_PAX_PAGEEXEC;
42272 + pax_flags |= MF_PAX_SEGMEXEC;
42273 + }
42274 +#endif
42275 +
42276 +#endif
42277 +
42278 + return pax_flags;
42279 +}
42280 +
42281 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42282 +{
42283 +
42284 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42285 + unsigned long i;
42286 +
42287 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42288 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42289 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42290 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42291 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42292 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42293 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42294 + return ~0UL;
42295 +
42296 +#ifdef CONFIG_PAX_SOFTMODE
42297 + if (pax_softmode)
42298 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42299 + else
42300 +#endif
42301 +
42302 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42303 + break;
42304 + }
42305 +#endif
42306 +
42307 + return ~0UL;
42308 +}
42309 +
42310 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42311 +{
42312 + unsigned long pax_flags = 0UL;
42313 +
42314 +#ifdef CONFIG_PAX_PAGEEXEC
42315 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42316 + pax_flags |= MF_PAX_PAGEEXEC;
42317 +#endif
42318 +
42319 +#ifdef CONFIG_PAX_SEGMEXEC
42320 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42321 + pax_flags |= MF_PAX_SEGMEXEC;
42322 +#endif
42323 +
42324 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42325 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42326 + if ((__supported_pte_mask & _PAGE_NX))
42327 + pax_flags &= ~MF_PAX_SEGMEXEC;
42328 + else
42329 + pax_flags &= ~MF_PAX_PAGEEXEC;
42330 + }
42331 +#endif
42332 +
42333 +#ifdef CONFIG_PAX_EMUTRAMP
42334 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42335 + pax_flags |= MF_PAX_EMUTRAMP;
42336 +#endif
42337 +
42338 +#ifdef CONFIG_PAX_MPROTECT
42339 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42340 + pax_flags |= MF_PAX_MPROTECT;
42341 +#endif
42342 +
42343 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42344 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42345 + pax_flags |= MF_PAX_RANDMMAP;
42346 +#endif
42347 +
42348 + return pax_flags;
42349 +}
42350 +
42351 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42352 +{
42353 + unsigned long pax_flags = 0UL;
42354 +
42355 +#ifdef CONFIG_PAX_PAGEEXEC
42356 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42357 + pax_flags |= MF_PAX_PAGEEXEC;
42358 +#endif
42359 +
42360 +#ifdef CONFIG_PAX_SEGMEXEC
42361 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42362 + pax_flags |= MF_PAX_SEGMEXEC;
42363 +#endif
42364 +
42365 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42366 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42367 + if ((__supported_pte_mask & _PAGE_NX))
42368 + pax_flags &= ~MF_PAX_SEGMEXEC;
42369 + else
42370 + pax_flags &= ~MF_PAX_PAGEEXEC;
42371 + }
42372 +#endif
42373 +
42374 +#ifdef CONFIG_PAX_EMUTRAMP
42375 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42376 + pax_flags |= MF_PAX_EMUTRAMP;
42377 +#endif
42378 +
42379 +#ifdef CONFIG_PAX_MPROTECT
42380 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42381 + pax_flags |= MF_PAX_MPROTECT;
42382 +#endif
42383 +
42384 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42385 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42386 + pax_flags |= MF_PAX_RANDMMAP;
42387 +#endif
42388 +
42389 + return pax_flags;
42390 +}
42391 +
42392 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42393 +{
42394 +
42395 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42396 + ssize_t xattr_size, i;
42397 + unsigned char xattr_value[5];
42398 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42399 +
42400 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42401 + if (xattr_size <= 0)
42402 + return ~0UL;
42403 +
42404 + for (i = 0; i < xattr_size; i++)
42405 + switch (xattr_value[i]) {
42406 + default:
42407 + return ~0UL;
42408 +
42409 +#define parse_flag(option1, option2, flag) \
42410 + case option1: \
42411 + pax_flags_hardmode |= MF_PAX_##flag; \
42412 + break; \
42413 + case option2: \
42414 + pax_flags_softmode |= MF_PAX_##flag; \
42415 + break;
42416 +
42417 + parse_flag('p', 'P', PAGEEXEC);
42418 + parse_flag('e', 'E', EMUTRAMP);
42419 + parse_flag('m', 'M', MPROTECT);
42420 + parse_flag('r', 'R', RANDMMAP);
42421 + parse_flag('s', 'S', SEGMEXEC);
42422 +
42423 +#undef parse_flag
42424 + }
42425 +
42426 + if (pax_flags_hardmode & pax_flags_softmode)
42427 + return ~0UL;
42428 +
42429 +#ifdef CONFIG_PAX_SOFTMODE
42430 + if (pax_softmode)
42431 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42432 + else
42433 +#endif
42434 +
42435 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42436 +#else
42437 + return ~0UL;
42438 +#endif
42439 +}
42440 +
42441 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42442 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42443 +{
42444 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42445 +
42446 + pax_flags = pax_parse_ei_pax(elf_ex);
42447 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42448 + xattr_pax_flags = pax_parse_xattr_pax(file);
42449 +
42450 + if (pt_pax_flags == ~0UL)
42451 + pt_pax_flags = xattr_pax_flags;
42452 + else if (xattr_pax_flags == ~0UL)
42453 + xattr_pax_flags = pt_pax_flags;
42454 + if (pt_pax_flags != xattr_pax_flags)
42455 + return -EINVAL;
42456 + if (pt_pax_flags != ~0UL)
42457 + pax_flags = pt_pax_flags;
42458 +
42459 + if (0 > pax_check_flags(&pax_flags))
42460 + return -EINVAL;
42461 +
42462 + current->mm->pax_flags = pax_flags;
42463 + return 0;
42464 +}
42465 +#endif
42466 +
42467 /*
42468 * These are the functions used to load ELF style executables and shared
42469 * libraries. There is no binary dependent code anywhere else.
42470 @@ -544,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42471 {
42472 unsigned int random_variable = 0;
42473
42474 +#ifdef CONFIG_PAX_RANDUSTACK
42475 + if (randomize_va_space)
42476 + return stack_top - current->mm->delta_stack;
42477 +#endif
42478 +
42479 if ((current->flags & PF_RANDOMIZE) &&
42480 !(current->personality & ADDR_NO_RANDOMIZE)) {
42481 random_variable = get_random_int() & STACK_RND_MASK;
42482 @@ -562,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42483 unsigned long load_addr = 0, load_bias = 0;
42484 int load_addr_set = 0;
42485 char * elf_interpreter = NULL;
42486 - unsigned long error;
42487 + unsigned long error = 0;
42488 struct elf_phdr *elf_ppnt, *elf_phdata;
42489 unsigned long elf_bss, elf_brk;
42490 int retval, i;
42491 @@ -572,11 +945,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42492 unsigned long start_code, end_code, start_data, end_data;
42493 unsigned long reloc_func_desc __maybe_unused = 0;
42494 int executable_stack = EXSTACK_DEFAULT;
42495 - unsigned long def_flags = 0;
42496 struct {
42497 struct elfhdr elf_ex;
42498 struct elfhdr interp_elf_ex;
42499 } *loc;
42500 + unsigned long pax_task_size = TASK_SIZE;
42501
42502 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42503 if (!loc) {
42504 @@ -713,11 +1086,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42505
42506 /* OK, This is the point of no return */
42507 current->flags &= ~PF_FORKNOEXEC;
42508 - current->mm->def_flags = def_flags;
42509 +
42510 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42511 + current->mm->pax_flags = 0UL;
42512 +#endif
42513 +
42514 +#ifdef CONFIG_PAX_DLRESOLVE
42515 + current->mm->call_dl_resolve = 0UL;
42516 +#endif
42517 +
42518 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42519 + current->mm->call_syscall = 0UL;
42520 +#endif
42521 +
42522 +#ifdef CONFIG_PAX_ASLR
42523 + current->mm->delta_mmap = 0UL;
42524 + current->mm->delta_stack = 0UL;
42525 +#endif
42526 +
42527 + current->mm->def_flags = 0;
42528 +
42529 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42530 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42531 + send_sig(SIGKILL, current, 0);
42532 + goto out_free_dentry;
42533 + }
42534 +#endif
42535 +
42536 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42537 + pax_set_initial_flags(bprm);
42538 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42539 + if (pax_set_initial_flags_func)
42540 + (pax_set_initial_flags_func)(bprm);
42541 +#endif
42542 +
42543 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42544 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42545 + current->mm->context.user_cs_limit = PAGE_SIZE;
42546 + current->mm->def_flags |= VM_PAGEEXEC;
42547 + }
42548 +#endif
42549 +
42550 +#ifdef CONFIG_PAX_SEGMEXEC
42551 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42552 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42553 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42554 + pax_task_size = SEGMEXEC_TASK_SIZE;
42555 + current->mm->def_flags |= VM_NOHUGEPAGE;
42556 + }
42557 +#endif
42558 +
42559 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42560 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42561 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42562 + put_cpu();
42563 + }
42564 +#endif
42565
42566 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42567 may depend on the personality. */
42568 SET_PERSONALITY(loc->elf_ex);
42569 +
42570 +#ifdef CONFIG_PAX_ASLR
42571 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42572 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42573 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42574 + }
42575 +#endif
42576 +
42577 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42578 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42579 + executable_stack = EXSTACK_DISABLE_X;
42580 + current->personality &= ~READ_IMPLIES_EXEC;
42581 + } else
42582 +#endif
42583 +
42584 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42585 current->personality |= READ_IMPLIES_EXEC;
42586
42587 @@ -808,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42588 #else
42589 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42590 #endif
42591 +
42592 +#ifdef CONFIG_PAX_RANDMMAP
42593 + /* PaX: randomize base address at the default exe base if requested */
42594 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42595 +#ifdef CONFIG_SPARC64
42596 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42597 +#else
42598 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42599 +#endif
42600 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42601 + elf_flags |= MAP_FIXED;
42602 + }
42603 +#endif
42604 +
42605 }
42606
42607 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42608 @@ -840,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42609 * allowed task size. Note that p_filesz must always be
42610 * <= p_memsz so it is only necessary to check p_memsz.
42611 */
42612 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42613 - elf_ppnt->p_memsz > TASK_SIZE ||
42614 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42615 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42616 + elf_ppnt->p_memsz > pax_task_size ||
42617 + pax_task_size - elf_ppnt->p_memsz < k) {
42618 /* set_brk can never work. Avoid overflows. */
42619 send_sig(SIGKILL, current, 0);
42620 retval = -EINVAL;
42621 @@ -870,6 +1327,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42622 start_data += load_bias;
42623 end_data += load_bias;
42624
42625 +#ifdef CONFIG_PAX_RANDMMAP
42626 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
42627 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
42628 +#endif
42629 +
42630 /* Calling set_brk effectively mmaps the pages that we need
42631 * for the bss and break sections. We must do this before
42632 * mapping in the interpreter, to make sure it doesn't wind
42633 @@ -881,9 +1343,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42634 goto out_free_dentry;
42635 }
42636 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42637 - send_sig(SIGSEGV, current, 0);
42638 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42639 - goto out_free_dentry;
42640 + /*
42641 + * This bss-zeroing can fail if the ELF
42642 + * file specifies odd protections. So
42643 + * we don't check the return value
42644 + */
42645 }
42646
42647 if (elf_interpreter) {
42648 @@ -1098,7 +1562,7 @@ out:
42649 * Decide what to dump of a segment, part, all or none.
42650 */
42651 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42652 - unsigned long mm_flags)
42653 + unsigned long mm_flags, long signr)
42654 {
42655 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42656
42657 @@ -1132,7 +1596,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42658 if (vma->vm_file == NULL)
42659 return 0;
42660
42661 - if (FILTER(MAPPED_PRIVATE))
42662 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42663 goto whole;
42664
42665 /*
42666 @@ -1354,9 +1818,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42667 {
42668 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42669 int i = 0;
42670 - do
42671 + do {
42672 i += 2;
42673 - while (auxv[i - 2] != AT_NULL);
42674 + } while (auxv[i - 2] != AT_NULL);
42675 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42676 }
42677
42678 @@ -1862,14 +2326,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42679 }
42680
42681 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42682 - unsigned long mm_flags)
42683 + struct coredump_params *cprm)
42684 {
42685 struct vm_area_struct *vma;
42686 size_t size = 0;
42687
42688 for (vma = first_vma(current, gate_vma); vma != NULL;
42689 vma = next_vma(vma, gate_vma))
42690 - size += vma_dump_size(vma, mm_flags);
42691 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42692 return size;
42693 }
42694
42695 @@ -1963,7 +2427,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42696
42697 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42698
42699 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42700 + offset += elf_core_vma_data_size(gate_vma, cprm);
42701 offset += elf_core_extra_data_size();
42702 e_shoff = offset;
42703
42704 @@ -1977,10 +2441,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42705 offset = dataoff;
42706
42707 size += sizeof(*elf);
42708 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42709 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42710 goto end_coredump;
42711
42712 size += sizeof(*phdr4note);
42713 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42714 if (size > cprm->limit
42715 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42716 goto end_coredump;
42717 @@ -1994,7 +2460,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42718 phdr.p_offset = offset;
42719 phdr.p_vaddr = vma->vm_start;
42720 phdr.p_paddr = 0;
42721 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42722 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42723 phdr.p_memsz = vma->vm_end - vma->vm_start;
42724 offset += phdr.p_filesz;
42725 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42726 @@ -2005,6 +2471,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42727 phdr.p_align = ELF_EXEC_PAGESIZE;
42728
42729 size += sizeof(phdr);
42730 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42731 if (size > cprm->limit
42732 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42733 goto end_coredump;
42734 @@ -2029,7 +2496,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42735 unsigned long addr;
42736 unsigned long end;
42737
42738 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42739 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42740
42741 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42742 struct page *page;
42743 @@ -2038,6 +2505,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42744 page = get_dump_page(addr);
42745 if (page) {
42746 void *kaddr = kmap(page);
42747 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42748 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42749 !dump_write(cprm->file, kaddr,
42750 PAGE_SIZE);
42751 @@ -2055,6 +2523,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42752
42753 if (e_phnum == PN_XNUM) {
42754 size += sizeof(*shdr4extnum);
42755 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42756 if (size > cprm->limit
42757 || !dump_write(cprm->file, shdr4extnum,
42758 sizeof(*shdr4extnum)))
42759 @@ -2075,6 +2544,97 @@ out:
42760
42761 #endif /* CONFIG_ELF_CORE */
42762
42763 +#ifdef CONFIG_PAX_MPROTECT
42764 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
42765 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42766 + * we'll remove VM_MAYWRITE for good on RELRO segments.
42767 + *
42768 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42769 + * basis because we want to allow the common case and not the special ones.
42770 + */
42771 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42772 +{
42773 + struct elfhdr elf_h;
42774 + struct elf_phdr elf_p;
42775 + unsigned long i;
42776 + unsigned long oldflags;
42777 + bool is_textrel_rw, is_textrel_rx, is_relro;
42778 +
42779 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42780 + return;
42781 +
42782 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42783 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42784 +
42785 +#ifdef CONFIG_PAX_ELFRELOCS
42786 + /* possible TEXTREL */
42787 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42788 + 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);
42789 +#else
42790 + is_textrel_rw = false;
42791 + is_textrel_rx = false;
42792 +#endif
42793 +
42794 + /* possible RELRO */
42795 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42796 +
42797 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42798 + return;
42799 +
42800 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42801 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42802 +
42803 +#ifdef CONFIG_PAX_ETEXECRELOCS
42804 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42805 +#else
42806 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42807 +#endif
42808 +
42809 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42810 + !elf_check_arch(&elf_h) ||
42811 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42812 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42813 + return;
42814 +
42815 + for (i = 0UL; i < elf_h.e_phnum; i++) {
42816 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42817 + return;
42818 + switch (elf_p.p_type) {
42819 + case PT_DYNAMIC:
42820 + if (!is_textrel_rw && !is_textrel_rx)
42821 + continue;
42822 + i = 0UL;
42823 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42824 + elf_dyn dyn;
42825 +
42826 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42827 + return;
42828 + if (dyn.d_tag == DT_NULL)
42829 + return;
42830 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42831 + gr_log_textrel(vma);
42832 + if (is_textrel_rw)
42833 + vma->vm_flags |= VM_MAYWRITE;
42834 + else
42835 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42836 + vma->vm_flags &= ~VM_MAYWRITE;
42837 + return;
42838 + }
42839 + i++;
42840 + }
42841 + return;
42842 +
42843 + case PT_GNU_RELRO:
42844 + if (!is_relro)
42845 + continue;
42846 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42847 + vma->vm_flags &= ~VM_MAYWRITE;
42848 + return;
42849 + }
42850 + }
42851 +}
42852 +#endif
42853 +
42854 static int __init init_elf_binfmt(void)
42855 {
42856 return register_binfmt(&elf_format);
42857 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42858 index 1bffbe0..c8c283e 100644
42859 --- a/fs/binfmt_flat.c
42860 +++ b/fs/binfmt_flat.c
42861 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42862 realdatastart = (unsigned long) -ENOMEM;
42863 printk("Unable to allocate RAM for process data, errno %d\n",
42864 (int)-realdatastart);
42865 + down_write(&current->mm->mmap_sem);
42866 do_munmap(current->mm, textpos, text_len);
42867 + up_write(&current->mm->mmap_sem);
42868 ret = realdatastart;
42869 goto err;
42870 }
42871 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42872 }
42873 if (IS_ERR_VALUE(result)) {
42874 printk("Unable to read data+bss, errno %d\n", (int)-result);
42875 + down_write(&current->mm->mmap_sem);
42876 do_munmap(current->mm, textpos, text_len);
42877 do_munmap(current->mm, realdatastart, len);
42878 + up_write(&current->mm->mmap_sem);
42879 ret = result;
42880 goto err;
42881 }
42882 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42883 }
42884 if (IS_ERR_VALUE(result)) {
42885 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42886 + down_write(&current->mm->mmap_sem);
42887 do_munmap(current->mm, textpos, text_len + data_len + extra +
42888 MAX_SHARED_LIBS * sizeof(unsigned long));
42889 + up_write(&current->mm->mmap_sem);
42890 ret = result;
42891 goto err;
42892 }
42893 diff --git a/fs/bio.c b/fs/bio.c
42894 index 9bfade8..782f3b9 100644
42895 --- a/fs/bio.c
42896 +++ b/fs/bio.c
42897 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
42898 const int read = bio_data_dir(bio) == READ;
42899 struct bio_map_data *bmd = bio->bi_private;
42900 int i;
42901 - char *p = bmd->sgvecs[0].iov_base;
42902 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
42903
42904 __bio_for_each_segment(bvec, bio, i, 0) {
42905 char *addr = page_address(bvec->bv_page);
42906 diff --git a/fs/block_dev.c b/fs/block_dev.c
42907 index 1c44b8d..e2507b4 100644
42908 --- a/fs/block_dev.c
42909 +++ b/fs/block_dev.c
42910 @@ -681,7 +681,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
42911 else if (bdev->bd_contains == bdev)
42912 return true; /* is a whole device which isn't held */
42913
42914 - else if (whole->bd_holder == bd_may_claim)
42915 + else if (whole->bd_holder == (void *)bd_may_claim)
42916 return true; /* is a partition of a device that is being partitioned */
42917 else if (whole->bd_holder != NULL)
42918 return false; /* is a partition of a held device */
42919 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
42920 index 011cab3..9ace713 100644
42921 --- a/fs/btrfs/ctree.c
42922 +++ b/fs/btrfs/ctree.c
42923 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
42924 free_extent_buffer(buf);
42925 add_root_to_dirty_list(root);
42926 } else {
42927 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42928 - parent_start = parent->start;
42929 - else
42930 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
42931 + if (parent)
42932 + parent_start = parent->start;
42933 + else
42934 + parent_start = 0;
42935 + } else
42936 parent_start = 0;
42937
42938 WARN_ON(trans->transid != btrfs_header_generation(parent));
42939 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
42940 index b2d004a..6bb543d 100644
42941 --- a/fs/btrfs/inode.c
42942 +++ b/fs/btrfs/inode.c
42943 @@ -6922,7 +6922,7 @@ fail:
42944 return -ENOMEM;
42945 }
42946
42947 -static int btrfs_getattr(struct vfsmount *mnt,
42948 +int btrfs_getattr(struct vfsmount *mnt,
42949 struct dentry *dentry, struct kstat *stat)
42950 {
42951 struct inode *inode = dentry->d_inode;
42952 @@ -6934,6 +6934,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
42953 return 0;
42954 }
42955
42956 +EXPORT_SYMBOL(btrfs_getattr);
42957 +
42958 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
42959 +{
42960 + return BTRFS_I(inode)->root->anon_dev;
42961 +}
42962 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
42963 +
42964 /*
42965 * If a file is moved, it will inherit the cow and compression flags of the new
42966 * directory.
42967 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
42968 index dae5dfe..6aa01b1 100644
42969 --- a/fs/btrfs/ioctl.c
42970 +++ b/fs/btrfs/ioctl.c
42971 @@ -2704,9 +2704,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42972 for (i = 0; i < num_types; i++) {
42973 struct btrfs_space_info *tmp;
42974
42975 + /* Don't copy in more than we allocated */
42976 if (!slot_count)
42977 break;
42978
42979 + slot_count--;
42980 +
42981 info = NULL;
42982 rcu_read_lock();
42983 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
42984 @@ -2728,15 +2731,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42985 memcpy(dest, &space, sizeof(space));
42986 dest++;
42987 space_args.total_spaces++;
42988 - slot_count--;
42989 }
42990 - if (!slot_count)
42991 - break;
42992 }
42993 up_read(&info->groups_sem);
42994 }
42995
42996 - user_dest = (struct btrfs_ioctl_space_info *)
42997 + user_dest = (struct btrfs_ioctl_space_info __user *)
42998 (arg + sizeof(struct btrfs_ioctl_space_args));
42999
43000 if (copy_to_user(user_dest, dest_orig, alloc_size))
43001 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43002 index 59bb176..be9977d 100644
43003 --- a/fs/btrfs/relocation.c
43004 +++ b/fs/btrfs/relocation.c
43005 @@ -1242,7 +1242,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43006 }
43007 spin_unlock(&rc->reloc_root_tree.lock);
43008
43009 - BUG_ON((struct btrfs_root *)node->data != root);
43010 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43011
43012 if (!del) {
43013 spin_lock(&rc->reloc_root_tree.lock);
43014 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43015 index 622f469..e8d2d55 100644
43016 --- a/fs/cachefiles/bind.c
43017 +++ b/fs/cachefiles/bind.c
43018 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43019 args);
43020
43021 /* start by checking things over */
43022 - ASSERT(cache->fstop_percent >= 0 &&
43023 - cache->fstop_percent < cache->fcull_percent &&
43024 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43025 cache->fcull_percent < cache->frun_percent &&
43026 cache->frun_percent < 100);
43027
43028 - ASSERT(cache->bstop_percent >= 0 &&
43029 - cache->bstop_percent < cache->bcull_percent &&
43030 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43031 cache->bcull_percent < cache->brun_percent &&
43032 cache->brun_percent < 100);
43033
43034 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43035 index 0a1467b..6a53245 100644
43036 --- a/fs/cachefiles/daemon.c
43037 +++ b/fs/cachefiles/daemon.c
43038 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43039 if (n > buflen)
43040 return -EMSGSIZE;
43041
43042 - if (copy_to_user(_buffer, buffer, n) != 0)
43043 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43044 return -EFAULT;
43045
43046 return n;
43047 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43048 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43049 return -EIO;
43050
43051 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43052 + if (datalen > PAGE_SIZE - 1)
43053 return -EOPNOTSUPP;
43054
43055 /* drag the command string into the kernel so we can parse it */
43056 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43057 if (args[0] != '%' || args[1] != '\0')
43058 return -EINVAL;
43059
43060 - if (fstop < 0 || fstop >= cache->fcull_percent)
43061 + if (fstop >= cache->fcull_percent)
43062 return cachefiles_daemon_range_error(cache, args);
43063
43064 cache->fstop_percent = fstop;
43065 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43066 if (args[0] != '%' || args[1] != '\0')
43067 return -EINVAL;
43068
43069 - if (bstop < 0 || bstop >= cache->bcull_percent)
43070 + if (bstop >= cache->bcull_percent)
43071 return cachefiles_daemon_range_error(cache, args);
43072
43073 cache->bstop_percent = bstop;
43074 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43075 index bd6bc1b..b627b53 100644
43076 --- a/fs/cachefiles/internal.h
43077 +++ b/fs/cachefiles/internal.h
43078 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43079 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43080 struct rb_root active_nodes; /* active nodes (can't be culled) */
43081 rwlock_t active_lock; /* lock for active_nodes */
43082 - atomic_t gravecounter; /* graveyard uniquifier */
43083 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43084 unsigned frun_percent; /* when to stop culling (% files) */
43085 unsigned fcull_percent; /* when to start culling (% files) */
43086 unsigned fstop_percent; /* when to stop allocating (% files) */
43087 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43088 * proc.c
43089 */
43090 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43091 -extern atomic_t cachefiles_lookup_histogram[HZ];
43092 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43093 -extern atomic_t cachefiles_create_histogram[HZ];
43094 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43095 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43096 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43097
43098 extern int __init cachefiles_proc_init(void);
43099 extern void cachefiles_proc_cleanup(void);
43100 static inline
43101 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43102 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43103 {
43104 unsigned long jif = jiffies - start_jif;
43105 if (jif >= HZ)
43106 jif = HZ - 1;
43107 - atomic_inc(&histogram[jif]);
43108 + atomic_inc_unchecked(&histogram[jif]);
43109 }
43110
43111 #else
43112 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43113 index a0358c2..d6137f2 100644
43114 --- a/fs/cachefiles/namei.c
43115 +++ b/fs/cachefiles/namei.c
43116 @@ -318,7 +318,7 @@ try_again:
43117 /* first step is to make up a grave dentry in the graveyard */
43118 sprintf(nbuffer, "%08x%08x",
43119 (uint32_t) get_seconds(),
43120 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43121 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43122
43123 /* do the multiway lock magic */
43124 trap = lock_rename(cache->graveyard, dir);
43125 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43126 index eccd339..4c1d995 100644
43127 --- a/fs/cachefiles/proc.c
43128 +++ b/fs/cachefiles/proc.c
43129 @@ -14,9 +14,9 @@
43130 #include <linux/seq_file.h>
43131 #include "internal.h"
43132
43133 -atomic_t cachefiles_lookup_histogram[HZ];
43134 -atomic_t cachefiles_mkdir_histogram[HZ];
43135 -atomic_t cachefiles_create_histogram[HZ];
43136 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43137 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43138 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43139
43140 /*
43141 * display the latency histogram
43142 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43143 return 0;
43144 default:
43145 index = (unsigned long) v - 3;
43146 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43147 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43148 - z = atomic_read(&cachefiles_create_histogram[index]);
43149 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43150 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43151 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43152 if (x == 0 && y == 0 && z == 0)
43153 return 0;
43154
43155 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43156 index 0e3c092..818480e 100644
43157 --- a/fs/cachefiles/rdwr.c
43158 +++ b/fs/cachefiles/rdwr.c
43159 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43160 old_fs = get_fs();
43161 set_fs(KERNEL_DS);
43162 ret = file->f_op->write(
43163 - file, (const void __user *) data, len, &pos);
43164 + file, (const void __force_user *) data, len, &pos);
43165 set_fs(old_fs);
43166 kunmap(page);
43167 if (ret != len)
43168 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43169 index 382abc9..bd89646 100644
43170 --- a/fs/ceph/dir.c
43171 +++ b/fs/ceph/dir.c
43172 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43173 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43174 struct ceph_mds_client *mdsc = fsc->mdsc;
43175 unsigned frag = fpos_frag(filp->f_pos);
43176 - int off = fpos_off(filp->f_pos);
43177 + unsigned int off = fpos_off(filp->f_pos);
43178 int err;
43179 u32 ftype;
43180 struct ceph_mds_reply_info_parsed *rinfo;
43181 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43182 index 6d40656..bc1f825 100644
43183 --- a/fs/cifs/cifs_debug.c
43184 +++ b/fs/cifs/cifs_debug.c
43185 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43186
43187 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43188 #ifdef CONFIG_CIFS_STATS2
43189 - atomic_set(&totBufAllocCount, 0);
43190 - atomic_set(&totSmBufAllocCount, 0);
43191 + atomic_set_unchecked(&totBufAllocCount, 0);
43192 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43193 #endif /* CONFIG_CIFS_STATS2 */
43194 spin_lock(&cifs_tcp_ses_lock);
43195 list_for_each(tmp1, &cifs_tcp_ses_list) {
43196 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43197 tcon = list_entry(tmp3,
43198 struct cifs_tcon,
43199 tcon_list);
43200 - atomic_set(&tcon->num_smbs_sent, 0);
43201 - atomic_set(&tcon->num_writes, 0);
43202 - atomic_set(&tcon->num_reads, 0);
43203 - atomic_set(&tcon->num_oplock_brks, 0);
43204 - atomic_set(&tcon->num_opens, 0);
43205 - atomic_set(&tcon->num_posixopens, 0);
43206 - atomic_set(&tcon->num_posixmkdirs, 0);
43207 - atomic_set(&tcon->num_closes, 0);
43208 - atomic_set(&tcon->num_deletes, 0);
43209 - atomic_set(&tcon->num_mkdirs, 0);
43210 - atomic_set(&tcon->num_rmdirs, 0);
43211 - atomic_set(&tcon->num_renames, 0);
43212 - atomic_set(&tcon->num_t2renames, 0);
43213 - atomic_set(&tcon->num_ffirst, 0);
43214 - atomic_set(&tcon->num_fnext, 0);
43215 - atomic_set(&tcon->num_fclose, 0);
43216 - atomic_set(&tcon->num_hardlinks, 0);
43217 - atomic_set(&tcon->num_symlinks, 0);
43218 - atomic_set(&tcon->num_locks, 0);
43219 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43220 + atomic_set_unchecked(&tcon->num_writes, 0);
43221 + atomic_set_unchecked(&tcon->num_reads, 0);
43222 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43223 + atomic_set_unchecked(&tcon->num_opens, 0);
43224 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43225 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43226 + atomic_set_unchecked(&tcon->num_closes, 0);
43227 + atomic_set_unchecked(&tcon->num_deletes, 0);
43228 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43229 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43230 + atomic_set_unchecked(&tcon->num_renames, 0);
43231 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43232 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43233 + atomic_set_unchecked(&tcon->num_fnext, 0);
43234 + atomic_set_unchecked(&tcon->num_fclose, 0);
43235 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43236 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43237 + atomic_set_unchecked(&tcon->num_locks, 0);
43238 }
43239 }
43240 }
43241 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43242 smBufAllocCount.counter, cifs_min_small);
43243 #ifdef CONFIG_CIFS_STATS2
43244 seq_printf(m, "Total Large %d Small %d Allocations\n",
43245 - atomic_read(&totBufAllocCount),
43246 - atomic_read(&totSmBufAllocCount));
43247 + atomic_read_unchecked(&totBufAllocCount),
43248 + atomic_read_unchecked(&totSmBufAllocCount));
43249 #endif /* CONFIG_CIFS_STATS2 */
43250
43251 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43252 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43253 if (tcon->need_reconnect)
43254 seq_puts(m, "\tDISCONNECTED ");
43255 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43256 - atomic_read(&tcon->num_smbs_sent),
43257 - atomic_read(&tcon->num_oplock_brks));
43258 + atomic_read_unchecked(&tcon->num_smbs_sent),
43259 + atomic_read_unchecked(&tcon->num_oplock_brks));
43260 seq_printf(m, "\nReads: %d Bytes: %lld",
43261 - atomic_read(&tcon->num_reads),
43262 + atomic_read_unchecked(&tcon->num_reads),
43263 (long long)(tcon->bytes_read));
43264 seq_printf(m, "\nWrites: %d Bytes: %lld",
43265 - atomic_read(&tcon->num_writes),
43266 + atomic_read_unchecked(&tcon->num_writes),
43267 (long long)(tcon->bytes_written));
43268 seq_printf(m, "\nFlushes: %d",
43269 - atomic_read(&tcon->num_flushes));
43270 + atomic_read_unchecked(&tcon->num_flushes));
43271 seq_printf(m, "\nLocks: %d HardLinks: %d "
43272 "Symlinks: %d",
43273 - atomic_read(&tcon->num_locks),
43274 - atomic_read(&tcon->num_hardlinks),
43275 - atomic_read(&tcon->num_symlinks));
43276 + atomic_read_unchecked(&tcon->num_locks),
43277 + atomic_read_unchecked(&tcon->num_hardlinks),
43278 + atomic_read_unchecked(&tcon->num_symlinks));
43279 seq_printf(m, "\nOpens: %d Closes: %d "
43280 "Deletes: %d",
43281 - atomic_read(&tcon->num_opens),
43282 - atomic_read(&tcon->num_closes),
43283 - atomic_read(&tcon->num_deletes));
43284 + atomic_read_unchecked(&tcon->num_opens),
43285 + atomic_read_unchecked(&tcon->num_closes),
43286 + atomic_read_unchecked(&tcon->num_deletes));
43287 seq_printf(m, "\nPosix Opens: %d "
43288 "Posix Mkdirs: %d",
43289 - atomic_read(&tcon->num_posixopens),
43290 - atomic_read(&tcon->num_posixmkdirs));
43291 + atomic_read_unchecked(&tcon->num_posixopens),
43292 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43293 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43294 - atomic_read(&tcon->num_mkdirs),
43295 - atomic_read(&tcon->num_rmdirs));
43296 + atomic_read_unchecked(&tcon->num_mkdirs),
43297 + atomic_read_unchecked(&tcon->num_rmdirs));
43298 seq_printf(m, "\nRenames: %d T2 Renames %d",
43299 - atomic_read(&tcon->num_renames),
43300 - atomic_read(&tcon->num_t2renames));
43301 + atomic_read_unchecked(&tcon->num_renames),
43302 + atomic_read_unchecked(&tcon->num_t2renames));
43303 seq_printf(m, "\nFindFirst: %d FNext %d "
43304 "FClose %d",
43305 - atomic_read(&tcon->num_ffirst),
43306 - atomic_read(&tcon->num_fnext),
43307 - atomic_read(&tcon->num_fclose));
43308 + atomic_read_unchecked(&tcon->num_ffirst),
43309 + atomic_read_unchecked(&tcon->num_fnext),
43310 + atomic_read_unchecked(&tcon->num_fclose));
43311 }
43312 }
43313 }
43314 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43315 index 54b8f1e..f6a4c00 100644
43316 --- a/fs/cifs/cifsfs.c
43317 +++ b/fs/cifs/cifsfs.c
43318 @@ -981,7 +981,7 @@ cifs_init_request_bufs(void)
43319 cifs_req_cachep = kmem_cache_create("cifs_request",
43320 CIFSMaxBufSize +
43321 MAX_CIFS_HDR_SIZE, 0,
43322 - SLAB_HWCACHE_ALIGN, NULL);
43323 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43324 if (cifs_req_cachep == NULL)
43325 return -ENOMEM;
43326
43327 @@ -1008,7 +1008,7 @@ cifs_init_request_bufs(void)
43328 efficient to alloc 1 per page off the slab compared to 17K (5page)
43329 alloc of large cifs buffers even when page debugging is on */
43330 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43331 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43332 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43333 NULL);
43334 if (cifs_sm_req_cachep == NULL) {
43335 mempool_destroy(cifs_req_poolp);
43336 @@ -1093,8 +1093,8 @@ init_cifs(void)
43337 atomic_set(&bufAllocCount, 0);
43338 atomic_set(&smBufAllocCount, 0);
43339 #ifdef CONFIG_CIFS_STATS2
43340 - atomic_set(&totBufAllocCount, 0);
43341 - atomic_set(&totSmBufAllocCount, 0);
43342 + atomic_set_unchecked(&totBufAllocCount, 0);
43343 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43344 #endif /* CONFIG_CIFS_STATS2 */
43345
43346 atomic_set(&midCount, 0);
43347 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43348 index 95dad9d..fe7af1a 100644
43349 --- a/fs/cifs/cifsglob.h
43350 +++ b/fs/cifs/cifsglob.h
43351 @@ -381,28 +381,28 @@ struct cifs_tcon {
43352 __u16 Flags; /* optional support bits */
43353 enum statusEnum tidStatus;
43354 #ifdef CONFIG_CIFS_STATS
43355 - atomic_t num_smbs_sent;
43356 - atomic_t num_writes;
43357 - atomic_t num_reads;
43358 - atomic_t num_flushes;
43359 - atomic_t num_oplock_brks;
43360 - atomic_t num_opens;
43361 - atomic_t num_closes;
43362 - atomic_t num_deletes;
43363 - atomic_t num_mkdirs;
43364 - atomic_t num_posixopens;
43365 - atomic_t num_posixmkdirs;
43366 - atomic_t num_rmdirs;
43367 - atomic_t num_renames;
43368 - atomic_t num_t2renames;
43369 - atomic_t num_ffirst;
43370 - atomic_t num_fnext;
43371 - atomic_t num_fclose;
43372 - atomic_t num_hardlinks;
43373 - atomic_t num_symlinks;
43374 - atomic_t num_locks;
43375 - atomic_t num_acl_get;
43376 - atomic_t num_acl_set;
43377 + atomic_unchecked_t num_smbs_sent;
43378 + atomic_unchecked_t num_writes;
43379 + atomic_unchecked_t num_reads;
43380 + atomic_unchecked_t num_flushes;
43381 + atomic_unchecked_t num_oplock_brks;
43382 + atomic_unchecked_t num_opens;
43383 + atomic_unchecked_t num_closes;
43384 + atomic_unchecked_t num_deletes;
43385 + atomic_unchecked_t num_mkdirs;
43386 + atomic_unchecked_t num_posixopens;
43387 + atomic_unchecked_t num_posixmkdirs;
43388 + atomic_unchecked_t num_rmdirs;
43389 + atomic_unchecked_t num_renames;
43390 + atomic_unchecked_t num_t2renames;
43391 + atomic_unchecked_t num_ffirst;
43392 + atomic_unchecked_t num_fnext;
43393 + atomic_unchecked_t num_fclose;
43394 + atomic_unchecked_t num_hardlinks;
43395 + atomic_unchecked_t num_symlinks;
43396 + atomic_unchecked_t num_locks;
43397 + atomic_unchecked_t num_acl_get;
43398 + atomic_unchecked_t num_acl_set;
43399 #ifdef CONFIG_CIFS_STATS2
43400 unsigned long long time_writes;
43401 unsigned long long time_reads;
43402 @@ -613,7 +613,7 @@ convert_delimiter(char *path, char delim)
43403 }
43404
43405 #ifdef CONFIG_CIFS_STATS
43406 -#define cifs_stats_inc atomic_inc
43407 +#define cifs_stats_inc atomic_inc_unchecked
43408
43409 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43410 unsigned int bytes)
43411 @@ -953,8 +953,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43412 /* Various Debug counters */
43413 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43414 #ifdef CONFIG_CIFS_STATS2
43415 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43416 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43417 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43418 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43419 #endif
43420 GLOBAL_EXTERN atomic_t smBufAllocCount;
43421 GLOBAL_EXTERN atomic_t midCount;
43422 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43423 index db3f18c..1f5955e 100644
43424 --- a/fs/cifs/link.c
43425 +++ b/fs/cifs/link.c
43426 @@ -593,7 +593,7 @@ symlink_exit:
43427
43428 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43429 {
43430 - char *p = nd_get_link(nd);
43431 + const char *p = nd_get_link(nd);
43432 if (!IS_ERR(p))
43433 kfree(p);
43434 }
43435 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43436 index 7c16933..c8212b5 100644
43437 --- a/fs/cifs/misc.c
43438 +++ b/fs/cifs/misc.c
43439 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43440 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43441 atomic_inc(&bufAllocCount);
43442 #ifdef CONFIG_CIFS_STATS2
43443 - atomic_inc(&totBufAllocCount);
43444 + atomic_inc_unchecked(&totBufAllocCount);
43445 #endif /* CONFIG_CIFS_STATS2 */
43446 }
43447
43448 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43449 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43450 atomic_inc(&smBufAllocCount);
43451 #ifdef CONFIG_CIFS_STATS2
43452 - atomic_inc(&totSmBufAllocCount);
43453 + atomic_inc_unchecked(&totSmBufAllocCount);
43454 #endif /* CONFIG_CIFS_STATS2 */
43455
43456 }
43457 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43458 index 6901578..d402eb5 100644
43459 --- a/fs/coda/cache.c
43460 +++ b/fs/coda/cache.c
43461 @@ -24,7 +24,7 @@
43462 #include "coda_linux.h"
43463 #include "coda_cache.h"
43464
43465 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43466 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43467
43468 /* replace or extend an acl cache hit */
43469 void coda_cache_enter(struct inode *inode, int mask)
43470 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43471 struct coda_inode_info *cii = ITOC(inode);
43472
43473 spin_lock(&cii->c_lock);
43474 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43475 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43476 if (cii->c_uid != current_fsuid()) {
43477 cii->c_uid = current_fsuid();
43478 cii->c_cached_perm = mask;
43479 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43480 {
43481 struct coda_inode_info *cii = ITOC(inode);
43482 spin_lock(&cii->c_lock);
43483 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43484 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43485 spin_unlock(&cii->c_lock);
43486 }
43487
43488 /* remove all acl caches */
43489 void coda_cache_clear_all(struct super_block *sb)
43490 {
43491 - atomic_inc(&permission_epoch);
43492 + atomic_inc_unchecked(&permission_epoch);
43493 }
43494
43495
43496 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43497 spin_lock(&cii->c_lock);
43498 hit = (mask & cii->c_cached_perm) == mask &&
43499 cii->c_uid == current_fsuid() &&
43500 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43501 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43502 spin_unlock(&cii->c_lock);
43503
43504 return hit;
43505 diff --git a/fs/compat.c b/fs/compat.c
43506 index 58b1da4..afcd9b8 100644
43507 --- a/fs/compat.c
43508 +++ b/fs/compat.c
43509 @@ -133,8 +133,8 @@ asmlinkage long compat_sys_utimes(const char __user *filename, struct compat_tim
43510 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
43511 {
43512 compat_ino_t ino = stat->ino;
43513 - typeof(ubuf->st_uid) uid = 0;
43514 - typeof(ubuf->st_gid) gid = 0;
43515 + typeof(((struct compat_stat *)0)->st_uid) uid = 0;
43516 + typeof(((struct compat_stat *)0)->st_gid) gid = 0;
43517 int err;
43518
43519 SET_UID(uid, stat->uid);
43520 @@ -508,7 +508,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43521
43522 set_fs(KERNEL_DS);
43523 /* The __user pointer cast is valid because of the set_fs() */
43524 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43525 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43526 set_fs(oldfs);
43527 /* truncating is ok because it's a user address */
43528 if (!ret)
43529 @@ -566,7 +566,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43530 goto out;
43531
43532 ret = -EINVAL;
43533 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43534 + if (nr_segs > UIO_MAXIOV)
43535 goto out;
43536 if (nr_segs > fast_segs) {
43537 ret = -ENOMEM;
43538 @@ -848,6 +848,7 @@ struct compat_old_linux_dirent {
43539
43540 struct compat_readdir_callback {
43541 struct compat_old_linux_dirent __user *dirent;
43542 + struct file * file;
43543 int result;
43544 };
43545
43546 @@ -865,6 +866,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43547 buf->result = -EOVERFLOW;
43548 return -EOVERFLOW;
43549 }
43550 +
43551 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43552 + return 0;
43553 +
43554 buf->result++;
43555 dirent = buf->dirent;
43556 if (!access_ok(VERIFY_WRITE, dirent,
43557 @@ -897,6 +902,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43558
43559 buf.result = 0;
43560 buf.dirent = dirent;
43561 + buf.file = file;
43562
43563 error = vfs_readdir(file, compat_fillonedir, &buf);
43564 if (buf.result)
43565 @@ -917,6 +923,7 @@ struct compat_linux_dirent {
43566 struct compat_getdents_callback {
43567 struct compat_linux_dirent __user *current_dir;
43568 struct compat_linux_dirent __user *previous;
43569 + struct file * file;
43570 int count;
43571 int error;
43572 };
43573 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43574 buf->error = -EOVERFLOW;
43575 return -EOVERFLOW;
43576 }
43577 +
43578 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43579 + return 0;
43580 +
43581 dirent = buf->previous;
43582 if (dirent) {
43583 if (__put_user(offset, &dirent->d_off))
43584 @@ -985,6 +996,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43585 buf.previous = NULL;
43586 buf.count = count;
43587 buf.error = 0;
43588 + buf.file = file;
43589
43590 error = vfs_readdir(file, compat_filldir, &buf);
43591 if (error >= 0)
43592 @@ -1006,6 +1018,7 @@ out:
43593 struct compat_getdents_callback64 {
43594 struct linux_dirent64 __user *current_dir;
43595 struct linux_dirent64 __user *previous;
43596 + struct file * file;
43597 int count;
43598 int error;
43599 };
43600 @@ -1022,6 +1035,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43601 buf->error = -EINVAL; /* only used if we fail.. */
43602 if (reclen > buf->count)
43603 return -EINVAL;
43604 +
43605 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43606 + return 0;
43607 +
43608 dirent = buf->previous;
43609
43610 if (dirent) {
43611 @@ -1073,13 +1090,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43612 buf.previous = NULL;
43613 buf.count = count;
43614 buf.error = 0;
43615 + buf.file = file;
43616
43617 error = vfs_readdir(file, compat_filldir64, &buf);
43618 if (error >= 0)
43619 error = buf.error;
43620 lastdirent = buf.previous;
43621 if (lastdirent) {
43622 - typeof(lastdirent->d_off) d_off = file->f_pos;
43623 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43624 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43625 error = -EFAULT;
43626 else
43627 @@ -1446,6 +1464,8 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp,
43628 struct fdtable *fdt;
43629 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
43630
43631 + pax_track_stack();
43632 +
43633 if (n < 0)
43634 goto out_nofds;
43635
43636 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43637 index 112e45a..b59845b 100644
43638 --- a/fs/compat_binfmt_elf.c
43639 +++ b/fs/compat_binfmt_elf.c
43640 @@ -30,11 +30,13 @@
43641 #undef elf_phdr
43642 #undef elf_shdr
43643 #undef elf_note
43644 +#undef elf_dyn
43645 #undef elf_addr_t
43646 #define elfhdr elf32_hdr
43647 #define elf_phdr elf32_phdr
43648 #define elf_shdr elf32_shdr
43649 #define elf_note elf32_note
43650 +#define elf_dyn Elf32_Dyn
43651 #define elf_addr_t Elf32_Addr
43652
43653 /*
43654 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43655 index 51352de..93292ff 100644
43656 --- a/fs/compat_ioctl.c
43657 +++ b/fs/compat_ioctl.c
43658 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43659
43660 err = get_user(palp, &up->palette);
43661 err |= get_user(length, &up->length);
43662 + if (err)
43663 + return -EFAULT;
43664
43665 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43666 err = put_user(compat_ptr(palp), &up_native->palette);
43667 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43668 return -EFAULT;
43669 if (__get_user(udata, &ss32->iomem_base))
43670 return -EFAULT;
43671 - ss.iomem_base = compat_ptr(udata);
43672 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43673 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43674 __get_user(ss.port_high, &ss32->port_high))
43675 return -EFAULT;
43676 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
43677 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43678 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43679 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43680 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43681 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43682 return -EFAULT;
43683
43684 return ioctl_preallocate(file, p);
43685 @@ -1644,8 +1646,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43686 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43687 {
43688 unsigned int a, b;
43689 - a = *(unsigned int *)p;
43690 - b = *(unsigned int *)q;
43691 + a = *(const unsigned int *)p;
43692 + b = *(const unsigned int *)q;
43693 if (a > b)
43694 return 1;
43695 if (a < b)
43696 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43697 index 9a37a9b..35792b6 100644
43698 --- a/fs/configfs/dir.c
43699 +++ b/fs/configfs/dir.c
43700 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43701 }
43702 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43703 struct configfs_dirent *next;
43704 - const char * name;
43705 + const unsigned char * name;
43706 + char d_name[sizeof(next->s_dentry->d_iname)];
43707 int len;
43708 struct inode *inode = NULL;
43709
43710 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43711 continue;
43712
43713 name = configfs_get_name(next);
43714 - len = strlen(name);
43715 + if (next->s_dentry && name == next->s_dentry->d_iname) {
43716 + len = next->s_dentry->d_name.len;
43717 + memcpy(d_name, name, len);
43718 + name = d_name;
43719 + } else
43720 + len = strlen(name);
43721
43722 /*
43723 * We'll have a dentry and an inode for
43724 diff --git a/fs/dcache.c b/fs/dcache.c
43725 index 8b732a2..6db6c27 100644
43726 --- a/fs/dcache.c
43727 +++ b/fs/dcache.c
43728 @@ -3015,7 +3015,7 @@ void __init vfs_caches_init(unsigned long mempages)
43729 mempages -= reserve;
43730
43731 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43732 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43733 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43734
43735 dcache_init();
43736 inode_init();
43737 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43738 index 528da01..bd8c23d 100644
43739 --- a/fs/ecryptfs/inode.c
43740 +++ b/fs/ecryptfs/inode.c
43741 @@ -691,7 +691,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43742 old_fs = get_fs();
43743 set_fs(get_ds());
43744 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43745 - (char __user *)lower_buf,
43746 + (char __force_user *)lower_buf,
43747 lower_bufsiz);
43748 set_fs(old_fs);
43749 if (rc < 0)
43750 @@ -737,7 +737,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43751 }
43752 old_fs = get_fs();
43753 set_fs(get_ds());
43754 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43755 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43756 set_fs(old_fs);
43757 if (rc < 0) {
43758 kfree(buf);
43759 @@ -752,7 +752,7 @@ out:
43760 static void
43761 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43762 {
43763 - char *buf = nd_get_link(nd);
43764 + const char *buf = nd_get_link(nd);
43765 if (!IS_ERR(buf)) {
43766 /* Free the char* */
43767 kfree(buf);
43768 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43769 index 940a82e..63af89e 100644
43770 --- a/fs/ecryptfs/miscdev.c
43771 +++ b/fs/ecryptfs/miscdev.c
43772 @@ -328,7 +328,7 @@ check_list:
43773 goto out_unlock_msg_ctx;
43774 i = 5;
43775 if (msg_ctx->msg) {
43776 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
43777 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43778 goto out_unlock_msg_ctx;
43779 i += packet_length_size;
43780 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43781 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43782 index 3745f7c..89cc7a3 100644
43783 --- a/fs/ecryptfs/read_write.c
43784 +++ b/fs/ecryptfs/read_write.c
43785 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43786 return -EIO;
43787 fs_save = get_fs();
43788 set_fs(get_ds());
43789 - rc = vfs_write(lower_file, data, size, &offset);
43790 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43791 set_fs(fs_save);
43792 mark_inode_dirty_sync(ecryptfs_inode);
43793 return rc;
43794 @@ -235,7 +235,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43795 return -EIO;
43796 fs_save = get_fs();
43797 set_fs(get_ds());
43798 - rc = vfs_read(lower_file, data, size, &offset);
43799 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43800 set_fs(fs_save);
43801 return rc;
43802 }
43803 diff --git a/fs/exec.c b/fs/exec.c
43804 index 25dcbe5..09c172c 100644
43805 --- a/fs/exec.c
43806 +++ b/fs/exec.c
43807 @@ -55,12 +55,28 @@
43808 #include <linux/pipe_fs_i.h>
43809 #include <linux/oom.h>
43810 #include <linux/compat.h>
43811 +#include <linux/random.h>
43812 +#include <linux/seq_file.h>
43813 +
43814 +#ifdef CONFIG_PAX_REFCOUNT
43815 +#include <linux/kallsyms.h>
43816 +#include <linux/kdebug.h>
43817 +#endif
43818
43819 #include <asm/uaccess.h>
43820 #include <asm/mmu_context.h>
43821 #include <asm/tlb.h>
43822 #include "internal.h"
43823
43824 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
43825 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
43826 +#endif
43827 +
43828 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43829 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43830 +EXPORT_SYMBOL(pax_set_initial_flags_func);
43831 +#endif
43832 +
43833 int core_uses_pid;
43834 char core_pattern[CORENAME_MAX_SIZE] = "core";
43835 unsigned int core_pipe_limit;
43836 @@ -70,7 +86,7 @@ struct core_name {
43837 char *corename;
43838 int used, size;
43839 };
43840 -static atomic_t call_count = ATOMIC_INIT(1);
43841 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43842
43843 /* The maximal length of core_pattern is also specified in sysctl.c */
43844
43845 @@ -188,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43846 int write)
43847 {
43848 struct page *page;
43849 - int ret;
43850
43851 -#ifdef CONFIG_STACK_GROWSUP
43852 - if (write) {
43853 - ret = expand_downwards(bprm->vma, pos);
43854 - if (ret < 0)
43855 - return NULL;
43856 - }
43857 -#endif
43858 - ret = get_user_pages(current, bprm->mm, pos,
43859 - 1, write, 1, &page, NULL);
43860 - if (ret <= 0)
43861 + if (0 > expand_downwards(bprm->vma, pos))
43862 + return NULL;
43863 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
43864 return NULL;
43865
43866 if (write) {
43867 @@ -274,6 +282,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43868 vma->vm_end = STACK_TOP_MAX;
43869 vma->vm_start = vma->vm_end - PAGE_SIZE;
43870 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
43871 +
43872 +#ifdef CONFIG_PAX_SEGMEXEC
43873 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
43874 +#endif
43875 +
43876 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
43877 INIT_LIST_HEAD(&vma->anon_vma_chain);
43878
43879 @@ -288,6 +301,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43880 mm->stack_vm = mm->total_vm = 1;
43881 up_write(&mm->mmap_sem);
43882 bprm->p = vma->vm_end - sizeof(void *);
43883 +
43884 +#ifdef CONFIG_PAX_RANDUSTACK
43885 + if (randomize_va_space)
43886 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
43887 +#endif
43888 +
43889 return 0;
43890 err:
43891 up_write(&mm->mmap_sem);
43892 @@ -396,19 +415,7 @@ err:
43893 return err;
43894 }
43895
43896 -struct user_arg_ptr {
43897 -#ifdef CONFIG_COMPAT
43898 - bool is_compat;
43899 -#endif
43900 - union {
43901 - const char __user *const __user *native;
43902 -#ifdef CONFIG_COMPAT
43903 - compat_uptr_t __user *compat;
43904 -#endif
43905 - } ptr;
43906 -};
43907 -
43908 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43909 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43910 {
43911 const char __user *native;
43912
43913 @@ -417,14 +424,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43914 compat_uptr_t compat;
43915
43916 if (get_user(compat, argv.ptr.compat + nr))
43917 - return ERR_PTR(-EFAULT);
43918 + return (const char __force_user *)ERR_PTR(-EFAULT);
43919
43920 return compat_ptr(compat);
43921 }
43922 #endif
43923
43924 if (get_user(native, argv.ptr.native + nr))
43925 - return ERR_PTR(-EFAULT);
43926 + return (const char __force_user *)ERR_PTR(-EFAULT);
43927
43928 return native;
43929 }
43930 @@ -443,7 +450,7 @@ static int count(struct user_arg_ptr argv, int max)
43931 if (!p)
43932 break;
43933
43934 - if (IS_ERR(p))
43935 + if (IS_ERR((const char __force_kernel *)p))
43936 return -EFAULT;
43937
43938 if (i++ >= max)
43939 @@ -477,7 +484,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
43940
43941 ret = -EFAULT;
43942 str = get_user_arg_ptr(argv, argc);
43943 - if (IS_ERR(str))
43944 + if (IS_ERR((const char __force_kernel *)str))
43945 goto out;
43946
43947 len = strnlen_user(str, MAX_ARG_STRLEN);
43948 @@ -559,7 +566,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
43949 int r;
43950 mm_segment_t oldfs = get_fs();
43951 struct user_arg_ptr argv = {
43952 - .ptr.native = (const char __user *const __user *)__argv,
43953 + .ptr.native = (const char __force_user *const __force_user *)__argv,
43954 };
43955
43956 set_fs(KERNEL_DS);
43957 @@ -594,7 +601,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43958 unsigned long new_end = old_end - shift;
43959 struct mmu_gather tlb;
43960
43961 - BUG_ON(new_start > new_end);
43962 + if (new_start >= new_end || new_start < mmap_min_addr)
43963 + return -ENOMEM;
43964
43965 /*
43966 * ensure there are no vmas between where we want to go
43967 @@ -603,6 +611,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43968 if (vma != find_vma(mm, new_start))
43969 return -EFAULT;
43970
43971 +#ifdef CONFIG_PAX_SEGMEXEC
43972 + BUG_ON(pax_find_mirror_vma(vma));
43973 +#endif
43974 +
43975 /*
43976 * cover the whole range: [new_start, old_end)
43977 */
43978 @@ -683,10 +695,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43979 stack_top = arch_align_stack(stack_top);
43980 stack_top = PAGE_ALIGN(stack_top);
43981
43982 - if (unlikely(stack_top < mmap_min_addr) ||
43983 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
43984 - return -ENOMEM;
43985 -
43986 stack_shift = vma->vm_end - stack_top;
43987
43988 bprm->p -= stack_shift;
43989 @@ -698,8 +706,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
43990 bprm->exec -= stack_shift;
43991
43992 down_write(&mm->mmap_sem);
43993 +
43994 + /* Move stack pages down in memory. */
43995 + if (stack_shift) {
43996 + ret = shift_arg_pages(vma, stack_shift);
43997 + if (ret)
43998 + goto out_unlock;
43999 + }
44000 +
44001 vm_flags = VM_STACK_FLAGS;
44002
44003 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44004 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44005 + vm_flags &= ~VM_EXEC;
44006 +
44007 +#ifdef CONFIG_PAX_MPROTECT
44008 + if (mm->pax_flags & MF_PAX_MPROTECT)
44009 + vm_flags &= ~VM_MAYEXEC;
44010 +#endif
44011 +
44012 + }
44013 +#endif
44014 +
44015 /*
44016 * Adjust stack execute permissions; explicitly enable for
44017 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44018 @@ -718,13 +746,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44019 goto out_unlock;
44020 BUG_ON(prev != vma);
44021
44022 - /* Move stack pages down in memory. */
44023 - if (stack_shift) {
44024 - ret = shift_arg_pages(vma, stack_shift);
44025 - if (ret)
44026 - goto out_unlock;
44027 - }
44028 -
44029 /* mprotect_fixup is overkill to remove the temporary stack flags */
44030 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44031
44032 @@ -805,7 +826,7 @@ int kernel_read(struct file *file, loff_t offset,
44033 old_fs = get_fs();
44034 set_fs(get_ds());
44035 /* The cast to a user pointer is valid due to the set_fs() */
44036 - result = vfs_read(file, (void __user *)addr, count, &pos);
44037 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44038 set_fs(old_fs);
44039 return result;
44040 }
44041 @@ -1251,7 +1272,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
44042 }
44043 rcu_read_unlock();
44044
44045 - if (p->fs->users > n_fs) {
44046 + if (atomic_read(&p->fs->users) > n_fs) {
44047 bprm->unsafe |= LSM_UNSAFE_SHARE;
44048 } else {
44049 res = -EAGAIN;
44050 @@ -1454,6 +1475,11 @@ static int do_execve_common(const char *filename,
44051 struct user_arg_ptr envp,
44052 struct pt_regs *regs)
44053 {
44054 +#ifdef CONFIG_GRKERNSEC
44055 + struct file *old_exec_file;
44056 + struct acl_subject_label *old_acl;
44057 + struct rlimit old_rlim[RLIM_NLIMITS];
44058 +#endif
44059 struct linux_binprm *bprm;
44060 struct file *file;
44061 struct files_struct *displaced;
44062 @@ -1461,6 +1487,8 @@ static int do_execve_common(const char *filename,
44063 int retval;
44064 const struct cred *cred = current_cred();
44065
44066 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44067 +
44068 /*
44069 * We move the actual failure in case of RLIMIT_NPROC excess from
44070 * set*uid() to execve() because too many poorly written programs
44071 @@ -1507,6 +1535,16 @@ static int do_execve_common(const char *filename,
44072 bprm->filename = filename;
44073 bprm->interp = filename;
44074
44075 + if (gr_process_user_ban()) {
44076 + retval = -EPERM;
44077 + goto out_file;
44078 + }
44079 +
44080 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44081 + retval = -EACCES;
44082 + goto out_file;
44083 + }
44084 +
44085 retval = bprm_mm_init(bprm);
44086 if (retval)
44087 goto out_file;
44088 @@ -1536,9 +1574,40 @@ static int do_execve_common(const char *filename,
44089 if (retval < 0)
44090 goto out;
44091
44092 + if (!gr_tpe_allow(file)) {
44093 + retval = -EACCES;
44094 + goto out;
44095 + }
44096 +
44097 + if (gr_check_crash_exec(file)) {
44098 + retval = -EACCES;
44099 + goto out;
44100 + }
44101 +
44102 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44103 +
44104 + gr_handle_exec_args(bprm, argv);
44105 +
44106 +#ifdef CONFIG_GRKERNSEC
44107 + old_acl = current->acl;
44108 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44109 + old_exec_file = current->exec_file;
44110 + get_file(file);
44111 + current->exec_file = file;
44112 +#endif
44113 +
44114 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44115 + bprm->unsafe & LSM_UNSAFE_SHARE);
44116 + if (retval < 0)
44117 + goto out_fail;
44118 +
44119 retval = search_binary_handler(bprm,regs);
44120 if (retval < 0)
44121 - goto out;
44122 + goto out_fail;
44123 +#ifdef CONFIG_GRKERNSEC
44124 + if (old_exec_file)
44125 + fput(old_exec_file);
44126 +#endif
44127
44128 /* execve succeeded */
44129 current->fs->in_exec = 0;
44130 @@ -1549,6 +1618,14 @@ static int do_execve_common(const char *filename,
44131 put_files_struct(displaced);
44132 return retval;
44133
44134 +out_fail:
44135 +#ifdef CONFIG_GRKERNSEC
44136 + current->acl = old_acl;
44137 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44138 + fput(current->exec_file);
44139 + current->exec_file = old_exec_file;
44140 +#endif
44141 +
44142 out:
44143 if (bprm->mm) {
44144 acct_arg_size(bprm, 0);
44145 @@ -1622,7 +1699,7 @@ static int expand_corename(struct core_name *cn)
44146 {
44147 char *old_corename = cn->corename;
44148
44149 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44150 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44151 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44152
44153 if (!cn->corename) {
44154 @@ -1719,7 +1796,7 @@ static int format_corename(struct core_name *cn, long signr)
44155 int pid_in_pattern = 0;
44156 int err = 0;
44157
44158 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44159 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44160 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44161 cn->used = 0;
44162
44163 @@ -1816,6 +1893,218 @@ out:
44164 return ispipe;
44165 }
44166
44167 +int pax_check_flags(unsigned long *flags)
44168 +{
44169 + int retval = 0;
44170 +
44171 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44172 + if (*flags & MF_PAX_SEGMEXEC)
44173 + {
44174 + *flags &= ~MF_PAX_SEGMEXEC;
44175 + retval = -EINVAL;
44176 + }
44177 +#endif
44178 +
44179 + if ((*flags & MF_PAX_PAGEEXEC)
44180 +
44181 +#ifdef CONFIG_PAX_PAGEEXEC
44182 + && (*flags & MF_PAX_SEGMEXEC)
44183 +#endif
44184 +
44185 + )
44186 + {
44187 + *flags &= ~MF_PAX_PAGEEXEC;
44188 + retval = -EINVAL;
44189 + }
44190 +
44191 + if ((*flags & MF_PAX_MPROTECT)
44192 +
44193 +#ifdef CONFIG_PAX_MPROTECT
44194 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44195 +#endif
44196 +
44197 + )
44198 + {
44199 + *flags &= ~MF_PAX_MPROTECT;
44200 + retval = -EINVAL;
44201 + }
44202 +
44203 + if ((*flags & MF_PAX_EMUTRAMP)
44204 +
44205 +#ifdef CONFIG_PAX_EMUTRAMP
44206 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44207 +#endif
44208 +
44209 + )
44210 + {
44211 + *flags &= ~MF_PAX_EMUTRAMP;
44212 + retval = -EINVAL;
44213 + }
44214 +
44215 + return retval;
44216 +}
44217 +
44218 +EXPORT_SYMBOL(pax_check_flags);
44219 +
44220 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44221 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44222 +{
44223 + struct task_struct *tsk = current;
44224 + struct mm_struct *mm = current->mm;
44225 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44226 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44227 + char *path_exec = NULL;
44228 + char *path_fault = NULL;
44229 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44230 +
44231 + if (buffer_exec && buffer_fault) {
44232 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44233 +
44234 + down_read(&mm->mmap_sem);
44235 + vma = mm->mmap;
44236 + while (vma && (!vma_exec || !vma_fault)) {
44237 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44238 + vma_exec = vma;
44239 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44240 + vma_fault = vma;
44241 + vma = vma->vm_next;
44242 + }
44243 + if (vma_exec) {
44244 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44245 + if (IS_ERR(path_exec))
44246 + path_exec = "<path too long>";
44247 + else {
44248 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44249 + if (path_exec) {
44250 + *path_exec = 0;
44251 + path_exec = buffer_exec;
44252 + } else
44253 + path_exec = "<path too long>";
44254 + }
44255 + }
44256 + if (vma_fault) {
44257 + start = vma_fault->vm_start;
44258 + end = vma_fault->vm_end;
44259 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44260 + if (vma_fault->vm_file) {
44261 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44262 + if (IS_ERR(path_fault))
44263 + path_fault = "<path too long>";
44264 + else {
44265 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44266 + if (path_fault) {
44267 + *path_fault = 0;
44268 + path_fault = buffer_fault;
44269 + } else
44270 + path_fault = "<path too long>";
44271 + }
44272 + } else
44273 + path_fault = "<anonymous mapping>";
44274 + }
44275 + up_read(&mm->mmap_sem);
44276 + }
44277 + if (tsk->signal->curr_ip)
44278 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44279 + else
44280 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44281 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44282 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44283 + task_uid(tsk), task_euid(tsk), pc, sp);
44284 + free_page((unsigned long)buffer_exec);
44285 + free_page((unsigned long)buffer_fault);
44286 + pax_report_insns(regs, pc, sp);
44287 + do_coredump(SIGKILL, SIGKILL, regs);
44288 +}
44289 +#endif
44290 +
44291 +#ifdef CONFIG_PAX_REFCOUNT
44292 +void pax_report_refcount_overflow(struct pt_regs *regs)
44293 +{
44294 + if (current->signal->curr_ip)
44295 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44296 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44297 + else
44298 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44299 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44300 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44301 + show_regs(regs);
44302 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44303 +}
44304 +#endif
44305 +
44306 +#ifdef CONFIG_PAX_USERCOPY
44307 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44308 +int object_is_on_stack(const void *obj, unsigned long len)
44309 +{
44310 + const void * const stack = task_stack_page(current);
44311 + const void * const stackend = stack + THREAD_SIZE;
44312 +
44313 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44314 + const void *frame = NULL;
44315 + const void *oldframe;
44316 +#endif
44317 +
44318 + if (obj + len < obj)
44319 + return -1;
44320 +
44321 + if (obj + len <= stack || stackend <= obj)
44322 + return 0;
44323 +
44324 + if (obj < stack || stackend < obj + len)
44325 + return -1;
44326 +
44327 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44328 + oldframe = __builtin_frame_address(1);
44329 + if (oldframe)
44330 + frame = __builtin_frame_address(2);
44331 + /*
44332 + low ----------------------------------------------> high
44333 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44334 + ^----------------^
44335 + allow copies only within here
44336 + */
44337 + while (stack <= frame && frame < stackend) {
44338 + /* if obj + len extends past the last frame, this
44339 + check won't pass and the next frame will be 0,
44340 + causing us to bail out and correctly report
44341 + the copy as invalid
44342 + */
44343 + if (obj + len <= frame)
44344 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44345 + oldframe = frame;
44346 + frame = *(const void * const *)frame;
44347 + }
44348 + return -1;
44349 +#else
44350 + return 1;
44351 +#endif
44352 +}
44353 +
44354 +NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44355 +{
44356 + if (current->signal->curr_ip)
44357 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44358 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44359 + else
44360 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44361 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44362 + dump_stack();
44363 + gr_handle_kernel_exploit();
44364 + do_group_exit(SIGKILL);
44365 +}
44366 +#endif
44367 +
44368 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44369 +void pax_track_stack(void)
44370 +{
44371 + unsigned long sp = (unsigned long)&sp;
44372 + if (sp < current_thread_info()->lowest_stack &&
44373 + sp > (unsigned long)task_stack_page(current))
44374 + current_thread_info()->lowest_stack = sp;
44375 +}
44376 +EXPORT_SYMBOL(pax_track_stack);
44377 +#endif
44378 +
44379 static int zap_process(struct task_struct *start, int exit_code)
44380 {
44381 struct task_struct *t;
44382 @@ -2027,17 +2316,17 @@ static void wait_for_dump_helpers(struct file *file)
44383 pipe = file->f_path.dentry->d_inode->i_pipe;
44384
44385 pipe_lock(pipe);
44386 - pipe->readers++;
44387 - pipe->writers--;
44388 + atomic_inc(&pipe->readers);
44389 + atomic_dec(&pipe->writers);
44390
44391 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44392 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44393 wake_up_interruptible_sync(&pipe->wait);
44394 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44395 pipe_wait(pipe);
44396 }
44397
44398 - pipe->readers--;
44399 - pipe->writers++;
44400 + atomic_dec(&pipe->readers);
44401 + atomic_inc(&pipe->writers);
44402 pipe_unlock(pipe);
44403
44404 }
44405 @@ -2098,7 +2387,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44406 int retval = 0;
44407 int flag = 0;
44408 int ispipe;
44409 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44410 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44411 struct coredump_params cprm = {
44412 .signr = signr,
44413 .regs = regs,
44414 @@ -2113,6 +2402,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44415
44416 audit_core_dumps(signr);
44417
44418 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44419 + gr_handle_brute_attach(current, cprm.mm_flags);
44420 +
44421 binfmt = mm->binfmt;
44422 if (!binfmt || !binfmt->core_dump)
44423 goto fail;
44424 @@ -2180,7 +2472,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44425 }
44426 cprm.limit = RLIM_INFINITY;
44427
44428 - dump_count = atomic_inc_return(&core_dump_count);
44429 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44430 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44431 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44432 task_tgid_vnr(current), current->comm);
44433 @@ -2207,6 +2499,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44434 } else {
44435 struct inode *inode;
44436
44437 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44438 +
44439 if (cprm.limit < binfmt->min_coredump)
44440 goto fail_unlock;
44441
44442 @@ -2250,7 +2544,7 @@ close_fail:
44443 filp_close(cprm.file, NULL);
44444 fail_dropcount:
44445 if (ispipe)
44446 - atomic_dec(&core_dump_count);
44447 + atomic_dec_unchecked(&core_dump_count);
44448 fail_unlock:
44449 kfree(cn.corename);
44450 fail_corename:
44451 @@ -2269,7 +2563,7 @@ fail:
44452 */
44453 int dump_write(struct file *file, const void *addr, int nr)
44454 {
44455 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44456 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44457 }
44458 EXPORT_SYMBOL(dump_write);
44459
44460 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44461 index 8f44cef..cb07120 100644
44462 --- a/fs/ext2/balloc.c
44463 +++ b/fs/ext2/balloc.c
44464 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44465
44466 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44467 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44468 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44469 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44470 sbi->s_resuid != current_fsuid() &&
44471 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44472 return 0;
44473 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44474 index 6386d76..0a266b1 100644
44475 --- a/fs/ext3/balloc.c
44476 +++ b/fs/ext3/balloc.c
44477 @@ -1446,7 +1446,7 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
44478
44479 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44480 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44481 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44482 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44483 sbi->s_resuid != current_fsuid() &&
44484 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44485 return 0;
44486 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44487 index f8224ad..fbef97c 100644
44488 --- a/fs/ext4/balloc.c
44489 +++ b/fs/ext4/balloc.c
44490 @@ -394,8 +394,8 @@ static int ext4_has_free_blocks(struct ext4_sb_info *sbi,
44491 /* Hm, nope. Are (enough) root reserved blocks available? */
44492 if (sbi->s_resuid == current_fsuid() ||
44493 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44494 - capable(CAP_SYS_RESOURCE) ||
44495 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44496 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44497 + capable_nolog(CAP_SYS_RESOURCE)) {
44498
44499 if (free_blocks >= (nblocks + dirty_blocks))
44500 return 1;
44501 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44502 index 5c38120..2291d18 100644
44503 --- a/fs/ext4/ext4.h
44504 +++ b/fs/ext4/ext4.h
44505 @@ -1180,19 +1180,19 @@ struct ext4_sb_info {
44506 unsigned long s_mb_last_start;
44507
44508 /* stats for buddy allocator */
44509 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44510 - atomic_t s_bal_success; /* we found long enough chunks */
44511 - atomic_t s_bal_allocated; /* in blocks */
44512 - atomic_t s_bal_ex_scanned; /* total extents scanned */
44513 - atomic_t s_bal_goals; /* goal hits */
44514 - atomic_t s_bal_breaks; /* too long searches */
44515 - atomic_t s_bal_2orders; /* 2^order hits */
44516 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44517 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44518 + atomic_unchecked_t s_bal_allocated; /* in blocks */
44519 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44520 + atomic_unchecked_t s_bal_goals; /* goal hits */
44521 + atomic_unchecked_t s_bal_breaks; /* too long searches */
44522 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44523 spinlock_t s_bal_lock;
44524 unsigned long s_mb_buddies_generated;
44525 unsigned long long s_mb_generation_time;
44526 - atomic_t s_mb_lost_chunks;
44527 - atomic_t s_mb_preallocated;
44528 - atomic_t s_mb_discarded;
44529 + atomic_unchecked_t s_mb_lost_chunks;
44530 + atomic_unchecked_t s_mb_preallocated;
44531 + atomic_unchecked_t s_mb_discarded;
44532 atomic_t s_lock_busy;
44533
44534 /* locality groups */
44535 diff --git a/fs/ext4/file.c b/fs/ext4/file.c
44536 index e4095e9..1c006c5 100644
44537 --- a/fs/ext4/file.c
44538 +++ b/fs/ext4/file.c
44539 @@ -181,8 +181,8 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
44540 path.dentry = mnt->mnt_root;
44541 cp = d_path(&path, buf, sizeof(buf));
44542 if (!IS_ERR(cp)) {
44543 - memcpy(sbi->s_es->s_last_mounted, cp,
44544 - sizeof(sbi->s_es->s_last_mounted));
44545 + strlcpy(sbi->s_es->s_last_mounted, cp,
44546 + sizeof(sbi->s_es->s_last_mounted));
44547 ext4_mark_super_dirty(sb);
44548 }
44549 }
44550 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
44551 index f18bfe3..43759b1 100644
44552 --- a/fs/ext4/ioctl.c
44553 +++ b/fs/ext4/ioctl.c
44554 @@ -348,7 +348,7 @@ mext_out:
44555 if (!blk_queue_discard(q))
44556 return -EOPNOTSUPP;
44557
44558 - if (copy_from_user(&range, (struct fstrim_range *)arg,
44559 + if (copy_from_user(&range, (struct fstrim_range __user *)arg,
44560 sizeof(range)))
44561 return -EFAULT;
44562
44563 @@ -358,7 +358,7 @@ mext_out:
44564 if (ret < 0)
44565 return ret;
44566
44567 - if (copy_to_user((struct fstrim_range *)arg, &range,
44568 + if (copy_to_user((struct fstrim_range __user *)arg, &range,
44569 sizeof(range)))
44570 return -EFAULT;
44571
44572 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44573 index 17a5a57..b6be3c5 100644
44574 --- a/fs/ext4/mballoc.c
44575 +++ b/fs/ext4/mballoc.c
44576 @@ -1795,7 +1795,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44577 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44578
44579 if (EXT4_SB(sb)->s_mb_stats)
44580 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44581 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44582
44583 break;
44584 }
44585 @@ -2089,7 +2089,7 @@ repeat:
44586 ac->ac_status = AC_STATUS_CONTINUE;
44587 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44588 cr = 3;
44589 - atomic_inc(&sbi->s_mb_lost_chunks);
44590 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44591 goto repeat;
44592 }
44593 }
44594 @@ -2132,6 +2132,8 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
44595 ext4_grpblk_t counters[16];
44596 } sg;
44597
44598 + pax_track_stack();
44599 +
44600 group--;
44601 if (group == 0)
44602 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
44603 @@ -2573,25 +2575,25 @@ int ext4_mb_release(struct super_block *sb)
44604 if (sbi->s_mb_stats) {
44605 ext4_msg(sb, KERN_INFO,
44606 "mballoc: %u blocks %u reqs (%u success)",
44607 - atomic_read(&sbi->s_bal_allocated),
44608 - atomic_read(&sbi->s_bal_reqs),
44609 - atomic_read(&sbi->s_bal_success));
44610 + atomic_read_unchecked(&sbi->s_bal_allocated),
44611 + atomic_read_unchecked(&sbi->s_bal_reqs),
44612 + atomic_read_unchecked(&sbi->s_bal_success));
44613 ext4_msg(sb, KERN_INFO,
44614 "mballoc: %u extents scanned, %u goal hits, "
44615 "%u 2^N hits, %u breaks, %u lost",
44616 - atomic_read(&sbi->s_bal_ex_scanned),
44617 - atomic_read(&sbi->s_bal_goals),
44618 - atomic_read(&sbi->s_bal_2orders),
44619 - atomic_read(&sbi->s_bal_breaks),
44620 - atomic_read(&sbi->s_mb_lost_chunks));
44621 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44622 + atomic_read_unchecked(&sbi->s_bal_goals),
44623 + atomic_read_unchecked(&sbi->s_bal_2orders),
44624 + atomic_read_unchecked(&sbi->s_bal_breaks),
44625 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44626 ext4_msg(sb, KERN_INFO,
44627 "mballoc: %lu generated and it took %Lu",
44628 sbi->s_mb_buddies_generated,
44629 sbi->s_mb_generation_time);
44630 ext4_msg(sb, KERN_INFO,
44631 "mballoc: %u preallocated, %u discarded",
44632 - atomic_read(&sbi->s_mb_preallocated),
44633 - atomic_read(&sbi->s_mb_discarded));
44634 + atomic_read_unchecked(&sbi->s_mb_preallocated),
44635 + atomic_read_unchecked(&sbi->s_mb_discarded));
44636 }
44637
44638 free_percpu(sbi->s_locality_groups);
44639 @@ -3070,16 +3072,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44640 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44641
44642 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44643 - atomic_inc(&sbi->s_bal_reqs);
44644 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44645 + atomic_inc_unchecked(&sbi->s_bal_reqs);
44646 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44647 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44648 - atomic_inc(&sbi->s_bal_success);
44649 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44650 + atomic_inc_unchecked(&sbi->s_bal_success);
44651 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44652 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44653 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44654 - atomic_inc(&sbi->s_bal_goals);
44655 + atomic_inc_unchecked(&sbi->s_bal_goals);
44656 if (ac->ac_found > sbi->s_mb_max_to_scan)
44657 - atomic_inc(&sbi->s_bal_breaks);
44658 + atomic_inc_unchecked(&sbi->s_bal_breaks);
44659 }
44660
44661 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44662 @@ -3477,7 +3479,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44663 trace_ext4_mb_new_inode_pa(ac, pa);
44664
44665 ext4_mb_use_inode_pa(ac, pa);
44666 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44667 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44668
44669 ei = EXT4_I(ac->ac_inode);
44670 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44671 @@ -3537,7 +3539,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44672 trace_ext4_mb_new_group_pa(ac, pa);
44673
44674 ext4_mb_use_group_pa(ac, pa);
44675 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44676 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44677
44678 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44679 lg = ac->ac_lg;
44680 @@ -3625,7 +3627,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44681 * from the bitmap and continue.
44682 */
44683 }
44684 - atomic_add(free, &sbi->s_mb_discarded);
44685 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
44686
44687 return err;
44688 }
44689 @@ -3643,7 +3645,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44690 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44691 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44692 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44693 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44694 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44695 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44696
44697 return 0;
44698 diff --git a/fs/fcntl.c b/fs/fcntl.c
44699 index 22764c7..86372c9 100644
44700 --- a/fs/fcntl.c
44701 +++ b/fs/fcntl.c
44702 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44703 if (err)
44704 return err;
44705
44706 + if (gr_handle_chroot_fowner(pid, type))
44707 + return -ENOENT;
44708 + if (gr_check_protected_task_fowner(pid, type))
44709 + return -EACCES;
44710 +
44711 f_modown(filp, pid, type, force);
44712 return 0;
44713 }
44714 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44715
44716 static int f_setown_ex(struct file *filp, unsigned long arg)
44717 {
44718 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44719 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44720 struct f_owner_ex owner;
44721 struct pid *pid;
44722 int type;
44723 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44724
44725 static int f_getown_ex(struct file *filp, unsigned long arg)
44726 {
44727 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44728 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44729 struct f_owner_ex owner;
44730 int ret = 0;
44731
44732 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44733 switch (cmd) {
44734 case F_DUPFD:
44735 case F_DUPFD_CLOEXEC:
44736 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44737 if (arg >= rlimit(RLIMIT_NOFILE))
44738 break;
44739 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44740 diff --git a/fs/fifo.c b/fs/fifo.c
44741 index b1a524d..4ee270e 100644
44742 --- a/fs/fifo.c
44743 +++ b/fs/fifo.c
44744 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44745 */
44746 filp->f_op = &read_pipefifo_fops;
44747 pipe->r_counter++;
44748 - if (pipe->readers++ == 0)
44749 + if (atomic_inc_return(&pipe->readers) == 1)
44750 wake_up_partner(inode);
44751
44752 - if (!pipe->writers) {
44753 + if (!atomic_read(&pipe->writers)) {
44754 if ((filp->f_flags & O_NONBLOCK)) {
44755 /* suppress POLLHUP until we have
44756 * seen a writer */
44757 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44758 * errno=ENXIO when there is no process reading the FIFO.
44759 */
44760 ret = -ENXIO;
44761 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44762 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44763 goto err;
44764
44765 filp->f_op = &write_pipefifo_fops;
44766 pipe->w_counter++;
44767 - if (!pipe->writers++)
44768 + if (atomic_inc_return(&pipe->writers) == 1)
44769 wake_up_partner(inode);
44770
44771 - if (!pipe->readers) {
44772 + if (!atomic_read(&pipe->readers)) {
44773 wait_for_partner(inode, &pipe->r_counter);
44774 if (signal_pending(current))
44775 goto err_wr;
44776 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44777 */
44778 filp->f_op = &rdwr_pipefifo_fops;
44779
44780 - pipe->readers++;
44781 - pipe->writers++;
44782 + atomic_inc(&pipe->readers);
44783 + atomic_inc(&pipe->writers);
44784 pipe->r_counter++;
44785 pipe->w_counter++;
44786 - if (pipe->readers == 1 || pipe->writers == 1)
44787 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44788 wake_up_partner(inode);
44789 break;
44790
44791 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
44792 return 0;
44793
44794 err_rd:
44795 - if (!--pipe->readers)
44796 + if (atomic_dec_and_test(&pipe->readers))
44797 wake_up_interruptible(&pipe->wait);
44798 ret = -ERESTARTSYS;
44799 goto err;
44800
44801 err_wr:
44802 - if (!--pipe->writers)
44803 + if (atomic_dec_and_test(&pipe->writers))
44804 wake_up_interruptible(&pipe->wait);
44805 ret = -ERESTARTSYS;
44806 goto err;
44807
44808 err:
44809 - if (!pipe->readers && !pipe->writers)
44810 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
44811 free_pipe_info(inode);
44812
44813 err_nocleanup:
44814 diff --git a/fs/file.c b/fs/file.c
44815 index 4c6992d..104cdea 100644
44816 --- a/fs/file.c
44817 +++ b/fs/file.c
44818 @@ -15,6 +15,7 @@
44819 #include <linux/slab.h>
44820 #include <linux/vmalloc.h>
44821 #include <linux/file.h>
44822 +#include <linux/security.h>
44823 #include <linux/fdtable.h>
44824 #include <linux/bitops.h>
44825 #include <linux/interrupt.h>
44826 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
44827 * N.B. For clone tasks sharing a files structure, this test
44828 * will limit the total number of files that can be opened.
44829 */
44830 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
44831 if (nr >= rlimit(RLIMIT_NOFILE))
44832 return -EMFILE;
44833
44834 diff --git a/fs/filesystems.c b/fs/filesystems.c
44835 index 0845f84..7b4ebef 100644
44836 --- a/fs/filesystems.c
44837 +++ b/fs/filesystems.c
44838 @@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(const char *name)
44839 int len = dot ? dot - name : strlen(name);
44840
44841 fs = __get_fs_type(name, len);
44842 +
44843 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
44844 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
44845 +#else
44846 if (!fs && (request_module("%.*s", len, name) == 0))
44847 +#endif
44848 fs = __get_fs_type(name, len);
44849
44850 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
44851 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
44852 index 78b519c..212c0d0 100644
44853 --- a/fs/fs_struct.c
44854 +++ b/fs/fs_struct.c
44855 @@ -4,6 +4,7 @@
44856 #include <linux/path.h>
44857 #include <linux/slab.h>
44858 #include <linux/fs_struct.h>
44859 +#include <linux/grsecurity.h>
44860 #include "internal.h"
44861
44862 static inline void path_get_longterm(struct path *path)
44863 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
44864 old_root = fs->root;
44865 fs->root = *path;
44866 path_get_longterm(path);
44867 + gr_set_chroot_entries(current, path);
44868 write_seqcount_end(&fs->seq);
44869 spin_unlock(&fs->lock);
44870 if (old_root.dentry)
44871 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
44872 && fs->root.mnt == old_root->mnt) {
44873 path_get_longterm(new_root);
44874 fs->root = *new_root;
44875 + gr_set_chroot_entries(p, new_root);
44876 count++;
44877 }
44878 if (fs->pwd.dentry == old_root->dentry
44879 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
44880 spin_lock(&fs->lock);
44881 write_seqcount_begin(&fs->seq);
44882 tsk->fs = NULL;
44883 - kill = !--fs->users;
44884 + gr_clear_chroot_entries(tsk);
44885 + kill = !atomic_dec_return(&fs->users);
44886 write_seqcount_end(&fs->seq);
44887 spin_unlock(&fs->lock);
44888 task_unlock(tsk);
44889 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44890 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
44891 /* We don't need to lock fs - think why ;-) */
44892 if (fs) {
44893 - fs->users = 1;
44894 + atomic_set(&fs->users, 1);
44895 fs->in_exec = 0;
44896 spin_lock_init(&fs->lock);
44897 seqcount_init(&fs->seq);
44898 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44899 spin_lock(&old->lock);
44900 fs->root = old->root;
44901 path_get_longterm(&fs->root);
44902 + /* instead of calling gr_set_chroot_entries here,
44903 + we call it from every caller of this function
44904 + */
44905 fs->pwd = old->pwd;
44906 path_get_longterm(&fs->pwd);
44907 spin_unlock(&old->lock);
44908 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
44909
44910 task_lock(current);
44911 spin_lock(&fs->lock);
44912 - kill = !--fs->users;
44913 + kill = !atomic_dec_return(&fs->users);
44914 current->fs = new_fs;
44915 + gr_set_chroot_entries(current, &new_fs->root);
44916 spin_unlock(&fs->lock);
44917 task_unlock(current);
44918
44919 @@ -170,7 +178,7 @@ EXPORT_SYMBOL(current_umask);
44920
44921 /* to be mentioned only in INIT_TASK */
44922 struct fs_struct init_fs = {
44923 - .users = 1,
44924 + .users = ATOMIC_INIT(1),
44925 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
44926 .seq = SEQCNT_ZERO,
44927 .umask = 0022,
44928 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
44929 task_lock(current);
44930
44931 spin_lock(&init_fs.lock);
44932 - init_fs.users++;
44933 + atomic_inc(&init_fs.users);
44934 spin_unlock(&init_fs.lock);
44935
44936 spin_lock(&fs->lock);
44937 current->fs = &init_fs;
44938 - kill = !--fs->users;
44939 + gr_set_chroot_entries(current, &current->fs->root);
44940 + kill = !atomic_dec_return(&fs->users);
44941 spin_unlock(&fs->lock);
44942
44943 task_unlock(current);
44944 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
44945 index 9905350..02eaec4 100644
44946 --- a/fs/fscache/cookie.c
44947 +++ b/fs/fscache/cookie.c
44948 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
44949 parent ? (char *) parent->def->name : "<no-parent>",
44950 def->name, netfs_data);
44951
44952 - fscache_stat(&fscache_n_acquires);
44953 + fscache_stat_unchecked(&fscache_n_acquires);
44954
44955 /* if there's no parent cookie, then we don't create one here either */
44956 if (!parent) {
44957 - fscache_stat(&fscache_n_acquires_null);
44958 + fscache_stat_unchecked(&fscache_n_acquires_null);
44959 _leave(" [no parent]");
44960 return NULL;
44961 }
44962 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
44963 /* allocate and initialise a cookie */
44964 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
44965 if (!cookie) {
44966 - fscache_stat(&fscache_n_acquires_oom);
44967 + fscache_stat_unchecked(&fscache_n_acquires_oom);
44968 _leave(" [ENOMEM]");
44969 return NULL;
44970 }
44971 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44972
44973 switch (cookie->def->type) {
44974 case FSCACHE_COOKIE_TYPE_INDEX:
44975 - fscache_stat(&fscache_n_cookie_index);
44976 + fscache_stat_unchecked(&fscache_n_cookie_index);
44977 break;
44978 case FSCACHE_COOKIE_TYPE_DATAFILE:
44979 - fscache_stat(&fscache_n_cookie_data);
44980 + fscache_stat_unchecked(&fscache_n_cookie_data);
44981 break;
44982 default:
44983 - fscache_stat(&fscache_n_cookie_special);
44984 + fscache_stat_unchecked(&fscache_n_cookie_special);
44985 break;
44986 }
44987
44988 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44989 if (fscache_acquire_non_index_cookie(cookie) < 0) {
44990 atomic_dec(&parent->n_children);
44991 __fscache_cookie_put(cookie);
44992 - fscache_stat(&fscache_n_acquires_nobufs);
44993 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
44994 _leave(" = NULL");
44995 return NULL;
44996 }
44997 }
44998
44999 - fscache_stat(&fscache_n_acquires_ok);
45000 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45001 _leave(" = %p", cookie);
45002 return cookie;
45003 }
45004 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45005 cache = fscache_select_cache_for_object(cookie->parent);
45006 if (!cache) {
45007 up_read(&fscache_addremove_sem);
45008 - fscache_stat(&fscache_n_acquires_no_cache);
45009 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45010 _leave(" = -ENOMEDIUM [no cache]");
45011 return -ENOMEDIUM;
45012 }
45013 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45014 object = cache->ops->alloc_object(cache, cookie);
45015 fscache_stat_d(&fscache_n_cop_alloc_object);
45016 if (IS_ERR(object)) {
45017 - fscache_stat(&fscache_n_object_no_alloc);
45018 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45019 ret = PTR_ERR(object);
45020 goto error;
45021 }
45022
45023 - fscache_stat(&fscache_n_object_alloc);
45024 + fscache_stat_unchecked(&fscache_n_object_alloc);
45025
45026 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45027
45028 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45029 struct fscache_object *object;
45030 struct hlist_node *_p;
45031
45032 - fscache_stat(&fscache_n_updates);
45033 + fscache_stat_unchecked(&fscache_n_updates);
45034
45035 if (!cookie) {
45036 - fscache_stat(&fscache_n_updates_null);
45037 + fscache_stat_unchecked(&fscache_n_updates_null);
45038 _leave(" [no cookie]");
45039 return;
45040 }
45041 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45042 struct fscache_object *object;
45043 unsigned long event;
45044
45045 - fscache_stat(&fscache_n_relinquishes);
45046 + fscache_stat_unchecked(&fscache_n_relinquishes);
45047 if (retire)
45048 - fscache_stat(&fscache_n_relinquishes_retire);
45049 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45050
45051 if (!cookie) {
45052 - fscache_stat(&fscache_n_relinquishes_null);
45053 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45054 _leave(" [no cookie]");
45055 return;
45056 }
45057 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45058
45059 /* wait for the cookie to finish being instantiated (or to fail) */
45060 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45061 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45062 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45063 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45064 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45065 }
45066 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45067 index f6aad48..88dcf26 100644
45068 --- a/fs/fscache/internal.h
45069 +++ b/fs/fscache/internal.h
45070 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45071 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45072 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45073
45074 -extern atomic_t fscache_n_op_pend;
45075 -extern atomic_t fscache_n_op_run;
45076 -extern atomic_t fscache_n_op_enqueue;
45077 -extern atomic_t fscache_n_op_deferred_release;
45078 -extern atomic_t fscache_n_op_release;
45079 -extern atomic_t fscache_n_op_gc;
45080 -extern atomic_t fscache_n_op_cancelled;
45081 -extern atomic_t fscache_n_op_rejected;
45082 +extern atomic_unchecked_t fscache_n_op_pend;
45083 +extern atomic_unchecked_t fscache_n_op_run;
45084 +extern atomic_unchecked_t fscache_n_op_enqueue;
45085 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45086 +extern atomic_unchecked_t fscache_n_op_release;
45087 +extern atomic_unchecked_t fscache_n_op_gc;
45088 +extern atomic_unchecked_t fscache_n_op_cancelled;
45089 +extern atomic_unchecked_t fscache_n_op_rejected;
45090
45091 -extern atomic_t fscache_n_attr_changed;
45092 -extern atomic_t fscache_n_attr_changed_ok;
45093 -extern atomic_t fscache_n_attr_changed_nobufs;
45094 -extern atomic_t fscache_n_attr_changed_nomem;
45095 -extern atomic_t fscache_n_attr_changed_calls;
45096 +extern atomic_unchecked_t fscache_n_attr_changed;
45097 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45098 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45099 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45100 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45101
45102 -extern atomic_t fscache_n_allocs;
45103 -extern atomic_t fscache_n_allocs_ok;
45104 -extern atomic_t fscache_n_allocs_wait;
45105 -extern atomic_t fscache_n_allocs_nobufs;
45106 -extern atomic_t fscache_n_allocs_intr;
45107 -extern atomic_t fscache_n_allocs_object_dead;
45108 -extern atomic_t fscache_n_alloc_ops;
45109 -extern atomic_t fscache_n_alloc_op_waits;
45110 +extern atomic_unchecked_t fscache_n_allocs;
45111 +extern atomic_unchecked_t fscache_n_allocs_ok;
45112 +extern atomic_unchecked_t fscache_n_allocs_wait;
45113 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45114 +extern atomic_unchecked_t fscache_n_allocs_intr;
45115 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45116 +extern atomic_unchecked_t fscache_n_alloc_ops;
45117 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45118
45119 -extern atomic_t fscache_n_retrievals;
45120 -extern atomic_t fscache_n_retrievals_ok;
45121 -extern atomic_t fscache_n_retrievals_wait;
45122 -extern atomic_t fscache_n_retrievals_nodata;
45123 -extern atomic_t fscache_n_retrievals_nobufs;
45124 -extern atomic_t fscache_n_retrievals_intr;
45125 -extern atomic_t fscache_n_retrievals_nomem;
45126 -extern atomic_t fscache_n_retrievals_object_dead;
45127 -extern atomic_t fscache_n_retrieval_ops;
45128 -extern atomic_t fscache_n_retrieval_op_waits;
45129 +extern atomic_unchecked_t fscache_n_retrievals;
45130 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45131 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45132 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45133 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45134 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45135 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45136 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45137 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45138 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45139
45140 -extern atomic_t fscache_n_stores;
45141 -extern atomic_t fscache_n_stores_ok;
45142 -extern atomic_t fscache_n_stores_again;
45143 -extern atomic_t fscache_n_stores_nobufs;
45144 -extern atomic_t fscache_n_stores_oom;
45145 -extern atomic_t fscache_n_store_ops;
45146 -extern atomic_t fscache_n_store_calls;
45147 -extern atomic_t fscache_n_store_pages;
45148 -extern atomic_t fscache_n_store_radix_deletes;
45149 -extern atomic_t fscache_n_store_pages_over_limit;
45150 +extern atomic_unchecked_t fscache_n_stores;
45151 +extern atomic_unchecked_t fscache_n_stores_ok;
45152 +extern atomic_unchecked_t fscache_n_stores_again;
45153 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45154 +extern atomic_unchecked_t fscache_n_stores_oom;
45155 +extern atomic_unchecked_t fscache_n_store_ops;
45156 +extern atomic_unchecked_t fscache_n_store_calls;
45157 +extern atomic_unchecked_t fscache_n_store_pages;
45158 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45159 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45160
45161 -extern atomic_t fscache_n_store_vmscan_not_storing;
45162 -extern atomic_t fscache_n_store_vmscan_gone;
45163 -extern atomic_t fscache_n_store_vmscan_busy;
45164 -extern atomic_t fscache_n_store_vmscan_cancelled;
45165 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45166 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45167 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45168 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45169
45170 -extern atomic_t fscache_n_marks;
45171 -extern atomic_t fscache_n_uncaches;
45172 +extern atomic_unchecked_t fscache_n_marks;
45173 +extern atomic_unchecked_t fscache_n_uncaches;
45174
45175 -extern atomic_t fscache_n_acquires;
45176 -extern atomic_t fscache_n_acquires_null;
45177 -extern atomic_t fscache_n_acquires_no_cache;
45178 -extern atomic_t fscache_n_acquires_ok;
45179 -extern atomic_t fscache_n_acquires_nobufs;
45180 -extern atomic_t fscache_n_acquires_oom;
45181 +extern atomic_unchecked_t fscache_n_acquires;
45182 +extern atomic_unchecked_t fscache_n_acquires_null;
45183 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45184 +extern atomic_unchecked_t fscache_n_acquires_ok;
45185 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45186 +extern atomic_unchecked_t fscache_n_acquires_oom;
45187
45188 -extern atomic_t fscache_n_updates;
45189 -extern atomic_t fscache_n_updates_null;
45190 -extern atomic_t fscache_n_updates_run;
45191 +extern atomic_unchecked_t fscache_n_updates;
45192 +extern atomic_unchecked_t fscache_n_updates_null;
45193 +extern atomic_unchecked_t fscache_n_updates_run;
45194
45195 -extern atomic_t fscache_n_relinquishes;
45196 -extern atomic_t fscache_n_relinquishes_null;
45197 -extern atomic_t fscache_n_relinquishes_waitcrt;
45198 -extern atomic_t fscache_n_relinquishes_retire;
45199 +extern atomic_unchecked_t fscache_n_relinquishes;
45200 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45201 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45202 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45203
45204 -extern atomic_t fscache_n_cookie_index;
45205 -extern atomic_t fscache_n_cookie_data;
45206 -extern atomic_t fscache_n_cookie_special;
45207 +extern atomic_unchecked_t fscache_n_cookie_index;
45208 +extern atomic_unchecked_t fscache_n_cookie_data;
45209 +extern atomic_unchecked_t fscache_n_cookie_special;
45210
45211 -extern atomic_t fscache_n_object_alloc;
45212 -extern atomic_t fscache_n_object_no_alloc;
45213 -extern atomic_t fscache_n_object_lookups;
45214 -extern atomic_t fscache_n_object_lookups_negative;
45215 -extern atomic_t fscache_n_object_lookups_positive;
45216 -extern atomic_t fscache_n_object_lookups_timed_out;
45217 -extern atomic_t fscache_n_object_created;
45218 -extern atomic_t fscache_n_object_avail;
45219 -extern atomic_t fscache_n_object_dead;
45220 +extern atomic_unchecked_t fscache_n_object_alloc;
45221 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45222 +extern atomic_unchecked_t fscache_n_object_lookups;
45223 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45224 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45225 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45226 +extern atomic_unchecked_t fscache_n_object_created;
45227 +extern atomic_unchecked_t fscache_n_object_avail;
45228 +extern atomic_unchecked_t fscache_n_object_dead;
45229
45230 -extern atomic_t fscache_n_checkaux_none;
45231 -extern atomic_t fscache_n_checkaux_okay;
45232 -extern atomic_t fscache_n_checkaux_update;
45233 -extern atomic_t fscache_n_checkaux_obsolete;
45234 +extern atomic_unchecked_t fscache_n_checkaux_none;
45235 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45236 +extern atomic_unchecked_t fscache_n_checkaux_update;
45237 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45238
45239 extern atomic_t fscache_n_cop_alloc_object;
45240 extern atomic_t fscache_n_cop_lookup_object;
45241 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45242 atomic_inc(stat);
45243 }
45244
45245 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45246 +{
45247 + atomic_inc_unchecked(stat);
45248 +}
45249 +
45250 static inline void fscache_stat_d(atomic_t *stat)
45251 {
45252 atomic_dec(stat);
45253 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45254
45255 #define __fscache_stat(stat) (NULL)
45256 #define fscache_stat(stat) do {} while (0)
45257 +#define fscache_stat_unchecked(stat) do {} while (0)
45258 #define fscache_stat_d(stat) do {} while (0)
45259 #endif
45260
45261 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45262 index b6b897c..0ffff9c 100644
45263 --- a/fs/fscache/object.c
45264 +++ b/fs/fscache/object.c
45265 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45266 /* update the object metadata on disk */
45267 case FSCACHE_OBJECT_UPDATING:
45268 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45269 - fscache_stat(&fscache_n_updates_run);
45270 + fscache_stat_unchecked(&fscache_n_updates_run);
45271 fscache_stat(&fscache_n_cop_update_object);
45272 object->cache->ops->update_object(object);
45273 fscache_stat_d(&fscache_n_cop_update_object);
45274 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45275 spin_lock(&object->lock);
45276 object->state = FSCACHE_OBJECT_DEAD;
45277 spin_unlock(&object->lock);
45278 - fscache_stat(&fscache_n_object_dead);
45279 + fscache_stat_unchecked(&fscache_n_object_dead);
45280 goto terminal_transit;
45281
45282 /* handle the parent cache of this object being withdrawn from
45283 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45284 spin_lock(&object->lock);
45285 object->state = FSCACHE_OBJECT_DEAD;
45286 spin_unlock(&object->lock);
45287 - fscache_stat(&fscache_n_object_dead);
45288 + fscache_stat_unchecked(&fscache_n_object_dead);
45289 goto terminal_transit;
45290
45291 /* complain about the object being woken up once it is
45292 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45293 parent->cookie->def->name, cookie->def->name,
45294 object->cache->tag->name);
45295
45296 - fscache_stat(&fscache_n_object_lookups);
45297 + fscache_stat_unchecked(&fscache_n_object_lookups);
45298 fscache_stat(&fscache_n_cop_lookup_object);
45299 ret = object->cache->ops->lookup_object(object);
45300 fscache_stat_d(&fscache_n_cop_lookup_object);
45301 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45302 if (ret == -ETIMEDOUT) {
45303 /* probably stuck behind another object, so move this one to
45304 * the back of the queue */
45305 - fscache_stat(&fscache_n_object_lookups_timed_out);
45306 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45307 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45308 }
45309
45310 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45311
45312 spin_lock(&object->lock);
45313 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45314 - fscache_stat(&fscache_n_object_lookups_negative);
45315 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45316
45317 /* transit here to allow write requests to begin stacking up
45318 * and read requests to begin returning ENODATA */
45319 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45320 * result, in which case there may be data available */
45321 spin_lock(&object->lock);
45322 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45323 - fscache_stat(&fscache_n_object_lookups_positive);
45324 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45325
45326 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45327
45328 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45329 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45330 } else {
45331 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45332 - fscache_stat(&fscache_n_object_created);
45333 + fscache_stat_unchecked(&fscache_n_object_created);
45334
45335 object->state = FSCACHE_OBJECT_AVAILABLE;
45336 spin_unlock(&object->lock);
45337 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45338 fscache_enqueue_dependents(object);
45339
45340 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45341 - fscache_stat(&fscache_n_object_avail);
45342 + fscache_stat_unchecked(&fscache_n_object_avail);
45343
45344 _leave("");
45345 }
45346 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45347 enum fscache_checkaux result;
45348
45349 if (!object->cookie->def->check_aux) {
45350 - fscache_stat(&fscache_n_checkaux_none);
45351 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45352 return FSCACHE_CHECKAUX_OKAY;
45353 }
45354
45355 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45356 switch (result) {
45357 /* entry okay as is */
45358 case FSCACHE_CHECKAUX_OKAY:
45359 - fscache_stat(&fscache_n_checkaux_okay);
45360 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45361 break;
45362
45363 /* entry requires update */
45364 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45365 - fscache_stat(&fscache_n_checkaux_update);
45366 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45367 break;
45368
45369 /* entry requires deletion */
45370 case FSCACHE_CHECKAUX_OBSOLETE:
45371 - fscache_stat(&fscache_n_checkaux_obsolete);
45372 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45373 break;
45374
45375 default:
45376 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45377 index 30afdfa..2256596 100644
45378 --- a/fs/fscache/operation.c
45379 +++ b/fs/fscache/operation.c
45380 @@ -17,7 +17,7 @@
45381 #include <linux/slab.h>
45382 #include "internal.h"
45383
45384 -atomic_t fscache_op_debug_id;
45385 +atomic_unchecked_t fscache_op_debug_id;
45386 EXPORT_SYMBOL(fscache_op_debug_id);
45387
45388 /**
45389 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45390 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45391 ASSERTCMP(atomic_read(&op->usage), >, 0);
45392
45393 - fscache_stat(&fscache_n_op_enqueue);
45394 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45395 switch (op->flags & FSCACHE_OP_TYPE) {
45396 case FSCACHE_OP_ASYNC:
45397 _debug("queue async");
45398 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45399 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45400 if (op->processor)
45401 fscache_enqueue_operation(op);
45402 - fscache_stat(&fscache_n_op_run);
45403 + fscache_stat_unchecked(&fscache_n_op_run);
45404 }
45405
45406 /*
45407 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45408 if (object->n_ops > 1) {
45409 atomic_inc(&op->usage);
45410 list_add_tail(&op->pend_link, &object->pending_ops);
45411 - fscache_stat(&fscache_n_op_pend);
45412 + fscache_stat_unchecked(&fscache_n_op_pend);
45413 } else if (!list_empty(&object->pending_ops)) {
45414 atomic_inc(&op->usage);
45415 list_add_tail(&op->pend_link, &object->pending_ops);
45416 - fscache_stat(&fscache_n_op_pend);
45417 + fscache_stat_unchecked(&fscache_n_op_pend);
45418 fscache_start_operations(object);
45419 } else {
45420 ASSERTCMP(object->n_in_progress, ==, 0);
45421 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45422 object->n_exclusive++; /* reads and writes must wait */
45423 atomic_inc(&op->usage);
45424 list_add_tail(&op->pend_link, &object->pending_ops);
45425 - fscache_stat(&fscache_n_op_pend);
45426 + fscache_stat_unchecked(&fscache_n_op_pend);
45427 ret = 0;
45428 } else {
45429 /* not allowed to submit ops in any other state */
45430 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45431 if (object->n_exclusive > 0) {
45432 atomic_inc(&op->usage);
45433 list_add_tail(&op->pend_link, &object->pending_ops);
45434 - fscache_stat(&fscache_n_op_pend);
45435 + fscache_stat_unchecked(&fscache_n_op_pend);
45436 } else if (!list_empty(&object->pending_ops)) {
45437 atomic_inc(&op->usage);
45438 list_add_tail(&op->pend_link, &object->pending_ops);
45439 - fscache_stat(&fscache_n_op_pend);
45440 + fscache_stat_unchecked(&fscache_n_op_pend);
45441 fscache_start_operations(object);
45442 } else {
45443 ASSERTCMP(object->n_exclusive, ==, 0);
45444 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45445 object->n_ops++;
45446 atomic_inc(&op->usage);
45447 list_add_tail(&op->pend_link, &object->pending_ops);
45448 - fscache_stat(&fscache_n_op_pend);
45449 + fscache_stat_unchecked(&fscache_n_op_pend);
45450 ret = 0;
45451 } else if (object->state == FSCACHE_OBJECT_DYING ||
45452 object->state == FSCACHE_OBJECT_LC_DYING ||
45453 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45454 - fscache_stat(&fscache_n_op_rejected);
45455 + fscache_stat_unchecked(&fscache_n_op_rejected);
45456 ret = -ENOBUFS;
45457 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45458 fscache_report_unexpected_submission(object, op, ostate);
45459 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45460
45461 ret = -EBUSY;
45462 if (!list_empty(&op->pend_link)) {
45463 - fscache_stat(&fscache_n_op_cancelled);
45464 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45465 list_del_init(&op->pend_link);
45466 object->n_ops--;
45467 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45468 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45469 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45470 BUG();
45471
45472 - fscache_stat(&fscache_n_op_release);
45473 + fscache_stat_unchecked(&fscache_n_op_release);
45474
45475 if (op->release) {
45476 op->release(op);
45477 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45478 * lock, and defer it otherwise */
45479 if (!spin_trylock(&object->lock)) {
45480 _debug("defer put");
45481 - fscache_stat(&fscache_n_op_deferred_release);
45482 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
45483
45484 cache = object->cache;
45485 spin_lock(&cache->op_gc_list_lock);
45486 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45487
45488 _debug("GC DEFERRED REL OBJ%x OP%x",
45489 object->debug_id, op->debug_id);
45490 - fscache_stat(&fscache_n_op_gc);
45491 + fscache_stat_unchecked(&fscache_n_op_gc);
45492
45493 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45494
45495 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45496 index 3f7a59b..cf196cc 100644
45497 --- a/fs/fscache/page.c
45498 +++ b/fs/fscache/page.c
45499 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45500 val = radix_tree_lookup(&cookie->stores, page->index);
45501 if (!val) {
45502 rcu_read_unlock();
45503 - fscache_stat(&fscache_n_store_vmscan_not_storing);
45504 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45505 __fscache_uncache_page(cookie, page);
45506 return true;
45507 }
45508 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45509 spin_unlock(&cookie->stores_lock);
45510
45511 if (xpage) {
45512 - fscache_stat(&fscache_n_store_vmscan_cancelled);
45513 - fscache_stat(&fscache_n_store_radix_deletes);
45514 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45515 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45516 ASSERTCMP(xpage, ==, page);
45517 } else {
45518 - fscache_stat(&fscache_n_store_vmscan_gone);
45519 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45520 }
45521
45522 wake_up_bit(&cookie->flags, 0);
45523 @@ -107,7 +107,7 @@ page_busy:
45524 /* we might want to wait here, but that could deadlock the allocator as
45525 * the work threads writing to the cache may all end up sleeping
45526 * on memory allocation */
45527 - fscache_stat(&fscache_n_store_vmscan_busy);
45528 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45529 return false;
45530 }
45531 EXPORT_SYMBOL(__fscache_maybe_release_page);
45532 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45533 FSCACHE_COOKIE_STORING_TAG);
45534 if (!radix_tree_tag_get(&cookie->stores, page->index,
45535 FSCACHE_COOKIE_PENDING_TAG)) {
45536 - fscache_stat(&fscache_n_store_radix_deletes);
45537 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45538 xpage = radix_tree_delete(&cookie->stores, page->index);
45539 }
45540 spin_unlock(&cookie->stores_lock);
45541 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45542
45543 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45544
45545 - fscache_stat(&fscache_n_attr_changed_calls);
45546 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45547
45548 if (fscache_object_is_active(object)) {
45549 fscache_stat(&fscache_n_cop_attr_changed);
45550 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45551
45552 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45553
45554 - fscache_stat(&fscache_n_attr_changed);
45555 + fscache_stat_unchecked(&fscache_n_attr_changed);
45556
45557 op = kzalloc(sizeof(*op), GFP_KERNEL);
45558 if (!op) {
45559 - fscache_stat(&fscache_n_attr_changed_nomem);
45560 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45561 _leave(" = -ENOMEM");
45562 return -ENOMEM;
45563 }
45564 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45565 if (fscache_submit_exclusive_op(object, op) < 0)
45566 goto nobufs;
45567 spin_unlock(&cookie->lock);
45568 - fscache_stat(&fscache_n_attr_changed_ok);
45569 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45570 fscache_put_operation(op);
45571 _leave(" = 0");
45572 return 0;
45573 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45574 nobufs:
45575 spin_unlock(&cookie->lock);
45576 kfree(op);
45577 - fscache_stat(&fscache_n_attr_changed_nobufs);
45578 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45579 _leave(" = %d", -ENOBUFS);
45580 return -ENOBUFS;
45581 }
45582 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45583 /* allocate a retrieval operation and attempt to submit it */
45584 op = kzalloc(sizeof(*op), GFP_NOIO);
45585 if (!op) {
45586 - fscache_stat(&fscache_n_retrievals_nomem);
45587 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45588 return NULL;
45589 }
45590
45591 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45592 return 0;
45593 }
45594
45595 - fscache_stat(&fscache_n_retrievals_wait);
45596 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
45597
45598 jif = jiffies;
45599 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45600 fscache_wait_bit_interruptible,
45601 TASK_INTERRUPTIBLE) != 0) {
45602 - fscache_stat(&fscache_n_retrievals_intr);
45603 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45604 _leave(" = -ERESTARTSYS");
45605 return -ERESTARTSYS;
45606 }
45607 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45608 */
45609 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45610 struct fscache_retrieval *op,
45611 - atomic_t *stat_op_waits,
45612 - atomic_t *stat_object_dead)
45613 + atomic_unchecked_t *stat_op_waits,
45614 + atomic_unchecked_t *stat_object_dead)
45615 {
45616 int ret;
45617
45618 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45619 goto check_if_dead;
45620
45621 _debug(">>> WT");
45622 - fscache_stat(stat_op_waits);
45623 + fscache_stat_unchecked(stat_op_waits);
45624 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45625 fscache_wait_bit_interruptible,
45626 TASK_INTERRUPTIBLE) < 0) {
45627 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45628
45629 check_if_dead:
45630 if (unlikely(fscache_object_is_dead(object))) {
45631 - fscache_stat(stat_object_dead);
45632 + fscache_stat_unchecked(stat_object_dead);
45633 return -ENOBUFS;
45634 }
45635 return 0;
45636 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45637
45638 _enter("%p,%p,,,", cookie, page);
45639
45640 - fscache_stat(&fscache_n_retrievals);
45641 + fscache_stat_unchecked(&fscache_n_retrievals);
45642
45643 if (hlist_empty(&cookie->backing_objects))
45644 goto nobufs;
45645 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45646 goto nobufs_unlock;
45647 spin_unlock(&cookie->lock);
45648
45649 - fscache_stat(&fscache_n_retrieval_ops);
45650 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45651
45652 /* pin the netfs read context in case we need to do the actual netfs
45653 * read because we've encountered a cache read failure */
45654 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45655
45656 error:
45657 if (ret == -ENOMEM)
45658 - fscache_stat(&fscache_n_retrievals_nomem);
45659 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45660 else if (ret == -ERESTARTSYS)
45661 - fscache_stat(&fscache_n_retrievals_intr);
45662 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45663 else if (ret == -ENODATA)
45664 - fscache_stat(&fscache_n_retrievals_nodata);
45665 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45666 else if (ret < 0)
45667 - fscache_stat(&fscache_n_retrievals_nobufs);
45668 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45669 else
45670 - fscache_stat(&fscache_n_retrievals_ok);
45671 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45672
45673 fscache_put_retrieval(op);
45674 _leave(" = %d", ret);
45675 @@ -429,7 +429,7 @@ nobufs_unlock:
45676 spin_unlock(&cookie->lock);
45677 kfree(op);
45678 nobufs:
45679 - fscache_stat(&fscache_n_retrievals_nobufs);
45680 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45681 _leave(" = -ENOBUFS");
45682 return -ENOBUFS;
45683 }
45684 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45685
45686 _enter("%p,,%d,,,", cookie, *nr_pages);
45687
45688 - fscache_stat(&fscache_n_retrievals);
45689 + fscache_stat_unchecked(&fscache_n_retrievals);
45690
45691 if (hlist_empty(&cookie->backing_objects))
45692 goto nobufs;
45693 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45694 goto nobufs_unlock;
45695 spin_unlock(&cookie->lock);
45696
45697 - fscache_stat(&fscache_n_retrieval_ops);
45698 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45699
45700 /* pin the netfs read context in case we need to do the actual netfs
45701 * read because we've encountered a cache read failure */
45702 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45703
45704 error:
45705 if (ret == -ENOMEM)
45706 - fscache_stat(&fscache_n_retrievals_nomem);
45707 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45708 else if (ret == -ERESTARTSYS)
45709 - fscache_stat(&fscache_n_retrievals_intr);
45710 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45711 else if (ret == -ENODATA)
45712 - fscache_stat(&fscache_n_retrievals_nodata);
45713 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45714 else if (ret < 0)
45715 - fscache_stat(&fscache_n_retrievals_nobufs);
45716 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45717 else
45718 - fscache_stat(&fscache_n_retrievals_ok);
45719 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45720
45721 fscache_put_retrieval(op);
45722 _leave(" = %d", ret);
45723 @@ -545,7 +545,7 @@ nobufs_unlock:
45724 spin_unlock(&cookie->lock);
45725 kfree(op);
45726 nobufs:
45727 - fscache_stat(&fscache_n_retrievals_nobufs);
45728 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45729 _leave(" = -ENOBUFS");
45730 return -ENOBUFS;
45731 }
45732 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45733
45734 _enter("%p,%p,,,", cookie, page);
45735
45736 - fscache_stat(&fscache_n_allocs);
45737 + fscache_stat_unchecked(&fscache_n_allocs);
45738
45739 if (hlist_empty(&cookie->backing_objects))
45740 goto nobufs;
45741 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45742 goto nobufs_unlock;
45743 spin_unlock(&cookie->lock);
45744
45745 - fscache_stat(&fscache_n_alloc_ops);
45746 + fscache_stat_unchecked(&fscache_n_alloc_ops);
45747
45748 ret = fscache_wait_for_retrieval_activation(
45749 object, op,
45750 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45751
45752 error:
45753 if (ret == -ERESTARTSYS)
45754 - fscache_stat(&fscache_n_allocs_intr);
45755 + fscache_stat_unchecked(&fscache_n_allocs_intr);
45756 else if (ret < 0)
45757 - fscache_stat(&fscache_n_allocs_nobufs);
45758 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45759 else
45760 - fscache_stat(&fscache_n_allocs_ok);
45761 + fscache_stat_unchecked(&fscache_n_allocs_ok);
45762
45763 fscache_put_retrieval(op);
45764 _leave(" = %d", ret);
45765 @@ -625,7 +625,7 @@ nobufs_unlock:
45766 spin_unlock(&cookie->lock);
45767 kfree(op);
45768 nobufs:
45769 - fscache_stat(&fscache_n_allocs_nobufs);
45770 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45771 _leave(" = -ENOBUFS");
45772 return -ENOBUFS;
45773 }
45774 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45775
45776 spin_lock(&cookie->stores_lock);
45777
45778 - fscache_stat(&fscache_n_store_calls);
45779 + fscache_stat_unchecked(&fscache_n_store_calls);
45780
45781 /* find a page to store */
45782 page = NULL;
45783 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45784 page = results[0];
45785 _debug("gang %d [%lx]", n, page->index);
45786 if (page->index > op->store_limit) {
45787 - fscache_stat(&fscache_n_store_pages_over_limit);
45788 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45789 goto superseded;
45790 }
45791
45792 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45793 spin_unlock(&cookie->stores_lock);
45794 spin_unlock(&object->lock);
45795
45796 - fscache_stat(&fscache_n_store_pages);
45797 + fscache_stat_unchecked(&fscache_n_store_pages);
45798 fscache_stat(&fscache_n_cop_write_page);
45799 ret = object->cache->ops->write_page(op, page);
45800 fscache_stat_d(&fscache_n_cop_write_page);
45801 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45802 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45803 ASSERT(PageFsCache(page));
45804
45805 - fscache_stat(&fscache_n_stores);
45806 + fscache_stat_unchecked(&fscache_n_stores);
45807
45808 op = kzalloc(sizeof(*op), GFP_NOIO);
45809 if (!op)
45810 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45811 spin_unlock(&cookie->stores_lock);
45812 spin_unlock(&object->lock);
45813
45814 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
45815 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
45816 op->store_limit = object->store_limit;
45817
45818 if (fscache_submit_op(object, &op->op) < 0)
45819 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45820
45821 spin_unlock(&cookie->lock);
45822 radix_tree_preload_end();
45823 - fscache_stat(&fscache_n_store_ops);
45824 - fscache_stat(&fscache_n_stores_ok);
45825 + fscache_stat_unchecked(&fscache_n_store_ops);
45826 + fscache_stat_unchecked(&fscache_n_stores_ok);
45827
45828 /* the work queue now carries its own ref on the object */
45829 fscache_put_operation(&op->op);
45830 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45831 return 0;
45832
45833 already_queued:
45834 - fscache_stat(&fscache_n_stores_again);
45835 + fscache_stat_unchecked(&fscache_n_stores_again);
45836 already_pending:
45837 spin_unlock(&cookie->stores_lock);
45838 spin_unlock(&object->lock);
45839 spin_unlock(&cookie->lock);
45840 radix_tree_preload_end();
45841 kfree(op);
45842 - fscache_stat(&fscache_n_stores_ok);
45843 + fscache_stat_unchecked(&fscache_n_stores_ok);
45844 _leave(" = 0");
45845 return 0;
45846
45847 @@ -851,14 +851,14 @@ nobufs:
45848 spin_unlock(&cookie->lock);
45849 radix_tree_preload_end();
45850 kfree(op);
45851 - fscache_stat(&fscache_n_stores_nobufs);
45852 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
45853 _leave(" = -ENOBUFS");
45854 return -ENOBUFS;
45855
45856 nomem_free:
45857 kfree(op);
45858 nomem:
45859 - fscache_stat(&fscache_n_stores_oom);
45860 + fscache_stat_unchecked(&fscache_n_stores_oom);
45861 _leave(" = -ENOMEM");
45862 return -ENOMEM;
45863 }
45864 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
45865 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45866 ASSERTCMP(page, !=, NULL);
45867
45868 - fscache_stat(&fscache_n_uncaches);
45869 + fscache_stat_unchecked(&fscache_n_uncaches);
45870
45871 /* cache withdrawal may beat us to it */
45872 if (!PageFsCache(page))
45873 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
45874 unsigned long loop;
45875
45876 #ifdef CONFIG_FSCACHE_STATS
45877 - atomic_add(pagevec->nr, &fscache_n_marks);
45878 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
45879 #endif
45880
45881 for (loop = 0; loop < pagevec->nr; loop++) {
45882 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
45883 index 4765190..2a067f2 100644
45884 --- a/fs/fscache/stats.c
45885 +++ b/fs/fscache/stats.c
45886 @@ -18,95 +18,95 @@
45887 /*
45888 * operation counters
45889 */
45890 -atomic_t fscache_n_op_pend;
45891 -atomic_t fscache_n_op_run;
45892 -atomic_t fscache_n_op_enqueue;
45893 -atomic_t fscache_n_op_requeue;
45894 -atomic_t fscache_n_op_deferred_release;
45895 -atomic_t fscache_n_op_release;
45896 -atomic_t fscache_n_op_gc;
45897 -atomic_t fscache_n_op_cancelled;
45898 -atomic_t fscache_n_op_rejected;
45899 +atomic_unchecked_t fscache_n_op_pend;
45900 +atomic_unchecked_t fscache_n_op_run;
45901 +atomic_unchecked_t fscache_n_op_enqueue;
45902 +atomic_unchecked_t fscache_n_op_requeue;
45903 +atomic_unchecked_t fscache_n_op_deferred_release;
45904 +atomic_unchecked_t fscache_n_op_release;
45905 +atomic_unchecked_t fscache_n_op_gc;
45906 +atomic_unchecked_t fscache_n_op_cancelled;
45907 +atomic_unchecked_t fscache_n_op_rejected;
45908
45909 -atomic_t fscache_n_attr_changed;
45910 -atomic_t fscache_n_attr_changed_ok;
45911 -atomic_t fscache_n_attr_changed_nobufs;
45912 -atomic_t fscache_n_attr_changed_nomem;
45913 -atomic_t fscache_n_attr_changed_calls;
45914 +atomic_unchecked_t fscache_n_attr_changed;
45915 +atomic_unchecked_t fscache_n_attr_changed_ok;
45916 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
45917 +atomic_unchecked_t fscache_n_attr_changed_nomem;
45918 +atomic_unchecked_t fscache_n_attr_changed_calls;
45919
45920 -atomic_t fscache_n_allocs;
45921 -atomic_t fscache_n_allocs_ok;
45922 -atomic_t fscache_n_allocs_wait;
45923 -atomic_t fscache_n_allocs_nobufs;
45924 -atomic_t fscache_n_allocs_intr;
45925 -atomic_t fscache_n_allocs_object_dead;
45926 -atomic_t fscache_n_alloc_ops;
45927 -atomic_t fscache_n_alloc_op_waits;
45928 +atomic_unchecked_t fscache_n_allocs;
45929 +atomic_unchecked_t fscache_n_allocs_ok;
45930 +atomic_unchecked_t fscache_n_allocs_wait;
45931 +atomic_unchecked_t fscache_n_allocs_nobufs;
45932 +atomic_unchecked_t fscache_n_allocs_intr;
45933 +atomic_unchecked_t fscache_n_allocs_object_dead;
45934 +atomic_unchecked_t fscache_n_alloc_ops;
45935 +atomic_unchecked_t fscache_n_alloc_op_waits;
45936
45937 -atomic_t fscache_n_retrievals;
45938 -atomic_t fscache_n_retrievals_ok;
45939 -atomic_t fscache_n_retrievals_wait;
45940 -atomic_t fscache_n_retrievals_nodata;
45941 -atomic_t fscache_n_retrievals_nobufs;
45942 -atomic_t fscache_n_retrievals_intr;
45943 -atomic_t fscache_n_retrievals_nomem;
45944 -atomic_t fscache_n_retrievals_object_dead;
45945 -atomic_t fscache_n_retrieval_ops;
45946 -atomic_t fscache_n_retrieval_op_waits;
45947 +atomic_unchecked_t fscache_n_retrievals;
45948 +atomic_unchecked_t fscache_n_retrievals_ok;
45949 +atomic_unchecked_t fscache_n_retrievals_wait;
45950 +atomic_unchecked_t fscache_n_retrievals_nodata;
45951 +atomic_unchecked_t fscache_n_retrievals_nobufs;
45952 +atomic_unchecked_t fscache_n_retrievals_intr;
45953 +atomic_unchecked_t fscache_n_retrievals_nomem;
45954 +atomic_unchecked_t fscache_n_retrievals_object_dead;
45955 +atomic_unchecked_t fscache_n_retrieval_ops;
45956 +atomic_unchecked_t fscache_n_retrieval_op_waits;
45957
45958 -atomic_t fscache_n_stores;
45959 -atomic_t fscache_n_stores_ok;
45960 -atomic_t fscache_n_stores_again;
45961 -atomic_t fscache_n_stores_nobufs;
45962 -atomic_t fscache_n_stores_oom;
45963 -atomic_t fscache_n_store_ops;
45964 -atomic_t fscache_n_store_calls;
45965 -atomic_t fscache_n_store_pages;
45966 -atomic_t fscache_n_store_radix_deletes;
45967 -atomic_t fscache_n_store_pages_over_limit;
45968 +atomic_unchecked_t fscache_n_stores;
45969 +atomic_unchecked_t fscache_n_stores_ok;
45970 +atomic_unchecked_t fscache_n_stores_again;
45971 +atomic_unchecked_t fscache_n_stores_nobufs;
45972 +atomic_unchecked_t fscache_n_stores_oom;
45973 +atomic_unchecked_t fscache_n_store_ops;
45974 +atomic_unchecked_t fscache_n_store_calls;
45975 +atomic_unchecked_t fscache_n_store_pages;
45976 +atomic_unchecked_t fscache_n_store_radix_deletes;
45977 +atomic_unchecked_t fscache_n_store_pages_over_limit;
45978
45979 -atomic_t fscache_n_store_vmscan_not_storing;
45980 -atomic_t fscache_n_store_vmscan_gone;
45981 -atomic_t fscache_n_store_vmscan_busy;
45982 -atomic_t fscache_n_store_vmscan_cancelled;
45983 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45984 +atomic_unchecked_t fscache_n_store_vmscan_gone;
45985 +atomic_unchecked_t fscache_n_store_vmscan_busy;
45986 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45987
45988 -atomic_t fscache_n_marks;
45989 -atomic_t fscache_n_uncaches;
45990 +atomic_unchecked_t fscache_n_marks;
45991 +atomic_unchecked_t fscache_n_uncaches;
45992
45993 -atomic_t fscache_n_acquires;
45994 -atomic_t fscache_n_acquires_null;
45995 -atomic_t fscache_n_acquires_no_cache;
45996 -atomic_t fscache_n_acquires_ok;
45997 -atomic_t fscache_n_acquires_nobufs;
45998 -atomic_t fscache_n_acquires_oom;
45999 +atomic_unchecked_t fscache_n_acquires;
46000 +atomic_unchecked_t fscache_n_acquires_null;
46001 +atomic_unchecked_t fscache_n_acquires_no_cache;
46002 +atomic_unchecked_t fscache_n_acquires_ok;
46003 +atomic_unchecked_t fscache_n_acquires_nobufs;
46004 +atomic_unchecked_t fscache_n_acquires_oom;
46005
46006 -atomic_t fscache_n_updates;
46007 -atomic_t fscache_n_updates_null;
46008 -atomic_t fscache_n_updates_run;
46009 +atomic_unchecked_t fscache_n_updates;
46010 +atomic_unchecked_t fscache_n_updates_null;
46011 +atomic_unchecked_t fscache_n_updates_run;
46012
46013 -atomic_t fscache_n_relinquishes;
46014 -atomic_t fscache_n_relinquishes_null;
46015 -atomic_t fscache_n_relinquishes_waitcrt;
46016 -atomic_t fscache_n_relinquishes_retire;
46017 +atomic_unchecked_t fscache_n_relinquishes;
46018 +atomic_unchecked_t fscache_n_relinquishes_null;
46019 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46020 +atomic_unchecked_t fscache_n_relinquishes_retire;
46021
46022 -atomic_t fscache_n_cookie_index;
46023 -atomic_t fscache_n_cookie_data;
46024 -atomic_t fscache_n_cookie_special;
46025 +atomic_unchecked_t fscache_n_cookie_index;
46026 +atomic_unchecked_t fscache_n_cookie_data;
46027 +atomic_unchecked_t fscache_n_cookie_special;
46028
46029 -atomic_t fscache_n_object_alloc;
46030 -atomic_t fscache_n_object_no_alloc;
46031 -atomic_t fscache_n_object_lookups;
46032 -atomic_t fscache_n_object_lookups_negative;
46033 -atomic_t fscache_n_object_lookups_positive;
46034 -atomic_t fscache_n_object_lookups_timed_out;
46035 -atomic_t fscache_n_object_created;
46036 -atomic_t fscache_n_object_avail;
46037 -atomic_t fscache_n_object_dead;
46038 +atomic_unchecked_t fscache_n_object_alloc;
46039 +atomic_unchecked_t fscache_n_object_no_alloc;
46040 +atomic_unchecked_t fscache_n_object_lookups;
46041 +atomic_unchecked_t fscache_n_object_lookups_negative;
46042 +atomic_unchecked_t fscache_n_object_lookups_positive;
46043 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46044 +atomic_unchecked_t fscache_n_object_created;
46045 +atomic_unchecked_t fscache_n_object_avail;
46046 +atomic_unchecked_t fscache_n_object_dead;
46047
46048 -atomic_t fscache_n_checkaux_none;
46049 -atomic_t fscache_n_checkaux_okay;
46050 -atomic_t fscache_n_checkaux_update;
46051 -atomic_t fscache_n_checkaux_obsolete;
46052 +atomic_unchecked_t fscache_n_checkaux_none;
46053 +atomic_unchecked_t fscache_n_checkaux_okay;
46054 +atomic_unchecked_t fscache_n_checkaux_update;
46055 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46056
46057 atomic_t fscache_n_cop_alloc_object;
46058 atomic_t fscache_n_cop_lookup_object;
46059 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46060 seq_puts(m, "FS-Cache statistics\n");
46061
46062 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46063 - atomic_read(&fscache_n_cookie_index),
46064 - atomic_read(&fscache_n_cookie_data),
46065 - atomic_read(&fscache_n_cookie_special));
46066 + atomic_read_unchecked(&fscache_n_cookie_index),
46067 + atomic_read_unchecked(&fscache_n_cookie_data),
46068 + atomic_read_unchecked(&fscache_n_cookie_special));
46069
46070 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46071 - atomic_read(&fscache_n_object_alloc),
46072 - atomic_read(&fscache_n_object_no_alloc),
46073 - atomic_read(&fscache_n_object_avail),
46074 - atomic_read(&fscache_n_object_dead));
46075 + atomic_read_unchecked(&fscache_n_object_alloc),
46076 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46077 + atomic_read_unchecked(&fscache_n_object_avail),
46078 + atomic_read_unchecked(&fscache_n_object_dead));
46079 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46080 - atomic_read(&fscache_n_checkaux_none),
46081 - atomic_read(&fscache_n_checkaux_okay),
46082 - atomic_read(&fscache_n_checkaux_update),
46083 - atomic_read(&fscache_n_checkaux_obsolete));
46084 + atomic_read_unchecked(&fscache_n_checkaux_none),
46085 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46086 + atomic_read_unchecked(&fscache_n_checkaux_update),
46087 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46088
46089 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46090 - atomic_read(&fscache_n_marks),
46091 - atomic_read(&fscache_n_uncaches));
46092 + atomic_read_unchecked(&fscache_n_marks),
46093 + atomic_read_unchecked(&fscache_n_uncaches));
46094
46095 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46096 " oom=%u\n",
46097 - atomic_read(&fscache_n_acquires),
46098 - atomic_read(&fscache_n_acquires_null),
46099 - atomic_read(&fscache_n_acquires_no_cache),
46100 - atomic_read(&fscache_n_acquires_ok),
46101 - atomic_read(&fscache_n_acquires_nobufs),
46102 - atomic_read(&fscache_n_acquires_oom));
46103 + atomic_read_unchecked(&fscache_n_acquires),
46104 + atomic_read_unchecked(&fscache_n_acquires_null),
46105 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46106 + atomic_read_unchecked(&fscache_n_acquires_ok),
46107 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46108 + atomic_read_unchecked(&fscache_n_acquires_oom));
46109
46110 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46111 - atomic_read(&fscache_n_object_lookups),
46112 - atomic_read(&fscache_n_object_lookups_negative),
46113 - atomic_read(&fscache_n_object_lookups_positive),
46114 - atomic_read(&fscache_n_object_created),
46115 - atomic_read(&fscache_n_object_lookups_timed_out));
46116 + atomic_read_unchecked(&fscache_n_object_lookups),
46117 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46118 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46119 + atomic_read_unchecked(&fscache_n_object_created),
46120 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46121
46122 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46123 - atomic_read(&fscache_n_updates),
46124 - atomic_read(&fscache_n_updates_null),
46125 - atomic_read(&fscache_n_updates_run));
46126 + atomic_read_unchecked(&fscache_n_updates),
46127 + atomic_read_unchecked(&fscache_n_updates_null),
46128 + atomic_read_unchecked(&fscache_n_updates_run));
46129
46130 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46131 - atomic_read(&fscache_n_relinquishes),
46132 - atomic_read(&fscache_n_relinquishes_null),
46133 - atomic_read(&fscache_n_relinquishes_waitcrt),
46134 - atomic_read(&fscache_n_relinquishes_retire));
46135 + atomic_read_unchecked(&fscache_n_relinquishes),
46136 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46137 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46138 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46139
46140 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46141 - atomic_read(&fscache_n_attr_changed),
46142 - atomic_read(&fscache_n_attr_changed_ok),
46143 - atomic_read(&fscache_n_attr_changed_nobufs),
46144 - atomic_read(&fscache_n_attr_changed_nomem),
46145 - atomic_read(&fscache_n_attr_changed_calls));
46146 + atomic_read_unchecked(&fscache_n_attr_changed),
46147 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46148 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46149 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46150 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46151
46152 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46153 - atomic_read(&fscache_n_allocs),
46154 - atomic_read(&fscache_n_allocs_ok),
46155 - atomic_read(&fscache_n_allocs_wait),
46156 - atomic_read(&fscache_n_allocs_nobufs),
46157 - atomic_read(&fscache_n_allocs_intr));
46158 + atomic_read_unchecked(&fscache_n_allocs),
46159 + atomic_read_unchecked(&fscache_n_allocs_ok),
46160 + atomic_read_unchecked(&fscache_n_allocs_wait),
46161 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46162 + atomic_read_unchecked(&fscache_n_allocs_intr));
46163 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46164 - atomic_read(&fscache_n_alloc_ops),
46165 - atomic_read(&fscache_n_alloc_op_waits),
46166 - atomic_read(&fscache_n_allocs_object_dead));
46167 + atomic_read_unchecked(&fscache_n_alloc_ops),
46168 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46169 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46170
46171 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46172 " int=%u oom=%u\n",
46173 - atomic_read(&fscache_n_retrievals),
46174 - atomic_read(&fscache_n_retrievals_ok),
46175 - atomic_read(&fscache_n_retrievals_wait),
46176 - atomic_read(&fscache_n_retrievals_nodata),
46177 - atomic_read(&fscache_n_retrievals_nobufs),
46178 - atomic_read(&fscache_n_retrievals_intr),
46179 - atomic_read(&fscache_n_retrievals_nomem));
46180 + atomic_read_unchecked(&fscache_n_retrievals),
46181 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46182 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46183 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46184 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46185 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46186 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46187 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46188 - atomic_read(&fscache_n_retrieval_ops),
46189 - atomic_read(&fscache_n_retrieval_op_waits),
46190 - atomic_read(&fscache_n_retrievals_object_dead));
46191 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46192 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46193 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46194
46195 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46196 - atomic_read(&fscache_n_stores),
46197 - atomic_read(&fscache_n_stores_ok),
46198 - atomic_read(&fscache_n_stores_again),
46199 - atomic_read(&fscache_n_stores_nobufs),
46200 - atomic_read(&fscache_n_stores_oom));
46201 + atomic_read_unchecked(&fscache_n_stores),
46202 + atomic_read_unchecked(&fscache_n_stores_ok),
46203 + atomic_read_unchecked(&fscache_n_stores_again),
46204 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46205 + atomic_read_unchecked(&fscache_n_stores_oom));
46206 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46207 - atomic_read(&fscache_n_store_ops),
46208 - atomic_read(&fscache_n_store_calls),
46209 - atomic_read(&fscache_n_store_pages),
46210 - atomic_read(&fscache_n_store_radix_deletes),
46211 - atomic_read(&fscache_n_store_pages_over_limit));
46212 + atomic_read_unchecked(&fscache_n_store_ops),
46213 + atomic_read_unchecked(&fscache_n_store_calls),
46214 + atomic_read_unchecked(&fscache_n_store_pages),
46215 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46216 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46217
46218 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46219 - atomic_read(&fscache_n_store_vmscan_not_storing),
46220 - atomic_read(&fscache_n_store_vmscan_gone),
46221 - atomic_read(&fscache_n_store_vmscan_busy),
46222 - atomic_read(&fscache_n_store_vmscan_cancelled));
46223 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46224 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46225 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46226 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46227
46228 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46229 - atomic_read(&fscache_n_op_pend),
46230 - atomic_read(&fscache_n_op_run),
46231 - atomic_read(&fscache_n_op_enqueue),
46232 - atomic_read(&fscache_n_op_cancelled),
46233 - atomic_read(&fscache_n_op_rejected));
46234 + atomic_read_unchecked(&fscache_n_op_pend),
46235 + atomic_read_unchecked(&fscache_n_op_run),
46236 + atomic_read_unchecked(&fscache_n_op_enqueue),
46237 + atomic_read_unchecked(&fscache_n_op_cancelled),
46238 + atomic_read_unchecked(&fscache_n_op_rejected));
46239 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46240 - atomic_read(&fscache_n_op_deferred_release),
46241 - atomic_read(&fscache_n_op_release),
46242 - atomic_read(&fscache_n_op_gc));
46243 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46244 + atomic_read_unchecked(&fscache_n_op_release),
46245 + atomic_read_unchecked(&fscache_n_op_gc));
46246
46247 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46248 atomic_read(&fscache_n_cop_alloc_object),
46249 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46250 index b6cca47..ec782c3 100644
46251 --- a/fs/fuse/cuse.c
46252 +++ b/fs/fuse/cuse.c
46253 @@ -586,10 +586,12 @@ static int __init cuse_init(void)
46254 INIT_LIST_HEAD(&cuse_conntbl[i]);
46255
46256 /* inherit and extend fuse_dev_operations */
46257 - cuse_channel_fops = fuse_dev_operations;
46258 - cuse_channel_fops.owner = THIS_MODULE;
46259 - cuse_channel_fops.open = cuse_channel_open;
46260 - cuse_channel_fops.release = cuse_channel_release;
46261 + pax_open_kernel();
46262 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46263 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46264 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46265 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46266 + pax_close_kernel();
46267
46268 cuse_class = class_create(THIS_MODULE, "cuse");
46269 if (IS_ERR(cuse_class))
46270 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46271 index 2aaf3ea..8e50863 100644
46272 --- a/fs/fuse/dev.c
46273 +++ b/fs/fuse/dev.c
46274 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46275 ret = 0;
46276 pipe_lock(pipe);
46277
46278 - if (!pipe->readers) {
46279 + if (!atomic_read(&pipe->readers)) {
46280 send_sig(SIGPIPE, current, 0);
46281 if (!ret)
46282 ret = -EPIPE;
46283 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46284 index 9f63e49..d8a64c0 100644
46285 --- a/fs/fuse/dir.c
46286 +++ b/fs/fuse/dir.c
46287 @@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *dentry)
46288 return link;
46289 }
46290
46291 -static void free_link(char *link)
46292 +static void free_link(const char *link)
46293 {
46294 if (!IS_ERR(link))
46295 free_page((unsigned long) link);
46296 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46297 index 900cf98..3896726 100644
46298 --- a/fs/gfs2/inode.c
46299 +++ b/fs/gfs2/inode.c
46300 @@ -1517,7 +1517,7 @@ out:
46301
46302 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46303 {
46304 - char *s = nd_get_link(nd);
46305 + const char *s = nd_get_link(nd);
46306 if (!IS_ERR(s))
46307 kfree(s);
46308 }
46309 diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
46310 index 4dfbfec..947c9c2 100644
46311 --- a/fs/hfsplus/catalog.c
46312 +++ b/fs/hfsplus/catalog.c
46313 @@ -179,6 +179,8 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid,
46314 int err;
46315 u16 type;
46316
46317 + pax_track_stack();
46318 +
46319 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
46320 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
46321 if (err)
46322 @@ -210,6 +212,8 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,
46323 int entry_size;
46324 int err;
46325
46326 + pax_track_stack();
46327 +
46328 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n",
46329 str->name, cnid, inode->i_nlink);
46330 err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
46331 @@ -353,6 +357,8 @@ int hfsplus_rename_cat(u32 cnid,
46332 int entry_size, type;
46333 int err;
46334
46335 + pax_track_stack();
46336 +
46337 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n",
46338 cnid, src_dir->i_ino, src_name->name,
46339 dst_dir->i_ino, dst_name->name);
46340 diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
46341 index 25b2443..09a3341 100644
46342 --- a/fs/hfsplus/dir.c
46343 +++ b/fs/hfsplus/dir.c
46344 @@ -131,6 +131,8 @@ static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir)
46345 struct hfsplus_readdir_data *rd;
46346 u16 type;
46347
46348 + pax_track_stack();
46349 +
46350 if (filp->f_pos >= inode->i_size)
46351 return 0;
46352
46353 diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
46354 index 4cc1e3a..ad0f70b 100644
46355 --- a/fs/hfsplus/inode.c
46356 +++ b/fs/hfsplus/inode.c
46357 @@ -501,6 +501,8 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
46358 int res = 0;
46359 u16 type;
46360
46361 + pax_track_stack();
46362 +
46363 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
46364
46365 HFSPLUS_I(inode)->linkid = 0;
46366 @@ -564,6 +566,8 @@ int hfsplus_cat_write_inode(struct inode *inode)
46367 struct hfs_find_data fd;
46368 hfsplus_cat_entry entry;
46369
46370 + pax_track_stack();
46371 +
46372 if (HFSPLUS_IS_RSRC(inode))
46373 main_inode = HFSPLUS_I(inode)->rsrc_inode;
46374
46375 diff --git a/fs/hfsplus/ioctl.c b/fs/hfsplus/ioctl.c
46376 index fbaa669..c548cd0 100644
46377 --- a/fs/hfsplus/ioctl.c
46378 +++ b/fs/hfsplus/ioctl.c
46379 @@ -122,6 +122,8 @@ int hfsplus_setxattr(struct dentry *dentry, const char *name,
46380 struct hfsplus_cat_file *file;
46381 int res;
46382
46383 + pax_track_stack();
46384 +
46385 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
46386 return -EOPNOTSUPP;
46387
46388 @@ -166,6 +168,8 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
46389 struct hfsplus_cat_file *file;
46390 ssize_t res = 0;
46391
46392 + pax_track_stack();
46393 +
46394 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
46395 return -EOPNOTSUPP;
46396
46397 diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
46398 index d24a9b6..dd9b3dd 100644
46399 --- a/fs/hfsplus/super.c
46400 +++ b/fs/hfsplus/super.c
46401 @@ -347,6 +347,8 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
46402 u64 last_fs_block, last_fs_page;
46403 int err;
46404
46405 + pax_track_stack();
46406 +
46407 err = -EINVAL;
46408 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
46409 if (!sbi)
46410 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46411 index ec88953..cb5e98e 100644
46412 --- a/fs/hugetlbfs/inode.c
46413 +++ b/fs/hugetlbfs/inode.c
46414 @@ -915,7 +915,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46415 .kill_sb = kill_litter_super,
46416 };
46417
46418 -static struct vfsmount *hugetlbfs_vfsmount;
46419 +struct vfsmount *hugetlbfs_vfsmount;
46420
46421 static int can_do_hugetlb_shm(void)
46422 {
46423 diff --git a/fs/inode.c b/fs/inode.c
46424 index ec79246..054c36a 100644
46425 --- a/fs/inode.c
46426 +++ b/fs/inode.c
46427 @@ -787,8 +787,8 @@ unsigned int get_next_ino(void)
46428
46429 #ifdef CONFIG_SMP
46430 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46431 - static atomic_t shared_last_ino;
46432 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46433 + static atomic_unchecked_t shared_last_ino;
46434 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46435
46436 res = next - LAST_INO_BATCH;
46437 }
46438 diff --git a/fs/jbd/checkpoint.c b/fs/jbd/checkpoint.c
46439 index f94fc48..3bb8d30 100644
46440 --- a/fs/jbd/checkpoint.c
46441 +++ b/fs/jbd/checkpoint.c
46442 @@ -358,6 +358,8 @@ int log_do_checkpoint(journal_t *journal)
46443 tid_t this_tid;
46444 int result;
46445
46446 + pax_track_stack();
46447 +
46448 jbd_debug(1, "Start checkpoint\n");
46449
46450 /*
46451 diff --git a/fs/jffs2/compr_rtime.c b/fs/jffs2/compr_rtime.c
46452 index 16a5047..88ff6ca 100644
46453 --- a/fs/jffs2/compr_rtime.c
46454 +++ b/fs/jffs2/compr_rtime.c
46455 @@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned char *data_in,
46456 int outpos = 0;
46457 int pos=0;
46458
46459 + pax_track_stack();
46460 +
46461 memset(positions,0,sizeof(positions));
46462
46463 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
46464 @@ -78,6 +80,8 @@ static int jffs2_rtime_decompress(unsigned char *data_in,
46465 int outpos = 0;
46466 int pos=0;
46467
46468 + pax_track_stack();
46469 +
46470 memset(positions,0,sizeof(positions));
46471
46472 while (outpos<destlen) {
46473 diff --git a/fs/jffs2/compr_rubin.c b/fs/jffs2/compr_rubin.c
46474 index 9e7cec8..4713089 100644
46475 --- a/fs/jffs2/compr_rubin.c
46476 +++ b/fs/jffs2/compr_rubin.c
46477 @@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsigned char *data_in,
46478 int ret;
46479 uint32_t mysrclen, mydstlen;
46480
46481 + pax_track_stack();
46482 +
46483 mysrclen = *sourcelen;
46484 mydstlen = *dstlen - 8;
46485
46486 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46487 index e513f19..2ab1351 100644
46488 --- a/fs/jffs2/erase.c
46489 +++ b/fs/jffs2/erase.c
46490 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46491 struct jffs2_unknown_node marker = {
46492 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46493 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46494 - .totlen = cpu_to_je32(c->cleanmarker_size)
46495 + .totlen = cpu_to_je32(c->cleanmarker_size),
46496 + .hdr_crc = cpu_to_je32(0)
46497 };
46498
46499 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46500 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46501 index 4515bea..178f2d6 100644
46502 --- a/fs/jffs2/wbuf.c
46503 +++ b/fs/jffs2/wbuf.c
46504 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46505 {
46506 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46507 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46508 - .totlen = constant_cpu_to_je32(8)
46509 + .totlen = constant_cpu_to_je32(8),
46510 + .hdr_crc = constant_cpu_to_je32(0)
46511 };
46512
46513 /*
46514 diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
46515 index 3e93cdd..c8a80e1 100644
46516 --- a/fs/jffs2/xattr.c
46517 +++ b/fs/jffs2/xattr.c
46518 @@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
46519
46520 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
46521
46522 + pax_track_stack();
46523 +
46524 /* Phase.1 : Merge same xref */
46525 for (i=0; i < XREF_TMPHASH_SIZE; i++)
46526 xref_tmphash[i] = NULL;
46527 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46528 index 06c8a67..589dbbd 100644
46529 --- a/fs/jfs/super.c
46530 +++ b/fs/jfs/super.c
46531 @@ -803,7 +803,7 @@ static int __init init_jfs_fs(void)
46532
46533 jfs_inode_cachep =
46534 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46535 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46536 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46537 init_once);
46538 if (jfs_inode_cachep == NULL)
46539 return -ENOMEM;
46540 diff --git a/fs/libfs.c b/fs/libfs.c
46541 index c18e9a1..0b04e2c 100644
46542 --- a/fs/libfs.c
46543 +++ b/fs/libfs.c
46544 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46545
46546 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46547 struct dentry *next;
46548 + char d_name[sizeof(next->d_iname)];
46549 + const unsigned char *name;
46550 +
46551 next = list_entry(p, struct dentry, d_u.d_child);
46552 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46553 if (!simple_positive(next)) {
46554 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46555
46556 spin_unlock(&next->d_lock);
46557 spin_unlock(&dentry->d_lock);
46558 - if (filldir(dirent, next->d_name.name,
46559 + name = next->d_name.name;
46560 + if (name == next->d_iname) {
46561 + memcpy(d_name, name, next->d_name.len);
46562 + name = d_name;
46563 + }
46564 + if (filldir(dirent, name,
46565 next->d_name.len, filp->f_pos,
46566 next->d_inode->i_ino,
46567 dt_type(next->d_inode)) < 0)
46568 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46569 index 8392cb8..ae8ed40 100644
46570 --- a/fs/lockd/clntproc.c
46571 +++ b/fs/lockd/clntproc.c
46572 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46573 /*
46574 * Cookie counter for NLM requests
46575 */
46576 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46577 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46578
46579 void nlmclnt_next_cookie(struct nlm_cookie *c)
46580 {
46581 - u32 cookie = atomic_inc_return(&nlm_cookie);
46582 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46583
46584 memcpy(c->data, &cookie, 4);
46585 c->len=4;
46586 @@ -621,6 +621,8 @@ nlmclnt_reclaim(struct nlm_host *host, struct file_lock *fl)
46587 struct nlm_rqst reqst, *req;
46588 int status;
46589
46590 + pax_track_stack();
46591 +
46592 req = &reqst;
46593 memset(req, 0, sizeof(*req));
46594 locks_init_lock(&req->a_args.lock.fl);
46595 diff --git a/fs/locks.c b/fs/locks.c
46596 index 703f545..150a552 100644
46597 --- a/fs/locks.c
46598 +++ b/fs/locks.c
46599 @@ -2022,16 +2022,16 @@ void locks_remove_flock(struct file *filp)
46600 return;
46601
46602 if (filp->f_op && filp->f_op->flock) {
46603 - struct file_lock fl = {
46604 + struct file_lock flock = {
46605 .fl_pid = current->tgid,
46606 .fl_file = filp,
46607 .fl_flags = FL_FLOCK,
46608 .fl_type = F_UNLCK,
46609 .fl_end = OFFSET_MAX,
46610 };
46611 - filp->f_op->flock(filp, F_SETLKW, &fl);
46612 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46613 - fl.fl_ops->fl_release_private(&fl);
46614 + filp->f_op->flock(filp, F_SETLKW, &flock);
46615 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46616 + flock.fl_ops->fl_release_private(&flock);
46617 }
46618
46619 lock_flocks();
46620 diff --git a/fs/logfs/super.c b/fs/logfs/super.c
46621 index ce03a18..ac8c14f 100644
46622 --- a/fs/logfs/super.c
46623 +++ b/fs/logfs/super.c
46624 @@ -266,6 +266,8 @@ static int logfs_recover_sb(struct super_block *sb)
46625 struct logfs_disk_super _ds1, *ds1 = &_ds1;
46626 int err, valid0, valid1;
46627
46628 + pax_track_stack();
46629 +
46630 /* read first superblock */
46631 err = wbuf_read(sb, super->s_sb_ofs[0], sizeof(*ds0), ds0);
46632 if (err)
46633 diff --git a/fs/minix/bitmap.c b/fs/minix/bitmap.c
46634 index 3f32bcb..7c82c29 100644
46635 --- a/fs/minix/bitmap.c
46636 +++ b/fs/minix/bitmap.c
46637 @@ -20,10 +20,11 @@ static const int nibblemap[] = { 4,3,3,2,3,2,2,1,3,2,2,1,2,1,1,0 };
46638
46639 static DEFINE_SPINLOCK(bitmap_lock);
46640
46641 -static unsigned long count_free(struct buffer_head *map[], unsigned numblocks, __u32 numbits)
46642 +static unsigned long count_free(struct buffer_head *map[], unsigned blocksize, __u32 numbits)
46643 {
46644 unsigned i, j, sum = 0;
46645 struct buffer_head *bh;
46646 + unsigned numblocks = minix_blocks_needed(numbits, blocksize);
46647
46648 for (i=0; i<numblocks-1; i++) {
46649 if (!(bh=map[i]))
46650 @@ -105,10 +106,12 @@ int minix_new_block(struct inode * inode)
46651 return 0;
46652 }
46653
46654 -unsigned long minix_count_free_blocks(struct minix_sb_info *sbi)
46655 +unsigned long minix_count_free_blocks(struct super_block *sb)
46656 {
46657 - return (count_free(sbi->s_zmap, sbi->s_zmap_blocks,
46658 - sbi->s_nzones - sbi->s_firstdatazone + 1)
46659 + struct minix_sb_info *sbi = minix_sb(sb);
46660 + u32 bits = sbi->s_nzones - (sbi->s_firstdatazone + 1);
46661 +
46662 + return (count_free(sbi->s_zmap, sb->s_blocksize, bits)
46663 << sbi->s_log_zone_size);
46664 }
46665
46666 @@ -273,7 +276,10 @@ struct inode *minix_new_inode(const struct inode *dir, int mode, int *error)
46667 return inode;
46668 }
46669
46670 -unsigned long minix_count_free_inodes(struct minix_sb_info *sbi)
46671 +unsigned long minix_count_free_inodes(struct super_block *sb)
46672 {
46673 - return count_free(sbi->s_imap, sbi->s_imap_blocks, sbi->s_ninodes + 1);
46674 + struct minix_sb_info *sbi = minix_sb(sb);
46675 + u32 bits = sbi->s_ninodes + 1;
46676 +
46677 + return count_free(sbi->s_imap, sb->s_blocksize, bits);
46678 }
46679 diff --git a/fs/minix/inode.c b/fs/minix/inode.c
46680 index e7d23e2..1ed1351 100644
46681 --- a/fs/minix/inode.c
46682 +++ b/fs/minix/inode.c
46683 @@ -279,6 +279,27 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
46684 else if (sbi->s_mount_state & MINIX_ERROR_FS)
46685 printk("MINIX-fs: mounting file system with errors, "
46686 "running fsck is recommended\n");
46687 +
46688 + /* Apparently minix can create filesystems that allocate more blocks for
46689 + * the bitmaps than needed. We simply ignore that, but verify it didn't
46690 + * create one with not enough blocks and bail out if so.
46691 + */
46692 + block = minix_blocks_needed(sbi->s_ninodes, s->s_blocksize);
46693 + if (sbi->s_imap_blocks < block) {
46694 + printk("MINIX-fs: file system does not have enough "
46695 + "imap blocks allocated. Refusing to mount\n");
46696 + goto out_iput;
46697 + }
46698 +
46699 + block = minix_blocks_needed(
46700 + (sbi->s_nzones - (sbi->s_firstdatazone + 1)),
46701 + s->s_blocksize);
46702 + if (sbi->s_zmap_blocks < block) {
46703 + printk("MINIX-fs: file system does not have enough "
46704 + "zmap blocks allocated. Refusing to mount.\n");
46705 + goto out_iput;
46706 + }
46707 +
46708 return 0;
46709
46710 out_iput:
46711 @@ -339,10 +360,10 @@ static int minix_statfs(struct dentry *dentry, struct kstatfs *buf)
46712 buf->f_type = sb->s_magic;
46713 buf->f_bsize = sb->s_blocksize;
46714 buf->f_blocks = (sbi->s_nzones - sbi->s_firstdatazone) << sbi->s_log_zone_size;
46715 - buf->f_bfree = minix_count_free_blocks(sbi);
46716 + buf->f_bfree = minix_count_free_blocks(sb);
46717 buf->f_bavail = buf->f_bfree;
46718 buf->f_files = sbi->s_ninodes;
46719 - buf->f_ffree = minix_count_free_inodes(sbi);
46720 + buf->f_ffree = minix_count_free_inodes(sb);
46721 buf->f_namelen = sbi->s_namelen;
46722 buf->f_fsid.val[0] = (u32)id;
46723 buf->f_fsid.val[1] = (u32)(id >> 32);
46724 diff --git a/fs/minix/minix.h b/fs/minix/minix.h
46725 index 341e212..6415fe0 100644
46726 --- a/fs/minix/minix.h
46727 +++ b/fs/minix/minix.h
46728 @@ -48,10 +48,10 @@ extern struct minix_inode * minix_V1_raw_inode(struct super_block *, ino_t, stru
46729 extern struct minix2_inode * minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **);
46730 extern struct inode * minix_new_inode(const struct inode *, int, int *);
46731 extern void minix_free_inode(struct inode * inode);
46732 -extern unsigned long minix_count_free_inodes(struct minix_sb_info *sbi);
46733 +extern unsigned long minix_count_free_inodes(struct super_block *sb);
46734 extern int minix_new_block(struct inode * inode);
46735 extern void minix_free_block(struct inode *inode, unsigned long block);
46736 -extern unsigned long minix_count_free_blocks(struct minix_sb_info *sbi);
46737 +extern unsigned long minix_count_free_blocks(struct super_block *sb);
46738 extern int minix_getattr(struct vfsmount *, struct dentry *, struct kstat *);
46739 extern int minix_prepare_chunk(struct page *page, loff_t pos, unsigned len);
46740
46741 @@ -88,6 +88,11 @@ static inline struct minix_inode_info *minix_i(struct inode *inode)
46742 return list_entry(inode, struct minix_inode_info, vfs_inode);
46743 }
46744
46745 +static inline unsigned minix_blocks_needed(unsigned bits, unsigned blocksize)
46746 +{
46747 + return DIV_ROUND_UP(bits, blocksize * 8);
46748 +}
46749 +
46750 #if defined(CONFIG_MINIX_FS_NATIVE_ENDIAN) && \
46751 defined(CONFIG_MINIX_FS_BIG_ENDIAN_16BIT_INDEXED)
46752
46753 diff --git a/fs/namei.c b/fs/namei.c
46754 index 3d15072..c1ddf9c 100644
46755 --- a/fs/namei.c
46756 +++ b/fs/namei.c
46757 @@ -281,16 +281,32 @@ int generic_permission(struct inode *inode, int mask)
46758 if (ret != -EACCES)
46759 return ret;
46760
46761 +#ifdef CONFIG_GRKERNSEC
46762 + /* we'll block if we have to log due to a denied capability use */
46763 + if (mask & MAY_NOT_BLOCK)
46764 + return -ECHILD;
46765 +#endif
46766 +
46767 if (S_ISDIR(inode->i_mode)) {
46768 /* DACs are overridable for directories */
46769 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46770 - return 0;
46771 if (!(mask & MAY_WRITE))
46772 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46773 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46774 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46775 return 0;
46776 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46777 + return 0;
46778 return -EACCES;
46779 }
46780 /*
46781 + * Searching includes executable on directories, else just read.
46782 + */
46783 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46784 + if (mask == MAY_READ)
46785 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46786 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46787 + return 0;
46788 +
46789 + /*
46790 * Read/write DACs are always overridable.
46791 * Executable DACs are overridable when there is
46792 * at least one exec bit set.
46793 @@ -299,14 +315,6 @@ int generic_permission(struct inode *inode, int mask)
46794 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46795 return 0;
46796
46797 - /*
46798 - * Searching includes executable on directories, else just read.
46799 - */
46800 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46801 - if (mask == MAY_READ)
46802 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46803 - return 0;
46804 -
46805 return -EACCES;
46806 }
46807
46808 @@ -653,11 +661,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46809 return error;
46810 }
46811
46812 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
46813 + dentry->d_inode, dentry, nd->path.mnt)) {
46814 + error = -EACCES;
46815 + *p = ERR_PTR(error); /* no ->put_link(), please */
46816 + path_put(&nd->path);
46817 + return error;
46818 + }
46819 +
46820 nd->last_type = LAST_BIND;
46821 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46822 error = PTR_ERR(*p);
46823 if (!IS_ERR(*p)) {
46824 - char *s = nd_get_link(nd);
46825 + const char *s = nd_get_link(nd);
46826 error = 0;
46827 if (s)
46828 error = __vfs_follow_link(nd, s);
46829 @@ -1622,6 +1638,21 @@ static int path_lookupat(int dfd, const char *name,
46830 if (!err)
46831 err = complete_walk(nd);
46832
46833 + if (!(nd->flags & LOOKUP_PARENT)) {
46834 +#ifdef CONFIG_GRKERNSEC
46835 + if (flags & LOOKUP_RCU) {
46836 + if (!err)
46837 + path_put(&nd->path);
46838 + err = -ECHILD;
46839 + } else
46840 +#endif
46841 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46842 + if (!err)
46843 + path_put(&nd->path);
46844 + err = -ENOENT;
46845 + }
46846 + }
46847 +
46848 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46849 if (!nd->inode->i_op->lookup) {
46850 path_put(&nd->path);
46851 @@ -1649,6 +1680,15 @@ static int do_path_lookup(int dfd, const char *name,
46852 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46853
46854 if (likely(!retval)) {
46855 + if (*name != '/' && nd->path.dentry && nd->inode) {
46856 +#ifdef CONFIG_GRKERNSEC
46857 + if (flags & LOOKUP_RCU)
46858 + return -ECHILD;
46859 +#endif
46860 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46861 + return -ENOENT;
46862 + }
46863 +
46864 if (unlikely(!audit_dummy_context())) {
46865 if (nd->path.dentry && nd->inode)
46866 audit_inode(name, nd->path.dentry);
46867 @@ -2049,7 +2089,27 @@ static int may_open(struct path *path, int acc_mode, int flag)
46868 /*
46869 * Ensure there are no outstanding leases on the file.
46870 */
46871 - return break_lease(inode, flag);
46872 + error = break_lease(inode, flag);
46873 +
46874 + if (error)
46875 + return error;
46876 +
46877 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
46878 + error = -EPERM;
46879 + goto exit;
46880 + }
46881 +
46882 + if (gr_handle_rawio(inode)) {
46883 + error = -EPERM;
46884 + goto exit;
46885 + }
46886 +
46887 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode)) {
46888 + error = -EACCES;
46889 + goto exit;
46890 + }
46891 +exit:
46892 + return error;
46893 }
46894
46895 static int handle_truncate(struct file *filp)
46896 @@ -2110,6 +2170,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46897 error = complete_walk(nd);
46898 if (error)
46899 return ERR_PTR(error);
46900 +#ifdef CONFIG_GRKERNSEC
46901 + if (nd->flags & LOOKUP_RCU) {
46902 + error = -ECHILD;
46903 + goto exit;
46904 + }
46905 +#endif
46906 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46907 + error = -ENOENT;
46908 + goto exit;
46909 + }
46910 audit_inode(pathname, nd->path.dentry);
46911 if (open_flag & O_CREAT) {
46912 error = -EISDIR;
46913 @@ -2120,6 +2190,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46914 error = complete_walk(nd);
46915 if (error)
46916 return ERR_PTR(error);
46917 +#ifdef CONFIG_GRKERNSEC
46918 + if (nd->flags & LOOKUP_RCU) {
46919 + error = -ECHILD;
46920 + goto exit;
46921 + }
46922 +#endif
46923 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46924 + error = -ENOENT;
46925 + goto exit;
46926 + }
46927 audit_inode(pathname, dir);
46928 goto ok;
46929 }
46930 @@ -2141,6 +2221,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46931 error = complete_walk(nd);
46932 if (error)
46933 return ERR_PTR(-ECHILD);
46934 +#ifdef CONFIG_GRKERNSEC
46935 + if (nd->flags & LOOKUP_RCU) {
46936 + error = -ECHILD;
46937 + goto exit;
46938 + }
46939 +#endif
46940 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46941 + error = -ENOENT;
46942 + goto exit;
46943 + }
46944
46945 error = -ENOTDIR;
46946 if (nd->flags & LOOKUP_DIRECTORY) {
46947 @@ -2181,6 +2271,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46948 /* Negative dentry, just create the file */
46949 if (!dentry->d_inode) {
46950 int mode = op->mode;
46951 +
46952 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46953 + error = -EACCES;
46954 + goto exit_mutex_unlock;
46955 + }
46956 +
46957 if (!IS_POSIXACL(dir->d_inode))
46958 mode &= ~current_umask();
46959 /*
46960 @@ -2204,6 +2300,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46961 error = vfs_create(dir->d_inode, dentry, mode, nd);
46962 if (error)
46963 goto exit_mutex_unlock;
46964 + else
46965 + gr_handle_create(path->dentry, path->mnt);
46966 mutex_unlock(&dir->d_inode->i_mutex);
46967 dput(nd->path.dentry);
46968 nd->path.dentry = dentry;
46969 @@ -2213,6 +2311,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46970 /*
46971 * It already exists.
46972 */
46973 +
46974 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46975 + error = -ENOENT;
46976 + goto exit_mutex_unlock;
46977 + }
46978 +
46979 + /* only check if O_CREAT is specified, all other checks need to go
46980 + into may_open */
46981 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46982 + error = -EACCES;
46983 + goto exit_mutex_unlock;
46984 + }
46985 +
46986 mutex_unlock(&dir->d_inode->i_mutex);
46987 audit_inode(pathname, path->dentry);
46988
46989 @@ -2425,6 +2536,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46990 *path = nd.path;
46991 return dentry;
46992 eexist:
46993 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46994 + dput(dentry);
46995 + dentry = ERR_PTR(-ENOENT);
46996 + goto fail;
46997 + }
46998 dput(dentry);
46999 dentry = ERR_PTR(-EEXIST);
47000 fail:
47001 @@ -2447,6 +2563,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47002 }
47003 EXPORT_SYMBOL(user_path_create);
47004
47005 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47006 +{
47007 + char *tmp = getname(pathname);
47008 + struct dentry *res;
47009 + if (IS_ERR(tmp))
47010 + return ERR_CAST(tmp);
47011 + res = kern_path_create(dfd, tmp, path, is_dir);
47012 + if (IS_ERR(res))
47013 + putname(tmp);
47014 + else
47015 + *to = tmp;
47016 + return res;
47017 +}
47018 +
47019 int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
47020 {
47021 int error = may_create(dir, dentry);
47022 @@ -2514,6 +2644,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
47023 error = mnt_want_write(path.mnt);
47024 if (error)
47025 goto out_dput;
47026 +
47027 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47028 + error = -EPERM;
47029 + goto out_drop_write;
47030 + }
47031 +
47032 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47033 + error = -EACCES;
47034 + goto out_drop_write;
47035 + }
47036 +
47037 error = security_path_mknod(&path, dentry, mode, dev);
47038 if (error)
47039 goto out_drop_write;
47040 @@ -2531,6 +2672,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
47041 }
47042 out_drop_write:
47043 mnt_drop_write(path.mnt);
47044 +
47045 + if (!error)
47046 + gr_handle_create(dentry, path.mnt);
47047 out_dput:
47048 dput(dentry);
47049 mutex_unlock(&path.dentry->d_inode->i_mutex);
47050 @@ -2580,12 +2724,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
47051 error = mnt_want_write(path.mnt);
47052 if (error)
47053 goto out_dput;
47054 +
47055 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47056 + error = -EACCES;
47057 + goto out_drop_write;
47058 + }
47059 +
47060 error = security_path_mkdir(&path, dentry, mode);
47061 if (error)
47062 goto out_drop_write;
47063 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47064 out_drop_write:
47065 mnt_drop_write(path.mnt);
47066 +
47067 + if (!error)
47068 + gr_handle_create(dentry, path.mnt);
47069 out_dput:
47070 dput(dentry);
47071 mutex_unlock(&path.dentry->d_inode->i_mutex);
47072 @@ -2665,6 +2818,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47073 char * name;
47074 struct dentry *dentry;
47075 struct nameidata nd;
47076 + ino_t saved_ino = 0;
47077 + dev_t saved_dev = 0;
47078
47079 error = user_path_parent(dfd, pathname, &nd, &name);
47080 if (error)
47081 @@ -2693,6 +2848,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47082 error = -ENOENT;
47083 goto exit3;
47084 }
47085 +
47086 + saved_ino = dentry->d_inode->i_ino;
47087 + saved_dev = gr_get_dev_from_dentry(dentry);
47088 +
47089 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47090 + error = -EACCES;
47091 + goto exit3;
47092 + }
47093 +
47094 error = mnt_want_write(nd.path.mnt);
47095 if (error)
47096 goto exit3;
47097 @@ -2700,6 +2864,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47098 if (error)
47099 goto exit4;
47100 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47101 + if (!error && (saved_dev || saved_ino))
47102 + gr_handle_delete(saved_ino, saved_dev);
47103 exit4:
47104 mnt_drop_write(nd.path.mnt);
47105 exit3:
47106 @@ -2762,6 +2928,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47107 struct dentry *dentry;
47108 struct nameidata nd;
47109 struct inode *inode = NULL;
47110 + ino_t saved_ino = 0;
47111 + dev_t saved_dev = 0;
47112
47113 error = user_path_parent(dfd, pathname, &nd, &name);
47114 if (error)
47115 @@ -2784,6 +2952,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47116 if (!inode)
47117 goto slashes;
47118 ihold(inode);
47119 +
47120 + if (inode->i_nlink <= 1) {
47121 + saved_ino = inode->i_ino;
47122 + saved_dev = gr_get_dev_from_dentry(dentry);
47123 + }
47124 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47125 + error = -EACCES;
47126 + goto exit2;
47127 + }
47128 +
47129 error = mnt_want_write(nd.path.mnt);
47130 if (error)
47131 goto exit2;
47132 @@ -2791,6 +2969,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47133 if (error)
47134 goto exit3;
47135 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47136 + if (!error && (saved_ino || saved_dev))
47137 + gr_handle_delete(saved_ino, saved_dev);
47138 exit3:
47139 mnt_drop_write(nd.path.mnt);
47140 exit2:
47141 @@ -2866,10 +3046,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47142 error = mnt_want_write(path.mnt);
47143 if (error)
47144 goto out_dput;
47145 +
47146 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47147 + error = -EACCES;
47148 + goto out_drop_write;
47149 + }
47150 +
47151 error = security_path_symlink(&path, dentry, from);
47152 if (error)
47153 goto out_drop_write;
47154 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47155 + if (!error)
47156 + gr_handle_create(dentry, path.mnt);
47157 out_drop_write:
47158 mnt_drop_write(path.mnt);
47159 out_dput:
47160 @@ -2941,6 +3129,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47161 {
47162 struct dentry *new_dentry;
47163 struct path old_path, new_path;
47164 + char *to = NULL;
47165 int how = 0;
47166 int error;
47167
47168 @@ -2964,7 +3153,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47169 if (error)
47170 return error;
47171
47172 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47173 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47174 error = PTR_ERR(new_dentry);
47175 if (IS_ERR(new_dentry))
47176 goto out;
47177 @@ -2975,13 +3164,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47178 error = mnt_want_write(new_path.mnt);
47179 if (error)
47180 goto out_dput;
47181 +
47182 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47183 + old_path.dentry->d_inode,
47184 + old_path.dentry->d_inode->i_mode, to)) {
47185 + error = -EACCES;
47186 + goto out_drop_write;
47187 + }
47188 +
47189 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47190 + old_path.dentry, old_path.mnt, to)) {
47191 + error = -EACCES;
47192 + goto out_drop_write;
47193 + }
47194 +
47195 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47196 if (error)
47197 goto out_drop_write;
47198 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47199 + if (!error)
47200 + gr_handle_create(new_dentry, new_path.mnt);
47201 out_drop_write:
47202 mnt_drop_write(new_path.mnt);
47203 out_dput:
47204 + putname(to);
47205 dput(new_dentry);
47206 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47207 path_put(&new_path);
47208 @@ -3153,6 +3359,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47209 char *to;
47210 int error;
47211
47212 + pax_track_stack();
47213 +
47214 error = user_path_parent(olddfd, oldname, &oldnd, &from);
47215 if (error)
47216 goto exit;
47217 @@ -3209,6 +3417,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47218 if (new_dentry == trap)
47219 goto exit5;
47220
47221 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47222 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47223 + to);
47224 + if (error)
47225 + goto exit5;
47226 +
47227 error = mnt_want_write(oldnd.path.mnt);
47228 if (error)
47229 goto exit5;
47230 @@ -3218,6 +3432,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47231 goto exit6;
47232 error = vfs_rename(old_dir->d_inode, old_dentry,
47233 new_dir->d_inode, new_dentry);
47234 + if (!error)
47235 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47236 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47237 exit6:
47238 mnt_drop_write(oldnd.path.mnt);
47239 exit5:
47240 @@ -3243,6 +3460,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47241
47242 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47243 {
47244 + char tmpbuf[64];
47245 + const char *newlink;
47246 int len;
47247
47248 len = PTR_ERR(link);
47249 @@ -3252,7 +3471,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47250 len = strlen(link);
47251 if (len > (unsigned) buflen)
47252 len = buflen;
47253 - if (copy_to_user(buffer, link, len))
47254 +
47255 + if (len < sizeof(tmpbuf)) {
47256 + memcpy(tmpbuf, link, len);
47257 + newlink = tmpbuf;
47258 + } else
47259 + newlink = link;
47260 +
47261 + if (copy_to_user(buffer, newlink, len))
47262 len = -EFAULT;
47263 out:
47264 return len;
47265 diff --git a/fs/namespace.c b/fs/namespace.c
47266 index 5e7f2e9..cd13685 100644
47267 --- a/fs/namespace.c
47268 +++ b/fs/namespace.c
47269 @@ -1326,6 +1326,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
47270 if (!(sb->s_flags & MS_RDONLY))
47271 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47272 up_write(&sb->s_umount);
47273 +
47274 + gr_log_remount(mnt->mnt_devname, retval);
47275 +
47276 return retval;
47277 }
47278
47279 @@ -1345,6 +1348,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
47280 br_write_unlock(vfsmount_lock);
47281 up_write(&namespace_sem);
47282 release_mounts(&umount_list);
47283 +
47284 + gr_log_unmount(mnt->mnt_devname, retval);
47285 +
47286 return retval;
47287 }
47288
47289 @@ -2336,6 +2342,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47290 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47291 MS_STRICTATIME);
47292
47293 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47294 + retval = -EPERM;
47295 + goto dput_out;
47296 + }
47297 +
47298 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47299 + retval = -EPERM;
47300 + goto dput_out;
47301 + }
47302 +
47303 if (flags & MS_REMOUNT)
47304 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47305 data_page);
47306 @@ -2350,6 +2366,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47307 dev_name, data_page);
47308 dput_out:
47309 path_put(&path);
47310 +
47311 + gr_log_mount(dev_name, dir_name, retval);
47312 +
47313 return retval;
47314 }
47315
47316 @@ -2573,6 +2592,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47317 if (error)
47318 goto out2;
47319
47320 + if (gr_handle_chroot_pivot()) {
47321 + error = -EPERM;
47322 + goto out2;
47323 + }
47324 +
47325 get_fs_root(current->fs, &root);
47326 error = lock_mount(&old);
47327 if (error)
47328 diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
47329 index 9c51f62..503b252 100644
47330 --- a/fs/ncpfs/dir.c
47331 +++ b/fs/ncpfs/dir.c
47332 @@ -299,6 +299,8 @@ ncp_lookup_validate(struct dentry *dentry, struct nameidata *nd)
47333 int res, val = 0, len;
47334 __u8 __name[NCP_MAXPATHLEN + 1];
47335
47336 + pax_track_stack();
47337 +
47338 if (dentry == dentry->d_sb->s_root)
47339 return 1;
47340
47341 @@ -844,6 +846,8 @@ static struct dentry *ncp_lookup(struct inode *dir, struct dentry *dentry, struc
47342 int error, res, len;
47343 __u8 __name[NCP_MAXPATHLEN + 1];
47344
47345 + pax_track_stack();
47346 +
47347 error = -EIO;
47348 if (!ncp_conn_valid(server))
47349 goto finished;
47350 @@ -931,6 +935,8 @@ int ncp_create_new(struct inode *dir, struct dentry *dentry, int mode,
47351 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
47352 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
47353
47354 + pax_track_stack();
47355 +
47356 ncp_age_dentry(server, dentry);
47357 len = sizeof(__name);
47358 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
47359 @@ -992,6 +998,8 @@ static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
47360 int error, len;
47361 __u8 __name[NCP_MAXPATHLEN + 1];
47362
47363 + pax_track_stack();
47364 +
47365 DPRINTK("ncp_mkdir: making %s/%s\n",
47366 dentry->d_parent->d_name.name, dentry->d_name.name);
47367
47368 @@ -1140,6 +1148,8 @@ static int ncp_rename(struct inode *old_dir, struct dentry *old_dentry,
47369 int old_len, new_len;
47370 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
47371
47372 + pax_track_stack();
47373 +
47374 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
47375 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
47376 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
47377 diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
47378 index 202f370..9d4565e 100644
47379 --- a/fs/ncpfs/inode.c
47380 +++ b/fs/ncpfs/inode.c
47381 @@ -461,6 +461,8 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
47382 #endif
47383 struct ncp_entry_info finfo;
47384
47385 + pax_track_stack();
47386 +
47387 memset(&data, 0, sizeof(data));
47388 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
47389 if (!server)
47390 diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
47391 index 281ae95..dd895b9 100644
47392 --- a/fs/nfs/blocklayout/blocklayout.c
47393 +++ b/fs/nfs/blocklayout/blocklayout.c
47394 @@ -90,7 +90,7 @@ static int is_writable(struct pnfs_block_extent *be, sector_t isect)
47395 */
47396 struct parallel_io {
47397 struct kref refcnt;
47398 - struct rpc_call_ops call_ops;
47399 + rpc_call_ops_no_const call_ops;
47400 void (*pnfs_callback) (void *data);
47401 void *data;
47402 };
47403 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47404 index 679d2f5..ef1ffec 100644
47405 --- a/fs/nfs/inode.c
47406 +++ b/fs/nfs/inode.c
47407 @@ -150,7 +150,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47408 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47409 nfsi->attrtimeo_timestamp = jiffies;
47410
47411 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47412 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47413 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47414 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47415 else
47416 @@ -1002,16 +1002,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47417 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47418 }
47419
47420 -static atomic_long_t nfs_attr_generation_counter;
47421 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47422
47423 static unsigned long nfs_read_attr_generation_counter(void)
47424 {
47425 - return atomic_long_read(&nfs_attr_generation_counter);
47426 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47427 }
47428
47429 unsigned long nfs_inc_attr_generation_counter(void)
47430 {
47431 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47432 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47433 }
47434
47435 void nfs_fattr_init(struct nfs_fattr *fattr)
47436 diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
47437 index 6f8bcc7..8f823c5 100644
47438 --- a/fs/nfsd/nfs4state.c
47439 +++ b/fs/nfsd/nfs4state.c
47440 @@ -3999,6 +3999,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
47441 unsigned int strhashval;
47442 int err;
47443
47444 + pax_track_stack();
47445 +
47446 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
47447 (long long) lock->lk_offset,
47448 (long long) lock->lk_length);
47449 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
47450 index f810996..cec8977 100644
47451 --- a/fs/nfsd/nfs4xdr.c
47452 +++ b/fs/nfsd/nfs4xdr.c
47453 @@ -1875,6 +1875,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
47454 .dentry = dentry,
47455 };
47456
47457 + pax_track_stack();
47458 +
47459 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
47460 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
47461 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
47462 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47463 index acf88ae..4fd6245 100644
47464 --- a/fs/nfsd/vfs.c
47465 +++ b/fs/nfsd/vfs.c
47466 @@ -896,7 +896,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47467 } else {
47468 oldfs = get_fs();
47469 set_fs(KERNEL_DS);
47470 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47471 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47472 set_fs(oldfs);
47473 }
47474
47475 @@ -1000,7 +1000,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47476
47477 /* Write the data. */
47478 oldfs = get_fs(); set_fs(KERNEL_DS);
47479 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47480 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47481 set_fs(oldfs);
47482 if (host_err < 0)
47483 goto out_nfserr;
47484 @@ -1535,7 +1535,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47485 */
47486
47487 oldfs = get_fs(); set_fs(KERNEL_DS);
47488 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
47489 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
47490 set_fs(oldfs);
47491
47492 if (host_err < 0)
47493 diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
47494 index 3e65427..ac258be 100644
47495 --- a/fs/nilfs2/ioctl.c
47496 +++ b/fs/nilfs2/ioctl.c
47497 @@ -625,6 +625,9 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
47498 if (argv[n].v_nmembs > nsegs * nilfs->ns_blocks_per_segment)
47499 goto out_free;
47500
47501 + if (argv[n].v_nmembs >= UINT_MAX / argv[n].v_size)
47502 + goto out_free;
47503 +
47504 len = argv[n].v_size * argv[n].v_nmembs;
47505 base = (void __user *)(unsigned long)argv[n].v_base;
47506 if (len == 0) {
47507 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47508 index 9fde1c0..14e8827 100644
47509 --- a/fs/notify/fanotify/fanotify_user.c
47510 +++ b/fs/notify/fanotify/fanotify_user.c
47511 @@ -276,7 +276,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47512 goto out_close_fd;
47513
47514 ret = -EFAULT;
47515 - if (copy_to_user(buf, &fanotify_event_metadata,
47516 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47517 + copy_to_user(buf, &fanotify_event_metadata,
47518 fanotify_event_metadata.event_len))
47519 goto out_kill_access_response;
47520
47521 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47522 index ee18815..7aa5d01 100644
47523 --- a/fs/notify/notification.c
47524 +++ b/fs/notify/notification.c
47525 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47526 * get set to 0 so it will never get 'freed'
47527 */
47528 static struct fsnotify_event *q_overflow_event;
47529 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47530 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47531
47532 /**
47533 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47534 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47535 */
47536 u32 fsnotify_get_cookie(void)
47537 {
47538 - return atomic_inc_return(&fsnotify_sync_cookie);
47539 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47540 }
47541 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47542
47543 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47544 index 99e3610..02c1068 100644
47545 --- a/fs/ntfs/dir.c
47546 +++ b/fs/ntfs/dir.c
47547 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47548 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47549 ~(s64)(ndir->itype.index.block_size - 1)));
47550 /* Bounds checks. */
47551 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47552 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47553 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47554 "inode 0x%lx or driver bug.", vdir->i_ino);
47555 goto err_out;
47556 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47557 index c587e2d..3641eaa 100644
47558 --- a/fs/ntfs/file.c
47559 +++ b/fs/ntfs/file.c
47560 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47561 #endif /* NTFS_RW */
47562 };
47563
47564 -const struct file_operations ntfs_empty_file_ops = {};
47565 +const struct file_operations ntfs_empty_file_ops __read_only;
47566
47567 -const struct inode_operations ntfs_empty_inode_ops = {};
47568 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47569 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47570 index 210c352..a174f83 100644
47571 --- a/fs/ocfs2/localalloc.c
47572 +++ b/fs/ocfs2/localalloc.c
47573 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47574 goto bail;
47575 }
47576
47577 - atomic_inc(&osb->alloc_stats.moves);
47578 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47579
47580 bail:
47581 if (handle)
47582 diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
47583 index 53aa41e..d7df9f1 100644
47584 --- a/fs/ocfs2/namei.c
47585 +++ b/fs/ocfs2/namei.c
47586 @@ -1063,6 +1063,8 @@ static int ocfs2_rename(struct inode *old_dir,
47587 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
47588 struct ocfs2_dir_lookup_result target_insert = { NULL, };
47589
47590 + pax_track_stack();
47591 +
47592 /* At some point it might be nice to break this function up a
47593 * bit. */
47594
47595 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47596 index 4092858..51c70ff 100644
47597 --- a/fs/ocfs2/ocfs2.h
47598 +++ b/fs/ocfs2/ocfs2.h
47599 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47600
47601 struct ocfs2_alloc_stats
47602 {
47603 - atomic_t moves;
47604 - atomic_t local_data;
47605 - atomic_t bitmap_data;
47606 - atomic_t bg_allocs;
47607 - atomic_t bg_extends;
47608 + atomic_unchecked_t moves;
47609 + atomic_unchecked_t local_data;
47610 + atomic_unchecked_t bitmap_data;
47611 + atomic_unchecked_t bg_allocs;
47612 + atomic_unchecked_t bg_extends;
47613 };
47614
47615 enum ocfs2_local_alloc_state
47616 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47617 index ba5d97e..c77db25 100644
47618 --- a/fs/ocfs2/suballoc.c
47619 +++ b/fs/ocfs2/suballoc.c
47620 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47621 mlog_errno(status);
47622 goto bail;
47623 }
47624 - atomic_inc(&osb->alloc_stats.bg_extends);
47625 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47626
47627 /* You should never ask for this much metadata */
47628 BUG_ON(bits_wanted >
47629 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47630 mlog_errno(status);
47631 goto bail;
47632 }
47633 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47634 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47635
47636 *suballoc_loc = res.sr_bg_blkno;
47637 *suballoc_bit_start = res.sr_bit_offset;
47638 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47639 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47640 res->sr_bits);
47641
47642 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47643 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47644
47645 BUG_ON(res->sr_bits != 1);
47646
47647 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47648 mlog_errno(status);
47649 goto bail;
47650 }
47651 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47652 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47653
47654 BUG_ON(res.sr_bits != 1);
47655
47656 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47657 cluster_start,
47658 num_clusters);
47659 if (!status)
47660 - atomic_inc(&osb->alloc_stats.local_data);
47661 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47662 } else {
47663 if (min_clusters > (osb->bitmap_cpg - 1)) {
47664 /* The only paths asking for contiguousness
47665 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47666 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47667 res.sr_bg_blkno,
47668 res.sr_bit_offset);
47669 - atomic_inc(&osb->alloc_stats.bitmap_data);
47670 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47671 *num_clusters = res.sr_bits;
47672 }
47673 }
47674 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47675 index 56f6102..1433c29 100644
47676 --- a/fs/ocfs2/super.c
47677 +++ b/fs/ocfs2/super.c
47678 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47679 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47680 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47681 "Stats",
47682 - atomic_read(&osb->alloc_stats.bitmap_data),
47683 - atomic_read(&osb->alloc_stats.local_data),
47684 - atomic_read(&osb->alloc_stats.bg_allocs),
47685 - atomic_read(&osb->alloc_stats.moves),
47686 - atomic_read(&osb->alloc_stats.bg_extends));
47687 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47688 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47689 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47690 + atomic_read_unchecked(&osb->alloc_stats.moves),
47691 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47692
47693 out += snprintf(buf + out, len - out,
47694 "%10s => State: %u Descriptor: %llu Size: %u bits "
47695 @@ -2112,11 +2112,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47696 spin_lock_init(&osb->osb_xattr_lock);
47697 ocfs2_init_steal_slots(osb);
47698
47699 - atomic_set(&osb->alloc_stats.moves, 0);
47700 - atomic_set(&osb->alloc_stats.local_data, 0);
47701 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47702 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47703 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47704 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47705 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47706 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47707 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47708 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47709
47710 /* Copy the blockcheck stats from the superblock probe */
47711 osb->osb_ecc_stats = *stats;
47712 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47713 index 5d22872..523db20 100644
47714 --- a/fs/ocfs2/symlink.c
47715 +++ b/fs/ocfs2/symlink.c
47716 @@ -142,7 +142,7 @@ bail:
47717
47718 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47719 {
47720 - char *link = nd_get_link(nd);
47721 + const char *link = nd_get_link(nd);
47722 if (!IS_ERR(link))
47723 kfree(link);
47724 }
47725 diff --git a/fs/open.c b/fs/open.c
47726 index f711921..28d5958 100644
47727 --- a/fs/open.c
47728 +++ b/fs/open.c
47729 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47730 error = locks_verify_truncate(inode, NULL, length);
47731 if (!error)
47732 error = security_path_truncate(&path);
47733 +
47734 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47735 + error = -EACCES;
47736 +
47737 if (!error)
47738 error = do_truncate(path.dentry, length, 0, NULL);
47739
47740 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47741 if (__mnt_is_readonly(path.mnt))
47742 res = -EROFS;
47743
47744 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47745 + res = -EACCES;
47746 +
47747 out_path_release:
47748 path_put(&path);
47749 out:
47750 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47751 if (error)
47752 goto dput_and_out;
47753
47754 + gr_log_chdir(path.dentry, path.mnt);
47755 +
47756 set_fs_pwd(current->fs, &path);
47757
47758 dput_and_out:
47759 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47760 goto out_putf;
47761
47762 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47763 +
47764 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47765 + error = -EPERM;
47766 +
47767 + if (!error)
47768 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47769 +
47770 if (!error)
47771 set_fs_pwd(current->fs, &file->f_path);
47772 out_putf:
47773 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47774 if (error)
47775 goto dput_and_out;
47776
47777 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47778 + goto dput_and_out;
47779 +
47780 set_fs_root(current->fs, &path);
47781 +
47782 + gr_handle_chroot_chdir(&path);
47783 +
47784 error = 0;
47785 dput_and_out:
47786 path_put(&path);
47787 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
47788 if (error)
47789 return error;
47790 mutex_lock(&inode->i_mutex);
47791 +
47792 + if (!gr_acl_handle_fchmod(path->dentry, path->mnt, mode)) {
47793 + error = -EACCES;
47794 + goto out_unlock;
47795 + }
47796 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47797 + error = -EACCES;
47798 + goto out_unlock;
47799 + }
47800 +
47801 error = security_path_chmod(path->dentry, path->mnt, mode);
47802 if (error)
47803 goto out_unlock;
47804 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47805 int error;
47806 struct iattr newattrs;
47807
47808 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47809 + return -EACCES;
47810 +
47811 newattrs.ia_valid = ATTR_CTIME;
47812 if (user != (uid_t) -1) {
47813 newattrs.ia_valid |= ATTR_UID;
47814 diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
47815 index 6296b40..417c00f 100644
47816 --- a/fs/partitions/efi.c
47817 +++ b/fs/partitions/efi.c
47818 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
47819 if (!gpt)
47820 return NULL;
47821
47822 + if (!le32_to_cpu(gpt->num_partition_entries))
47823 + return NULL;
47824 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
47825 + if (!pte)
47826 + return NULL;
47827 +
47828 count = le32_to_cpu(gpt->num_partition_entries) *
47829 le32_to_cpu(gpt->sizeof_partition_entry);
47830 - if (!count)
47831 - return NULL;
47832 - pte = kzalloc(count, GFP_KERNEL);
47833 - if (!pte)
47834 - return NULL;
47835 -
47836 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
47837 (u8 *) pte,
47838 count) < count) {
47839 diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
47840 index af9fdf0..75b15c3 100644
47841 --- a/fs/partitions/ldm.c
47842 +++ b/fs/partitions/ldm.c
47843 @@ -1322,7 +1322,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
47844 goto found;
47845 }
47846
47847 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
47848 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
47849 if (!f) {
47850 ldm_crit ("Out of memory.");
47851 return false;
47852 diff --git a/fs/pipe.c b/fs/pipe.c
47853 index 0e0be1d..f62a72d 100644
47854 --- a/fs/pipe.c
47855 +++ b/fs/pipe.c
47856 @@ -420,9 +420,9 @@ redo:
47857 }
47858 if (bufs) /* More to do? */
47859 continue;
47860 - if (!pipe->writers)
47861 + if (!atomic_read(&pipe->writers))
47862 break;
47863 - if (!pipe->waiting_writers) {
47864 + if (!atomic_read(&pipe->waiting_writers)) {
47865 /* syscall merging: Usually we must not sleep
47866 * if O_NONBLOCK is set, or if we got some data.
47867 * But if a writer sleeps in kernel space, then
47868 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47869 mutex_lock(&inode->i_mutex);
47870 pipe = inode->i_pipe;
47871
47872 - if (!pipe->readers) {
47873 + if (!atomic_read(&pipe->readers)) {
47874 send_sig(SIGPIPE, current, 0);
47875 ret = -EPIPE;
47876 goto out;
47877 @@ -530,7 +530,7 @@ redo1:
47878 for (;;) {
47879 int bufs;
47880
47881 - if (!pipe->readers) {
47882 + if (!atomic_read(&pipe->readers)) {
47883 send_sig(SIGPIPE, current, 0);
47884 if (!ret)
47885 ret = -EPIPE;
47886 @@ -616,9 +616,9 @@ redo2:
47887 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47888 do_wakeup = 0;
47889 }
47890 - pipe->waiting_writers++;
47891 + atomic_inc(&pipe->waiting_writers);
47892 pipe_wait(pipe);
47893 - pipe->waiting_writers--;
47894 + atomic_dec(&pipe->waiting_writers);
47895 }
47896 out:
47897 mutex_unlock(&inode->i_mutex);
47898 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47899 mask = 0;
47900 if (filp->f_mode & FMODE_READ) {
47901 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47902 - if (!pipe->writers && filp->f_version != pipe->w_counter)
47903 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47904 mask |= POLLHUP;
47905 }
47906
47907 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47908 * Most Unices do not set POLLERR for FIFOs but on Linux they
47909 * behave exactly like pipes for poll().
47910 */
47911 - if (!pipe->readers)
47912 + if (!atomic_read(&pipe->readers))
47913 mask |= POLLERR;
47914 }
47915
47916 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47917
47918 mutex_lock(&inode->i_mutex);
47919 pipe = inode->i_pipe;
47920 - pipe->readers -= decr;
47921 - pipe->writers -= decw;
47922 + atomic_sub(decr, &pipe->readers);
47923 + atomic_sub(decw, &pipe->writers);
47924
47925 - if (!pipe->readers && !pipe->writers) {
47926 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47927 free_pipe_info(inode);
47928 } else {
47929 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47930 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47931
47932 if (inode->i_pipe) {
47933 ret = 0;
47934 - inode->i_pipe->readers++;
47935 + atomic_inc(&inode->i_pipe->readers);
47936 }
47937
47938 mutex_unlock(&inode->i_mutex);
47939 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47940
47941 if (inode->i_pipe) {
47942 ret = 0;
47943 - inode->i_pipe->writers++;
47944 + atomic_inc(&inode->i_pipe->writers);
47945 }
47946
47947 mutex_unlock(&inode->i_mutex);
47948 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47949 if (inode->i_pipe) {
47950 ret = 0;
47951 if (filp->f_mode & FMODE_READ)
47952 - inode->i_pipe->readers++;
47953 + atomic_inc(&inode->i_pipe->readers);
47954 if (filp->f_mode & FMODE_WRITE)
47955 - inode->i_pipe->writers++;
47956 + atomic_inc(&inode->i_pipe->writers);
47957 }
47958
47959 mutex_unlock(&inode->i_mutex);
47960 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
47961 inode->i_pipe = NULL;
47962 }
47963
47964 -static struct vfsmount *pipe_mnt __read_mostly;
47965 +struct vfsmount *pipe_mnt __read_mostly;
47966
47967 /*
47968 * pipefs_dname() is called from d_path().
47969 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
47970 goto fail_iput;
47971 inode->i_pipe = pipe;
47972
47973 - pipe->readers = pipe->writers = 1;
47974 + atomic_set(&pipe->readers, 1);
47975 + atomic_set(&pipe->writers, 1);
47976 inode->i_fop = &rdwr_pipefifo_fops;
47977
47978 /*
47979 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47980 index 15af622..0e9f4467 100644
47981 --- a/fs/proc/Kconfig
47982 +++ b/fs/proc/Kconfig
47983 @@ -30,12 +30,12 @@ config PROC_FS
47984
47985 config PROC_KCORE
47986 bool "/proc/kcore support" if !ARM
47987 - depends on PROC_FS && MMU
47988 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47989
47990 config PROC_VMCORE
47991 bool "/proc/vmcore support"
47992 - depends on PROC_FS && CRASH_DUMP
47993 - default y
47994 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47995 + default n
47996 help
47997 Exports the dump image of crashed kernel in ELF format.
47998
47999 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48000 limited in memory.
48001
48002 config PROC_PAGE_MONITOR
48003 - default y
48004 - depends on PROC_FS && MMU
48005 + default n
48006 + depends on PROC_FS && MMU && !GRKERNSEC
48007 bool "Enable /proc page monitoring" if EXPERT
48008 help
48009 Various /proc files exist to monitor process memory utilization:
48010 diff --git a/fs/proc/array.c b/fs/proc/array.c
48011 index 3a1dafd..c7fed72 100644
48012 --- a/fs/proc/array.c
48013 +++ b/fs/proc/array.c
48014 @@ -60,6 +60,7 @@
48015 #include <linux/tty.h>
48016 #include <linux/string.h>
48017 #include <linux/mman.h>
48018 +#include <linux/grsecurity.h>
48019 #include <linux/proc_fs.h>
48020 #include <linux/ioport.h>
48021 #include <linux/uaccess.h>
48022 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48023 seq_putc(m, '\n');
48024 }
48025
48026 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48027 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48028 +{
48029 + if (p->mm)
48030 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48031 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48032 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48033 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48034 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48035 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48036 + else
48037 + seq_printf(m, "PaX:\t-----\n");
48038 +}
48039 +#endif
48040 +
48041 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48042 struct pid *pid, struct task_struct *task)
48043 {
48044 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48045 task_cpus_allowed(m, task);
48046 cpuset_task_status_allowed(m, task);
48047 task_context_switch_counts(m, task);
48048 +
48049 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48050 + task_pax(m, task);
48051 +#endif
48052 +
48053 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48054 + task_grsec_rbac(m, task);
48055 +#endif
48056 +
48057 return 0;
48058 }
48059
48060 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48061 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48062 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48063 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48064 +#endif
48065 +
48066 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48067 struct pid *pid, struct task_struct *task, int whole)
48068 {
48069 @@ -378,6 +409,8 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48070 char tcomm[sizeof(task->comm)];
48071 unsigned long flags;
48072
48073 + pax_track_stack();
48074 +
48075 state = *get_task_state(task);
48076 vsize = eip = esp = 0;
48077 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
48078 @@ -449,6 +482,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48079 gtime = task->gtime;
48080 }
48081
48082 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48083 + if (PAX_RAND_FLAGS(mm)) {
48084 + eip = 0;
48085 + esp = 0;
48086 + wchan = 0;
48087 + }
48088 +#endif
48089 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48090 + wchan = 0;
48091 + eip =0;
48092 + esp =0;
48093 +#endif
48094 +
48095 /* scale priority and nice values from timeslices to -20..20 */
48096 /* to make it look like a "normal" Unix priority/nice value */
48097 priority = task_prio(task);
48098 @@ -489,9 +535,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48099 vsize,
48100 mm ? get_mm_rss(mm) : 0,
48101 rsslim,
48102 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48103 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
48104 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
48105 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
48106 +#else
48107 mm ? (permitted ? mm->start_code : 1) : 0,
48108 mm ? (permitted ? mm->end_code : 1) : 0,
48109 (permitted && mm) ? mm->start_stack : 0,
48110 +#endif
48111 esp,
48112 eip,
48113 /* The signal information here is obsolete.
48114 @@ -544,3 +596,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48115
48116 return 0;
48117 }
48118 +
48119 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48120 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48121 +{
48122 + u32 curr_ip = 0;
48123 + unsigned long flags;
48124 +
48125 + if (lock_task_sighand(task, &flags)) {
48126 + curr_ip = task->signal->curr_ip;
48127 + unlock_task_sighand(task, &flags);
48128 + }
48129 +
48130 + return sprintf(buffer, "%pI4\n", &curr_ip);
48131 +}
48132 +#endif
48133 diff --git a/fs/proc/base.c b/fs/proc/base.c
48134 index 5eb0206..fe01db4 100644
48135 --- a/fs/proc/base.c
48136 +++ b/fs/proc/base.c
48137 @@ -107,6 +107,22 @@ struct pid_entry {
48138 union proc_op op;
48139 };
48140
48141 +struct getdents_callback {
48142 + struct linux_dirent __user * current_dir;
48143 + struct linux_dirent __user * previous;
48144 + struct file * file;
48145 + int count;
48146 + int error;
48147 +};
48148 +
48149 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
48150 + loff_t offset, u64 ino, unsigned int d_type)
48151 +{
48152 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
48153 + buf->error = -EINVAL;
48154 + return 0;
48155 +}
48156 +
48157 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48158 .name = (NAME), \
48159 .len = sizeof(NAME) - 1, \
48160 @@ -209,6 +225,9 @@ static struct mm_struct *__check_mem_permission(struct task_struct *task)
48161 if (task == current)
48162 return mm;
48163
48164 + if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
48165 + return ERR_PTR(-EPERM);
48166 +
48167 /*
48168 * If current is actively ptrace'ing, and would also be
48169 * permitted to freshly attach with ptrace now, permit it.
48170 @@ -282,6 +301,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48171 if (!mm->arg_end)
48172 goto out_mm; /* Shh! No looking before we're done */
48173
48174 + if (gr_acl_handle_procpidmem(task))
48175 + goto out_mm;
48176 +
48177 len = mm->arg_end - mm->arg_start;
48178
48179 if (len > PAGE_SIZE)
48180 @@ -309,12 +331,28 @@ out:
48181 return res;
48182 }
48183
48184 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48185 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48186 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48187 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48188 +#endif
48189 +
48190 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48191 {
48192 struct mm_struct *mm = mm_for_maps(task);
48193 int res = PTR_ERR(mm);
48194 if (mm && !IS_ERR(mm)) {
48195 unsigned int nwords = 0;
48196 +
48197 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48198 + /* allow if we're currently ptracing this task */
48199 + if (PAX_RAND_FLAGS(mm) &&
48200 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48201 + mmput(mm);
48202 + return 0;
48203 + }
48204 +#endif
48205 +
48206 do {
48207 nwords += 2;
48208 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48209 @@ -328,7 +366,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48210 }
48211
48212
48213 -#ifdef CONFIG_KALLSYMS
48214 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48215 /*
48216 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48217 * Returns the resolved symbol. If that fails, simply return the address.
48218 @@ -367,7 +405,7 @@ static void unlock_trace(struct task_struct *task)
48219 mutex_unlock(&task->signal->cred_guard_mutex);
48220 }
48221
48222 -#ifdef CONFIG_STACKTRACE
48223 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48224
48225 #define MAX_STACK_TRACE_DEPTH 64
48226
48227 @@ -558,7 +596,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48228 return count;
48229 }
48230
48231 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48232 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48233 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48234 {
48235 long nr;
48236 @@ -587,7 +625,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48237 /************************************************************************/
48238
48239 /* permission checks */
48240 -static int proc_fd_access_allowed(struct inode *inode)
48241 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48242 {
48243 struct task_struct *task;
48244 int allowed = 0;
48245 @@ -597,7 +635,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48246 */
48247 task = get_proc_task(inode);
48248 if (task) {
48249 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48250 + if (log)
48251 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
48252 + else
48253 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48254 put_task_struct(task);
48255 }
48256 return allowed;
48257 @@ -978,6 +1019,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48258 if (!task)
48259 goto out_no_task;
48260
48261 + if (gr_acl_handle_procpidmem(task))
48262 + goto out;
48263 +
48264 ret = -ENOMEM;
48265 page = (char *)__get_free_page(GFP_TEMPORARY);
48266 if (!page)
48267 @@ -1613,7 +1657,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48268 path_put(&nd->path);
48269
48270 /* Are we allowed to snoop on the tasks file descriptors? */
48271 - if (!proc_fd_access_allowed(inode))
48272 + if (!proc_fd_access_allowed(inode,0))
48273 goto out;
48274
48275 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
48276 @@ -1652,8 +1696,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48277 struct path path;
48278
48279 /* Are we allowed to snoop on the tasks file descriptors? */
48280 - if (!proc_fd_access_allowed(inode))
48281 - goto out;
48282 + /* logging this is needed for learning on chromium to work properly,
48283 + but we don't want to flood the logs from 'ps' which does a readlink
48284 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48285 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48286 + */
48287 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48288 + if (!proc_fd_access_allowed(inode,0))
48289 + goto out;
48290 + } else {
48291 + if (!proc_fd_access_allowed(inode,1))
48292 + goto out;
48293 + }
48294
48295 error = PROC_I(inode)->op.proc_get_link(inode, &path);
48296 if (error)
48297 @@ -1718,7 +1772,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48298 rcu_read_lock();
48299 cred = __task_cred(task);
48300 inode->i_uid = cred->euid;
48301 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48302 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48303 +#else
48304 inode->i_gid = cred->egid;
48305 +#endif
48306 rcu_read_unlock();
48307 }
48308 security_task_to_inode(task, inode);
48309 @@ -1736,6 +1794,9 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48310 struct inode *inode = dentry->d_inode;
48311 struct task_struct *task;
48312 const struct cred *cred;
48313 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48314 + const struct cred *tmpcred = current_cred();
48315 +#endif
48316
48317 generic_fillattr(inode, stat);
48318
48319 @@ -1743,13 +1804,41 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48320 stat->uid = 0;
48321 stat->gid = 0;
48322 task = pid_task(proc_pid(inode), PIDTYPE_PID);
48323 +
48324 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
48325 + rcu_read_unlock();
48326 + return -ENOENT;
48327 + }
48328 +
48329 if (task) {
48330 + cred = __task_cred(task);
48331 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48332 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48333 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48334 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48335 +#endif
48336 + ) {
48337 +#endif
48338 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48339 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48340 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48341 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48342 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48343 +#endif
48344 task_dumpable(task)) {
48345 - cred = __task_cred(task);
48346 stat->uid = cred->euid;
48347 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48348 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48349 +#else
48350 stat->gid = cred->egid;
48351 +#endif
48352 }
48353 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48354 + } else {
48355 + rcu_read_unlock();
48356 + return -ENOENT;
48357 + }
48358 +#endif
48359 }
48360 rcu_read_unlock();
48361 return 0;
48362 @@ -1786,11 +1875,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48363
48364 if (task) {
48365 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48366 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48367 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48368 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48369 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48370 +#endif
48371 task_dumpable(task)) {
48372 rcu_read_lock();
48373 cred = __task_cred(task);
48374 inode->i_uid = cred->euid;
48375 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48376 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48377 +#else
48378 inode->i_gid = cred->egid;
48379 +#endif
48380 rcu_read_unlock();
48381 } else {
48382 inode->i_uid = 0;
48383 @@ -1908,7 +2006,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48384 int fd = proc_fd(inode);
48385
48386 if (task) {
48387 - files = get_files_struct(task);
48388 + if (!gr_acl_handle_procpidmem(task))
48389 + files = get_files_struct(task);
48390 put_task_struct(task);
48391 }
48392 if (files) {
48393 @@ -2176,11 +2275,21 @@ static const struct file_operations proc_fd_operations = {
48394 */
48395 static int proc_fd_permission(struct inode *inode, int mask)
48396 {
48397 + struct task_struct *task;
48398 int rv = generic_permission(inode, mask);
48399 - if (rv == 0)
48400 - return 0;
48401 +
48402 if (task_pid(current) == proc_pid(inode))
48403 rv = 0;
48404 +
48405 + task = get_proc_task(inode);
48406 + if (task == NULL)
48407 + return rv;
48408 +
48409 + if (gr_acl_handle_procpidmem(task))
48410 + rv = -EACCES;
48411 +
48412 + put_task_struct(task);
48413 +
48414 return rv;
48415 }
48416
48417 @@ -2290,6 +2399,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48418 if (!task)
48419 goto out_no_task;
48420
48421 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48422 + goto out;
48423 +
48424 /*
48425 * Yes, it does not scale. And it should not. Don't add
48426 * new entries into /proc/<tgid>/ without very good reasons.
48427 @@ -2334,6 +2446,9 @@ static int proc_pident_readdir(struct file *filp,
48428 if (!task)
48429 goto out_no_task;
48430
48431 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48432 + goto out;
48433 +
48434 ret = 0;
48435 i = filp->f_pos;
48436 switch (i) {
48437 @@ -2604,7 +2719,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48438 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48439 void *cookie)
48440 {
48441 - char *s = nd_get_link(nd);
48442 + const char *s = nd_get_link(nd);
48443 if (!IS_ERR(s))
48444 __putname(s);
48445 }
48446 @@ -2802,7 +2917,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48447 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48448 #endif
48449 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48450 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48451 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48452 INF("syscall", S_IRUGO, proc_pid_syscall),
48453 #endif
48454 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48455 @@ -2827,10 +2942,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48456 #ifdef CONFIG_SECURITY
48457 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48458 #endif
48459 -#ifdef CONFIG_KALLSYMS
48460 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48461 INF("wchan", S_IRUGO, proc_pid_wchan),
48462 #endif
48463 -#ifdef CONFIG_STACKTRACE
48464 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48465 ONE("stack", S_IRUGO, proc_pid_stack),
48466 #endif
48467 #ifdef CONFIG_SCHEDSTATS
48468 @@ -2864,6 +2979,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48469 #ifdef CONFIG_HARDWALL
48470 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48471 #endif
48472 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48473 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48474 +#endif
48475 };
48476
48477 static int proc_tgid_base_readdir(struct file * filp,
48478 @@ -2989,7 +3107,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48479 if (!inode)
48480 goto out;
48481
48482 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48483 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48484 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48485 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48486 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48487 +#else
48488 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48489 +#endif
48490 inode->i_op = &proc_tgid_base_inode_operations;
48491 inode->i_fop = &proc_tgid_base_operations;
48492 inode->i_flags|=S_IMMUTABLE;
48493 @@ -3031,7 +3156,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48494 if (!task)
48495 goto out;
48496
48497 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48498 + goto out_put_task;
48499 +
48500 result = proc_pid_instantiate(dir, dentry, task, NULL);
48501 +out_put_task:
48502 put_task_struct(task);
48503 out:
48504 return result;
48505 @@ -3096,6 +3225,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
48506 {
48507 unsigned int nr;
48508 struct task_struct *reaper;
48509 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48510 + const struct cred *tmpcred = current_cred();
48511 + const struct cred *itercred;
48512 +#endif
48513 + filldir_t __filldir = filldir;
48514 struct tgid_iter iter;
48515 struct pid_namespace *ns;
48516
48517 @@ -3119,8 +3253,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
48518 for (iter = next_tgid(ns, iter);
48519 iter.task;
48520 iter.tgid += 1, iter = next_tgid(ns, iter)) {
48521 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48522 + rcu_read_lock();
48523 + itercred = __task_cred(iter.task);
48524 +#endif
48525 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
48526 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48527 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
48528 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48529 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48530 +#endif
48531 + )
48532 +#endif
48533 + )
48534 + __filldir = &gr_fake_filldir;
48535 + else
48536 + __filldir = filldir;
48537 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48538 + rcu_read_unlock();
48539 +#endif
48540 filp->f_pos = iter.tgid + TGID_OFFSET;
48541 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
48542 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
48543 put_task_struct(iter.task);
48544 goto out;
48545 }
48546 @@ -3148,7 +3301,7 @@ static const struct pid_entry tid_base_stuff[] = {
48547 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48548 #endif
48549 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48550 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48551 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48552 INF("syscall", S_IRUGO, proc_pid_syscall),
48553 #endif
48554 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48555 @@ -3172,10 +3325,10 @@ static const struct pid_entry tid_base_stuff[] = {
48556 #ifdef CONFIG_SECURITY
48557 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48558 #endif
48559 -#ifdef CONFIG_KALLSYMS
48560 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48561 INF("wchan", S_IRUGO, proc_pid_wchan),
48562 #endif
48563 -#ifdef CONFIG_STACKTRACE
48564 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48565 ONE("stack", S_IRUGO, proc_pid_stack),
48566 #endif
48567 #ifdef CONFIG_SCHEDSTATS
48568 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48569 index 82676e3..5f8518a 100644
48570 --- a/fs/proc/cmdline.c
48571 +++ b/fs/proc/cmdline.c
48572 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48573
48574 static int __init proc_cmdline_init(void)
48575 {
48576 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48577 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48578 +#else
48579 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48580 +#endif
48581 return 0;
48582 }
48583 module_init(proc_cmdline_init);
48584 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48585 index b143471..bb105e5 100644
48586 --- a/fs/proc/devices.c
48587 +++ b/fs/proc/devices.c
48588 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48589
48590 static int __init proc_devices_init(void)
48591 {
48592 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48593 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48594 +#else
48595 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48596 +#endif
48597 return 0;
48598 }
48599 module_init(proc_devices_init);
48600 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48601 index 7ed72d6..d5f061a 100644
48602 --- a/fs/proc/inode.c
48603 +++ b/fs/proc/inode.c
48604 @@ -18,12 +18,18 @@
48605 #include <linux/module.h>
48606 #include <linux/sysctl.h>
48607 #include <linux/slab.h>
48608 +#include <linux/grsecurity.h>
48609
48610 #include <asm/system.h>
48611 #include <asm/uaccess.h>
48612
48613 #include "internal.h"
48614
48615 +#ifdef CONFIG_PROC_SYSCTL
48616 +extern const struct inode_operations proc_sys_inode_operations;
48617 +extern const struct inode_operations proc_sys_dir_operations;
48618 +#endif
48619 +
48620 static void proc_evict_inode(struct inode *inode)
48621 {
48622 struct proc_dir_entry *de;
48623 @@ -49,6 +55,13 @@ static void proc_evict_inode(struct inode *inode)
48624 ns_ops = PROC_I(inode)->ns_ops;
48625 if (ns_ops && ns_ops->put)
48626 ns_ops->put(PROC_I(inode)->ns);
48627 +
48628 +#ifdef CONFIG_PROC_SYSCTL
48629 + if (inode->i_op == &proc_sys_inode_operations ||
48630 + inode->i_op == &proc_sys_dir_operations)
48631 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48632 +#endif
48633 +
48634 }
48635
48636 static struct kmem_cache * proc_inode_cachep;
48637 @@ -440,7 +453,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48638 if (de->mode) {
48639 inode->i_mode = de->mode;
48640 inode->i_uid = de->uid;
48641 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48642 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48643 +#else
48644 inode->i_gid = de->gid;
48645 +#endif
48646 }
48647 if (de->size)
48648 inode->i_size = de->size;
48649 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48650 index 7838e5c..ff92cbc 100644
48651 --- a/fs/proc/internal.h
48652 +++ b/fs/proc/internal.h
48653 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48654 struct pid *pid, struct task_struct *task);
48655 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48656 struct pid *pid, struct task_struct *task);
48657 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48658 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48659 +#endif
48660 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48661
48662 extern const struct file_operations proc_maps_operations;
48663 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48664 index d245cb2..7e645bd 100644
48665 --- a/fs/proc/kcore.c
48666 +++ b/fs/proc/kcore.c
48667 @@ -321,6 +321,8 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
48668 off_t offset = 0;
48669 struct kcore_list *m;
48670
48671 + pax_track_stack();
48672 +
48673 /* setup ELF header */
48674 elf = (struct elfhdr *) bufp;
48675 bufp += sizeof(struct elfhdr);
48676 @@ -478,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48677 * the addresses in the elf_phdr on our list.
48678 */
48679 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48680 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48681 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48682 + if (tsz > buflen)
48683 tsz = buflen;
48684 -
48685 +
48686 while (buflen) {
48687 struct kcore_list *m;
48688
48689 @@ -509,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48690 kfree(elf_buf);
48691 } else {
48692 if (kern_addr_valid(start)) {
48693 - unsigned long n;
48694 + char *elf_buf;
48695 + mm_segment_t oldfs;
48696
48697 - n = copy_to_user(buffer, (char *)start, tsz);
48698 - /*
48699 - * We cannot distingush between fault on source
48700 - * and fault on destination. When this happens
48701 - * we clear too and hope it will trigger the
48702 - * EFAULT again.
48703 - */
48704 - if (n) {
48705 - if (clear_user(buffer + tsz - n,
48706 - n))
48707 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48708 + if (!elf_buf)
48709 + return -ENOMEM;
48710 + oldfs = get_fs();
48711 + set_fs(KERNEL_DS);
48712 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48713 + set_fs(oldfs);
48714 + if (copy_to_user(buffer, elf_buf, tsz)) {
48715 + kfree(elf_buf);
48716 return -EFAULT;
48717 + }
48718 }
48719 + set_fs(oldfs);
48720 + kfree(elf_buf);
48721 } else {
48722 if (clear_user(buffer, tsz))
48723 return -EFAULT;
48724 @@ -542,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48725
48726 static int open_kcore(struct inode *inode, struct file *filp)
48727 {
48728 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48729 + return -EPERM;
48730 +#endif
48731 if (!capable(CAP_SYS_RAWIO))
48732 return -EPERM;
48733 if (kcore_need_update)
48734 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48735 index 80e4645..d2689e9 100644
48736 --- a/fs/proc/meminfo.c
48737 +++ b/fs/proc/meminfo.c
48738 @@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48739 unsigned long pages[NR_LRU_LISTS];
48740 int lru;
48741
48742 + pax_track_stack();
48743 +
48744 /*
48745 * display in kilobytes.
48746 */
48747 @@ -158,7 +160,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48748 vmi.used >> 10,
48749 vmi.largest_chunk >> 10
48750 #ifdef CONFIG_MEMORY_FAILURE
48751 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48752 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48753 #endif
48754 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48755 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48756 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48757 index b1822dd..df622cb 100644
48758 --- a/fs/proc/nommu.c
48759 +++ b/fs/proc/nommu.c
48760 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48761 if (len < 1)
48762 len = 1;
48763 seq_printf(m, "%*c", len, ' ');
48764 - seq_path(m, &file->f_path, "");
48765 + seq_path(m, &file->f_path, "\n\\");
48766 }
48767
48768 seq_putc(m, '\n');
48769 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48770 index f738024..876984a 100644
48771 --- a/fs/proc/proc_net.c
48772 +++ b/fs/proc/proc_net.c
48773 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48774 struct task_struct *task;
48775 struct nsproxy *ns;
48776 struct net *net = NULL;
48777 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48778 + const struct cred *cred = current_cred();
48779 +#endif
48780 +
48781 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48782 + if (cred->fsuid)
48783 + return net;
48784 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48785 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48786 + return net;
48787 +#endif
48788
48789 rcu_read_lock();
48790 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48791 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48792 index 1a77dbe..56ec911 100644
48793 --- a/fs/proc/proc_sysctl.c
48794 +++ b/fs/proc/proc_sysctl.c
48795 @@ -8,11 +8,13 @@
48796 #include <linux/namei.h>
48797 #include "internal.h"
48798
48799 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
48800 +
48801 static const struct dentry_operations proc_sys_dentry_operations;
48802 static const struct file_operations proc_sys_file_operations;
48803 -static const struct inode_operations proc_sys_inode_operations;
48804 +const struct inode_operations proc_sys_inode_operations;
48805 static const struct file_operations proc_sys_dir_file_operations;
48806 -static const struct inode_operations proc_sys_dir_operations;
48807 +const struct inode_operations proc_sys_dir_operations;
48808
48809 static struct inode *proc_sys_make_inode(struct super_block *sb,
48810 struct ctl_table_header *head, struct ctl_table *table)
48811 @@ -121,8 +123,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48812
48813 err = NULL;
48814 d_set_d_op(dentry, &proc_sys_dentry_operations);
48815 +
48816 + gr_handle_proc_create(dentry, inode);
48817 +
48818 d_add(dentry, inode);
48819
48820 + if (gr_handle_sysctl(p, MAY_EXEC))
48821 + err = ERR_PTR(-ENOENT);
48822 +
48823 out:
48824 sysctl_head_finish(head);
48825 return err;
48826 @@ -202,6 +210,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48827 return -ENOMEM;
48828 } else {
48829 d_set_d_op(child, &proc_sys_dentry_operations);
48830 +
48831 + gr_handle_proc_create(child, inode);
48832 +
48833 d_add(child, inode);
48834 }
48835 } else {
48836 @@ -230,6 +241,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48837 if (*pos < file->f_pos)
48838 continue;
48839
48840 + if (gr_handle_sysctl(table, 0))
48841 + continue;
48842 +
48843 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
48844 if (res)
48845 return res;
48846 @@ -355,6 +369,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48847 if (IS_ERR(head))
48848 return PTR_ERR(head);
48849
48850 + if (table && gr_handle_sysctl(table, MAY_EXEC))
48851 + return -ENOENT;
48852 +
48853 generic_fillattr(inode, stat);
48854 if (table)
48855 stat->mode = (stat->mode & S_IFMT) | table->mode;
48856 @@ -370,17 +387,18 @@ static const struct file_operations proc_sys_file_operations = {
48857 };
48858
48859 static const struct file_operations proc_sys_dir_file_operations = {
48860 + .read = generic_read_dir,
48861 .readdir = proc_sys_readdir,
48862 .llseek = generic_file_llseek,
48863 };
48864
48865 -static const struct inode_operations proc_sys_inode_operations = {
48866 +const struct inode_operations proc_sys_inode_operations = {
48867 .permission = proc_sys_permission,
48868 .setattr = proc_sys_setattr,
48869 .getattr = proc_sys_getattr,
48870 };
48871
48872 -static const struct inode_operations proc_sys_dir_operations = {
48873 +const struct inode_operations proc_sys_dir_operations = {
48874 .lookup = proc_sys_lookup,
48875 .permission = proc_sys_permission,
48876 .setattr = proc_sys_setattr,
48877 diff --git a/fs/proc/root.c b/fs/proc/root.c
48878 index 9a8a2b7..3018df6 100644
48879 --- a/fs/proc/root.c
48880 +++ b/fs/proc/root.c
48881 @@ -123,7 +123,15 @@ void __init proc_root_init(void)
48882 #ifdef CONFIG_PROC_DEVICETREE
48883 proc_device_tree_init();
48884 #endif
48885 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48886 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48887 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48888 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48889 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48890 +#endif
48891 +#else
48892 proc_mkdir("bus", NULL);
48893 +#endif
48894 proc_sys_init();
48895 }
48896
48897 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48898 index c7d4ee6..41c5564 100644
48899 --- a/fs/proc/task_mmu.c
48900 +++ b/fs/proc/task_mmu.c
48901 @@ -51,8 +51,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48902 "VmExe:\t%8lu kB\n"
48903 "VmLib:\t%8lu kB\n"
48904 "VmPTE:\t%8lu kB\n"
48905 - "VmSwap:\t%8lu kB\n",
48906 - hiwater_vm << (PAGE_SHIFT-10),
48907 + "VmSwap:\t%8lu kB\n"
48908 +
48909 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48910 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48911 +#endif
48912 +
48913 + ,hiwater_vm << (PAGE_SHIFT-10),
48914 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48915 mm->locked_vm << (PAGE_SHIFT-10),
48916 hiwater_rss << (PAGE_SHIFT-10),
48917 @@ -60,7 +65,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48918 data << (PAGE_SHIFT-10),
48919 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48920 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48921 - swap << (PAGE_SHIFT-10));
48922 + swap << (PAGE_SHIFT-10)
48923 +
48924 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48925 + , mm->context.user_cs_base, mm->context.user_cs_limit
48926 +#endif
48927 +
48928 + );
48929 }
48930
48931 unsigned long task_vsize(struct mm_struct *mm)
48932 @@ -207,6 +218,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
48933 return ret;
48934 }
48935
48936 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48937 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48938 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48939 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48940 +#endif
48941 +
48942 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48943 {
48944 struct mm_struct *mm = vma->vm_mm;
48945 @@ -225,13 +242,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48946 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48947 }
48948
48949 - /* We don't show the stack guard page in /proc/maps */
48950 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48951 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48952 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48953 +#else
48954 start = vma->vm_start;
48955 - if (stack_guard_page_start(vma, start))
48956 - start += PAGE_SIZE;
48957 end = vma->vm_end;
48958 - if (stack_guard_page_end(vma, end))
48959 - end -= PAGE_SIZE;
48960 +#endif
48961
48962 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48963 start,
48964 @@ -240,7 +257,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48965 flags & VM_WRITE ? 'w' : '-',
48966 flags & VM_EXEC ? 'x' : '-',
48967 flags & VM_MAYSHARE ? 's' : 'p',
48968 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48969 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48970 +#else
48971 pgoff,
48972 +#endif
48973 MAJOR(dev), MINOR(dev), ino, &len);
48974
48975 /*
48976 @@ -249,7 +270,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48977 */
48978 if (file) {
48979 pad_len_spaces(m, len);
48980 - seq_path(m, &file->f_path, "\n");
48981 + seq_path(m, &file->f_path, "\n\\");
48982 } else {
48983 const char *name = arch_vma_name(vma);
48984 if (!name) {
48985 @@ -257,8 +278,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48986 if (vma->vm_start <= mm->brk &&
48987 vma->vm_end >= mm->start_brk) {
48988 name = "[heap]";
48989 - } else if (vma->vm_start <= mm->start_stack &&
48990 - vma->vm_end >= mm->start_stack) {
48991 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48992 + (vma->vm_start <= mm->start_stack &&
48993 + vma->vm_end >= mm->start_stack)) {
48994 name = "[stack]";
48995 }
48996 } else {
48997 @@ -433,11 +455,16 @@ static int show_smap(struct seq_file *m, void *v)
48998 };
48999
49000 memset(&mss, 0, sizeof mss);
49001 - mss.vma = vma;
49002 - /* mmap_sem is held in m_start */
49003 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49004 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49005 -
49006 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49007 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49008 +#endif
49009 + mss.vma = vma;
49010 + /* mmap_sem is held in m_start */
49011 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49012 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49013 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49014 + }
49015 +#endif
49016 show_map_vma(m, vma);
49017
49018 seq_printf(m,
49019 @@ -455,7 +482,11 @@ static int show_smap(struct seq_file *m, void *v)
49020 "KernelPageSize: %8lu kB\n"
49021 "MMUPageSize: %8lu kB\n"
49022 "Locked: %8lu kB\n",
49023 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49024 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49025 +#else
49026 (vma->vm_end - vma->vm_start) >> 10,
49027 +#endif
49028 mss.resident >> 10,
49029 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49030 mss.shared_clean >> 10,
49031 @@ -1031,7 +1062,7 @@ static int show_numa_map(struct seq_file *m, void *v)
49032
49033 if (file) {
49034 seq_printf(m, " file=");
49035 - seq_path(m, &file->f_path, "\n\t= ");
49036 + seq_path(m, &file->f_path, "\n\t\\= ");
49037 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49038 seq_printf(m, " heap");
49039 } else if (vma->vm_start <= mm->start_stack &&
49040 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49041 index 980de54..2a4db5f 100644
49042 --- a/fs/proc/task_nommu.c
49043 +++ b/fs/proc/task_nommu.c
49044 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49045 else
49046 bytes += kobjsize(mm);
49047
49048 - if (current->fs && current->fs->users > 1)
49049 + if (current->fs && atomic_read(&current->fs->users) > 1)
49050 sbytes += kobjsize(current->fs);
49051 else
49052 bytes += kobjsize(current->fs);
49053 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
49054
49055 if (file) {
49056 pad_len_spaces(m, len);
49057 - seq_path(m, &file->f_path, "");
49058 + seq_path(m, &file->f_path, "\n\\");
49059 } else if (mm) {
49060 if (vma->vm_start <= mm->start_stack &&
49061 vma->vm_end >= mm->start_stack) {
49062 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49063 index d67908b..d13f6a6 100644
49064 --- a/fs/quota/netlink.c
49065 +++ b/fs/quota/netlink.c
49066 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49067 void quota_send_warning(short type, unsigned int id, dev_t dev,
49068 const char warntype)
49069 {
49070 - static atomic_t seq;
49071 + static atomic_unchecked_t seq;
49072 struct sk_buff *skb;
49073 void *msg_head;
49074 int ret;
49075 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49076 "VFS: Not enough memory to send quota warning.\n");
49077 return;
49078 }
49079 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49080 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49081 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49082 if (!msg_head) {
49083 printk(KERN_ERR
49084 diff --git a/fs/readdir.c b/fs/readdir.c
49085 index 356f715..c918d38 100644
49086 --- a/fs/readdir.c
49087 +++ b/fs/readdir.c
49088 @@ -17,6 +17,7 @@
49089 #include <linux/security.h>
49090 #include <linux/syscalls.h>
49091 #include <linux/unistd.h>
49092 +#include <linux/namei.h>
49093
49094 #include <asm/uaccess.h>
49095
49096 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49097
49098 struct readdir_callback {
49099 struct old_linux_dirent __user * dirent;
49100 + struct file * file;
49101 int result;
49102 };
49103
49104 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49105 buf->result = -EOVERFLOW;
49106 return -EOVERFLOW;
49107 }
49108 +
49109 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49110 + return 0;
49111 +
49112 buf->result++;
49113 dirent = buf->dirent;
49114 if (!access_ok(VERIFY_WRITE, dirent,
49115 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49116
49117 buf.result = 0;
49118 buf.dirent = dirent;
49119 + buf.file = file;
49120
49121 error = vfs_readdir(file, fillonedir, &buf);
49122 if (buf.result)
49123 @@ -142,6 +149,7 @@ struct linux_dirent {
49124 struct getdents_callback {
49125 struct linux_dirent __user * current_dir;
49126 struct linux_dirent __user * previous;
49127 + struct file * file;
49128 int count;
49129 int error;
49130 };
49131 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49132 buf->error = -EOVERFLOW;
49133 return -EOVERFLOW;
49134 }
49135 +
49136 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49137 + return 0;
49138 +
49139 dirent = buf->previous;
49140 if (dirent) {
49141 if (__put_user(offset, &dirent->d_off))
49142 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49143 buf.previous = NULL;
49144 buf.count = count;
49145 buf.error = 0;
49146 + buf.file = file;
49147
49148 error = vfs_readdir(file, filldir, &buf);
49149 if (error >= 0)
49150 @@ -229,6 +242,7 @@ out:
49151 struct getdents_callback64 {
49152 struct linux_dirent64 __user * current_dir;
49153 struct linux_dirent64 __user * previous;
49154 + struct file *file;
49155 int count;
49156 int error;
49157 };
49158 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49159 buf->error = -EINVAL; /* only used if we fail.. */
49160 if (reclen > buf->count)
49161 return -EINVAL;
49162 +
49163 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49164 + return 0;
49165 +
49166 dirent = buf->previous;
49167 if (dirent) {
49168 if (__put_user(offset, &dirent->d_off))
49169 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49170
49171 buf.current_dir = dirent;
49172 buf.previous = NULL;
49173 + buf.file = file;
49174 buf.count = count;
49175 buf.error = 0;
49176
49177 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49178 error = buf.error;
49179 lastdirent = buf.previous;
49180 if (lastdirent) {
49181 - typeof(lastdirent->d_off) d_off = file->f_pos;
49182 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49183 if (__put_user(d_off, &lastdirent->d_off))
49184 error = -EFAULT;
49185 else
49186 diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
49187 index 133e935..349ef18 100644
49188 --- a/fs/reiserfs/dir.c
49189 +++ b/fs/reiserfs/dir.c
49190 @@ -75,6 +75,8 @@ int reiserfs_readdir_dentry(struct dentry *dentry, void *dirent,
49191 struct reiserfs_dir_entry de;
49192 int ret = 0;
49193
49194 + pax_track_stack();
49195 +
49196 reiserfs_write_lock(inode->i_sb);
49197
49198 reiserfs_check_lock_depth(inode->i_sb, "readdir");
49199 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49200 index 60c0804..d814f98 100644
49201 --- a/fs/reiserfs/do_balan.c
49202 +++ b/fs/reiserfs/do_balan.c
49203 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49204 return;
49205 }
49206
49207 - atomic_inc(&(fs_generation(tb->tb_sb)));
49208 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49209 do_balance_starts(tb);
49210
49211 /* balance leaf returns 0 except if combining L R and S into
49212 diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
49213 index a159ba5..0396a76 100644
49214 --- a/fs/reiserfs/journal.c
49215 +++ b/fs/reiserfs/journal.c
49216 @@ -2289,6 +2289,8 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
49217 struct buffer_head *bh;
49218 int i, j;
49219
49220 + pax_track_stack();
49221 +
49222 bh = __getblk(dev, block, bufsize);
49223 if (buffer_uptodate(bh))
49224 return (bh);
49225 diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
49226 index ef39232..0fa91ba 100644
49227 --- a/fs/reiserfs/namei.c
49228 +++ b/fs/reiserfs/namei.c
49229 @@ -1225,6 +1225,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
49230 unsigned long savelink = 1;
49231 struct timespec ctime;
49232
49233 + pax_track_stack();
49234 +
49235 /* three balancings: (1) old name removal, (2) new name insertion
49236 and (3) maybe "save" link insertion
49237 stat data updates: (1) old directory,
49238 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49239 index 7a99811..2c9286f 100644
49240 --- a/fs/reiserfs/procfs.c
49241 +++ b/fs/reiserfs/procfs.c
49242 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49243 "SMALL_TAILS " : "NO_TAILS ",
49244 replay_only(sb) ? "REPLAY_ONLY " : "",
49245 convert_reiserfs(sb) ? "CONV " : "",
49246 - atomic_read(&r->s_generation_counter),
49247 + atomic_read_unchecked(&r->s_generation_counter),
49248 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49249 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49250 SF(s_good_search_by_key_reada), SF(s_bmaps),
49251 @@ -299,6 +299,8 @@ static int show_journal(struct seq_file *m, struct super_block *sb)
49252 struct journal_params *jp = &rs->s_v1.s_journal;
49253 char b[BDEVNAME_SIZE];
49254
49255 + pax_track_stack();
49256 +
49257 seq_printf(m, /* on-disk fields */
49258 "jp_journal_1st_block: \t%i\n"
49259 "jp_journal_dev: \t%s[%x]\n"
49260 diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
49261 index 313d39d..3a5811b 100644
49262 --- a/fs/reiserfs/stree.c
49263 +++ b/fs/reiserfs/stree.c
49264 @@ -1196,6 +1196,8 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
49265 int iter = 0;
49266 #endif
49267
49268 + pax_track_stack();
49269 +
49270 BUG_ON(!th->t_trans_id);
49271
49272 init_tb_struct(th, &s_del_balance, sb, path,
49273 @@ -1333,6 +1335,8 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
49274 int retval;
49275 int quota_cut_bytes = 0;
49276
49277 + pax_track_stack();
49278 +
49279 BUG_ON(!th->t_trans_id);
49280
49281 le_key2cpu_key(&cpu_key, key);
49282 @@ -1562,6 +1566,8 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
49283 int quota_cut_bytes;
49284 loff_t tail_pos = 0;
49285
49286 + pax_track_stack();
49287 +
49288 BUG_ON(!th->t_trans_id);
49289
49290 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
49291 @@ -1957,6 +1963,8 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
49292 int retval;
49293 int fs_gen;
49294
49295 + pax_track_stack();
49296 +
49297 BUG_ON(!th->t_trans_id);
49298
49299 fs_gen = get_generation(inode->i_sb);
49300 @@ -2045,6 +2053,8 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
49301 int fs_gen = 0;
49302 int quota_bytes = 0;
49303
49304 + pax_track_stack();
49305 +
49306 BUG_ON(!th->t_trans_id);
49307
49308 if (inode) { /* Do we count quotas for item? */
49309 diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
49310 index 14363b9..dd95a04 100644
49311 --- a/fs/reiserfs/super.c
49312 +++ b/fs/reiserfs/super.c
49313 @@ -927,6 +927,8 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
49314 {.option_name = NULL}
49315 };
49316
49317 + pax_track_stack();
49318 +
49319 *blocks = 0;
49320 if (!options || !*options)
49321 /* use default configuration: create tails, journaling on, no
49322 diff --git a/fs/select.c b/fs/select.c
49323 index d33418f..f8e06bc 100644
49324 --- a/fs/select.c
49325 +++ b/fs/select.c
49326 @@ -20,6 +20,7 @@
49327 #include <linux/module.h>
49328 #include <linux/slab.h>
49329 #include <linux/poll.h>
49330 +#include <linux/security.h>
49331 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49332 #include <linux/file.h>
49333 #include <linux/fdtable.h>
49334 @@ -403,6 +404,8 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
49335 int retval, i, timed_out = 0;
49336 unsigned long slack = 0;
49337
49338 + pax_track_stack();
49339 +
49340 rcu_read_lock();
49341 retval = max_select_fd(n, fds);
49342 rcu_read_unlock();
49343 @@ -528,6 +531,8 @@ int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
49344 /* Allocate small arguments on the stack to save memory and be faster */
49345 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
49346
49347 + pax_track_stack();
49348 +
49349 ret = -EINVAL;
49350 if (n < 0)
49351 goto out_nofds;
49352 @@ -837,6 +842,9 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49353 struct poll_list *walk = head;
49354 unsigned long todo = nfds;
49355
49356 + pax_track_stack();
49357 +
49358 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49359 if (nfds > rlimit(RLIMIT_NOFILE))
49360 return -EINVAL;
49361
49362 diff --git a/fs/seq_file.c b/fs/seq_file.c
49363 index dba43c3..a99fb63 100644
49364 --- a/fs/seq_file.c
49365 +++ b/fs/seq_file.c
49366 @@ -76,7 +76,8 @@ static int traverse(struct seq_file *m, loff_t offset)
49367 return 0;
49368 }
49369 if (!m->buf) {
49370 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49371 + m->size = PAGE_SIZE;
49372 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
49373 if (!m->buf)
49374 return -ENOMEM;
49375 }
49376 @@ -116,7 +117,8 @@ static int traverse(struct seq_file *m, loff_t offset)
49377 Eoverflow:
49378 m->op->stop(m, p);
49379 kfree(m->buf);
49380 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49381 + m->size <<= 1;
49382 + m->buf = kmalloc(m->size, GFP_KERNEL);
49383 return !m->buf ? -ENOMEM : -EAGAIN;
49384 }
49385
49386 @@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49387 m->version = file->f_version;
49388 /* grab buffer if we didn't have one */
49389 if (!m->buf) {
49390 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49391 + m->size = PAGE_SIZE;
49392 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
49393 if (!m->buf)
49394 goto Enomem;
49395 }
49396 @@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49397 goto Fill;
49398 m->op->stop(m, p);
49399 kfree(m->buf);
49400 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49401 + m->size <<= 1;
49402 + m->buf = kmalloc(m->size, GFP_KERNEL);
49403 if (!m->buf)
49404 goto Enomem;
49405 m->count = 0;
49406 @@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
49407 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49408 void *data)
49409 {
49410 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49411 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49412 int res = -ENOMEM;
49413
49414 if (op) {
49415 diff --git a/fs/splice.c b/fs/splice.c
49416 index fa2defa..9a697a5 100644
49417 --- a/fs/splice.c
49418 +++ b/fs/splice.c
49419 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49420 pipe_lock(pipe);
49421
49422 for (;;) {
49423 - if (!pipe->readers) {
49424 + if (!atomic_read(&pipe->readers)) {
49425 send_sig(SIGPIPE, current, 0);
49426 if (!ret)
49427 ret = -EPIPE;
49428 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49429 do_wakeup = 0;
49430 }
49431
49432 - pipe->waiting_writers++;
49433 + atomic_inc(&pipe->waiting_writers);
49434 pipe_wait(pipe);
49435 - pipe->waiting_writers--;
49436 + atomic_dec(&pipe->waiting_writers);
49437 }
49438
49439 pipe_unlock(pipe);
49440 @@ -320,6 +320,8 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
49441 .spd_release = spd_release_page,
49442 };
49443
49444 + pax_track_stack();
49445 +
49446 if (splice_grow_spd(pipe, &spd))
49447 return -ENOMEM;
49448
49449 @@ -560,7 +562,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49450 old_fs = get_fs();
49451 set_fs(get_ds());
49452 /* The cast to a user pointer is valid due to the set_fs() */
49453 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49454 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49455 set_fs(old_fs);
49456
49457 return res;
49458 @@ -575,7 +577,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49459 old_fs = get_fs();
49460 set_fs(get_ds());
49461 /* The cast to a user pointer is valid due to the set_fs() */
49462 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49463 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49464 set_fs(old_fs);
49465
49466 return res;
49467 @@ -603,6 +605,8 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49468 .spd_release = spd_release_page,
49469 };
49470
49471 + pax_track_stack();
49472 +
49473 if (splice_grow_spd(pipe, &spd))
49474 return -ENOMEM;
49475
49476 @@ -626,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49477 goto err;
49478
49479 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49480 - vec[i].iov_base = (void __user *) page_address(page);
49481 + vec[i].iov_base = (void __force_user *) page_address(page);
49482 vec[i].iov_len = this_len;
49483 spd.pages[i] = page;
49484 spd.nr_pages++;
49485 @@ -846,10 +850,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49486 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49487 {
49488 while (!pipe->nrbufs) {
49489 - if (!pipe->writers)
49490 + if (!atomic_read(&pipe->writers))
49491 return 0;
49492
49493 - if (!pipe->waiting_writers && sd->num_spliced)
49494 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49495 return 0;
49496
49497 if (sd->flags & SPLICE_F_NONBLOCK)
49498 @@ -1182,7 +1186,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49499 * out of the pipe right after the splice_to_pipe(). So set
49500 * PIPE_READERS appropriately.
49501 */
49502 - pipe->readers = 1;
49503 + atomic_set(&pipe->readers, 1);
49504
49505 current->splice_pipe = pipe;
49506 }
49507 @@ -1619,6 +1623,8 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,
49508 };
49509 long ret;
49510
49511 + pax_track_stack();
49512 +
49513 pipe = get_pipe_info(file);
49514 if (!pipe)
49515 return -EBADF;
49516 @@ -1734,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49517 ret = -ERESTARTSYS;
49518 break;
49519 }
49520 - if (!pipe->writers)
49521 + if (!atomic_read(&pipe->writers))
49522 break;
49523 - if (!pipe->waiting_writers) {
49524 + if (!atomic_read(&pipe->waiting_writers)) {
49525 if (flags & SPLICE_F_NONBLOCK) {
49526 ret = -EAGAIN;
49527 break;
49528 @@ -1768,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49529 pipe_lock(pipe);
49530
49531 while (pipe->nrbufs >= pipe->buffers) {
49532 - if (!pipe->readers) {
49533 + if (!atomic_read(&pipe->readers)) {
49534 send_sig(SIGPIPE, current, 0);
49535 ret = -EPIPE;
49536 break;
49537 @@ -1781,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49538 ret = -ERESTARTSYS;
49539 break;
49540 }
49541 - pipe->waiting_writers++;
49542 + atomic_inc(&pipe->waiting_writers);
49543 pipe_wait(pipe);
49544 - pipe->waiting_writers--;
49545 + atomic_dec(&pipe->waiting_writers);
49546 }
49547
49548 pipe_unlock(pipe);
49549 @@ -1819,14 +1825,14 @@ retry:
49550 pipe_double_lock(ipipe, opipe);
49551
49552 do {
49553 - if (!opipe->readers) {
49554 + if (!atomic_read(&opipe->readers)) {
49555 send_sig(SIGPIPE, current, 0);
49556 if (!ret)
49557 ret = -EPIPE;
49558 break;
49559 }
49560
49561 - if (!ipipe->nrbufs && !ipipe->writers)
49562 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49563 break;
49564
49565 /*
49566 @@ -1923,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49567 pipe_double_lock(ipipe, opipe);
49568
49569 do {
49570 - if (!opipe->readers) {
49571 + if (!atomic_read(&opipe->readers)) {
49572 send_sig(SIGPIPE, current, 0);
49573 if (!ret)
49574 ret = -EPIPE;
49575 @@ -1968,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49576 * return EAGAIN if we have the potential of some data in the
49577 * future, otherwise just return 0
49578 */
49579 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49580 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49581 ret = -EAGAIN;
49582
49583 pipe_unlock(ipipe);
49584 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49585 index 1ad8c93..6633545 100644
49586 --- a/fs/sysfs/file.c
49587 +++ b/fs/sysfs/file.c
49588 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49589
49590 struct sysfs_open_dirent {
49591 atomic_t refcnt;
49592 - atomic_t event;
49593 + atomic_unchecked_t event;
49594 wait_queue_head_t poll;
49595 struct list_head buffers; /* goes through sysfs_buffer.list */
49596 };
49597 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49598 if (!sysfs_get_active(attr_sd))
49599 return -ENODEV;
49600
49601 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49602 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49603 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49604
49605 sysfs_put_active(attr_sd);
49606 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49607 return -ENOMEM;
49608
49609 atomic_set(&new_od->refcnt, 0);
49610 - atomic_set(&new_od->event, 1);
49611 + atomic_set_unchecked(&new_od->event, 1);
49612 init_waitqueue_head(&new_od->poll);
49613 INIT_LIST_HEAD(&new_od->buffers);
49614 goto retry;
49615 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49616
49617 sysfs_put_active(attr_sd);
49618
49619 - if (buffer->event != atomic_read(&od->event))
49620 + if (buffer->event != atomic_read_unchecked(&od->event))
49621 goto trigger;
49622
49623 return DEFAULT_POLLMASK;
49624 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49625
49626 od = sd->s_attr.open;
49627 if (od) {
49628 - atomic_inc(&od->event);
49629 + atomic_inc_unchecked(&od->event);
49630 wake_up_interruptible(&od->poll);
49631 }
49632
49633 diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
49634 index e34f0d9..740ea7b 100644
49635 --- a/fs/sysfs/mount.c
49636 +++ b/fs/sysfs/mount.c
49637 @@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
49638 .s_name = "",
49639 .s_count = ATOMIC_INIT(1),
49640 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT),
49641 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49642 + .s_mode = S_IFDIR | S_IRWXU,
49643 +#else
49644 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
49645 +#endif
49646 .s_ino = 1,
49647 };
49648
49649 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49650 index a7ac78f..02158e1 100644
49651 --- a/fs/sysfs/symlink.c
49652 +++ b/fs/sysfs/symlink.c
49653 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49654
49655 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49656 {
49657 - char *page = nd_get_link(nd);
49658 + const char *page = nd_get_link(nd);
49659 if (!IS_ERR(page))
49660 free_page((unsigned long)page);
49661 }
49662 diff --git a/fs/udf/inode.c b/fs/udf/inode.c
49663 index 1d1358e..408bedb 100644
49664 --- a/fs/udf/inode.c
49665 +++ b/fs/udf/inode.c
49666 @@ -560,6 +560,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
49667 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
49668 int lastblock = 0;
49669
49670 + pax_track_stack();
49671 +
49672 prev_epos.offset = udf_file_entry_alloc_offset(inode);
49673 prev_epos.block = iinfo->i_location;
49674 prev_epos.bh = NULL;
49675 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49676 index 9215700..bf1f68e 100644
49677 --- a/fs/udf/misc.c
49678 +++ b/fs/udf/misc.c
49679 @@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49680
49681 u8 udf_tag_checksum(const struct tag *t)
49682 {
49683 - u8 *data = (u8 *)t;
49684 + const u8 *data = (const u8 *)t;
49685 u8 checksum = 0;
49686 int i;
49687 for (i = 0; i < sizeof(struct tag); ++i)
49688 diff --git a/fs/utimes.c b/fs/utimes.c
49689 index ba653f3..06ea4b1 100644
49690 --- a/fs/utimes.c
49691 +++ b/fs/utimes.c
49692 @@ -1,6 +1,7 @@
49693 #include <linux/compiler.h>
49694 #include <linux/file.h>
49695 #include <linux/fs.h>
49696 +#include <linux/security.h>
49697 #include <linux/linkage.h>
49698 #include <linux/mount.h>
49699 #include <linux/namei.h>
49700 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49701 goto mnt_drop_write_and_out;
49702 }
49703 }
49704 +
49705 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49706 + error = -EACCES;
49707 + goto mnt_drop_write_and_out;
49708 + }
49709 +
49710 mutex_lock(&inode->i_mutex);
49711 error = notify_change(path->dentry, &newattrs);
49712 mutex_unlock(&inode->i_mutex);
49713 diff --git a/fs/xattr.c b/fs/xattr.c
49714 index f060663..def7007 100644
49715 --- a/fs/xattr.c
49716 +++ b/fs/xattr.c
49717 @@ -254,7 +254,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49718 * Extended attribute SET operations
49719 */
49720 static long
49721 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49722 +setxattr(struct path *path, const char __user *name, const void __user *value,
49723 size_t size, int flags)
49724 {
49725 int error;
49726 @@ -278,7 +278,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49727 return PTR_ERR(kvalue);
49728 }
49729
49730 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49731 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49732 + error = -EACCES;
49733 + goto out;
49734 + }
49735 +
49736 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49737 +out:
49738 kfree(kvalue);
49739 return error;
49740 }
49741 @@ -295,7 +301,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49742 return error;
49743 error = mnt_want_write(path.mnt);
49744 if (!error) {
49745 - error = setxattr(path.dentry, name, value, size, flags);
49746 + error = setxattr(&path, name, value, size, flags);
49747 mnt_drop_write(path.mnt);
49748 }
49749 path_put(&path);
49750 @@ -314,7 +320,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49751 return error;
49752 error = mnt_want_write(path.mnt);
49753 if (!error) {
49754 - error = setxattr(path.dentry, name, value, size, flags);
49755 + error = setxattr(&path, name, value, size, flags);
49756 mnt_drop_write(path.mnt);
49757 }
49758 path_put(&path);
49759 @@ -325,17 +331,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49760 const void __user *,value, size_t, size, int, flags)
49761 {
49762 struct file *f;
49763 - struct dentry *dentry;
49764 int error = -EBADF;
49765
49766 f = fget(fd);
49767 if (!f)
49768 return error;
49769 - dentry = f->f_path.dentry;
49770 - audit_inode(NULL, dentry);
49771 + audit_inode(NULL, f->f_path.dentry);
49772 error = mnt_want_write_file(f);
49773 if (!error) {
49774 - error = setxattr(dentry, name, value, size, flags);
49775 + error = setxattr(&f->f_path, name, value, size, flags);
49776 mnt_drop_write(f->f_path.mnt);
49777 }
49778 fput(f);
49779 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49780 index 8d5a506..7f62712 100644
49781 --- a/fs/xattr_acl.c
49782 +++ b/fs/xattr_acl.c
49783 @@ -17,8 +17,8 @@
49784 struct posix_acl *
49785 posix_acl_from_xattr(const void *value, size_t size)
49786 {
49787 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49788 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49789 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49790 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49791 int count;
49792 struct posix_acl *acl;
49793 struct posix_acl_entry *acl_e;
49794 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49795 index 452a291..91a95f3b 100644
49796 --- a/fs/xfs/xfs_bmap.c
49797 +++ b/fs/xfs/xfs_bmap.c
49798 @@ -250,7 +250,7 @@ xfs_bmap_validate_ret(
49799 int nmap,
49800 int ret_nmap);
49801 #else
49802 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49803 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49804 #endif /* DEBUG */
49805
49806 STATIC int
49807 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49808 index 79d05e8..e3e5861 100644
49809 --- a/fs/xfs/xfs_dir2_sf.c
49810 +++ b/fs/xfs/xfs_dir2_sf.c
49811 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49812 }
49813
49814 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49815 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49816 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49817 + char name[sfep->namelen];
49818 + memcpy(name, sfep->name, sfep->namelen);
49819 + if (filldir(dirent, name, sfep->namelen,
49820 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49821 + *offset = off & 0x7fffffff;
49822 + return 0;
49823 + }
49824 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49825 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49826 *offset = off & 0x7fffffff;
49827 return 0;
49828 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49829 index f7ce7de..e1a5db0 100644
49830 --- a/fs/xfs/xfs_ioctl.c
49831 +++ b/fs/xfs/xfs_ioctl.c
49832 @@ -128,7 +128,7 @@ xfs_find_handle(
49833 }
49834
49835 error = -EFAULT;
49836 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49837 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49838 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49839 goto out_put;
49840
49841 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49842 index 474920b..97169a9 100644
49843 --- a/fs/xfs/xfs_iops.c
49844 +++ b/fs/xfs/xfs_iops.c
49845 @@ -446,7 +446,7 @@ xfs_vn_put_link(
49846 struct nameidata *nd,
49847 void *p)
49848 {
49849 - char *s = nd_get_link(nd);
49850 + const char *s = nd_get_link(nd);
49851
49852 if (!IS_ERR(s))
49853 kfree(s);
49854 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49855 new file mode 100644
49856 index 0000000..4639511
49857 --- /dev/null
49858 +++ b/grsecurity/Kconfig
49859 @@ -0,0 +1,1051 @@
49860 +#
49861 +# grecurity configuration
49862 +#
49863 +
49864 +menu "Grsecurity"
49865 +
49866 +config GRKERNSEC
49867 + bool "Grsecurity"
49868 + select CRYPTO
49869 + select CRYPTO_SHA256
49870 + help
49871 + If you say Y here, you will be able to configure many features
49872 + that will enhance the security of your system. It is highly
49873 + recommended that you say Y here and read through the help
49874 + for each option so that you fully understand the features and
49875 + can evaluate their usefulness for your machine.
49876 +
49877 +choice
49878 + prompt "Security Level"
49879 + depends on GRKERNSEC
49880 + default GRKERNSEC_CUSTOM
49881 +
49882 +config GRKERNSEC_LOW
49883 + bool "Low"
49884 + select GRKERNSEC_LINK
49885 + select GRKERNSEC_FIFO
49886 + select GRKERNSEC_RANDNET
49887 + select GRKERNSEC_DMESG
49888 + select GRKERNSEC_CHROOT
49889 + select GRKERNSEC_CHROOT_CHDIR
49890 +
49891 + help
49892 + If you choose this option, several of the grsecurity options will
49893 + be enabled that will give you greater protection against a number
49894 + of attacks, while assuring that none of your software will have any
49895 + conflicts with the additional security measures. If you run a lot
49896 + of unusual software, or you are having problems with the higher
49897 + security levels, you should say Y here. With this option, the
49898 + following features are enabled:
49899 +
49900 + - Linking restrictions
49901 + - FIFO restrictions
49902 + - Restricted dmesg
49903 + - Enforced chdir("/") on chroot
49904 + - Runtime module disabling
49905 +
49906 +config GRKERNSEC_MEDIUM
49907 + bool "Medium"
49908 + select PAX
49909 + select PAX_EI_PAX
49910 + select PAX_PT_PAX_FLAGS
49911 + select PAX_HAVE_ACL_FLAGS
49912 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49913 + select GRKERNSEC_CHROOT
49914 + select GRKERNSEC_CHROOT_SYSCTL
49915 + select GRKERNSEC_LINK
49916 + select GRKERNSEC_FIFO
49917 + select GRKERNSEC_DMESG
49918 + select GRKERNSEC_RANDNET
49919 + select GRKERNSEC_FORKFAIL
49920 + select GRKERNSEC_TIME
49921 + select GRKERNSEC_SIGNAL
49922 + select GRKERNSEC_CHROOT
49923 + select GRKERNSEC_CHROOT_UNIX
49924 + select GRKERNSEC_CHROOT_MOUNT
49925 + select GRKERNSEC_CHROOT_PIVOT
49926 + select GRKERNSEC_CHROOT_DOUBLE
49927 + select GRKERNSEC_CHROOT_CHDIR
49928 + select GRKERNSEC_CHROOT_MKNOD
49929 + select GRKERNSEC_PROC
49930 + select GRKERNSEC_PROC_USERGROUP
49931 + select PAX_RANDUSTACK
49932 + select PAX_ASLR
49933 + select PAX_RANDMMAP
49934 + select PAX_REFCOUNT if (X86 || SPARC64)
49935 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
49936 +
49937 + help
49938 + If you say Y here, several features in addition to those included
49939 + in the low additional security level will be enabled. These
49940 + features provide even more security to your system, though in rare
49941 + cases they may be incompatible with very old or poorly written
49942 + software. If you enable this option, make sure that your auth
49943 + service (identd) is running as gid 1001. With this option,
49944 + the following features (in addition to those provided in the
49945 + low additional security level) will be enabled:
49946 +
49947 + - Failed fork logging
49948 + - Time change logging
49949 + - Signal logging
49950 + - Deny mounts in chroot
49951 + - Deny double chrooting
49952 + - Deny sysctl writes in chroot
49953 + - Deny mknod in chroot
49954 + - Deny access to abstract AF_UNIX sockets out of chroot
49955 + - Deny pivot_root in chroot
49956 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
49957 + - /proc restrictions with special GID set to 10 (usually wheel)
49958 + - Address Space Layout Randomization (ASLR)
49959 + - Prevent exploitation of most refcount overflows
49960 + - Bounds checking of copying between the kernel and userland
49961 +
49962 +config GRKERNSEC_HIGH
49963 + bool "High"
49964 + select GRKERNSEC_LINK
49965 + select GRKERNSEC_FIFO
49966 + select GRKERNSEC_DMESG
49967 + select GRKERNSEC_FORKFAIL
49968 + select GRKERNSEC_TIME
49969 + select GRKERNSEC_SIGNAL
49970 + select GRKERNSEC_CHROOT
49971 + select GRKERNSEC_CHROOT_SHMAT
49972 + select GRKERNSEC_CHROOT_UNIX
49973 + select GRKERNSEC_CHROOT_MOUNT
49974 + select GRKERNSEC_CHROOT_FCHDIR
49975 + select GRKERNSEC_CHROOT_PIVOT
49976 + select GRKERNSEC_CHROOT_DOUBLE
49977 + select GRKERNSEC_CHROOT_CHDIR
49978 + select GRKERNSEC_CHROOT_MKNOD
49979 + select GRKERNSEC_CHROOT_CAPS
49980 + select GRKERNSEC_CHROOT_SYSCTL
49981 + select GRKERNSEC_CHROOT_FINDTASK
49982 + select GRKERNSEC_SYSFS_RESTRICT
49983 + select GRKERNSEC_PROC
49984 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49985 + select GRKERNSEC_HIDESYM
49986 + select GRKERNSEC_BRUTE
49987 + select GRKERNSEC_PROC_USERGROUP
49988 + select GRKERNSEC_KMEM
49989 + select GRKERNSEC_RESLOG
49990 + select GRKERNSEC_RANDNET
49991 + select GRKERNSEC_PROC_ADD
49992 + select GRKERNSEC_CHROOT_CHMOD
49993 + select GRKERNSEC_CHROOT_NICE
49994 + select GRKERNSEC_SETXID
49995 + select GRKERNSEC_AUDIT_MOUNT
49996 + select GRKERNSEC_MODHARDEN if (MODULES)
49997 + select GRKERNSEC_HARDEN_PTRACE
49998 + select GRKERNSEC_VM86 if (X86_32)
49999 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
50000 + select PAX
50001 + select PAX_RANDUSTACK
50002 + select PAX_ASLR
50003 + select PAX_RANDMMAP
50004 + select PAX_NOEXEC
50005 + select PAX_MPROTECT
50006 + select PAX_EI_PAX
50007 + select PAX_PT_PAX_FLAGS
50008 + select PAX_HAVE_ACL_FLAGS
50009 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
50010 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
50011 + select PAX_RANDKSTACK if (X86_TSC && X86)
50012 + select PAX_SEGMEXEC if (X86_32)
50013 + select PAX_PAGEEXEC
50014 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
50015 + select PAX_EMUTRAMP if (PARISC)
50016 + select PAX_EMUSIGRT if (PARISC)
50017 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
50018 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
50019 + select PAX_REFCOUNT if (X86 || SPARC64)
50020 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
50021 + help
50022 + If you say Y here, many of the features of grsecurity will be
50023 + enabled, which will protect you against many kinds of attacks
50024 + against your system. The heightened security comes at a cost
50025 + of an increased chance of incompatibilities with rare software
50026 + on your machine. Since this security level enables PaX, you should
50027 + view <http://pax.grsecurity.net> and read about the PaX
50028 + project. While you are there, download chpax and run it on
50029 + binaries that cause problems with PaX. Also remember that
50030 + since the /proc restrictions are enabled, you must run your
50031 + identd as gid 1001. This security level enables the following
50032 + features in addition to those listed in the low and medium
50033 + security levels:
50034 +
50035 + - Additional /proc restrictions
50036 + - Chmod restrictions in chroot
50037 + - No signals, ptrace, or viewing of processes outside of chroot
50038 + - Capability restrictions in chroot
50039 + - Deny fchdir out of chroot
50040 + - Priority restrictions in chroot
50041 + - Segmentation-based implementation of PaX
50042 + - Mprotect restrictions
50043 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
50044 + - Kernel stack randomization
50045 + - Mount/unmount/remount logging
50046 + - Kernel symbol hiding
50047 + - Hardening of module auto-loading
50048 + - Ptrace restrictions
50049 + - Restricted vm86 mode
50050 + - Restricted sysfs/debugfs
50051 + - Active kernel exploit response
50052 +
50053 +config GRKERNSEC_CUSTOM
50054 + bool "Custom"
50055 + help
50056 + If you say Y here, you will be able to configure every grsecurity
50057 + option, which allows you to enable many more features that aren't
50058 + covered in the basic security levels. These additional features
50059 + include TPE, socket restrictions, and the sysctl system for
50060 + grsecurity. It is advised that you read through the help for
50061 + each option to determine its usefulness in your situation.
50062 +
50063 +endchoice
50064 +
50065 +menu "Address Space Protection"
50066 +depends on GRKERNSEC
50067 +
50068 +config GRKERNSEC_KMEM
50069 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50070 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50071 + help
50072 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50073 + be written to or read from to modify or leak the contents of the running
50074 + kernel. /dev/port will also not be allowed to be opened. If you have module
50075 + support disabled, enabling this will close up four ways that are
50076 + currently used to insert malicious code into the running kernel.
50077 + Even with all these features enabled, we still highly recommend that
50078 + you use the RBAC system, as it is still possible for an attacker to
50079 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50080 + If you are not using XFree86, you may be able to stop this additional
50081 + case by enabling the 'Disable privileged I/O' option. Though nothing
50082 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50083 + but only to video memory, which is the only writing we allow in this
50084 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50085 + not be allowed to mprotect it with PROT_WRITE later.
50086 + It is highly recommended that you say Y here if you meet all the
50087 + conditions above.
50088 +
50089 +config GRKERNSEC_VM86
50090 + bool "Restrict VM86 mode"
50091 + depends on X86_32
50092 +
50093 + help
50094 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50095 + make use of a special execution mode on 32bit x86 processors called
50096 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50097 + video cards and will still work with this option enabled. The purpose
50098 + of the option is to prevent exploitation of emulation errors in
50099 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50100 + Nearly all users should be able to enable this option.
50101 +
50102 +config GRKERNSEC_IO
50103 + bool "Disable privileged I/O"
50104 + depends on X86
50105 + select RTC_CLASS
50106 + select RTC_INTF_DEV
50107 + select RTC_DRV_CMOS
50108 +
50109 + help
50110 + If you say Y here, all ioperm and iopl calls will return an error.
50111 + Ioperm and iopl can be used to modify the running kernel.
50112 + Unfortunately, some programs need this access to operate properly,
50113 + the most notable of which are XFree86 and hwclock. hwclock can be
50114 + remedied by having RTC support in the kernel, so real-time
50115 + clock support is enabled if this option is enabled, to ensure
50116 + that hwclock operates correctly. XFree86 still will not
50117 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50118 + IF YOU USE XFree86. If you use XFree86 and you still want to
50119 + protect your kernel against modification, use the RBAC system.
50120 +
50121 +config GRKERNSEC_PROC_MEMMAP
50122 + bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
50123 + default y if (PAX_NOEXEC || PAX_ASLR)
50124 + depends on PAX_NOEXEC || PAX_ASLR
50125 + help
50126 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50127 + give no information about the addresses of its mappings if
50128 + PaX features that rely on random addresses are enabled on the task.
50129 + If you use PaX it is greatly recommended that you say Y here as it
50130 + closes up a hole that makes the full ASLR useless for suid
50131 + binaries.
50132 +
50133 +config GRKERNSEC_BRUTE
50134 + bool "Deter exploit bruteforcing"
50135 + help
50136 + If you say Y here, attempts to bruteforce exploits against forking
50137 + daemons such as apache or sshd, as well as against suid/sgid binaries
50138 + will be deterred. When a child of a forking daemon is killed by PaX
50139 + or crashes due to an illegal instruction or other suspicious signal,
50140 + the parent process will be delayed 30 seconds upon every subsequent
50141 + fork until the administrator is able to assess the situation and
50142 + restart the daemon.
50143 + In the suid/sgid case, the attempt is logged, the user has all their
50144 + processes terminated, and they are prevented from executing any further
50145 + processes for 15 minutes.
50146 + It is recommended that you also enable signal logging in the auditing
50147 + section so that logs are generated when a process triggers a suspicious
50148 + signal.
50149 + If the sysctl option is enabled, a sysctl option with name
50150 + "deter_bruteforce" is created.
50151 +
50152 +
50153 +config GRKERNSEC_MODHARDEN
50154 + bool "Harden module auto-loading"
50155 + depends on MODULES
50156 + help
50157 + If you say Y here, module auto-loading in response to use of some
50158 + feature implemented by an unloaded module will be restricted to
50159 + root users. Enabling this option helps defend against attacks
50160 + by unprivileged users who abuse the auto-loading behavior to
50161 + cause a vulnerable module to load that is then exploited.
50162 +
50163 + If this option prevents a legitimate use of auto-loading for a
50164 + non-root user, the administrator can execute modprobe manually
50165 + with the exact name of the module mentioned in the alert log.
50166 + Alternatively, the administrator can add the module to the list
50167 + of modules loaded at boot by modifying init scripts.
50168 +
50169 + Modification of init scripts will most likely be needed on
50170 + Ubuntu servers with encrypted home directory support enabled,
50171 + as the first non-root user logging in will cause the ecb(aes),
50172 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50173 +
50174 +config GRKERNSEC_HIDESYM
50175 + bool "Hide kernel symbols"
50176 + help
50177 + If you say Y here, getting information on loaded modules, and
50178 + displaying all kernel symbols through a syscall will be restricted
50179 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50180 + /proc/kallsyms will be restricted to the root user. The RBAC
50181 + system can hide that entry even from root.
50182 +
50183 + This option also prevents leaking of kernel addresses through
50184 + several /proc entries.
50185 +
50186 + Note that this option is only effective provided the following
50187 + conditions are met:
50188 + 1) The kernel using grsecurity is not precompiled by some distribution
50189 + 2) You have also enabled GRKERNSEC_DMESG
50190 + 3) You are using the RBAC system and hiding other files such as your
50191 + kernel image and System.map. Alternatively, enabling this option
50192 + causes the permissions on /boot, /lib/modules, and the kernel
50193 + source directory to change at compile time to prevent
50194 + reading by non-root users.
50195 + If the above conditions are met, this option will aid in providing a
50196 + useful protection against local kernel exploitation of overflows
50197 + and arbitrary read/write vulnerabilities.
50198 +
50199 +config GRKERNSEC_KERN_LOCKOUT
50200 + bool "Active kernel exploit response"
50201 + depends on X86 || ARM || PPC || SPARC
50202 + help
50203 + If you say Y here, when a PaX alert is triggered due to suspicious
50204 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50205 + or an OOPs occurs due to bad memory accesses, instead of just
50206 + terminating the offending process (and potentially allowing
50207 + a subsequent exploit from the same user), we will take one of two
50208 + actions:
50209 + If the user was root, we will panic the system
50210 + If the user was non-root, we will log the attempt, terminate
50211 + all processes owned by the user, then prevent them from creating
50212 + any new processes until the system is restarted
50213 + This deters repeated kernel exploitation/bruteforcing attempts
50214 + and is useful for later forensics.
50215 +
50216 +endmenu
50217 +menu "Role Based Access Control Options"
50218 +depends on GRKERNSEC
50219 +
50220 +config GRKERNSEC_RBAC_DEBUG
50221 + bool
50222 +
50223 +config GRKERNSEC_NO_RBAC
50224 + bool "Disable RBAC system"
50225 + help
50226 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50227 + preventing the RBAC system from being enabled. You should only say Y
50228 + here if you have no intention of using the RBAC system, so as to prevent
50229 + an attacker with root access from misusing the RBAC system to hide files
50230 + and processes when loadable module support and /dev/[k]mem have been
50231 + locked down.
50232 +
50233 +config GRKERNSEC_ACL_HIDEKERN
50234 + bool "Hide kernel processes"
50235 + help
50236 + If you say Y here, all kernel threads will be hidden to all
50237 + processes but those whose subject has the "view hidden processes"
50238 + flag.
50239 +
50240 +config GRKERNSEC_ACL_MAXTRIES
50241 + int "Maximum tries before password lockout"
50242 + default 3
50243 + help
50244 + This option enforces the maximum number of times a user can attempt
50245 + to authorize themselves with the grsecurity RBAC system before being
50246 + denied the ability to attempt authorization again for a specified time.
50247 + The lower the number, the harder it will be to brute-force a password.
50248 +
50249 +config GRKERNSEC_ACL_TIMEOUT
50250 + int "Time to wait after max password tries, in seconds"
50251 + default 30
50252 + help
50253 + This option specifies the time the user must wait after attempting to
50254 + authorize to the RBAC system with the maximum number of invalid
50255 + passwords. The higher the number, the harder it will be to brute-force
50256 + a password.
50257 +
50258 +endmenu
50259 +menu "Filesystem Protections"
50260 +depends on GRKERNSEC
50261 +
50262 +config GRKERNSEC_PROC
50263 + bool "Proc restrictions"
50264 + help
50265 + If you say Y here, the permissions of the /proc filesystem
50266 + will be altered to enhance system security and privacy. You MUST
50267 + choose either a user only restriction or a user and group restriction.
50268 + Depending upon the option you choose, you can either restrict users to
50269 + see only the processes they themselves run, or choose a group that can
50270 + view all processes and files normally restricted to root if you choose
50271 + the "restrict to user only" option. NOTE: If you're running identd as
50272 + a non-root user, you will have to run it as the group you specify here.
50273 +
50274 +config GRKERNSEC_PROC_USER
50275 + bool "Restrict /proc to user only"
50276 + depends on GRKERNSEC_PROC
50277 + help
50278 + If you say Y here, non-root users will only be able to view their own
50279 + processes, and restricts them from viewing network-related information,
50280 + and viewing kernel symbol and module information.
50281 +
50282 +config GRKERNSEC_PROC_USERGROUP
50283 + bool "Allow special group"
50284 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50285 + help
50286 + If you say Y here, you will be able to select a group that will be
50287 + able to view all processes and network-related information. If you've
50288 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50289 + remain hidden. This option is useful if you want to run identd as
50290 + a non-root user.
50291 +
50292 +config GRKERNSEC_PROC_GID
50293 + int "GID for special group"
50294 + depends on GRKERNSEC_PROC_USERGROUP
50295 + default 1001
50296 +
50297 +config GRKERNSEC_PROC_ADD
50298 + bool "Additional restrictions"
50299 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50300 + help
50301 + If you say Y here, additional restrictions will be placed on
50302 + /proc that keep normal users from viewing device information and
50303 + slabinfo information that could be useful for exploits.
50304 +
50305 +config GRKERNSEC_LINK
50306 + bool "Linking restrictions"
50307 + help
50308 + If you say Y here, /tmp race exploits will be prevented, since users
50309 + will no longer be able to follow symlinks owned by other users in
50310 + world-writable +t directories (e.g. /tmp), unless the owner of the
50311 + symlink is the owner of the directory. users will also not be
50312 + able to hardlink to files they do not own. If the sysctl option is
50313 + enabled, a sysctl option with name "linking_restrictions" is created.
50314 +
50315 +config GRKERNSEC_FIFO
50316 + bool "FIFO restrictions"
50317 + help
50318 + If you say Y here, users will not be able to write to FIFOs they don't
50319 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50320 + the FIFO is the same owner of the directory it's held in. If the sysctl
50321 + option is enabled, a sysctl option with name "fifo_restrictions" is
50322 + created.
50323 +
50324 +config GRKERNSEC_SYSFS_RESTRICT
50325 + bool "Sysfs/debugfs restriction"
50326 + depends on SYSFS
50327 + help
50328 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50329 + any filesystem normally mounted under it (e.g. debugfs) will only
50330 + be accessible by root. These filesystems generally provide access
50331 + to hardware and debug information that isn't appropriate for unprivileged
50332 + users of the system. Sysfs and debugfs have also become a large source
50333 + of new vulnerabilities, ranging from infoleaks to local compromise.
50334 + There has been very little oversight with an eye toward security involved
50335 + in adding new exporters of information to these filesystems, so their
50336 + use is discouraged.
50337 + This option is equivalent to a chmod 0700 of the mount paths.
50338 +
50339 +config GRKERNSEC_ROFS
50340 + bool "Runtime read-only mount protection"
50341 + help
50342 + If you say Y here, a sysctl option with name "romount_protect" will
50343 + be created. By setting this option to 1 at runtime, filesystems
50344 + will be protected in the following ways:
50345 + * No new writable mounts will be allowed
50346 + * Existing read-only mounts won't be able to be remounted read/write
50347 + * Write operations will be denied on all block devices
50348 + This option acts independently of grsec_lock: once it is set to 1,
50349 + it cannot be turned off. Therefore, please be mindful of the resulting
50350 + behavior if this option is enabled in an init script on a read-only
50351 + filesystem. This feature is mainly intended for secure embedded systems.
50352 +
50353 +config GRKERNSEC_CHROOT
50354 + bool "Chroot jail restrictions"
50355 + help
50356 + If you say Y here, you will be able to choose several options that will
50357 + make breaking out of a chrooted jail much more difficult. If you
50358 + encounter no software incompatibilities with the following options, it
50359 + is recommended that you enable each one.
50360 +
50361 +config GRKERNSEC_CHROOT_MOUNT
50362 + bool "Deny mounts"
50363 + depends on GRKERNSEC_CHROOT
50364 + help
50365 + If you say Y here, processes inside a chroot will not be able to
50366 + mount or remount filesystems. If the sysctl option is enabled, a
50367 + sysctl option with name "chroot_deny_mount" is created.
50368 +
50369 +config GRKERNSEC_CHROOT_DOUBLE
50370 + bool "Deny double-chroots"
50371 + depends on GRKERNSEC_CHROOT
50372 + help
50373 + If you say Y here, processes inside a chroot will not be able to chroot
50374 + again outside the chroot. This is a widely used method of breaking
50375 + out of a chroot jail and should not be allowed. If the sysctl
50376 + option is enabled, a sysctl option with name
50377 + "chroot_deny_chroot" is created.
50378 +
50379 +config GRKERNSEC_CHROOT_PIVOT
50380 + bool "Deny pivot_root in chroot"
50381 + depends on GRKERNSEC_CHROOT
50382 + help
50383 + If you say Y here, processes inside a chroot will not be able to use
50384 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50385 + works similar to chroot in that it changes the root filesystem. This
50386 + function could be misused in a chrooted process to attempt to break out
50387 + of the chroot, and therefore should not be allowed. If the sysctl
50388 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50389 + created.
50390 +
50391 +config GRKERNSEC_CHROOT_CHDIR
50392 + bool "Enforce chdir(\"/\") on all chroots"
50393 + depends on GRKERNSEC_CHROOT
50394 + help
50395 + If you say Y here, the current working directory of all newly-chrooted
50396 + applications will be set to the the root directory of the chroot.
50397 + The man page on chroot(2) states:
50398 + Note that this call does not change the current working
50399 + directory, so that `.' can be outside the tree rooted at
50400 + `/'. In particular, the super-user can escape from a
50401 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50402 +
50403 + It is recommended that you say Y here, since it's not known to break
50404 + any software. If the sysctl option is enabled, a sysctl option with
50405 + name "chroot_enforce_chdir" is created.
50406 +
50407 +config GRKERNSEC_CHROOT_CHMOD
50408 + bool "Deny (f)chmod +s"
50409 + depends on GRKERNSEC_CHROOT
50410 + help
50411 + If you say Y here, processes inside a chroot will not be able to chmod
50412 + or fchmod files to make them have suid or sgid bits. This protects
50413 + against another published method of breaking a chroot. If the sysctl
50414 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50415 + created.
50416 +
50417 +config GRKERNSEC_CHROOT_FCHDIR
50418 + bool "Deny fchdir out of chroot"
50419 + depends on GRKERNSEC_CHROOT
50420 + help
50421 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50422 + to a file descriptor of the chrooting process that points to a directory
50423 + outside the filesystem will be stopped. If the sysctl option
50424 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50425 +
50426 +config GRKERNSEC_CHROOT_MKNOD
50427 + bool "Deny mknod"
50428 + depends on GRKERNSEC_CHROOT
50429 + help
50430 + If you say Y here, processes inside a chroot will not be allowed to
50431 + mknod. The problem with using mknod inside a chroot is that it
50432 + would allow an attacker to create a device entry that is the same
50433 + as one on the physical root of your system, which could range from
50434 + anything from the console device to a device for your harddrive (which
50435 + they could then use to wipe the drive or steal data). It is recommended
50436 + that you say Y here, unless you run into software incompatibilities.
50437 + If the sysctl option is enabled, a sysctl option with name
50438 + "chroot_deny_mknod" is created.
50439 +
50440 +config GRKERNSEC_CHROOT_SHMAT
50441 + bool "Deny shmat() out of chroot"
50442 + depends on GRKERNSEC_CHROOT
50443 + help
50444 + If you say Y here, processes inside a chroot will not be able to attach
50445 + to shared memory segments that were created outside of the chroot jail.
50446 + It is recommended that you say Y here. If the sysctl option is enabled,
50447 + a sysctl option with name "chroot_deny_shmat" is created.
50448 +
50449 +config GRKERNSEC_CHROOT_UNIX
50450 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50451 + depends on GRKERNSEC_CHROOT
50452 + help
50453 + If you say Y here, processes inside a chroot will not be able to
50454 + connect to abstract (meaning not belonging to a filesystem) Unix
50455 + domain sockets that were bound outside of a chroot. It is recommended
50456 + that you say Y here. If the sysctl option is enabled, a sysctl option
50457 + with name "chroot_deny_unix" is created.
50458 +
50459 +config GRKERNSEC_CHROOT_FINDTASK
50460 + bool "Protect outside processes"
50461 + depends on GRKERNSEC_CHROOT
50462 + help
50463 + If you say Y here, processes inside a chroot will not be able to
50464 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50465 + getsid, or view any process outside of the chroot. If the sysctl
50466 + option is enabled, a sysctl option with name "chroot_findtask" is
50467 + created.
50468 +
50469 +config GRKERNSEC_CHROOT_NICE
50470 + bool "Restrict priority changes"
50471 + depends on GRKERNSEC_CHROOT
50472 + help
50473 + If you say Y here, processes inside a chroot will not be able to raise
50474 + the priority of processes in the chroot, or alter the priority of
50475 + processes outside the chroot. This provides more security than simply
50476 + removing CAP_SYS_NICE from the process' capability set. If the
50477 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50478 + is created.
50479 +
50480 +config GRKERNSEC_CHROOT_SYSCTL
50481 + bool "Deny sysctl writes"
50482 + depends on GRKERNSEC_CHROOT
50483 + help
50484 + If you say Y here, an attacker in a chroot will not be able to
50485 + write to sysctl entries, either by sysctl(2) or through a /proc
50486 + interface. It is strongly recommended that you say Y here. If the
50487 + sysctl option is enabled, a sysctl option with name
50488 + "chroot_deny_sysctl" is created.
50489 +
50490 +config GRKERNSEC_CHROOT_CAPS
50491 + bool "Capability restrictions"
50492 + depends on GRKERNSEC_CHROOT
50493 + help
50494 + If you say Y here, the capabilities on all processes within a
50495 + chroot jail will be lowered to stop module insertion, raw i/o,
50496 + system and net admin tasks, rebooting the system, modifying immutable
50497 + files, modifying IPC owned by another, and changing the system time.
50498 + This is left an option because it can break some apps. Disable this
50499 + if your chrooted apps are having problems performing those kinds of
50500 + tasks. If the sysctl option is enabled, a sysctl option with
50501 + name "chroot_caps" is created.
50502 +
50503 +endmenu
50504 +menu "Kernel Auditing"
50505 +depends on GRKERNSEC
50506 +
50507 +config GRKERNSEC_AUDIT_GROUP
50508 + bool "Single group for auditing"
50509 + help
50510 + If you say Y here, the exec, chdir, and (un)mount logging features
50511 + will only operate on a group you specify. This option is recommended
50512 + if you only want to watch certain users instead of having a large
50513 + amount of logs from the entire system. If the sysctl option is enabled,
50514 + a sysctl option with name "audit_group" is created.
50515 +
50516 +config GRKERNSEC_AUDIT_GID
50517 + int "GID for auditing"
50518 + depends on GRKERNSEC_AUDIT_GROUP
50519 + default 1007
50520 +
50521 +config GRKERNSEC_EXECLOG
50522 + bool "Exec logging"
50523 + help
50524 + If you say Y here, all execve() calls will be logged (since the
50525 + other exec*() calls are frontends to execve(), all execution
50526 + will be logged). Useful for shell-servers that like to keep track
50527 + of their users. If the sysctl option is enabled, a sysctl option with
50528 + name "exec_logging" is created.
50529 + WARNING: This option when enabled will produce a LOT of logs, especially
50530 + on an active system.
50531 +
50532 +config GRKERNSEC_RESLOG
50533 + bool "Resource logging"
50534 + help
50535 + If you say Y here, all attempts to overstep resource limits will
50536 + be logged with the resource name, the requested size, and the current
50537 + limit. It is highly recommended that you say Y here. If the sysctl
50538 + option is enabled, a sysctl option with name "resource_logging" is
50539 + created. If the RBAC system is enabled, the sysctl value is ignored.
50540 +
50541 +config GRKERNSEC_CHROOT_EXECLOG
50542 + bool "Log execs within chroot"
50543 + help
50544 + If you say Y here, all executions inside a chroot jail will be logged
50545 + to syslog. This can cause a large amount of logs if certain
50546 + applications (eg. djb's daemontools) are installed on the system, and
50547 + is therefore left as an option. If the sysctl option is enabled, a
50548 + sysctl option with name "chroot_execlog" is created.
50549 +
50550 +config GRKERNSEC_AUDIT_PTRACE
50551 + bool "Ptrace logging"
50552 + help
50553 + If you say Y here, all attempts to attach to a process via ptrace
50554 + will be logged. If the sysctl option is enabled, a sysctl option
50555 + with name "audit_ptrace" is created.
50556 +
50557 +config GRKERNSEC_AUDIT_CHDIR
50558 + bool "Chdir logging"
50559 + help
50560 + If you say Y here, all chdir() calls will be logged. If the sysctl
50561 + option is enabled, a sysctl option with name "audit_chdir" is created.
50562 +
50563 +config GRKERNSEC_AUDIT_MOUNT
50564 + bool "(Un)Mount logging"
50565 + help
50566 + If you say Y here, all mounts and unmounts will be logged. If the
50567 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50568 + created.
50569 +
50570 +config GRKERNSEC_SIGNAL
50571 + bool "Signal logging"
50572 + help
50573 + If you say Y here, certain important signals will be logged, such as
50574 + SIGSEGV, which will as a result inform you of when a error in a program
50575 + occurred, which in some cases could mean a possible exploit attempt.
50576 + If the sysctl option is enabled, a sysctl option with name
50577 + "signal_logging" is created.
50578 +
50579 +config GRKERNSEC_FORKFAIL
50580 + bool "Fork failure logging"
50581 + help
50582 + If you say Y here, all failed fork() attempts will be logged.
50583 + This could suggest a fork bomb, or someone attempting to overstep
50584 + their process limit. If the sysctl option is enabled, a sysctl option
50585 + with name "forkfail_logging" is created.
50586 +
50587 +config GRKERNSEC_TIME
50588 + bool "Time change logging"
50589 + help
50590 + If you say Y here, any changes of the system clock will be logged.
50591 + If the sysctl option is enabled, a sysctl option with name
50592 + "timechange_logging" is created.
50593 +
50594 +config GRKERNSEC_PROC_IPADDR
50595 + bool "/proc/<pid>/ipaddr support"
50596 + help
50597 + If you say Y here, a new entry will be added to each /proc/<pid>
50598 + directory that contains the IP address of the person using the task.
50599 + The IP is carried across local TCP and AF_UNIX stream sockets.
50600 + This information can be useful for IDS/IPSes to perform remote response
50601 + to a local attack. The entry is readable by only the owner of the
50602 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50603 + the RBAC system), and thus does not create privacy concerns.
50604 +
50605 +config GRKERNSEC_RWXMAP_LOG
50606 + bool 'Denied RWX mmap/mprotect logging'
50607 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50608 + help
50609 + If you say Y here, calls to mmap() and mprotect() with explicit
50610 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50611 + denied by the PAX_MPROTECT feature. If the sysctl option is
50612 + enabled, a sysctl option with name "rwxmap_logging" is created.
50613 +
50614 +config GRKERNSEC_AUDIT_TEXTREL
50615 + bool 'ELF text relocations logging (READ HELP)'
50616 + depends on PAX_MPROTECT
50617 + help
50618 + If you say Y here, text relocations will be logged with the filename
50619 + of the offending library or binary. The purpose of the feature is
50620 + to help Linux distribution developers get rid of libraries and
50621 + binaries that need text relocations which hinder the future progress
50622 + of PaX. Only Linux distribution developers should say Y here, and
50623 + never on a production machine, as this option creates an information
50624 + leak that could aid an attacker in defeating the randomization of
50625 + a single memory region. If the sysctl option is enabled, a sysctl
50626 + option with name "audit_textrel" is created.
50627 +
50628 +endmenu
50629 +
50630 +menu "Executable Protections"
50631 +depends on GRKERNSEC
50632 +
50633 +config GRKERNSEC_DMESG
50634 + bool "Dmesg(8) restriction"
50635 + help
50636 + If you say Y here, non-root users will not be able to use dmesg(8)
50637 + to view up to the last 4kb of messages in the kernel's log buffer.
50638 + The kernel's log buffer often contains kernel addresses and other
50639 + identifying information useful to an attacker in fingerprinting a
50640 + system for a targeted exploit.
50641 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50642 + created.
50643 +
50644 +config GRKERNSEC_HARDEN_PTRACE
50645 + bool "Deter ptrace-based process snooping"
50646 + help
50647 + If you say Y here, TTY sniffers and other malicious monitoring
50648 + programs implemented through ptrace will be defeated. If you
50649 + have been using the RBAC system, this option has already been
50650 + enabled for several years for all users, with the ability to make
50651 + fine-grained exceptions.
50652 +
50653 + This option only affects the ability of non-root users to ptrace
50654 + processes that are not a descendent of the ptracing process.
50655 + This means that strace ./binary and gdb ./binary will still work,
50656 + but attaching to arbitrary processes will not. If the sysctl
50657 + option is enabled, a sysctl option with name "harden_ptrace" is
50658 + created.
50659 +
50660 +config GRKERNSEC_SETXID
50661 + bool "Enforce consistent multithreaded privileges"
50662 + help
50663 + If you say Y here, a change from a root uid to a non-root uid
50664 + in a multithreaded application will cause the resulting uids,
50665 + gids, supplementary groups, and capabilities in that thread
50666 + to be propagated to the other threads of the process. In most
50667 + cases this is unnecessary, as glibc will emulate this behavior
50668 + on behalf of the application. Other libcs do not act in the
50669 + same way, allowing the other threads of the process to continue
50670 + running with root privileges. If the sysctl option is enabled,
50671 + a sysctl option with name "consistent_setxid" is created.
50672 +
50673 +config GRKERNSEC_TPE
50674 + bool "Trusted Path Execution (TPE)"
50675 + help
50676 + If you say Y here, you will be able to choose a gid to add to the
50677 + supplementary groups of users you want to mark as "untrusted."
50678 + These users will not be able to execute any files that are not in
50679 + root-owned directories writable only by root. If the sysctl option
50680 + is enabled, a sysctl option with name "tpe" is created.
50681 +
50682 +config GRKERNSEC_TPE_ALL
50683 + bool "Partially restrict all non-root users"
50684 + depends on GRKERNSEC_TPE
50685 + help
50686 + If you say Y here, all non-root users will be covered under
50687 + a weaker TPE restriction. This is separate from, and in addition to,
50688 + the main TPE options that you have selected elsewhere. Thus, if a
50689 + "trusted" GID is chosen, this restriction applies to even that GID.
50690 + Under this restriction, all non-root users will only be allowed to
50691 + execute files in directories they own that are not group or
50692 + world-writable, or in directories owned by root and writable only by
50693 + root. If the sysctl option is enabled, a sysctl option with name
50694 + "tpe_restrict_all" is created.
50695 +
50696 +config GRKERNSEC_TPE_INVERT
50697 + bool "Invert GID option"
50698 + depends on GRKERNSEC_TPE
50699 + help
50700 + If you say Y here, the group you specify in the TPE configuration will
50701 + decide what group TPE restrictions will be *disabled* for. This
50702 + option is useful if you want TPE restrictions to be applied to most
50703 + users on the system. If the sysctl option is enabled, a sysctl option
50704 + with name "tpe_invert" is created. Unlike other sysctl options, this
50705 + entry will default to on for backward-compatibility.
50706 +
50707 +config GRKERNSEC_TPE_GID
50708 + int "GID for untrusted users"
50709 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50710 + default 1005
50711 + help
50712 + Setting this GID determines what group TPE restrictions will be
50713 + *enabled* for. If the sysctl option is enabled, a sysctl option
50714 + with name "tpe_gid" is created.
50715 +
50716 +config GRKERNSEC_TPE_GID
50717 + int "GID for trusted users"
50718 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50719 + default 1005
50720 + help
50721 + Setting this GID determines what group TPE restrictions will be
50722 + *disabled* for. If the sysctl option is enabled, a sysctl option
50723 + with name "tpe_gid" is created.
50724 +
50725 +endmenu
50726 +menu "Network Protections"
50727 +depends on GRKERNSEC
50728 +
50729 +config GRKERNSEC_RANDNET
50730 + bool "Larger entropy pools"
50731 + help
50732 + If you say Y here, the entropy pools used for many features of Linux
50733 + and grsecurity will be doubled in size. Since several grsecurity
50734 + features use additional randomness, it is recommended that you say Y
50735 + here. Saying Y here has a similar effect as modifying
50736 + /proc/sys/kernel/random/poolsize.
50737 +
50738 +config GRKERNSEC_BLACKHOLE
50739 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50740 + depends on NET
50741 + help
50742 + If you say Y here, neither TCP resets nor ICMP
50743 + destination-unreachable packets will be sent in response to packets
50744 + sent to ports for which no associated listening process exists.
50745 + This feature supports both IPV4 and IPV6 and exempts the
50746 + loopback interface from blackholing. Enabling this feature
50747 + makes a host more resilient to DoS attacks and reduces network
50748 + visibility against scanners.
50749 +
50750 + The blackhole feature as-implemented is equivalent to the FreeBSD
50751 + blackhole feature, as it prevents RST responses to all packets, not
50752 + just SYNs. Under most application behavior this causes no
50753 + problems, but applications (like haproxy) may not close certain
50754 + connections in a way that cleanly terminates them on the remote
50755 + end, leaving the remote host in LAST_ACK state. Because of this
50756 + side-effect and to prevent intentional LAST_ACK DoSes, this
50757 + feature also adds automatic mitigation against such attacks.
50758 + The mitigation drastically reduces the amount of time a socket
50759 + can spend in LAST_ACK state. If you're using haproxy and not
50760 + all servers it connects to have this option enabled, consider
50761 + disabling this feature on the haproxy host.
50762 +
50763 + If the sysctl option is enabled, two sysctl options with names
50764 + "ip_blackhole" and "lastack_retries" will be created.
50765 + While "ip_blackhole" takes the standard zero/non-zero on/off
50766 + toggle, "lastack_retries" uses the same kinds of values as
50767 + "tcp_retries1" and "tcp_retries2". The default value of 4
50768 + prevents a socket from lasting more than 45 seconds in LAST_ACK
50769 + state.
50770 +
50771 +config GRKERNSEC_SOCKET
50772 + bool "Socket restrictions"
50773 + depends on NET
50774 + help
50775 + If you say Y here, you will be able to choose from several options.
50776 + If you assign a GID on your system and add it to the supplementary
50777 + groups of users you want to restrict socket access to, this patch
50778 + will perform up to three things, based on the option(s) you choose.
50779 +
50780 +config GRKERNSEC_SOCKET_ALL
50781 + bool "Deny any sockets to group"
50782 + depends on GRKERNSEC_SOCKET
50783 + help
50784 + If you say Y here, you will be able to choose a GID of whose users will
50785 + be unable to connect to other hosts from your machine or run server
50786 + applications from your machine. If the sysctl option is enabled, a
50787 + sysctl option with name "socket_all" is created.
50788 +
50789 +config GRKERNSEC_SOCKET_ALL_GID
50790 + int "GID to deny all sockets for"
50791 + depends on GRKERNSEC_SOCKET_ALL
50792 + default 1004
50793 + help
50794 + Here you can choose the GID to disable socket access for. Remember to
50795 + add the users you want socket access disabled for to the GID
50796 + specified here. If the sysctl option is enabled, a sysctl option
50797 + with name "socket_all_gid" is created.
50798 +
50799 +config GRKERNSEC_SOCKET_CLIENT
50800 + bool "Deny client sockets to group"
50801 + depends on GRKERNSEC_SOCKET
50802 + help
50803 + If you say Y here, you will be able to choose a GID of whose users will
50804 + be unable to connect to other hosts from your machine, but will be
50805 + able to run servers. If this option is enabled, all users in the group
50806 + you specify will have to use passive mode when initiating ftp transfers
50807 + from the shell on your machine. If the sysctl option is enabled, a
50808 + sysctl option with name "socket_client" is created.
50809 +
50810 +config GRKERNSEC_SOCKET_CLIENT_GID
50811 + int "GID to deny client sockets for"
50812 + depends on GRKERNSEC_SOCKET_CLIENT
50813 + default 1003
50814 + help
50815 + Here you can choose the GID to disable client socket access for.
50816 + Remember to add the users you want client socket access disabled for to
50817 + the GID specified here. If the sysctl option is enabled, a sysctl
50818 + option with name "socket_client_gid" is created.
50819 +
50820 +config GRKERNSEC_SOCKET_SERVER
50821 + bool "Deny server sockets to group"
50822 + depends on GRKERNSEC_SOCKET
50823 + help
50824 + If you say Y here, you will be able to choose a GID of whose users will
50825 + be unable to run server applications from your machine. If the sysctl
50826 + option is enabled, a sysctl option with name "socket_server" is created.
50827 +
50828 +config GRKERNSEC_SOCKET_SERVER_GID
50829 + int "GID to deny server sockets for"
50830 + depends on GRKERNSEC_SOCKET_SERVER
50831 + default 1002
50832 + help
50833 + Here you can choose the GID to disable server socket access for.
50834 + Remember to add the users you want server socket access disabled for to
50835 + the GID specified here. If the sysctl option is enabled, a sysctl
50836 + option with name "socket_server_gid" is created.
50837 +
50838 +endmenu
50839 +menu "Sysctl support"
50840 +depends on GRKERNSEC && SYSCTL
50841 +
50842 +config GRKERNSEC_SYSCTL
50843 + bool "Sysctl support"
50844 + help
50845 + If you say Y here, you will be able to change the options that
50846 + grsecurity runs with at bootup, without having to recompile your
50847 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50848 + to enable (1) or disable (0) various features. All the sysctl entries
50849 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50850 + All features enabled in the kernel configuration are disabled at boot
50851 + if you do not say Y to the "Turn on features by default" option.
50852 + All options should be set at startup, and the grsec_lock entry should
50853 + be set to a non-zero value after all the options are set.
50854 + *THIS IS EXTREMELY IMPORTANT*
50855 +
50856 +config GRKERNSEC_SYSCTL_DISTRO
50857 + bool "Extra sysctl support for distro makers (READ HELP)"
50858 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50859 + help
50860 + If you say Y here, additional sysctl options will be created
50861 + for features that affect processes running as root. Therefore,
50862 + it is critical when using this option that the grsec_lock entry be
50863 + enabled after boot. Only distros with prebuilt kernel packages
50864 + with this option enabled that can ensure grsec_lock is enabled
50865 + after boot should use this option.
50866 + *Failure to set grsec_lock after boot makes all grsec features
50867 + this option covers useless*
50868 +
50869 + Currently this option creates the following sysctl entries:
50870 + "Disable Privileged I/O": "disable_priv_io"
50871 +
50872 +config GRKERNSEC_SYSCTL_ON
50873 + bool "Turn on features by default"
50874 + depends on GRKERNSEC_SYSCTL
50875 + help
50876 + If you say Y here, instead of having all features enabled in the
50877 + kernel configuration disabled at boot time, the features will be
50878 + enabled at boot time. It is recommended you say Y here unless
50879 + there is some reason you would want all sysctl-tunable features to
50880 + be disabled by default. As mentioned elsewhere, it is important
50881 + to enable the grsec_lock entry once you have finished modifying
50882 + the sysctl entries.
50883 +
50884 +endmenu
50885 +menu "Logging Options"
50886 +depends on GRKERNSEC
50887 +
50888 +config GRKERNSEC_FLOODTIME
50889 + int "Seconds in between log messages (minimum)"
50890 + default 10
50891 + help
50892 + This option allows you to enforce the number of seconds between
50893 + grsecurity log messages. The default should be suitable for most
50894 + people, however, if you choose to change it, choose a value small enough
50895 + to allow informative logs to be produced, but large enough to
50896 + prevent flooding.
50897 +
50898 +config GRKERNSEC_FLOODBURST
50899 + int "Number of messages in a burst (maximum)"
50900 + default 6
50901 + help
50902 + This option allows you to choose the maximum number of messages allowed
50903 + within the flood time interval you chose in a separate option. The
50904 + default should be suitable for most people, however if you find that
50905 + many of your logs are being interpreted as flooding, you may want to
50906 + raise this value.
50907 +
50908 +endmenu
50909 +
50910 +endmenu
50911 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50912 new file mode 100644
50913 index 0000000..be9ae3a
50914 --- /dev/null
50915 +++ b/grsecurity/Makefile
50916 @@ -0,0 +1,36 @@
50917 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50918 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50919 +# into an RBAC system
50920 +#
50921 +# All code in this directory and various hooks inserted throughout the kernel
50922 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50923 +# under the GPL v2 or higher
50924 +
50925 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50926 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50927 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50928 +
50929 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50930 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50931 + gracl_learn.o grsec_log.o
50932 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50933 +
50934 +ifdef CONFIG_NET
50935 +obj-y += grsec_sock.o
50936 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50937 +endif
50938 +
50939 +ifndef CONFIG_GRKERNSEC
50940 +obj-y += grsec_disabled.o
50941 +endif
50942 +
50943 +ifdef CONFIG_GRKERNSEC_HIDESYM
50944 +extra-y := grsec_hidesym.o
50945 +$(obj)/grsec_hidesym.o:
50946 + @-chmod -f 500 /boot
50947 + @-chmod -f 500 /lib/modules
50948 + @-chmod -f 500 /lib64/modules
50949 + @-chmod -f 500 /lib32/modules
50950 + @-chmod -f 700 .
50951 + @echo ' grsec: protected kernel image paths'
50952 +endif
50953 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50954 new file mode 100644
50955 index 0000000..09258e0
50956 --- /dev/null
50957 +++ b/grsecurity/gracl.c
50958 @@ -0,0 +1,4156 @@
50959 +#include <linux/kernel.h>
50960 +#include <linux/module.h>
50961 +#include <linux/sched.h>
50962 +#include <linux/mm.h>
50963 +#include <linux/file.h>
50964 +#include <linux/fs.h>
50965 +#include <linux/namei.h>
50966 +#include <linux/mount.h>
50967 +#include <linux/tty.h>
50968 +#include <linux/proc_fs.h>
50969 +#include <linux/lglock.h>
50970 +#include <linux/slab.h>
50971 +#include <linux/vmalloc.h>
50972 +#include <linux/types.h>
50973 +#include <linux/sysctl.h>
50974 +#include <linux/netdevice.h>
50975 +#include <linux/ptrace.h>
50976 +#include <linux/gracl.h>
50977 +#include <linux/gralloc.h>
50978 +#include <linux/grsecurity.h>
50979 +#include <linux/grinternal.h>
50980 +#include <linux/pid_namespace.h>
50981 +#include <linux/fdtable.h>
50982 +#include <linux/percpu.h>
50983 +
50984 +#include <asm/uaccess.h>
50985 +#include <asm/errno.h>
50986 +#include <asm/mman.h>
50987 +
50988 +static struct acl_role_db acl_role_set;
50989 +static struct name_db name_set;
50990 +static struct inodev_db inodev_set;
50991 +
50992 +/* for keeping track of userspace pointers used for subjects, so we
50993 + can share references in the kernel as well
50994 +*/
50995 +
50996 +static struct path real_root;
50997 +
50998 +static struct acl_subj_map_db subj_map_set;
50999 +
51000 +static struct acl_role_label *default_role;
51001 +
51002 +static struct acl_role_label *role_list;
51003 +
51004 +static u16 acl_sp_role_value;
51005 +
51006 +extern char *gr_shared_page[4];
51007 +static DEFINE_MUTEX(gr_dev_mutex);
51008 +DEFINE_RWLOCK(gr_inode_lock);
51009 +
51010 +struct gr_arg *gr_usermode;
51011 +
51012 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51013 +
51014 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51015 +extern void gr_clear_learn_entries(void);
51016 +
51017 +#ifdef CONFIG_GRKERNSEC_RESLOG
51018 +extern void gr_log_resource(const struct task_struct *task,
51019 + const int res, const unsigned long wanted, const int gt);
51020 +#endif
51021 +
51022 +unsigned char *gr_system_salt;
51023 +unsigned char *gr_system_sum;
51024 +
51025 +static struct sprole_pw **acl_special_roles = NULL;
51026 +static __u16 num_sprole_pws = 0;
51027 +
51028 +static struct acl_role_label *kernel_role = NULL;
51029 +
51030 +static unsigned int gr_auth_attempts = 0;
51031 +static unsigned long gr_auth_expires = 0UL;
51032 +
51033 +#ifdef CONFIG_NET
51034 +extern struct vfsmount *sock_mnt;
51035 +#endif
51036 +
51037 +extern struct vfsmount *pipe_mnt;
51038 +extern struct vfsmount *shm_mnt;
51039 +#ifdef CONFIG_HUGETLBFS
51040 +extern struct vfsmount *hugetlbfs_vfsmount;
51041 +#endif
51042 +
51043 +static struct acl_object_label *fakefs_obj_rw;
51044 +static struct acl_object_label *fakefs_obj_rwx;
51045 +
51046 +extern int gr_init_uidset(void);
51047 +extern void gr_free_uidset(void);
51048 +extern void gr_remove_uid(uid_t uid);
51049 +extern int gr_find_uid(uid_t uid);
51050 +
51051 +DECLARE_BRLOCK(vfsmount_lock);
51052 +
51053 +__inline__ int
51054 +gr_acl_is_enabled(void)
51055 +{
51056 + return (gr_status & GR_READY);
51057 +}
51058 +
51059 +#ifdef CONFIG_BTRFS_FS
51060 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51061 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51062 +#endif
51063 +
51064 +static inline dev_t __get_dev(const struct dentry *dentry)
51065 +{
51066 +#ifdef CONFIG_BTRFS_FS
51067 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51068 + return get_btrfs_dev_from_inode(dentry->d_inode);
51069 + else
51070 +#endif
51071 + return dentry->d_inode->i_sb->s_dev;
51072 +}
51073 +
51074 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51075 +{
51076 + return __get_dev(dentry);
51077 +}
51078 +
51079 +static char gr_task_roletype_to_char(struct task_struct *task)
51080 +{
51081 + switch (task->role->roletype &
51082 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51083 + GR_ROLE_SPECIAL)) {
51084 + case GR_ROLE_DEFAULT:
51085 + return 'D';
51086 + case GR_ROLE_USER:
51087 + return 'U';
51088 + case GR_ROLE_GROUP:
51089 + return 'G';
51090 + case GR_ROLE_SPECIAL:
51091 + return 'S';
51092 + }
51093 +
51094 + return 'X';
51095 +}
51096 +
51097 +char gr_roletype_to_char(void)
51098 +{
51099 + return gr_task_roletype_to_char(current);
51100 +}
51101 +
51102 +__inline__ int
51103 +gr_acl_tpe_check(void)
51104 +{
51105 + if (unlikely(!(gr_status & GR_READY)))
51106 + return 0;
51107 + if (current->role->roletype & GR_ROLE_TPE)
51108 + return 1;
51109 + else
51110 + return 0;
51111 +}
51112 +
51113 +int
51114 +gr_handle_rawio(const struct inode *inode)
51115 +{
51116 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51117 + if (inode && S_ISBLK(inode->i_mode) &&
51118 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51119 + !capable(CAP_SYS_RAWIO))
51120 + return 1;
51121 +#endif
51122 + return 0;
51123 +}
51124 +
51125 +static int
51126 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51127 +{
51128 + if (likely(lena != lenb))
51129 + return 0;
51130 +
51131 + return !memcmp(a, b, lena);
51132 +}
51133 +
51134 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51135 +{
51136 + *buflen -= namelen;
51137 + if (*buflen < 0)
51138 + return -ENAMETOOLONG;
51139 + *buffer -= namelen;
51140 + memcpy(*buffer, str, namelen);
51141 + return 0;
51142 +}
51143 +
51144 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51145 +{
51146 + return prepend(buffer, buflen, name->name, name->len);
51147 +}
51148 +
51149 +static int prepend_path(const struct path *path, struct path *root,
51150 + char **buffer, int *buflen)
51151 +{
51152 + struct dentry *dentry = path->dentry;
51153 + struct vfsmount *vfsmnt = path->mnt;
51154 + bool slash = false;
51155 + int error = 0;
51156 +
51157 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51158 + struct dentry * parent;
51159 +
51160 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51161 + /* Global root? */
51162 + if (vfsmnt->mnt_parent == vfsmnt) {
51163 + goto out;
51164 + }
51165 + dentry = vfsmnt->mnt_mountpoint;
51166 + vfsmnt = vfsmnt->mnt_parent;
51167 + continue;
51168 + }
51169 + parent = dentry->d_parent;
51170 + prefetch(parent);
51171 + spin_lock(&dentry->d_lock);
51172 + error = prepend_name(buffer, buflen, &dentry->d_name);
51173 + spin_unlock(&dentry->d_lock);
51174 + if (!error)
51175 + error = prepend(buffer, buflen, "/", 1);
51176 + if (error)
51177 + break;
51178 +
51179 + slash = true;
51180 + dentry = parent;
51181 + }
51182 +
51183 +out:
51184 + if (!error && !slash)
51185 + error = prepend(buffer, buflen, "/", 1);
51186 +
51187 + return error;
51188 +}
51189 +
51190 +/* this must be called with vfsmount_lock and rename_lock held */
51191 +
51192 +static char *__our_d_path(const struct path *path, struct path *root,
51193 + char *buf, int buflen)
51194 +{
51195 + char *res = buf + buflen;
51196 + int error;
51197 +
51198 + prepend(&res, &buflen, "\0", 1);
51199 + error = prepend_path(path, root, &res, &buflen);
51200 + if (error)
51201 + return ERR_PTR(error);
51202 +
51203 + return res;
51204 +}
51205 +
51206 +static char *
51207 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51208 +{
51209 + char *retval;
51210 +
51211 + retval = __our_d_path(path, root, buf, buflen);
51212 + if (unlikely(IS_ERR(retval)))
51213 + retval = strcpy(buf, "<path too long>");
51214 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51215 + retval[1] = '\0';
51216 +
51217 + return retval;
51218 +}
51219 +
51220 +static char *
51221 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51222 + char *buf, int buflen)
51223 +{
51224 + struct path path;
51225 + char *res;
51226 +
51227 + path.dentry = (struct dentry *)dentry;
51228 + path.mnt = (struct vfsmount *)vfsmnt;
51229 +
51230 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51231 + by the RBAC system */
51232 + res = gen_full_path(&path, &real_root, buf, buflen);
51233 +
51234 + return res;
51235 +}
51236 +
51237 +static char *
51238 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51239 + char *buf, int buflen)
51240 +{
51241 + char *res;
51242 + struct path path;
51243 + struct path root;
51244 + struct task_struct *reaper = &init_task;
51245 +
51246 + path.dentry = (struct dentry *)dentry;
51247 + path.mnt = (struct vfsmount *)vfsmnt;
51248 +
51249 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51250 + get_fs_root(reaper->fs, &root);
51251 +
51252 + write_seqlock(&rename_lock);
51253 + br_read_lock(vfsmount_lock);
51254 + res = gen_full_path(&path, &root, buf, buflen);
51255 + br_read_unlock(vfsmount_lock);
51256 + write_sequnlock(&rename_lock);
51257 +
51258 + path_put(&root);
51259 + return res;
51260 +}
51261 +
51262 +static char *
51263 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51264 +{
51265 + char *ret;
51266 + write_seqlock(&rename_lock);
51267 + br_read_lock(vfsmount_lock);
51268 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51269 + PAGE_SIZE);
51270 + br_read_unlock(vfsmount_lock);
51271 + write_sequnlock(&rename_lock);
51272 + return ret;
51273 +}
51274 +
51275 +static char *
51276 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51277 +{
51278 + char *ret;
51279 + char *buf;
51280 + int buflen;
51281 +
51282 + write_seqlock(&rename_lock);
51283 + br_read_lock(vfsmount_lock);
51284 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51285 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51286 + buflen = (int)(ret - buf);
51287 + if (buflen >= 5)
51288 + prepend(&ret, &buflen, "/proc", 5);
51289 + else
51290 + ret = strcpy(buf, "<path too long>");
51291 + br_read_unlock(vfsmount_lock);
51292 + write_sequnlock(&rename_lock);
51293 + return ret;
51294 +}
51295 +
51296 +char *
51297 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51298 +{
51299 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51300 + PAGE_SIZE);
51301 +}
51302 +
51303 +char *
51304 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51305 +{
51306 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51307 + PAGE_SIZE);
51308 +}
51309 +
51310 +char *
51311 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51312 +{
51313 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51314 + PAGE_SIZE);
51315 +}
51316 +
51317 +char *
51318 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51319 +{
51320 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51321 + PAGE_SIZE);
51322 +}
51323 +
51324 +char *
51325 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51326 +{
51327 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51328 + PAGE_SIZE);
51329 +}
51330 +
51331 +__inline__ __u32
51332 +to_gr_audit(const __u32 reqmode)
51333 +{
51334 + /* masks off auditable permission flags, then shifts them to create
51335 + auditing flags, and adds the special case of append auditing if
51336 + we're requesting write */
51337 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51338 +}
51339 +
51340 +struct acl_subject_label *
51341 +lookup_subject_map(const struct acl_subject_label *userp)
51342 +{
51343 + unsigned int index = shash(userp, subj_map_set.s_size);
51344 + struct subject_map *match;
51345 +
51346 + match = subj_map_set.s_hash[index];
51347 +
51348 + while (match && match->user != userp)
51349 + match = match->next;
51350 +
51351 + if (match != NULL)
51352 + return match->kernel;
51353 + else
51354 + return NULL;
51355 +}
51356 +
51357 +static void
51358 +insert_subj_map_entry(struct subject_map *subjmap)
51359 +{
51360 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51361 + struct subject_map **curr;
51362 +
51363 + subjmap->prev = NULL;
51364 +
51365 + curr = &subj_map_set.s_hash[index];
51366 + if (*curr != NULL)
51367 + (*curr)->prev = subjmap;
51368 +
51369 + subjmap->next = *curr;
51370 + *curr = subjmap;
51371 +
51372 + return;
51373 +}
51374 +
51375 +static struct acl_role_label *
51376 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51377 + const gid_t gid)
51378 +{
51379 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51380 + struct acl_role_label *match;
51381 + struct role_allowed_ip *ipp;
51382 + unsigned int x;
51383 + u32 curr_ip = task->signal->curr_ip;
51384 +
51385 + task->signal->saved_ip = curr_ip;
51386 +
51387 + match = acl_role_set.r_hash[index];
51388 +
51389 + while (match) {
51390 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51391 + for (x = 0; x < match->domain_child_num; x++) {
51392 + if (match->domain_children[x] == uid)
51393 + goto found;
51394 + }
51395 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51396 + break;
51397 + match = match->next;
51398 + }
51399 +found:
51400 + if (match == NULL) {
51401 + try_group:
51402 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51403 + match = acl_role_set.r_hash[index];
51404 +
51405 + while (match) {
51406 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51407 + for (x = 0; x < match->domain_child_num; x++) {
51408 + if (match->domain_children[x] == gid)
51409 + goto found2;
51410 + }
51411 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51412 + break;
51413 + match = match->next;
51414 + }
51415 +found2:
51416 + if (match == NULL)
51417 + match = default_role;
51418 + if (match->allowed_ips == NULL)
51419 + return match;
51420 + else {
51421 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51422 + if (likely
51423 + ((ntohl(curr_ip) & ipp->netmask) ==
51424 + (ntohl(ipp->addr) & ipp->netmask)))
51425 + return match;
51426 + }
51427 + match = default_role;
51428 + }
51429 + } else if (match->allowed_ips == NULL) {
51430 + return match;
51431 + } else {
51432 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51433 + if (likely
51434 + ((ntohl(curr_ip) & ipp->netmask) ==
51435 + (ntohl(ipp->addr) & ipp->netmask)))
51436 + return match;
51437 + }
51438 + goto try_group;
51439 + }
51440 +
51441 + return match;
51442 +}
51443 +
51444 +struct acl_subject_label *
51445 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51446 + const struct acl_role_label *role)
51447 +{
51448 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51449 + struct acl_subject_label *match;
51450 +
51451 + match = role->subj_hash[index];
51452 +
51453 + while (match && (match->inode != ino || match->device != dev ||
51454 + (match->mode & GR_DELETED))) {
51455 + match = match->next;
51456 + }
51457 +
51458 + if (match && !(match->mode & GR_DELETED))
51459 + return match;
51460 + else
51461 + return NULL;
51462 +}
51463 +
51464 +struct acl_subject_label *
51465 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51466 + const struct acl_role_label *role)
51467 +{
51468 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51469 + struct acl_subject_label *match;
51470 +
51471 + match = role->subj_hash[index];
51472 +
51473 + while (match && (match->inode != ino || match->device != dev ||
51474 + !(match->mode & GR_DELETED))) {
51475 + match = match->next;
51476 + }
51477 +
51478 + if (match && (match->mode & GR_DELETED))
51479 + return match;
51480 + else
51481 + return NULL;
51482 +}
51483 +
51484 +static struct acl_object_label *
51485 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51486 + const struct acl_subject_label *subj)
51487 +{
51488 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51489 + struct acl_object_label *match;
51490 +
51491 + match = subj->obj_hash[index];
51492 +
51493 + while (match && (match->inode != ino || match->device != dev ||
51494 + (match->mode & GR_DELETED))) {
51495 + match = match->next;
51496 + }
51497 +
51498 + if (match && !(match->mode & GR_DELETED))
51499 + return match;
51500 + else
51501 + return NULL;
51502 +}
51503 +
51504 +static struct acl_object_label *
51505 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51506 + const struct acl_subject_label *subj)
51507 +{
51508 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51509 + struct acl_object_label *match;
51510 +
51511 + match = subj->obj_hash[index];
51512 +
51513 + while (match && (match->inode != ino || match->device != dev ||
51514 + !(match->mode & GR_DELETED))) {
51515 + match = match->next;
51516 + }
51517 +
51518 + if (match && (match->mode & GR_DELETED))
51519 + return match;
51520 +
51521 + match = subj->obj_hash[index];
51522 +
51523 + while (match && (match->inode != ino || match->device != dev ||
51524 + (match->mode & GR_DELETED))) {
51525 + match = match->next;
51526 + }
51527 +
51528 + if (match && !(match->mode & GR_DELETED))
51529 + return match;
51530 + else
51531 + return NULL;
51532 +}
51533 +
51534 +static struct name_entry *
51535 +lookup_name_entry(const char *name)
51536 +{
51537 + unsigned int len = strlen(name);
51538 + unsigned int key = full_name_hash(name, len);
51539 + unsigned int index = key % name_set.n_size;
51540 + struct name_entry *match;
51541 +
51542 + match = name_set.n_hash[index];
51543 +
51544 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51545 + match = match->next;
51546 +
51547 + return match;
51548 +}
51549 +
51550 +static struct name_entry *
51551 +lookup_name_entry_create(const char *name)
51552 +{
51553 + unsigned int len = strlen(name);
51554 + unsigned int key = full_name_hash(name, len);
51555 + unsigned int index = key % name_set.n_size;
51556 + struct name_entry *match;
51557 +
51558 + match = name_set.n_hash[index];
51559 +
51560 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51561 + !match->deleted))
51562 + match = match->next;
51563 +
51564 + if (match && match->deleted)
51565 + return match;
51566 +
51567 + match = name_set.n_hash[index];
51568 +
51569 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51570 + match->deleted))
51571 + match = match->next;
51572 +
51573 + if (match && !match->deleted)
51574 + return match;
51575 + else
51576 + return NULL;
51577 +}
51578 +
51579 +static struct inodev_entry *
51580 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51581 +{
51582 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51583 + struct inodev_entry *match;
51584 +
51585 + match = inodev_set.i_hash[index];
51586 +
51587 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51588 + match = match->next;
51589 +
51590 + return match;
51591 +}
51592 +
51593 +static void
51594 +insert_inodev_entry(struct inodev_entry *entry)
51595 +{
51596 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51597 + inodev_set.i_size);
51598 + struct inodev_entry **curr;
51599 +
51600 + entry->prev = NULL;
51601 +
51602 + curr = &inodev_set.i_hash[index];
51603 + if (*curr != NULL)
51604 + (*curr)->prev = entry;
51605 +
51606 + entry->next = *curr;
51607 + *curr = entry;
51608 +
51609 + return;
51610 +}
51611 +
51612 +static void
51613 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51614 +{
51615 + unsigned int index =
51616 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51617 + struct acl_role_label **curr;
51618 + struct acl_role_label *tmp;
51619 +
51620 + curr = &acl_role_set.r_hash[index];
51621 +
51622 + /* if role was already inserted due to domains and already has
51623 + a role in the same bucket as it attached, then we need to
51624 + combine these two buckets
51625 + */
51626 + if (role->next) {
51627 + tmp = role->next;
51628 + while (tmp->next)
51629 + tmp = tmp->next;
51630 + tmp->next = *curr;
51631 + } else
51632 + role->next = *curr;
51633 + *curr = role;
51634 +
51635 + return;
51636 +}
51637 +
51638 +static void
51639 +insert_acl_role_label(struct acl_role_label *role)
51640 +{
51641 + int i;
51642 +
51643 + if (role_list == NULL) {
51644 + role_list = role;
51645 + role->prev = NULL;
51646 + } else {
51647 + role->prev = role_list;
51648 + role_list = role;
51649 + }
51650 +
51651 + /* used for hash chains */
51652 + role->next = NULL;
51653 +
51654 + if (role->roletype & GR_ROLE_DOMAIN) {
51655 + for (i = 0; i < role->domain_child_num; i++)
51656 + __insert_acl_role_label(role, role->domain_children[i]);
51657 + } else
51658 + __insert_acl_role_label(role, role->uidgid);
51659 +}
51660 +
51661 +static int
51662 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51663 +{
51664 + struct name_entry **curr, *nentry;
51665 + struct inodev_entry *ientry;
51666 + unsigned int len = strlen(name);
51667 + unsigned int key = full_name_hash(name, len);
51668 + unsigned int index = key % name_set.n_size;
51669 +
51670 + curr = &name_set.n_hash[index];
51671 +
51672 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51673 + curr = &((*curr)->next);
51674 +
51675 + if (*curr != NULL)
51676 + return 1;
51677 +
51678 + nentry = acl_alloc(sizeof (struct name_entry));
51679 + if (nentry == NULL)
51680 + return 0;
51681 + ientry = acl_alloc(sizeof (struct inodev_entry));
51682 + if (ientry == NULL)
51683 + return 0;
51684 + ientry->nentry = nentry;
51685 +
51686 + nentry->key = key;
51687 + nentry->name = name;
51688 + nentry->inode = inode;
51689 + nentry->device = device;
51690 + nentry->len = len;
51691 + nentry->deleted = deleted;
51692 +
51693 + nentry->prev = NULL;
51694 + curr = &name_set.n_hash[index];
51695 + if (*curr != NULL)
51696 + (*curr)->prev = nentry;
51697 + nentry->next = *curr;
51698 + *curr = nentry;
51699 +
51700 + /* insert us into the table searchable by inode/dev */
51701 + insert_inodev_entry(ientry);
51702 +
51703 + return 1;
51704 +}
51705 +
51706 +static void
51707 +insert_acl_obj_label(struct acl_object_label *obj,
51708 + struct acl_subject_label *subj)
51709 +{
51710 + unsigned int index =
51711 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51712 + struct acl_object_label **curr;
51713 +
51714 +
51715 + obj->prev = NULL;
51716 +
51717 + curr = &subj->obj_hash[index];
51718 + if (*curr != NULL)
51719 + (*curr)->prev = obj;
51720 +
51721 + obj->next = *curr;
51722 + *curr = obj;
51723 +
51724 + return;
51725 +}
51726 +
51727 +static void
51728 +insert_acl_subj_label(struct acl_subject_label *obj,
51729 + struct acl_role_label *role)
51730 +{
51731 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51732 + struct acl_subject_label **curr;
51733 +
51734 + obj->prev = NULL;
51735 +
51736 + curr = &role->subj_hash[index];
51737 + if (*curr != NULL)
51738 + (*curr)->prev = obj;
51739 +
51740 + obj->next = *curr;
51741 + *curr = obj;
51742 +
51743 + return;
51744 +}
51745 +
51746 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51747 +
51748 +static void *
51749 +create_table(__u32 * len, int elementsize)
51750 +{
51751 + unsigned int table_sizes[] = {
51752 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51753 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51754 + 4194301, 8388593, 16777213, 33554393, 67108859
51755 + };
51756 + void *newtable = NULL;
51757 + unsigned int pwr = 0;
51758 +
51759 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51760 + table_sizes[pwr] <= *len)
51761 + pwr++;
51762 +
51763 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51764 + return newtable;
51765 +
51766 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51767 + newtable =
51768 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51769 + else
51770 + newtable = vmalloc(table_sizes[pwr] * elementsize);
51771 +
51772 + *len = table_sizes[pwr];
51773 +
51774 + return newtable;
51775 +}
51776 +
51777 +static int
51778 +init_variables(const struct gr_arg *arg)
51779 +{
51780 + struct task_struct *reaper = &init_task;
51781 + unsigned int stacksize;
51782 +
51783 + subj_map_set.s_size = arg->role_db.num_subjects;
51784 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51785 + name_set.n_size = arg->role_db.num_objects;
51786 + inodev_set.i_size = arg->role_db.num_objects;
51787 +
51788 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51789 + !name_set.n_size || !inodev_set.i_size)
51790 + return 1;
51791 +
51792 + if (!gr_init_uidset())
51793 + return 1;
51794 +
51795 + /* set up the stack that holds allocation info */
51796 +
51797 + stacksize = arg->role_db.num_pointers + 5;
51798 +
51799 + if (!acl_alloc_stack_init(stacksize))
51800 + return 1;
51801 +
51802 + /* grab reference for the real root dentry and vfsmount */
51803 + get_fs_root(reaper->fs, &real_root);
51804 +
51805 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51806 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51807 +#endif
51808 +
51809 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51810 + if (fakefs_obj_rw == NULL)
51811 + return 1;
51812 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51813 +
51814 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51815 + if (fakefs_obj_rwx == NULL)
51816 + return 1;
51817 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51818 +
51819 + subj_map_set.s_hash =
51820 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51821 + acl_role_set.r_hash =
51822 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51823 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51824 + inodev_set.i_hash =
51825 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51826 +
51827 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51828 + !name_set.n_hash || !inodev_set.i_hash)
51829 + return 1;
51830 +
51831 + memset(subj_map_set.s_hash, 0,
51832 + sizeof(struct subject_map *) * subj_map_set.s_size);
51833 + memset(acl_role_set.r_hash, 0,
51834 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51835 + memset(name_set.n_hash, 0,
51836 + sizeof (struct name_entry *) * name_set.n_size);
51837 + memset(inodev_set.i_hash, 0,
51838 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51839 +
51840 + return 0;
51841 +}
51842 +
51843 +/* free information not needed after startup
51844 + currently contains user->kernel pointer mappings for subjects
51845 +*/
51846 +
51847 +static void
51848 +free_init_variables(void)
51849 +{
51850 + __u32 i;
51851 +
51852 + if (subj_map_set.s_hash) {
51853 + for (i = 0; i < subj_map_set.s_size; i++) {
51854 + if (subj_map_set.s_hash[i]) {
51855 + kfree(subj_map_set.s_hash[i]);
51856 + subj_map_set.s_hash[i] = NULL;
51857 + }
51858 + }
51859 +
51860 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51861 + PAGE_SIZE)
51862 + kfree(subj_map_set.s_hash);
51863 + else
51864 + vfree(subj_map_set.s_hash);
51865 + }
51866 +
51867 + return;
51868 +}
51869 +
51870 +static void
51871 +free_variables(void)
51872 +{
51873 + struct acl_subject_label *s;
51874 + struct acl_role_label *r;
51875 + struct task_struct *task, *task2;
51876 + unsigned int x;
51877 +
51878 + gr_clear_learn_entries();
51879 +
51880 + read_lock(&tasklist_lock);
51881 + do_each_thread(task2, task) {
51882 + task->acl_sp_role = 0;
51883 + task->acl_role_id = 0;
51884 + task->acl = NULL;
51885 + task->role = NULL;
51886 + } while_each_thread(task2, task);
51887 + read_unlock(&tasklist_lock);
51888 +
51889 + /* release the reference to the real root dentry and vfsmount */
51890 + path_put(&real_root);
51891 +
51892 + /* free all object hash tables */
51893 +
51894 + FOR_EACH_ROLE_START(r)
51895 + if (r->subj_hash == NULL)
51896 + goto next_role;
51897 + FOR_EACH_SUBJECT_START(r, s, x)
51898 + if (s->obj_hash == NULL)
51899 + break;
51900 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51901 + kfree(s->obj_hash);
51902 + else
51903 + vfree(s->obj_hash);
51904 + FOR_EACH_SUBJECT_END(s, x)
51905 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51906 + if (s->obj_hash == NULL)
51907 + break;
51908 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51909 + kfree(s->obj_hash);
51910 + else
51911 + vfree(s->obj_hash);
51912 + FOR_EACH_NESTED_SUBJECT_END(s)
51913 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51914 + kfree(r->subj_hash);
51915 + else
51916 + vfree(r->subj_hash);
51917 + r->subj_hash = NULL;
51918 +next_role:
51919 + FOR_EACH_ROLE_END(r)
51920 +
51921 + acl_free_all();
51922 +
51923 + if (acl_role_set.r_hash) {
51924 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51925 + PAGE_SIZE)
51926 + kfree(acl_role_set.r_hash);
51927 + else
51928 + vfree(acl_role_set.r_hash);
51929 + }
51930 + if (name_set.n_hash) {
51931 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
51932 + PAGE_SIZE)
51933 + kfree(name_set.n_hash);
51934 + else
51935 + vfree(name_set.n_hash);
51936 + }
51937 +
51938 + if (inodev_set.i_hash) {
51939 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51940 + PAGE_SIZE)
51941 + kfree(inodev_set.i_hash);
51942 + else
51943 + vfree(inodev_set.i_hash);
51944 + }
51945 +
51946 + gr_free_uidset();
51947 +
51948 + memset(&name_set, 0, sizeof (struct name_db));
51949 + memset(&inodev_set, 0, sizeof (struct inodev_db));
51950 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51951 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51952 +
51953 + default_role = NULL;
51954 + role_list = NULL;
51955 +
51956 + return;
51957 +}
51958 +
51959 +static __u32
51960 +count_user_objs(struct acl_object_label *userp)
51961 +{
51962 + struct acl_object_label o_tmp;
51963 + __u32 num = 0;
51964 +
51965 + while (userp) {
51966 + if (copy_from_user(&o_tmp, userp,
51967 + sizeof (struct acl_object_label)))
51968 + break;
51969 +
51970 + userp = o_tmp.prev;
51971 + num++;
51972 + }
51973 +
51974 + return num;
51975 +}
51976 +
51977 +static struct acl_subject_label *
51978 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51979 +
51980 +static int
51981 +copy_user_glob(struct acl_object_label *obj)
51982 +{
51983 + struct acl_object_label *g_tmp, **guser;
51984 + unsigned int len;
51985 + char *tmp;
51986 +
51987 + if (obj->globbed == NULL)
51988 + return 0;
51989 +
51990 + guser = &obj->globbed;
51991 + while (*guser) {
51992 + g_tmp = (struct acl_object_label *)
51993 + acl_alloc(sizeof (struct acl_object_label));
51994 + if (g_tmp == NULL)
51995 + return -ENOMEM;
51996 +
51997 + if (copy_from_user(g_tmp, *guser,
51998 + sizeof (struct acl_object_label)))
51999 + return -EFAULT;
52000 +
52001 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52002 +
52003 + if (!len || len >= PATH_MAX)
52004 + return -EINVAL;
52005 +
52006 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52007 + return -ENOMEM;
52008 +
52009 + if (copy_from_user(tmp, g_tmp->filename, len))
52010 + return -EFAULT;
52011 + tmp[len-1] = '\0';
52012 + g_tmp->filename = tmp;
52013 +
52014 + *guser = g_tmp;
52015 + guser = &(g_tmp->next);
52016 + }
52017 +
52018 + return 0;
52019 +}
52020 +
52021 +static int
52022 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52023 + struct acl_role_label *role)
52024 +{
52025 + struct acl_object_label *o_tmp;
52026 + unsigned int len;
52027 + int ret;
52028 + char *tmp;
52029 +
52030 + while (userp) {
52031 + if ((o_tmp = (struct acl_object_label *)
52032 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52033 + return -ENOMEM;
52034 +
52035 + if (copy_from_user(o_tmp, userp,
52036 + sizeof (struct acl_object_label)))
52037 + return -EFAULT;
52038 +
52039 + userp = o_tmp->prev;
52040 +
52041 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52042 +
52043 + if (!len || len >= PATH_MAX)
52044 + return -EINVAL;
52045 +
52046 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52047 + return -ENOMEM;
52048 +
52049 + if (copy_from_user(tmp, o_tmp->filename, len))
52050 + return -EFAULT;
52051 + tmp[len-1] = '\0';
52052 + o_tmp->filename = tmp;
52053 +
52054 + insert_acl_obj_label(o_tmp, subj);
52055 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52056 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52057 + return -ENOMEM;
52058 +
52059 + ret = copy_user_glob(o_tmp);
52060 + if (ret)
52061 + return ret;
52062 +
52063 + if (o_tmp->nested) {
52064 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52065 + if (IS_ERR(o_tmp->nested))
52066 + return PTR_ERR(o_tmp->nested);
52067 +
52068 + /* insert into nested subject list */
52069 + o_tmp->nested->next = role->hash->first;
52070 + role->hash->first = o_tmp->nested;
52071 + }
52072 + }
52073 +
52074 + return 0;
52075 +}
52076 +
52077 +static __u32
52078 +count_user_subjs(struct acl_subject_label *userp)
52079 +{
52080 + struct acl_subject_label s_tmp;
52081 + __u32 num = 0;
52082 +
52083 + while (userp) {
52084 + if (copy_from_user(&s_tmp, userp,
52085 + sizeof (struct acl_subject_label)))
52086 + break;
52087 +
52088 + userp = s_tmp.prev;
52089 + /* do not count nested subjects against this count, since
52090 + they are not included in the hash table, but are
52091 + attached to objects. We have already counted
52092 + the subjects in userspace for the allocation
52093 + stack
52094 + */
52095 + if (!(s_tmp.mode & GR_NESTED))
52096 + num++;
52097 + }
52098 +
52099 + return num;
52100 +}
52101 +
52102 +static int
52103 +copy_user_allowedips(struct acl_role_label *rolep)
52104 +{
52105 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52106 +
52107 + ruserip = rolep->allowed_ips;
52108 +
52109 + while (ruserip) {
52110 + rlast = rtmp;
52111 +
52112 + if ((rtmp = (struct role_allowed_ip *)
52113 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52114 + return -ENOMEM;
52115 +
52116 + if (copy_from_user(rtmp, ruserip,
52117 + sizeof (struct role_allowed_ip)))
52118 + return -EFAULT;
52119 +
52120 + ruserip = rtmp->prev;
52121 +
52122 + if (!rlast) {
52123 + rtmp->prev = NULL;
52124 + rolep->allowed_ips = rtmp;
52125 + } else {
52126 + rlast->next = rtmp;
52127 + rtmp->prev = rlast;
52128 + }
52129 +
52130 + if (!ruserip)
52131 + rtmp->next = NULL;
52132 + }
52133 +
52134 + return 0;
52135 +}
52136 +
52137 +static int
52138 +copy_user_transitions(struct acl_role_label *rolep)
52139 +{
52140 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52141 +
52142 + unsigned int len;
52143 + char *tmp;
52144 +
52145 + rusertp = rolep->transitions;
52146 +
52147 + while (rusertp) {
52148 + rlast = rtmp;
52149 +
52150 + if ((rtmp = (struct role_transition *)
52151 + acl_alloc(sizeof (struct role_transition))) == NULL)
52152 + return -ENOMEM;
52153 +
52154 + if (copy_from_user(rtmp, rusertp,
52155 + sizeof (struct role_transition)))
52156 + return -EFAULT;
52157 +
52158 + rusertp = rtmp->prev;
52159 +
52160 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52161 +
52162 + if (!len || len >= GR_SPROLE_LEN)
52163 + return -EINVAL;
52164 +
52165 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52166 + return -ENOMEM;
52167 +
52168 + if (copy_from_user(tmp, rtmp->rolename, len))
52169 + return -EFAULT;
52170 + tmp[len-1] = '\0';
52171 + rtmp->rolename = tmp;
52172 +
52173 + if (!rlast) {
52174 + rtmp->prev = NULL;
52175 + rolep->transitions = rtmp;
52176 + } else {
52177 + rlast->next = rtmp;
52178 + rtmp->prev = rlast;
52179 + }
52180 +
52181 + if (!rusertp)
52182 + rtmp->next = NULL;
52183 + }
52184 +
52185 + return 0;
52186 +}
52187 +
52188 +static struct acl_subject_label *
52189 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52190 +{
52191 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52192 + unsigned int len;
52193 + char *tmp;
52194 + __u32 num_objs;
52195 + struct acl_ip_label **i_tmp, *i_utmp2;
52196 + struct gr_hash_struct ghash;
52197 + struct subject_map *subjmap;
52198 + unsigned int i_num;
52199 + int err;
52200 +
52201 + s_tmp = lookup_subject_map(userp);
52202 +
52203 + /* we've already copied this subject into the kernel, just return
52204 + the reference to it, and don't copy it over again
52205 + */
52206 + if (s_tmp)
52207 + return(s_tmp);
52208 +
52209 + if ((s_tmp = (struct acl_subject_label *)
52210 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52211 + return ERR_PTR(-ENOMEM);
52212 +
52213 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52214 + if (subjmap == NULL)
52215 + return ERR_PTR(-ENOMEM);
52216 +
52217 + subjmap->user = userp;
52218 + subjmap->kernel = s_tmp;
52219 + insert_subj_map_entry(subjmap);
52220 +
52221 + if (copy_from_user(s_tmp, userp,
52222 + sizeof (struct acl_subject_label)))
52223 + return ERR_PTR(-EFAULT);
52224 +
52225 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52226 +
52227 + if (!len || len >= PATH_MAX)
52228 + return ERR_PTR(-EINVAL);
52229 +
52230 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52231 + return ERR_PTR(-ENOMEM);
52232 +
52233 + if (copy_from_user(tmp, s_tmp->filename, len))
52234 + return ERR_PTR(-EFAULT);
52235 + tmp[len-1] = '\0';
52236 + s_tmp->filename = tmp;
52237 +
52238 + if (!strcmp(s_tmp->filename, "/"))
52239 + role->root_label = s_tmp;
52240 +
52241 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52242 + return ERR_PTR(-EFAULT);
52243 +
52244 + /* copy user and group transition tables */
52245 +
52246 + if (s_tmp->user_trans_num) {
52247 + uid_t *uidlist;
52248 +
52249 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52250 + if (uidlist == NULL)
52251 + return ERR_PTR(-ENOMEM);
52252 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52253 + return ERR_PTR(-EFAULT);
52254 +
52255 + s_tmp->user_transitions = uidlist;
52256 + }
52257 +
52258 + if (s_tmp->group_trans_num) {
52259 + gid_t *gidlist;
52260 +
52261 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52262 + if (gidlist == NULL)
52263 + return ERR_PTR(-ENOMEM);
52264 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52265 + return ERR_PTR(-EFAULT);
52266 +
52267 + s_tmp->group_transitions = gidlist;
52268 + }
52269 +
52270 + /* set up object hash table */
52271 + num_objs = count_user_objs(ghash.first);
52272 +
52273 + s_tmp->obj_hash_size = num_objs;
52274 + s_tmp->obj_hash =
52275 + (struct acl_object_label **)
52276 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52277 +
52278 + if (!s_tmp->obj_hash)
52279 + return ERR_PTR(-ENOMEM);
52280 +
52281 + memset(s_tmp->obj_hash, 0,
52282 + s_tmp->obj_hash_size *
52283 + sizeof (struct acl_object_label *));
52284 +
52285 + /* add in objects */
52286 + err = copy_user_objs(ghash.first, s_tmp, role);
52287 +
52288 + if (err)
52289 + return ERR_PTR(err);
52290 +
52291 + /* set pointer for parent subject */
52292 + if (s_tmp->parent_subject) {
52293 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52294 +
52295 + if (IS_ERR(s_tmp2))
52296 + return s_tmp2;
52297 +
52298 + s_tmp->parent_subject = s_tmp2;
52299 + }
52300 +
52301 + /* add in ip acls */
52302 +
52303 + if (!s_tmp->ip_num) {
52304 + s_tmp->ips = NULL;
52305 + goto insert;
52306 + }
52307 +
52308 + i_tmp =
52309 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52310 + sizeof (struct acl_ip_label *));
52311 +
52312 + if (!i_tmp)
52313 + return ERR_PTR(-ENOMEM);
52314 +
52315 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52316 + *(i_tmp + i_num) =
52317 + (struct acl_ip_label *)
52318 + acl_alloc(sizeof (struct acl_ip_label));
52319 + if (!*(i_tmp + i_num))
52320 + return ERR_PTR(-ENOMEM);
52321 +
52322 + if (copy_from_user
52323 + (&i_utmp2, s_tmp->ips + i_num,
52324 + sizeof (struct acl_ip_label *)))
52325 + return ERR_PTR(-EFAULT);
52326 +
52327 + if (copy_from_user
52328 + (*(i_tmp + i_num), i_utmp2,
52329 + sizeof (struct acl_ip_label)))
52330 + return ERR_PTR(-EFAULT);
52331 +
52332 + if ((*(i_tmp + i_num))->iface == NULL)
52333 + continue;
52334 +
52335 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52336 + if (!len || len >= IFNAMSIZ)
52337 + return ERR_PTR(-EINVAL);
52338 + tmp = acl_alloc(len);
52339 + if (tmp == NULL)
52340 + return ERR_PTR(-ENOMEM);
52341 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52342 + return ERR_PTR(-EFAULT);
52343 + (*(i_tmp + i_num))->iface = tmp;
52344 + }
52345 +
52346 + s_tmp->ips = i_tmp;
52347 +
52348 +insert:
52349 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52350 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52351 + return ERR_PTR(-ENOMEM);
52352 +
52353 + return s_tmp;
52354 +}
52355 +
52356 +static int
52357 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52358 +{
52359 + struct acl_subject_label s_pre;
52360 + struct acl_subject_label * ret;
52361 + int err;
52362 +
52363 + while (userp) {
52364 + if (copy_from_user(&s_pre, userp,
52365 + sizeof (struct acl_subject_label)))
52366 + return -EFAULT;
52367 +
52368 + /* do not add nested subjects here, add
52369 + while parsing objects
52370 + */
52371 +
52372 + if (s_pre.mode & GR_NESTED) {
52373 + userp = s_pre.prev;
52374 + continue;
52375 + }
52376 +
52377 + ret = do_copy_user_subj(userp, role);
52378 +
52379 + err = PTR_ERR(ret);
52380 + if (IS_ERR(ret))
52381 + return err;
52382 +
52383 + insert_acl_subj_label(ret, role);
52384 +
52385 + userp = s_pre.prev;
52386 + }
52387 +
52388 + return 0;
52389 +}
52390 +
52391 +static int
52392 +copy_user_acl(struct gr_arg *arg)
52393 +{
52394 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52395 + struct sprole_pw *sptmp;
52396 + struct gr_hash_struct *ghash;
52397 + uid_t *domainlist;
52398 + unsigned int r_num;
52399 + unsigned int len;
52400 + char *tmp;
52401 + int err = 0;
52402 + __u16 i;
52403 + __u32 num_subjs;
52404 +
52405 + /* we need a default and kernel role */
52406 + if (arg->role_db.num_roles < 2)
52407 + return -EINVAL;
52408 +
52409 + /* copy special role authentication info from userspace */
52410 +
52411 + num_sprole_pws = arg->num_sprole_pws;
52412 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52413 +
52414 + if (!acl_special_roles) {
52415 + err = -ENOMEM;
52416 + goto cleanup;
52417 + }
52418 +
52419 + for (i = 0; i < num_sprole_pws; i++) {
52420 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52421 + if (!sptmp) {
52422 + err = -ENOMEM;
52423 + goto cleanup;
52424 + }
52425 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52426 + sizeof (struct sprole_pw))) {
52427 + err = -EFAULT;
52428 + goto cleanup;
52429 + }
52430 +
52431 + len =
52432 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52433 +
52434 + if (!len || len >= GR_SPROLE_LEN) {
52435 + err = -EINVAL;
52436 + goto cleanup;
52437 + }
52438 +
52439 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
52440 + err = -ENOMEM;
52441 + goto cleanup;
52442 + }
52443 +
52444 + if (copy_from_user(tmp, sptmp->rolename, len)) {
52445 + err = -EFAULT;
52446 + goto cleanup;
52447 + }
52448 + tmp[len-1] = '\0';
52449 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52450 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52451 +#endif
52452 + sptmp->rolename = tmp;
52453 + acl_special_roles[i] = sptmp;
52454 + }
52455 +
52456 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52457 +
52458 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52459 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52460 +
52461 + if (!r_tmp) {
52462 + err = -ENOMEM;
52463 + goto cleanup;
52464 + }
52465 +
52466 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52467 + sizeof (struct acl_role_label *))) {
52468 + err = -EFAULT;
52469 + goto cleanup;
52470 + }
52471 +
52472 + if (copy_from_user(r_tmp, r_utmp2,
52473 + sizeof (struct acl_role_label))) {
52474 + err = -EFAULT;
52475 + goto cleanup;
52476 + }
52477 +
52478 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52479 +
52480 + if (!len || len >= PATH_MAX) {
52481 + err = -EINVAL;
52482 + goto cleanup;
52483 + }
52484 +
52485 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
52486 + err = -ENOMEM;
52487 + goto cleanup;
52488 + }
52489 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
52490 + err = -EFAULT;
52491 + goto cleanup;
52492 + }
52493 + tmp[len-1] = '\0';
52494 + r_tmp->rolename = tmp;
52495 +
52496 + if (!strcmp(r_tmp->rolename, "default")
52497 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52498 + default_role = r_tmp;
52499 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52500 + kernel_role = r_tmp;
52501 + }
52502 +
52503 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
52504 + err = -ENOMEM;
52505 + goto cleanup;
52506 + }
52507 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
52508 + err = -EFAULT;
52509 + goto cleanup;
52510 + }
52511 +
52512 + r_tmp->hash = ghash;
52513 +
52514 + num_subjs = count_user_subjs(r_tmp->hash->first);
52515 +
52516 + r_tmp->subj_hash_size = num_subjs;
52517 + r_tmp->subj_hash =
52518 + (struct acl_subject_label **)
52519 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52520 +
52521 + if (!r_tmp->subj_hash) {
52522 + err = -ENOMEM;
52523 + goto cleanup;
52524 + }
52525 +
52526 + err = copy_user_allowedips(r_tmp);
52527 + if (err)
52528 + goto cleanup;
52529 +
52530 + /* copy domain info */
52531 + if (r_tmp->domain_children != NULL) {
52532 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52533 + if (domainlist == NULL) {
52534 + err = -ENOMEM;
52535 + goto cleanup;
52536 + }
52537 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
52538 + err = -EFAULT;
52539 + goto cleanup;
52540 + }
52541 + r_tmp->domain_children = domainlist;
52542 + }
52543 +
52544 + err = copy_user_transitions(r_tmp);
52545 + if (err)
52546 + goto cleanup;
52547 +
52548 + memset(r_tmp->subj_hash, 0,
52549 + r_tmp->subj_hash_size *
52550 + sizeof (struct acl_subject_label *));
52551 +
52552 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52553 +
52554 + if (err)
52555 + goto cleanup;
52556 +
52557 + /* set nested subject list to null */
52558 + r_tmp->hash->first = NULL;
52559 +
52560 + insert_acl_role_label(r_tmp);
52561 + }
52562 +
52563 + goto return_err;
52564 + cleanup:
52565 + free_variables();
52566 + return_err:
52567 + return err;
52568 +
52569 +}
52570 +
52571 +static int
52572 +gracl_init(struct gr_arg *args)
52573 +{
52574 + int error = 0;
52575 +
52576 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52577 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52578 +
52579 + if (init_variables(args)) {
52580 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52581 + error = -ENOMEM;
52582 + free_variables();
52583 + goto out;
52584 + }
52585 +
52586 + error = copy_user_acl(args);
52587 + free_init_variables();
52588 + if (error) {
52589 + free_variables();
52590 + goto out;
52591 + }
52592 +
52593 + if ((error = gr_set_acls(0))) {
52594 + free_variables();
52595 + goto out;
52596 + }
52597 +
52598 + pax_open_kernel();
52599 + gr_status |= GR_READY;
52600 + pax_close_kernel();
52601 +
52602 + out:
52603 + return error;
52604 +}
52605 +
52606 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52607 +
52608 +static int
52609 +glob_match(const char *p, const char *n)
52610 +{
52611 + char c;
52612 +
52613 + while ((c = *p++) != '\0') {
52614 + switch (c) {
52615 + case '?':
52616 + if (*n == '\0')
52617 + return 1;
52618 + else if (*n == '/')
52619 + return 1;
52620 + break;
52621 + case '\\':
52622 + if (*n != c)
52623 + return 1;
52624 + break;
52625 + case '*':
52626 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52627 + if (*n == '/')
52628 + return 1;
52629 + else if (c == '?') {
52630 + if (*n == '\0')
52631 + return 1;
52632 + else
52633 + ++n;
52634 + }
52635 + }
52636 + if (c == '\0') {
52637 + return 0;
52638 + } else {
52639 + const char *endp;
52640 +
52641 + if ((endp = strchr(n, '/')) == NULL)
52642 + endp = n + strlen(n);
52643 +
52644 + if (c == '[') {
52645 + for (--p; n < endp; ++n)
52646 + if (!glob_match(p, n))
52647 + return 0;
52648 + } else if (c == '/') {
52649 + while (*n != '\0' && *n != '/')
52650 + ++n;
52651 + if (*n == '/' && !glob_match(p, n + 1))
52652 + return 0;
52653 + } else {
52654 + for (--p; n < endp; ++n)
52655 + if (*n == c && !glob_match(p, n))
52656 + return 0;
52657 + }
52658 +
52659 + return 1;
52660 + }
52661 + case '[':
52662 + {
52663 + int not;
52664 + char cold;
52665 +
52666 + if (*n == '\0' || *n == '/')
52667 + return 1;
52668 +
52669 + not = (*p == '!' || *p == '^');
52670 + if (not)
52671 + ++p;
52672 +
52673 + c = *p++;
52674 + for (;;) {
52675 + unsigned char fn = (unsigned char)*n;
52676 +
52677 + if (c == '\0')
52678 + return 1;
52679 + else {
52680 + if (c == fn)
52681 + goto matched;
52682 + cold = c;
52683 + c = *p++;
52684 +
52685 + if (c == '-' && *p != ']') {
52686 + unsigned char cend = *p++;
52687 +
52688 + if (cend == '\0')
52689 + return 1;
52690 +
52691 + if (cold <= fn && fn <= cend)
52692 + goto matched;
52693 +
52694 + c = *p++;
52695 + }
52696 + }
52697 +
52698 + if (c == ']')
52699 + break;
52700 + }
52701 + if (!not)
52702 + return 1;
52703 + break;
52704 + matched:
52705 + while (c != ']') {
52706 + if (c == '\0')
52707 + return 1;
52708 +
52709 + c = *p++;
52710 + }
52711 + if (not)
52712 + return 1;
52713 + }
52714 + break;
52715 + default:
52716 + if (c != *n)
52717 + return 1;
52718 + }
52719 +
52720 + ++n;
52721 + }
52722 +
52723 + if (*n == '\0')
52724 + return 0;
52725 +
52726 + if (*n == '/')
52727 + return 0;
52728 +
52729 + return 1;
52730 +}
52731 +
52732 +static struct acl_object_label *
52733 +chk_glob_label(struct acl_object_label *globbed,
52734 + struct dentry *dentry, struct vfsmount *mnt, char **path)
52735 +{
52736 + struct acl_object_label *tmp;
52737 +
52738 + if (*path == NULL)
52739 + *path = gr_to_filename_nolock(dentry, mnt);
52740 +
52741 + tmp = globbed;
52742 +
52743 + while (tmp) {
52744 + if (!glob_match(tmp->filename, *path))
52745 + return tmp;
52746 + tmp = tmp->next;
52747 + }
52748 +
52749 + return NULL;
52750 +}
52751 +
52752 +static struct acl_object_label *
52753 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52754 + const ino_t curr_ino, const dev_t curr_dev,
52755 + const struct acl_subject_label *subj, char **path, const int checkglob)
52756 +{
52757 + struct acl_subject_label *tmpsubj;
52758 + struct acl_object_label *retval;
52759 + struct acl_object_label *retval2;
52760 +
52761 + tmpsubj = (struct acl_subject_label *) subj;
52762 + read_lock(&gr_inode_lock);
52763 + do {
52764 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52765 + if (retval) {
52766 + if (checkglob && retval->globbed) {
52767 + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
52768 + (struct vfsmount *)orig_mnt, path);
52769 + if (retval2)
52770 + retval = retval2;
52771 + }
52772 + break;
52773 + }
52774 + } while ((tmpsubj = tmpsubj->parent_subject));
52775 + read_unlock(&gr_inode_lock);
52776 +
52777 + return retval;
52778 +}
52779 +
52780 +static __inline__ struct acl_object_label *
52781 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52782 + struct dentry *curr_dentry,
52783 + const struct acl_subject_label *subj, char **path, const int checkglob)
52784 +{
52785 + int newglob = checkglob;
52786 + ino_t inode;
52787 + dev_t device;
52788 +
52789 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52790 + as we don't want a / * rule to match instead of the / object
52791 + don't do this for create lookups that call this function though, since they're looking up
52792 + on the parent and thus need globbing checks on all paths
52793 + */
52794 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52795 + newglob = GR_NO_GLOB;
52796 +
52797 + spin_lock(&curr_dentry->d_lock);
52798 + inode = curr_dentry->d_inode->i_ino;
52799 + device = __get_dev(curr_dentry);
52800 + spin_unlock(&curr_dentry->d_lock);
52801 +
52802 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52803 +}
52804 +
52805 +static struct acl_object_label *
52806 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52807 + const struct acl_subject_label *subj, char *path, const int checkglob)
52808 +{
52809 + struct dentry *dentry = (struct dentry *) l_dentry;
52810 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52811 + struct acl_object_label *retval;
52812 + struct dentry *parent;
52813 +
52814 + write_seqlock(&rename_lock);
52815 + br_read_lock(vfsmount_lock);
52816 +
52817 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52818 +#ifdef CONFIG_NET
52819 + mnt == sock_mnt ||
52820 +#endif
52821 +#ifdef CONFIG_HUGETLBFS
52822 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52823 +#endif
52824 + /* ignore Eric Biederman */
52825 + IS_PRIVATE(l_dentry->d_inode))) {
52826 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52827 + goto out;
52828 + }
52829 +
52830 + for (;;) {
52831 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52832 + break;
52833 +
52834 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52835 + if (mnt->mnt_parent == mnt)
52836 + break;
52837 +
52838 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52839 + if (retval != NULL)
52840 + goto out;
52841 +
52842 + dentry = mnt->mnt_mountpoint;
52843 + mnt = mnt->mnt_parent;
52844 + continue;
52845 + }
52846 +
52847 + parent = dentry->d_parent;
52848 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52849 + if (retval != NULL)
52850 + goto out;
52851 +
52852 + dentry = parent;
52853 + }
52854 +
52855 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52856 +
52857 + /* real_root is pinned so we don't have to hold a reference */
52858 + if (retval == NULL)
52859 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52860 +out:
52861 + br_read_unlock(vfsmount_lock);
52862 + write_sequnlock(&rename_lock);
52863 +
52864 + BUG_ON(retval == NULL);
52865 +
52866 + return retval;
52867 +}
52868 +
52869 +static __inline__ struct acl_object_label *
52870 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52871 + const struct acl_subject_label *subj)
52872 +{
52873 + char *path = NULL;
52874 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52875 +}
52876 +
52877 +static __inline__ struct acl_object_label *
52878 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52879 + const struct acl_subject_label *subj)
52880 +{
52881 + char *path = NULL;
52882 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52883 +}
52884 +
52885 +static __inline__ struct acl_object_label *
52886 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52887 + const struct acl_subject_label *subj, char *path)
52888 +{
52889 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52890 +}
52891 +
52892 +static struct acl_subject_label *
52893 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52894 + const struct acl_role_label *role)
52895 +{
52896 + struct dentry *dentry = (struct dentry *) l_dentry;
52897 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52898 + struct acl_subject_label *retval;
52899 + struct dentry *parent;
52900 +
52901 + write_seqlock(&rename_lock);
52902 + br_read_lock(vfsmount_lock);
52903 +
52904 + for (;;) {
52905 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52906 + break;
52907 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52908 + if (mnt->mnt_parent == mnt)
52909 + break;
52910 +
52911 + spin_lock(&dentry->d_lock);
52912 + read_lock(&gr_inode_lock);
52913 + retval =
52914 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52915 + __get_dev(dentry), role);
52916 + read_unlock(&gr_inode_lock);
52917 + spin_unlock(&dentry->d_lock);
52918 + if (retval != NULL)
52919 + goto out;
52920 +
52921 + dentry = mnt->mnt_mountpoint;
52922 + mnt = mnt->mnt_parent;
52923 + continue;
52924 + }
52925 +
52926 + spin_lock(&dentry->d_lock);
52927 + read_lock(&gr_inode_lock);
52928 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52929 + __get_dev(dentry), role);
52930 + read_unlock(&gr_inode_lock);
52931 + parent = dentry->d_parent;
52932 + spin_unlock(&dentry->d_lock);
52933 +
52934 + if (retval != NULL)
52935 + goto out;
52936 +
52937 + dentry = parent;
52938 + }
52939 +
52940 + spin_lock(&dentry->d_lock);
52941 + read_lock(&gr_inode_lock);
52942 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52943 + __get_dev(dentry), role);
52944 + read_unlock(&gr_inode_lock);
52945 + spin_unlock(&dentry->d_lock);
52946 +
52947 + if (unlikely(retval == NULL)) {
52948 + /* real_root is pinned, we don't need to hold a reference */
52949 + read_lock(&gr_inode_lock);
52950 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52951 + __get_dev(real_root.dentry), role);
52952 + read_unlock(&gr_inode_lock);
52953 + }
52954 +out:
52955 + br_read_unlock(vfsmount_lock);
52956 + write_sequnlock(&rename_lock);
52957 +
52958 + BUG_ON(retval == NULL);
52959 +
52960 + return retval;
52961 +}
52962 +
52963 +static void
52964 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52965 +{
52966 + struct task_struct *task = current;
52967 + const struct cred *cred = current_cred();
52968 +
52969 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52970 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52971 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52972 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52973 +
52974 + return;
52975 +}
52976 +
52977 +static void
52978 +gr_log_learn_sysctl(const char *path, const __u32 mode)
52979 +{
52980 + struct task_struct *task = current;
52981 + const struct cred *cred = current_cred();
52982 +
52983 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52984 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52985 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52986 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
52987 +
52988 + return;
52989 +}
52990 +
52991 +static void
52992 +gr_log_learn_id_change(const char type, const unsigned int real,
52993 + const unsigned int effective, const unsigned int fs)
52994 +{
52995 + struct task_struct *task = current;
52996 + const struct cred *cred = current_cred();
52997 +
52998 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52999 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53000 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53001 + type, real, effective, fs, &task->signal->saved_ip);
53002 +
53003 + return;
53004 +}
53005 +
53006 +__u32
53007 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53008 + const struct vfsmount * mnt)
53009 +{
53010 + __u32 retval = mode;
53011 + struct acl_subject_label *curracl;
53012 + struct acl_object_label *currobj;
53013 +
53014 + if (unlikely(!(gr_status & GR_READY)))
53015 + return (mode & ~GR_AUDITS);
53016 +
53017 + curracl = current->acl;
53018 +
53019 + currobj = chk_obj_label(dentry, mnt, curracl);
53020 + retval = currobj->mode & mode;
53021 +
53022 + /* if we're opening a specified transfer file for writing
53023 + (e.g. /dev/initctl), then transfer our role to init
53024 + */
53025 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53026 + current->role->roletype & GR_ROLE_PERSIST)) {
53027 + struct task_struct *task = init_pid_ns.child_reaper;
53028 +
53029 + if (task->role != current->role) {
53030 + task->acl_sp_role = 0;
53031 + task->acl_role_id = current->acl_role_id;
53032 + task->role = current->role;
53033 + rcu_read_lock();
53034 + read_lock(&grsec_exec_file_lock);
53035 + gr_apply_subject_to_task(task);
53036 + read_unlock(&grsec_exec_file_lock);
53037 + rcu_read_unlock();
53038 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53039 + }
53040 + }
53041 +
53042 + if (unlikely
53043 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53044 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53045 + __u32 new_mode = mode;
53046 +
53047 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53048 +
53049 + retval = new_mode;
53050 +
53051 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53052 + new_mode |= GR_INHERIT;
53053 +
53054 + if (!(mode & GR_NOLEARN))
53055 + gr_log_learn(dentry, mnt, new_mode);
53056 + }
53057 +
53058 + return retval;
53059 +}
53060 +
53061 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53062 + const struct dentry *parent,
53063 + const struct vfsmount *mnt)
53064 +{
53065 + struct name_entry *match;
53066 + struct acl_object_label *matchpo;
53067 + struct acl_subject_label *curracl;
53068 + char *path;
53069 +
53070 + if (unlikely(!(gr_status & GR_READY)))
53071 + return NULL;
53072 +
53073 + preempt_disable();
53074 + path = gr_to_filename_rbac(new_dentry, mnt);
53075 + match = lookup_name_entry_create(path);
53076 +
53077 + curracl = current->acl;
53078 +
53079 + if (match) {
53080 + read_lock(&gr_inode_lock);
53081 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53082 + read_unlock(&gr_inode_lock);
53083 +
53084 + if (matchpo) {
53085 + preempt_enable();
53086 + return matchpo;
53087 + }
53088 + }
53089 +
53090 + // lookup parent
53091 +
53092 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53093 +
53094 + preempt_enable();
53095 + return matchpo;
53096 +}
53097 +
53098 +__u32
53099 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53100 + const struct vfsmount * mnt, const __u32 mode)
53101 +{
53102 + struct acl_object_label *matchpo;
53103 + __u32 retval;
53104 +
53105 + if (unlikely(!(gr_status & GR_READY)))
53106 + return (mode & ~GR_AUDITS);
53107 +
53108 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53109 +
53110 + retval = matchpo->mode & mode;
53111 +
53112 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53113 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53114 + __u32 new_mode = mode;
53115 +
53116 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53117 +
53118 + gr_log_learn(new_dentry, mnt, new_mode);
53119 + return new_mode;
53120 + }
53121 +
53122 + return retval;
53123 +}
53124 +
53125 +__u32
53126 +gr_check_link(const struct dentry * new_dentry,
53127 + const struct dentry * parent_dentry,
53128 + const struct vfsmount * parent_mnt,
53129 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53130 +{
53131 + struct acl_object_label *obj;
53132 + __u32 oldmode, newmode;
53133 + __u32 needmode;
53134 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53135 + GR_DELETE | GR_INHERIT;
53136 +
53137 + if (unlikely(!(gr_status & GR_READY)))
53138 + return (GR_CREATE | GR_LINK);
53139 +
53140 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53141 + oldmode = obj->mode;
53142 +
53143 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53144 + newmode = obj->mode;
53145 +
53146 + needmode = newmode & checkmodes;
53147 +
53148 + // old name for hardlink must have at least the permissions of the new name
53149 + if ((oldmode & needmode) != needmode)
53150 + goto bad;
53151 +
53152 + // if old name had restrictions/auditing, make sure the new name does as well
53153 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53154 +
53155 + // don't allow hardlinking of suid/sgid files without permission
53156 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53157 + needmode |= GR_SETID;
53158 +
53159 + if ((newmode & needmode) != needmode)
53160 + goto bad;
53161 +
53162 + // enforce minimum permissions
53163 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53164 + return newmode;
53165 +bad:
53166 + needmode = oldmode;
53167 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53168 + needmode |= GR_SETID;
53169 +
53170 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53171 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53172 + return (GR_CREATE | GR_LINK);
53173 + } else if (newmode & GR_SUPPRESS)
53174 + return GR_SUPPRESS;
53175 + else
53176 + return 0;
53177 +}
53178 +
53179 +int
53180 +gr_check_hidden_task(const struct task_struct *task)
53181 +{
53182 + if (unlikely(!(gr_status & GR_READY)))
53183 + return 0;
53184 +
53185 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53186 + return 1;
53187 +
53188 + return 0;
53189 +}
53190 +
53191 +int
53192 +gr_check_protected_task(const struct task_struct *task)
53193 +{
53194 + if (unlikely(!(gr_status & GR_READY) || !task))
53195 + return 0;
53196 +
53197 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53198 + task->acl != current->acl)
53199 + return 1;
53200 +
53201 + return 0;
53202 +}
53203 +
53204 +int
53205 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53206 +{
53207 + struct task_struct *p;
53208 + int ret = 0;
53209 +
53210 + if (unlikely(!(gr_status & GR_READY) || !pid))
53211 + return ret;
53212 +
53213 + read_lock(&tasklist_lock);
53214 + do_each_pid_task(pid, type, p) {
53215 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53216 + p->acl != current->acl) {
53217 + ret = 1;
53218 + goto out;
53219 + }
53220 + } while_each_pid_task(pid, type, p);
53221 +out:
53222 + read_unlock(&tasklist_lock);
53223 +
53224 + return ret;
53225 +}
53226 +
53227 +void
53228 +gr_copy_label(struct task_struct *tsk)
53229 +{
53230 + tsk->signal->used_accept = 0;
53231 + tsk->acl_sp_role = 0;
53232 + tsk->acl_role_id = current->acl_role_id;
53233 + tsk->acl = current->acl;
53234 + tsk->role = current->role;
53235 + tsk->signal->curr_ip = current->signal->curr_ip;
53236 + tsk->signal->saved_ip = current->signal->saved_ip;
53237 + if (current->exec_file)
53238 + get_file(current->exec_file);
53239 + tsk->exec_file = current->exec_file;
53240 + tsk->is_writable = current->is_writable;
53241 + if (unlikely(current->signal->used_accept)) {
53242 + current->signal->curr_ip = 0;
53243 + current->signal->saved_ip = 0;
53244 + }
53245 +
53246 + return;
53247 +}
53248 +
53249 +static void
53250 +gr_set_proc_res(struct task_struct *task)
53251 +{
53252 + struct acl_subject_label *proc;
53253 + unsigned short i;
53254 +
53255 + proc = task->acl;
53256 +
53257 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53258 + return;
53259 +
53260 + for (i = 0; i < RLIM_NLIMITS; i++) {
53261 + if (!(proc->resmask & (1 << i)))
53262 + continue;
53263 +
53264 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53265 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53266 + }
53267 +
53268 + return;
53269 +}
53270 +
53271 +extern int __gr_process_user_ban(struct user_struct *user);
53272 +
53273 +int
53274 +gr_check_user_change(int real, int effective, int fs)
53275 +{
53276 + unsigned int i;
53277 + __u16 num;
53278 + uid_t *uidlist;
53279 + int curuid;
53280 + int realok = 0;
53281 + int effectiveok = 0;
53282 + int fsok = 0;
53283 +
53284 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53285 + struct user_struct *user;
53286 +
53287 + if (real == -1)
53288 + goto skipit;
53289 +
53290 + user = find_user(real);
53291 + if (user == NULL)
53292 + goto skipit;
53293 +
53294 + if (__gr_process_user_ban(user)) {
53295 + /* for find_user */
53296 + free_uid(user);
53297 + return 1;
53298 + }
53299 +
53300 + /* for find_user */
53301 + free_uid(user);
53302 +
53303 +skipit:
53304 +#endif
53305 +
53306 + if (unlikely(!(gr_status & GR_READY)))
53307 + return 0;
53308 +
53309 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53310 + gr_log_learn_id_change('u', real, effective, fs);
53311 +
53312 + num = current->acl->user_trans_num;
53313 + uidlist = current->acl->user_transitions;
53314 +
53315 + if (uidlist == NULL)
53316 + return 0;
53317 +
53318 + if (real == -1)
53319 + realok = 1;
53320 + if (effective == -1)
53321 + effectiveok = 1;
53322 + if (fs == -1)
53323 + fsok = 1;
53324 +
53325 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53326 + for (i = 0; i < num; i++) {
53327 + curuid = (int)uidlist[i];
53328 + if (real == curuid)
53329 + realok = 1;
53330 + if (effective == curuid)
53331 + effectiveok = 1;
53332 + if (fs == curuid)
53333 + fsok = 1;
53334 + }
53335 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53336 + for (i = 0; i < num; i++) {
53337 + curuid = (int)uidlist[i];
53338 + if (real == curuid)
53339 + break;
53340 + if (effective == curuid)
53341 + break;
53342 + if (fs == curuid)
53343 + break;
53344 + }
53345 + /* not in deny list */
53346 + if (i == num) {
53347 + realok = 1;
53348 + effectiveok = 1;
53349 + fsok = 1;
53350 + }
53351 + }
53352 +
53353 + if (realok && effectiveok && fsok)
53354 + return 0;
53355 + else {
53356 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53357 + return 1;
53358 + }
53359 +}
53360 +
53361 +int
53362 +gr_check_group_change(int real, int effective, int fs)
53363 +{
53364 + unsigned int i;
53365 + __u16 num;
53366 + gid_t *gidlist;
53367 + int curgid;
53368 + int realok = 0;
53369 + int effectiveok = 0;
53370 + int fsok = 0;
53371 +
53372 + if (unlikely(!(gr_status & GR_READY)))
53373 + return 0;
53374 +
53375 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53376 + gr_log_learn_id_change('g', real, effective, fs);
53377 +
53378 + num = current->acl->group_trans_num;
53379 + gidlist = current->acl->group_transitions;
53380 +
53381 + if (gidlist == NULL)
53382 + return 0;
53383 +
53384 + if (real == -1)
53385 + realok = 1;
53386 + if (effective == -1)
53387 + effectiveok = 1;
53388 + if (fs == -1)
53389 + fsok = 1;
53390 +
53391 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53392 + for (i = 0; i < num; i++) {
53393 + curgid = (int)gidlist[i];
53394 + if (real == curgid)
53395 + realok = 1;
53396 + if (effective == curgid)
53397 + effectiveok = 1;
53398 + if (fs == curgid)
53399 + fsok = 1;
53400 + }
53401 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53402 + for (i = 0; i < num; i++) {
53403 + curgid = (int)gidlist[i];
53404 + if (real == curgid)
53405 + break;
53406 + if (effective == curgid)
53407 + break;
53408 + if (fs == curgid)
53409 + break;
53410 + }
53411 + /* not in deny list */
53412 + if (i == num) {
53413 + realok = 1;
53414 + effectiveok = 1;
53415 + fsok = 1;
53416 + }
53417 + }
53418 +
53419 + if (realok && effectiveok && fsok)
53420 + return 0;
53421 + else {
53422 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53423 + return 1;
53424 + }
53425 +}
53426 +
53427 +void
53428 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53429 +{
53430 + struct acl_role_label *role = task->role;
53431 + struct acl_subject_label *subj = NULL;
53432 + struct acl_object_label *obj;
53433 + struct file *filp;
53434 +
53435 + if (unlikely(!(gr_status & GR_READY)))
53436 + return;
53437 +
53438 + filp = task->exec_file;
53439 +
53440 + /* kernel process, we'll give them the kernel role */
53441 + if (unlikely(!filp)) {
53442 + task->role = kernel_role;
53443 + task->acl = kernel_role->root_label;
53444 + return;
53445 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53446 + role = lookup_acl_role_label(task, uid, gid);
53447 +
53448 + /* perform subject lookup in possibly new role
53449 + we can use this result below in the case where role == task->role
53450 + */
53451 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53452 +
53453 + /* if we changed uid/gid, but result in the same role
53454 + and are using inheritance, don't lose the inherited subject
53455 + if current subject is other than what normal lookup
53456 + would result in, we arrived via inheritance, don't
53457 + lose subject
53458 + */
53459 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53460 + (subj == task->acl)))
53461 + task->acl = subj;
53462 +
53463 + task->role = role;
53464 +
53465 + task->is_writable = 0;
53466 +
53467 + /* ignore additional mmap checks for processes that are writable
53468 + by the default ACL */
53469 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53470 + if (unlikely(obj->mode & GR_WRITE))
53471 + task->is_writable = 1;
53472 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53473 + if (unlikely(obj->mode & GR_WRITE))
53474 + task->is_writable = 1;
53475 +
53476 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53477 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53478 +#endif
53479 +
53480 + gr_set_proc_res(task);
53481 +
53482 + return;
53483 +}
53484 +
53485 +int
53486 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53487 + const int unsafe_share)
53488 +{
53489 + struct task_struct *task = current;
53490 + struct acl_subject_label *newacl;
53491 + struct acl_object_label *obj;
53492 + __u32 retmode;
53493 +
53494 + if (unlikely(!(gr_status & GR_READY)))
53495 + return 0;
53496 +
53497 + newacl = chk_subj_label(dentry, mnt, task->role);
53498 +
53499 + task_lock(task);
53500 + if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
53501 + !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53502 + !(task->role->roletype & GR_ROLE_GOD) &&
53503 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53504 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
53505 + task_unlock(task);
53506 + if (unsafe_share)
53507 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53508 + else
53509 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53510 + return -EACCES;
53511 + }
53512 + task_unlock(task);
53513 +
53514 + obj = chk_obj_label(dentry, mnt, task->acl);
53515 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53516 +
53517 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53518 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53519 + if (obj->nested)
53520 + task->acl = obj->nested;
53521 + else
53522 + task->acl = newacl;
53523 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53524 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53525 +
53526 + task->is_writable = 0;
53527 +
53528 + /* ignore additional mmap checks for processes that are writable
53529 + by the default ACL */
53530 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53531 + if (unlikely(obj->mode & GR_WRITE))
53532 + task->is_writable = 1;
53533 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53534 + if (unlikely(obj->mode & GR_WRITE))
53535 + task->is_writable = 1;
53536 +
53537 + gr_set_proc_res(task);
53538 +
53539 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53540 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53541 +#endif
53542 + return 0;
53543 +}
53544 +
53545 +/* always called with valid inodev ptr */
53546 +static void
53547 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53548 +{
53549 + struct acl_object_label *matchpo;
53550 + struct acl_subject_label *matchps;
53551 + struct acl_subject_label *subj;
53552 + struct acl_role_label *role;
53553 + unsigned int x;
53554 +
53555 + FOR_EACH_ROLE_START(role)
53556 + FOR_EACH_SUBJECT_START(role, subj, x)
53557 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53558 + matchpo->mode |= GR_DELETED;
53559 + FOR_EACH_SUBJECT_END(subj,x)
53560 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53561 + if (subj->inode == ino && subj->device == dev)
53562 + subj->mode |= GR_DELETED;
53563 + FOR_EACH_NESTED_SUBJECT_END(subj)
53564 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53565 + matchps->mode |= GR_DELETED;
53566 + FOR_EACH_ROLE_END(role)
53567 +
53568 + inodev->nentry->deleted = 1;
53569 +
53570 + return;
53571 +}
53572 +
53573 +void
53574 +gr_handle_delete(const ino_t ino, const dev_t dev)
53575 +{
53576 + struct inodev_entry *inodev;
53577 +
53578 + if (unlikely(!(gr_status & GR_READY)))
53579 + return;
53580 +
53581 + write_lock(&gr_inode_lock);
53582 + inodev = lookup_inodev_entry(ino, dev);
53583 + if (inodev != NULL)
53584 + do_handle_delete(inodev, ino, dev);
53585 + write_unlock(&gr_inode_lock);
53586 +
53587 + return;
53588 +}
53589 +
53590 +static void
53591 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53592 + const ino_t newinode, const dev_t newdevice,
53593 + struct acl_subject_label *subj)
53594 +{
53595 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53596 + struct acl_object_label *match;
53597 +
53598 + match = subj->obj_hash[index];
53599 +
53600 + while (match && (match->inode != oldinode ||
53601 + match->device != olddevice ||
53602 + !(match->mode & GR_DELETED)))
53603 + match = match->next;
53604 +
53605 + if (match && (match->inode == oldinode)
53606 + && (match->device == olddevice)
53607 + && (match->mode & GR_DELETED)) {
53608 + if (match->prev == NULL) {
53609 + subj->obj_hash[index] = match->next;
53610 + if (match->next != NULL)
53611 + match->next->prev = NULL;
53612 + } else {
53613 + match->prev->next = match->next;
53614 + if (match->next != NULL)
53615 + match->next->prev = match->prev;
53616 + }
53617 + match->prev = NULL;
53618 + match->next = NULL;
53619 + match->inode = newinode;
53620 + match->device = newdevice;
53621 + match->mode &= ~GR_DELETED;
53622 +
53623 + insert_acl_obj_label(match, subj);
53624 + }
53625 +
53626 + return;
53627 +}
53628 +
53629 +static void
53630 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53631 + const ino_t newinode, const dev_t newdevice,
53632 + struct acl_role_label *role)
53633 +{
53634 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53635 + struct acl_subject_label *match;
53636 +
53637 + match = role->subj_hash[index];
53638 +
53639 + while (match && (match->inode != oldinode ||
53640 + match->device != olddevice ||
53641 + !(match->mode & GR_DELETED)))
53642 + match = match->next;
53643 +
53644 + if (match && (match->inode == oldinode)
53645 + && (match->device == olddevice)
53646 + && (match->mode & GR_DELETED)) {
53647 + if (match->prev == NULL) {
53648 + role->subj_hash[index] = match->next;
53649 + if (match->next != NULL)
53650 + match->next->prev = NULL;
53651 + } else {
53652 + match->prev->next = match->next;
53653 + if (match->next != NULL)
53654 + match->next->prev = match->prev;
53655 + }
53656 + match->prev = NULL;
53657 + match->next = NULL;
53658 + match->inode = newinode;
53659 + match->device = newdevice;
53660 + match->mode &= ~GR_DELETED;
53661 +
53662 + insert_acl_subj_label(match, role);
53663 + }
53664 +
53665 + return;
53666 +}
53667 +
53668 +static void
53669 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53670 + const ino_t newinode, const dev_t newdevice)
53671 +{
53672 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53673 + struct inodev_entry *match;
53674 +
53675 + match = inodev_set.i_hash[index];
53676 +
53677 + while (match && (match->nentry->inode != oldinode ||
53678 + match->nentry->device != olddevice || !match->nentry->deleted))
53679 + match = match->next;
53680 +
53681 + if (match && (match->nentry->inode == oldinode)
53682 + && (match->nentry->device == olddevice) &&
53683 + match->nentry->deleted) {
53684 + if (match->prev == NULL) {
53685 + inodev_set.i_hash[index] = match->next;
53686 + if (match->next != NULL)
53687 + match->next->prev = NULL;
53688 + } else {
53689 + match->prev->next = match->next;
53690 + if (match->next != NULL)
53691 + match->next->prev = match->prev;
53692 + }
53693 + match->prev = NULL;
53694 + match->next = NULL;
53695 + match->nentry->inode = newinode;
53696 + match->nentry->device = newdevice;
53697 + match->nentry->deleted = 0;
53698 +
53699 + insert_inodev_entry(match);
53700 + }
53701 +
53702 + return;
53703 +}
53704 +
53705 +static void
53706 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53707 +{
53708 + struct acl_subject_label *subj;
53709 + struct acl_role_label *role;
53710 + unsigned int x;
53711 +
53712 + FOR_EACH_ROLE_START(role)
53713 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53714 +
53715 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53716 + if ((subj->inode == ino) && (subj->device == dev)) {
53717 + subj->inode = ino;
53718 + subj->device = dev;
53719 + }
53720 + FOR_EACH_NESTED_SUBJECT_END(subj)
53721 + FOR_EACH_SUBJECT_START(role, subj, x)
53722 + update_acl_obj_label(matchn->inode, matchn->device,
53723 + ino, dev, subj);
53724 + FOR_EACH_SUBJECT_END(subj,x)
53725 + FOR_EACH_ROLE_END(role)
53726 +
53727 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53728 +
53729 + return;
53730 +}
53731 +
53732 +static void
53733 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53734 + const struct vfsmount *mnt)
53735 +{
53736 + ino_t ino = dentry->d_inode->i_ino;
53737 + dev_t dev = __get_dev(dentry);
53738 +
53739 + __do_handle_create(matchn, ino, dev);
53740 +
53741 + return;
53742 +}
53743 +
53744 +void
53745 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53746 +{
53747 + struct name_entry *matchn;
53748 +
53749 + if (unlikely(!(gr_status & GR_READY)))
53750 + return;
53751 +
53752 + preempt_disable();
53753 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53754 +
53755 + if (unlikely((unsigned long)matchn)) {
53756 + write_lock(&gr_inode_lock);
53757 + do_handle_create(matchn, dentry, mnt);
53758 + write_unlock(&gr_inode_lock);
53759 + }
53760 + preempt_enable();
53761 +
53762 + return;
53763 +}
53764 +
53765 +void
53766 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53767 +{
53768 + struct name_entry *matchn;
53769 +
53770 + if (unlikely(!(gr_status & GR_READY)))
53771 + return;
53772 +
53773 + preempt_disable();
53774 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53775 +
53776 + if (unlikely((unsigned long)matchn)) {
53777 + write_lock(&gr_inode_lock);
53778 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53779 + write_unlock(&gr_inode_lock);
53780 + }
53781 + preempt_enable();
53782 +
53783 + return;
53784 +}
53785 +
53786 +void
53787 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53788 + struct dentry *old_dentry,
53789 + struct dentry *new_dentry,
53790 + struct vfsmount *mnt, const __u8 replace)
53791 +{
53792 + struct name_entry *matchn;
53793 + struct inodev_entry *inodev;
53794 + struct inode *inode = new_dentry->d_inode;
53795 + ino_t old_ino = old_dentry->d_inode->i_ino;
53796 + dev_t old_dev = __get_dev(old_dentry);
53797 +
53798 + /* vfs_rename swaps the name and parent link for old_dentry and
53799 + new_dentry
53800 + at this point, old_dentry has the new name, parent link, and inode
53801 + for the renamed file
53802 + if a file is being replaced by a rename, new_dentry has the inode
53803 + and name for the replaced file
53804 + */
53805 +
53806 + if (unlikely(!(gr_status & GR_READY)))
53807 + return;
53808 +
53809 + preempt_disable();
53810 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53811 +
53812 + /* we wouldn't have to check d_inode if it weren't for
53813 + NFS silly-renaming
53814 + */
53815 +
53816 + write_lock(&gr_inode_lock);
53817 + if (unlikely(replace && inode)) {
53818 + ino_t new_ino = inode->i_ino;
53819 + dev_t new_dev = __get_dev(new_dentry);
53820 +
53821 + inodev = lookup_inodev_entry(new_ino, new_dev);
53822 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53823 + do_handle_delete(inodev, new_ino, new_dev);
53824 + }
53825 +
53826 + inodev = lookup_inodev_entry(old_ino, old_dev);
53827 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53828 + do_handle_delete(inodev, old_ino, old_dev);
53829 +
53830 + if (unlikely((unsigned long)matchn))
53831 + do_handle_create(matchn, old_dentry, mnt);
53832 +
53833 + write_unlock(&gr_inode_lock);
53834 + preempt_enable();
53835 +
53836 + return;
53837 +}
53838 +
53839 +static int
53840 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53841 + unsigned char **sum)
53842 +{
53843 + struct acl_role_label *r;
53844 + struct role_allowed_ip *ipp;
53845 + struct role_transition *trans;
53846 + unsigned int i;
53847 + int found = 0;
53848 + u32 curr_ip = current->signal->curr_ip;
53849 +
53850 + current->signal->saved_ip = curr_ip;
53851 +
53852 + /* check transition table */
53853 +
53854 + for (trans = current->role->transitions; trans; trans = trans->next) {
53855 + if (!strcmp(rolename, trans->rolename)) {
53856 + found = 1;
53857 + break;
53858 + }
53859 + }
53860 +
53861 + if (!found)
53862 + return 0;
53863 +
53864 + /* handle special roles that do not require authentication
53865 + and check ip */
53866 +
53867 + FOR_EACH_ROLE_START(r)
53868 + if (!strcmp(rolename, r->rolename) &&
53869 + (r->roletype & GR_ROLE_SPECIAL)) {
53870 + found = 0;
53871 + if (r->allowed_ips != NULL) {
53872 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53873 + if ((ntohl(curr_ip) & ipp->netmask) ==
53874 + (ntohl(ipp->addr) & ipp->netmask))
53875 + found = 1;
53876 + }
53877 + } else
53878 + found = 2;
53879 + if (!found)
53880 + return 0;
53881 +
53882 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53883 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53884 + *salt = NULL;
53885 + *sum = NULL;
53886 + return 1;
53887 + }
53888 + }
53889 + FOR_EACH_ROLE_END(r)
53890 +
53891 + for (i = 0; i < num_sprole_pws; i++) {
53892 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53893 + *salt = acl_special_roles[i]->salt;
53894 + *sum = acl_special_roles[i]->sum;
53895 + return 1;
53896 + }
53897 + }
53898 +
53899 + return 0;
53900 +}
53901 +
53902 +static void
53903 +assign_special_role(char *rolename)
53904 +{
53905 + struct acl_object_label *obj;
53906 + struct acl_role_label *r;
53907 + struct acl_role_label *assigned = NULL;
53908 + struct task_struct *tsk;
53909 + struct file *filp;
53910 +
53911 + FOR_EACH_ROLE_START(r)
53912 + if (!strcmp(rolename, r->rolename) &&
53913 + (r->roletype & GR_ROLE_SPECIAL)) {
53914 + assigned = r;
53915 + break;
53916 + }
53917 + FOR_EACH_ROLE_END(r)
53918 +
53919 + if (!assigned)
53920 + return;
53921 +
53922 + read_lock(&tasklist_lock);
53923 + read_lock(&grsec_exec_file_lock);
53924 +
53925 + tsk = current->real_parent;
53926 + if (tsk == NULL)
53927 + goto out_unlock;
53928 +
53929 + filp = tsk->exec_file;
53930 + if (filp == NULL)
53931 + goto out_unlock;
53932 +
53933 + tsk->is_writable = 0;
53934 +
53935 + tsk->acl_sp_role = 1;
53936 + tsk->acl_role_id = ++acl_sp_role_value;
53937 + tsk->role = assigned;
53938 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53939 +
53940 + /* ignore additional mmap checks for processes that are writable
53941 + by the default ACL */
53942 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53943 + if (unlikely(obj->mode & GR_WRITE))
53944 + tsk->is_writable = 1;
53945 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53946 + if (unlikely(obj->mode & GR_WRITE))
53947 + tsk->is_writable = 1;
53948 +
53949 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53950 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53951 +#endif
53952 +
53953 +out_unlock:
53954 + read_unlock(&grsec_exec_file_lock);
53955 + read_unlock(&tasklist_lock);
53956 + return;
53957 +}
53958 +
53959 +int gr_check_secure_terminal(struct task_struct *task)
53960 +{
53961 + struct task_struct *p, *p2, *p3;
53962 + struct files_struct *files;
53963 + struct fdtable *fdt;
53964 + struct file *our_file = NULL, *file;
53965 + int i;
53966 +
53967 + if (task->signal->tty == NULL)
53968 + return 1;
53969 +
53970 + files = get_files_struct(task);
53971 + if (files != NULL) {
53972 + rcu_read_lock();
53973 + fdt = files_fdtable(files);
53974 + for (i=0; i < fdt->max_fds; i++) {
53975 + file = fcheck_files(files, i);
53976 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53977 + get_file(file);
53978 + our_file = file;
53979 + }
53980 + }
53981 + rcu_read_unlock();
53982 + put_files_struct(files);
53983 + }
53984 +
53985 + if (our_file == NULL)
53986 + return 1;
53987 +
53988 + read_lock(&tasklist_lock);
53989 + do_each_thread(p2, p) {
53990 + files = get_files_struct(p);
53991 + if (files == NULL ||
53992 + (p->signal && p->signal->tty == task->signal->tty)) {
53993 + if (files != NULL)
53994 + put_files_struct(files);
53995 + continue;
53996 + }
53997 + rcu_read_lock();
53998 + fdt = files_fdtable(files);
53999 + for (i=0; i < fdt->max_fds; i++) {
54000 + file = fcheck_files(files, i);
54001 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54002 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54003 + p3 = task;
54004 + while (p3->pid > 0) {
54005 + if (p3 == p)
54006 + break;
54007 + p3 = p3->real_parent;
54008 + }
54009 + if (p3 == p)
54010 + break;
54011 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54012 + gr_handle_alertkill(p);
54013 + rcu_read_unlock();
54014 + put_files_struct(files);
54015 + read_unlock(&tasklist_lock);
54016 + fput(our_file);
54017 + return 0;
54018 + }
54019 + }
54020 + rcu_read_unlock();
54021 + put_files_struct(files);
54022 + } while_each_thread(p2, p);
54023 + read_unlock(&tasklist_lock);
54024 +
54025 + fput(our_file);
54026 + return 1;
54027 +}
54028 +
54029 +ssize_t
54030 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54031 +{
54032 + struct gr_arg_wrapper uwrap;
54033 + unsigned char *sprole_salt = NULL;
54034 + unsigned char *sprole_sum = NULL;
54035 + int error = sizeof (struct gr_arg_wrapper);
54036 + int error2 = 0;
54037 +
54038 + mutex_lock(&gr_dev_mutex);
54039 +
54040 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54041 + error = -EPERM;
54042 + goto out;
54043 + }
54044 +
54045 + if (count != sizeof (struct gr_arg_wrapper)) {
54046 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54047 + error = -EINVAL;
54048 + goto out;
54049 + }
54050 +
54051 +
54052 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54053 + gr_auth_expires = 0;
54054 + gr_auth_attempts = 0;
54055 + }
54056 +
54057 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54058 + error = -EFAULT;
54059 + goto out;
54060 + }
54061 +
54062 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54063 + error = -EINVAL;
54064 + goto out;
54065 + }
54066 +
54067 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54068 + error = -EFAULT;
54069 + goto out;
54070 + }
54071 +
54072 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54073 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54074 + time_after(gr_auth_expires, get_seconds())) {
54075 + error = -EBUSY;
54076 + goto out;
54077 + }
54078 +
54079 + /* if non-root trying to do anything other than use a special role,
54080 + do not attempt authentication, do not count towards authentication
54081 + locking
54082 + */
54083 +
54084 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54085 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54086 + current_uid()) {
54087 + error = -EPERM;
54088 + goto out;
54089 + }
54090 +
54091 + /* ensure pw and special role name are null terminated */
54092 +
54093 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54094 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54095 +
54096 + /* Okay.
54097 + * We have our enough of the argument structure..(we have yet
54098 + * to copy_from_user the tables themselves) . Copy the tables
54099 + * only if we need them, i.e. for loading operations. */
54100 +
54101 + switch (gr_usermode->mode) {
54102 + case GR_STATUS:
54103 + if (gr_status & GR_READY) {
54104 + error = 1;
54105 + if (!gr_check_secure_terminal(current))
54106 + error = 3;
54107 + } else
54108 + error = 2;
54109 + goto out;
54110 + case GR_SHUTDOWN:
54111 + if ((gr_status & GR_READY)
54112 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54113 + pax_open_kernel();
54114 + gr_status &= ~GR_READY;
54115 + pax_close_kernel();
54116 +
54117 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54118 + free_variables();
54119 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54120 + memset(gr_system_salt, 0, GR_SALT_LEN);
54121 + memset(gr_system_sum, 0, GR_SHA_LEN);
54122 + } else if (gr_status & GR_READY) {
54123 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54124 + error = -EPERM;
54125 + } else {
54126 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54127 + error = -EAGAIN;
54128 + }
54129 + break;
54130 + case GR_ENABLE:
54131 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54132 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54133 + else {
54134 + if (gr_status & GR_READY)
54135 + error = -EAGAIN;
54136 + else
54137 + error = error2;
54138 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54139 + }
54140 + break;
54141 + case GR_RELOAD:
54142 + if (!(gr_status & GR_READY)) {
54143 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54144 + error = -EAGAIN;
54145 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54146 + preempt_disable();
54147 +
54148 + pax_open_kernel();
54149 + gr_status &= ~GR_READY;
54150 + pax_close_kernel();
54151 +
54152 + free_variables();
54153 + if (!(error2 = gracl_init(gr_usermode))) {
54154 + preempt_enable();
54155 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54156 + } else {
54157 + preempt_enable();
54158 + error = error2;
54159 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54160 + }
54161 + } else {
54162 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54163 + error = -EPERM;
54164 + }
54165 + break;
54166 + case GR_SEGVMOD:
54167 + if (unlikely(!(gr_status & GR_READY))) {
54168 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54169 + error = -EAGAIN;
54170 + break;
54171 + }
54172 +
54173 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54174 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54175 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54176 + struct acl_subject_label *segvacl;
54177 + segvacl =
54178 + lookup_acl_subj_label(gr_usermode->segv_inode,
54179 + gr_usermode->segv_device,
54180 + current->role);
54181 + if (segvacl) {
54182 + segvacl->crashes = 0;
54183 + segvacl->expires = 0;
54184 + }
54185 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54186 + gr_remove_uid(gr_usermode->segv_uid);
54187 + }
54188 + } else {
54189 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54190 + error = -EPERM;
54191 + }
54192 + break;
54193 + case GR_SPROLE:
54194 + case GR_SPROLEPAM:
54195 + if (unlikely(!(gr_status & GR_READY))) {
54196 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54197 + error = -EAGAIN;
54198 + break;
54199 + }
54200 +
54201 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54202 + current->role->expires = 0;
54203 + current->role->auth_attempts = 0;
54204 + }
54205 +
54206 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54207 + time_after(current->role->expires, get_seconds())) {
54208 + error = -EBUSY;
54209 + goto out;
54210 + }
54211 +
54212 + if (lookup_special_role_auth
54213 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54214 + && ((!sprole_salt && !sprole_sum)
54215 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54216 + char *p = "";
54217 + assign_special_role(gr_usermode->sp_role);
54218 + read_lock(&tasklist_lock);
54219 + if (current->real_parent)
54220 + p = current->real_parent->role->rolename;
54221 + read_unlock(&tasklist_lock);
54222 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54223 + p, acl_sp_role_value);
54224 + } else {
54225 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54226 + error = -EPERM;
54227 + if(!(current->role->auth_attempts++))
54228 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54229 +
54230 + goto out;
54231 + }
54232 + break;
54233 + case GR_UNSPROLE:
54234 + if (unlikely(!(gr_status & GR_READY))) {
54235 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54236 + error = -EAGAIN;
54237 + break;
54238 + }
54239 +
54240 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54241 + char *p = "";
54242 + int i = 0;
54243 +
54244 + read_lock(&tasklist_lock);
54245 + if (current->real_parent) {
54246 + p = current->real_parent->role->rolename;
54247 + i = current->real_parent->acl_role_id;
54248 + }
54249 + read_unlock(&tasklist_lock);
54250 +
54251 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54252 + gr_set_acls(1);
54253 + } else {
54254 + error = -EPERM;
54255 + goto out;
54256 + }
54257 + break;
54258 + default:
54259 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54260 + error = -EINVAL;
54261 + break;
54262 + }
54263 +
54264 + if (error != -EPERM)
54265 + goto out;
54266 +
54267 + if(!(gr_auth_attempts++))
54268 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54269 +
54270 + out:
54271 + mutex_unlock(&gr_dev_mutex);
54272 + return error;
54273 +}
54274 +
54275 +/* must be called with
54276 + rcu_read_lock();
54277 + read_lock(&tasklist_lock);
54278 + read_lock(&grsec_exec_file_lock);
54279 +*/
54280 +int gr_apply_subject_to_task(struct task_struct *task)
54281 +{
54282 + struct acl_object_label *obj;
54283 + char *tmpname;
54284 + struct acl_subject_label *tmpsubj;
54285 + struct file *filp;
54286 + struct name_entry *nmatch;
54287 +
54288 + filp = task->exec_file;
54289 + if (filp == NULL)
54290 + return 0;
54291 +
54292 + /* the following is to apply the correct subject
54293 + on binaries running when the RBAC system
54294 + is enabled, when the binaries have been
54295 + replaced or deleted since their execution
54296 + -----
54297 + when the RBAC system starts, the inode/dev
54298 + from exec_file will be one the RBAC system
54299 + is unaware of. It only knows the inode/dev
54300 + of the present file on disk, or the absence
54301 + of it.
54302 + */
54303 + preempt_disable();
54304 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54305 +
54306 + nmatch = lookup_name_entry(tmpname);
54307 + preempt_enable();
54308 + tmpsubj = NULL;
54309 + if (nmatch) {
54310 + if (nmatch->deleted)
54311 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54312 + else
54313 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54314 + if (tmpsubj != NULL)
54315 + task->acl = tmpsubj;
54316 + }
54317 + if (tmpsubj == NULL)
54318 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54319 + task->role);
54320 + if (task->acl) {
54321 + task->is_writable = 0;
54322 + /* ignore additional mmap checks for processes that are writable
54323 + by the default ACL */
54324 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54325 + if (unlikely(obj->mode & GR_WRITE))
54326 + task->is_writable = 1;
54327 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54328 + if (unlikely(obj->mode & GR_WRITE))
54329 + task->is_writable = 1;
54330 +
54331 + gr_set_proc_res(task);
54332 +
54333 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54334 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54335 +#endif
54336 + } else {
54337 + return 1;
54338 + }
54339 +
54340 + return 0;
54341 +}
54342 +
54343 +int
54344 +gr_set_acls(const int type)
54345 +{
54346 + struct task_struct *task, *task2;
54347 + struct acl_role_label *role = current->role;
54348 + __u16 acl_role_id = current->acl_role_id;
54349 + const struct cred *cred;
54350 + int ret;
54351 +
54352 + rcu_read_lock();
54353 + read_lock(&tasklist_lock);
54354 + read_lock(&grsec_exec_file_lock);
54355 + do_each_thread(task2, task) {
54356 + /* check to see if we're called from the exit handler,
54357 + if so, only replace ACLs that have inherited the admin
54358 + ACL */
54359 +
54360 + if (type && (task->role != role ||
54361 + task->acl_role_id != acl_role_id))
54362 + continue;
54363 +
54364 + task->acl_role_id = 0;
54365 + task->acl_sp_role = 0;
54366 +
54367 + if (task->exec_file) {
54368 + cred = __task_cred(task);
54369 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54370 + ret = gr_apply_subject_to_task(task);
54371 + if (ret) {
54372 + read_unlock(&grsec_exec_file_lock);
54373 + read_unlock(&tasklist_lock);
54374 + rcu_read_unlock();
54375 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54376 + return ret;
54377 + }
54378 + } else {
54379 + // it's a kernel process
54380 + task->role = kernel_role;
54381 + task->acl = kernel_role->root_label;
54382 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54383 + task->acl->mode &= ~GR_PROCFIND;
54384 +#endif
54385 + }
54386 + } while_each_thread(task2, task);
54387 + read_unlock(&grsec_exec_file_lock);
54388 + read_unlock(&tasklist_lock);
54389 + rcu_read_unlock();
54390 +
54391 + return 0;
54392 +}
54393 +
54394 +void
54395 +gr_learn_resource(const struct task_struct *task,
54396 + const int res, const unsigned long wanted, const int gt)
54397 +{
54398 + struct acl_subject_label *acl;
54399 + const struct cred *cred;
54400 +
54401 + if (unlikely((gr_status & GR_READY) &&
54402 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54403 + goto skip_reslog;
54404 +
54405 +#ifdef CONFIG_GRKERNSEC_RESLOG
54406 + gr_log_resource(task, res, wanted, gt);
54407 +#endif
54408 + skip_reslog:
54409 +
54410 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54411 + return;
54412 +
54413 + acl = task->acl;
54414 +
54415 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54416 + !(acl->resmask & (1 << (unsigned short) res))))
54417 + return;
54418 +
54419 + if (wanted >= acl->res[res].rlim_cur) {
54420 + unsigned long res_add;
54421 +
54422 + res_add = wanted;
54423 + switch (res) {
54424 + case RLIMIT_CPU:
54425 + res_add += GR_RLIM_CPU_BUMP;
54426 + break;
54427 + case RLIMIT_FSIZE:
54428 + res_add += GR_RLIM_FSIZE_BUMP;
54429 + break;
54430 + case RLIMIT_DATA:
54431 + res_add += GR_RLIM_DATA_BUMP;
54432 + break;
54433 + case RLIMIT_STACK:
54434 + res_add += GR_RLIM_STACK_BUMP;
54435 + break;
54436 + case RLIMIT_CORE:
54437 + res_add += GR_RLIM_CORE_BUMP;
54438 + break;
54439 + case RLIMIT_RSS:
54440 + res_add += GR_RLIM_RSS_BUMP;
54441 + break;
54442 + case RLIMIT_NPROC:
54443 + res_add += GR_RLIM_NPROC_BUMP;
54444 + break;
54445 + case RLIMIT_NOFILE:
54446 + res_add += GR_RLIM_NOFILE_BUMP;
54447 + break;
54448 + case RLIMIT_MEMLOCK:
54449 + res_add += GR_RLIM_MEMLOCK_BUMP;
54450 + break;
54451 + case RLIMIT_AS:
54452 + res_add += GR_RLIM_AS_BUMP;
54453 + break;
54454 + case RLIMIT_LOCKS:
54455 + res_add += GR_RLIM_LOCKS_BUMP;
54456 + break;
54457 + case RLIMIT_SIGPENDING:
54458 + res_add += GR_RLIM_SIGPENDING_BUMP;
54459 + break;
54460 + case RLIMIT_MSGQUEUE:
54461 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54462 + break;
54463 + case RLIMIT_NICE:
54464 + res_add += GR_RLIM_NICE_BUMP;
54465 + break;
54466 + case RLIMIT_RTPRIO:
54467 + res_add += GR_RLIM_RTPRIO_BUMP;
54468 + break;
54469 + case RLIMIT_RTTIME:
54470 + res_add += GR_RLIM_RTTIME_BUMP;
54471 + break;
54472 + }
54473 +
54474 + acl->res[res].rlim_cur = res_add;
54475 +
54476 + if (wanted > acl->res[res].rlim_max)
54477 + acl->res[res].rlim_max = res_add;
54478 +
54479 + /* only log the subject filename, since resource logging is supported for
54480 + single-subject learning only */
54481 + rcu_read_lock();
54482 + cred = __task_cred(task);
54483 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54484 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54485 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54486 + "", (unsigned long) res, &task->signal->saved_ip);
54487 + rcu_read_unlock();
54488 + }
54489 +
54490 + return;
54491 +}
54492 +
54493 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54494 +void
54495 +pax_set_initial_flags(struct linux_binprm *bprm)
54496 +{
54497 + struct task_struct *task = current;
54498 + struct acl_subject_label *proc;
54499 + unsigned long flags;
54500 +
54501 + if (unlikely(!(gr_status & GR_READY)))
54502 + return;
54503 +
54504 + flags = pax_get_flags(task);
54505 +
54506 + proc = task->acl;
54507 +
54508 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54509 + flags &= ~MF_PAX_PAGEEXEC;
54510 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54511 + flags &= ~MF_PAX_SEGMEXEC;
54512 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54513 + flags &= ~MF_PAX_RANDMMAP;
54514 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54515 + flags &= ~MF_PAX_EMUTRAMP;
54516 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54517 + flags &= ~MF_PAX_MPROTECT;
54518 +
54519 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54520 + flags |= MF_PAX_PAGEEXEC;
54521 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54522 + flags |= MF_PAX_SEGMEXEC;
54523 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54524 + flags |= MF_PAX_RANDMMAP;
54525 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54526 + flags |= MF_PAX_EMUTRAMP;
54527 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54528 + flags |= MF_PAX_MPROTECT;
54529 +
54530 + pax_set_flags(task, flags);
54531 +
54532 + return;
54533 +}
54534 +#endif
54535 +
54536 +#ifdef CONFIG_SYSCTL
54537 +/* Eric Biederman likes breaking userland ABI and every inode-based security
54538 + system to save 35kb of memory */
54539 +
54540 +/* we modify the passed in filename, but adjust it back before returning */
54541 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54542 +{
54543 + struct name_entry *nmatch;
54544 + char *p, *lastp = NULL;
54545 + struct acl_object_label *obj = NULL, *tmp;
54546 + struct acl_subject_label *tmpsubj;
54547 + char c = '\0';
54548 +
54549 + read_lock(&gr_inode_lock);
54550 +
54551 + p = name + len - 1;
54552 + do {
54553 + nmatch = lookup_name_entry(name);
54554 + if (lastp != NULL)
54555 + *lastp = c;
54556 +
54557 + if (nmatch == NULL)
54558 + goto next_component;
54559 + tmpsubj = current->acl;
54560 + do {
54561 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54562 + if (obj != NULL) {
54563 + tmp = obj->globbed;
54564 + while (tmp) {
54565 + if (!glob_match(tmp->filename, name)) {
54566 + obj = tmp;
54567 + goto found_obj;
54568 + }
54569 + tmp = tmp->next;
54570 + }
54571 + goto found_obj;
54572 + }
54573 + } while ((tmpsubj = tmpsubj->parent_subject));
54574 +next_component:
54575 + /* end case */
54576 + if (p == name)
54577 + break;
54578 +
54579 + while (*p != '/')
54580 + p--;
54581 + if (p == name)
54582 + lastp = p + 1;
54583 + else {
54584 + lastp = p;
54585 + p--;
54586 + }
54587 + c = *lastp;
54588 + *lastp = '\0';
54589 + } while (1);
54590 +found_obj:
54591 + read_unlock(&gr_inode_lock);
54592 + /* obj returned will always be non-null */
54593 + return obj;
54594 +}
54595 +
54596 +/* returns 0 when allowing, non-zero on error
54597 + op of 0 is used for readdir, so we don't log the names of hidden files
54598 +*/
54599 +__u32
54600 +gr_handle_sysctl(const struct ctl_table *table, const int op)
54601 +{
54602 + struct ctl_table *tmp;
54603 + const char *proc_sys = "/proc/sys";
54604 + char *path;
54605 + struct acl_object_label *obj;
54606 + unsigned short len = 0, pos = 0, depth = 0, i;
54607 + __u32 err = 0;
54608 + __u32 mode = 0;
54609 +
54610 + if (unlikely(!(gr_status & GR_READY)))
54611 + return 0;
54612 +
54613 + /* for now, ignore operations on non-sysctl entries if it's not a
54614 + readdir*/
54615 + if (table->child != NULL && op != 0)
54616 + return 0;
54617 +
54618 + mode |= GR_FIND;
54619 + /* it's only a read if it's an entry, read on dirs is for readdir */
54620 + if (op & MAY_READ)
54621 + mode |= GR_READ;
54622 + if (op & MAY_WRITE)
54623 + mode |= GR_WRITE;
54624 +
54625 + preempt_disable();
54626 +
54627 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54628 +
54629 + /* it's only a read/write if it's an actual entry, not a dir
54630 + (which are opened for readdir)
54631 + */
54632 +
54633 + /* convert the requested sysctl entry into a pathname */
54634 +
54635 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54636 + len += strlen(tmp->procname);
54637 + len++;
54638 + depth++;
54639 + }
54640 +
54641 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54642 + /* deny */
54643 + goto out;
54644 + }
54645 +
54646 + memset(path, 0, PAGE_SIZE);
54647 +
54648 + memcpy(path, proc_sys, strlen(proc_sys));
54649 +
54650 + pos += strlen(proc_sys);
54651 +
54652 + for (; depth > 0; depth--) {
54653 + path[pos] = '/';
54654 + pos++;
54655 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54656 + if (depth == i) {
54657 + memcpy(path + pos, tmp->procname,
54658 + strlen(tmp->procname));
54659 + pos += strlen(tmp->procname);
54660 + }
54661 + i++;
54662 + }
54663 + }
54664 +
54665 + obj = gr_lookup_by_name(path, pos);
54666 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54667 +
54668 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54669 + ((err & mode) != mode))) {
54670 + __u32 new_mode = mode;
54671 +
54672 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54673 +
54674 + err = 0;
54675 + gr_log_learn_sysctl(path, new_mode);
54676 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54677 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54678 + err = -ENOENT;
54679 + } else if (!(err & GR_FIND)) {
54680 + err = -ENOENT;
54681 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54682 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54683 + path, (mode & GR_READ) ? " reading" : "",
54684 + (mode & GR_WRITE) ? " writing" : "");
54685 + err = -EACCES;
54686 + } else if ((err & mode) != mode) {
54687 + err = -EACCES;
54688 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54689 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54690 + path, (mode & GR_READ) ? " reading" : "",
54691 + (mode & GR_WRITE) ? " writing" : "");
54692 + err = 0;
54693 + } else
54694 + err = 0;
54695 +
54696 + out:
54697 + preempt_enable();
54698 +
54699 + return err;
54700 +}
54701 +#endif
54702 +
54703 +int
54704 +gr_handle_proc_ptrace(struct task_struct *task)
54705 +{
54706 + struct file *filp;
54707 + struct task_struct *tmp = task;
54708 + struct task_struct *curtemp = current;
54709 + __u32 retmode;
54710 +
54711 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54712 + if (unlikely(!(gr_status & GR_READY)))
54713 + return 0;
54714 +#endif
54715 +
54716 + read_lock(&tasklist_lock);
54717 + read_lock(&grsec_exec_file_lock);
54718 + filp = task->exec_file;
54719 +
54720 + while (tmp->pid > 0) {
54721 + if (tmp == curtemp)
54722 + break;
54723 + tmp = tmp->real_parent;
54724 + }
54725 +
54726 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54727 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54728 + read_unlock(&grsec_exec_file_lock);
54729 + read_unlock(&tasklist_lock);
54730 + return 1;
54731 + }
54732 +
54733 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54734 + if (!(gr_status & GR_READY)) {
54735 + read_unlock(&grsec_exec_file_lock);
54736 + read_unlock(&tasklist_lock);
54737 + return 0;
54738 + }
54739 +#endif
54740 +
54741 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54742 + read_unlock(&grsec_exec_file_lock);
54743 + read_unlock(&tasklist_lock);
54744 +
54745 + if (retmode & GR_NOPTRACE)
54746 + return 1;
54747 +
54748 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54749 + && (current->acl != task->acl || (current->acl != current->role->root_label
54750 + && current->pid != task->pid)))
54751 + return 1;
54752 +
54753 + return 0;
54754 +}
54755 +
54756 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54757 +{
54758 + if (unlikely(!(gr_status & GR_READY)))
54759 + return;
54760 +
54761 + if (!(current->role->roletype & GR_ROLE_GOD))
54762 + return;
54763 +
54764 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54765 + p->role->rolename, gr_task_roletype_to_char(p),
54766 + p->acl->filename);
54767 +}
54768 +
54769 +int
54770 +gr_handle_ptrace(struct task_struct *task, const long request)
54771 +{
54772 + struct task_struct *tmp = task;
54773 + struct task_struct *curtemp = current;
54774 + __u32 retmode;
54775 +
54776 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54777 + if (unlikely(!(gr_status & GR_READY)))
54778 + return 0;
54779 +#endif
54780 +
54781 + read_lock(&tasklist_lock);
54782 + while (tmp->pid > 0) {
54783 + if (tmp == curtemp)
54784 + break;
54785 + tmp = tmp->real_parent;
54786 + }
54787 +
54788 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54789 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54790 + read_unlock(&tasklist_lock);
54791 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54792 + return 1;
54793 + }
54794 + read_unlock(&tasklist_lock);
54795 +
54796 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54797 + if (!(gr_status & GR_READY))
54798 + return 0;
54799 +#endif
54800 +
54801 + read_lock(&grsec_exec_file_lock);
54802 + if (unlikely(!task->exec_file)) {
54803 + read_unlock(&grsec_exec_file_lock);
54804 + return 0;
54805 + }
54806 +
54807 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54808 + read_unlock(&grsec_exec_file_lock);
54809 +
54810 + if (retmode & GR_NOPTRACE) {
54811 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54812 + return 1;
54813 + }
54814 +
54815 + if (retmode & GR_PTRACERD) {
54816 + switch (request) {
54817 + case PTRACE_SEIZE:
54818 + case PTRACE_POKETEXT:
54819 + case PTRACE_POKEDATA:
54820 + case PTRACE_POKEUSR:
54821 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54822 + case PTRACE_SETREGS:
54823 + case PTRACE_SETFPREGS:
54824 +#endif
54825 +#ifdef CONFIG_X86
54826 + case PTRACE_SETFPXREGS:
54827 +#endif
54828 +#ifdef CONFIG_ALTIVEC
54829 + case PTRACE_SETVRREGS:
54830 +#endif
54831 + return 1;
54832 + default:
54833 + return 0;
54834 + }
54835 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54836 + !(current->role->roletype & GR_ROLE_GOD) &&
54837 + (current->acl != task->acl)) {
54838 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54839 + return 1;
54840 + }
54841 +
54842 + return 0;
54843 +}
54844 +
54845 +static int is_writable_mmap(const struct file *filp)
54846 +{
54847 + struct task_struct *task = current;
54848 + struct acl_object_label *obj, *obj2;
54849 +
54850 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54851 + !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode) && (filp->f_path.mnt != shm_mnt || (filp->f_path.dentry->d_inode->i_nlink > 0))) {
54852 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54853 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54854 + task->role->root_label);
54855 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54856 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54857 + return 1;
54858 + }
54859 + }
54860 + return 0;
54861 +}
54862 +
54863 +int
54864 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54865 +{
54866 + __u32 mode;
54867 +
54868 + if (unlikely(!file || !(prot & PROT_EXEC)))
54869 + return 1;
54870 +
54871 + if (is_writable_mmap(file))
54872 + return 0;
54873 +
54874 + mode =
54875 + gr_search_file(file->f_path.dentry,
54876 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54877 + file->f_path.mnt);
54878 +
54879 + if (!gr_tpe_allow(file))
54880 + return 0;
54881 +
54882 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54883 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54884 + return 0;
54885 + } else if (unlikely(!(mode & GR_EXEC))) {
54886 + return 0;
54887 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54888 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54889 + return 1;
54890 + }
54891 +
54892 + return 1;
54893 +}
54894 +
54895 +int
54896 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54897 +{
54898 + __u32 mode;
54899 +
54900 + if (unlikely(!file || !(prot & PROT_EXEC)))
54901 + return 1;
54902 +
54903 + if (is_writable_mmap(file))
54904 + return 0;
54905 +
54906 + mode =
54907 + gr_search_file(file->f_path.dentry,
54908 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54909 + file->f_path.mnt);
54910 +
54911 + if (!gr_tpe_allow(file))
54912 + return 0;
54913 +
54914 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54915 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54916 + return 0;
54917 + } else if (unlikely(!(mode & GR_EXEC))) {
54918 + return 0;
54919 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54920 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54921 + return 1;
54922 + }
54923 +
54924 + return 1;
54925 +}
54926 +
54927 +void
54928 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54929 +{
54930 + unsigned long runtime;
54931 + unsigned long cputime;
54932 + unsigned int wday, cday;
54933 + __u8 whr, chr;
54934 + __u8 wmin, cmin;
54935 + __u8 wsec, csec;
54936 + struct timespec timeval;
54937 +
54938 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54939 + !(task->acl->mode & GR_PROCACCT)))
54940 + return;
54941 +
54942 + do_posix_clock_monotonic_gettime(&timeval);
54943 + runtime = timeval.tv_sec - task->start_time.tv_sec;
54944 + wday = runtime / (3600 * 24);
54945 + runtime -= wday * (3600 * 24);
54946 + whr = runtime / 3600;
54947 + runtime -= whr * 3600;
54948 + wmin = runtime / 60;
54949 + runtime -= wmin * 60;
54950 + wsec = runtime;
54951 +
54952 + cputime = (task->utime + task->stime) / HZ;
54953 + cday = cputime / (3600 * 24);
54954 + cputime -= cday * (3600 * 24);
54955 + chr = cputime / 3600;
54956 + cputime -= chr * 3600;
54957 + cmin = cputime / 60;
54958 + cputime -= cmin * 60;
54959 + csec = cputime;
54960 +
54961 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54962 +
54963 + return;
54964 +}
54965 +
54966 +void gr_set_kernel_label(struct task_struct *task)
54967 +{
54968 + if (gr_status & GR_READY) {
54969 + task->role = kernel_role;
54970 + task->acl = kernel_role->root_label;
54971 + }
54972 + return;
54973 +}
54974 +
54975 +#ifdef CONFIG_TASKSTATS
54976 +int gr_is_taskstats_denied(int pid)
54977 +{
54978 + struct task_struct *task;
54979 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54980 + const struct cred *cred;
54981 +#endif
54982 + int ret = 0;
54983 +
54984 + /* restrict taskstats viewing to un-chrooted root users
54985 + who have the 'view' subject flag if the RBAC system is enabled
54986 + */
54987 +
54988 + rcu_read_lock();
54989 + read_lock(&tasklist_lock);
54990 + task = find_task_by_vpid(pid);
54991 + if (task) {
54992 +#ifdef CONFIG_GRKERNSEC_CHROOT
54993 + if (proc_is_chrooted(task))
54994 + ret = -EACCES;
54995 +#endif
54996 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54997 + cred = __task_cred(task);
54998 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54999 + if (cred->uid != 0)
55000 + ret = -EACCES;
55001 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55002 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55003 + ret = -EACCES;
55004 +#endif
55005 +#endif
55006 + if (gr_status & GR_READY) {
55007 + if (!(task->acl->mode & GR_VIEW))
55008 + ret = -EACCES;
55009 + }
55010 + } else
55011 + ret = -ENOENT;
55012 +
55013 + read_unlock(&tasklist_lock);
55014 + rcu_read_unlock();
55015 +
55016 + return ret;
55017 +}
55018 +#endif
55019 +
55020 +/* AUXV entries are filled via a descendant of search_binary_handler
55021 + after we've already applied the subject for the target
55022 +*/
55023 +int gr_acl_enable_at_secure(void)
55024 +{
55025 + if (unlikely(!(gr_status & GR_READY)))
55026 + return 0;
55027 +
55028 + if (current->acl->mode & GR_ATSECURE)
55029 + return 1;
55030 +
55031 + return 0;
55032 +}
55033 +
55034 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55035 +{
55036 + struct task_struct *task = current;
55037 + struct dentry *dentry = file->f_path.dentry;
55038 + struct vfsmount *mnt = file->f_path.mnt;
55039 + struct acl_object_label *obj, *tmp;
55040 + struct acl_subject_label *subj;
55041 + unsigned int bufsize;
55042 + int is_not_root;
55043 + char *path;
55044 + dev_t dev = __get_dev(dentry);
55045 +
55046 + if (unlikely(!(gr_status & GR_READY)))
55047 + return 1;
55048 +
55049 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55050 + return 1;
55051 +
55052 + /* ignore Eric Biederman */
55053 + if (IS_PRIVATE(dentry->d_inode))
55054 + return 1;
55055 +
55056 + subj = task->acl;
55057 + do {
55058 + obj = lookup_acl_obj_label(ino, dev, subj);
55059 + if (obj != NULL)
55060 + return (obj->mode & GR_FIND) ? 1 : 0;
55061 + } while ((subj = subj->parent_subject));
55062 +
55063 + /* this is purely an optimization since we're looking for an object
55064 + for the directory we're doing a readdir on
55065 + if it's possible for any globbed object to match the entry we're
55066 + filling into the directory, then the object we find here will be
55067 + an anchor point with attached globbed objects
55068 + */
55069 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55070 + if (obj->globbed == NULL)
55071 + return (obj->mode & GR_FIND) ? 1 : 0;
55072 +
55073 + is_not_root = ((obj->filename[0] == '/') &&
55074 + (obj->filename[1] == '\0')) ? 0 : 1;
55075 + bufsize = PAGE_SIZE - namelen - is_not_root;
55076 +
55077 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55078 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55079 + return 1;
55080 +
55081 + preempt_disable();
55082 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55083 + bufsize);
55084 +
55085 + bufsize = strlen(path);
55086 +
55087 + /* if base is "/", don't append an additional slash */
55088 + if (is_not_root)
55089 + *(path + bufsize) = '/';
55090 + memcpy(path + bufsize + is_not_root, name, namelen);
55091 + *(path + bufsize + namelen + is_not_root) = '\0';
55092 +
55093 + tmp = obj->globbed;
55094 + while (tmp) {
55095 + if (!glob_match(tmp->filename, path)) {
55096 + preempt_enable();
55097 + return (tmp->mode & GR_FIND) ? 1 : 0;
55098 + }
55099 + tmp = tmp->next;
55100 + }
55101 + preempt_enable();
55102 + return (obj->mode & GR_FIND) ? 1 : 0;
55103 +}
55104 +
55105 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55106 +EXPORT_SYMBOL(gr_acl_is_enabled);
55107 +#endif
55108 +EXPORT_SYMBOL(gr_learn_resource);
55109 +EXPORT_SYMBOL(gr_set_kernel_label);
55110 +#ifdef CONFIG_SECURITY
55111 +EXPORT_SYMBOL(gr_check_user_change);
55112 +EXPORT_SYMBOL(gr_check_group_change);
55113 +#endif
55114 +
55115 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55116 new file mode 100644
55117 index 0000000..34fefda
55118 --- /dev/null
55119 +++ b/grsecurity/gracl_alloc.c
55120 @@ -0,0 +1,105 @@
55121 +#include <linux/kernel.h>
55122 +#include <linux/mm.h>
55123 +#include <linux/slab.h>
55124 +#include <linux/vmalloc.h>
55125 +#include <linux/gracl.h>
55126 +#include <linux/grsecurity.h>
55127 +
55128 +static unsigned long alloc_stack_next = 1;
55129 +static unsigned long alloc_stack_size = 1;
55130 +static void **alloc_stack;
55131 +
55132 +static __inline__ int
55133 +alloc_pop(void)
55134 +{
55135 + if (alloc_stack_next == 1)
55136 + return 0;
55137 +
55138 + kfree(alloc_stack[alloc_stack_next - 2]);
55139 +
55140 + alloc_stack_next--;
55141 +
55142 + return 1;
55143 +}
55144 +
55145 +static __inline__ int
55146 +alloc_push(void *buf)
55147 +{
55148 + if (alloc_stack_next >= alloc_stack_size)
55149 + return 1;
55150 +
55151 + alloc_stack[alloc_stack_next - 1] = buf;
55152 +
55153 + alloc_stack_next++;
55154 +
55155 + return 0;
55156 +}
55157 +
55158 +void *
55159 +acl_alloc(unsigned long len)
55160 +{
55161 + void *ret = NULL;
55162 +
55163 + if (!len || len > PAGE_SIZE)
55164 + goto out;
55165 +
55166 + ret = kmalloc(len, GFP_KERNEL);
55167 +
55168 + if (ret) {
55169 + if (alloc_push(ret)) {
55170 + kfree(ret);
55171 + ret = NULL;
55172 + }
55173 + }
55174 +
55175 +out:
55176 + return ret;
55177 +}
55178 +
55179 +void *
55180 +acl_alloc_num(unsigned long num, unsigned long len)
55181 +{
55182 + if (!len || (num > (PAGE_SIZE / len)))
55183 + return NULL;
55184 +
55185 + return acl_alloc(num * len);
55186 +}
55187 +
55188 +void
55189 +acl_free_all(void)
55190 +{
55191 + if (gr_acl_is_enabled() || !alloc_stack)
55192 + return;
55193 +
55194 + while (alloc_pop()) ;
55195 +
55196 + if (alloc_stack) {
55197 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55198 + kfree(alloc_stack);
55199 + else
55200 + vfree(alloc_stack);
55201 + }
55202 +
55203 + alloc_stack = NULL;
55204 + alloc_stack_size = 1;
55205 + alloc_stack_next = 1;
55206 +
55207 + return;
55208 +}
55209 +
55210 +int
55211 +acl_alloc_stack_init(unsigned long size)
55212 +{
55213 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55214 + alloc_stack =
55215 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55216 + else
55217 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55218 +
55219 + alloc_stack_size = size;
55220 +
55221 + if (!alloc_stack)
55222 + return 0;
55223 + else
55224 + return 1;
55225 +}
55226 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55227 new file mode 100644
55228 index 0000000..955ddfb
55229 --- /dev/null
55230 +++ b/grsecurity/gracl_cap.c
55231 @@ -0,0 +1,101 @@
55232 +#include <linux/kernel.h>
55233 +#include <linux/module.h>
55234 +#include <linux/sched.h>
55235 +#include <linux/gracl.h>
55236 +#include <linux/grsecurity.h>
55237 +#include <linux/grinternal.h>
55238 +
55239 +extern const char *captab_log[];
55240 +extern int captab_log_entries;
55241 +
55242 +int
55243 +gr_acl_is_capable(const int cap)
55244 +{
55245 + struct task_struct *task = current;
55246 + const struct cred *cred = current_cred();
55247 + struct acl_subject_label *curracl;
55248 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55249 + kernel_cap_t cap_audit = __cap_empty_set;
55250 +
55251 + if (!gr_acl_is_enabled())
55252 + return 1;
55253 +
55254 + curracl = task->acl;
55255 +
55256 + cap_drop = curracl->cap_lower;
55257 + cap_mask = curracl->cap_mask;
55258 + cap_audit = curracl->cap_invert_audit;
55259 +
55260 + while ((curracl = curracl->parent_subject)) {
55261 + /* if the cap isn't specified in the current computed mask but is specified in the
55262 + current level subject, and is lowered in the current level subject, then add
55263 + it to the set of dropped capabilities
55264 + otherwise, add the current level subject's mask to the current computed mask
55265 + */
55266 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55267 + cap_raise(cap_mask, cap);
55268 + if (cap_raised(curracl->cap_lower, cap))
55269 + cap_raise(cap_drop, cap);
55270 + if (cap_raised(curracl->cap_invert_audit, cap))
55271 + cap_raise(cap_audit, cap);
55272 + }
55273 + }
55274 +
55275 + if (!cap_raised(cap_drop, cap)) {
55276 + if (cap_raised(cap_audit, cap))
55277 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55278 + return 1;
55279 + }
55280 +
55281 + curracl = task->acl;
55282 +
55283 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55284 + && cap_raised(cred->cap_effective, cap)) {
55285 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55286 + task->role->roletype, cred->uid,
55287 + cred->gid, task->exec_file ?
55288 + gr_to_filename(task->exec_file->f_path.dentry,
55289 + task->exec_file->f_path.mnt) : curracl->filename,
55290 + curracl->filename, 0UL,
55291 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55292 + return 1;
55293 + }
55294 +
55295 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55296 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55297 + return 0;
55298 +}
55299 +
55300 +int
55301 +gr_acl_is_capable_nolog(const int cap)
55302 +{
55303 + struct acl_subject_label *curracl;
55304 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55305 +
55306 + if (!gr_acl_is_enabled())
55307 + return 1;
55308 +
55309 + curracl = current->acl;
55310 +
55311 + cap_drop = curracl->cap_lower;
55312 + cap_mask = curracl->cap_mask;
55313 +
55314 + while ((curracl = curracl->parent_subject)) {
55315 + /* if the cap isn't specified in the current computed mask but is specified in the
55316 + current level subject, and is lowered in the current level subject, then add
55317 + it to the set of dropped capabilities
55318 + otherwise, add the current level subject's mask to the current computed mask
55319 + */
55320 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55321 + cap_raise(cap_mask, cap);
55322 + if (cap_raised(curracl->cap_lower, cap))
55323 + cap_raise(cap_drop, cap);
55324 + }
55325 + }
55326 +
55327 + if (!cap_raised(cap_drop, cap))
55328 + return 1;
55329 +
55330 + return 0;
55331 +}
55332 +
55333 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55334 new file mode 100644
55335 index 0000000..4eda5c3
55336 --- /dev/null
55337 +++ b/grsecurity/gracl_fs.c
55338 @@ -0,0 +1,433 @@
55339 +#include <linux/kernel.h>
55340 +#include <linux/sched.h>
55341 +#include <linux/types.h>
55342 +#include <linux/fs.h>
55343 +#include <linux/file.h>
55344 +#include <linux/stat.h>
55345 +#include <linux/grsecurity.h>
55346 +#include <linux/grinternal.h>
55347 +#include <linux/gracl.h>
55348 +
55349 +__u32
55350 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55351 + const struct vfsmount * mnt)
55352 +{
55353 + __u32 mode;
55354 +
55355 + if (unlikely(!dentry->d_inode))
55356 + return GR_FIND;
55357 +
55358 + mode =
55359 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55360 +
55361 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55362 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55363 + return mode;
55364 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55365 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55366 + return 0;
55367 + } else if (unlikely(!(mode & GR_FIND)))
55368 + return 0;
55369 +
55370 + return GR_FIND;
55371 +}
55372 +
55373 +__u32
55374 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55375 + int acc_mode)
55376 +{
55377 + __u32 reqmode = GR_FIND;
55378 + __u32 mode;
55379 +
55380 + if (unlikely(!dentry->d_inode))
55381 + return reqmode;
55382 +
55383 + if (acc_mode & MAY_APPEND)
55384 + reqmode |= GR_APPEND;
55385 + else if (acc_mode & MAY_WRITE)
55386 + reqmode |= GR_WRITE;
55387 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55388 + reqmode |= GR_READ;
55389 +
55390 + mode =
55391 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55392 + mnt);
55393 +
55394 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55395 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55396 + reqmode & GR_READ ? " reading" : "",
55397 + reqmode & GR_WRITE ? " writing" : reqmode &
55398 + GR_APPEND ? " appending" : "");
55399 + return reqmode;
55400 + } else
55401 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55402 + {
55403 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55404 + reqmode & GR_READ ? " reading" : "",
55405 + reqmode & GR_WRITE ? " writing" : reqmode &
55406 + GR_APPEND ? " appending" : "");
55407 + return 0;
55408 + } else if (unlikely((mode & reqmode) != reqmode))
55409 + return 0;
55410 +
55411 + return reqmode;
55412 +}
55413 +
55414 +__u32
55415 +gr_acl_handle_creat(const struct dentry * dentry,
55416 + const struct dentry * p_dentry,
55417 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55418 + const int imode)
55419 +{
55420 + __u32 reqmode = GR_WRITE | GR_CREATE;
55421 + __u32 mode;
55422 +
55423 + if (acc_mode & MAY_APPEND)
55424 + reqmode |= GR_APPEND;
55425 + // if a directory was required or the directory already exists, then
55426 + // don't count this open as a read
55427 + if ((acc_mode & MAY_READ) &&
55428 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55429 + reqmode |= GR_READ;
55430 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55431 + reqmode |= GR_SETID;
55432 +
55433 + mode =
55434 + gr_check_create(dentry, p_dentry, p_mnt,
55435 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55436 +
55437 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55438 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55439 + reqmode & GR_READ ? " reading" : "",
55440 + reqmode & GR_WRITE ? " writing" : reqmode &
55441 + GR_APPEND ? " appending" : "");
55442 + return reqmode;
55443 + } else
55444 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55445 + {
55446 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55447 + reqmode & GR_READ ? " reading" : "",
55448 + reqmode & GR_WRITE ? " writing" : reqmode &
55449 + GR_APPEND ? " appending" : "");
55450 + return 0;
55451 + } else if (unlikely((mode & reqmode) != reqmode))
55452 + return 0;
55453 +
55454 + return reqmode;
55455 +}
55456 +
55457 +__u32
55458 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55459 + const int fmode)
55460 +{
55461 + __u32 mode, reqmode = GR_FIND;
55462 +
55463 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55464 + reqmode |= GR_EXEC;
55465 + if (fmode & S_IWOTH)
55466 + reqmode |= GR_WRITE;
55467 + if (fmode & S_IROTH)
55468 + reqmode |= GR_READ;
55469 +
55470 + mode =
55471 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55472 + mnt);
55473 +
55474 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55475 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55476 + reqmode & GR_READ ? " reading" : "",
55477 + reqmode & GR_WRITE ? " writing" : "",
55478 + reqmode & GR_EXEC ? " executing" : "");
55479 + return reqmode;
55480 + } else
55481 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55482 + {
55483 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55484 + reqmode & GR_READ ? " reading" : "",
55485 + reqmode & GR_WRITE ? " writing" : "",
55486 + reqmode & GR_EXEC ? " executing" : "");
55487 + return 0;
55488 + } else if (unlikely((mode & reqmode) != reqmode))
55489 + return 0;
55490 +
55491 + return reqmode;
55492 +}
55493 +
55494 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55495 +{
55496 + __u32 mode;
55497 +
55498 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55499 +
55500 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55501 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55502 + return mode;
55503 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55504 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55505 + return 0;
55506 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55507 + return 0;
55508 +
55509 + return (reqmode);
55510 +}
55511 +
55512 +__u32
55513 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55514 +{
55515 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55516 +}
55517 +
55518 +__u32
55519 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55520 +{
55521 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55522 +}
55523 +
55524 +__u32
55525 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55526 +{
55527 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55528 +}
55529 +
55530 +__u32
55531 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55532 +{
55533 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55534 +}
55535 +
55536 +__u32
55537 +gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
55538 + mode_t mode)
55539 +{
55540 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55541 + return 1;
55542 +
55543 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55544 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55545 + GR_FCHMOD_ACL_MSG);
55546 + } else {
55547 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
55548 + }
55549 +}
55550 +
55551 +__u32
55552 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55553 + mode_t mode)
55554 +{
55555 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55556 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55557 + GR_CHMOD_ACL_MSG);
55558 + } else {
55559 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55560 + }
55561 +}
55562 +
55563 +__u32
55564 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55565 +{
55566 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55567 +}
55568 +
55569 +__u32
55570 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55571 +{
55572 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55573 +}
55574 +
55575 +__u32
55576 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55577 +{
55578 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55579 +}
55580 +
55581 +__u32
55582 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55583 +{
55584 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55585 + GR_UNIXCONNECT_ACL_MSG);
55586 +}
55587 +
55588 +/* hardlinks require at minimum create and link permission,
55589 + any additional privilege required is based on the
55590 + privilege of the file being linked to
55591 +*/
55592 +__u32
55593 +gr_acl_handle_link(const struct dentry * new_dentry,
55594 + const struct dentry * parent_dentry,
55595 + const struct vfsmount * parent_mnt,
55596 + const struct dentry * old_dentry,
55597 + const struct vfsmount * old_mnt, const char *to)
55598 +{
55599 + __u32 mode;
55600 + __u32 needmode = GR_CREATE | GR_LINK;
55601 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55602 +
55603 + mode =
55604 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55605 + old_mnt);
55606 +
55607 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55608 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55609 + return mode;
55610 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55611 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55612 + return 0;
55613 + } else if (unlikely((mode & needmode) != needmode))
55614 + return 0;
55615 +
55616 + return 1;
55617 +}
55618 +
55619 +__u32
55620 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55621 + const struct dentry * parent_dentry,
55622 + const struct vfsmount * parent_mnt, const char *from)
55623 +{
55624 + __u32 needmode = GR_WRITE | GR_CREATE;
55625 + __u32 mode;
55626 +
55627 + mode =
55628 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55629 + GR_CREATE | GR_AUDIT_CREATE |
55630 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55631 +
55632 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55633 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55634 + return mode;
55635 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55636 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55637 + return 0;
55638 + } else if (unlikely((mode & needmode) != needmode))
55639 + return 0;
55640 +
55641 + return (GR_WRITE | GR_CREATE);
55642 +}
55643 +
55644 +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)
55645 +{
55646 + __u32 mode;
55647 +
55648 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55649 +
55650 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55651 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55652 + return mode;
55653 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55654 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55655 + return 0;
55656 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55657 + return 0;
55658 +
55659 + return (reqmode);
55660 +}
55661 +
55662 +__u32
55663 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55664 + const struct dentry * parent_dentry,
55665 + const struct vfsmount * parent_mnt,
55666 + const int mode)
55667 +{
55668 + __u32 reqmode = GR_WRITE | GR_CREATE;
55669 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55670 + reqmode |= GR_SETID;
55671 +
55672 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55673 + reqmode, GR_MKNOD_ACL_MSG);
55674 +}
55675 +
55676 +__u32
55677 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55678 + const struct dentry *parent_dentry,
55679 + const struct vfsmount *parent_mnt)
55680 +{
55681 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55682 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55683 +}
55684 +
55685 +#define RENAME_CHECK_SUCCESS(old, new) \
55686 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55687 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55688 +
55689 +int
55690 +gr_acl_handle_rename(struct dentry *new_dentry,
55691 + struct dentry *parent_dentry,
55692 + const struct vfsmount *parent_mnt,
55693 + struct dentry *old_dentry,
55694 + struct inode *old_parent_inode,
55695 + struct vfsmount *old_mnt, const char *newname)
55696 +{
55697 + __u32 comp1, comp2;
55698 + int error = 0;
55699 +
55700 + if (unlikely(!gr_acl_is_enabled()))
55701 + return 0;
55702 +
55703 + if (!new_dentry->d_inode) {
55704 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55705 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55706 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55707 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55708 + GR_DELETE | GR_AUDIT_DELETE |
55709 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55710 + GR_SUPPRESS, old_mnt);
55711 + } else {
55712 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55713 + GR_CREATE | GR_DELETE |
55714 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55715 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55716 + GR_SUPPRESS, parent_mnt);
55717 + comp2 =
55718 + gr_search_file(old_dentry,
55719 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55720 + GR_DELETE | GR_AUDIT_DELETE |
55721 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55722 + }
55723 +
55724 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55725 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55726 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55727 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55728 + && !(comp2 & GR_SUPPRESS)) {
55729 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55730 + error = -EACCES;
55731 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55732 + error = -EACCES;
55733 +
55734 + return error;
55735 +}
55736 +
55737 +void
55738 +gr_acl_handle_exit(void)
55739 +{
55740 + u16 id;
55741 + char *rolename;
55742 + struct file *exec_file;
55743 +
55744 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55745 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55746 + id = current->acl_role_id;
55747 + rolename = current->role->rolename;
55748 + gr_set_acls(1);
55749 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55750 + }
55751 +
55752 + write_lock(&grsec_exec_file_lock);
55753 + exec_file = current->exec_file;
55754 + current->exec_file = NULL;
55755 + write_unlock(&grsec_exec_file_lock);
55756 +
55757 + if (exec_file)
55758 + fput(exec_file);
55759 +}
55760 +
55761 +int
55762 +gr_acl_handle_procpidmem(const struct task_struct *task)
55763 +{
55764 + if (unlikely(!gr_acl_is_enabled()))
55765 + return 0;
55766 +
55767 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55768 + return -EACCES;
55769 +
55770 + return 0;
55771 +}
55772 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55773 new file mode 100644
55774 index 0000000..17050ca
55775 --- /dev/null
55776 +++ b/grsecurity/gracl_ip.c
55777 @@ -0,0 +1,381 @@
55778 +#include <linux/kernel.h>
55779 +#include <asm/uaccess.h>
55780 +#include <asm/errno.h>
55781 +#include <net/sock.h>
55782 +#include <linux/file.h>
55783 +#include <linux/fs.h>
55784 +#include <linux/net.h>
55785 +#include <linux/in.h>
55786 +#include <linux/skbuff.h>
55787 +#include <linux/ip.h>
55788 +#include <linux/udp.h>
55789 +#include <linux/types.h>
55790 +#include <linux/sched.h>
55791 +#include <linux/netdevice.h>
55792 +#include <linux/inetdevice.h>
55793 +#include <linux/gracl.h>
55794 +#include <linux/grsecurity.h>
55795 +#include <linux/grinternal.h>
55796 +
55797 +#define GR_BIND 0x01
55798 +#define GR_CONNECT 0x02
55799 +#define GR_INVERT 0x04
55800 +#define GR_BINDOVERRIDE 0x08
55801 +#define GR_CONNECTOVERRIDE 0x10
55802 +#define GR_SOCK_FAMILY 0x20
55803 +
55804 +static const char * gr_protocols[IPPROTO_MAX] = {
55805 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55806 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55807 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55808 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55809 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55810 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55811 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55812 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55813 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55814 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55815 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55816 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55817 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55818 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55819 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55820 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55821 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55822 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55823 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55824 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55825 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55826 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55827 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55828 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55829 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55830 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55831 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55832 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55833 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55834 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55835 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55836 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55837 + };
55838 +
55839 +static const char * gr_socktypes[SOCK_MAX] = {
55840 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55841 + "unknown:7", "unknown:8", "unknown:9", "packet"
55842 + };
55843 +
55844 +static const char * gr_sockfamilies[AF_MAX+1] = {
55845 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55846 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55847 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55848 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55849 + };
55850 +
55851 +const char *
55852 +gr_proto_to_name(unsigned char proto)
55853 +{
55854 + return gr_protocols[proto];
55855 +}
55856 +
55857 +const char *
55858 +gr_socktype_to_name(unsigned char type)
55859 +{
55860 + return gr_socktypes[type];
55861 +}
55862 +
55863 +const char *
55864 +gr_sockfamily_to_name(unsigned char family)
55865 +{
55866 + return gr_sockfamilies[family];
55867 +}
55868 +
55869 +int
55870 +gr_search_socket(const int domain, const int type, const int protocol)
55871 +{
55872 + struct acl_subject_label *curr;
55873 + const struct cred *cred = current_cred();
55874 +
55875 + if (unlikely(!gr_acl_is_enabled()))
55876 + goto exit;
55877 +
55878 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
55879 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55880 + goto exit; // let the kernel handle it
55881 +
55882 + curr = current->acl;
55883 +
55884 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55885 + /* the family is allowed, if this is PF_INET allow it only if
55886 + the extra sock type/protocol checks pass */
55887 + if (domain == PF_INET)
55888 + goto inet_check;
55889 + goto exit;
55890 + } else {
55891 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55892 + __u32 fakeip = 0;
55893 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55894 + current->role->roletype, cred->uid,
55895 + cred->gid, current->exec_file ?
55896 + gr_to_filename(current->exec_file->f_path.dentry,
55897 + current->exec_file->f_path.mnt) :
55898 + curr->filename, curr->filename,
55899 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55900 + &current->signal->saved_ip);
55901 + goto exit;
55902 + }
55903 + goto exit_fail;
55904 + }
55905 +
55906 +inet_check:
55907 + /* the rest of this checking is for IPv4 only */
55908 + if (!curr->ips)
55909 + goto exit;
55910 +
55911 + if ((curr->ip_type & (1 << type)) &&
55912 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55913 + goto exit;
55914 +
55915 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55916 + /* we don't place acls on raw sockets , and sometimes
55917 + dgram/ip sockets are opened for ioctl and not
55918 + bind/connect, so we'll fake a bind learn log */
55919 + if (type == SOCK_RAW || type == SOCK_PACKET) {
55920 + __u32 fakeip = 0;
55921 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55922 + current->role->roletype, cred->uid,
55923 + cred->gid, current->exec_file ?
55924 + gr_to_filename(current->exec_file->f_path.dentry,
55925 + current->exec_file->f_path.mnt) :
55926 + curr->filename, curr->filename,
55927 + &fakeip, 0, type,
55928 + protocol, GR_CONNECT, &current->signal->saved_ip);
55929 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55930 + __u32 fakeip = 0;
55931 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55932 + current->role->roletype, cred->uid,
55933 + cred->gid, current->exec_file ?
55934 + gr_to_filename(current->exec_file->f_path.dentry,
55935 + current->exec_file->f_path.mnt) :
55936 + curr->filename, curr->filename,
55937 + &fakeip, 0, type,
55938 + protocol, GR_BIND, &current->signal->saved_ip);
55939 + }
55940 + /* we'll log when they use connect or bind */
55941 + goto exit;
55942 + }
55943 +
55944 +exit_fail:
55945 + if (domain == PF_INET)
55946 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55947 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
55948 + else
55949 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55950 + gr_socktype_to_name(type), protocol);
55951 +
55952 + return 0;
55953 +exit:
55954 + return 1;
55955 +}
55956 +
55957 +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)
55958 +{
55959 + if ((ip->mode & mode) &&
55960 + (ip_port >= ip->low) &&
55961 + (ip_port <= ip->high) &&
55962 + ((ntohl(ip_addr) & our_netmask) ==
55963 + (ntohl(our_addr) & our_netmask))
55964 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55965 + && (ip->type & (1 << type))) {
55966 + if (ip->mode & GR_INVERT)
55967 + return 2; // specifically denied
55968 + else
55969 + return 1; // allowed
55970 + }
55971 +
55972 + return 0; // not specifically allowed, may continue parsing
55973 +}
55974 +
55975 +static int
55976 +gr_search_connectbind(const int full_mode, struct sock *sk,
55977 + struct sockaddr_in *addr, const int type)
55978 +{
55979 + char iface[IFNAMSIZ] = {0};
55980 + struct acl_subject_label *curr;
55981 + struct acl_ip_label *ip;
55982 + struct inet_sock *isk;
55983 + struct net_device *dev;
55984 + struct in_device *idev;
55985 + unsigned long i;
55986 + int ret;
55987 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55988 + __u32 ip_addr = 0;
55989 + __u32 our_addr;
55990 + __u32 our_netmask;
55991 + char *p;
55992 + __u16 ip_port = 0;
55993 + const struct cred *cred = current_cred();
55994 +
55995 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55996 + return 0;
55997 +
55998 + curr = current->acl;
55999 + isk = inet_sk(sk);
56000 +
56001 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56002 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56003 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56004 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56005 + struct sockaddr_in saddr;
56006 + int err;
56007 +
56008 + saddr.sin_family = AF_INET;
56009 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56010 + saddr.sin_port = isk->inet_sport;
56011 +
56012 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56013 + if (err)
56014 + return err;
56015 +
56016 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56017 + if (err)
56018 + return err;
56019 + }
56020 +
56021 + if (!curr->ips)
56022 + return 0;
56023 +
56024 + ip_addr = addr->sin_addr.s_addr;
56025 + ip_port = ntohs(addr->sin_port);
56026 +
56027 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56028 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56029 + current->role->roletype, cred->uid,
56030 + cred->gid, current->exec_file ?
56031 + gr_to_filename(current->exec_file->f_path.dentry,
56032 + current->exec_file->f_path.mnt) :
56033 + curr->filename, curr->filename,
56034 + &ip_addr, ip_port, type,
56035 + sk->sk_protocol, mode, &current->signal->saved_ip);
56036 + return 0;
56037 + }
56038 +
56039 + for (i = 0; i < curr->ip_num; i++) {
56040 + ip = *(curr->ips + i);
56041 + if (ip->iface != NULL) {
56042 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56043 + p = strchr(iface, ':');
56044 + if (p != NULL)
56045 + *p = '\0';
56046 + dev = dev_get_by_name(sock_net(sk), iface);
56047 + if (dev == NULL)
56048 + continue;
56049 + idev = in_dev_get(dev);
56050 + if (idev == NULL) {
56051 + dev_put(dev);
56052 + continue;
56053 + }
56054 + rcu_read_lock();
56055 + for_ifa(idev) {
56056 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56057 + our_addr = ifa->ifa_address;
56058 + our_netmask = 0xffffffff;
56059 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56060 + if (ret == 1) {
56061 + rcu_read_unlock();
56062 + in_dev_put(idev);
56063 + dev_put(dev);
56064 + return 0;
56065 + } else if (ret == 2) {
56066 + rcu_read_unlock();
56067 + in_dev_put(idev);
56068 + dev_put(dev);
56069 + goto denied;
56070 + }
56071 + }
56072 + } endfor_ifa(idev);
56073 + rcu_read_unlock();
56074 + in_dev_put(idev);
56075 + dev_put(dev);
56076 + } else {
56077 + our_addr = ip->addr;
56078 + our_netmask = ip->netmask;
56079 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56080 + if (ret == 1)
56081 + return 0;
56082 + else if (ret == 2)
56083 + goto denied;
56084 + }
56085 + }
56086 +
56087 +denied:
56088 + if (mode == GR_BIND)
56089 + gr_log_int5_str2(GR_DONT_AUDIT, GR_BIND_ACL_MSG, &ip_addr, ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
56090 + else if (mode == GR_CONNECT)
56091 + gr_log_int5_str2(GR_DONT_AUDIT, GR_CONNECT_ACL_MSG, &ip_addr, ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
56092 +
56093 + return -EACCES;
56094 +}
56095 +
56096 +int
56097 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56098 +{
56099 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56100 +}
56101 +
56102 +int
56103 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56104 +{
56105 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56106 +}
56107 +
56108 +int gr_search_listen(struct socket *sock)
56109 +{
56110 + struct sock *sk = sock->sk;
56111 + struct sockaddr_in addr;
56112 +
56113 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56114 + addr.sin_port = inet_sk(sk)->inet_sport;
56115 +
56116 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56117 +}
56118 +
56119 +int gr_search_accept(struct socket *sock)
56120 +{
56121 + struct sock *sk = sock->sk;
56122 + struct sockaddr_in addr;
56123 +
56124 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56125 + addr.sin_port = inet_sk(sk)->inet_sport;
56126 +
56127 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56128 +}
56129 +
56130 +int
56131 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56132 +{
56133 + if (addr)
56134 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56135 + else {
56136 + struct sockaddr_in sin;
56137 + const struct inet_sock *inet = inet_sk(sk);
56138 +
56139 + sin.sin_addr.s_addr = inet->inet_daddr;
56140 + sin.sin_port = inet->inet_dport;
56141 +
56142 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56143 + }
56144 +}
56145 +
56146 +int
56147 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56148 +{
56149 + struct sockaddr_in sin;
56150 +
56151 + if (unlikely(skb->len < sizeof (struct udphdr)))
56152 + return 0; // skip this packet
56153 +
56154 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56155 + sin.sin_port = udp_hdr(skb)->source;
56156 +
56157 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56158 +}
56159 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56160 new file mode 100644
56161 index 0000000..25f54ef
56162 --- /dev/null
56163 +++ b/grsecurity/gracl_learn.c
56164 @@ -0,0 +1,207 @@
56165 +#include <linux/kernel.h>
56166 +#include <linux/mm.h>
56167 +#include <linux/sched.h>
56168 +#include <linux/poll.h>
56169 +#include <linux/string.h>
56170 +#include <linux/file.h>
56171 +#include <linux/types.h>
56172 +#include <linux/vmalloc.h>
56173 +#include <linux/grinternal.h>
56174 +
56175 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56176 + size_t count, loff_t *ppos);
56177 +extern int gr_acl_is_enabled(void);
56178 +
56179 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56180 +static int gr_learn_attached;
56181 +
56182 +/* use a 512k buffer */
56183 +#define LEARN_BUFFER_SIZE (512 * 1024)
56184 +
56185 +static DEFINE_SPINLOCK(gr_learn_lock);
56186 +static DEFINE_MUTEX(gr_learn_user_mutex);
56187 +
56188 +/* we need to maintain two buffers, so that the kernel context of grlearn
56189 + uses a semaphore around the userspace copying, and the other kernel contexts
56190 + use a spinlock when copying into the buffer, since they cannot sleep
56191 +*/
56192 +static char *learn_buffer;
56193 +static char *learn_buffer_user;
56194 +static int learn_buffer_len;
56195 +static int learn_buffer_user_len;
56196 +
56197 +static ssize_t
56198 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56199 +{
56200 + DECLARE_WAITQUEUE(wait, current);
56201 + ssize_t retval = 0;
56202 +
56203 + add_wait_queue(&learn_wait, &wait);
56204 + set_current_state(TASK_INTERRUPTIBLE);
56205 + do {
56206 + mutex_lock(&gr_learn_user_mutex);
56207 + spin_lock(&gr_learn_lock);
56208 + if (learn_buffer_len)
56209 + break;
56210 + spin_unlock(&gr_learn_lock);
56211 + mutex_unlock(&gr_learn_user_mutex);
56212 + if (file->f_flags & O_NONBLOCK) {
56213 + retval = -EAGAIN;
56214 + goto out;
56215 + }
56216 + if (signal_pending(current)) {
56217 + retval = -ERESTARTSYS;
56218 + goto out;
56219 + }
56220 +
56221 + schedule();
56222 + } while (1);
56223 +
56224 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56225 + learn_buffer_user_len = learn_buffer_len;
56226 + retval = learn_buffer_len;
56227 + learn_buffer_len = 0;
56228 +
56229 + spin_unlock(&gr_learn_lock);
56230 +
56231 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56232 + retval = -EFAULT;
56233 +
56234 + mutex_unlock(&gr_learn_user_mutex);
56235 +out:
56236 + set_current_state(TASK_RUNNING);
56237 + remove_wait_queue(&learn_wait, &wait);
56238 + return retval;
56239 +}
56240 +
56241 +static unsigned int
56242 +poll_learn(struct file * file, poll_table * wait)
56243 +{
56244 + poll_wait(file, &learn_wait, wait);
56245 +
56246 + if (learn_buffer_len)
56247 + return (POLLIN | POLLRDNORM);
56248 +
56249 + return 0;
56250 +}
56251 +
56252 +void
56253 +gr_clear_learn_entries(void)
56254 +{
56255 + char *tmp;
56256 +
56257 + mutex_lock(&gr_learn_user_mutex);
56258 + spin_lock(&gr_learn_lock);
56259 + tmp = learn_buffer;
56260 + learn_buffer = NULL;
56261 + spin_unlock(&gr_learn_lock);
56262 + if (tmp)
56263 + vfree(tmp);
56264 + if (learn_buffer_user != NULL) {
56265 + vfree(learn_buffer_user);
56266 + learn_buffer_user = NULL;
56267 + }
56268 + learn_buffer_len = 0;
56269 + mutex_unlock(&gr_learn_user_mutex);
56270 +
56271 + return;
56272 +}
56273 +
56274 +void
56275 +gr_add_learn_entry(const char *fmt, ...)
56276 +{
56277 + va_list args;
56278 + unsigned int len;
56279 +
56280 + if (!gr_learn_attached)
56281 + return;
56282 +
56283 + spin_lock(&gr_learn_lock);
56284 +
56285 + /* leave a gap at the end so we know when it's "full" but don't have to
56286 + compute the exact length of the string we're trying to append
56287 + */
56288 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56289 + spin_unlock(&gr_learn_lock);
56290 + wake_up_interruptible(&learn_wait);
56291 + return;
56292 + }
56293 + if (learn_buffer == NULL) {
56294 + spin_unlock(&gr_learn_lock);
56295 + return;
56296 + }
56297 +
56298 + va_start(args, fmt);
56299 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56300 + va_end(args);
56301 +
56302 + learn_buffer_len += len + 1;
56303 +
56304 + spin_unlock(&gr_learn_lock);
56305 + wake_up_interruptible(&learn_wait);
56306 +
56307 + return;
56308 +}
56309 +
56310 +static int
56311 +open_learn(struct inode *inode, struct file *file)
56312 +{
56313 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56314 + return -EBUSY;
56315 + if (file->f_mode & FMODE_READ) {
56316 + int retval = 0;
56317 + mutex_lock(&gr_learn_user_mutex);
56318 + if (learn_buffer == NULL)
56319 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56320 + if (learn_buffer_user == NULL)
56321 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56322 + if (learn_buffer == NULL) {
56323 + retval = -ENOMEM;
56324 + goto out_error;
56325 + }
56326 + if (learn_buffer_user == NULL) {
56327 + retval = -ENOMEM;
56328 + goto out_error;
56329 + }
56330 + learn_buffer_len = 0;
56331 + learn_buffer_user_len = 0;
56332 + gr_learn_attached = 1;
56333 +out_error:
56334 + mutex_unlock(&gr_learn_user_mutex);
56335 + return retval;
56336 + }
56337 + return 0;
56338 +}
56339 +
56340 +static int
56341 +close_learn(struct inode *inode, struct file *file)
56342 +{
56343 + if (file->f_mode & FMODE_READ) {
56344 + char *tmp = NULL;
56345 + mutex_lock(&gr_learn_user_mutex);
56346 + spin_lock(&gr_learn_lock);
56347 + tmp = learn_buffer;
56348 + learn_buffer = NULL;
56349 + spin_unlock(&gr_learn_lock);
56350 + if (tmp)
56351 + vfree(tmp);
56352 + if (learn_buffer_user != NULL) {
56353 + vfree(learn_buffer_user);
56354 + learn_buffer_user = NULL;
56355 + }
56356 + learn_buffer_len = 0;
56357 + learn_buffer_user_len = 0;
56358 + gr_learn_attached = 0;
56359 + mutex_unlock(&gr_learn_user_mutex);
56360 + }
56361 +
56362 + return 0;
56363 +}
56364 +
56365 +const struct file_operations grsec_fops = {
56366 + .read = read_learn,
56367 + .write = write_grsec_handler,
56368 + .open = open_learn,
56369 + .release = close_learn,
56370 + .poll = poll_learn,
56371 +};
56372 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56373 new file mode 100644
56374 index 0000000..39645c9
56375 --- /dev/null
56376 +++ b/grsecurity/gracl_res.c
56377 @@ -0,0 +1,68 @@
56378 +#include <linux/kernel.h>
56379 +#include <linux/sched.h>
56380 +#include <linux/gracl.h>
56381 +#include <linux/grinternal.h>
56382 +
56383 +static const char *restab_log[] = {
56384 + [RLIMIT_CPU] = "RLIMIT_CPU",
56385 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56386 + [RLIMIT_DATA] = "RLIMIT_DATA",
56387 + [RLIMIT_STACK] = "RLIMIT_STACK",
56388 + [RLIMIT_CORE] = "RLIMIT_CORE",
56389 + [RLIMIT_RSS] = "RLIMIT_RSS",
56390 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56391 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56392 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56393 + [RLIMIT_AS] = "RLIMIT_AS",
56394 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56395 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56396 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56397 + [RLIMIT_NICE] = "RLIMIT_NICE",
56398 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56399 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56400 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56401 +};
56402 +
56403 +void
56404 +gr_log_resource(const struct task_struct *task,
56405 + const int res, const unsigned long wanted, const int gt)
56406 +{
56407 + const struct cred *cred;
56408 + unsigned long rlim;
56409 +
56410 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56411 + return;
56412 +
56413 + // not yet supported resource
56414 + if (unlikely(!restab_log[res]))
56415 + return;
56416 +
56417 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56418 + rlim = task_rlimit_max(task, res);
56419 + else
56420 + rlim = task_rlimit(task, res);
56421 +
56422 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56423 + return;
56424 +
56425 + rcu_read_lock();
56426 + cred = __task_cred(task);
56427 +
56428 + if (res == RLIMIT_NPROC &&
56429 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56430 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56431 + goto out_rcu_unlock;
56432 + else if (res == RLIMIT_MEMLOCK &&
56433 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56434 + goto out_rcu_unlock;
56435 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56436 + goto out_rcu_unlock;
56437 + rcu_read_unlock();
56438 +
56439 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56440 +
56441 + return;
56442 +out_rcu_unlock:
56443 + rcu_read_unlock();
56444 + return;
56445 +}
56446 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56447 new file mode 100644
56448 index 0000000..5556be3
56449 --- /dev/null
56450 +++ b/grsecurity/gracl_segv.c
56451 @@ -0,0 +1,299 @@
56452 +#include <linux/kernel.h>
56453 +#include <linux/mm.h>
56454 +#include <asm/uaccess.h>
56455 +#include <asm/errno.h>
56456 +#include <asm/mman.h>
56457 +#include <net/sock.h>
56458 +#include <linux/file.h>
56459 +#include <linux/fs.h>
56460 +#include <linux/net.h>
56461 +#include <linux/in.h>
56462 +#include <linux/slab.h>
56463 +#include <linux/types.h>
56464 +#include <linux/sched.h>
56465 +#include <linux/timer.h>
56466 +#include <linux/gracl.h>
56467 +#include <linux/grsecurity.h>
56468 +#include <linux/grinternal.h>
56469 +
56470 +static struct crash_uid *uid_set;
56471 +static unsigned short uid_used;
56472 +static DEFINE_SPINLOCK(gr_uid_lock);
56473 +extern rwlock_t gr_inode_lock;
56474 +extern struct acl_subject_label *
56475 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56476 + struct acl_role_label *role);
56477 +
56478 +#ifdef CONFIG_BTRFS_FS
56479 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56480 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56481 +#endif
56482 +
56483 +static inline dev_t __get_dev(const struct dentry *dentry)
56484 +{
56485 +#ifdef CONFIG_BTRFS_FS
56486 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56487 + return get_btrfs_dev_from_inode(dentry->d_inode);
56488 + else
56489 +#endif
56490 + return dentry->d_inode->i_sb->s_dev;
56491 +}
56492 +
56493 +int
56494 +gr_init_uidset(void)
56495 +{
56496 + uid_set =
56497 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56498 + uid_used = 0;
56499 +
56500 + return uid_set ? 1 : 0;
56501 +}
56502 +
56503 +void
56504 +gr_free_uidset(void)
56505 +{
56506 + if (uid_set)
56507 + kfree(uid_set);
56508 +
56509 + return;
56510 +}
56511 +
56512 +int
56513 +gr_find_uid(const uid_t uid)
56514 +{
56515 + struct crash_uid *tmp = uid_set;
56516 + uid_t buid;
56517 + int low = 0, high = uid_used - 1, mid;
56518 +
56519 + while (high >= low) {
56520 + mid = (low + high) >> 1;
56521 + buid = tmp[mid].uid;
56522 + if (buid == uid)
56523 + return mid;
56524 + if (buid > uid)
56525 + high = mid - 1;
56526 + if (buid < uid)
56527 + low = mid + 1;
56528 + }
56529 +
56530 + return -1;
56531 +}
56532 +
56533 +static __inline__ void
56534 +gr_insertsort(void)
56535 +{
56536 + unsigned short i, j;
56537 + struct crash_uid index;
56538 +
56539 + for (i = 1; i < uid_used; i++) {
56540 + index = uid_set[i];
56541 + j = i;
56542 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56543 + uid_set[j] = uid_set[j - 1];
56544 + j--;
56545 + }
56546 + uid_set[j] = index;
56547 + }
56548 +
56549 + return;
56550 +}
56551 +
56552 +static __inline__ void
56553 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56554 +{
56555 + int loc;
56556 +
56557 + if (uid_used == GR_UIDTABLE_MAX)
56558 + return;
56559 +
56560 + loc = gr_find_uid(uid);
56561 +
56562 + if (loc >= 0) {
56563 + uid_set[loc].expires = expires;
56564 + return;
56565 + }
56566 +
56567 + uid_set[uid_used].uid = uid;
56568 + uid_set[uid_used].expires = expires;
56569 + uid_used++;
56570 +
56571 + gr_insertsort();
56572 +
56573 + return;
56574 +}
56575 +
56576 +void
56577 +gr_remove_uid(const unsigned short loc)
56578 +{
56579 + unsigned short i;
56580 +
56581 + for (i = loc + 1; i < uid_used; i++)
56582 + uid_set[i - 1] = uid_set[i];
56583 +
56584 + uid_used--;
56585 +
56586 + return;
56587 +}
56588 +
56589 +int
56590 +gr_check_crash_uid(const uid_t uid)
56591 +{
56592 + int loc;
56593 + int ret = 0;
56594 +
56595 + if (unlikely(!gr_acl_is_enabled()))
56596 + return 0;
56597 +
56598 + spin_lock(&gr_uid_lock);
56599 + loc = gr_find_uid(uid);
56600 +
56601 + if (loc < 0)
56602 + goto out_unlock;
56603 +
56604 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56605 + gr_remove_uid(loc);
56606 + else
56607 + ret = 1;
56608 +
56609 +out_unlock:
56610 + spin_unlock(&gr_uid_lock);
56611 + return ret;
56612 +}
56613 +
56614 +static __inline__ int
56615 +proc_is_setxid(const struct cred *cred)
56616 +{
56617 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
56618 + cred->uid != cred->fsuid)
56619 + return 1;
56620 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56621 + cred->gid != cred->fsgid)
56622 + return 1;
56623 +
56624 + return 0;
56625 +}
56626 +
56627 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56628 +
56629 +void
56630 +gr_handle_crash(struct task_struct *task, const int sig)
56631 +{
56632 + struct acl_subject_label *curr;
56633 + struct task_struct *tsk, *tsk2;
56634 + const struct cred *cred;
56635 + const struct cred *cred2;
56636 +
56637 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56638 + return;
56639 +
56640 + if (unlikely(!gr_acl_is_enabled()))
56641 + return;
56642 +
56643 + curr = task->acl;
56644 +
56645 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56646 + return;
56647 +
56648 + if (time_before_eq(curr->expires, get_seconds())) {
56649 + curr->expires = 0;
56650 + curr->crashes = 0;
56651 + }
56652 +
56653 + curr->crashes++;
56654 +
56655 + if (!curr->expires)
56656 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56657 +
56658 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56659 + time_after(curr->expires, get_seconds())) {
56660 + rcu_read_lock();
56661 + cred = __task_cred(task);
56662 + if (cred->uid && proc_is_setxid(cred)) {
56663 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56664 + spin_lock(&gr_uid_lock);
56665 + gr_insert_uid(cred->uid, curr->expires);
56666 + spin_unlock(&gr_uid_lock);
56667 + curr->expires = 0;
56668 + curr->crashes = 0;
56669 + read_lock(&tasklist_lock);
56670 + do_each_thread(tsk2, tsk) {
56671 + cred2 = __task_cred(tsk);
56672 + if (tsk != task && cred2->uid == cred->uid)
56673 + gr_fake_force_sig(SIGKILL, tsk);
56674 + } while_each_thread(tsk2, tsk);
56675 + read_unlock(&tasklist_lock);
56676 + } else {
56677 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56678 + read_lock(&tasklist_lock);
56679 + read_lock(&grsec_exec_file_lock);
56680 + do_each_thread(tsk2, tsk) {
56681 + if (likely(tsk != task)) {
56682 + // if this thread has the same subject as the one that triggered
56683 + // RES_CRASH and it's the same binary, kill it
56684 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56685 + gr_fake_force_sig(SIGKILL, tsk);
56686 + }
56687 + } while_each_thread(tsk2, tsk);
56688 + read_unlock(&grsec_exec_file_lock);
56689 + read_unlock(&tasklist_lock);
56690 + }
56691 + rcu_read_unlock();
56692 + }
56693 +
56694 + return;
56695 +}
56696 +
56697 +int
56698 +gr_check_crash_exec(const struct file *filp)
56699 +{
56700 + struct acl_subject_label *curr;
56701 +
56702 + if (unlikely(!gr_acl_is_enabled()))
56703 + return 0;
56704 +
56705 + read_lock(&gr_inode_lock);
56706 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56707 + __get_dev(filp->f_path.dentry),
56708 + current->role);
56709 + read_unlock(&gr_inode_lock);
56710 +
56711 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56712 + (!curr->crashes && !curr->expires))
56713 + return 0;
56714 +
56715 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56716 + time_after(curr->expires, get_seconds()))
56717 + return 1;
56718 + else if (time_before_eq(curr->expires, get_seconds())) {
56719 + curr->crashes = 0;
56720 + curr->expires = 0;
56721 + }
56722 +
56723 + return 0;
56724 +}
56725 +
56726 +void
56727 +gr_handle_alertkill(struct task_struct *task)
56728 +{
56729 + struct acl_subject_label *curracl;
56730 + __u32 curr_ip;
56731 + struct task_struct *p, *p2;
56732 +
56733 + if (unlikely(!gr_acl_is_enabled()))
56734 + return;
56735 +
56736 + curracl = task->acl;
56737 + curr_ip = task->signal->curr_ip;
56738 +
56739 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56740 + read_lock(&tasklist_lock);
56741 + do_each_thread(p2, p) {
56742 + if (p->signal->curr_ip == curr_ip)
56743 + gr_fake_force_sig(SIGKILL, p);
56744 + } while_each_thread(p2, p);
56745 + read_unlock(&tasklist_lock);
56746 + } else if (curracl->mode & GR_KILLPROC)
56747 + gr_fake_force_sig(SIGKILL, task);
56748 +
56749 + return;
56750 +}
56751 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56752 new file mode 100644
56753 index 0000000..9d83a69
56754 --- /dev/null
56755 +++ b/grsecurity/gracl_shm.c
56756 @@ -0,0 +1,40 @@
56757 +#include <linux/kernel.h>
56758 +#include <linux/mm.h>
56759 +#include <linux/sched.h>
56760 +#include <linux/file.h>
56761 +#include <linux/ipc.h>
56762 +#include <linux/gracl.h>
56763 +#include <linux/grsecurity.h>
56764 +#include <linux/grinternal.h>
56765 +
56766 +int
56767 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56768 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56769 +{
56770 + struct task_struct *task;
56771 +
56772 + if (!gr_acl_is_enabled())
56773 + return 1;
56774 +
56775 + rcu_read_lock();
56776 + read_lock(&tasklist_lock);
56777 +
56778 + task = find_task_by_vpid(shm_cprid);
56779 +
56780 + if (unlikely(!task))
56781 + task = find_task_by_vpid(shm_lapid);
56782 +
56783 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56784 + (task->pid == shm_lapid)) &&
56785 + (task->acl->mode & GR_PROTSHM) &&
56786 + (task->acl != current->acl))) {
56787 + read_unlock(&tasklist_lock);
56788 + rcu_read_unlock();
56789 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56790 + return 0;
56791 + }
56792 + read_unlock(&tasklist_lock);
56793 + rcu_read_unlock();
56794 +
56795 + return 1;
56796 +}
56797 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56798 new file mode 100644
56799 index 0000000..bc0be01
56800 --- /dev/null
56801 +++ b/grsecurity/grsec_chdir.c
56802 @@ -0,0 +1,19 @@
56803 +#include <linux/kernel.h>
56804 +#include <linux/sched.h>
56805 +#include <linux/fs.h>
56806 +#include <linux/file.h>
56807 +#include <linux/grsecurity.h>
56808 +#include <linux/grinternal.h>
56809 +
56810 +void
56811 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56812 +{
56813 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56814 + if ((grsec_enable_chdir && grsec_enable_group &&
56815 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56816 + !grsec_enable_group)) {
56817 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56818 + }
56819 +#endif
56820 + return;
56821 +}
56822 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56823 new file mode 100644
56824 index 0000000..a2dc675
56825 --- /dev/null
56826 +++ b/grsecurity/grsec_chroot.c
56827 @@ -0,0 +1,351 @@
56828 +#include <linux/kernel.h>
56829 +#include <linux/module.h>
56830 +#include <linux/sched.h>
56831 +#include <linux/file.h>
56832 +#include <linux/fs.h>
56833 +#include <linux/mount.h>
56834 +#include <linux/types.h>
56835 +#include <linux/pid_namespace.h>
56836 +#include <linux/grsecurity.h>
56837 +#include <linux/grinternal.h>
56838 +
56839 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56840 +{
56841 +#ifdef CONFIG_GRKERNSEC
56842 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56843 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
56844 + task->gr_is_chrooted = 1;
56845 + else
56846 + task->gr_is_chrooted = 0;
56847 +
56848 + task->gr_chroot_dentry = path->dentry;
56849 +#endif
56850 + return;
56851 +}
56852 +
56853 +void gr_clear_chroot_entries(struct task_struct *task)
56854 +{
56855 +#ifdef CONFIG_GRKERNSEC
56856 + task->gr_is_chrooted = 0;
56857 + task->gr_chroot_dentry = NULL;
56858 +#endif
56859 + return;
56860 +}
56861 +
56862 +int
56863 +gr_handle_chroot_unix(const pid_t pid)
56864 +{
56865 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56866 + struct task_struct *p;
56867 +
56868 + if (unlikely(!grsec_enable_chroot_unix))
56869 + return 1;
56870 +
56871 + if (likely(!proc_is_chrooted(current)))
56872 + return 1;
56873 +
56874 + rcu_read_lock();
56875 + read_lock(&tasklist_lock);
56876 + p = find_task_by_vpid_unrestricted(pid);
56877 + if (unlikely(p && !have_same_root(current, p))) {
56878 + read_unlock(&tasklist_lock);
56879 + rcu_read_unlock();
56880 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56881 + return 0;
56882 + }
56883 + read_unlock(&tasklist_lock);
56884 + rcu_read_unlock();
56885 +#endif
56886 + return 1;
56887 +}
56888 +
56889 +int
56890 +gr_handle_chroot_nice(void)
56891 +{
56892 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56893 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56894 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56895 + return -EPERM;
56896 + }
56897 +#endif
56898 + return 0;
56899 +}
56900 +
56901 +int
56902 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56903 +{
56904 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56905 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56906 + && proc_is_chrooted(current)) {
56907 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56908 + return -EACCES;
56909 + }
56910 +#endif
56911 + return 0;
56912 +}
56913 +
56914 +int
56915 +gr_handle_chroot_rawio(const struct inode *inode)
56916 +{
56917 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56918 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56919 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56920 + return 1;
56921 +#endif
56922 + return 0;
56923 +}
56924 +
56925 +int
56926 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56927 +{
56928 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56929 + struct task_struct *p;
56930 + int ret = 0;
56931 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56932 + return ret;
56933 +
56934 + read_lock(&tasklist_lock);
56935 + do_each_pid_task(pid, type, p) {
56936 + if (!have_same_root(current, p)) {
56937 + ret = 1;
56938 + goto out;
56939 + }
56940 + } while_each_pid_task(pid, type, p);
56941 +out:
56942 + read_unlock(&tasklist_lock);
56943 + return ret;
56944 +#endif
56945 + return 0;
56946 +}
56947 +
56948 +int
56949 +gr_pid_is_chrooted(struct task_struct *p)
56950 +{
56951 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56952 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56953 + return 0;
56954 +
56955 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56956 + !have_same_root(current, p)) {
56957 + return 1;
56958 + }
56959 +#endif
56960 + return 0;
56961 +}
56962 +
56963 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56964 +
56965 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56966 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56967 +{
56968 + struct path path, currentroot;
56969 + int ret = 0;
56970 +
56971 + path.dentry = (struct dentry *)u_dentry;
56972 + path.mnt = (struct vfsmount *)u_mnt;
56973 + get_fs_root(current->fs, &currentroot);
56974 + if (path_is_under(&path, &currentroot))
56975 + ret = 1;
56976 + path_put(&currentroot);
56977 +
56978 + return ret;
56979 +}
56980 +#endif
56981 +
56982 +int
56983 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56984 +{
56985 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56986 + if (!grsec_enable_chroot_fchdir)
56987 + return 1;
56988 +
56989 + if (!proc_is_chrooted(current))
56990 + return 1;
56991 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56992 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56993 + return 0;
56994 + }
56995 +#endif
56996 + return 1;
56997 +}
56998 +
56999 +int
57000 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57001 + const time_t shm_createtime)
57002 +{
57003 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57004 + struct task_struct *p;
57005 + time_t starttime;
57006 +
57007 + if (unlikely(!grsec_enable_chroot_shmat))
57008 + return 1;
57009 +
57010 + if (likely(!proc_is_chrooted(current)))
57011 + return 1;
57012 +
57013 + rcu_read_lock();
57014 + read_lock(&tasklist_lock);
57015 +
57016 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57017 + starttime = p->start_time.tv_sec;
57018 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57019 + if (have_same_root(current, p)) {
57020 + goto allow;
57021 + } else {
57022 + read_unlock(&tasklist_lock);
57023 + rcu_read_unlock();
57024 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57025 + return 0;
57026 + }
57027 + }
57028 + /* creator exited, pid reuse, fall through to next check */
57029 + }
57030 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57031 + if (unlikely(!have_same_root(current, p))) {
57032 + read_unlock(&tasklist_lock);
57033 + rcu_read_unlock();
57034 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57035 + return 0;
57036 + }
57037 + }
57038 +
57039 +allow:
57040 + read_unlock(&tasklist_lock);
57041 + rcu_read_unlock();
57042 +#endif
57043 + return 1;
57044 +}
57045 +
57046 +void
57047 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57048 +{
57049 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57050 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57051 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57052 +#endif
57053 + return;
57054 +}
57055 +
57056 +int
57057 +gr_handle_chroot_mknod(const struct dentry *dentry,
57058 + const struct vfsmount *mnt, const int mode)
57059 +{
57060 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57061 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57062 + proc_is_chrooted(current)) {
57063 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57064 + return -EPERM;
57065 + }
57066 +#endif
57067 + return 0;
57068 +}
57069 +
57070 +int
57071 +gr_handle_chroot_mount(const struct dentry *dentry,
57072 + const struct vfsmount *mnt, const char *dev_name)
57073 +{
57074 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57075 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57076 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57077 + return -EPERM;
57078 + }
57079 +#endif
57080 + return 0;
57081 +}
57082 +
57083 +int
57084 +gr_handle_chroot_pivot(void)
57085 +{
57086 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57087 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57088 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57089 + return -EPERM;
57090 + }
57091 +#endif
57092 + return 0;
57093 +}
57094 +
57095 +int
57096 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57097 +{
57098 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57099 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57100 + !gr_is_outside_chroot(dentry, mnt)) {
57101 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57102 + return -EPERM;
57103 + }
57104 +#endif
57105 + return 0;
57106 +}
57107 +
57108 +extern const char *captab_log[];
57109 +extern int captab_log_entries;
57110 +
57111 +int
57112 +gr_chroot_is_capable(const int cap)
57113 +{
57114 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57115 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
57116 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57117 + if (cap_raised(chroot_caps, cap)) {
57118 + const struct cred *creds = current_cred();
57119 + if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
57120 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
57121 + }
57122 + return 0;
57123 + }
57124 + }
57125 +#endif
57126 + return 1;
57127 +}
57128 +
57129 +int
57130 +gr_chroot_is_capable_nolog(const int cap)
57131 +{
57132 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57133 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
57134 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57135 + if (cap_raised(chroot_caps, cap)) {
57136 + return 0;
57137 + }
57138 + }
57139 +#endif
57140 + return 1;
57141 +}
57142 +
57143 +int
57144 +gr_handle_chroot_sysctl(const int op)
57145 +{
57146 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57147 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57148 + proc_is_chrooted(current))
57149 + return -EACCES;
57150 +#endif
57151 + return 0;
57152 +}
57153 +
57154 +void
57155 +gr_handle_chroot_chdir(struct path *path)
57156 +{
57157 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57158 + if (grsec_enable_chroot_chdir)
57159 + set_fs_pwd(current->fs, path);
57160 +#endif
57161 + return;
57162 +}
57163 +
57164 +int
57165 +gr_handle_chroot_chmod(const struct dentry *dentry,
57166 + const struct vfsmount *mnt, const int mode)
57167 +{
57168 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57169 + /* allow chmod +s on directories, but not files */
57170 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57171 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57172 + proc_is_chrooted(current)) {
57173 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57174 + return -EPERM;
57175 + }
57176 +#endif
57177 + return 0;
57178 +}
57179 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57180 new file mode 100644
57181 index 0000000..d81a586
57182 --- /dev/null
57183 +++ b/grsecurity/grsec_disabled.c
57184 @@ -0,0 +1,439 @@
57185 +#include <linux/kernel.h>
57186 +#include <linux/module.h>
57187 +#include <linux/sched.h>
57188 +#include <linux/file.h>
57189 +#include <linux/fs.h>
57190 +#include <linux/kdev_t.h>
57191 +#include <linux/net.h>
57192 +#include <linux/in.h>
57193 +#include <linux/ip.h>
57194 +#include <linux/skbuff.h>
57195 +#include <linux/sysctl.h>
57196 +
57197 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57198 +void
57199 +pax_set_initial_flags(struct linux_binprm *bprm)
57200 +{
57201 + return;
57202 +}
57203 +#endif
57204 +
57205 +#ifdef CONFIG_SYSCTL
57206 +__u32
57207 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57208 +{
57209 + return 0;
57210 +}
57211 +#endif
57212 +
57213 +#ifdef CONFIG_TASKSTATS
57214 +int gr_is_taskstats_denied(int pid)
57215 +{
57216 + return 0;
57217 +}
57218 +#endif
57219 +
57220 +int
57221 +gr_acl_is_enabled(void)
57222 +{
57223 + return 0;
57224 +}
57225 +
57226 +void
57227 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57228 +{
57229 + return;
57230 +}
57231 +
57232 +int
57233 +gr_handle_rawio(const struct inode *inode)
57234 +{
57235 + return 0;
57236 +}
57237 +
57238 +void
57239 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57240 +{
57241 + return;
57242 +}
57243 +
57244 +int
57245 +gr_handle_ptrace(struct task_struct *task, const long request)
57246 +{
57247 + return 0;
57248 +}
57249 +
57250 +int
57251 +gr_handle_proc_ptrace(struct task_struct *task)
57252 +{
57253 + return 0;
57254 +}
57255 +
57256 +void
57257 +gr_learn_resource(const struct task_struct *task,
57258 + const int res, const unsigned long wanted, const int gt)
57259 +{
57260 + return;
57261 +}
57262 +
57263 +int
57264 +gr_set_acls(const int type)
57265 +{
57266 + return 0;
57267 +}
57268 +
57269 +int
57270 +gr_check_hidden_task(const struct task_struct *tsk)
57271 +{
57272 + return 0;
57273 +}
57274 +
57275 +int
57276 +gr_check_protected_task(const struct task_struct *task)
57277 +{
57278 + return 0;
57279 +}
57280 +
57281 +int
57282 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57283 +{
57284 + return 0;
57285 +}
57286 +
57287 +void
57288 +gr_copy_label(struct task_struct *tsk)
57289 +{
57290 + return;
57291 +}
57292 +
57293 +void
57294 +gr_set_pax_flags(struct task_struct *task)
57295 +{
57296 + return;
57297 +}
57298 +
57299 +int
57300 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57301 + const int unsafe_share)
57302 +{
57303 + return 0;
57304 +}
57305 +
57306 +void
57307 +gr_handle_delete(const ino_t ino, const dev_t dev)
57308 +{
57309 + return;
57310 +}
57311 +
57312 +void
57313 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57314 +{
57315 + return;
57316 +}
57317 +
57318 +void
57319 +gr_handle_crash(struct task_struct *task, const int sig)
57320 +{
57321 + return;
57322 +}
57323 +
57324 +int
57325 +gr_check_crash_exec(const struct file *filp)
57326 +{
57327 + return 0;
57328 +}
57329 +
57330 +int
57331 +gr_check_crash_uid(const uid_t uid)
57332 +{
57333 + return 0;
57334 +}
57335 +
57336 +void
57337 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57338 + struct dentry *old_dentry,
57339 + struct dentry *new_dentry,
57340 + struct vfsmount *mnt, const __u8 replace)
57341 +{
57342 + return;
57343 +}
57344 +
57345 +int
57346 +gr_search_socket(const int family, const int type, const int protocol)
57347 +{
57348 + return 1;
57349 +}
57350 +
57351 +int
57352 +gr_search_connectbind(const int mode, const struct socket *sock,
57353 + const struct sockaddr_in *addr)
57354 +{
57355 + return 0;
57356 +}
57357 +
57358 +void
57359 +gr_handle_alertkill(struct task_struct *task)
57360 +{
57361 + return;
57362 +}
57363 +
57364 +__u32
57365 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57366 +{
57367 + return 1;
57368 +}
57369 +
57370 +__u32
57371 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57372 + const struct vfsmount * mnt)
57373 +{
57374 + return 1;
57375 +}
57376 +
57377 +__u32
57378 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57379 + int acc_mode)
57380 +{
57381 + return 1;
57382 +}
57383 +
57384 +__u32
57385 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57386 +{
57387 + return 1;
57388 +}
57389 +
57390 +__u32
57391 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57392 +{
57393 + return 1;
57394 +}
57395 +
57396 +int
57397 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57398 + unsigned int *vm_flags)
57399 +{
57400 + return 1;
57401 +}
57402 +
57403 +__u32
57404 +gr_acl_handle_truncate(const struct dentry * dentry,
57405 + const struct vfsmount * mnt)
57406 +{
57407 + return 1;
57408 +}
57409 +
57410 +__u32
57411 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57412 +{
57413 + return 1;
57414 +}
57415 +
57416 +__u32
57417 +gr_acl_handle_access(const struct dentry * dentry,
57418 + const struct vfsmount * mnt, const int fmode)
57419 +{
57420 + return 1;
57421 +}
57422 +
57423 +__u32
57424 +gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
57425 + mode_t mode)
57426 +{
57427 + return 1;
57428 +}
57429 +
57430 +__u32
57431 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57432 + mode_t mode)
57433 +{
57434 + return 1;
57435 +}
57436 +
57437 +__u32
57438 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57439 +{
57440 + return 1;
57441 +}
57442 +
57443 +__u32
57444 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57445 +{
57446 + return 1;
57447 +}
57448 +
57449 +void
57450 +grsecurity_init(void)
57451 +{
57452 + return;
57453 +}
57454 +
57455 +__u32
57456 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57457 + const struct dentry * parent_dentry,
57458 + const struct vfsmount * parent_mnt,
57459 + const int mode)
57460 +{
57461 + return 1;
57462 +}
57463 +
57464 +__u32
57465 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57466 + const struct dentry * parent_dentry,
57467 + const struct vfsmount * parent_mnt)
57468 +{
57469 + return 1;
57470 +}
57471 +
57472 +__u32
57473 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57474 + const struct dentry * parent_dentry,
57475 + const struct vfsmount * parent_mnt, const char *from)
57476 +{
57477 + return 1;
57478 +}
57479 +
57480 +__u32
57481 +gr_acl_handle_link(const struct dentry * new_dentry,
57482 + const struct dentry * parent_dentry,
57483 + const struct vfsmount * parent_mnt,
57484 + const struct dentry * old_dentry,
57485 + const struct vfsmount * old_mnt, const char *to)
57486 +{
57487 + return 1;
57488 +}
57489 +
57490 +int
57491 +gr_acl_handle_rename(const struct dentry *new_dentry,
57492 + const struct dentry *parent_dentry,
57493 + const struct vfsmount *parent_mnt,
57494 + const struct dentry *old_dentry,
57495 + const struct inode *old_parent_inode,
57496 + const struct vfsmount *old_mnt, const char *newname)
57497 +{
57498 + return 0;
57499 +}
57500 +
57501 +int
57502 +gr_acl_handle_filldir(const struct file *file, const char *name,
57503 + const int namelen, const ino_t ino)
57504 +{
57505 + return 1;
57506 +}
57507 +
57508 +int
57509 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57510 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57511 +{
57512 + return 1;
57513 +}
57514 +
57515 +int
57516 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57517 +{
57518 + return 0;
57519 +}
57520 +
57521 +int
57522 +gr_search_accept(const struct socket *sock)
57523 +{
57524 + return 0;
57525 +}
57526 +
57527 +int
57528 +gr_search_listen(const struct socket *sock)
57529 +{
57530 + return 0;
57531 +}
57532 +
57533 +int
57534 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57535 +{
57536 + return 0;
57537 +}
57538 +
57539 +__u32
57540 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57541 +{
57542 + return 1;
57543 +}
57544 +
57545 +__u32
57546 +gr_acl_handle_creat(const struct dentry * dentry,
57547 + const struct dentry * p_dentry,
57548 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57549 + const int imode)
57550 +{
57551 + return 1;
57552 +}
57553 +
57554 +void
57555 +gr_acl_handle_exit(void)
57556 +{
57557 + return;
57558 +}
57559 +
57560 +int
57561 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57562 +{
57563 + return 1;
57564 +}
57565 +
57566 +void
57567 +gr_set_role_label(const uid_t uid, const gid_t gid)
57568 +{
57569 + return;
57570 +}
57571 +
57572 +int
57573 +gr_acl_handle_procpidmem(const struct task_struct *task)
57574 +{
57575 + return 0;
57576 +}
57577 +
57578 +int
57579 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57580 +{
57581 + return 0;
57582 +}
57583 +
57584 +int
57585 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57586 +{
57587 + return 0;
57588 +}
57589 +
57590 +void
57591 +gr_set_kernel_label(struct task_struct *task)
57592 +{
57593 + return;
57594 +}
57595 +
57596 +int
57597 +gr_check_user_change(int real, int effective, int fs)
57598 +{
57599 + return 0;
57600 +}
57601 +
57602 +int
57603 +gr_check_group_change(int real, int effective, int fs)
57604 +{
57605 + return 0;
57606 +}
57607 +
57608 +int gr_acl_enable_at_secure(void)
57609 +{
57610 + return 0;
57611 +}
57612 +
57613 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57614 +{
57615 + return dentry->d_inode->i_sb->s_dev;
57616 +}
57617 +
57618 +EXPORT_SYMBOL(gr_learn_resource);
57619 +EXPORT_SYMBOL(gr_set_kernel_label);
57620 +#ifdef CONFIG_SECURITY
57621 +EXPORT_SYMBOL(gr_check_user_change);
57622 +EXPORT_SYMBOL(gr_check_group_change);
57623 +#endif
57624 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57625 new file mode 100644
57626 index 0000000..2b05ada
57627 --- /dev/null
57628 +++ b/grsecurity/grsec_exec.c
57629 @@ -0,0 +1,146 @@
57630 +#include <linux/kernel.h>
57631 +#include <linux/sched.h>
57632 +#include <linux/file.h>
57633 +#include <linux/binfmts.h>
57634 +#include <linux/fs.h>
57635 +#include <linux/types.h>
57636 +#include <linux/grdefs.h>
57637 +#include <linux/grsecurity.h>
57638 +#include <linux/grinternal.h>
57639 +#include <linux/capability.h>
57640 +#include <linux/module.h>
57641 +
57642 +#include <asm/uaccess.h>
57643 +
57644 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57645 +static char gr_exec_arg_buf[132];
57646 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57647 +#endif
57648 +
57649 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57650 +
57651 +void
57652 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57653 +{
57654 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57655 + char *grarg = gr_exec_arg_buf;
57656 + unsigned int i, x, execlen = 0;
57657 + char c;
57658 +
57659 + if (!((grsec_enable_execlog && grsec_enable_group &&
57660 + in_group_p(grsec_audit_gid))
57661 + || (grsec_enable_execlog && !grsec_enable_group)))
57662 + return;
57663 +
57664 + mutex_lock(&gr_exec_arg_mutex);
57665 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57666 +
57667 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57668 + const char __user *p;
57669 + unsigned int len;
57670 +
57671 + p = get_user_arg_ptr(argv, i);
57672 + if (IS_ERR(p))
57673 + goto log;
57674 +
57675 + len = strnlen_user(p, 128 - execlen);
57676 + if (len > 128 - execlen)
57677 + len = 128 - execlen;
57678 + else if (len > 0)
57679 + len--;
57680 + if (copy_from_user(grarg + execlen, p, len))
57681 + goto log;
57682 +
57683 + /* rewrite unprintable characters */
57684 + for (x = 0; x < len; x++) {
57685 + c = *(grarg + execlen + x);
57686 + if (c < 32 || c > 126)
57687 + *(grarg + execlen + x) = ' ';
57688 + }
57689 +
57690 + execlen += len;
57691 + *(grarg + execlen) = ' ';
57692 + *(grarg + execlen + 1) = '\0';
57693 + execlen++;
57694 + }
57695 +
57696 + log:
57697 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57698 + bprm->file->f_path.mnt, grarg);
57699 + mutex_unlock(&gr_exec_arg_mutex);
57700 +#endif
57701 + return;
57702 +}
57703 +
57704 +#ifdef CONFIG_GRKERNSEC
57705 +extern int gr_acl_is_capable(const int cap);
57706 +extern int gr_acl_is_capable_nolog(const int cap);
57707 +extern int gr_chroot_is_capable(const int cap);
57708 +extern int gr_chroot_is_capable_nolog(const int cap);
57709 +#endif
57710 +
57711 +const char *captab_log[] = {
57712 + "CAP_CHOWN",
57713 + "CAP_DAC_OVERRIDE",
57714 + "CAP_DAC_READ_SEARCH",
57715 + "CAP_FOWNER",
57716 + "CAP_FSETID",
57717 + "CAP_KILL",
57718 + "CAP_SETGID",
57719 + "CAP_SETUID",
57720 + "CAP_SETPCAP",
57721 + "CAP_LINUX_IMMUTABLE",
57722 + "CAP_NET_BIND_SERVICE",
57723 + "CAP_NET_BROADCAST",
57724 + "CAP_NET_ADMIN",
57725 + "CAP_NET_RAW",
57726 + "CAP_IPC_LOCK",
57727 + "CAP_IPC_OWNER",
57728 + "CAP_SYS_MODULE",
57729 + "CAP_SYS_RAWIO",
57730 + "CAP_SYS_CHROOT",
57731 + "CAP_SYS_PTRACE",
57732 + "CAP_SYS_PACCT",
57733 + "CAP_SYS_ADMIN",
57734 + "CAP_SYS_BOOT",
57735 + "CAP_SYS_NICE",
57736 + "CAP_SYS_RESOURCE",
57737 + "CAP_SYS_TIME",
57738 + "CAP_SYS_TTY_CONFIG",
57739 + "CAP_MKNOD",
57740 + "CAP_LEASE",
57741 + "CAP_AUDIT_WRITE",
57742 + "CAP_AUDIT_CONTROL",
57743 + "CAP_SETFCAP",
57744 + "CAP_MAC_OVERRIDE",
57745 + "CAP_MAC_ADMIN",
57746 + "CAP_SYSLOG",
57747 + "CAP_WAKE_ALARM"
57748 +};
57749 +
57750 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57751 +
57752 +int gr_is_capable(const int cap)
57753 +{
57754 +#ifdef CONFIG_GRKERNSEC
57755 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57756 + return 1;
57757 + return 0;
57758 +#else
57759 + return 1;
57760 +#endif
57761 +}
57762 +
57763 +int gr_is_capable_nolog(const int cap)
57764 +{
57765 +#ifdef CONFIG_GRKERNSEC
57766 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57767 + return 1;
57768 + return 0;
57769 +#else
57770 + return 1;
57771 +#endif
57772 +}
57773 +
57774 +EXPORT_SYMBOL(gr_is_capable);
57775 +EXPORT_SYMBOL(gr_is_capable_nolog);
57776 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57777 new file mode 100644
57778 index 0000000..d3ee748
57779 --- /dev/null
57780 +++ b/grsecurity/grsec_fifo.c
57781 @@ -0,0 +1,24 @@
57782 +#include <linux/kernel.h>
57783 +#include <linux/sched.h>
57784 +#include <linux/fs.h>
57785 +#include <linux/file.h>
57786 +#include <linux/grinternal.h>
57787 +
57788 +int
57789 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57790 + const struct dentry *dir, const int flag, const int acc_mode)
57791 +{
57792 +#ifdef CONFIG_GRKERNSEC_FIFO
57793 + const struct cred *cred = current_cred();
57794 +
57795 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57796 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57797 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57798 + (cred->fsuid != dentry->d_inode->i_uid)) {
57799 + if (!inode_permission(dentry->d_inode, acc_mode))
57800 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57801 + return -EACCES;
57802 + }
57803 +#endif
57804 + return 0;
57805 +}
57806 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57807 new file mode 100644
57808 index 0000000..8ca18bf
57809 --- /dev/null
57810 +++ b/grsecurity/grsec_fork.c
57811 @@ -0,0 +1,23 @@
57812 +#include <linux/kernel.h>
57813 +#include <linux/sched.h>
57814 +#include <linux/grsecurity.h>
57815 +#include <linux/grinternal.h>
57816 +#include <linux/errno.h>
57817 +
57818 +void
57819 +gr_log_forkfail(const int retval)
57820 +{
57821 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57822 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57823 + switch (retval) {
57824 + case -EAGAIN:
57825 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57826 + break;
57827 + case -ENOMEM:
57828 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57829 + break;
57830 + }
57831 + }
57832 +#endif
57833 + return;
57834 +}
57835 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57836 new file mode 100644
57837 index 0000000..cb8e5a1
57838 --- /dev/null
57839 +++ b/grsecurity/grsec_init.c
57840 @@ -0,0 +1,273 @@
57841 +#include <linux/kernel.h>
57842 +#include <linux/sched.h>
57843 +#include <linux/mm.h>
57844 +#include <linux/gracl.h>
57845 +#include <linux/slab.h>
57846 +#include <linux/vmalloc.h>
57847 +#include <linux/percpu.h>
57848 +#include <linux/module.h>
57849 +
57850 +int grsec_enable_setxid;
57851 +int grsec_enable_brute;
57852 +int grsec_enable_link;
57853 +int grsec_enable_dmesg;
57854 +int grsec_enable_harden_ptrace;
57855 +int grsec_enable_fifo;
57856 +int grsec_enable_execlog;
57857 +int grsec_enable_signal;
57858 +int grsec_enable_forkfail;
57859 +int grsec_enable_audit_ptrace;
57860 +int grsec_enable_time;
57861 +int grsec_enable_audit_textrel;
57862 +int grsec_enable_group;
57863 +int grsec_audit_gid;
57864 +int grsec_enable_chdir;
57865 +int grsec_enable_mount;
57866 +int grsec_enable_rofs;
57867 +int grsec_enable_chroot_findtask;
57868 +int grsec_enable_chroot_mount;
57869 +int grsec_enable_chroot_shmat;
57870 +int grsec_enable_chroot_fchdir;
57871 +int grsec_enable_chroot_double;
57872 +int grsec_enable_chroot_pivot;
57873 +int grsec_enable_chroot_chdir;
57874 +int grsec_enable_chroot_chmod;
57875 +int grsec_enable_chroot_mknod;
57876 +int grsec_enable_chroot_nice;
57877 +int grsec_enable_chroot_execlog;
57878 +int grsec_enable_chroot_caps;
57879 +int grsec_enable_chroot_sysctl;
57880 +int grsec_enable_chroot_unix;
57881 +int grsec_enable_tpe;
57882 +int grsec_tpe_gid;
57883 +int grsec_enable_blackhole;
57884 +#ifdef CONFIG_IPV6_MODULE
57885 +EXPORT_SYMBOL(grsec_enable_blackhole);
57886 +#endif
57887 +int grsec_lastack_retries;
57888 +int grsec_enable_tpe_all;
57889 +int grsec_enable_tpe_invert;
57890 +int grsec_enable_socket_all;
57891 +int grsec_socket_all_gid;
57892 +int grsec_enable_socket_client;
57893 +int grsec_socket_client_gid;
57894 +int grsec_enable_socket_server;
57895 +int grsec_socket_server_gid;
57896 +int grsec_resource_logging;
57897 +int grsec_disable_privio;
57898 +int grsec_enable_log_rwxmaps;
57899 +int grsec_lock;
57900 +
57901 +DEFINE_SPINLOCK(grsec_alert_lock);
57902 +unsigned long grsec_alert_wtime = 0;
57903 +unsigned long grsec_alert_fyet = 0;
57904 +
57905 +DEFINE_SPINLOCK(grsec_audit_lock);
57906 +
57907 +DEFINE_RWLOCK(grsec_exec_file_lock);
57908 +
57909 +char *gr_shared_page[4];
57910 +
57911 +char *gr_alert_log_fmt;
57912 +char *gr_audit_log_fmt;
57913 +char *gr_alert_log_buf;
57914 +char *gr_audit_log_buf;
57915 +
57916 +extern struct gr_arg *gr_usermode;
57917 +extern unsigned char *gr_system_salt;
57918 +extern unsigned char *gr_system_sum;
57919 +
57920 +void __init
57921 +grsecurity_init(void)
57922 +{
57923 + int j;
57924 + /* create the per-cpu shared pages */
57925 +
57926 +#ifdef CONFIG_X86
57927 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57928 +#endif
57929 +
57930 + for (j = 0; j < 4; j++) {
57931 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57932 + if (gr_shared_page[j] == NULL) {
57933 + panic("Unable to allocate grsecurity shared page");
57934 + return;
57935 + }
57936 + }
57937 +
57938 + /* allocate log buffers */
57939 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57940 + if (!gr_alert_log_fmt) {
57941 + panic("Unable to allocate grsecurity alert log format buffer");
57942 + return;
57943 + }
57944 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57945 + if (!gr_audit_log_fmt) {
57946 + panic("Unable to allocate grsecurity audit log format buffer");
57947 + return;
57948 + }
57949 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57950 + if (!gr_alert_log_buf) {
57951 + panic("Unable to allocate grsecurity alert log buffer");
57952 + return;
57953 + }
57954 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57955 + if (!gr_audit_log_buf) {
57956 + panic("Unable to allocate grsecurity audit log buffer");
57957 + return;
57958 + }
57959 +
57960 + /* allocate memory for authentication structure */
57961 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57962 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57963 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57964 +
57965 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57966 + panic("Unable to allocate grsecurity authentication structure");
57967 + return;
57968 + }
57969 +
57970 +
57971 +#ifdef CONFIG_GRKERNSEC_IO
57972 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57973 + grsec_disable_privio = 1;
57974 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57975 + grsec_disable_privio = 1;
57976 +#else
57977 + grsec_disable_privio = 0;
57978 +#endif
57979 +#endif
57980 +
57981 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57982 + /* for backward compatibility, tpe_invert always defaults to on if
57983 + enabled in the kernel
57984 + */
57985 + grsec_enable_tpe_invert = 1;
57986 +#endif
57987 +
57988 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57989 +#ifndef CONFIG_GRKERNSEC_SYSCTL
57990 + grsec_lock = 1;
57991 +#endif
57992 +
57993 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57994 + grsec_enable_audit_textrel = 1;
57995 +#endif
57996 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57997 + grsec_enable_log_rwxmaps = 1;
57998 +#endif
57999 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58000 + grsec_enable_group = 1;
58001 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58002 +#endif
58003 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58004 + grsec_enable_chdir = 1;
58005 +#endif
58006 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58007 + grsec_enable_harden_ptrace = 1;
58008 +#endif
58009 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58010 + grsec_enable_mount = 1;
58011 +#endif
58012 +#ifdef CONFIG_GRKERNSEC_LINK
58013 + grsec_enable_link = 1;
58014 +#endif
58015 +#ifdef CONFIG_GRKERNSEC_BRUTE
58016 + grsec_enable_brute = 1;
58017 +#endif
58018 +#ifdef CONFIG_GRKERNSEC_DMESG
58019 + grsec_enable_dmesg = 1;
58020 +#endif
58021 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58022 + grsec_enable_blackhole = 1;
58023 + grsec_lastack_retries = 4;
58024 +#endif
58025 +#ifdef CONFIG_GRKERNSEC_FIFO
58026 + grsec_enable_fifo = 1;
58027 +#endif
58028 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58029 + grsec_enable_execlog = 1;
58030 +#endif
58031 +#ifdef CONFIG_GRKERNSEC_SETXID
58032 + grsec_enable_setxid = 1;
58033 +#endif
58034 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58035 + grsec_enable_signal = 1;
58036 +#endif
58037 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58038 + grsec_enable_forkfail = 1;
58039 +#endif
58040 +#ifdef CONFIG_GRKERNSEC_TIME
58041 + grsec_enable_time = 1;
58042 +#endif
58043 +#ifdef CONFIG_GRKERNSEC_RESLOG
58044 + grsec_resource_logging = 1;
58045 +#endif
58046 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58047 + grsec_enable_chroot_findtask = 1;
58048 +#endif
58049 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58050 + grsec_enable_chroot_unix = 1;
58051 +#endif
58052 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58053 + grsec_enable_chroot_mount = 1;
58054 +#endif
58055 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58056 + grsec_enable_chroot_fchdir = 1;
58057 +#endif
58058 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58059 + grsec_enable_chroot_shmat = 1;
58060 +#endif
58061 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58062 + grsec_enable_audit_ptrace = 1;
58063 +#endif
58064 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58065 + grsec_enable_chroot_double = 1;
58066 +#endif
58067 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58068 + grsec_enable_chroot_pivot = 1;
58069 +#endif
58070 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58071 + grsec_enable_chroot_chdir = 1;
58072 +#endif
58073 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58074 + grsec_enable_chroot_chmod = 1;
58075 +#endif
58076 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58077 + grsec_enable_chroot_mknod = 1;
58078 +#endif
58079 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58080 + grsec_enable_chroot_nice = 1;
58081 +#endif
58082 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58083 + grsec_enable_chroot_execlog = 1;
58084 +#endif
58085 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58086 + grsec_enable_chroot_caps = 1;
58087 +#endif
58088 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58089 + grsec_enable_chroot_sysctl = 1;
58090 +#endif
58091 +#ifdef CONFIG_GRKERNSEC_TPE
58092 + grsec_enable_tpe = 1;
58093 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58094 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58095 + grsec_enable_tpe_all = 1;
58096 +#endif
58097 +#endif
58098 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58099 + grsec_enable_socket_all = 1;
58100 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58101 +#endif
58102 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58103 + grsec_enable_socket_client = 1;
58104 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58105 +#endif
58106 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58107 + grsec_enable_socket_server = 1;
58108 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58109 +#endif
58110 +#endif
58111 +
58112 + return;
58113 +}
58114 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58115 new file mode 100644
58116 index 0000000..3efe141
58117 --- /dev/null
58118 +++ b/grsecurity/grsec_link.c
58119 @@ -0,0 +1,43 @@
58120 +#include <linux/kernel.h>
58121 +#include <linux/sched.h>
58122 +#include <linux/fs.h>
58123 +#include <linux/file.h>
58124 +#include <linux/grinternal.h>
58125 +
58126 +int
58127 +gr_handle_follow_link(const struct inode *parent,
58128 + const struct inode *inode,
58129 + const struct dentry *dentry, const struct vfsmount *mnt)
58130 +{
58131 +#ifdef CONFIG_GRKERNSEC_LINK
58132 + const struct cred *cred = current_cred();
58133 +
58134 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58135 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
58136 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
58137 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58138 + return -EACCES;
58139 + }
58140 +#endif
58141 + return 0;
58142 +}
58143 +
58144 +int
58145 +gr_handle_hardlink(const struct dentry *dentry,
58146 + const struct vfsmount *mnt,
58147 + struct inode *inode, const int mode, const char *to)
58148 +{
58149 +#ifdef CONFIG_GRKERNSEC_LINK
58150 + const struct cred *cred = current_cred();
58151 +
58152 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
58153 + (!S_ISREG(mode) || (mode & S_ISUID) ||
58154 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58155 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58156 + !capable(CAP_FOWNER) && cred->uid) {
58157 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58158 + return -EPERM;
58159 + }
58160 +#endif
58161 + return 0;
58162 +}
58163 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58164 new file mode 100644
58165 index 0000000..a45d2e9
58166 --- /dev/null
58167 +++ b/grsecurity/grsec_log.c
58168 @@ -0,0 +1,322 @@
58169 +#include <linux/kernel.h>
58170 +#include <linux/sched.h>
58171 +#include <linux/file.h>
58172 +#include <linux/tty.h>
58173 +#include <linux/fs.h>
58174 +#include <linux/grinternal.h>
58175 +
58176 +#ifdef CONFIG_TREE_PREEMPT_RCU
58177 +#define DISABLE_PREEMPT() preempt_disable()
58178 +#define ENABLE_PREEMPT() preempt_enable()
58179 +#else
58180 +#define DISABLE_PREEMPT()
58181 +#define ENABLE_PREEMPT()
58182 +#endif
58183 +
58184 +#define BEGIN_LOCKS(x) \
58185 + DISABLE_PREEMPT(); \
58186 + rcu_read_lock(); \
58187 + read_lock(&tasklist_lock); \
58188 + read_lock(&grsec_exec_file_lock); \
58189 + if (x != GR_DO_AUDIT) \
58190 + spin_lock(&grsec_alert_lock); \
58191 + else \
58192 + spin_lock(&grsec_audit_lock)
58193 +
58194 +#define END_LOCKS(x) \
58195 + if (x != GR_DO_AUDIT) \
58196 + spin_unlock(&grsec_alert_lock); \
58197 + else \
58198 + spin_unlock(&grsec_audit_lock); \
58199 + read_unlock(&grsec_exec_file_lock); \
58200 + read_unlock(&tasklist_lock); \
58201 + rcu_read_unlock(); \
58202 + ENABLE_PREEMPT(); \
58203 + if (x == GR_DONT_AUDIT) \
58204 + gr_handle_alertkill(current)
58205 +
58206 +enum {
58207 + FLOODING,
58208 + NO_FLOODING
58209 +};
58210 +
58211 +extern char *gr_alert_log_fmt;
58212 +extern char *gr_audit_log_fmt;
58213 +extern char *gr_alert_log_buf;
58214 +extern char *gr_audit_log_buf;
58215 +
58216 +static int gr_log_start(int audit)
58217 +{
58218 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58219 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58220 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58221 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58222 + unsigned long curr_secs = get_seconds();
58223 +
58224 + if (audit == GR_DO_AUDIT)
58225 + goto set_fmt;
58226 +
58227 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58228 + grsec_alert_wtime = curr_secs;
58229 + grsec_alert_fyet = 0;
58230 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58231 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58232 + grsec_alert_fyet++;
58233 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58234 + grsec_alert_wtime = curr_secs;
58235 + grsec_alert_fyet++;
58236 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58237 + return FLOODING;
58238 + }
58239 + else return FLOODING;
58240 +
58241 +set_fmt:
58242 +#endif
58243 + memset(buf, 0, PAGE_SIZE);
58244 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58245 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58246 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58247 + } else if (current->signal->curr_ip) {
58248 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58249 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58250 + } else if (gr_acl_is_enabled()) {
58251 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58252 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58253 + } else {
58254 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58255 + strcpy(buf, fmt);
58256 + }
58257 +
58258 + return NO_FLOODING;
58259 +}
58260 +
58261 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58262 + __attribute__ ((format (printf, 2, 0)));
58263 +
58264 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58265 +{
58266 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58267 + unsigned int len = strlen(buf);
58268 +
58269 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58270 +
58271 + return;
58272 +}
58273 +
58274 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58275 + __attribute__ ((format (printf, 2, 3)));
58276 +
58277 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58278 +{
58279 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58280 + unsigned int len = strlen(buf);
58281 + va_list ap;
58282 +
58283 + va_start(ap, msg);
58284 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58285 + va_end(ap);
58286 +
58287 + return;
58288 +}
58289 +
58290 +static void gr_log_end(int audit, int append_default)
58291 +{
58292 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58293 +
58294 + if (append_default) {
58295 + unsigned int len = strlen(buf);
58296 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58297 + }
58298 +
58299 + printk("%s\n", buf);
58300 +
58301 + return;
58302 +}
58303 +
58304 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58305 +{
58306 + int logtype;
58307 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58308 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58309 + void *voidptr = NULL;
58310 + int num1 = 0, num2 = 0;
58311 + unsigned long ulong1 = 0, ulong2 = 0;
58312 + struct dentry *dentry = NULL;
58313 + struct vfsmount *mnt = NULL;
58314 + struct file *file = NULL;
58315 + struct task_struct *task = NULL;
58316 + const struct cred *cred, *pcred;
58317 + va_list ap;
58318 +
58319 + BEGIN_LOCKS(audit);
58320 + logtype = gr_log_start(audit);
58321 + if (logtype == FLOODING) {
58322 + END_LOCKS(audit);
58323 + return;
58324 + }
58325 + va_start(ap, argtypes);
58326 + switch (argtypes) {
58327 + case GR_TTYSNIFF:
58328 + task = va_arg(ap, struct task_struct *);
58329 + gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid);
58330 + break;
58331 + case GR_SYSCTL_HIDDEN:
58332 + str1 = va_arg(ap, char *);
58333 + gr_log_middle_varargs(audit, msg, result, str1);
58334 + break;
58335 + case GR_RBAC:
58336 + dentry = va_arg(ap, struct dentry *);
58337 + mnt = va_arg(ap, struct vfsmount *);
58338 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58339 + break;
58340 + case GR_RBAC_STR:
58341 + dentry = va_arg(ap, struct dentry *);
58342 + mnt = va_arg(ap, struct vfsmount *);
58343 + str1 = va_arg(ap, char *);
58344 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58345 + break;
58346 + case GR_STR_RBAC:
58347 + str1 = va_arg(ap, char *);
58348 + dentry = va_arg(ap, struct dentry *);
58349 + mnt = va_arg(ap, struct vfsmount *);
58350 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58351 + break;
58352 + case GR_RBAC_MODE2:
58353 + dentry = va_arg(ap, struct dentry *);
58354 + mnt = va_arg(ap, struct vfsmount *);
58355 + str1 = va_arg(ap, char *);
58356 + str2 = va_arg(ap, char *);
58357 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58358 + break;
58359 + case GR_RBAC_MODE3:
58360 + dentry = va_arg(ap, struct dentry *);
58361 + mnt = va_arg(ap, struct vfsmount *);
58362 + str1 = va_arg(ap, char *);
58363 + str2 = va_arg(ap, char *);
58364 + str3 = va_arg(ap, char *);
58365 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58366 + break;
58367 + case GR_FILENAME:
58368 + dentry = va_arg(ap, struct dentry *);
58369 + mnt = va_arg(ap, struct vfsmount *);
58370 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58371 + break;
58372 + case GR_STR_FILENAME:
58373 + str1 = va_arg(ap, char *);
58374 + dentry = va_arg(ap, struct dentry *);
58375 + mnt = va_arg(ap, struct vfsmount *);
58376 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58377 + break;
58378 + case GR_FILENAME_STR:
58379 + dentry = va_arg(ap, struct dentry *);
58380 + mnt = va_arg(ap, struct vfsmount *);
58381 + str1 = va_arg(ap, char *);
58382 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58383 + break;
58384 + case GR_FILENAME_TWO_INT:
58385 + dentry = va_arg(ap, struct dentry *);
58386 + mnt = va_arg(ap, struct vfsmount *);
58387 + num1 = va_arg(ap, int);
58388 + num2 = va_arg(ap, int);
58389 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58390 + break;
58391 + case GR_FILENAME_TWO_INT_STR:
58392 + dentry = va_arg(ap, struct dentry *);
58393 + mnt = va_arg(ap, struct vfsmount *);
58394 + num1 = va_arg(ap, int);
58395 + num2 = va_arg(ap, int);
58396 + str1 = va_arg(ap, char *);
58397 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58398 + break;
58399 + case GR_TEXTREL:
58400 + file = va_arg(ap, struct file *);
58401 + ulong1 = va_arg(ap, unsigned long);
58402 + ulong2 = va_arg(ap, unsigned long);
58403 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58404 + break;
58405 + case GR_PTRACE:
58406 + task = va_arg(ap, struct task_struct *);
58407 + 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);
58408 + break;
58409 + case GR_RESOURCE:
58410 + task = va_arg(ap, struct task_struct *);
58411 + cred = __task_cred(task);
58412 + pcred = __task_cred(task->real_parent);
58413 + ulong1 = va_arg(ap, unsigned long);
58414 + str1 = va_arg(ap, char *);
58415 + ulong2 = va_arg(ap, unsigned long);
58416 + 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->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
58417 + break;
58418 + case GR_CAP:
58419 + task = va_arg(ap, struct task_struct *);
58420 + cred = __task_cred(task);
58421 + pcred = __task_cred(task->real_parent);
58422 + str1 = va_arg(ap, char *);
58423 + 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->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
58424 + break;
58425 + case GR_SIG:
58426 + str1 = va_arg(ap, char *);
58427 + voidptr = va_arg(ap, void *);
58428 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58429 + break;
58430 + case GR_SIG2:
58431 + task = va_arg(ap, struct task_struct *);
58432 + cred = __task_cred(task);
58433 + pcred = __task_cred(task->real_parent);
58434 + num1 = va_arg(ap, int);
58435 + 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->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
58436 + break;
58437 + case GR_CRASH1:
58438 + task = va_arg(ap, struct task_struct *);
58439 + cred = __task_cred(task);
58440 + pcred = __task_cred(task->real_parent);
58441 + ulong1 = va_arg(ap, unsigned long);
58442 + 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->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, cred->uid, ulong1);
58443 + break;
58444 + case GR_CRASH2:
58445 + task = va_arg(ap, struct task_struct *);
58446 + cred = __task_cred(task);
58447 + pcred = __task_cred(task->real_parent);
58448 + ulong1 = va_arg(ap, unsigned long);
58449 + 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->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, ulong1);
58450 + break;
58451 + case GR_RWXMAP:
58452 + file = va_arg(ap, struct file *);
58453 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58454 + break;
58455 + case GR_PSACCT:
58456 + {
58457 + unsigned int wday, cday;
58458 + __u8 whr, chr;
58459 + __u8 wmin, cmin;
58460 + __u8 wsec, csec;
58461 + char cur_tty[64] = { 0 };
58462 + char parent_tty[64] = { 0 };
58463 +
58464 + task = va_arg(ap, struct task_struct *);
58465 + wday = va_arg(ap, unsigned int);
58466 + cday = va_arg(ap, unsigned int);
58467 + whr = va_arg(ap, int);
58468 + chr = va_arg(ap, int);
58469 + wmin = va_arg(ap, int);
58470 + cmin = va_arg(ap, int);
58471 + wsec = va_arg(ap, int);
58472 + csec = va_arg(ap, int);
58473 + ulong1 = va_arg(ap, unsigned long);
58474 + cred = __task_cred(task);
58475 + pcred = __task_cred(task->real_parent);
58476 +
58477 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, &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->real_parent->comm, task->real_parent->pid, &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), pcred->uid, pcred->euid, pcred->gid, pcred->egid);
58478 + }
58479 + break;
58480 + default:
58481 + gr_log_middle(audit, msg, ap);
58482 + }
58483 + va_end(ap);
58484 + // these don't need DEFAULTSECARGS printed on the end
58485 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58486 + gr_log_end(audit, 0);
58487 + else
58488 + gr_log_end(audit, 1);
58489 + END_LOCKS(audit);
58490 +}
58491 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58492 new file mode 100644
58493 index 0000000..6c0416b
58494 --- /dev/null
58495 +++ b/grsecurity/grsec_mem.c
58496 @@ -0,0 +1,33 @@
58497 +#include <linux/kernel.h>
58498 +#include <linux/sched.h>
58499 +#include <linux/mm.h>
58500 +#include <linux/mman.h>
58501 +#include <linux/grinternal.h>
58502 +
58503 +void
58504 +gr_handle_ioperm(void)
58505 +{
58506 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58507 + return;
58508 +}
58509 +
58510 +void
58511 +gr_handle_iopl(void)
58512 +{
58513 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58514 + return;
58515 +}
58516 +
58517 +void
58518 +gr_handle_mem_readwrite(u64 from, u64 to)
58519 +{
58520 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58521 + return;
58522 +}
58523 +
58524 +void
58525 +gr_handle_vm86(void)
58526 +{
58527 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58528 + return;
58529 +}
58530 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58531 new file mode 100644
58532 index 0000000..2131422
58533 --- /dev/null
58534 +++ b/grsecurity/grsec_mount.c
58535 @@ -0,0 +1,62 @@
58536 +#include <linux/kernel.h>
58537 +#include <linux/sched.h>
58538 +#include <linux/mount.h>
58539 +#include <linux/grsecurity.h>
58540 +#include <linux/grinternal.h>
58541 +
58542 +void
58543 +gr_log_remount(const char *devname, const int retval)
58544 +{
58545 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58546 + if (grsec_enable_mount && (retval >= 0))
58547 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58548 +#endif
58549 + return;
58550 +}
58551 +
58552 +void
58553 +gr_log_unmount(const char *devname, const int retval)
58554 +{
58555 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58556 + if (grsec_enable_mount && (retval >= 0))
58557 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58558 +#endif
58559 + return;
58560 +}
58561 +
58562 +void
58563 +gr_log_mount(const char *from, const char *to, const int retval)
58564 +{
58565 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58566 + if (grsec_enable_mount && (retval >= 0))
58567 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58568 +#endif
58569 + return;
58570 +}
58571 +
58572 +int
58573 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58574 +{
58575 +#ifdef CONFIG_GRKERNSEC_ROFS
58576 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58577 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58578 + return -EPERM;
58579 + } else
58580 + return 0;
58581 +#endif
58582 + return 0;
58583 +}
58584 +
58585 +int
58586 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58587 +{
58588 +#ifdef CONFIG_GRKERNSEC_ROFS
58589 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58590 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58591 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58592 + return -EPERM;
58593 + } else
58594 + return 0;
58595 +#endif
58596 + return 0;
58597 +}
58598 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58599 new file mode 100644
58600 index 0000000..a3b12a0
58601 --- /dev/null
58602 +++ b/grsecurity/grsec_pax.c
58603 @@ -0,0 +1,36 @@
58604 +#include <linux/kernel.h>
58605 +#include <linux/sched.h>
58606 +#include <linux/mm.h>
58607 +#include <linux/file.h>
58608 +#include <linux/grinternal.h>
58609 +#include <linux/grsecurity.h>
58610 +
58611 +void
58612 +gr_log_textrel(struct vm_area_struct * vma)
58613 +{
58614 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58615 + if (grsec_enable_audit_textrel)
58616 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58617 +#endif
58618 + return;
58619 +}
58620 +
58621 +void
58622 +gr_log_rwxmmap(struct file *file)
58623 +{
58624 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58625 + if (grsec_enable_log_rwxmaps)
58626 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58627 +#endif
58628 + return;
58629 +}
58630 +
58631 +void
58632 +gr_log_rwxmprotect(struct file *file)
58633 +{
58634 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58635 + if (grsec_enable_log_rwxmaps)
58636 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58637 +#endif
58638 + return;
58639 +}
58640 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58641 new file mode 100644
58642 index 0000000..472c1d6
58643 --- /dev/null
58644 +++ b/grsecurity/grsec_ptrace.c
58645 @@ -0,0 +1,14 @@
58646 +#include <linux/kernel.h>
58647 +#include <linux/sched.h>
58648 +#include <linux/grinternal.h>
58649 +#include <linux/grsecurity.h>
58650 +
58651 +void
58652 +gr_audit_ptrace(struct task_struct *task)
58653 +{
58654 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58655 + if (grsec_enable_audit_ptrace)
58656 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58657 +#endif
58658 + return;
58659 +}
58660 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58661 new file mode 100644
58662 index 0000000..cf090b3
58663 --- /dev/null
58664 +++ b/grsecurity/grsec_sig.c
58665 @@ -0,0 +1,206 @@
58666 +#include <linux/kernel.h>
58667 +#include <linux/sched.h>
58668 +#include <linux/delay.h>
58669 +#include <linux/grsecurity.h>
58670 +#include <linux/grinternal.h>
58671 +#include <linux/hardirq.h>
58672 +
58673 +char *signames[] = {
58674 + [SIGSEGV] = "Segmentation fault",
58675 + [SIGILL] = "Illegal instruction",
58676 + [SIGABRT] = "Abort",
58677 + [SIGBUS] = "Invalid alignment/Bus error"
58678 +};
58679 +
58680 +void
58681 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58682 +{
58683 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58684 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58685 + (sig == SIGABRT) || (sig == SIGBUS))) {
58686 + if (t->pid == current->pid) {
58687 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58688 + } else {
58689 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58690 + }
58691 + }
58692 +#endif
58693 + return;
58694 +}
58695 +
58696 +int
58697 +gr_handle_signal(const struct task_struct *p, const int sig)
58698 +{
58699 +#ifdef CONFIG_GRKERNSEC
58700 + if (current->pid > 1 && gr_check_protected_task(p)) {
58701 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58702 + return -EPERM;
58703 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58704 + return -EPERM;
58705 + }
58706 +#endif
58707 + return 0;
58708 +}
58709 +
58710 +#ifdef CONFIG_GRKERNSEC
58711 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58712 +
58713 +int gr_fake_force_sig(int sig, struct task_struct *t)
58714 +{
58715 + unsigned long int flags;
58716 + int ret, blocked, ignored;
58717 + struct k_sigaction *action;
58718 +
58719 + spin_lock_irqsave(&t->sighand->siglock, flags);
58720 + action = &t->sighand->action[sig-1];
58721 + ignored = action->sa.sa_handler == SIG_IGN;
58722 + blocked = sigismember(&t->blocked, sig);
58723 + if (blocked || ignored) {
58724 + action->sa.sa_handler = SIG_DFL;
58725 + if (blocked) {
58726 + sigdelset(&t->blocked, sig);
58727 + recalc_sigpending_and_wake(t);
58728 + }
58729 + }
58730 + if (action->sa.sa_handler == SIG_DFL)
58731 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58732 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58733 +
58734 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58735 +
58736 + return ret;
58737 +}
58738 +#endif
58739 +
58740 +#ifdef CONFIG_GRKERNSEC_BRUTE
58741 +#define GR_USER_BAN_TIME (15 * 60)
58742 +
58743 +static int __get_dumpable(unsigned long mm_flags)
58744 +{
58745 + int ret;
58746 +
58747 + ret = mm_flags & MMF_DUMPABLE_MASK;
58748 + return (ret >= 2) ? 2 : ret;
58749 +}
58750 +#endif
58751 +
58752 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58753 +{
58754 +#ifdef CONFIG_GRKERNSEC_BRUTE
58755 + uid_t uid = 0;
58756 +
58757 + if (!grsec_enable_brute)
58758 + return;
58759 +
58760 + rcu_read_lock();
58761 + read_lock(&tasklist_lock);
58762 + read_lock(&grsec_exec_file_lock);
58763 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58764 + p->real_parent->brute = 1;
58765 + else {
58766 + const struct cred *cred = __task_cred(p), *cred2;
58767 + struct task_struct *tsk, *tsk2;
58768 +
58769 + if (!__get_dumpable(mm_flags) && cred->uid) {
58770 + struct user_struct *user;
58771 +
58772 + uid = cred->uid;
58773 +
58774 + /* this is put upon execution past expiration */
58775 + user = find_user(uid);
58776 + if (user == NULL)
58777 + goto unlock;
58778 + user->banned = 1;
58779 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58780 + if (user->ban_expires == ~0UL)
58781 + user->ban_expires--;
58782 +
58783 + do_each_thread(tsk2, tsk) {
58784 + cred2 = __task_cred(tsk);
58785 + if (tsk != p && cred2->uid == uid)
58786 + gr_fake_force_sig(SIGKILL, tsk);
58787 + } while_each_thread(tsk2, tsk);
58788 + }
58789 + }
58790 +unlock:
58791 + read_unlock(&grsec_exec_file_lock);
58792 + read_unlock(&tasklist_lock);
58793 + rcu_read_unlock();
58794 +
58795 + if (uid)
58796 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58797 +
58798 +#endif
58799 + return;
58800 +}
58801 +
58802 +void gr_handle_brute_check(void)
58803 +{
58804 +#ifdef CONFIG_GRKERNSEC_BRUTE
58805 + if (current->brute)
58806 + msleep(30 * 1000);
58807 +#endif
58808 + return;
58809 +}
58810 +
58811 +void gr_handle_kernel_exploit(void)
58812 +{
58813 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58814 + const struct cred *cred;
58815 + struct task_struct *tsk, *tsk2;
58816 + struct user_struct *user;
58817 + uid_t uid;
58818 +
58819 + if (in_irq() || in_serving_softirq() || in_nmi())
58820 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58821 +
58822 + uid = current_uid();
58823 +
58824 + if (uid == 0)
58825 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58826 + else {
58827 + /* kill all the processes of this user, hold a reference
58828 + to their creds struct, and prevent them from creating
58829 + another process until system reset
58830 + */
58831 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58832 + /* we intentionally leak this ref */
58833 + user = get_uid(current->cred->user);
58834 + if (user) {
58835 + user->banned = 1;
58836 + user->ban_expires = ~0UL;
58837 + }
58838 +
58839 + read_lock(&tasklist_lock);
58840 + do_each_thread(tsk2, tsk) {
58841 + cred = __task_cred(tsk);
58842 + if (cred->uid == uid)
58843 + gr_fake_force_sig(SIGKILL, tsk);
58844 + } while_each_thread(tsk2, tsk);
58845 + read_unlock(&tasklist_lock);
58846 + }
58847 +#endif
58848 +}
58849 +
58850 +int __gr_process_user_ban(struct user_struct *user)
58851 +{
58852 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58853 + if (unlikely(user->banned)) {
58854 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58855 + user->banned = 0;
58856 + user->ban_expires = 0;
58857 + free_uid(user);
58858 + } else
58859 + return -EPERM;
58860 + }
58861 +#endif
58862 + return 0;
58863 +}
58864 +
58865 +int gr_process_user_ban(void)
58866 +{
58867 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58868 + return __gr_process_user_ban(current->cred->user);
58869 +#endif
58870 + return 0;
58871 +}
58872 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58873 new file mode 100644
58874 index 0000000..4030d57
58875 --- /dev/null
58876 +++ b/grsecurity/grsec_sock.c
58877 @@ -0,0 +1,244 @@
58878 +#include <linux/kernel.h>
58879 +#include <linux/module.h>
58880 +#include <linux/sched.h>
58881 +#include <linux/file.h>
58882 +#include <linux/net.h>
58883 +#include <linux/in.h>
58884 +#include <linux/ip.h>
58885 +#include <net/sock.h>
58886 +#include <net/inet_sock.h>
58887 +#include <linux/grsecurity.h>
58888 +#include <linux/grinternal.h>
58889 +#include <linux/gracl.h>
58890 +
58891 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58892 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58893 +
58894 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58895 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58896 +
58897 +#ifdef CONFIG_UNIX_MODULE
58898 +EXPORT_SYMBOL(gr_acl_handle_unix);
58899 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58900 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58901 +EXPORT_SYMBOL(gr_handle_create);
58902 +#endif
58903 +
58904 +#ifdef CONFIG_GRKERNSEC
58905 +#define gr_conn_table_size 32749
58906 +struct conn_table_entry {
58907 + struct conn_table_entry *next;
58908 + struct signal_struct *sig;
58909 +};
58910 +
58911 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58912 +DEFINE_SPINLOCK(gr_conn_table_lock);
58913 +
58914 +extern const char * gr_socktype_to_name(unsigned char type);
58915 +extern const char * gr_proto_to_name(unsigned char proto);
58916 +extern const char * gr_sockfamily_to_name(unsigned char family);
58917 +
58918 +static __inline__ int
58919 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58920 +{
58921 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58922 +}
58923 +
58924 +static __inline__ int
58925 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58926 + __u16 sport, __u16 dport)
58927 +{
58928 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58929 + sig->gr_sport == sport && sig->gr_dport == dport))
58930 + return 1;
58931 + else
58932 + return 0;
58933 +}
58934 +
58935 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58936 +{
58937 + struct conn_table_entry **match;
58938 + unsigned int index;
58939 +
58940 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58941 + sig->gr_sport, sig->gr_dport,
58942 + gr_conn_table_size);
58943 +
58944 + newent->sig = sig;
58945 +
58946 + match = &gr_conn_table[index];
58947 + newent->next = *match;
58948 + *match = newent;
58949 +
58950 + return;
58951 +}
58952 +
58953 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58954 +{
58955 + struct conn_table_entry *match, *last = NULL;
58956 + unsigned int index;
58957 +
58958 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58959 + sig->gr_sport, sig->gr_dport,
58960 + gr_conn_table_size);
58961 +
58962 + match = gr_conn_table[index];
58963 + while (match && !conn_match(match->sig,
58964 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58965 + sig->gr_dport)) {
58966 + last = match;
58967 + match = match->next;
58968 + }
58969 +
58970 + if (match) {
58971 + if (last)
58972 + last->next = match->next;
58973 + else
58974 + gr_conn_table[index] = NULL;
58975 + kfree(match);
58976 + }
58977 +
58978 + return;
58979 +}
58980 +
58981 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58982 + __u16 sport, __u16 dport)
58983 +{
58984 + struct conn_table_entry *match;
58985 + unsigned int index;
58986 +
58987 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58988 +
58989 + match = gr_conn_table[index];
58990 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58991 + match = match->next;
58992 +
58993 + if (match)
58994 + return match->sig;
58995 + else
58996 + return NULL;
58997 +}
58998 +
58999 +#endif
59000 +
59001 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59002 +{
59003 +#ifdef CONFIG_GRKERNSEC
59004 + struct signal_struct *sig = task->signal;
59005 + struct conn_table_entry *newent;
59006 +
59007 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59008 + if (newent == NULL)
59009 + return;
59010 + /* no bh lock needed since we are called with bh disabled */
59011 + spin_lock(&gr_conn_table_lock);
59012 + gr_del_task_from_ip_table_nolock(sig);
59013 + sig->gr_saddr = inet->inet_rcv_saddr;
59014 + sig->gr_daddr = inet->inet_daddr;
59015 + sig->gr_sport = inet->inet_sport;
59016 + sig->gr_dport = inet->inet_dport;
59017 + gr_add_to_task_ip_table_nolock(sig, newent);
59018 + spin_unlock(&gr_conn_table_lock);
59019 +#endif
59020 + return;
59021 +}
59022 +
59023 +void gr_del_task_from_ip_table(struct task_struct *task)
59024 +{
59025 +#ifdef CONFIG_GRKERNSEC
59026 + spin_lock_bh(&gr_conn_table_lock);
59027 + gr_del_task_from_ip_table_nolock(task->signal);
59028 + spin_unlock_bh(&gr_conn_table_lock);
59029 +#endif
59030 + return;
59031 +}
59032 +
59033 +void
59034 +gr_attach_curr_ip(const struct sock *sk)
59035 +{
59036 +#ifdef CONFIG_GRKERNSEC
59037 + struct signal_struct *p, *set;
59038 + const struct inet_sock *inet = inet_sk(sk);
59039 +
59040 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59041 + return;
59042 +
59043 + set = current->signal;
59044 +
59045 + spin_lock_bh(&gr_conn_table_lock);
59046 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59047 + inet->inet_dport, inet->inet_sport);
59048 + if (unlikely(p != NULL)) {
59049 + set->curr_ip = p->curr_ip;
59050 + set->used_accept = 1;
59051 + gr_del_task_from_ip_table_nolock(p);
59052 + spin_unlock_bh(&gr_conn_table_lock);
59053 + return;
59054 + }
59055 + spin_unlock_bh(&gr_conn_table_lock);
59056 +
59057 + set->curr_ip = inet->inet_daddr;
59058 + set->used_accept = 1;
59059 +#endif
59060 + return;
59061 +}
59062 +
59063 +int
59064 +gr_handle_sock_all(const int family, const int type, const int protocol)
59065 +{
59066 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59067 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59068 + (family != AF_UNIX)) {
59069 + if (family == AF_INET)
59070 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59071 + else
59072 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59073 + return -EACCES;
59074 + }
59075 +#endif
59076 + return 0;
59077 +}
59078 +
59079 +int
59080 +gr_handle_sock_server(const struct sockaddr *sck)
59081 +{
59082 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59083 + if (grsec_enable_socket_server &&
59084 + in_group_p(grsec_socket_server_gid) &&
59085 + sck && (sck->sa_family != AF_UNIX) &&
59086 + (sck->sa_family != AF_LOCAL)) {
59087 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59088 + return -EACCES;
59089 + }
59090 +#endif
59091 + return 0;
59092 +}
59093 +
59094 +int
59095 +gr_handle_sock_server_other(const struct sock *sck)
59096 +{
59097 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59098 + if (grsec_enable_socket_server &&
59099 + in_group_p(grsec_socket_server_gid) &&
59100 + sck && (sck->sk_family != AF_UNIX) &&
59101 + (sck->sk_family != AF_LOCAL)) {
59102 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59103 + return -EACCES;
59104 + }
59105 +#endif
59106 + return 0;
59107 +}
59108 +
59109 +int
59110 +gr_handle_sock_client(const struct sockaddr *sck)
59111 +{
59112 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59113 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59114 + sck && (sck->sa_family != AF_UNIX) &&
59115 + (sck->sa_family != AF_LOCAL)) {
59116 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59117 + return -EACCES;
59118 + }
59119 +#endif
59120 + return 0;
59121 +}
59122 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59123 new file mode 100644
59124 index 0000000..bceef2f
59125 --- /dev/null
59126 +++ b/grsecurity/grsec_sysctl.c
59127 @@ -0,0 +1,442 @@
59128 +#include <linux/kernel.h>
59129 +#include <linux/sched.h>
59130 +#include <linux/sysctl.h>
59131 +#include <linux/grsecurity.h>
59132 +#include <linux/grinternal.h>
59133 +
59134 +int
59135 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59136 +{
59137 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59138 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59139 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59140 + return -EACCES;
59141 + }
59142 +#endif
59143 + return 0;
59144 +}
59145 +
59146 +#ifdef CONFIG_GRKERNSEC_ROFS
59147 +static int __maybe_unused one = 1;
59148 +#endif
59149 +
59150 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59151 +struct ctl_table grsecurity_table[] = {
59152 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59153 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59154 +#ifdef CONFIG_GRKERNSEC_IO
59155 + {
59156 + .procname = "disable_priv_io",
59157 + .data = &grsec_disable_privio,
59158 + .maxlen = sizeof(int),
59159 + .mode = 0600,
59160 + .proc_handler = &proc_dointvec,
59161 + },
59162 +#endif
59163 +#endif
59164 +#ifdef CONFIG_GRKERNSEC_LINK
59165 + {
59166 + .procname = "linking_restrictions",
59167 + .data = &grsec_enable_link,
59168 + .maxlen = sizeof(int),
59169 + .mode = 0600,
59170 + .proc_handler = &proc_dointvec,
59171 + },
59172 +#endif
59173 +#ifdef CONFIG_GRKERNSEC_BRUTE
59174 + {
59175 + .procname = "deter_bruteforce",
59176 + .data = &grsec_enable_brute,
59177 + .maxlen = sizeof(int),
59178 + .mode = 0600,
59179 + .proc_handler = &proc_dointvec,
59180 + },
59181 +#endif
59182 +#ifdef CONFIG_GRKERNSEC_FIFO
59183 + {
59184 + .procname = "fifo_restrictions",
59185 + .data = &grsec_enable_fifo,
59186 + .maxlen = sizeof(int),
59187 + .mode = 0600,
59188 + .proc_handler = &proc_dointvec,
59189 + },
59190 +#endif
59191 +#ifdef CONFIG_GRKERNSEC_SETXID
59192 + {
59193 + .procname = "consistent_setxid",
59194 + .data = &grsec_enable_setxid,
59195 + .maxlen = sizeof(int),
59196 + .mode = 0600,
59197 + .proc_handler = &proc_dointvec,
59198 + },
59199 +#endif
59200 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59201 + {
59202 + .procname = "ip_blackhole",
59203 + .data = &grsec_enable_blackhole,
59204 + .maxlen = sizeof(int),
59205 + .mode = 0600,
59206 + .proc_handler = &proc_dointvec,
59207 + },
59208 + {
59209 + .procname = "lastack_retries",
59210 + .data = &grsec_lastack_retries,
59211 + .maxlen = sizeof(int),
59212 + .mode = 0600,
59213 + .proc_handler = &proc_dointvec,
59214 + },
59215 +#endif
59216 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59217 + {
59218 + .procname = "exec_logging",
59219 + .data = &grsec_enable_execlog,
59220 + .maxlen = sizeof(int),
59221 + .mode = 0600,
59222 + .proc_handler = &proc_dointvec,
59223 + },
59224 +#endif
59225 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59226 + {
59227 + .procname = "rwxmap_logging",
59228 + .data = &grsec_enable_log_rwxmaps,
59229 + .maxlen = sizeof(int),
59230 + .mode = 0600,
59231 + .proc_handler = &proc_dointvec,
59232 + },
59233 +#endif
59234 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59235 + {
59236 + .procname = "signal_logging",
59237 + .data = &grsec_enable_signal,
59238 + .maxlen = sizeof(int),
59239 + .mode = 0600,
59240 + .proc_handler = &proc_dointvec,
59241 + },
59242 +#endif
59243 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59244 + {
59245 + .procname = "forkfail_logging",
59246 + .data = &grsec_enable_forkfail,
59247 + .maxlen = sizeof(int),
59248 + .mode = 0600,
59249 + .proc_handler = &proc_dointvec,
59250 + },
59251 +#endif
59252 +#ifdef CONFIG_GRKERNSEC_TIME
59253 + {
59254 + .procname = "timechange_logging",
59255 + .data = &grsec_enable_time,
59256 + .maxlen = sizeof(int),
59257 + .mode = 0600,
59258 + .proc_handler = &proc_dointvec,
59259 + },
59260 +#endif
59261 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59262 + {
59263 + .procname = "chroot_deny_shmat",
59264 + .data = &grsec_enable_chroot_shmat,
59265 + .maxlen = sizeof(int),
59266 + .mode = 0600,
59267 + .proc_handler = &proc_dointvec,
59268 + },
59269 +#endif
59270 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59271 + {
59272 + .procname = "chroot_deny_unix",
59273 + .data = &grsec_enable_chroot_unix,
59274 + .maxlen = sizeof(int),
59275 + .mode = 0600,
59276 + .proc_handler = &proc_dointvec,
59277 + },
59278 +#endif
59279 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59280 + {
59281 + .procname = "chroot_deny_mount",
59282 + .data = &grsec_enable_chroot_mount,
59283 + .maxlen = sizeof(int),
59284 + .mode = 0600,
59285 + .proc_handler = &proc_dointvec,
59286 + },
59287 +#endif
59288 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59289 + {
59290 + .procname = "chroot_deny_fchdir",
59291 + .data = &grsec_enable_chroot_fchdir,
59292 + .maxlen = sizeof(int),
59293 + .mode = 0600,
59294 + .proc_handler = &proc_dointvec,
59295 + },
59296 +#endif
59297 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59298 + {
59299 + .procname = "chroot_deny_chroot",
59300 + .data = &grsec_enable_chroot_double,
59301 + .maxlen = sizeof(int),
59302 + .mode = 0600,
59303 + .proc_handler = &proc_dointvec,
59304 + },
59305 +#endif
59306 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59307 + {
59308 + .procname = "chroot_deny_pivot",
59309 + .data = &grsec_enable_chroot_pivot,
59310 + .maxlen = sizeof(int),
59311 + .mode = 0600,
59312 + .proc_handler = &proc_dointvec,
59313 + },
59314 +#endif
59315 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59316 + {
59317 + .procname = "chroot_enforce_chdir",
59318 + .data = &grsec_enable_chroot_chdir,
59319 + .maxlen = sizeof(int),
59320 + .mode = 0600,
59321 + .proc_handler = &proc_dointvec,
59322 + },
59323 +#endif
59324 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59325 + {
59326 + .procname = "chroot_deny_chmod",
59327 + .data = &grsec_enable_chroot_chmod,
59328 + .maxlen = sizeof(int),
59329 + .mode = 0600,
59330 + .proc_handler = &proc_dointvec,
59331 + },
59332 +#endif
59333 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59334 + {
59335 + .procname = "chroot_deny_mknod",
59336 + .data = &grsec_enable_chroot_mknod,
59337 + .maxlen = sizeof(int),
59338 + .mode = 0600,
59339 + .proc_handler = &proc_dointvec,
59340 + },
59341 +#endif
59342 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59343 + {
59344 + .procname = "chroot_restrict_nice",
59345 + .data = &grsec_enable_chroot_nice,
59346 + .maxlen = sizeof(int),
59347 + .mode = 0600,
59348 + .proc_handler = &proc_dointvec,
59349 + },
59350 +#endif
59351 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59352 + {
59353 + .procname = "chroot_execlog",
59354 + .data = &grsec_enable_chroot_execlog,
59355 + .maxlen = sizeof(int),
59356 + .mode = 0600,
59357 + .proc_handler = &proc_dointvec,
59358 + },
59359 +#endif
59360 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59361 + {
59362 + .procname = "chroot_caps",
59363 + .data = &grsec_enable_chroot_caps,
59364 + .maxlen = sizeof(int),
59365 + .mode = 0600,
59366 + .proc_handler = &proc_dointvec,
59367 + },
59368 +#endif
59369 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59370 + {
59371 + .procname = "chroot_deny_sysctl",
59372 + .data = &grsec_enable_chroot_sysctl,
59373 + .maxlen = sizeof(int),
59374 + .mode = 0600,
59375 + .proc_handler = &proc_dointvec,
59376 + },
59377 +#endif
59378 +#ifdef CONFIG_GRKERNSEC_TPE
59379 + {
59380 + .procname = "tpe",
59381 + .data = &grsec_enable_tpe,
59382 + .maxlen = sizeof(int),
59383 + .mode = 0600,
59384 + .proc_handler = &proc_dointvec,
59385 + },
59386 + {
59387 + .procname = "tpe_gid",
59388 + .data = &grsec_tpe_gid,
59389 + .maxlen = sizeof(int),
59390 + .mode = 0600,
59391 + .proc_handler = &proc_dointvec,
59392 + },
59393 +#endif
59394 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59395 + {
59396 + .procname = "tpe_invert",
59397 + .data = &grsec_enable_tpe_invert,
59398 + .maxlen = sizeof(int),
59399 + .mode = 0600,
59400 + .proc_handler = &proc_dointvec,
59401 + },
59402 +#endif
59403 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59404 + {
59405 + .procname = "tpe_restrict_all",
59406 + .data = &grsec_enable_tpe_all,
59407 + .maxlen = sizeof(int),
59408 + .mode = 0600,
59409 + .proc_handler = &proc_dointvec,
59410 + },
59411 +#endif
59412 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59413 + {
59414 + .procname = "socket_all",
59415 + .data = &grsec_enable_socket_all,
59416 + .maxlen = sizeof(int),
59417 + .mode = 0600,
59418 + .proc_handler = &proc_dointvec,
59419 + },
59420 + {
59421 + .procname = "socket_all_gid",
59422 + .data = &grsec_socket_all_gid,
59423 + .maxlen = sizeof(int),
59424 + .mode = 0600,
59425 + .proc_handler = &proc_dointvec,
59426 + },
59427 +#endif
59428 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59429 + {
59430 + .procname = "socket_client",
59431 + .data = &grsec_enable_socket_client,
59432 + .maxlen = sizeof(int),
59433 + .mode = 0600,
59434 + .proc_handler = &proc_dointvec,
59435 + },
59436 + {
59437 + .procname = "socket_client_gid",
59438 + .data = &grsec_socket_client_gid,
59439 + .maxlen = sizeof(int),
59440 + .mode = 0600,
59441 + .proc_handler = &proc_dointvec,
59442 + },
59443 +#endif
59444 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59445 + {
59446 + .procname = "socket_server",
59447 + .data = &grsec_enable_socket_server,
59448 + .maxlen = sizeof(int),
59449 + .mode = 0600,
59450 + .proc_handler = &proc_dointvec,
59451 + },
59452 + {
59453 + .procname = "socket_server_gid",
59454 + .data = &grsec_socket_server_gid,
59455 + .maxlen = sizeof(int),
59456 + .mode = 0600,
59457 + .proc_handler = &proc_dointvec,
59458 + },
59459 +#endif
59460 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59461 + {
59462 + .procname = "audit_group",
59463 + .data = &grsec_enable_group,
59464 + .maxlen = sizeof(int),
59465 + .mode = 0600,
59466 + .proc_handler = &proc_dointvec,
59467 + },
59468 + {
59469 + .procname = "audit_gid",
59470 + .data = &grsec_audit_gid,
59471 + .maxlen = sizeof(int),
59472 + .mode = 0600,
59473 + .proc_handler = &proc_dointvec,
59474 + },
59475 +#endif
59476 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59477 + {
59478 + .procname = "audit_chdir",
59479 + .data = &grsec_enable_chdir,
59480 + .maxlen = sizeof(int),
59481 + .mode = 0600,
59482 + .proc_handler = &proc_dointvec,
59483 + },
59484 +#endif
59485 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59486 + {
59487 + .procname = "audit_mount",
59488 + .data = &grsec_enable_mount,
59489 + .maxlen = sizeof(int),
59490 + .mode = 0600,
59491 + .proc_handler = &proc_dointvec,
59492 + },
59493 +#endif
59494 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59495 + {
59496 + .procname = "audit_textrel",
59497 + .data = &grsec_enable_audit_textrel,
59498 + .maxlen = sizeof(int),
59499 + .mode = 0600,
59500 + .proc_handler = &proc_dointvec,
59501 + },
59502 +#endif
59503 +#ifdef CONFIG_GRKERNSEC_DMESG
59504 + {
59505 + .procname = "dmesg",
59506 + .data = &grsec_enable_dmesg,
59507 + .maxlen = sizeof(int),
59508 + .mode = 0600,
59509 + .proc_handler = &proc_dointvec,
59510 + },
59511 +#endif
59512 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59513 + {
59514 + .procname = "chroot_findtask",
59515 + .data = &grsec_enable_chroot_findtask,
59516 + .maxlen = sizeof(int),
59517 + .mode = 0600,
59518 + .proc_handler = &proc_dointvec,
59519 + },
59520 +#endif
59521 +#ifdef CONFIG_GRKERNSEC_RESLOG
59522 + {
59523 + .procname = "resource_logging",
59524 + .data = &grsec_resource_logging,
59525 + .maxlen = sizeof(int),
59526 + .mode = 0600,
59527 + .proc_handler = &proc_dointvec,
59528 + },
59529 +#endif
59530 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59531 + {
59532 + .procname = "audit_ptrace",
59533 + .data = &grsec_enable_audit_ptrace,
59534 + .maxlen = sizeof(int),
59535 + .mode = 0600,
59536 + .proc_handler = &proc_dointvec,
59537 + },
59538 +#endif
59539 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59540 + {
59541 + .procname = "harden_ptrace",
59542 + .data = &grsec_enable_harden_ptrace,
59543 + .maxlen = sizeof(int),
59544 + .mode = 0600,
59545 + .proc_handler = &proc_dointvec,
59546 + },
59547 +#endif
59548 + {
59549 + .procname = "grsec_lock",
59550 + .data = &grsec_lock,
59551 + .maxlen = sizeof(int),
59552 + .mode = 0600,
59553 + .proc_handler = &proc_dointvec,
59554 + },
59555 +#endif
59556 +#ifdef CONFIG_GRKERNSEC_ROFS
59557 + {
59558 + .procname = "romount_protect",
59559 + .data = &grsec_enable_rofs,
59560 + .maxlen = sizeof(int),
59561 + .mode = 0600,
59562 + .proc_handler = &proc_dointvec_minmax,
59563 + .extra1 = &one,
59564 + .extra2 = &one,
59565 + },
59566 +#endif
59567 + { }
59568 +};
59569 +#endif
59570 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59571 new file mode 100644
59572 index 0000000..0dc13c3
59573 --- /dev/null
59574 +++ b/grsecurity/grsec_time.c
59575 @@ -0,0 +1,16 @@
59576 +#include <linux/kernel.h>
59577 +#include <linux/sched.h>
59578 +#include <linux/grinternal.h>
59579 +#include <linux/module.h>
59580 +
59581 +void
59582 +gr_log_timechange(void)
59583 +{
59584 +#ifdef CONFIG_GRKERNSEC_TIME
59585 + if (grsec_enable_time)
59586 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59587 +#endif
59588 + return;
59589 +}
59590 +
59591 +EXPORT_SYMBOL(gr_log_timechange);
59592 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59593 new file mode 100644
59594 index 0000000..4a78774
59595 --- /dev/null
59596 +++ b/grsecurity/grsec_tpe.c
59597 @@ -0,0 +1,39 @@
59598 +#include <linux/kernel.h>
59599 +#include <linux/sched.h>
59600 +#include <linux/file.h>
59601 +#include <linux/fs.h>
59602 +#include <linux/grinternal.h>
59603 +
59604 +extern int gr_acl_tpe_check(void);
59605 +
59606 +int
59607 +gr_tpe_allow(const struct file *file)
59608 +{
59609 +#ifdef CONFIG_GRKERNSEC
59610 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59611 + const struct cred *cred = current_cred();
59612 +
59613 + if (cred->uid && ((grsec_enable_tpe &&
59614 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59615 + ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
59616 + (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
59617 +#else
59618 + in_group_p(grsec_tpe_gid)
59619 +#endif
59620 + ) || gr_acl_tpe_check()) &&
59621 + (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
59622 + (inode->i_mode & S_IWOTH))))) {
59623 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59624 + return 0;
59625 + }
59626 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59627 + if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
59628 + ((inode->i_uid && (inode->i_uid != cred->uid)) ||
59629 + (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
59630 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59631 + return 0;
59632 + }
59633 +#endif
59634 +#endif
59635 + return 1;
59636 +}
59637 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59638 new file mode 100644
59639 index 0000000..9f7b1ac
59640 --- /dev/null
59641 +++ b/grsecurity/grsum.c
59642 @@ -0,0 +1,61 @@
59643 +#include <linux/err.h>
59644 +#include <linux/kernel.h>
59645 +#include <linux/sched.h>
59646 +#include <linux/mm.h>
59647 +#include <linux/scatterlist.h>
59648 +#include <linux/crypto.h>
59649 +#include <linux/gracl.h>
59650 +
59651 +
59652 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59653 +#error "crypto and sha256 must be built into the kernel"
59654 +#endif
59655 +
59656 +int
59657 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59658 +{
59659 + char *p;
59660 + struct crypto_hash *tfm;
59661 + struct hash_desc desc;
59662 + struct scatterlist sg;
59663 + unsigned char temp_sum[GR_SHA_LEN];
59664 + volatile int retval = 0;
59665 + volatile int dummy = 0;
59666 + unsigned int i;
59667 +
59668 + sg_init_table(&sg, 1);
59669 +
59670 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59671 + if (IS_ERR(tfm)) {
59672 + /* should never happen, since sha256 should be built in */
59673 + return 1;
59674 + }
59675 +
59676 + desc.tfm = tfm;
59677 + desc.flags = 0;
59678 +
59679 + crypto_hash_init(&desc);
59680 +
59681 + p = salt;
59682 + sg_set_buf(&sg, p, GR_SALT_LEN);
59683 + crypto_hash_update(&desc, &sg, sg.length);
59684 +
59685 + p = entry->pw;
59686 + sg_set_buf(&sg, p, strlen(p));
59687 +
59688 + crypto_hash_update(&desc, &sg, sg.length);
59689 +
59690 + crypto_hash_final(&desc, temp_sum);
59691 +
59692 + memset(entry->pw, 0, GR_PW_LEN);
59693 +
59694 + for (i = 0; i < GR_SHA_LEN; i++)
59695 + if (sum[i] != temp_sum[i])
59696 + retval = 1;
59697 + else
59698 + dummy = 1; // waste a cycle
59699 +
59700 + crypto_free_hash(tfm);
59701 +
59702 + return retval;
59703 +}
59704 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59705 index 6cd5b64..f620d2d 100644
59706 --- a/include/acpi/acpi_bus.h
59707 +++ b/include/acpi/acpi_bus.h
59708 @@ -107,7 +107,7 @@ struct acpi_device_ops {
59709 acpi_op_bind bind;
59710 acpi_op_unbind unbind;
59711 acpi_op_notify notify;
59712 -};
59713 +} __no_const;
59714
59715 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59716
59717 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59718 index b7babf0..71e4e74 100644
59719 --- a/include/asm-generic/atomic-long.h
59720 +++ b/include/asm-generic/atomic-long.h
59721 @@ -22,6 +22,12 @@
59722
59723 typedef atomic64_t atomic_long_t;
59724
59725 +#ifdef CONFIG_PAX_REFCOUNT
59726 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59727 +#else
59728 +typedef atomic64_t atomic_long_unchecked_t;
59729 +#endif
59730 +
59731 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59732
59733 static inline long atomic_long_read(atomic_long_t *l)
59734 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59735 return (long)atomic64_read(v);
59736 }
59737
59738 +#ifdef CONFIG_PAX_REFCOUNT
59739 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59740 +{
59741 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59742 +
59743 + return (long)atomic64_read_unchecked(v);
59744 +}
59745 +#endif
59746 +
59747 static inline void atomic_long_set(atomic_long_t *l, long i)
59748 {
59749 atomic64_t *v = (atomic64_t *)l;
59750 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59751 atomic64_set(v, i);
59752 }
59753
59754 +#ifdef CONFIG_PAX_REFCOUNT
59755 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59756 +{
59757 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59758 +
59759 + atomic64_set_unchecked(v, i);
59760 +}
59761 +#endif
59762 +
59763 static inline void atomic_long_inc(atomic_long_t *l)
59764 {
59765 atomic64_t *v = (atomic64_t *)l;
59766 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59767 atomic64_inc(v);
59768 }
59769
59770 +#ifdef CONFIG_PAX_REFCOUNT
59771 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59772 +{
59773 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59774 +
59775 + atomic64_inc_unchecked(v);
59776 +}
59777 +#endif
59778 +
59779 static inline void atomic_long_dec(atomic_long_t *l)
59780 {
59781 atomic64_t *v = (atomic64_t *)l;
59782 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59783 atomic64_dec(v);
59784 }
59785
59786 +#ifdef CONFIG_PAX_REFCOUNT
59787 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59788 +{
59789 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59790 +
59791 + atomic64_dec_unchecked(v);
59792 +}
59793 +#endif
59794 +
59795 static inline void atomic_long_add(long i, atomic_long_t *l)
59796 {
59797 atomic64_t *v = (atomic64_t *)l;
59798 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59799 atomic64_add(i, v);
59800 }
59801
59802 +#ifdef CONFIG_PAX_REFCOUNT
59803 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59804 +{
59805 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59806 +
59807 + atomic64_add_unchecked(i, v);
59808 +}
59809 +#endif
59810 +
59811 static inline void atomic_long_sub(long i, atomic_long_t *l)
59812 {
59813 atomic64_t *v = (atomic64_t *)l;
59814 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59815 atomic64_sub(i, v);
59816 }
59817
59818 +#ifdef CONFIG_PAX_REFCOUNT
59819 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59820 +{
59821 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59822 +
59823 + atomic64_sub_unchecked(i, v);
59824 +}
59825 +#endif
59826 +
59827 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59828 {
59829 atomic64_t *v = (atomic64_t *)l;
59830 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59831 return (long)atomic64_inc_return(v);
59832 }
59833
59834 +#ifdef CONFIG_PAX_REFCOUNT
59835 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59836 +{
59837 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59838 +
59839 + return (long)atomic64_inc_return_unchecked(v);
59840 +}
59841 +#endif
59842 +
59843 static inline long atomic_long_dec_return(atomic_long_t *l)
59844 {
59845 atomic64_t *v = (atomic64_t *)l;
59846 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59847
59848 typedef atomic_t atomic_long_t;
59849
59850 +#ifdef CONFIG_PAX_REFCOUNT
59851 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59852 +#else
59853 +typedef atomic_t atomic_long_unchecked_t;
59854 +#endif
59855 +
59856 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59857 static inline long atomic_long_read(atomic_long_t *l)
59858 {
59859 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59860 return (long)atomic_read(v);
59861 }
59862
59863 +#ifdef CONFIG_PAX_REFCOUNT
59864 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59865 +{
59866 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59867 +
59868 + return (long)atomic_read_unchecked(v);
59869 +}
59870 +#endif
59871 +
59872 static inline void atomic_long_set(atomic_long_t *l, long i)
59873 {
59874 atomic_t *v = (atomic_t *)l;
59875 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59876 atomic_set(v, i);
59877 }
59878
59879 +#ifdef CONFIG_PAX_REFCOUNT
59880 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59881 +{
59882 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59883 +
59884 + atomic_set_unchecked(v, i);
59885 +}
59886 +#endif
59887 +
59888 static inline void atomic_long_inc(atomic_long_t *l)
59889 {
59890 atomic_t *v = (atomic_t *)l;
59891 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59892 atomic_inc(v);
59893 }
59894
59895 +#ifdef CONFIG_PAX_REFCOUNT
59896 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59897 +{
59898 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59899 +
59900 + atomic_inc_unchecked(v);
59901 +}
59902 +#endif
59903 +
59904 static inline void atomic_long_dec(atomic_long_t *l)
59905 {
59906 atomic_t *v = (atomic_t *)l;
59907 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59908 atomic_dec(v);
59909 }
59910
59911 +#ifdef CONFIG_PAX_REFCOUNT
59912 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59913 +{
59914 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59915 +
59916 + atomic_dec_unchecked(v);
59917 +}
59918 +#endif
59919 +
59920 static inline void atomic_long_add(long i, atomic_long_t *l)
59921 {
59922 atomic_t *v = (atomic_t *)l;
59923 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59924 atomic_add(i, v);
59925 }
59926
59927 +#ifdef CONFIG_PAX_REFCOUNT
59928 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59929 +{
59930 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59931 +
59932 + atomic_add_unchecked(i, v);
59933 +}
59934 +#endif
59935 +
59936 static inline void atomic_long_sub(long i, atomic_long_t *l)
59937 {
59938 atomic_t *v = (atomic_t *)l;
59939 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59940 atomic_sub(i, v);
59941 }
59942
59943 +#ifdef CONFIG_PAX_REFCOUNT
59944 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59945 +{
59946 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59947 +
59948 + atomic_sub_unchecked(i, v);
59949 +}
59950 +#endif
59951 +
59952 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59953 {
59954 atomic_t *v = (atomic_t *)l;
59955 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59956 return (long)atomic_inc_return(v);
59957 }
59958
59959 +#ifdef CONFIG_PAX_REFCOUNT
59960 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59961 +{
59962 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59963 +
59964 + return (long)atomic_inc_return_unchecked(v);
59965 +}
59966 +#endif
59967 +
59968 static inline long atomic_long_dec_return(atomic_long_t *l)
59969 {
59970 atomic_t *v = (atomic_t *)l;
59971 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59972
59973 #endif /* BITS_PER_LONG == 64 */
59974
59975 +#ifdef CONFIG_PAX_REFCOUNT
59976 +static inline void pax_refcount_needs_these_functions(void)
59977 +{
59978 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
59979 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59980 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59981 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59982 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59983 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59984 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59985 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59986 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59987 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59988 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59989 +
59990 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59991 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59992 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59993 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59994 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59995 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59996 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59997 +}
59998 +#else
59999 +#define atomic_read_unchecked(v) atomic_read(v)
60000 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60001 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60002 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60003 +#define atomic_inc_unchecked(v) atomic_inc(v)
60004 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60005 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60006 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60007 +#define atomic_dec_unchecked(v) atomic_dec(v)
60008 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60009 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60010 +
60011 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60012 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60013 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60014 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60015 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60016 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60017 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60018 +#endif
60019 +
60020 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60021 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60022 index b18ce4f..2ee2843 100644
60023 --- a/include/asm-generic/atomic64.h
60024 +++ b/include/asm-generic/atomic64.h
60025 @@ -16,6 +16,8 @@ typedef struct {
60026 long long counter;
60027 } atomic64_t;
60028
60029 +typedef atomic64_t atomic64_unchecked_t;
60030 +
60031 #define ATOMIC64_INIT(i) { (i) }
60032
60033 extern long long atomic64_read(const atomic64_t *v);
60034 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60035 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60036 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60037
60038 +#define atomic64_read_unchecked(v) atomic64_read(v)
60039 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60040 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60041 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60042 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60043 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60044 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60045 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60046 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60047 +
60048 #endif /* _ASM_GENERIC_ATOMIC64_H */
60049 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60050 index 1bfcfe5..e04c5c9 100644
60051 --- a/include/asm-generic/cache.h
60052 +++ b/include/asm-generic/cache.h
60053 @@ -6,7 +6,7 @@
60054 * cache lines need to provide their own cache.h.
60055 */
60056
60057 -#define L1_CACHE_SHIFT 5
60058 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60059 +#define L1_CACHE_SHIFT 5UL
60060 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60061
60062 #endif /* __ASM_GENERIC_CACHE_H */
60063 diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
60064 index 1ca3efc..e3dc852 100644
60065 --- a/include/asm-generic/int-l64.h
60066 +++ b/include/asm-generic/int-l64.h
60067 @@ -46,6 +46,8 @@ typedef unsigned int u32;
60068 typedef signed long s64;
60069 typedef unsigned long u64;
60070
60071 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
60072 +
60073 #define S8_C(x) x
60074 #define U8_C(x) x ## U
60075 #define S16_C(x) x
60076 diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
60077 index f394147..b6152b9 100644
60078 --- a/include/asm-generic/int-ll64.h
60079 +++ b/include/asm-generic/int-ll64.h
60080 @@ -51,6 +51,8 @@ typedef unsigned int u32;
60081 typedef signed long long s64;
60082 typedef unsigned long long u64;
60083
60084 +typedef unsigned long long intoverflow_t;
60085 +
60086 #define S8_C(x) x
60087 #define U8_C(x) x ## U
60088 #define S16_C(x) x
60089 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60090 index 0232ccb..13d9165 100644
60091 --- a/include/asm-generic/kmap_types.h
60092 +++ b/include/asm-generic/kmap_types.h
60093 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60094 KMAP_D(17) KM_NMI,
60095 KMAP_D(18) KM_NMI_PTE,
60096 KMAP_D(19) KM_KDB,
60097 +KMAP_D(20) KM_CLEARPAGE,
60098 /*
60099 * Remember to update debug_kmap_atomic() when adding new kmap types!
60100 */
60101 -KMAP_D(20) KM_TYPE_NR
60102 +KMAP_D(21) KM_TYPE_NR
60103 };
60104
60105 #undef KMAP_D
60106 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60107 index 725612b..9cc513a 100644
60108 --- a/include/asm-generic/pgtable-nopmd.h
60109 +++ b/include/asm-generic/pgtable-nopmd.h
60110 @@ -1,14 +1,19 @@
60111 #ifndef _PGTABLE_NOPMD_H
60112 #define _PGTABLE_NOPMD_H
60113
60114 -#ifndef __ASSEMBLY__
60115 -
60116 #include <asm-generic/pgtable-nopud.h>
60117
60118 -struct mm_struct;
60119 -
60120 #define __PAGETABLE_PMD_FOLDED
60121
60122 +#define PMD_SHIFT PUD_SHIFT
60123 +#define PTRS_PER_PMD 1
60124 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60125 +#define PMD_MASK (~(PMD_SIZE-1))
60126 +
60127 +#ifndef __ASSEMBLY__
60128 +
60129 +struct mm_struct;
60130 +
60131 /*
60132 * Having the pmd type consist of a pud gets the size right, and allows
60133 * us to conceptually access the pud entry that this pmd is folded into
60134 @@ -16,11 +21,6 @@ struct mm_struct;
60135 */
60136 typedef struct { pud_t pud; } pmd_t;
60137
60138 -#define PMD_SHIFT PUD_SHIFT
60139 -#define PTRS_PER_PMD 1
60140 -#define PMD_SIZE (1UL << PMD_SHIFT)
60141 -#define PMD_MASK (~(PMD_SIZE-1))
60142 -
60143 /*
60144 * The "pud_xxx()" functions here are trivial for a folded two-level
60145 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60146 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60147 index 810431d..ccc3638 100644
60148 --- a/include/asm-generic/pgtable-nopud.h
60149 +++ b/include/asm-generic/pgtable-nopud.h
60150 @@ -1,10 +1,15 @@
60151 #ifndef _PGTABLE_NOPUD_H
60152 #define _PGTABLE_NOPUD_H
60153
60154 -#ifndef __ASSEMBLY__
60155 -
60156 #define __PAGETABLE_PUD_FOLDED
60157
60158 +#define PUD_SHIFT PGDIR_SHIFT
60159 +#define PTRS_PER_PUD 1
60160 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60161 +#define PUD_MASK (~(PUD_SIZE-1))
60162 +
60163 +#ifndef __ASSEMBLY__
60164 +
60165 /*
60166 * Having the pud type consist of a pgd gets the size right, and allows
60167 * us to conceptually access the pgd entry that this pud is folded into
60168 @@ -12,11 +17,6 @@
60169 */
60170 typedef struct { pgd_t pgd; } pud_t;
60171
60172 -#define PUD_SHIFT PGDIR_SHIFT
60173 -#define PTRS_PER_PUD 1
60174 -#define PUD_SIZE (1UL << PUD_SHIFT)
60175 -#define PUD_MASK (~(PUD_SIZE-1))
60176 -
60177 /*
60178 * The "pgd_xxx()" functions here are trivial for a folded two-level
60179 * setup: the pud is never bad, and a pud always exists (as it's folded
60180 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60181 index 76bff2b..c7a14e2 100644
60182 --- a/include/asm-generic/pgtable.h
60183 +++ b/include/asm-generic/pgtable.h
60184 @@ -443,6 +443,14 @@ static inline int pmd_write(pmd_t pmd)
60185 #endif /* __HAVE_ARCH_PMD_WRITE */
60186 #endif
60187
60188 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60189 +static inline unsigned long pax_open_kernel(void) { return 0; }
60190 +#endif
60191 +
60192 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60193 +static inline unsigned long pax_close_kernel(void) { return 0; }
60194 +#endif
60195 +
60196 #endif /* !__ASSEMBLY__ */
60197
60198 #endif /* _ASM_GENERIC_PGTABLE_H */
60199 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60200 index db22d13..1f2e3e1 100644
60201 --- a/include/asm-generic/vmlinux.lds.h
60202 +++ b/include/asm-generic/vmlinux.lds.h
60203 @@ -217,6 +217,7 @@
60204 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60205 VMLINUX_SYMBOL(__start_rodata) = .; \
60206 *(.rodata) *(.rodata.*) \
60207 + *(.data..read_only) \
60208 *(__vermagic) /* Kernel version magic */ \
60209 . = ALIGN(8); \
60210 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60211 @@ -723,17 +724,18 @@
60212 * section in the linker script will go there too. @phdr should have
60213 * a leading colon.
60214 *
60215 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60216 + * Note that this macros defines per_cpu_load as an absolute symbol.
60217 * If there is no need to put the percpu section at a predetermined
60218 * address, use PERCPU_SECTION.
60219 */
60220 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60221 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60222 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60223 + per_cpu_load = .; \
60224 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60225 - LOAD_OFFSET) { \
60226 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60227 PERCPU_INPUT(cacheline) \
60228 } phdr \
60229 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60230 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60231
60232 /**
60233 * PERCPU_SECTION - define output section for percpu area, simple version
60234 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60235 index 9b7c2bb..76b7d1e 100644
60236 --- a/include/drm/drmP.h
60237 +++ b/include/drm/drmP.h
60238 @@ -73,6 +73,7 @@
60239 #include <linux/workqueue.h>
60240 #include <linux/poll.h>
60241 #include <asm/pgalloc.h>
60242 +#include <asm/local.h>
60243 #include "drm.h"
60244
60245 #include <linux/idr.h>
60246 @@ -1035,7 +1036,7 @@ struct drm_device {
60247
60248 /** \name Usage Counters */
60249 /*@{ */
60250 - int open_count; /**< Outstanding files open */
60251 + local_t open_count; /**< Outstanding files open */
60252 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60253 atomic_t vma_count; /**< Outstanding vma areas open */
60254 int buf_use; /**< Buffers in use -- cannot alloc */
60255 @@ -1046,7 +1047,7 @@ struct drm_device {
60256 /*@{ */
60257 unsigned long counters;
60258 enum drm_stat_type types[15];
60259 - atomic_t counts[15];
60260 + atomic_unchecked_t counts[15];
60261 /*@} */
60262
60263 struct list_head filelist;
60264 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60265 index 73b0712..0b7ef2f 100644
60266 --- a/include/drm/drm_crtc_helper.h
60267 +++ b/include/drm/drm_crtc_helper.h
60268 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
60269
60270 /* disable crtc when not in use - more explicit than dpms off */
60271 void (*disable)(struct drm_crtc *crtc);
60272 -};
60273 +} __no_const;
60274
60275 struct drm_encoder_helper_funcs {
60276 void (*dpms)(struct drm_encoder *encoder, int mode);
60277 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
60278 struct drm_connector *connector);
60279 /* disable encoder when not in use - more explicit than dpms off */
60280 void (*disable)(struct drm_encoder *encoder);
60281 -};
60282 +} __no_const;
60283
60284 struct drm_connector_helper_funcs {
60285 int (*get_modes)(struct drm_connector *connector);
60286 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60287 index 26c1f78..6722682 100644
60288 --- a/include/drm/ttm/ttm_memory.h
60289 +++ b/include/drm/ttm/ttm_memory.h
60290 @@ -47,7 +47,7 @@
60291
60292 struct ttm_mem_shrink {
60293 int (*do_shrink) (struct ttm_mem_shrink *);
60294 -};
60295 +} __no_const;
60296
60297 /**
60298 * struct ttm_mem_global - Global memory accounting structure.
60299 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60300 index e86dfca..40cc55f 100644
60301 --- a/include/linux/a.out.h
60302 +++ b/include/linux/a.out.h
60303 @@ -39,6 +39,14 @@ enum machine_type {
60304 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60305 };
60306
60307 +/* Constants for the N_FLAGS field */
60308 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60309 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60310 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60311 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60312 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60313 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60314 +
60315 #if !defined (N_MAGIC)
60316 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60317 #endif
60318 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60319 index 49a83ca..df96b54 100644
60320 --- a/include/linux/atmdev.h
60321 +++ b/include/linux/atmdev.h
60322 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60323 #endif
60324
60325 struct k_atm_aal_stats {
60326 -#define __HANDLE_ITEM(i) atomic_t i
60327 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60328 __AAL_STAT_ITEMS
60329 #undef __HANDLE_ITEM
60330 };
60331 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60332 index fd88a39..f4d0bad 100644
60333 --- a/include/linux/binfmts.h
60334 +++ b/include/linux/binfmts.h
60335 @@ -88,6 +88,7 @@ struct linux_binfmt {
60336 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60337 int (*load_shlib)(struct file *);
60338 int (*core_dump)(struct coredump_params *cprm);
60339 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60340 unsigned long min_coredump; /* minimal dump size */
60341 };
60342
60343 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60344 index 5e30b45..5fdcf66 100644
60345 --- a/include/linux/blkdev.h
60346 +++ b/include/linux/blkdev.h
60347 @@ -1318,7 +1318,7 @@ struct block_device_operations {
60348 /* this callback is with swap_lock and sometimes page table lock held */
60349 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60350 struct module *owner;
60351 -};
60352 +} __do_const;
60353
60354 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60355 unsigned long);
60356 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60357 index 8e9e4bc..88bd457 100644
60358 --- a/include/linux/blktrace_api.h
60359 +++ b/include/linux/blktrace_api.h
60360 @@ -162,7 +162,7 @@ struct blk_trace {
60361 struct dentry *dir;
60362 struct dentry *dropped_file;
60363 struct dentry *msg_file;
60364 - atomic_t dropped;
60365 + atomic_unchecked_t dropped;
60366 };
60367
60368 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60369 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60370 index 83195fb..0b0f77d 100644
60371 --- a/include/linux/byteorder/little_endian.h
60372 +++ b/include/linux/byteorder/little_endian.h
60373 @@ -42,51 +42,51 @@
60374
60375 static inline __le64 __cpu_to_le64p(const __u64 *p)
60376 {
60377 - return (__force __le64)*p;
60378 + return (__force const __le64)*p;
60379 }
60380 static inline __u64 __le64_to_cpup(const __le64 *p)
60381 {
60382 - return (__force __u64)*p;
60383 + return (__force const __u64)*p;
60384 }
60385 static inline __le32 __cpu_to_le32p(const __u32 *p)
60386 {
60387 - return (__force __le32)*p;
60388 + return (__force const __le32)*p;
60389 }
60390 static inline __u32 __le32_to_cpup(const __le32 *p)
60391 {
60392 - return (__force __u32)*p;
60393 + return (__force const __u32)*p;
60394 }
60395 static inline __le16 __cpu_to_le16p(const __u16 *p)
60396 {
60397 - return (__force __le16)*p;
60398 + return (__force const __le16)*p;
60399 }
60400 static inline __u16 __le16_to_cpup(const __le16 *p)
60401 {
60402 - return (__force __u16)*p;
60403 + return (__force const __u16)*p;
60404 }
60405 static inline __be64 __cpu_to_be64p(const __u64 *p)
60406 {
60407 - return (__force __be64)__swab64p(p);
60408 + return (__force const __be64)__swab64p(p);
60409 }
60410 static inline __u64 __be64_to_cpup(const __be64 *p)
60411 {
60412 - return __swab64p((__u64 *)p);
60413 + return __swab64p((const __u64 *)p);
60414 }
60415 static inline __be32 __cpu_to_be32p(const __u32 *p)
60416 {
60417 - return (__force __be32)__swab32p(p);
60418 + return (__force const __be32)__swab32p(p);
60419 }
60420 static inline __u32 __be32_to_cpup(const __be32 *p)
60421 {
60422 - return __swab32p((__u32 *)p);
60423 + return __swab32p((const __u32 *)p);
60424 }
60425 static inline __be16 __cpu_to_be16p(const __u16 *p)
60426 {
60427 - return (__force __be16)__swab16p(p);
60428 + return (__force const __be16)__swab16p(p);
60429 }
60430 static inline __u16 __be16_to_cpup(const __be16 *p)
60431 {
60432 - return __swab16p((__u16 *)p);
60433 + return __swab16p((const __u16 *)p);
60434 }
60435 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60436 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60437 diff --git a/include/linux/cache.h b/include/linux/cache.h
60438 index 4c57065..4307975 100644
60439 --- a/include/linux/cache.h
60440 +++ b/include/linux/cache.h
60441 @@ -16,6 +16,10 @@
60442 #define __read_mostly
60443 #endif
60444
60445 +#ifndef __read_only
60446 +#define __read_only __read_mostly
60447 +#endif
60448 +
60449 #ifndef ____cacheline_aligned
60450 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60451 #endif
60452 diff --git a/include/linux/capability.h b/include/linux/capability.h
60453 index c421123..e343179 100644
60454 --- a/include/linux/capability.h
60455 +++ b/include/linux/capability.h
60456 @@ -547,6 +547,9 @@ extern bool capable(int cap);
60457 extern bool ns_capable(struct user_namespace *ns, int cap);
60458 extern bool task_ns_capable(struct task_struct *t, int cap);
60459 extern bool nsown_capable(int cap);
60460 +extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
60461 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60462 +extern bool capable_nolog(int cap);
60463
60464 /* audit system wants to get cap info from files as well */
60465 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60466 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60467 index 04ffb2e..6799180 100644
60468 --- a/include/linux/cleancache.h
60469 +++ b/include/linux/cleancache.h
60470 @@ -31,7 +31,7 @@ struct cleancache_ops {
60471 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
60472 void (*flush_inode)(int, struct cleancache_filekey);
60473 void (*flush_fs)(int);
60474 -};
60475 +} __no_const;
60476
60477 extern struct cleancache_ops
60478 cleancache_register_ops(struct cleancache_ops *ops);
60479 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60480 index dfadc96..c0e70c1 100644
60481 --- a/include/linux/compiler-gcc4.h
60482 +++ b/include/linux/compiler-gcc4.h
60483 @@ -31,6 +31,12 @@
60484
60485
60486 #if __GNUC_MINOR__ >= 5
60487 +
60488 +#ifdef CONSTIFY_PLUGIN
60489 +#define __no_const __attribute__((no_const))
60490 +#define __do_const __attribute__((do_const))
60491 +#endif
60492 +
60493 /*
60494 * Mark a position in code as unreachable. This can be used to
60495 * suppress control flow warnings after asm blocks that transfer
60496 @@ -46,6 +52,11 @@
60497 #define __noclone __attribute__((__noclone__))
60498
60499 #endif
60500 +
60501 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60502 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60503 +#define __bos0(ptr) __bos((ptr), 0)
60504 +#define __bos1(ptr) __bos((ptr), 1)
60505 #endif
60506
60507 #if __GNUC_MINOR__ > 0
60508 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60509 index 320d6c9..8573a1c 100644
60510 --- a/include/linux/compiler.h
60511 +++ b/include/linux/compiler.h
60512 @@ -5,31 +5,62 @@
60513
60514 #ifdef __CHECKER__
60515 # define __user __attribute__((noderef, address_space(1)))
60516 +# define __force_user __force __user
60517 # define __kernel __attribute__((address_space(0)))
60518 +# define __force_kernel __force __kernel
60519 # define __safe __attribute__((safe))
60520 # define __force __attribute__((force))
60521 # define __nocast __attribute__((nocast))
60522 # define __iomem __attribute__((noderef, address_space(2)))
60523 +# define __force_iomem __force __iomem
60524 # define __acquires(x) __attribute__((context(x,0,1)))
60525 # define __releases(x) __attribute__((context(x,1,0)))
60526 # define __acquire(x) __context__(x,1)
60527 # define __release(x) __context__(x,-1)
60528 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60529 # define __percpu __attribute__((noderef, address_space(3)))
60530 +# define __force_percpu __force __percpu
60531 #ifdef CONFIG_SPARSE_RCU_POINTER
60532 # define __rcu __attribute__((noderef, address_space(4)))
60533 +# define __force_rcu __force __rcu
60534 #else
60535 # define __rcu
60536 +# define __force_rcu
60537 #endif
60538 extern void __chk_user_ptr(const volatile void __user *);
60539 extern void __chk_io_ptr(const volatile void __iomem *);
60540 +#elif defined(CHECKER_PLUGIN)
60541 +//# define __user
60542 +//# define __force_user
60543 +//# define __kernel
60544 +//# define __force_kernel
60545 +# define __safe
60546 +# define __force
60547 +# define __nocast
60548 +# define __iomem
60549 +# define __force_iomem
60550 +# define __chk_user_ptr(x) (void)0
60551 +# define __chk_io_ptr(x) (void)0
60552 +# define __builtin_warning(x, y...) (1)
60553 +# define __acquires(x)
60554 +# define __releases(x)
60555 +# define __acquire(x) (void)0
60556 +# define __release(x) (void)0
60557 +# define __cond_lock(x,c) (c)
60558 +# define __percpu
60559 +# define __force_percpu
60560 +# define __rcu
60561 +# define __force_rcu
60562 #else
60563 # define __user
60564 +# define __force_user
60565 # define __kernel
60566 +# define __force_kernel
60567 # define __safe
60568 # define __force
60569 # define __nocast
60570 # define __iomem
60571 +# define __force_iomem
60572 # define __chk_user_ptr(x) (void)0
60573 # define __chk_io_ptr(x) (void)0
60574 # define __builtin_warning(x, y...) (1)
60575 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60576 # define __release(x) (void)0
60577 # define __cond_lock(x,c) (c)
60578 # define __percpu
60579 +# define __force_percpu
60580 # define __rcu
60581 +# define __force_rcu
60582 #endif
60583
60584 #ifdef __KERNEL__
60585 @@ -264,6 +297,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60586 # define __attribute_const__ /* unimplemented */
60587 #endif
60588
60589 +#ifndef __no_const
60590 +# define __no_const
60591 +#endif
60592 +
60593 +#ifndef __do_const
60594 +# define __do_const
60595 +#endif
60596 +
60597 /*
60598 * Tell gcc if a function is cold. The compiler will assume any path
60599 * directly leading to the call is unlikely.
60600 @@ -273,6 +314,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60601 #define __cold
60602 #endif
60603
60604 +#ifndef __alloc_size
60605 +#define __alloc_size(...)
60606 +#endif
60607 +
60608 +#ifndef __bos
60609 +#define __bos(ptr, arg)
60610 +#endif
60611 +
60612 +#ifndef __bos0
60613 +#define __bos0(ptr)
60614 +#endif
60615 +
60616 +#ifndef __bos1
60617 +#define __bos1(ptr)
60618 +#endif
60619 +
60620 /* Simple shorthand for a section definition */
60621 #ifndef __section
60622 # define __section(S) __attribute__ ((__section__(#S)))
60623 @@ -306,6 +363,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60624 * use is to mediate communication between process-level code and irq/NMI
60625 * handlers, all running on the same CPU.
60626 */
60627 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60628 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60629 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60630
60631 #endif /* __LINUX_COMPILER_H */
60632 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
60633 index e9eaec5..bfeb9bb 100644
60634 --- a/include/linux/cpuset.h
60635 +++ b/include/linux/cpuset.h
60636 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
60637 * nodemask.
60638 */
60639 smp_mb();
60640 - --ACCESS_ONCE(current->mems_allowed_change_disable);
60641 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
60642 }
60643
60644 static inline void set_mems_allowed(nodemask_t nodemask)
60645 diff --git a/include/linux/cred.h b/include/linux/cred.h
60646 index 4030896..a5c9f09 100644
60647 --- a/include/linux/cred.h
60648 +++ b/include/linux/cred.h
60649 @@ -196,6 +196,11 @@ do { \
60650 __validate_process_creds(current, __FILE__, __LINE__); \
60651 } while(0)
60652
60653 +#define validate_task_creds(task) \
60654 +do { \
60655 + __validate_process_creds((task), __FILE__, __LINE__); \
60656 +} while(0)
60657 +
60658 extern void validate_creds_for_do_exit(struct task_struct *);
60659 #else
60660 static inline void validate_creds(const struct cred *cred)
60661 @@ -207,6 +212,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60662 static inline void validate_process_creds(void)
60663 {
60664 }
60665 +static inline void validate_task_creds(struct task_struct *task)
60666 +{
60667 +}
60668 #endif
60669
60670 /**
60671 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60672 index e5e468e..f079672 100644
60673 --- a/include/linux/crypto.h
60674 +++ b/include/linux/crypto.h
60675 @@ -361,7 +361,7 @@ struct cipher_tfm {
60676 const u8 *key, unsigned int keylen);
60677 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60678 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60679 -};
60680 +} __no_const;
60681
60682 struct hash_tfm {
60683 int (*init)(struct hash_desc *desc);
60684 @@ -382,13 +382,13 @@ struct compress_tfm {
60685 int (*cot_decompress)(struct crypto_tfm *tfm,
60686 const u8 *src, unsigned int slen,
60687 u8 *dst, unsigned int *dlen);
60688 -};
60689 +} __no_const;
60690
60691 struct rng_tfm {
60692 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60693 unsigned int dlen);
60694 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60695 -};
60696 +} __no_const;
60697
60698 #define crt_ablkcipher crt_u.ablkcipher
60699 #define crt_aead crt_u.aead
60700 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60701 index 7925bf0..d5143d2 100644
60702 --- a/include/linux/decompress/mm.h
60703 +++ b/include/linux/decompress/mm.h
60704 @@ -77,7 +77,7 @@ static void free(void *where)
60705 * warnings when not needed (indeed large_malloc / large_free are not
60706 * needed by inflate */
60707
60708 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60709 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60710 #define free(a) kfree(a)
60711
60712 #define large_malloc(a) vmalloc(a)
60713 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60714 index 347fdc3..cd01657 100644
60715 --- a/include/linux/dma-mapping.h
60716 +++ b/include/linux/dma-mapping.h
60717 @@ -42,7 +42,7 @@ struct dma_map_ops {
60718 int (*dma_supported)(struct device *dev, u64 mask);
60719 int (*set_dma_mask)(struct device *dev, u64 mask);
60720 int is_phys;
60721 -};
60722 +} __do_const;
60723
60724 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60725
60726 diff --git a/include/linux/efi.h b/include/linux/efi.h
60727 index 2362a0b..cfaf8fcc 100644
60728 --- a/include/linux/efi.h
60729 +++ b/include/linux/efi.h
60730 @@ -446,7 +446,7 @@ struct efivar_operations {
60731 efi_get_variable_t *get_variable;
60732 efi_get_next_variable_t *get_next_variable;
60733 efi_set_variable_t *set_variable;
60734 -};
60735 +} __no_const;
60736
60737 struct efivars {
60738 /*
60739 diff --git a/include/linux/elf.h b/include/linux/elf.h
60740 index 110821c..cb14c08 100644
60741 --- a/include/linux/elf.h
60742 +++ b/include/linux/elf.h
60743 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
60744 #define PT_GNU_EH_FRAME 0x6474e550
60745
60746 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60747 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60748 +
60749 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60750 +
60751 +/* Constants for the e_flags field */
60752 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60753 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60754 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60755 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60756 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60757 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60758
60759 /*
60760 * Extended Numbering
60761 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
60762 #define DT_DEBUG 21
60763 #define DT_TEXTREL 22
60764 #define DT_JMPREL 23
60765 +#define DT_FLAGS 30
60766 + #define DF_TEXTREL 0x00000004
60767 #define DT_ENCODING 32
60768 #define OLD_DT_LOOS 0x60000000
60769 #define DT_LOOS 0x6000000d
60770 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
60771 #define PF_W 0x2
60772 #define PF_X 0x1
60773
60774 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60775 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60776 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60777 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60778 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60779 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60780 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60781 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60782 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60783 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60784 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60785 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60786 +
60787 typedef struct elf32_phdr{
60788 Elf32_Word p_type;
60789 Elf32_Off p_offset;
60790 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
60791 #define EI_OSABI 7
60792 #define EI_PAD 8
60793
60794 +#define EI_PAX 14
60795 +
60796 #define ELFMAG0 0x7f /* EI_MAG */
60797 #define ELFMAG1 'E'
60798 #define ELFMAG2 'L'
60799 @@ -422,6 +450,7 @@ extern Elf32_Dyn _DYNAMIC [];
60800 #define elf_note elf32_note
60801 #define elf_addr_t Elf32_Off
60802 #define Elf_Half Elf32_Half
60803 +#define elf_dyn Elf32_Dyn
60804
60805 #else
60806
60807 @@ -432,6 +461,7 @@ extern Elf64_Dyn _DYNAMIC [];
60808 #define elf_note elf64_note
60809 #define elf_addr_t Elf64_Off
60810 #define Elf_Half Elf64_Half
60811 +#define elf_dyn Elf64_Dyn
60812
60813 #endif
60814
60815 diff --git a/include/linux/filter.h b/include/linux/filter.h
60816 index 741956f..f02f482 100644
60817 --- a/include/linux/filter.h
60818 +++ b/include/linux/filter.h
60819 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60820
60821 struct sk_buff;
60822 struct sock;
60823 +struct bpf_jit_work;
60824
60825 struct sk_filter
60826 {
60827 @@ -141,6 +142,9 @@ struct sk_filter
60828 unsigned int len; /* Number of filter blocks */
60829 unsigned int (*bpf_func)(const struct sk_buff *skb,
60830 const struct sock_filter *filter);
60831 +#ifdef CONFIG_BPF_JIT
60832 + struct bpf_jit_work *work;
60833 +#endif
60834 struct rcu_head rcu;
60835 struct sock_filter insns[0];
60836 };
60837 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60838 index 84ccf8e..2e9b14c 100644
60839 --- a/include/linux/firewire.h
60840 +++ b/include/linux/firewire.h
60841 @@ -428,7 +428,7 @@ struct fw_iso_context {
60842 union {
60843 fw_iso_callback_t sc;
60844 fw_iso_mc_callback_t mc;
60845 - } callback;
60846 + } __no_const callback;
60847 void *callback_data;
60848 };
60849
60850 diff --git a/include/linux/fs.h b/include/linux/fs.h
60851 index cf7bc25..0d2babf 100644
60852 --- a/include/linux/fs.h
60853 +++ b/include/linux/fs.h
60854 @@ -1588,7 +1588,8 @@ struct file_operations {
60855 int (*setlease)(struct file *, long, struct file_lock **);
60856 long (*fallocate)(struct file *file, int mode, loff_t offset,
60857 loff_t len);
60858 -};
60859 +} __do_const;
60860 +typedef struct file_operations __no_const file_operations_no_const;
60861
60862 struct inode_operations {
60863 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60864 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60865 index 003dc0f..3c4ea97 100644
60866 --- a/include/linux/fs_struct.h
60867 +++ b/include/linux/fs_struct.h
60868 @@ -6,7 +6,7 @@
60869 #include <linux/seqlock.h>
60870
60871 struct fs_struct {
60872 - int users;
60873 + atomic_t users;
60874 spinlock_t lock;
60875 seqcount_t seq;
60876 int umask;
60877 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60878 index af095b5..cf1220c 100644
60879 --- a/include/linux/fscache-cache.h
60880 +++ b/include/linux/fscache-cache.h
60881 @@ -102,7 +102,7 @@ struct fscache_operation {
60882 fscache_operation_release_t release;
60883 };
60884
60885 -extern atomic_t fscache_op_debug_id;
60886 +extern atomic_unchecked_t fscache_op_debug_id;
60887 extern void fscache_op_work_func(struct work_struct *work);
60888
60889 extern void fscache_enqueue_operation(struct fscache_operation *);
60890 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60891 {
60892 INIT_WORK(&op->work, fscache_op_work_func);
60893 atomic_set(&op->usage, 1);
60894 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60895 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60896 op->processor = processor;
60897 op->release = release;
60898 INIT_LIST_HEAD(&op->pend_link);
60899 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60900 index 2a53f10..0187fdf 100644
60901 --- a/include/linux/fsnotify.h
60902 +++ b/include/linux/fsnotify.h
60903 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60904 */
60905 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60906 {
60907 - return kstrdup(name, GFP_KERNEL);
60908 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60909 }
60910
60911 /*
60912 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60913 index 91d0e0a3..035666b 100644
60914 --- a/include/linux/fsnotify_backend.h
60915 +++ b/include/linux/fsnotify_backend.h
60916 @@ -105,6 +105,7 @@ struct fsnotify_ops {
60917 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60918 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60919 };
60920 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60921
60922 /*
60923 * A group is a "thing" that wants to receive notification about filesystem
60924 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60925 index 96efa67..1261547 100644
60926 --- a/include/linux/ftrace_event.h
60927 +++ b/include/linux/ftrace_event.h
60928 @@ -97,7 +97,7 @@ struct trace_event_functions {
60929 trace_print_func raw;
60930 trace_print_func hex;
60931 trace_print_func binary;
60932 -};
60933 +} __no_const;
60934
60935 struct trace_event {
60936 struct hlist_node node;
60937 @@ -252,7 +252,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60938 extern int trace_add_event_call(struct ftrace_event_call *call);
60939 extern void trace_remove_event_call(struct ftrace_event_call *call);
60940
60941 -#define is_signed_type(type) (((type)(-1)) < 0)
60942 +#define is_signed_type(type) (((type)(-1)) < (type)1)
60943
60944 int trace_set_clr_event(const char *system, const char *event, int set);
60945
60946 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60947 index 02fa469..a15f279 100644
60948 --- a/include/linux/genhd.h
60949 +++ b/include/linux/genhd.h
60950 @@ -184,7 +184,7 @@ struct gendisk {
60951 struct kobject *slave_dir;
60952
60953 struct timer_rand_state *random;
60954 - atomic_t sync_io; /* RAID */
60955 + atomic_unchecked_t sync_io; /* RAID */
60956 struct disk_events *ev;
60957 #ifdef CONFIG_BLK_DEV_INTEGRITY
60958 struct blk_integrity *integrity;
60959 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60960 new file mode 100644
60961 index 0000000..0dc3943
60962 --- /dev/null
60963 +++ b/include/linux/gracl.h
60964 @@ -0,0 +1,317 @@
60965 +#ifndef GR_ACL_H
60966 +#define GR_ACL_H
60967 +
60968 +#include <linux/grdefs.h>
60969 +#include <linux/resource.h>
60970 +#include <linux/capability.h>
60971 +#include <linux/dcache.h>
60972 +#include <asm/resource.h>
60973 +
60974 +/* Major status information */
60975 +
60976 +#define GR_VERSION "grsecurity 2.2.2"
60977 +#define GRSECURITY_VERSION 0x2202
60978 +
60979 +enum {
60980 + GR_SHUTDOWN = 0,
60981 + GR_ENABLE = 1,
60982 + GR_SPROLE = 2,
60983 + GR_RELOAD = 3,
60984 + GR_SEGVMOD = 4,
60985 + GR_STATUS = 5,
60986 + GR_UNSPROLE = 6,
60987 + GR_PASSSET = 7,
60988 + GR_SPROLEPAM = 8,
60989 +};
60990 +
60991 +/* Password setup definitions
60992 + * kernel/grhash.c */
60993 +enum {
60994 + GR_PW_LEN = 128,
60995 + GR_SALT_LEN = 16,
60996 + GR_SHA_LEN = 32,
60997 +};
60998 +
60999 +enum {
61000 + GR_SPROLE_LEN = 64,
61001 +};
61002 +
61003 +enum {
61004 + GR_NO_GLOB = 0,
61005 + GR_REG_GLOB,
61006 + GR_CREATE_GLOB
61007 +};
61008 +
61009 +#define GR_NLIMITS 32
61010 +
61011 +/* Begin Data Structures */
61012 +
61013 +struct sprole_pw {
61014 + unsigned char *rolename;
61015 + unsigned char salt[GR_SALT_LEN];
61016 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61017 +};
61018 +
61019 +struct name_entry {
61020 + __u32 key;
61021 + ino_t inode;
61022 + dev_t device;
61023 + char *name;
61024 + __u16 len;
61025 + __u8 deleted;
61026 + struct name_entry *prev;
61027 + struct name_entry *next;
61028 +};
61029 +
61030 +struct inodev_entry {
61031 + struct name_entry *nentry;
61032 + struct inodev_entry *prev;
61033 + struct inodev_entry *next;
61034 +};
61035 +
61036 +struct acl_role_db {
61037 + struct acl_role_label **r_hash;
61038 + __u32 r_size;
61039 +};
61040 +
61041 +struct inodev_db {
61042 + struct inodev_entry **i_hash;
61043 + __u32 i_size;
61044 +};
61045 +
61046 +struct name_db {
61047 + struct name_entry **n_hash;
61048 + __u32 n_size;
61049 +};
61050 +
61051 +struct crash_uid {
61052 + uid_t uid;
61053 + unsigned long expires;
61054 +};
61055 +
61056 +struct gr_hash_struct {
61057 + void **table;
61058 + void **nametable;
61059 + void *first;
61060 + __u32 table_size;
61061 + __u32 used_size;
61062 + int type;
61063 +};
61064 +
61065 +/* Userspace Grsecurity ACL data structures */
61066 +
61067 +struct acl_subject_label {
61068 + char *filename;
61069 + ino_t inode;
61070 + dev_t device;
61071 + __u32 mode;
61072 + kernel_cap_t cap_mask;
61073 + kernel_cap_t cap_lower;
61074 + kernel_cap_t cap_invert_audit;
61075 +
61076 + struct rlimit res[GR_NLIMITS];
61077 + __u32 resmask;
61078 +
61079 + __u8 user_trans_type;
61080 + __u8 group_trans_type;
61081 + uid_t *user_transitions;
61082 + gid_t *group_transitions;
61083 + __u16 user_trans_num;
61084 + __u16 group_trans_num;
61085 +
61086 + __u32 sock_families[2];
61087 + __u32 ip_proto[8];
61088 + __u32 ip_type;
61089 + struct acl_ip_label **ips;
61090 + __u32 ip_num;
61091 + __u32 inaddr_any_override;
61092 +
61093 + __u32 crashes;
61094 + unsigned long expires;
61095 +
61096 + struct acl_subject_label *parent_subject;
61097 + struct gr_hash_struct *hash;
61098 + struct acl_subject_label *prev;
61099 + struct acl_subject_label *next;
61100 +
61101 + struct acl_object_label **obj_hash;
61102 + __u32 obj_hash_size;
61103 + __u16 pax_flags;
61104 +};
61105 +
61106 +struct role_allowed_ip {
61107 + __u32 addr;
61108 + __u32 netmask;
61109 +
61110 + struct role_allowed_ip *prev;
61111 + struct role_allowed_ip *next;
61112 +};
61113 +
61114 +struct role_transition {
61115 + char *rolename;
61116 +
61117 + struct role_transition *prev;
61118 + struct role_transition *next;
61119 +};
61120 +
61121 +struct acl_role_label {
61122 + char *rolename;
61123 + uid_t uidgid;
61124 + __u16 roletype;
61125 +
61126 + __u16 auth_attempts;
61127 + unsigned long expires;
61128 +
61129 + struct acl_subject_label *root_label;
61130 + struct gr_hash_struct *hash;
61131 +
61132 + struct acl_role_label *prev;
61133 + struct acl_role_label *next;
61134 +
61135 + struct role_transition *transitions;
61136 + struct role_allowed_ip *allowed_ips;
61137 + uid_t *domain_children;
61138 + __u16 domain_child_num;
61139 +
61140 + struct acl_subject_label **subj_hash;
61141 + __u32 subj_hash_size;
61142 +};
61143 +
61144 +struct user_acl_role_db {
61145 + struct acl_role_label **r_table;
61146 + __u32 num_pointers; /* Number of allocations to track */
61147 + __u32 num_roles; /* Number of roles */
61148 + __u32 num_domain_children; /* Number of domain children */
61149 + __u32 num_subjects; /* Number of subjects */
61150 + __u32 num_objects; /* Number of objects */
61151 +};
61152 +
61153 +struct acl_object_label {
61154 + char *filename;
61155 + ino_t inode;
61156 + dev_t device;
61157 + __u32 mode;
61158 +
61159 + struct acl_subject_label *nested;
61160 + struct acl_object_label *globbed;
61161 +
61162 + /* next two structures not used */
61163 +
61164 + struct acl_object_label *prev;
61165 + struct acl_object_label *next;
61166 +};
61167 +
61168 +struct acl_ip_label {
61169 + char *iface;
61170 + __u32 addr;
61171 + __u32 netmask;
61172 + __u16 low, high;
61173 + __u8 mode;
61174 + __u32 type;
61175 + __u32 proto[8];
61176 +
61177 + /* next two structures not used */
61178 +
61179 + struct acl_ip_label *prev;
61180 + struct acl_ip_label *next;
61181 +};
61182 +
61183 +struct gr_arg {
61184 + struct user_acl_role_db role_db;
61185 + unsigned char pw[GR_PW_LEN];
61186 + unsigned char salt[GR_SALT_LEN];
61187 + unsigned char sum[GR_SHA_LEN];
61188 + unsigned char sp_role[GR_SPROLE_LEN];
61189 + struct sprole_pw *sprole_pws;
61190 + dev_t segv_device;
61191 + ino_t segv_inode;
61192 + uid_t segv_uid;
61193 + __u16 num_sprole_pws;
61194 + __u16 mode;
61195 +};
61196 +
61197 +struct gr_arg_wrapper {
61198 + struct gr_arg *arg;
61199 + __u32 version;
61200 + __u32 size;
61201 +};
61202 +
61203 +struct subject_map {
61204 + struct acl_subject_label *user;
61205 + struct acl_subject_label *kernel;
61206 + struct subject_map *prev;
61207 + struct subject_map *next;
61208 +};
61209 +
61210 +struct acl_subj_map_db {
61211 + struct subject_map **s_hash;
61212 + __u32 s_size;
61213 +};
61214 +
61215 +/* End Data Structures Section */
61216 +
61217 +/* Hash functions generated by empirical testing by Brad Spengler
61218 + Makes good use of the low bits of the inode. Generally 0-1 times
61219 + in loop for successful match. 0-3 for unsuccessful match.
61220 + Shift/add algorithm with modulus of table size and an XOR*/
61221 +
61222 +static __inline__ unsigned int
61223 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61224 +{
61225 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61226 +}
61227 +
61228 + static __inline__ unsigned int
61229 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61230 +{
61231 + return ((const unsigned long)userp % sz);
61232 +}
61233 +
61234 +static __inline__ unsigned int
61235 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61236 +{
61237 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61238 +}
61239 +
61240 +static __inline__ unsigned int
61241 +nhash(const char *name, const __u16 len, const unsigned int sz)
61242 +{
61243 + return full_name_hash((const unsigned char *)name, len) % sz;
61244 +}
61245 +
61246 +#define FOR_EACH_ROLE_START(role) \
61247 + role = role_list; \
61248 + while (role) {
61249 +
61250 +#define FOR_EACH_ROLE_END(role) \
61251 + role = role->prev; \
61252 + }
61253 +
61254 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61255 + subj = NULL; \
61256 + iter = 0; \
61257 + while (iter < role->subj_hash_size) { \
61258 + if (subj == NULL) \
61259 + subj = role->subj_hash[iter]; \
61260 + if (subj == NULL) { \
61261 + iter++; \
61262 + continue; \
61263 + }
61264 +
61265 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61266 + subj = subj->next; \
61267 + if (subj == NULL) \
61268 + iter++; \
61269 + }
61270 +
61271 +
61272 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61273 + subj = role->hash->first; \
61274 + while (subj != NULL) {
61275 +
61276 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61277 + subj = subj->next; \
61278 + }
61279 +
61280 +#endif
61281 +
61282 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61283 new file mode 100644
61284 index 0000000..323ecf2
61285 --- /dev/null
61286 +++ b/include/linux/gralloc.h
61287 @@ -0,0 +1,9 @@
61288 +#ifndef __GRALLOC_H
61289 +#define __GRALLOC_H
61290 +
61291 +void acl_free_all(void);
61292 +int acl_alloc_stack_init(unsigned long size);
61293 +void *acl_alloc(unsigned long len);
61294 +void *acl_alloc_num(unsigned long num, unsigned long len);
61295 +
61296 +#endif
61297 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61298 new file mode 100644
61299 index 0000000..b30e9bc
61300 --- /dev/null
61301 +++ b/include/linux/grdefs.h
61302 @@ -0,0 +1,140 @@
61303 +#ifndef GRDEFS_H
61304 +#define GRDEFS_H
61305 +
61306 +/* Begin grsecurity status declarations */
61307 +
61308 +enum {
61309 + GR_READY = 0x01,
61310 + GR_STATUS_INIT = 0x00 // disabled state
61311 +};
61312 +
61313 +/* Begin ACL declarations */
61314 +
61315 +/* Role flags */
61316 +
61317 +enum {
61318 + GR_ROLE_USER = 0x0001,
61319 + GR_ROLE_GROUP = 0x0002,
61320 + GR_ROLE_DEFAULT = 0x0004,
61321 + GR_ROLE_SPECIAL = 0x0008,
61322 + GR_ROLE_AUTH = 0x0010,
61323 + GR_ROLE_NOPW = 0x0020,
61324 + GR_ROLE_GOD = 0x0040,
61325 + GR_ROLE_LEARN = 0x0080,
61326 + GR_ROLE_TPE = 0x0100,
61327 + GR_ROLE_DOMAIN = 0x0200,
61328 + GR_ROLE_PAM = 0x0400,
61329 + GR_ROLE_PERSIST = 0x0800
61330 +};
61331 +
61332 +/* ACL Subject and Object mode flags */
61333 +enum {
61334 + GR_DELETED = 0x80000000
61335 +};
61336 +
61337 +/* ACL Object-only mode flags */
61338 +enum {
61339 + GR_READ = 0x00000001,
61340 + GR_APPEND = 0x00000002,
61341 + GR_WRITE = 0x00000004,
61342 + GR_EXEC = 0x00000008,
61343 + GR_FIND = 0x00000010,
61344 + GR_INHERIT = 0x00000020,
61345 + GR_SETID = 0x00000040,
61346 + GR_CREATE = 0x00000080,
61347 + GR_DELETE = 0x00000100,
61348 + GR_LINK = 0x00000200,
61349 + GR_AUDIT_READ = 0x00000400,
61350 + GR_AUDIT_APPEND = 0x00000800,
61351 + GR_AUDIT_WRITE = 0x00001000,
61352 + GR_AUDIT_EXEC = 0x00002000,
61353 + GR_AUDIT_FIND = 0x00004000,
61354 + GR_AUDIT_INHERIT= 0x00008000,
61355 + GR_AUDIT_SETID = 0x00010000,
61356 + GR_AUDIT_CREATE = 0x00020000,
61357 + GR_AUDIT_DELETE = 0x00040000,
61358 + GR_AUDIT_LINK = 0x00080000,
61359 + GR_PTRACERD = 0x00100000,
61360 + GR_NOPTRACE = 0x00200000,
61361 + GR_SUPPRESS = 0x00400000,
61362 + GR_NOLEARN = 0x00800000,
61363 + GR_INIT_TRANSFER= 0x01000000
61364 +};
61365 +
61366 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61367 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61368 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61369 +
61370 +/* ACL subject-only mode flags */
61371 +enum {
61372 + GR_KILL = 0x00000001,
61373 + GR_VIEW = 0x00000002,
61374 + GR_PROTECTED = 0x00000004,
61375 + GR_LEARN = 0x00000008,
61376 + GR_OVERRIDE = 0x00000010,
61377 + /* just a placeholder, this mode is only used in userspace */
61378 + GR_DUMMY = 0x00000020,
61379 + GR_PROTSHM = 0x00000040,
61380 + GR_KILLPROC = 0x00000080,
61381 + GR_KILLIPPROC = 0x00000100,
61382 + /* just a placeholder, this mode is only used in userspace */
61383 + GR_NOTROJAN = 0x00000200,
61384 + GR_PROTPROCFD = 0x00000400,
61385 + GR_PROCACCT = 0x00000800,
61386 + GR_RELAXPTRACE = 0x00001000,
61387 + GR_NESTED = 0x00002000,
61388 + GR_INHERITLEARN = 0x00004000,
61389 + GR_PROCFIND = 0x00008000,
61390 + GR_POVERRIDE = 0x00010000,
61391 + GR_KERNELAUTH = 0x00020000,
61392 + GR_ATSECURE = 0x00040000,
61393 + GR_SHMEXEC = 0x00080000
61394 +};
61395 +
61396 +enum {
61397 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61398 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61399 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61400 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61401 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61402 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61403 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61404 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61405 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61406 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61407 +};
61408 +
61409 +enum {
61410 + GR_ID_USER = 0x01,
61411 + GR_ID_GROUP = 0x02,
61412 +};
61413 +
61414 +enum {
61415 + GR_ID_ALLOW = 0x01,
61416 + GR_ID_DENY = 0x02,
61417 +};
61418 +
61419 +#define GR_CRASH_RES 31
61420 +#define GR_UIDTABLE_MAX 500
61421 +
61422 +/* begin resource learning section */
61423 +enum {
61424 + GR_RLIM_CPU_BUMP = 60,
61425 + GR_RLIM_FSIZE_BUMP = 50000,
61426 + GR_RLIM_DATA_BUMP = 10000,
61427 + GR_RLIM_STACK_BUMP = 1000,
61428 + GR_RLIM_CORE_BUMP = 10000,
61429 + GR_RLIM_RSS_BUMP = 500000,
61430 + GR_RLIM_NPROC_BUMP = 1,
61431 + GR_RLIM_NOFILE_BUMP = 5,
61432 + GR_RLIM_MEMLOCK_BUMP = 50000,
61433 + GR_RLIM_AS_BUMP = 500000,
61434 + GR_RLIM_LOCKS_BUMP = 2,
61435 + GR_RLIM_SIGPENDING_BUMP = 5,
61436 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61437 + GR_RLIM_NICE_BUMP = 1,
61438 + GR_RLIM_RTPRIO_BUMP = 1,
61439 + GR_RLIM_RTTIME_BUMP = 1000000
61440 +};
61441 +
61442 +#endif
61443 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61444 new file mode 100644
61445 index 0000000..60cda84
61446 --- /dev/null
61447 +++ b/include/linux/grinternal.h
61448 @@ -0,0 +1,220 @@
61449 +#ifndef __GRINTERNAL_H
61450 +#define __GRINTERNAL_H
61451 +
61452 +#ifdef CONFIG_GRKERNSEC
61453 +
61454 +#include <linux/fs.h>
61455 +#include <linux/mnt_namespace.h>
61456 +#include <linux/nsproxy.h>
61457 +#include <linux/gracl.h>
61458 +#include <linux/grdefs.h>
61459 +#include <linux/grmsg.h>
61460 +
61461 +void gr_add_learn_entry(const char *fmt, ...)
61462 + __attribute__ ((format (printf, 1, 2)));
61463 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61464 + const struct vfsmount *mnt);
61465 +__u32 gr_check_create(const struct dentry *new_dentry,
61466 + const struct dentry *parent,
61467 + const struct vfsmount *mnt, const __u32 mode);
61468 +int gr_check_protected_task(const struct task_struct *task);
61469 +__u32 to_gr_audit(const __u32 reqmode);
61470 +int gr_set_acls(const int type);
61471 +int gr_apply_subject_to_task(struct task_struct *task);
61472 +int gr_acl_is_enabled(void);
61473 +char gr_roletype_to_char(void);
61474 +
61475 +void gr_handle_alertkill(struct task_struct *task);
61476 +char *gr_to_filename(const struct dentry *dentry,
61477 + const struct vfsmount *mnt);
61478 +char *gr_to_filename1(const struct dentry *dentry,
61479 + const struct vfsmount *mnt);
61480 +char *gr_to_filename2(const struct dentry *dentry,
61481 + const struct vfsmount *mnt);
61482 +char *gr_to_filename3(const struct dentry *dentry,
61483 + const struct vfsmount *mnt);
61484 +
61485 +extern int grsec_enable_harden_ptrace;
61486 +extern int grsec_enable_link;
61487 +extern int grsec_enable_fifo;
61488 +extern int grsec_enable_execve;
61489 +extern int grsec_enable_shm;
61490 +extern int grsec_enable_execlog;
61491 +extern int grsec_enable_signal;
61492 +extern int grsec_enable_audit_ptrace;
61493 +extern int grsec_enable_forkfail;
61494 +extern int grsec_enable_time;
61495 +extern int grsec_enable_rofs;
61496 +extern int grsec_enable_chroot_shmat;
61497 +extern int grsec_enable_chroot_mount;
61498 +extern int grsec_enable_chroot_double;
61499 +extern int grsec_enable_chroot_pivot;
61500 +extern int grsec_enable_chroot_chdir;
61501 +extern int grsec_enable_chroot_chmod;
61502 +extern int grsec_enable_chroot_mknod;
61503 +extern int grsec_enable_chroot_fchdir;
61504 +extern int grsec_enable_chroot_nice;
61505 +extern int grsec_enable_chroot_execlog;
61506 +extern int grsec_enable_chroot_caps;
61507 +extern int grsec_enable_chroot_sysctl;
61508 +extern int grsec_enable_chroot_unix;
61509 +extern int grsec_enable_tpe;
61510 +extern int grsec_tpe_gid;
61511 +extern int grsec_enable_tpe_all;
61512 +extern int grsec_enable_tpe_invert;
61513 +extern int grsec_enable_socket_all;
61514 +extern int grsec_socket_all_gid;
61515 +extern int grsec_enable_socket_client;
61516 +extern int grsec_socket_client_gid;
61517 +extern int grsec_enable_socket_server;
61518 +extern int grsec_socket_server_gid;
61519 +extern int grsec_audit_gid;
61520 +extern int grsec_enable_group;
61521 +extern int grsec_enable_audit_textrel;
61522 +extern int grsec_enable_log_rwxmaps;
61523 +extern int grsec_enable_mount;
61524 +extern int grsec_enable_chdir;
61525 +extern int grsec_resource_logging;
61526 +extern int grsec_enable_blackhole;
61527 +extern int grsec_lastack_retries;
61528 +extern int grsec_enable_brute;
61529 +extern int grsec_lock;
61530 +
61531 +extern spinlock_t grsec_alert_lock;
61532 +extern unsigned long grsec_alert_wtime;
61533 +extern unsigned long grsec_alert_fyet;
61534 +
61535 +extern spinlock_t grsec_audit_lock;
61536 +
61537 +extern rwlock_t grsec_exec_file_lock;
61538 +
61539 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61540 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61541 + (tsk)->exec_file->f_vfsmnt) : "/")
61542 +
61543 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61544 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61545 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61546 +
61547 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61548 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61549 + (tsk)->exec_file->f_vfsmnt) : "/")
61550 +
61551 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61552 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61553 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61554 +
61555 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61556 +
61557 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61558 +
61559 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61560 + (task)->pid, (cred)->uid, \
61561 + (cred)->euid, (cred)->gid, (cred)->egid, \
61562 + gr_parent_task_fullpath(task), \
61563 + (task)->real_parent->comm, (task)->real_parent->pid, \
61564 + (pcred)->uid, (pcred)->euid, \
61565 + (pcred)->gid, (pcred)->egid
61566 +
61567 +#define GR_CHROOT_CAPS {{ \
61568 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61569 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61570 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61571 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61572 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61573 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61574 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61575 +
61576 +#define security_learn(normal_msg,args...) \
61577 +({ \
61578 + read_lock(&grsec_exec_file_lock); \
61579 + gr_add_learn_entry(normal_msg "\n", ## args); \
61580 + read_unlock(&grsec_exec_file_lock); \
61581 +})
61582 +
61583 +enum {
61584 + GR_DO_AUDIT,
61585 + GR_DONT_AUDIT,
61586 + /* used for non-audit messages that we shouldn't kill the task on */
61587 + GR_DONT_AUDIT_GOOD
61588 +};
61589 +
61590 +enum {
61591 + GR_TTYSNIFF,
61592 + GR_RBAC,
61593 + GR_RBAC_STR,
61594 + GR_STR_RBAC,
61595 + GR_RBAC_MODE2,
61596 + GR_RBAC_MODE3,
61597 + GR_FILENAME,
61598 + GR_SYSCTL_HIDDEN,
61599 + GR_NOARGS,
61600 + GR_ONE_INT,
61601 + GR_ONE_INT_TWO_STR,
61602 + GR_ONE_STR,
61603 + GR_STR_INT,
61604 + GR_TWO_STR_INT,
61605 + GR_TWO_INT,
61606 + GR_TWO_U64,
61607 + GR_THREE_INT,
61608 + GR_FIVE_INT_TWO_STR,
61609 + GR_TWO_STR,
61610 + GR_THREE_STR,
61611 + GR_FOUR_STR,
61612 + GR_STR_FILENAME,
61613 + GR_FILENAME_STR,
61614 + GR_FILENAME_TWO_INT,
61615 + GR_FILENAME_TWO_INT_STR,
61616 + GR_TEXTREL,
61617 + GR_PTRACE,
61618 + GR_RESOURCE,
61619 + GR_CAP,
61620 + GR_SIG,
61621 + GR_SIG2,
61622 + GR_CRASH1,
61623 + GR_CRASH2,
61624 + GR_PSACCT,
61625 + GR_RWXMAP
61626 +};
61627 +
61628 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61629 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61630 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61631 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61632 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61633 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61634 +#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)
61635 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61636 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61637 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61638 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61639 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61640 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61641 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61642 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61643 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61644 +#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)
61645 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61646 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61647 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61648 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61649 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61650 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61651 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61652 +#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)
61653 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61654 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61655 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61656 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61657 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61658 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61659 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61660 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61661 +#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)
61662 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61663 +
61664 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61665 +
61666 +#endif
61667 +
61668 +#endif
61669 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61670 new file mode 100644
61671 index 0000000..9d5fd4a
61672 --- /dev/null
61673 +++ b/include/linux/grmsg.h
61674 @@ -0,0 +1,108 @@
61675 +#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"
61676 +#define GR_ACL_PROCACCT_MSG "%.256s[%.16s:%d] IP:%pI4 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:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u"
61677 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61678 +#define GR_STOPMOD_MSG "denied modification of module state by "
61679 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61680 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61681 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61682 +#define GR_IOPL_MSG "denied use of iopl() by "
61683 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61684 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61685 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61686 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61687 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61688 +#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%pI4"
61689 +#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%pI4"
61690 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61691 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61692 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61693 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61694 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61695 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61696 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61697 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61698 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61699 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61700 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61701 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61702 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61703 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61704 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61705 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61706 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61707 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61708 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61709 +#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
61710 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61711 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61712 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61713 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61714 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61715 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61716 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61717 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61718 +#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
61719 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61720 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61721 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61722 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61723 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61724 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61725 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61726 +#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"
61727 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
61728 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61729 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61730 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61731 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61732 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61733 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61734 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61735 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61736 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61737 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61738 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61739 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61740 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61741 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61742 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61743 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61744 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61745 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61746 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61747 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61748 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61749 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61750 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61751 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61752 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61753 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61754 +#define GR_TIME_MSG "time set by "
61755 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61756 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61757 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61758 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61759 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61760 +#define GR_BIND_MSG "denied bind() by "
61761 +#define GR_CONNECT_MSG "denied connect() by "
61762 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61763 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61764 +#define GR_IP_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%pI4\t%u\t%u\t%u\t%u\t%pI4"
61765 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61766 +#define GR_CAP_ACL_MSG "use of %s denied for "
61767 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61768 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61769 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61770 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61771 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61772 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61773 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61774 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61775 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61776 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61777 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61778 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61779 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61780 +#define GR_VM86_MSG "denied use of vm86 by "
61781 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61782 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61783 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61784 new file mode 100644
61785 index 0000000..4620f36
61786 --- /dev/null
61787 +++ b/include/linux/grsecurity.h
61788 @@ -0,0 +1,231 @@
61789 +#ifndef GR_SECURITY_H
61790 +#define GR_SECURITY_H
61791 +#include <linux/fs.h>
61792 +#include <linux/fs_struct.h>
61793 +#include <linux/binfmts.h>
61794 +#include <linux/gracl.h>
61795 +
61796 +/* notify of brain-dead configs */
61797 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61798 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61799 +#endif
61800 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61801 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61802 +#endif
61803 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
61804 +#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
61805 +#endif
61806 +#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
61807 +#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
61808 +#endif
61809 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61810 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61811 +#endif
61812 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61813 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
61814 +#endif
61815 +
61816 +#include <linux/compat.h>
61817 +
61818 +struct user_arg_ptr {
61819 +#ifdef CONFIG_COMPAT
61820 + bool is_compat;
61821 +#endif
61822 + union {
61823 + const char __user *const __user *native;
61824 +#ifdef CONFIG_COMPAT
61825 + compat_uptr_t __user *compat;
61826 +#endif
61827 + } ptr;
61828 +};
61829 +
61830 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61831 +void gr_handle_brute_check(void);
61832 +void gr_handle_kernel_exploit(void);
61833 +int gr_process_user_ban(void);
61834 +
61835 +char gr_roletype_to_char(void);
61836 +
61837 +int gr_acl_enable_at_secure(void);
61838 +
61839 +int gr_check_user_change(int real, int effective, int fs);
61840 +int gr_check_group_change(int real, int effective, int fs);
61841 +
61842 +void gr_del_task_from_ip_table(struct task_struct *p);
61843 +
61844 +int gr_pid_is_chrooted(struct task_struct *p);
61845 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61846 +int gr_handle_chroot_nice(void);
61847 +int gr_handle_chroot_sysctl(const int op);
61848 +int gr_handle_chroot_setpriority(struct task_struct *p,
61849 + const int niceval);
61850 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61851 +int gr_handle_chroot_chroot(const struct dentry *dentry,
61852 + const struct vfsmount *mnt);
61853 +void gr_handle_chroot_chdir(struct path *path);
61854 +int gr_handle_chroot_chmod(const struct dentry *dentry,
61855 + const struct vfsmount *mnt, const int mode);
61856 +int gr_handle_chroot_mknod(const struct dentry *dentry,
61857 + const struct vfsmount *mnt, const int mode);
61858 +int gr_handle_chroot_mount(const struct dentry *dentry,
61859 + const struct vfsmount *mnt,
61860 + const char *dev_name);
61861 +int gr_handle_chroot_pivot(void);
61862 +int gr_handle_chroot_unix(const pid_t pid);
61863 +
61864 +int gr_handle_rawio(const struct inode *inode);
61865 +
61866 +void gr_handle_ioperm(void);
61867 +void gr_handle_iopl(void);
61868 +
61869 +int gr_tpe_allow(const struct file *file);
61870 +
61871 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61872 +void gr_clear_chroot_entries(struct task_struct *task);
61873 +
61874 +void gr_log_forkfail(const int retval);
61875 +void gr_log_timechange(void);
61876 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61877 +void gr_log_chdir(const struct dentry *dentry,
61878 + const struct vfsmount *mnt);
61879 +void gr_log_chroot_exec(const struct dentry *dentry,
61880 + const struct vfsmount *mnt);
61881 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61882 +void gr_log_remount(const char *devname, const int retval);
61883 +void gr_log_unmount(const char *devname, const int retval);
61884 +void gr_log_mount(const char *from, const char *to, const int retval);
61885 +void gr_log_textrel(struct vm_area_struct *vma);
61886 +void gr_log_rwxmmap(struct file *file);
61887 +void gr_log_rwxmprotect(struct file *file);
61888 +
61889 +int gr_handle_follow_link(const struct inode *parent,
61890 + const struct inode *inode,
61891 + const struct dentry *dentry,
61892 + const struct vfsmount *mnt);
61893 +int gr_handle_fifo(const struct dentry *dentry,
61894 + const struct vfsmount *mnt,
61895 + const struct dentry *dir, const int flag,
61896 + const int acc_mode);
61897 +int gr_handle_hardlink(const struct dentry *dentry,
61898 + const struct vfsmount *mnt,
61899 + struct inode *inode,
61900 + const int mode, const char *to);
61901 +
61902 +int gr_is_capable(const int cap);
61903 +int gr_is_capable_nolog(const int cap);
61904 +void gr_learn_resource(const struct task_struct *task, const int limit,
61905 + const unsigned long wanted, const int gt);
61906 +void gr_copy_label(struct task_struct *tsk);
61907 +void gr_handle_crash(struct task_struct *task, const int sig);
61908 +int gr_handle_signal(const struct task_struct *p, const int sig);
61909 +int gr_check_crash_uid(const uid_t uid);
61910 +int gr_check_protected_task(const struct task_struct *task);
61911 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61912 +int gr_acl_handle_mmap(const struct file *file,
61913 + const unsigned long prot);
61914 +int gr_acl_handle_mprotect(const struct file *file,
61915 + const unsigned long prot);
61916 +int gr_check_hidden_task(const struct task_struct *tsk);
61917 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61918 + const struct vfsmount *mnt);
61919 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
61920 + const struct vfsmount *mnt);
61921 +__u32 gr_acl_handle_access(const struct dentry *dentry,
61922 + const struct vfsmount *mnt, const int fmode);
61923 +__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
61924 + const struct vfsmount *mnt, mode_t mode);
61925 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61926 + const struct vfsmount *mnt, mode_t mode);
61927 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
61928 + const struct vfsmount *mnt);
61929 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61930 + const struct vfsmount *mnt);
61931 +int gr_handle_ptrace(struct task_struct *task, const long request);
61932 +int gr_handle_proc_ptrace(struct task_struct *task);
61933 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
61934 + const struct vfsmount *mnt);
61935 +int gr_check_crash_exec(const struct file *filp);
61936 +int gr_acl_is_enabled(void);
61937 +void gr_set_kernel_label(struct task_struct *task);
61938 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
61939 + const gid_t gid);
61940 +int gr_set_proc_label(const struct dentry *dentry,
61941 + const struct vfsmount *mnt,
61942 + const int unsafe_share);
61943 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61944 + const struct vfsmount *mnt);
61945 +__u32 gr_acl_handle_open(const struct dentry *dentry,
61946 + const struct vfsmount *mnt, int acc_mode);
61947 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
61948 + const struct dentry *p_dentry,
61949 + const struct vfsmount *p_mnt,
61950 + int open_flags, int acc_mode, const int imode);
61951 +void gr_handle_create(const struct dentry *dentry,
61952 + const struct vfsmount *mnt);
61953 +void gr_handle_proc_create(const struct dentry *dentry,
61954 + const struct inode *inode);
61955 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61956 + const struct dentry *parent_dentry,
61957 + const struct vfsmount *parent_mnt,
61958 + const int mode);
61959 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61960 + const struct dentry *parent_dentry,
61961 + const struct vfsmount *parent_mnt);
61962 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61963 + const struct vfsmount *mnt);
61964 +void gr_handle_delete(const ino_t ino, const dev_t dev);
61965 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61966 + const struct vfsmount *mnt);
61967 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61968 + const struct dentry *parent_dentry,
61969 + const struct vfsmount *parent_mnt,
61970 + const char *from);
61971 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61972 + const struct dentry *parent_dentry,
61973 + const struct vfsmount *parent_mnt,
61974 + const struct dentry *old_dentry,
61975 + const struct vfsmount *old_mnt, const char *to);
61976 +int gr_acl_handle_rename(struct dentry *new_dentry,
61977 + struct dentry *parent_dentry,
61978 + const struct vfsmount *parent_mnt,
61979 + struct dentry *old_dentry,
61980 + struct inode *old_parent_inode,
61981 + struct vfsmount *old_mnt, const char *newname);
61982 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61983 + struct dentry *old_dentry,
61984 + struct dentry *new_dentry,
61985 + struct vfsmount *mnt, const __u8 replace);
61986 +__u32 gr_check_link(const struct dentry *new_dentry,
61987 + const struct dentry *parent_dentry,
61988 + const struct vfsmount *parent_mnt,
61989 + const struct dentry *old_dentry,
61990 + const struct vfsmount *old_mnt);
61991 +int gr_acl_handle_filldir(const struct file *file, const char *name,
61992 + const unsigned int namelen, const ino_t ino);
61993 +
61994 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
61995 + const struct vfsmount *mnt);
61996 +void gr_acl_handle_exit(void);
61997 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
61998 +int gr_acl_handle_procpidmem(const struct task_struct *task);
61999 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62000 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62001 +void gr_audit_ptrace(struct task_struct *task);
62002 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62003 +
62004 +#ifdef CONFIG_GRKERNSEC
62005 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62006 +void gr_handle_vm86(void);
62007 +void gr_handle_mem_readwrite(u64 from, u64 to);
62008 +
62009 +extern int grsec_enable_dmesg;
62010 +extern int grsec_disable_privio;
62011 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62012 +extern int grsec_enable_chroot_findtask;
62013 +#endif
62014 +#ifdef CONFIG_GRKERNSEC_SETXID
62015 +extern int grsec_enable_setxid;
62016 +#endif
62017 +#endif
62018 +
62019 +#endif
62020 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62021 new file mode 100644
62022 index 0000000..e7ffaaf
62023 --- /dev/null
62024 +++ b/include/linux/grsock.h
62025 @@ -0,0 +1,19 @@
62026 +#ifndef __GRSOCK_H
62027 +#define __GRSOCK_H
62028 +
62029 +extern void gr_attach_curr_ip(const struct sock *sk);
62030 +extern int gr_handle_sock_all(const int family, const int type,
62031 + const int protocol);
62032 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62033 +extern int gr_handle_sock_server_other(const struct sock *sck);
62034 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62035 +extern int gr_search_connect(struct socket * sock,
62036 + struct sockaddr_in * addr);
62037 +extern int gr_search_bind(struct socket * sock,
62038 + struct sockaddr_in * addr);
62039 +extern int gr_search_listen(struct socket * sock);
62040 +extern int gr_search_accept(struct socket * sock);
62041 +extern int gr_search_socket(const int domain, const int type,
62042 + const int protocol);
62043 +
62044 +#endif
62045 diff --git a/include/linux/hid.h b/include/linux/hid.h
62046 index 9cf8e7a..5ec94d0 100644
62047 --- a/include/linux/hid.h
62048 +++ b/include/linux/hid.h
62049 @@ -676,7 +676,7 @@ struct hid_ll_driver {
62050 unsigned int code, int value);
62051
62052 int (*parse)(struct hid_device *hdev);
62053 -};
62054 +} __no_const;
62055
62056 #define PM_HINT_FULLON 1<<5
62057 #define PM_HINT_NORMAL 1<<1
62058 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62059 index 3a93f73..b19d0b3 100644
62060 --- a/include/linux/highmem.h
62061 +++ b/include/linux/highmem.h
62062 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
62063 kunmap_atomic(kaddr, KM_USER0);
62064 }
62065
62066 +static inline void sanitize_highpage(struct page *page)
62067 +{
62068 + void *kaddr;
62069 + unsigned long flags;
62070 +
62071 + local_irq_save(flags);
62072 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
62073 + clear_page(kaddr);
62074 + kunmap_atomic(kaddr, KM_CLEARPAGE);
62075 + local_irq_restore(flags);
62076 +}
62077 +
62078 static inline void zero_user_segments(struct page *page,
62079 unsigned start1, unsigned end1,
62080 unsigned start2, unsigned end2)
62081 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62082 index a6c652e..1f5878f 100644
62083 --- a/include/linux/i2c.h
62084 +++ b/include/linux/i2c.h
62085 @@ -346,6 +346,7 @@ struct i2c_algorithm {
62086 /* To determine what the adapter supports */
62087 u32 (*functionality) (struct i2c_adapter *);
62088 };
62089 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62090
62091 /*
62092 * i2c_adapter is the structure used to identify a physical i2c bus along
62093 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62094 index a6deef4..c56a7f2 100644
62095 --- a/include/linux/i2o.h
62096 +++ b/include/linux/i2o.h
62097 @@ -564,7 +564,7 @@ struct i2o_controller {
62098 struct i2o_device *exec; /* Executive */
62099 #if BITS_PER_LONG == 64
62100 spinlock_t context_list_lock; /* lock for context_list */
62101 - atomic_t context_list_counter; /* needed for unique contexts */
62102 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62103 struct list_head context_list; /* list of context id's
62104 and pointers */
62105 #endif
62106 diff --git a/include/linux/init.h b/include/linux/init.h
62107 index 9146f39..885354d 100644
62108 --- a/include/linux/init.h
62109 +++ b/include/linux/init.h
62110 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cmdline);
62111
62112 /* Each module must use one module_init(). */
62113 #define module_init(initfn) \
62114 - static inline initcall_t __inittest(void) \
62115 + static inline __used initcall_t __inittest(void) \
62116 { return initfn; } \
62117 int init_module(void) __attribute__((alias(#initfn)));
62118
62119 /* This is only required if you want to be unloadable. */
62120 #define module_exit(exitfn) \
62121 - static inline exitcall_t __exittest(void) \
62122 + static inline __used exitcall_t __exittest(void) \
62123 { return exitfn; } \
62124 void cleanup_module(void) __attribute__((alias(#exitfn)));
62125
62126 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62127 index d14e058..4162929 100644
62128 --- a/include/linux/init_task.h
62129 +++ b/include/linux/init_task.h
62130 @@ -126,6 +126,12 @@ extern struct cred init_cred;
62131 # define INIT_PERF_EVENTS(tsk)
62132 #endif
62133
62134 +#ifdef CONFIG_X86
62135 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62136 +#else
62137 +#define INIT_TASK_THREAD_INFO
62138 +#endif
62139 +
62140 /*
62141 * INIT_TASK is used to set up the first task table, touch at
62142 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62143 @@ -164,6 +170,7 @@ extern struct cred init_cred;
62144 RCU_INIT_POINTER(.cred, &init_cred), \
62145 .comm = "swapper", \
62146 .thread = INIT_THREAD, \
62147 + INIT_TASK_THREAD_INFO \
62148 .fs = &init_fs, \
62149 .files = &init_files, \
62150 .signal = &init_signals, \
62151 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62152 index 9310c69..6ebb244 100644
62153 --- a/include/linux/intel-iommu.h
62154 +++ b/include/linux/intel-iommu.h
62155 @@ -296,7 +296,7 @@ struct iommu_flush {
62156 u8 fm, u64 type);
62157 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62158 unsigned int size_order, u64 type);
62159 -};
62160 +} __no_const;
62161
62162 enum {
62163 SR_DMAR_FECTL_REG,
62164 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62165 index f51a81b..adfcb44 100644
62166 --- a/include/linux/interrupt.h
62167 +++ b/include/linux/interrupt.h
62168 @@ -425,7 +425,7 @@ enum
62169 /* map softirq index to softirq name. update 'softirq_to_name' in
62170 * kernel/softirq.c when adding a new softirq.
62171 */
62172 -extern char *softirq_to_name[NR_SOFTIRQS];
62173 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62174
62175 /* softirq mask and active fields moved to irq_cpustat_t in
62176 * asm/hardirq.h to get better cache usage. KAO
62177 @@ -433,12 +433,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62178
62179 struct softirq_action
62180 {
62181 - void (*action)(struct softirq_action *);
62182 + void (*action)(void);
62183 };
62184
62185 asmlinkage void do_softirq(void);
62186 asmlinkage void __do_softirq(void);
62187 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62188 +extern void open_softirq(int nr, void (*action)(void));
62189 extern void softirq_init(void);
62190 static inline void __raise_softirq_irqoff(unsigned int nr)
62191 {
62192 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62193 index 0df513b..fe901a2 100644
62194 --- a/include/linux/kallsyms.h
62195 +++ b/include/linux/kallsyms.h
62196 @@ -15,7 +15,8 @@
62197
62198 struct module;
62199
62200 -#ifdef CONFIG_KALLSYMS
62201 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62202 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62203 /* Lookup the address for a symbol. Returns 0 if not found. */
62204 unsigned long kallsyms_lookup_name(const char *name);
62205
62206 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62207 /* Stupid that this does nothing, but I didn't create this mess. */
62208 #define __print_symbol(fmt, addr)
62209 #endif /*CONFIG_KALLSYMS*/
62210 +#else /* when included by kallsyms.c, vsnprintf.c, or
62211 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62212 +extern void __print_symbol(const char *fmt, unsigned long address);
62213 +extern int sprint_backtrace(char *buffer, unsigned long address);
62214 +extern int sprint_symbol(char *buffer, unsigned long address);
62215 +const char *kallsyms_lookup(unsigned long addr,
62216 + unsigned long *symbolsize,
62217 + unsigned long *offset,
62218 + char **modname, char *namebuf);
62219 +#endif
62220
62221 /* This macro allows us to keep printk typechecking */
62222 static void __check_printsym_format(const char *fmt, ...)
62223 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62224 index fa39183..40160be 100644
62225 --- a/include/linux/kgdb.h
62226 +++ b/include/linux/kgdb.h
62227 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62228 extern int kgdb_io_module_registered;
62229
62230 extern atomic_t kgdb_setting_breakpoint;
62231 -extern atomic_t kgdb_cpu_doing_single_step;
62232 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62233
62234 extern struct task_struct *kgdb_usethread;
62235 extern struct task_struct *kgdb_contthread;
62236 @@ -251,7 +251,7 @@ struct kgdb_arch {
62237 void (*disable_hw_break)(struct pt_regs *regs);
62238 void (*remove_all_hw_break)(void);
62239 void (*correct_hw_break)(void);
62240 -};
62241 +} __do_const;
62242
62243 /**
62244 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62245 @@ -276,7 +276,7 @@ struct kgdb_io {
62246 void (*pre_exception) (void);
62247 void (*post_exception) (void);
62248 int is_console;
62249 -};
62250 +} __do_const;
62251
62252 extern struct kgdb_arch arch_kgdb_ops;
62253
62254 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62255 index 0da38cf..d23f05f 100644
62256 --- a/include/linux/kmod.h
62257 +++ b/include/linux/kmod.h
62258 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62259 * usually useless though. */
62260 extern int __request_module(bool wait, const char *name, ...) \
62261 __attribute__((format(printf, 2, 3)));
62262 +extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
62263 + __attribute__((format(printf, 3, 4)));
62264 #define request_module(mod...) __request_module(true, mod)
62265 #define request_module_nowait(mod...) __request_module(false, mod)
62266 #define try_then_request_module(x, mod...) \
62267 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62268 index eabb21a..3f030f4 100644
62269 --- a/include/linux/kvm_host.h
62270 +++ b/include/linux/kvm_host.h
62271 @@ -308,7 +308,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62272 void vcpu_load(struct kvm_vcpu *vcpu);
62273 void vcpu_put(struct kvm_vcpu *vcpu);
62274
62275 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62276 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62277 struct module *module);
62278 void kvm_exit(void);
62279
62280 @@ -454,7 +454,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62281 struct kvm_guest_debug *dbg);
62282 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62283
62284 -int kvm_arch_init(void *opaque);
62285 +int kvm_arch_init(const void *opaque);
62286 void kvm_arch_exit(void);
62287
62288 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62289 diff --git a/include/linux/libata.h b/include/linux/libata.h
62290 index efd6f98..5f5fd37 100644
62291 --- a/include/linux/libata.h
62292 +++ b/include/linux/libata.h
62293 @@ -909,7 +909,7 @@ struct ata_port_operations {
62294 * fields must be pointers.
62295 */
62296 const struct ata_port_operations *inherits;
62297 -};
62298 +} __do_const;
62299
62300 struct ata_port_info {
62301 unsigned long flags;
62302 diff --git a/include/linux/mca.h b/include/linux/mca.h
62303 index 3797270..7765ede 100644
62304 --- a/include/linux/mca.h
62305 +++ b/include/linux/mca.h
62306 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
62307 int region);
62308 void * (*mca_transform_memory)(struct mca_device *,
62309 void *memory);
62310 -};
62311 +} __no_const;
62312
62313 struct mca_bus {
62314 u64 default_dma_mask;
62315 diff --git a/include/linux/memory.h b/include/linux/memory.h
62316 index 935699b..11042cc 100644
62317 --- a/include/linux/memory.h
62318 +++ b/include/linux/memory.h
62319 @@ -144,7 +144,7 @@ struct memory_accessor {
62320 size_t count);
62321 ssize_t (*write)(struct memory_accessor *, const char *buf,
62322 off_t offset, size_t count);
62323 -};
62324 +} __no_const;
62325
62326 /*
62327 * Kernel text modification mutex, used for code patching. Users of this lock
62328 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62329 index 896b5e4..1159ad0 100644
62330 --- a/include/linux/mfd/abx500.h
62331 +++ b/include/linux/mfd/abx500.h
62332 @@ -234,6 +234,7 @@ struct abx500_ops {
62333 int (*event_registers_startup_state_get) (struct device *, u8 *);
62334 int (*startup_irq_enabled) (struct device *, unsigned int);
62335 };
62336 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62337
62338 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62339 void abx500_remove_ops(struct device *dev);
62340 diff --git a/include/linux/mm.h b/include/linux/mm.h
62341 index fedc5f0..7cedb6d 100644
62342 --- a/include/linux/mm.h
62343 +++ b/include/linux/mm.h
62344 @@ -114,7 +114,14 @@ extern unsigned int kobjsize(const void *objp);
62345
62346 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62347 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62348 +
62349 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62350 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62351 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62352 +#else
62353 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62354 +#endif
62355 +
62356 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62357 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62358
62359 @@ -1011,34 +1018,6 @@ int set_page_dirty(struct page *page);
62360 int set_page_dirty_lock(struct page *page);
62361 int clear_page_dirty_for_io(struct page *page);
62362
62363 -/* Is the vma a continuation of the stack vma above it? */
62364 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62365 -{
62366 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62367 -}
62368 -
62369 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62370 - unsigned long addr)
62371 -{
62372 - return (vma->vm_flags & VM_GROWSDOWN) &&
62373 - (vma->vm_start == addr) &&
62374 - !vma_growsdown(vma->vm_prev, addr);
62375 -}
62376 -
62377 -/* Is the vma a continuation of the stack vma below it? */
62378 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62379 -{
62380 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62381 -}
62382 -
62383 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62384 - unsigned long addr)
62385 -{
62386 - return (vma->vm_flags & VM_GROWSUP) &&
62387 - (vma->vm_end == addr) &&
62388 - !vma_growsup(vma->vm_next, addr);
62389 -}
62390 -
62391 extern unsigned long move_page_tables(struct vm_area_struct *vma,
62392 unsigned long old_addr, struct vm_area_struct *new_vma,
62393 unsigned long new_addr, unsigned long len);
62394 @@ -1133,6 +1112,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
62395 }
62396 #endif
62397
62398 +#ifdef CONFIG_MMU
62399 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62400 +#else
62401 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62402 +{
62403 + return __pgprot(0);
62404 +}
62405 +#endif
62406 +
62407 int vma_wants_writenotify(struct vm_area_struct *vma);
62408
62409 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62410 @@ -1417,6 +1405,7 @@ out:
62411 }
62412
62413 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62414 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62415
62416 extern unsigned long do_brk(unsigned long, unsigned long);
62417
62418 @@ -1474,6 +1463,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62419 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62420 struct vm_area_struct **pprev);
62421
62422 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62423 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62424 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62425 +
62426 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62427 NULL if none. Assume start_addr < end_addr. */
62428 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62429 @@ -1490,15 +1483,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
62430 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
62431 }
62432
62433 -#ifdef CONFIG_MMU
62434 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62435 -#else
62436 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62437 -{
62438 - return __pgprot(0);
62439 -}
62440 -#endif
62441 -
62442 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62443 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62444 unsigned long pfn, unsigned long size, pgprot_t);
62445 @@ -1612,7 +1596,7 @@ extern int unpoison_memory(unsigned long pfn);
62446 extern int sysctl_memory_failure_early_kill;
62447 extern int sysctl_memory_failure_recovery;
62448 extern void shake_page(struct page *p, int access);
62449 -extern atomic_long_t mce_bad_pages;
62450 +extern atomic_long_unchecked_t mce_bad_pages;
62451 extern int soft_offline_page(struct page *page, int flags);
62452
62453 extern void dump_page(struct page *page);
62454 @@ -1626,5 +1610,11 @@ extern void copy_user_huge_page(struct page *dst, struct page *src,
62455 unsigned int pages_per_huge_page);
62456 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
62457
62458 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62459 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62460 +#else
62461 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62462 +#endif
62463 +
62464 #endif /* __KERNEL__ */
62465 #endif /* _LINUX_MM_H */
62466 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62467 index 10a2f62..d655142 100644
62468 --- a/include/linux/mm_types.h
62469 +++ b/include/linux/mm_types.h
62470 @@ -230,6 +230,8 @@ struct vm_area_struct {
62471 #ifdef CONFIG_NUMA
62472 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62473 #endif
62474 +
62475 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62476 };
62477
62478 struct core_thread {
62479 @@ -362,6 +364,24 @@ struct mm_struct {
62480 #ifdef CONFIG_CPUMASK_OFFSTACK
62481 struct cpumask cpumask_allocation;
62482 #endif
62483 +
62484 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62485 + unsigned long pax_flags;
62486 +#endif
62487 +
62488 +#ifdef CONFIG_PAX_DLRESOLVE
62489 + unsigned long call_dl_resolve;
62490 +#endif
62491 +
62492 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62493 + unsigned long call_syscall;
62494 +#endif
62495 +
62496 +#ifdef CONFIG_PAX_ASLR
62497 + unsigned long delta_mmap; /* randomized offset */
62498 + unsigned long delta_stack; /* randomized offset */
62499 +#endif
62500 +
62501 };
62502
62503 static inline void mm_init_cpumask(struct mm_struct *mm)
62504 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62505 index 1d1b1e1..2a13c78 100644
62506 --- a/include/linux/mmu_notifier.h
62507 +++ b/include/linux/mmu_notifier.h
62508 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62509 */
62510 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62511 ({ \
62512 - pte_t __pte; \
62513 + pte_t ___pte; \
62514 struct vm_area_struct *___vma = __vma; \
62515 unsigned long ___address = __address; \
62516 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62517 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62518 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62519 - __pte; \
62520 + ___pte; \
62521 })
62522
62523 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62524 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62525 index be1ac8d..26868ce 100644
62526 --- a/include/linux/mmzone.h
62527 +++ b/include/linux/mmzone.h
62528 @@ -356,7 +356,7 @@ struct zone {
62529 unsigned long flags; /* zone flags, see below */
62530
62531 /* Zone statistics */
62532 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62533 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62534
62535 /*
62536 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62537 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62538 index ae28e93..1ac2233 100644
62539 --- a/include/linux/mod_devicetable.h
62540 +++ b/include/linux/mod_devicetable.h
62541 @@ -12,7 +12,7 @@
62542 typedef unsigned long kernel_ulong_t;
62543 #endif
62544
62545 -#define PCI_ANY_ID (~0)
62546 +#define PCI_ANY_ID ((__u16)~0)
62547
62548 struct pci_device_id {
62549 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62550 @@ -131,7 +131,7 @@ struct usb_device_id {
62551 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62552 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62553
62554 -#define HID_ANY_ID (~0)
62555 +#define HID_ANY_ID (~0U)
62556
62557 struct hid_device_id {
62558 __u16 bus;
62559 diff --git a/include/linux/module.h b/include/linux/module.h
62560 index 1c30087..fc2a442 100644
62561 --- a/include/linux/module.h
62562 +++ b/include/linux/module.h
62563 @@ -16,6 +16,7 @@
62564 #include <linux/kobject.h>
62565 #include <linux/moduleparam.h>
62566 #include <linux/tracepoint.h>
62567 +#include <linux/fs.h>
62568
62569 #include <linux/percpu.h>
62570 #include <asm/module.h>
62571 @@ -327,19 +328,16 @@ struct module
62572 int (*init)(void);
62573
62574 /* If this is non-NULL, vfree after init() returns */
62575 - void *module_init;
62576 + void *module_init_rx, *module_init_rw;
62577
62578 /* Here is the actual code + data, vfree'd on unload. */
62579 - void *module_core;
62580 + void *module_core_rx, *module_core_rw;
62581
62582 /* Here are the sizes of the init and core sections */
62583 - unsigned int init_size, core_size;
62584 + unsigned int init_size_rw, core_size_rw;
62585
62586 /* The size of the executable code in each section. */
62587 - unsigned int init_text_size, core_text_size;
62588 -
62589 - /* Size of RO sections of the module (text+rodata) */
62590 - unsigned int init_ro_size, core_ro_size;
62591 + unsigned int init_size_rx, core_size_rx;
62592
62593 /* Arch-specific module values */
62594 struct mod_arch_specific arch;
62595 @@ -395,6 +393,10 @@ struct module
62596 #ifdef CONFIG_EVENT_TRACING
62597 struct ftrace_event_call **trace_events;
62598 unsigned int num_trace_events;
62599 + struct file_operations trace_id;
62600 + struct file_operations trace_enable;
62601 + struct file_operations trace_format;
62602 + struct file_operations trace_filter;
62603 #endif
62604 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62605 unsigned int num_ftrace_callsites;
62606 @@ -445,16 +447,46 @@ bool is_module_address(unsigned long addr);
62607 bool is_module_percpu_address(unsigned long addr);
62608 bool is_module_text_address(unsigned long addr);
62609
62610 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62611 +{
62612 +
62613 +#ifdef CONFIG_PAX_KERNEXEC
62614 + if (ktla_ktva(addr) >= (unsigned long)start &&
62615 + ktla_ktva(addr) < (unsigned long)start + size)
62616 + return 1;
62617 +#endif
62618 +
62619 + return ((void *)addr >= start && (void *)addr < start + size);
62620 +}
62621 +
62622 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62623 +{
62624 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62625 +}
62626 +
62627 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62628 +{
62629 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62630 +}
62631 +
62632 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62633 +{
62634 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62635 +}
62636 +
62637 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62638 +{
62639 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62640 +}
62641 +
62642 static inline int within_module_core(unsigned long addr, struct module *mod)
62643 {
62644 - return (unsigned long)mod->module_core <= addr &&
62645 - addr < (unsigned long)mod->module_core + mod->core_size;
62646 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62647 }
62648
62649 static inline int within_module_init(unsigned long addr, struct module *mod)
62650 {
62651 - return (unsigned long)mod->module_init <= addr &&
62652 - addr < (unsigned long)mod->module_init + mod->init_size;
62653 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62654 }
62655
62656 /* Search for module by name: must hold module_mutex. */
62657 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62658 index b2be02e..6a9fdb1 100644
62659 --- a/include/linux/moduleloader.h
62660 +++ b/include/linux/moduleloader.h
62661 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62662 sections. Returns NULL on failure. */
62663 void *module_alloc(unsigned long size);
62664
62665 +#ifdef CONFIG_PAX_KERNEXEC
62666 +void *module_alloc_exec(unsigned long size);
62667 +#else
62668 +#define module_alloc_exec(x) module_alloc(x)
62669 +#endif
62670 +
62671 /* Free memory returned from module_alloc. */
62672 void module_free(struct module *mod, void *module_region);
62673
62674 +#ifdef CONFIG_PAX_KERNEXEC
62675 +void module_free_exec(struct module *mod, void *module_region);
62676 +#else
62677 +#define module_free_exec(x, y) module_free((x), (y))
62678 +#endif
62679 +
62680 /* Apply the given relocation to the (simplified) ELF. Return -error
62681 or 0. */
62682 int apply_relocate(Elf_Shdr *sechdrs,
62683 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62684 index ddaae98..3c70938 100644
62685 --- a/include/linux/moduleparam.h
62686 +++ b/include/linux/moduleparam.h
62687 @@ -255,7 +255,7 @@ static inline void __kernel_param_unlock(void)
62688 * @len is usually just sizeof(string).
62689 */
62690 #define module_param_string(name, string, len, perm) \
62691 - static const struct kparam_string __param_string_##name \
62692 + static const struct kparam_string __param_string_##name __used \
62693 = { len, string }; \
62694 __module_param_call(MODULE_PARAM_PREFIX, name, \
62695 &param_ops_string, \
62696 @@ -370,7 +370,7 @@ extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
62697 * module_param_named() for why this might be necessary.
62698 */
62699 #define module_param_array_named(name, array, type, nump, perm) \
62700 - static const struct kparam_array __param_arr_##name \
62701 + static const struct kparam_array __param_arr_##name __used \
62702 = { .max = ARRAY_SIZE(array), .num = nump, \
62703 .ops = &param_ops_##type, \
62704 .elemsize = sizeof(array[0]), .elem = array }; \
62705 diff --git a/include/linux/namei.h b/include/linux/namei.h
62706 index ffc0213..2c1f2cb 100644
62707 --- a/include/linux/namei.h
62708 +++ b/include/linux/namei.h
62709 @@ -24,7 +24,7 @@ struct nameidata {
62710 unsigned seq;
62711 int last_type;
62712 unsigned depth;
62713 - char *saved_names[MAX_NESTED_LINKS + 1];
62714 + const char *saved_names[MAX_NESTED_LINKS + 1];
62715
62716 /* Intent data */
62717 union {
62718 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62719 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62720 extern void unlock_rename(struct dentry *, struct dentry *);
62721
62722 -static inline void nd_set_link(struct nameidata *nd, char *path)
62723 +static inline void nd_set_link(struct nameidata *nd, const char *path)
62724 {
62725 nd->saved_names[nd->depth] = path;
62726 }
62727
62728 -static inline char *nd_get_link(struct nameidata *nd)
62729 +static inline const char *nd_get_link(const struct nameidata *nd)
62730 {
62731 return nd->saved_names[nd->depth];
62732 }
62733 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62734 index ddee79b..67af106 100644
62735 --- a/include/linux/netdevice.h
62736 +++ b/include/linux/netdevice.h
62737 @@ -944,6 +944,7 @@ struct net_device_ops {
62738 int (*ndo_set_features)(struct net_device *dev,
62739 u32 features);
62740 };
62741 +typedef struct net_device_ops __no_const net_device_ops_no_const;
62742
62743 /*
62744 * The DEVICE structure.
62745 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62746 new file mode 100644
62747 index 0000000..33f4af8
62748 --- /dev/null
62749 +++ b/include/linux/netfilter/xt_gradm.h
62750 @@ -0,0 +1,9 @@
62751 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
62752 +#define _LINUX_NETFILTER_XT_GRADM_H 1
62753 +
62754 +struct xt_gradm_mtinfo {
62755 + __u16 flags;
62756 + __u16 invflags;
62757 +};
62758 +
62759 +#endif
62760 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62761 index c65a18a..0c05f3a 100644
62762 --- a/include/linux/of_pdt.h
62763 +++ b/include/linux/of_pdt.h
62764 @@ -32,7 +32,7 @@ struct of_pdt_ops {
62765
62766 /* return 0 on success; fill in 'len' with number of bytes in path */
62767 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62768 -};
62769 +} __no_const;
62770
62771 extern void *prom_early_alloc(unsigned long size);
62772
62773 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62774 index 49c8727..34d2ae1 100644
62775 --- a/include/linux/oprofile.h
62776 +++ b/include/linux/oprofile.h
62777 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62778 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62779 char const * name, ulong * val);
62780
62781 -/** Create a file for read-only access to an atomic_t. */
62782 +/** Create a file for read-only access to an atomic_unchecked_t. */
62783 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62784 - char const * name, atomic_t * val);
62785 + char const * name, atomic_unchecked_t * val);
62786
62787 /** create a directory */
62788 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62789 diff --git a/include/linux/padata.h b/include/linux/padata.h
62790 index 4633b2f..988bc08 100644
62791 --- a/include/linux/padata.h
62792 +++ b/include/linux/padata.h
62793 @@ -129,7 +129,7 @@ struct parallel_data {
62794 struct padata_instance *pinst;
62795 struct padata_parallel_queue __percpu *pqueue;
62796 struct padata_serial_queue __percpu *squeue;
62797 - atomic_t seq_nr;
62798 + atomic_unchecked_t seq_nr;
62799 atomic_t reorder_objects;
62800 atomic_t refcnt;
62801 unsigned int max_seq_nr;
62802 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62803 index c816075..cd28c4d 100644
62804 --- a/include/linux/perf_event.h
62805 +++ b/include/linux/perf_event.h
62806 @@ -745,8 +745,8 @@ struct perf_event {
62807
62808 enum perf_event_active_state state;
62809 unsigned int attach_state;
62810 - local64_t count;
62811 - atomic64_t child_count;
62812 + local64_t count; /* PaX: fix it one day */
62813 + atomic64_unchecked_t child_count;
62814
62815 /*
62816 * These are the total time in nanoseconds that the event
62817 @@ -797,8 +797,8 @@ struct perf_event {
62818 * These accumulate total time (in nanoseconds) that children
62819 * events have been enabled and running, respectively.
62820 */
62821 - atomic64_t child_total_time_enabled;
62822 - atomic64_t child_total_time_running;
62823 + atomic64_unchecked_t child_total_time_enabled;
62824 + atomic64_unchecked_t child_total_time_running;
62825
62826 /*
62827 * Protect attach/detach and child_list:
62828 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62829 index 77257c9..51d473a 100644
62830 --- a/include/linux/pipe_fs_i.h
62831 +++ b/include/linux/pipe_fs_i.h
62832 @@ -46,9 +46,9 @@ struct pipe_buffer {
62833 struct pipe_inode_info {
62834 wait_queue_head_t wait;
62835 unsigned int nrbufs, curbuf, buffers;
62836 - unsigned int readers;
62837 - unsigned int writers;
62838 - unsigned int waiting_writers;
62839 + atomic_t readers;
62840 + atomic_t writers;
62841 + atomic_t waiting_writers;
62842 unsigned int r_counter;
62843 unsigned int w_counter;
62844 struct page *tmp_page;
62845 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62846 index daac05d..c6802ce 100644
62847 --- a/include/linux/pm_runtime.h
62848 +++ b/include/linux/pm_runtime.h
62849 @@ -99,7 +99,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62850
62851 static inline void pm_runtime_mark_last_busy(struct device *dev)
62852 {
62853 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
62854 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62855 }
62856
62857 #else /* !CONFIG_PM_RUNTIME */
62858 diff --git a/include/linux/poison.h b/include/linux/poison.h
62859 index 79159de..f1233a9 100644
62860 --- a/include/linux/poison.h
62861 +++ b/include/linux/poison.h
62862 @@ -19,8 +19,8 @@
62863 * under normal circumstances, used to verify that nobody uses
62864 * non-initialized list entries.
62865 */
62866 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62867 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62868 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62869 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62870
62871 /********** include/linux/timer.h **********/
62872 /*
62873 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62874 index 58969b2..ead129b 100644
62875 --- a/include/linux/preempt.h
62876 +++ b/include/linux/preempt.h
62877 @@ -123,7 +123,7 @@ struct preempt_ops {
62878 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62879 void (*sched_out)(struct preempt_notifier *notifier,
62880 struct task_struct *next);
62881 -};
62882 +} __no_const;
62883
62884 /**
62885 * preempt_notifier - key for installing preemption notifiers
62886 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62887 index 643b96c..ef55a9c 100644
62888 --- a/include/linux/proc_fs.h
62889 +++ b/include/linux/proc_fs.h
62890 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
62891 return proc_create_data(name, mode, parent, proc_fops, NULL);
62892 }
62893
62894 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
62895 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62896 +{
62897 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62898 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62899 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62900 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62901 +#else
62902 + return proc_create_data(name, mode, parent, proc_fops, NULL);
62903 +#endif
62904 +}
62905 +
62906 +
62907 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62908 mode_t mode, struct proc_dir_entry *base,
62909 read_proc_t *read_proc, void * data)
62910 @@ -258,7 +271,7 @@ union proc_op {
62911 int (*proc_show)(struct seq_file *m,
62912 struct pid_namespace *ns, struct pid *pid,
62913 struct task_struct *task);
62914 -};
62915 +} __no_const;
62916
62917 struct ctl_table_header;
62918 struct ctl_table;
62919 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
62920 index 800f113..af90cc8 100644
62921 --- a/include/linux/ptrace.h
62922 +++ b/include/linux/ptrace.h
62923 @@ -129,10 +129,10 @@ extern void __ptrace_unlink(struct task_struct *child);
62924 extern void exit_ptrace(struct task_struct *tracer);
62925 #define PTRACE_MODE_READ 1
62926 #define PTRACE_MODE_ATTACH 2
62927 -/* Returns 0 on success, -errno on denial. */
62928 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
62929 /* Returns true on success, false on denial. */
62930 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
62931 +/* Returns true on success, false on denial. */
62932 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
62933
62934 static inline int ptrace_reparented(struct task_struct *child)
62935 {
62936 diff --git a/include/linux/random.h b/include/linux/random.h
62937 index d13059f..2eaafaa 100644
62938 --- a/include/linux/random.h
62939 +++ b/include/linux/random.h
62940 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
62941
62942 u32 prandom32(struct rnd_state *);
62943
62944 +static inline unsigned long pax_get_random_long(void)
62945 +{
62946 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62947 +}
62948 +
62949 /*
62950 * Handle minimum values for seeds
62951 */
62952 static inline u32 __seed(u32 x, u32 m)
62953 {
62954 - return (x < m) ? x + m : x;
62955 + return (x <= m) ? x + m + 1 : x;
62956 }
62957
62958 /**
62959 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62960 index e0879a7..a12f962 100644
62961 --- a/include/linux/reboot.h
62962 +++ b/include/linux/reboot.h
62963 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62964 * Architecture-specific implementations of sys_reboot commands.
62965 */
62966
62967 -extern void machine_restart(char *cmd);
62968 -extern void machine_halt(void);
62969 -extern void machine_power_off(void);
62970 +extern void machine_restart(char *cmd) __noreturn;
62971 +extern void machine_halt(void) __noreturn;
62972 +extern void machine_power_off(void) __noreturn;
62973
62974 extern void machine_shutdown(void);
62975 struct pt_regs;
62976 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62977 */
62978
62979 extern void kernel_restart_prepare(char *cmd);
62980 -extern void kernel_restart(char *cmd);
62981 -extern void kernel_halt(void);
62982 -extern void kernel_power_off(void);
62983 +extern void kernel_restart(char *cmd) __noreturn;
62984 +extern void kernel_halt(void) __noreturn;
62985 +extern void kernel_power_off(void) __noreturn;
62986
62987 extern int C_A_D; /* for sysctl */
62988 void ctrl_alt_del(void);
62989 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62990 * Emergency restart, callable from an interrupt handler.
62991 */
62992
62993 -extern void emergency_restart(void);
62994 +extern void emergency_restart(void) __noreturn;
62995 #include <asm/emergency-restart.h>
62996
62997 #endif
62998 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
62999 index 96d465f..b084e05 100644
63000 --- a/include/linux/reiserfs_fs.h
63001 +++ b/include/linux/reiserfs_fs.h
63002 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63003 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63004
63005 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63006 -#define get_generation(s) atomic_read (&fs_generation(s))
63007 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63008 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63009 #define __fs_changed(gen,s) (gen != get_generation (s))
63010 #define fs_changed(gen,s) \
63011 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
63012 index 52c83b6..18ed7eb 100644
63013 --- a/include/linux/reiserfs_fs_sb.h
63014 +++ b/include/linux/reiserfs_fs_sb.h
63015 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
63016 /* Comment? -Hans */
63017 wait_queue_head_t s_wait;
63018 /* To be obsoleted soon by per buffer seals.. -Hans */
63019 - atomic_t s_generation_counter; // increased by one every time the
63020 + atomic_unchecked_t s_generation_counter; // increased by one every time the
63021 // tree gets re-balanced
63022 unsigned long s_properties; /* File system properties. Currently holds
63023 on-disk FS format */
63024 diff --git a/include/linux/relay.h b/include/linux/relay.h
63025 index 14a86bc..17d0700 100644
63026 --- a/include/linux/relay.h
63027 +++ b/include/linux/relay.h
63028 @@ -159,7 +159,7 @@ struct rchan_callbacks
63029 * The callback should return 0 if successful, negative if not.
63030 */
63031 int (*remove_buf_file)(struct dentry *dentry);
63032 -};
63033 +} __no_const;
63034
63035 /*
63036 * CONFIG_RELAY kernel API, kernel/relay.c
63037 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63038 index c6c6084..5bf1212 100644
63039 --- a/include/linux/rfkill.h
63040 +++ b/include/linux/rfkill.h
63041 @@ -147,6 +147,7 @@ struct rfkill_ops {
63042 void (*query)(struct rfkill *rfkill, void *data);
63043 int (*set_block)(void *data, bool blocked);
63044 };
63045 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63046
63047 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63048 /**
63049 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63050 index 2148b12..519b820 100644
63051 --- a/include/linux/rmap.h
63052 +++ b/include/linux/rmap.h
63053 @@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63054 void anon_vma_init(void); /* create anon_vma_cachep */
63055 int anon_vma_prepare(struct vm_area_struct *);
63056 void unlink_anon_vmas(struct vm_area_struct *);
63057 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63058 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63059 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63060 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63061 void __anon_vma_link(struct vm_area_struct *);
63062
63063 static inline void anon_vma_merge(struct vm_area_struct *vma,
63064 diff --git a/include/linux/sched.h b/include/linux/sched.h
63065 index 41d0237..5a64056 100644
63066 --- a/include/linux/sched.h
63067 +++ b/include/linux/sched.h
63068 @@ -100,6 +100,7 @@ struct bio_list;
63069 struct fs_struct;
63070 struct perf_event_context;
63071 struct blk_plug;
63072 +struct linux_binprm;
63073
63074 /*
63075 * List of flags we want to share for kernel threads,
63076 @@ -380,10 +381,13 @@ struct user_namespace;
63077 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63078
63079 extern int sysctl_max_map_count;
63080 +extern unsigned long sysctl_heap_stack_gap;
63081
63082 #include <linux/aio.h>
63083
63084 #ifdef CONFIG_MMU
63085 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63086 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63087 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63088 extern unsigned long
63089 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63090 @@ -629,6 +633,17 @@ struct signal_struct {
63091 #ifdef CONFIG_TASKSTATS
63092 struct taskstats *stats;
63093 #endif
63094 +
63095 +#ifdef CONFIG_GRKERNSEC
63096 + u32 curr_ip;
63097 + u32 saved_ip;
63098 + u32 gr_saddr;
63099 + u32 gr_daddr;
63100 + u16 gr_sport;
63101 + u16 gr_dport;
63102 + u8 used_accept:1;
63103 +#endif
63104 +
63105 #ifdef CONFIG_AUDIT
63106 unsigned audit_tty;
63107 struct tty_audit_buf *tty_audit_buf;
63108 @@ -710,6 +725,11 @@ struct user_struct {
63109 struct key *session_keyring; /* UID's default session keyring */
63110 #endif
63111
63112 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63113 + unsigned int banned;
63114 + unsigned long ban_expires;
63115 +#endif
63116 +
63117 /* Hash table maintenance information */
63118 struct hlist_node uidhash_node;
63119 uid_t uid;
63120 @@ -1340,8 +1360,8 @@ struct task_struct {
63121 struct list_head thread_group;
63122
63123 struct completion *vfork_done; /* for vfork() */
63124 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63125 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63126 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63127 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63128
63129 cputime_t utime, stime, utimescaled, stimescaled;
63130 cputime_t gtime;
63131 @@ -1357,13 +1377,6 @@ struct task_struct {
63132 struct task_cputime cputime_expires;
63133 struct list_head cpu_timers[3];
63134
63135 -/* process credentials */
63136 - const struct cred __rcu *real_cred; /* objective and real subjective task
63137 - * credentials (COW) */
63138 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63139 - * credentials (COW) */
63140 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63141 -
63142 char comm[TASK_COMM_LEN]; /* executable name excluding path
63143 - access with [gs]et_task_comm (which lock
63144 it with task_lock())
63145 @@ -1380,8 +1393,16 @@ struct task_struct {
63146 #endif
63147 /* CPU-specific state of this task */
63148 struct thread_struct thread;
63149 +/* thread_info moved to task_struct */
63150 +#ifdef CONFIG_X86
63151 + struct thread_info tinfo;
63152 +#endif
63153 /* filesystem information */
63154 struct fs_struct *fs;
63155 +
63156 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63157 + * credentials (COW) */
63158 +
63159 /* open file information */
63160 struct files_struct *files;
63161 /* namespaces */
63162 @@ -1428,6 +1449,11 @@ struct task_struct {
63163 struct rt_mutex_waiter *pi_blocked_on;
63164 #endif
63165
63166 +/* process credentials */
63167 + const struct cred __rcu *real_cred; /* objective and real subjective task
63168 + * credentials (COW) */
63169 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63170 +
63171 #ifdef CONFIG_DEBUG_MUTEXES
63172 /* mutex deadlock detection */
63173 struct mutex_waiter *blocked_on;
63174 @@ -1537,6 +1563,21 @@ struct task_struct {
63175 unsigned long default_timer_slack_ns;
63176
63177 struct list_head *scm_work_list;
63178 +
63179 +#ifdef CONFIG_GRKERNSEC
63180 + /* grsecurity */
63181 + struct dentry *gr_chroot_dentry;
63182 + struct acl_subject_label *acl;
63183 + struct acl_role_label *role;
63184 + struct file *exec_file;
63185 + u16 acl_role_id;
63186 + /* is this the task that authenticated to the special role */
63187 + u8 acl_sp_role;
63188 + u8 is_writable;
63189 + u8 brute;
63190 + u8 gr_is_chrooted;
63191 +#endif
63192 +
63193 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63194 /* Index of current stored address in ret_stack */
63195 int curr_ret_stack;
63196 @@ -1571,6 +1612,57 @@ struct task_struct {
63197 #endif
63198 };
63199
63200 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63201 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63202 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63203 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63204 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63205 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63206 +
63207 +#ifdef CONFIG_PAX_SOFTMODE
63208 +extern int pax_softmode;
63209 +#endif
63210 +
63211 +extern int pax_check_flags(unsigned long *);
63212 +
63213 +/* if tsk != current then task_lock must be held on it */
63214 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63215 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63216 +{
63217 + if (likely(tsk->mm))
63218 + return tsk->mm->pax_flags;
63219 + else
63220 + return 0UL;
63221 +}
63222 +
63223 +/* if tsk != current then task_lock must be held on it */
63224 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63225 +{
63226 + if (likely(tsk->mm)) {
63227 + tsk->mm->pax_flags = flags;
63228 + return 0;
63229 + }
63230 + return -EINVAL;
63231 +}
63232 +#endif
63233 +
63234 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63235 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63236 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63237 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63238 +#endif
63239 +
63240 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63241 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63242 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63243 +extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
63244 +
63245 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
63246 +extern void pax_track_stack(void);
63247 +#else
63248 +static inline void pax_track_stack(void) {}
63249 +#endif
63250 +
63251 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63252 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63253
63254 @@ -2074,7 +2166,9 @@ void yield(void);
63255 extern struct exec_domain default_exec_domain;
63256
63257 union thread_union {
63258 +#ifndef CONFIG_X86
63259 struct thread_info thread_info;
63260 +#endif
63261 unsigned long stack[THREAD_SIZE/sizeof(long)];
63262 };
63263
63264 @@ -2107,6 +2201,7 @@ extern struct pid_namespace init_pid_ns;
63265 */
63266
63267 extern struct task_struct *find_task_by_vpid(pid_t nr);
63268 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63269 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63270 struct pid_namespace *ns);
63271
63272 @@ -2243,7 +2338,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63273 extern void exit_itimers(struct signal_struct *);
63274 extern void flush_itimer_signals(void);
63275
63276 -extern NORET_TYPE void do_group_exit(int);
63277 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
63278
63279 extern void daemonize(const char *, ...);
63280 extern int allow_signal(int);
63281 @@ -2408,13 +2503,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63282
63283 #endif
63284
63285 -static inline int object_is_on_stack(void *obj)
63286 +static inline int object_starts_on_stack(void *obj)
63287 {
63288 - void *stack = task_stack_page(current);
63289 + const void *stack = task_stack_page(current);
63290
63291 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63292 }
63293
63294 +#ifdef CONFIG_PAX_USERCOPY
63295 +extern int object_is_on_stack(const void *obj, unsigned long len);
63296 +#endif
63297 +
63298 extern void thread_info_cache_init(void);
63299
63300 #ifdef CONFIG_DEBUG_STACK_USAGE
63301 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63302 index 899fbb4..1cb4138 100644
63303 --- a/include/linux/screen_info.h
63304 +++ b/include/linux/screen_info.h
63305 @@ -43,7 +43,8 @@ struct screen_info {
63306 __u16 pages; /* 0x32 */
63307 __u16 vesa_attributes; /* 0x34 */
63308 __u32 capabilities; /* 0x36 */
63309 - __u8 _reserved[6]; /* 0x3a */
63310 + __u16 vesapm_size; /* 0x3a */
63311 + __u8 _reserved[4]; /* 0x3c */
63312 } __attribute__((packed));
63313
63314 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63315 diff --git a/include/linux/security.h b/include/linux/security.h
63316 index ebd2a53..2d949ae 100644
63317 --- a/include/linux/security.h
63318 +++ b/include/linux/security.h
63319 @@ -36,6 +36,7 @@
63320 #include <linux/key.h>
63321 #include <linux/xfrm.h>
63322 #include <linux/slab.h>
63323 +#include <linux/grsecurity.h>
63324 #include <net/flow.h>
63325
63326 /* Maximum number of letters for an LSM name string */
63327 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63328 index be720cd..a0e1b94 100644
63329 --- a/include/linux/seq_file.h
63330 +++ b/include/linux/seq_file.h
63331 @@ -33,6 +33,7 @@ struct seq_operations {
63332 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63333 int (*show) (struct seq_file *m, void *v);
63334 };
63335 +typedef struct seq_operations __no_const seq_operations_no_const;
63336
63337 #define SEQ_SKIP 1
63338
63339 diff --git a/include/linux/shm.h b/include/linux/shm.h
63340 index 92808b8..c28cac4 100644
63341 --- a/include/linux/shm.h
63342 +++ b/include/linux/shm.h
63343 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63344
63345 /* The task created the shm object. NULL if the task is dead. */
63346 struct task_struct *shm_creator;
63347 +#ifdef CONFIG_GRKERNSEC
63348 + time_t shm_createtime;
63349 + pid_t shm_lapid;
63350 +#endif
63351 };
63352
63353 /* shm_mode upper byte flags */
63354 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63355 index 0f96646..cfb757a 100644
63356 --- a/include/linux/skbuff.h
63357 +++ b/include/linux/skbuff.h
63358 @@ -610,7 +610,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63359 */
63360 static inline int skb_queue_empty(const struct sk_buff_head *list)
63361 {
63362 - return list->next == (struct sk_buff *)list;
63363 + return list->next == (const struct sk_buff *)list;
63364 }
63365
63366 /**
63367 @@ -623,7 +623,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63368 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63369 const struct sk_buff *skb)
63370 {
63371 - return skb->next == (struct sk_buff *)list;
63372 + return skb->next == (const struct sk_buff *)list;
63373 }
63374
63375 /**
63376 @@ -636,7 +636,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63377 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63378 const struct sk_buff *skb)
63379 {
63380 - return skb->prev == (struct sk_buff *)list;
63381 + return skb->prev == (const struct sk_buff *)list;
63382 }
63383
63384 /**
63385 @@ -1458,7 +1458,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63386 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63387 */
63388 #ifndef NET_SKB_PAD
63389 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63390 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63391 #endif
63392
63393 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63394 diff --git a/include/linux/slab.h b/include/linux/slab.h
63395 index 573c809..e84c132 100644
63396 --- a/include/linux/slab.h
63397 +++ b/include/linux/slab.h
63398 @@ -11,12 +11,20 @@
63399
63400 #include <linux/gfp.h>
63401 #include <linux/types.h>
63402 +#include <linux/err.h>
63403
63404 /*
63405 * Flags to pass to kmem_cache_create().
63406 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63407 */
63408 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63409 +
63410 +#ifdef CONFIG_PAX_USERCOPY
63411 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63412 +#else
63413 +#define SLAB_USERCOPY 0x00000000UL
63414 +#endif
63415 +
63416 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63417 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63418 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63419 @@ -87,10 +95,13 @@
63420 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63421 * Both make kfree a no-op.
63422 */
63423 -#define ZERO_SIZE_PTR ((void *)16)
63424 +#define ZERO_SIZE_PTR \
63425 +({ \
63426 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63427 + (void *)(-MAX_ERRNO-1L); \
63428 +})
63429
63430 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63431 - (unsigned long)ZERO_SIZE_PTR)
63432 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63433
63434 /*
63435 * struct kmem_cache related prototypes
63436 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63437 void kfree(const void *);
63438 void kzfree(const void *);
63439 size_t ksize(const void *);
63440 +void check_object_size(const void *ptr, unsigned long n, bool to);
63441
63442 /*
63443 * Allocator specific definitions. These are mainly used to establish optimized
63444 @@ -353,4 +365,59 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
63445
63446 void __init kmem_cache_init_late(void);
63447
63448 +#define kmalloc(x, y) \
63449 +({ \
63450 + void *___retval; \
63451 + intoverflow_t ___x = (intoverflow_t)x; \
63452 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
63453 + ___retval = NULL; \
63454 + else \
63455 + ___retval = kmalloc((size_t)___x, (y)); \
63456 + ___retval; \
63457 +})
63458 +
63459 +#define kmalloc_node(x, y, z) \
63460 +({ \
63461 + void *___retval; \
63462 + intoverflow_t ___x = (intoverflow_t)x; \
63463 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
63464 + ___retval = NULL; \
63465 + else \
63466 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
63467 + ___retval; \
63468 +})
63469 +
63470 +#define kzalloc(x, y) \
63471 +({ \
63472 + void *___retval; \
63473 + intoverflow_t ___x = (intoverflow_t)x; \
63474 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
63475 + ___retval = NULL; \
63476 + else \
63477 + ___retval = kzalloc((size_t)___x, (y)); \
63478 + ___retval; \
63479 +})
63480 +
63481 +#define __krealloc(x, y, z) \
63482 +({ \
63483 + void *___retval; \
63484 + intoverflow_t ___y = (intoverflow_t)y; \
63485 + if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
63486 + ___retval = NULL; \
63487 + else \
63488 + ___retval = __krealloc((x), (size_t)___y, (z)); \
63489 + ___retval; \
63490 +})
63491 +
63492 +#define krealloc(x, y, z) \
63493 +({ \
63494 + void *___retval; \
63495 + intoverflow_t ___y = (intoverflow_t)y; \
63496 + if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
63497 + ___retval = NULL; \
63498 + else \
63499 + ___retval = krealloc((x), (size_t)___y, (z)); \
63500 + ___retval; \
63501 +})
63502 +
63503 #endif /* _LINUX_SLAB_H */
63504 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63505 index d00e0ba..1b3bf7b 100644
63506 --- a/include/linux/slab_def.h
63507 +++ b/include/linux/slab_def.h
63508 @@ -68,10 +68,10 @@ struct kmem_cache {
63509 unsigned long node_allocs;
63510 unsigned long node_frees;
63511 unsigned long node_overflow;
63512 - atomic_t allochit;
63513 - atomic_t allocmiss;
63514 - atomic_t freehit;
63515 - atomic_t freemiss;
63516 + atomic_unchecked_t allochit;
63517 + atomic_unchecked_t allocmiss;
63518 + atomic_unchecked_t freehit;
63519 + atomic_unchecked_t freemiss;
63520
63521 /*
63522 * If debugging is enabled, then the allocator can add additional
63523 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63524 index f58d641..c56bf9c 100644
63525 --- a/include/linux/slub_def.h
63526 +++ b/include/linux/slub_def.h
63527 @@ -85,7 +85,7 @@ struct kmem_cache {
63528 struct kmem_cache_order_objects max;
63529 struct kmem_cache_order_objects min;
63530 gfp_t allocflags; /* gfp flags to use on each alloc */
63531 - int refcount; /* Refcount for slab cache destroy */
63532 + atomic_t refcount; /* Refcount for slab cache destroy */
63533 void (*ctor)(void *);
63534 int inuse; /* Offset to metadata */
63535 int align; /* Alignment */
63536 @@ -211,7 +211,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63537 }
63538
63539 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63540 -void *__kmalloc(size_t size, gfp_t flags);
63541 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
63542
63543 static __always_inline void *
63544 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63545 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63546 index de8832d..0147b46 100644
63547 --- a/include/linux/sonet.h
63548 +++ b/include/linux/sonet.h
63549 @@ -61,7 +61,7 @@ struct sonet_stats {
63550 #include <linux/atomic.h>
63551
63552 struct k_sonet_stats {
63553 -#define __HANDLE_ITEM(i) atomic_t i
63554 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63555 __SONET_ITEMS
63556 #undef __HANDLE_ITEM
63557 };
63558 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63559 index db7bcaf..1aca77e 100644
63560 --- a/include/linux/sunrpc/clnt.h
63561 +++ b/include/linux/sunrpc/clnt.h
63562 @@ -169,9 +169,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63563 {
63564 switch (sap->sa_family) {
63565 case AF_INET:
63566 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
63567 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63568 case AF_INET6:
63569 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63570 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63571 }
63572 return 0;
63573 }
63574 @@ -204,7 +204,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63575 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63576 const struct sockaddr *src)
63577 {
63578 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63579 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63580 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63581
63582 dsin->sin_family = ssin->sin_family;
63583 @@ -301,7 +301,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63584 if (sa->sa_family != AF_INET6)
63585 return 0;
63586
63587 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63588 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63589 }
63590
63591 #endif /* __KERNEL__ */
63592 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63593 index e775689..9e206d9 100644
63594 --- a/include/linux/sunrpc/sched.h
63595 +++ b/include/linux/sunrpc/sched.h
63596 @@ -105,6 +105,7 @@ struct rpc_call_ops {
63597 void (*rpc_call_done)(struct rpc_task *, void *);
63598 void (*rpc_release)(void *);
63599 };
63600 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63601
63602 struct rpc_task_setup {
63603 struct rpc_task *task;
63604 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63605 index c14fe86..393245e 100644
63606 --- a/include/linux/sunrpc/svc_rdma.h
63607 +++ b/include/linux/sunrpc/svc_rdma.h
63608 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63609 extern unsigned int svcrdma_max_requests;
63610 extern unsigned int svcrdma_max_req_size;
63611
63612 -extern atomic_t rdma_stat_recv;
63613 -extern atomic_t rdma_stat_read;
63614 -extern atomic_t rdma_stat_write;
63615 -extern atomic_t rdma_stat_sq_starve;
63616 -extern atomic_t rdma_stat_rq_starve;
63617 -extern atomic_t rdma_stat_rq_poll;
63618 -extern atomic_t rdma_stat_rq_prod;
63619 -extern atomic_t rdma_stat_sq_poll;
63620 -extern atomic_t rdma_stat_sq_prod;
63621 +extern atomic_unchecked_t rdma_stat_recv;
63622 +extern atomic_unchecked_t rdma_stat_read;
63623 +extern atomic_unchecked_t rdma_stat_write;
63624 +extern atomic_unchecked_t rdma_stat_sq_starve;
63625 +extern atomic_unchecked_t rdma_stat_rq_starve;
63626 +extern atomic_unchecked_t rdma_stat_rq_poll;
63627 +extern atomic_unchecked_t rdma_stat_rq_prod;
63628 +extern atomic_unchecked_t rdma_stat_sq_poll;
63629 +extern atomic_unchecked_t rdma_stat_sq_prod;
63630
63631 #define RPCRDMA_VERSION 1
63632
63633 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63634 index 11684d9..0d245eb 100644
63635 --- a/include/linux/sysctl.h
63636 +++ b/include/linux/sysctl.h
63637 @@ -155,7 +155,11 @@ enum
63638 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63639 };
63640
63641 -
63642 +#ifdef CONFIG_PAX_SOFTMODE
63643 +enum {
63644 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63645 +};
63646 +#endif
63647
63648 /* CTL_VM names: */
63649 enum
63650 @@ -967,6 +971,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63651
63652 extern int proc_dostring(struct ctl_table *, int,
63653 void __user *, size_t *, loff_t *);
63654 +extern int proc_dostring_modpriv(struct ctl_table *, int,
63655 + void __user *, size_t *, loff_t *);
63656 extern int proc_dointvec(struct ctl_table *, int,
63657 void __user *, size_t *, loff_t *);
63658 extern int proc_dointvec_minmax(struct ctl_table *, int,
63659 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63660 index ff7dc08..893e1bd 100644
63661 --- a/include/linux/tty_ldisc.h
63662 +++ b/include/linux/tty_ldisc.h
63663 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63664
63665 struct module *owner;
63666
63667 - int refcount;
63668 + atomic_t refcount;
63669 };
63670
63671 struct tty_ldisc {
63672 diff --git a/include/linux/types.h b/include/linux/types.h
63673 index 176da8c..e45e473 100644
63674 --- a/include/linux/types.h
63675 +++ b/include/linux/types.h
63676 @@ -213,10 +213,26 @@ typedef struct {
63677 int counter;
63678 } atomic_t;
63679
63680 +#ifdef CONFIG_PAX_REFCOUNT
63681 +typedef struct {
63682 + int counter;
63683 +} atomic_unchecked_t;
63684 +#else
63685 +typedef atomic_t atomic_unchecked_t;
63686 +#endif
63687 +
63688 #ifdef CONFIG_64BIT
63689 typedef struct {
63690 long counter;
63691 } atomic64_t;
63692 +
63693 +#ifdef CONFIG_PAX_REFCOUNT
63694 +typedef struct {
63695 + long counter;
63696 +} atomic64_unchecked_t;
63697 +#else
63698 +typedef atomic64_t atomic64_unchecked_t;
63699 +#endif
63700 #endif
63701
63702 struct list_head {
63703 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63704 index 5ca0951..ab496a5 100644
63705 --- a/include/linux/uaccess.h
63706 +++ b/include/linux/uaccess.h
63707 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63708 long ret; \
63709 mm_segment_t old_fs = get_fs(); \
63710 \
63711 - set_fs(KERNEL_DS); \
63712 pagefault_disable(); \
63713 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63714 - pagefault_enable(); \
63715 + set_fs(KERNEL_DS); \
63716 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63717 set_fs(old_fs); \
63718 + pagefault_enable(); \
63719 ret; \
63720 })
63721
63722 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63723 index 99c1b4d..bb94261 100644
63724 --- a/include/linux/unaligned/access_ok.h
63725 +++ b/include/linux/unaligned/access_ok.h
63726 @@ -6,32 +6,32 @@
63727
63728 static inline u16 get_unaligned_le16(const void *p)
63729 {
63730 - return le16_to_cpup((__le16 *)p);
63731 + return le16_to_cpup((const __le16 *)p);
63732 }
63733
63734 static inline u32 get_unaligned_le32(const void *p)
63735 {
63736 - return le32_to_cpup((__le32 *)p);
63737 + return le32_to_cpup((const __le32 *)p);
63738 }
63739
63740 static inline u64 get_unaligned_le64(const void *p)
63741 {
63742 - return le64_to_cpup((__le64 *)p);
63743 + return le64_to_cpup((const __le64 *)p);
63744 }
63745
63746 static inline u16 get_unaligned_be16(const void *p)
63747 {
63748 - return be16_to_cpup((__be16 *)p);
63749 + return be16_to_cpup((const __be16 *)p);
63750 }
63751
63752 static inline u32 get_unaligned_be32(const void *p)
63753 {
63754 - return be32_to_cpup((__be32 *)p);
63755 + return be32_to_cpup((const __be32 *)p);
63756 }
63757
63758 static inline u64 get_unaligned_be64(const void *p)
63759 {
63760 - return be64_to_cpup((__be64 *)p);
63761 + return be64_to_cpup((const __be64 *)p);
63762 }
63763
63764 static inline void put_unaligned_le16(u16 val, void *p)
63765 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63766 index cf97b5b..40ebc87 100644
63767 --- a/include/linux/vermagic.h
63768 +++ b/include/linux/vermagic.h
63769 @@ -26,9 +26,35 @@
63770 #define MODULE_ARCH_VERMAGIC ""
63771 #endif
63772
63773 +#ifdef CONFIG_PAX_REFCOUNT
63774 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
63775 +#else
63776 +#define MODULE_PAX_REFCOUNT ""
63777 +#endif
63778 +
63779 +#ifdef CONSTIFY_PLUGIN
63780 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63781 +#else
63782 +#define MODULE_CONSTIFY_PLUGIN ""
63783 +#endif
63784 +
63785 +#ifdef STACKLEAK_PLUGIN
63786 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63787 +#else
63788 +#define MODULE_STACKLEAK_PLUGIN ""
63789 +#endif
63790 +
63791 +#ifdef CONFIG_GRKERNSEC
63792 +#define MODULE_GRSEC "GRSEC "
63793 +#else
63794 +#define MODULE_GRSEC ""
63795 +#endif
63796 +
63797 #define VERMAGIC_STRING \
63798 UTS_RELEASE " " \
63799 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63800 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63801 - MODULE_ARCH_VERMAGIC
63802 + MODULE_ARCH_VERMAGIC \
63803 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63804 + MODULE_GRSEC
63805
63806 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63807 index 687fb11..b342358 100644
63808 --- a/include/linux/vmalloc.h
63809 +++ b/include/linux/vmalloc.h
63810 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63811 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63812 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63813 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63814 +
63815 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63816 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63817 +#endif
63818 +
63819 /* bits [20..32] reserved for arch specific ioremap internals */
63820
63821 /*
63822 @@ -156,4 +161,103 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
63823 # endif
63824 #endif
63825
63826 +#define vmalloc(x) \
63827 +({ \
63828 + void *___retval; \
63829 + intoverflow_t ___x = (intoverflow_t)x; \
63830 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
63831 + ___retval = NULL; \
63832 + else \
63833 + ___retval = vmalloc((unsigned long)___x); \
63834 + ___retval; \
63835 +})
63836 +
63837 +#define vzalloc(x) \
63838 +({ \
63839 + void *___retval; \
63840 + intoverflow_t ___x = (intoverflow_t)x; \
63841 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
63842 + ___retval = NULL; \
63843 + else \
63844 + ___retval = vzalloc((unsigned long)___x); \
63845 + ___retval; \
63846 +})
63847 +
63848 +#define __vmalloc(x, y, z) \
63849 +({ \
63850 + void *___retval; \
63851 + intoverflow_t ___x = (intoverflow_t)x; \
63852 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
63853 + ___retval = NULL; \
63854 + else \
63855 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
63856 + ___retval; \
63857 +})
63858 +
63859 +#define vmalloc_user(x) \
63860 +({ \
63861 + void *___retval; \
63862 + intoverflow_t ___x = (intoverflow_t)x; \
63863 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
63864 + ___retval = NULL; \
63865 + else \
63866 + ___retval = vmalloc_user((unsigned long)___x); \
63867 + ___retval; \
63868 +})
63869 +
63870 +#define vmalloc_exec(x) \
63871 +({ \
63872 + void *___retval; \
63873 + intoverflow_t ___x = (intoverflow_t)x; \
63874 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
63875 + ___retval = NULL; \
63876 + else \
63877 + ___retval = vmalloc_exec((unsigned long)___x); \
63878 + ___retval; \
63879 +})
63880 +
63881 +#define vmalloc_node(x, y) \
63882 +({ \
63883 + void *___retval; \
63884 + intoverflow_t ___x = (intoverflow_t)x; \
63885 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
63886 + ___retval = NULL; \
63887 + else \
63888 + ___retval = vmalloc_node((unsigned long)___x, (y));\
63889 + ___retval; \
63890 +})
63891 +
63892 +#define vzalloc_node(x, y) \
63893 +({ \
63894 + void *___retval; \
63895 + intoverflow_t ___x = (intoverflow_t)x; \
63896 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
63897 + ___retval = NULL; \
63898 + else \
63899 + ___retval = vzalloc_node((unsigned long)___x, (y));\
63900 + ___retval; \
63901 +})
63902 +
63903 +#define vmalloc_32(x) \
63904 +({ \
63905 + void *___retval; \
63906 + intoverflow_t ___x = (intoverflow_t)x; \
63907 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
63908 + ___retval = NULL; \
63909 + else \
63910 + ___retval = vmalloc_32((unsigned long)___x); \
63911 + ___retval; \
63912 +})
63913 +
63914 +#define vmalloc_32_user(x) \
63915 +({ \
63916 +void *___retval; \
63917 + intoverflow_t ___x = (intoverflow_t)x; \
63918 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
63919 + ___retval = NULL; \
63920 + else \
63921 + ___retval = vmalloc_32_user((unsigned long)___x);\
63922 + ___retval; \
63923 +})
63924 +
63925 #endif /* _LINUX_VMALLOC_H */
63926 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
63927 index 65efb92..137adbb 100644
63928 --- a/include/linux/vmstat.h
63929 +++ b/include/linux/vmstat.h
63930 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
63931 /*
63932 * Zone based page accounting with per cpu differentials.
63933 */
63934 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63935 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63936
63937 static inline void zone_page_state_add(long x, struct zone *zone,
63938 enum zone_stat_item item)
63939 {
63940 - atomic_long_add(x, &zone->vm_stat[item]);
63941 - atomic_long_add(x, &vm_stat[item]);
63942 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
63943 + atomic_long_add_unchecked(x, &vm_stat[item]);
63944 }
63945
63946 static inline unsigned long global_page_state(enum zone_stat_item item)
63947 {
63948 - long x = atomic_long_read(&vm_stat[item]);
63949 + long x = atomic_long_read_unchecked(&vm_stat[item]);
63950 #ifdef CONFIG_SMP
63951 if (x < 0)
63952 x = 0;
63953 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
63954 static inline unsigned long zone_page_state(struct zone *zone,
63955 enum zone_stat_item item)
63956 {
63957 - long x = atomic_long_read(&zone->vm_stat[item]);
63958 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63959 #ifdef CONFIG_SMP
63960 if (x < 0)
63961 x = 0;
63962 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
63963 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
63964 enum zone_stat_item item)
63965 {
63966 - long x = atomic_long_read(&zone->vm_stat[item]);
63967 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63968
63969 #ifdef CONFIG_SMP
63970 int cpu;
63971 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
63972
63973 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
63974 {
63975 - atomic_long_inc(&zone->vm_stat[item]);
63976 - atomic_long_inc(&vm_stat[item]);
63977 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
63978 + atomic_long_inc_unchecked(&vm_stat[item]);
63979 }
63980
63981 static inline void __inc_zone_page_state(struct page *page,
63982 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
63983
63984 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
63985 {
63986 - atomic_long_dec(&zone->vm_stat[item]);
63987 - atomic_long_dec(&vm_stat[item]);
63988 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
63989 + atomic_long_dec_unchecked(&vm_stat[item]);
63990 }
63991
63992 static inline void __dec_zone_page_state(struct page *page,
63993 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
63994 index aed54c5..3e07f7a 100644
63995 --- a/include/linux/xattr.h
63996 +++ b/include/linux/xattr.h
63997 @@ -49,6 +49,11 @@
63998 #define XATTR_CAPS_SUFFIX "capability"
63999 #define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
64000
64001 +/* User namespace */
64002 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64003 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64004 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64005 +
64006 #ifdef __KERNEL__
64007
64008 #include <linux/types.h>
64009 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64010 index 4aeff96..b378cdc 100644
64011 --- a/include/media/saa7146_vv.h
64012 +++ b/include/media/saa7146_vv.h
64013 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
64014 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64015
64016 /* the extension can override this */
64017 - struct v4l2_ioctl_ops ops;
64018 + v4l2_ioctl_ops_no_const ops;
64019 /* pointer to the saa7146 core ops */
64020 const struct v4l2_ioctl_ops *core_ops;
64021
64022 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64023 index c7c40f1..4f01585 100644
64024 --- a/include/media/v4l2-dev.h
64025 +++ b/include/media/v4l2-dev.h
64026 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
64027
64028
64029 struct v4l2_file_operations {
64030 - struct module *owner;
64031 + struct module * const owner;
64032 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
64033 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
64034 unsigned int (*poll) (struct file *, struct poll_table_struct *);
64035 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
64036 int (*open) (struct file *);
64037 int (*release) (struct file *);
64038 };
64039 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64040
64041 /*
64042 * Newer version of video_device, handled by videodev2.c
64043 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64044 index dd9f1e7..8c4dd86 100644
64045 --- a/include/media/v4l2-ioctl.h
64046 +++ b/include/media/v4l2-ioctl.h
64047 @@ -272,7 +272,7 @@ struct v4l2_ioctl_ops {
64048 long (*vidioc_default) (struct file *file, void *fh,
64049 bool valid_prio, int cmd, void *arg);
64050 };
64051 -
64052 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64053
64054 /* v4l debugging and diagnostics */
64055
64056 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64057 index c5dedd8..a93b07b 100644
64058 --- a/include/net/caif/caif_hsi.h
64059 +++ b/include/net/caif/caif_hsi.h
64060 @@ -94,7 +94,7 @@ struct cfhsi_drv {
64061 void (*rx_done_cb) (struct cfhsi_drv *drv);
64062 void (*wake_up_cb) (struct cfhsi_drv *drv);
64063 void (*wake_down_cb) (struct cfhsi_drv *drv);
64064 -};
64065 +} __no_const;
64066
64067 /* Structure implemented by HSI device. */
64068 struct cfhsi_dev {
64069 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64070 index 9e5425b..8136ffc 100644
64071 --- a/include/net/caif/cfctrl.h
64072 +++ b/include/net/caif/cfctrl.h
64073 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64074 void (*radioset_rsp)(void);
64075 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64076 struct cflayer *client_layer);
64077 -};
64078 +} __no_const;
64079
64080 /* Link Setup Parameters for CAIF-Links. */
64081 struct cfctrl_link_param {
64082 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64083 struct cfctrl {
64084 struct cfsrvl serv;
64085 struct cfctrl_rsp res;
64086 - atomic_t req_seq_no;
64087 - atomic_t rsp_seq_no;
64088 + atomic_unchecked_t req_seq_no;
64089 + atomic_unchecked_t rsp_seq_no;
64090 struct list_head list;
64091 /* Protects from simultaneous access to first_req list */
64092 spinlock_t info_list_lock;
64093 diff --git a/include/net/flow.h b/include/net/flow.h
64094 index 57f15a7..0de26c6 100644
64095 --- a/include/net/flow.h
64096 +++ b/include/net/flow.h
64097 @@ -208,6 +208,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64098
64099 extern void flow_cache_flush(void);
64100 extern void flow_cache_flush_deferred(void);
64101 -extern atomic_t flow_cache_genid;
64102 +extern atomic_unchecked_t flow_cache_genid;
64103
64104 #endif
64105 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64106 index e9ff3fc..9d3e5c7 100644
64107 --- a/include/net/inetpeer.h
64108 +++ b/include/net/inetpeer.h
64109 @@ -48,8 +48,8 @@ struct inet_peer {
64110 */
64111 union {
64112 struct {
64113 - atomic_t rid; /* Frag reception counter */
64114 - atomic_t ip_id_count; /* IP ID for the next packet */
64115 + atomic_unchecked_t rid; /* Frag reception counter */
64116 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64117 __u32 tcp_ts;
64118 __u32 tcp_ts_stamp;
64119 };
64120 @@ -113,11 +113,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64121 more++;
64122 inet_peer_refcheck(p);
64123 do {
64124 - old = atomic_read(&p->ip_id_count);
64125 + old = atomic_read_unchecked(&p->ip_id_count);
64126 new = old + more;
64127 if (!new)
64128 new = 1;
64129 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64130 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64131 return new;
64132 }
64133
64134 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64135 index 10422ef..662570f 100644
64136 --- a/include/net/ip_fib.h
64137 +++ b/include/net/ip_fib.h
64138 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64139
64140 #define FIB_RES_SADDR(net, res) \
64141 ((FIB_RES_NH(res).nh_saddr_genid == \
64142 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64143 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64144 FIB_RES_NH(res).nh_saddr : \
64145 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64146 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64147 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64148 index 8fa4430..05dd772 100644
64149 --- a/include/net/ip_vs.h
64150 +++ b/include/net/ip_vs.h
64151 @@ -509,7 +509,7 @@ struct ip_vs_conn {
64152 struct ip_vs_conn *control; /* Master control connection */
64153 atomic_t n_control; /* Number of controlled ones */
64154 struct ip_vs_dest *dest; /* real server */
64155 - atomic_t in_pkts; /* incoming packet counter */
64156 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64157
64158 /* packet transmitter for different forwarding methods. If it
64159 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64160 @@ -647,7 +647,7 @@ struct ip_vs_dest {
64161 __be16 port; /* port number of the server */
64162 union nf_inet_addr addr; /* IP address of the server */
64163 volatile unsigned flags; /* dest status flags */
64164 - atomic_t conn_flags; /* flags to copy to conn */
64165 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64166 atomic_t weight; /* server weight */
64167
64168 atomic_t refcnt; /* reference counter */
64169 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64170 index 69b610a..fe3962c 100644
64171 --- a/include/net/irda/ircomm_core.h
64172 +++ b/include/net/irda/ircomm_core.h
64173 @@ -51,7 +51,7 @@ typedef struct {
64174 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64175 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64176 struct ircomm_info *);
64177 -} call_t;
64178 +} __no_const call_t;
64179
64180 struct ircomm_cb {
64181 irda_queue_t queue;
64182 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64183 index 59ba38bc..d515662 100644
64184 --- a/include/net/irda/ircomm_tty.h
64185 +++ b/include/net/irda/ircomm_tty.h
64186 @@ -35,6 +35,7 @@
64187 #include <linux/termios.h>
64188 #include <linux/timer.h>
64189 #include <linux/tty.h> /* struct tty_struct */
64190 +#include <asm/local.h>
64191
64192 #include <net/irda/irias_object.h>
64193 #include <net/irda/ircomm_core.h>
64194 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64195 unsigned short close_delay;
64196 unsigned short closing_wait; /* time to wait before closing */
64197
64198 - int open_count;
64199 - int blocked_open; /* # of blocked opens */
64200 + local_t open_count;
64201 + local_t blocked_open; /* # of blocked opens */
64202
64203 /* Protect concurent access to :
64204 * o self->open_count
64205 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64206 index f82a1e8..82d81e8 100644
64207 --- a/include/net/iucv/af_iucv.h
64208 +++ b/include/net/iucv/af_iucv.h
64209 @@ -87,7 +87,7 @@ struct iucv_sock {
64210 struct iucv_sock_list {
64211 struct hlist_head head;
64212 rwlock_t lock;
64213 - atomic_t autobind_name;
64214 + atomic_unchecked_t autobind_name;
64215 };
64216
64217 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64218 diff --git a/include/net/lapb.h b/include/net/lapb.h
64219 index 96cb5dd..25e8d4f 100644
64220 --- a/include/net/lapb.h
64221 +++ b/include/net/lapb.h
64222 @@ -95,7 +95,7 @@ struct lapb_cb {
64223 struct sk_buff_head write_queue;
64224 struct sk_buff_head ack_queue;
64225 unsigned char window;
64226 - struct lapb_register_struct callbacks;
64227 + struct lapb_register_struct *callbacks;
64228
64229 /* FRMR control information */
64230 struct lapb_frame frmr_data;
64231 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64232 index 2720884..3aa5c25 100644
64233 --- a/include/net/neighbour.h
64234 +++ b/include/net/neighbour.h
64235 @@ -122,7 +122,7 @@ struct neigh_ops {
64236 void (*error_report)(struct neighbour *, struct sk_buff *);
64237 int (*output)(struct neighbour *, struct sk_buff *);
64238 int (*connected_output)(struct neighbour *, struct sk_buff *);
64239 -};
64240 +} __do_const;
64241
64242 struct pneigh_entry {
64243 struct pneigh_entry *next;
64244 diff --git a/include/net/netlink.h b/include/net/netlink.h
64245 index 98c1854..d4add7b 100644
64246 --- a/include/net/netlink.h
64247 +++ b/include/net/netlink.h
64248 @@ -562,7 +562,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64249 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64250 {
64251 if (mark)
64252 - skb_trim(skb, (unsigned char *) mark - skb->data);
64253 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64254 }
64255
64256 /**
64257 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64258 index d786b4f..4c3dd41 100644
64259 --- a/include/net/netns/ipv4.h
64260 +++ b/include/net/netns/ipv4.h
64261 @@ -56,8 +56,8 @@ struct netns_ipv4 {
64262
64263 unsigned int sysctl_ping_group_range[2];
64264
64265 - atomic_t rt_genid;
64266 - atomic_t dev_addr_genid;
64267 + atomic_unchecked_t rt_genid;
64268 + atomic_unchecked_t dev_addr_genid;
64269
64270 #ifdef CONFIG_IP_MROUTE
64271 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64272 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64273 index 6a72a58..e6a127d 100644
64274 --- a/include/net/sctp/sctp.h
64275 +++ b/include/net/sctp/sctp.h
64276 @@ -318,9 +318,9 @@ do { \
64277
64278 #else /* SCTP_DEBUG */
64279
64280 -#define SCTP_DEBUG_PRINTK(whatever...)
64281 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64282 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64283 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64284 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64285 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64286 #define SCTP_ENABLE_DEBUG
64287 #define SCTP_DISABLE_DEBUG
64288 #define SCTP_ASSERT(expr, str, func)
64289 diff --git a/include/net/sock.h b/include/net/sock.h
64290 index 8e4062f..77b041e 100644
64291 --- a/include/net/sock.h
64292 +++ b/include/net/sock.h
64293 @@ -278,7 +278,7 @@ struct sock {
64294 #ifdef CONFIG_RPS
64295 __u32 sk_rxhash;
64296 #endif
64297 - atomic_t sk_drops;
64298 + atomic_unchecked_t sk_drops;
64299 int sk_rcvbuf;
64300
64301 struct sk_filter __rcu *sk_filter;
64302 @@ -1391,7 +1391,7 @@ static inline void sk_nocaps_add(struct sock *sk, int flags)
64303 }
64304
64305 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64306 - char __user *from, char *to,
64307 + char __user *from, unsigned char *to,
64308 int copy, int offset)
64309 {
64310 if (skb->ip_summed == CHECKSUM_NONE) {
64311 diff --git a/include/net/tcp.h b/include/net/tcp.h
64312 index acc620a..f4d99c6 100644
64313 --- a/include/net/tcp.h
64314 +++ b/include/net/tcp.h
64315 @@ -1401,8 +1401,8 @@ enum tcp_seq_states {
64316 struct tcp_seq_afinfo {
64317 char *name;
64318 sa_family_t family;
64319 - struct file_operations seq_fops;
64320 - struct seq_operations seq_ops;
64321 + file_operations_no_const seq_fops;
64322 + seq_operations_no_const seq_ops;
64323 };
64324
64325 struct tcp_iter_state {
64326 diff --git a/include/net/udp.h b/include/net/udp.h
64327 index 67ea6fc..e42aee8 100644
64328 --- a/include/net/udp.h
64329 +++ b/include/net/udp.h
64330 @@ -234,8 +234,8 @@ struct udp_seq_afinfo {
64331 char *name;
64332 sa_family_t family;
64333 struct udp_table *udp_table;
64334 - struct file_operations seq_fops;
64335 - struct seq_operations seq_ops;
64336 + file_operations_no_const seq_fops;
64337 + seq_operations_no_const seq_ops;
64338 };
64339
64340 struct udp_iter_state {
64341 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64342 index b203e14..1df3991 100644
64343 --- a/include/net/xfrm.h
64344 +++ b/include/net/xfrm.h
64345 @@ -505,7 +505,7 @@ struct xfrm_policy {
64346 struct timer_list timer;
64347
64348 struct flow_cache_object flo;
64349 - atomic_t genid;
64350 + atomic_unchecked_t genid;
64351 u32 priority;
64352 u32 index;
64353 struct xfrm_mark mark;
64354 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64355 index 2d0191c..a55797d 100644
64356 --- a/include/rdma/iw_cm.h
64357 +++ b/include/rdma/iw_cm.h
64358 @@ -120,7 +120,7 @@ struct iw_cm_verbs {
64359 int backlog);
64360
64361 int (*destroy_listen)(struct iw_cm_id *cm_id);
64362 -};
64363 +} __no_const;
64364
64365 /**
64366 * iw_create_cm_id - Create an IW CM identifier.
64367 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64368 index 7d96829..4ba78d3 100644
64369 --- a/include/scsi/libfc.h
64370 +++ b/include/scsi/libfc.h
64371 @@ -758,6 +758,7 @@ struct libfc_function_template {
64372 */
64373 void (*disc_stop_final) (struct fc_lport *);
64374 };
64375 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64376
64377 /**
64378 * struct fc_disc - Discovery context
64379 @@ -861,7 +862,7 @@ struct fc_lport {
64380 struct fc_vport *vport;
64381
64382 /* Operational Information */
64383 - struct libfc_function_template tt;
64384 + libfc_function_template_no_const tt;
64385 u8 link_up;
64386 u8 qfull;
64387 enum fc_lport_state state;
64388 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64389 index d371c3c..e228a8c 100644
64390 --- a/include/scsi/scsi_device.h
64391 +++ b/include/scsi/scsi_device.h
64392 @@ -161,9 +161,9 @@ struct scsi_device {
64393 unsigned int max_device_blocked; /* what device_blocked counts down from */
64394 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64395
64396 - atomic_t iorequest_cnt;
64397 - atomic_t iodone_cnt;
64398 - atomic_t ioerr_cnt;
64399 + atomic_unchecked_t iorequest_cnt;
64400 + atomic_unchecked_t iodone_cnt;
64401 + atomic_unchecked_t ioerr_cnt;
64402
64403 struct device sdev_gendev,
64404 sdev_dev;
64405 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64406 index 2a65167..91e01f8 100644
64407 --- a/include/scsi/scsi_transport_fc.h
64408 +++ b/include/scsi/scsi_transport_fc.h
64409 @@ -711,7 +711,7 @@ struct fc_function_template {
64410 unsigned long show_host_system_hostname:1;
64411
64412 unsigned long disable_target_scan:1;
64413 -};
64414 +} __do_const;
64415
64416
64417 /**
64418 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64419 index 030b87c..98a6954 100644
64420 --- a/include/sound/ak4xxx-adda.h
64421 +++ b/include/sound/ak4xxx-adda.h
64422 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64423 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64424 unsigned char val);
64425 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64426 -};
64427 +} __no_const;
64428
64429 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64430
64431 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64432 index 8c05e47..2b5df97 100644
64433 --- a/include/sound/hwdep.h
64434 +++ b/include/sound/hwdep.h
64435 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64436 struct snd_hwdep_dsp_status *status);
64437 int (*dsp_load)(struct snd_hwdep *hw,
64438 struct snd_hwdep_dsp_image *image);
64439 -};
64440 +} __no_const;
64441
64442 struct snd_hwdep {
64443 struct snd_card *card;
64444 diff --git a/include/sound/info.h b/include/sound/info.h
64445 index 4e94cf1..76748b1 100644
64446 --- a/include/sound/info.h
64447 +++ b/include/sound/info.h
64448 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
64449 struct snd_info_buffer *buffer);
64450 void (*write)(struct snd_info_entry *entry,
64451 struct snd_info_buffer *buffer);
64452 -};
64453 +} __no_const;
64454
64455 struct snd_info_entry_ops {
64456 int (*open)(struct snd_info_entry *entry,
64457 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64458 index 57e71fa..a2c7534 100644
64459 --- a/include/sound/pcm.h
64460 +++ b/include/sound/pcm.h
64461 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
64462 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64463 int (*ack)(struct snd_pcm_substream *substream);
64464 };
64465 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64466
64467 /*
64468 *
64469 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64470 index af1b49e..a5d55a5 100644
64471 --- a/include/sound/sb16_csp.h
64472 +++ b/include/sound/sb16_csp.h
64473 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64474 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64475 int (*csp_stop) (struct snd_sb_csp * p);
64476 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64477 -};
64478 +} __no_const;
64479
64480 /*
64481 * CSP private data
64482 diff --git a/include/sound/soc.h b/include/sound/soc.h
64483 index aa19f5a..a5b8208 100644
64484 --- a/include/sound/soc.h
64485 +++ b/include/sound/soc.h
64486 @@ -676,7 +676,7 @@ struct snd_soc_platform_driver {
64487 /* platform IO - used for platform DAPM */
64488 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64489 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64490 -};
64491 +} __do_const;
64492
64493 struct snd_soc_platform {
64494 const char *name;
64495 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64496 index 444cd6b..3327cc5 100644
64497 --- a/include/sound/ymfpci.h
64498 +++ b/include/sound/ymfpci.h
64499 @@ -358,7 +358,7 @@ struct snd_ymfpci {
64500 spinlock_t reg_lock;
64501 spinlock_t voice_lock;
64502 wait_queue_head_t interrupt_sleep;
64503 - atomic_t interrupt_sleep_count;
64504 + atomic_unchecked_t interrupt_sleep_count;
64505 struct snd_info_entry *proc_entry;
64506 const struct firmware *dsp_microcode;
64507 const struct firmware *controller_microcode;
64508 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64509 index 2704065..e10f3ef 100644
64510 --- a/include/target/target_core_base.h
64511 +++ b/include/target/target_core_base.h
64512 @@ -356,7 +356,7 @@ struct t10_reservation_ops {
64513 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64514 int (*t10_pr_register)(struct se_cmd *);
64515 int (*t10_pr_clear)(struct se_cmd *);
64516 -};
64517 +} __no_const;
64518
64519 struct t10_reservation {
64520 /* Reservation effects all target ports */
64521 @@ -496,8 +496,8 @@ struct se_cmd {
64522 atomic_t t_task_cdbs_left;
64523 atomic_t t_task_cdbs_ex_left;
64524 atomic_t t_task_cdbs_timeout_left;
64525 - atomic_t t_task_cdbs_sent;
64526 - atomic_t t_transport_aborted;
64527 + atomic_unchecked_t t_task_cdbs_sent;
64528 + atomic_unchecked_t t_transport_aborted;
64529 atomic_t t_transport_active;
64530 atomic_t t_transport_complete;
64531 atomic_t t_transport_queue_active;
64532 @@ -744,7 +744,7 @@ struct se_device {
64533 atomic_t active_cmds;
64534 atomic_t simple_cmds;
64535 atomic_t depth_left;
64536 - atomic_t dev_ordered_id;
64537 + atomic_unchecked_t dev_ordered_id;
64538 atomic_t dev_tur_active;
64539 atomic_t execute_tasks;
64540 atomic_t dev_status_thr_count;
64541 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64542 index 1c09820..7f5ec79 100644
64543 --- a/include/trace/events/irq.h
64544 +++ b/include/trace/events/irq.h
64545 @@ -36,7 +36,7 @@ struct softirq_action;
64546 */
64547 TRACE_EVENT(irq_handler_entry,
64548
64549 - TP_PROTO(int irq, struct irqaction *action),
64550 + TP_PROTO(int irq, const struct irqaction *action),
64551
64552 TP_ARGS(irq, action),
64553
64554 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64555 */
64556 TRACE_EVENT(irq_handler_exit,
64557
64558 - TP_PROTO(int irq, struct irqaction *action, int ret),
64559 + TP_PROTO(int irq, const struct irqaction *action, int ret),
64560
64561 TP_ARGS(irq, action, ret),
64562
64563 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64564 index 69d485a..dd0bee7 100644
64565 --- a/include/video/udlfb.h
64566 +++ b/include/video/udlfb.h
64567 @@ -51,10 +51,10 @@ struct dlfb_data {
64568 int base8;
64569 u32 pseudo_palette[256];
64570 /* blit-only rendering path metrics, exposed through sysfs */
64571 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64572 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64573 - atomic_t bytes_sent; /* to usb, after compression including overhead */
64574 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64575 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64576 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64577 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64578 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64579 };
64580
64581 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64582 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64583 index 0993a22..32ba2fe 100644
64584 --- a/include/video/uvesafb.h
64585 +++ b/include/video/uvesafb.h
64586 @@ -177,6 +177,7 @@ struct uvesafb_par {
64587 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64588 u8 pmi_setpal; /* PMI for palette changes */
64589 u16 *pmi_base; /* protected mode interface location */
64590 + u8 *pmi_code; /* protected mode code location */
64591 void *pmi_start;
64592 void *pmi_pal;
64593 u8 *vbe_state_orig; /*
64594 diff --git a/init/Kconfig b/init/Kconfig
64595 index d627783..693a9f3 100644
64596 --- a/init/Kconfig
64597 +++ b/init/Kconfig
64598 @@ -1202,7 +1202,7 @@ config SLUB_DEBUG
64599
64600 config COMPAT_BRK
64601 bool "Disable heap randomization"
64602 - default y
64603 + default n
64604 help
64605 Randomizing heap placement makes heap exploits harder, but it
64606 also breaks ancient binaries (including anything libc5 based).
64607 diff --git a/init/do_mounts.c b/init/do_mounts.c
64608 index c0851a8..4f8977d 100644
64609 --- a/init/do_mounts.c
64610 +++ b/init/do_mounts.c
64611 @@ -287,11 +287,11 @@ static void __init get_fs_names(char *page)
64612
64613 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64614 {
64615 - int err = sys_mount(name, "/root", fs, flags, data);
64616 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64617 if (err)
64618 return err;
64619
64620 - sys_chdir((const char __user __force *)"/root");
64621 + sys_chdir((const char __force_user*)"/root");
64622 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
64623 printk(KERN_INFO
64624 "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
64625 @@ -383,18 +383,18 @@ void __init change_floppy(char *fmt, ...)
64626 va_start(args, fmt);
64627 vsprintf(buf, fmt, args);
64628 va_end(args);
64629 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64630 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64631 if (fd >= 0) {
64632 sys_ioctl(fd, FDEJECT, 0);
64633 sys_close(fd);
64634 }
64635 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64636 - fd = sys_open("/dev/console", O_RDWR, 0);
64637 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64638 if (fd >= 0) {
64639 sys_ioctl(fd, TCGETS, (long)&termios);
64640 termios.c_lflag &= ~ICANON;
64641 sys_ioctl(fd, TCSETSF, (long)&termios);
64642 - sys_read(fd, &c, 1);
64643 + sys_read(fd, (char __user *)&c, 1);
64644 termios.c_lflag |= ICANON;
64645 sys_ioctl(fd, TCSETSF, (long)&termios);
64646 sys_close(fd);
64647 @@ -488,6 +488,6 @@ void __init prepare_namespace(void)
64648 mount_root();
64649 out:
64650 devtmpfs_mount("dev");
64651 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64652 - sys_chroot((const char __user __force *)".");
64653 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64654 + sys_chroot((const char __force_user *)".");
64655 }
64656 diff --git a/init/do_mounts.h b/init/do_mounts.h
64657 index f5b978a..69dbfe8 100644
64658 --- a/init/do_mounts.h
64659 +++ b/init/do_mounts.h
64660 @@ -15,15 +15,15 @@ extern int root_mountflags;
64661
64662 static inline int create_dev(char *name, dev_t dev)
64663 {
64664 - sys_unlink(name);
64665 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64666 + sys_unlink((char __force_user *)name);
64667 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64668 }
64669
64670 #if BITS_PER_LONG == 32
64671 static inline u32 bstat(char *name)
64672 {
64673 struct stat64 stat;
64674 - if (sys_stat64(name, &stat) != 0)
64675 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64676 return 0;
64677 if (!S_ISBLK(stat.st_mode))
64678 return 0;
64679 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64680 static inline u32 bstat(char *name)
64681 {
64682 struct stat stat;
64683 - if (sys_newstat(name, &stat) != 0)
64684 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64685 return 0;
64686 if (!S_ISBLK(stat.st_mode))
64687 return 0;
64688 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64689 index 3098a38..253064e 100644
64690 --- a/init/do_mounts_initrd.c
64691 +++ b/init/do_mounts_initrd.c
64692 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
64693 create_dev("/dev/root.old", Root_RAM0);
64694 /* mount initrd on rootfs' /root */
64695 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64696 - sys_mkdir("/old", 0700);
64697 - root_fd = sys_open("/", 0, 0);
64698 - old_fd = sys_open("/old", 0, 0);
64699 + sys_mkdir((const char __force_user *)"/old", 0700);
64700 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
64701 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64702 /* move initrd over / and chdir/chroot in initrd root */
64703 - sys_chdir("/root");
64704 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64705 - sys_chroot(".");
64706 + sys_chdir((const char __force_user *)"/root");
64707 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64708 + sys_chroot((const char __force_user *)".");
64709
64710 /*
64711 * In case that a resume from disk is carried out by linuxrc or one of
64712 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
64713
64714 /* move initrd to rootfs' /old */
64715 sys_fchdir(old_fd);
64716 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
64717 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64718 /* switch root and cwd back to / of rootfs */
64719 sys_fchdir(root_fd);
64720 - sys_chroot(".");
64721 + sys_chroot((const char __force_user *)".");
64722 sys_close(old_fd);
64723 sys_close(root_fd);
64724
64725 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64726 - sys_chdir("/old");
64727 + sys_chdir((const char __force_user *)"/old");
64728 return;
64729 }
64730
64731 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
64732 mount_root();
64733
64734 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64735 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64736 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64737 if (!error)
64738 printk("okay\n");
64739 else {
64740 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
64741 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64742 if (error == -ENOENT)
64743 printk("/initrd does not exist. Ignored.\n");
64744 else
64745 printk("failed\n");
64746 printk(KERN_NOTICE "Unmounting old root\n");
64747 - sys_umount("/old", MNT_DETACH);
64748 + sys_umount((char __force_user *)"/old", MNT_DETACH);
64749 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64750 if (fd < 0) {
64751 error = fd;
64752 @@ -116,11 +116,11 @@ int __init initrd_load(void)
64753 * mounted in the normal path.
64754 */
64755 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64756 - sys_unlink("/initrd.image");
64757 + sys_unlink((const char __force_user *)"/initrd.image");
64758 handle_initrd();
64759 return 1;
64760 }
64761 }
64762 - sys_unlink("/initrd.image");
64763 + sys_unlink((const char __force_user *)"/initrd.image");
64764 return 0;
64765 }
64766 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64767 index 32c4799..c27ee74 100644
64768 --- a/init/do_mounts_md.c
64769 +++ b/init/do_mounts_md.c
64770 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64771 partitioned ? "_d" : "", minor,
64772 md_setup_args[ent].device_names);
64773
64774 - fd = sys_open(name, 0, 0);
64775 + fd = sys_open((char __force_user *)name, 0, 0);
64776 if (fd < 0) {
64777 printk(KERN_ERR "md: open failed - cannot start "
64778 "array %s\n", name);
64779 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64780 * array without it
64781 */
64782 sys_close(fd);
64783 - fd = sys_open(name, 0, 0);
64784 + fd = sys_open((char __force_user *)name, 0, 0);
64785 sys_ioctl(fd, BLKRRPART, 0);
64786 }
64787 sys_close(fd);
64788 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64789
64790 wait_for_device_probe();
64791
64792 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64793 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64794 if (fd >= 0) {
64795 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64796 sys_close(fd);
64797 diff --git a/init/initramfs.c b/init/initramfs.c
64798 index 2531811..040d4d4 100644
64799 --- a/init/initramfs.c
64800 +++ b/init/initramfs.c
64801 @@ -74,7 +74,7 @@ static void __init free_hash(void)
64802 }
64803 }
64804
64805 -static long __init do_utime(char __user *filename, time_t mtime)
64806 +static long __init do_utime(__force char __user *filename, time_t mtime)
64807 {
64808 struct timespec t[2];
64809
64810 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
64811 struct dir_entry *de, *tmp;
64812 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64813 list_del(&de->list);
64814 - do_utime(de->name, de->mtime);
64815 + do_utime((char __force_user *)de->name, de->mtime);
64816 kfree(de->name);
64817 kfree(de);
64818 }
64819 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
64820 if (nlink >= 2) {
64821 char *old = find_link(major, minor, ino, mode, collected);
64822 if (old)
64823 - return (sys_link(old, collected) < 0) ? -1 : 1;
64824 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64825 }
64826 return 0;
64827 }
64828 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
64829 {
64830 struct stat st;
64831
64832 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64833 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64834 if (S_ISDIR(st.st_mode))
64835 - sys_rmdir(path);
64836 + sys_rmdir((char __force_user *)path);
64837 else
64838 - sys_unlink(path);
64839 + sys_unlink((char __force_user *)path);
64840 }
64841 }
64842
64843 @@ -305,7 +305,7 @@ static int __init do_name(void)
64844 int openflags = O_WRONLY|O_CREAT;
64845 if (ml != 1)
64846 openflags |= O_TRUNC;
64847 - wfd = sys_open(collected, openflags, mode);
64848 + wfd = sys_open((char __force_user *)collected, openflags, mode);
64849
64850 if (wfd >= 0) {
64851 sys_fchown(wfd, uid, gid);
64852 @@ -317,17 +317,17 @@ static int __init do_name(void)
64853 }
64854 }
64855 } else if (S_ISDIR(mode)) {
64856 - sys_mkdir(collected, mode);
64857 - sys_chown(collected, uid, gid);
64858 - sys_chmod(collected, mode);
64859 + sys_mkdir((char __force_user *)collected, mode);
64860 + sys_chown((char __force_user *)collected, uid, gid);
64861 + sys_chmod((char __force_user *)collected, mode);
64862 dir_add(collected, mtime);
64863 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64864 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64865 if (maybe_link() == 0) {
64866 - sys_mknod(collected, mode, rdev);
64867 - sys_chown(collected, uid, gid);
64868 - sys_chmod(collected, mode);
64869 - do_utime(collected, mtime);
64870 + sys_mknod((char __force_user *)collected, mode, rdev);
64871 + sys_chown((char __force_user *)collected, uid, gid);
64872 + sys_chmod((char __force_user *)collected, mode);
64873 + do_utime((char __force_user *)collected, mtime);
64874 }
64875 }
64876 return 0;
64877 @@ -336,15 +336,15 @@ static int __init do_name(void)
64878 static int __init do_copy(void)
64879 {
64880 if (count >= body_len) {
64881 - sys_write(wfd, victim, body_len);
64882 + sys_write(wfd, (char __force_user *)victim, body_len);
64883 sys_close(wfd);
64884 - do_utime(vcollected, mtime);
64885 + do_utime((char __force_user *)vcollected, mtime);
64886 kfree(vcollected);
64887 eat(body_len);
64888 state = SkipIt;
64889 return 0;
64890 } else {
64891 - sys_write(wfd, victim, count);
64892 + sys_write(wfd, (char __force_user *)victim, count);
64893 body_len -= count;
64894 eat(count);
64895 return 1;
64896 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
64897 {
64898 collected[N_ALIGN(name_len) + body_len] = '\0';
64899 clean_path(collected, 0);
64900 - sys_symlink(collected + N_ALIGN(name_len), collected);
64901 - sys_lchown(collected, uid, gid);
64902 - do_utime(collected, mtime);
64903 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64904 + sys_lchown((char __force_user *)collected, uid, gid);
64905 + do_utime((char __force_user *)collected, mtime);
64906 state = SkipIt;
64907 next_state = Reset;
64908 return 0;
64909 diff --git a/init/main.c b/init/main.c
64910 index 03b408d..5777f59 100644
64911 --- a/init/main.c
64912 +++ b/init/main.c
64913 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
64914 extern void tc_init(void);
64915 #endif
64916
64917 +extern void grsecurity_init(void);
64918 +
64919 /*
64920 * Debug helper: via this flag we know that we are in 'early bootup code'
64921 * where only the boot processor is running with IRQ disabled. This means
64922 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
64923
64924 __setup("reset_devices", set_reset_devices);
64925
64926 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
64927 +extern char pax_enter_kernel_user[];
64928 +extern char pax_exit_kernel_user[];
64929 +extern pgdval_t clone_pgd_mask;
64930 +#endif
64931 +
64932 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
64933 +static int __init setup_pax_nouderef(char *str)
64934 +{
64935 +#ifdef CONFIG_X86_32
64936 + unsigned int cpu;
64937 + struct desc_struct *gdt;
64938 +
64939 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
64940 + gdt = get_cpu_gdt_table(cpu);
64941 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
64942 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
64943 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
64944 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
64945 + }
64946 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
64947 +#else
64948 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
64949 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
64950 + clone_pgd_mask = ~(pgdval_t)0UL;
64951 +#endif
64952 +
64953 + return 0;
64954 +}
64955 +early_param("pax_nouderef", setup_pax_nouderef);
64956 +#endif
64957 +
64958 +#ifdef CONFIG_PAX_SOFTMODE
64959 +int pax_softmode;
64960 +
64961 +static int __init setup_pax_softmode(char *str)
64962 +{
64963 + get_option(&str, &pax_softmode);
64964 + return 1;
64965 +}
64966 +__setup("pax_softmode=", setup_pax_softmode);
64967 +#endif
64968 +
64969 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
64970 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
64971 static const char *panic_later, *panic_param;
64972 @@ -678,6 +723,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
64973 {
64974 int count = preempt_count();
64975 int ret;
64976 + const char *msg1 = "", *msg2 = "";
64977
64978 if (initcall_debug)
64979 ret = do_one_initcall_debug(fn);
64980 @@ -690,15 +736,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
64981 sprintf(msgbuf, "error code %d ", ret);
64982
64983 if (preempt_count() != count) {
64984 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
64985 + msg1 = " preemption imbalance";
64986 preempt_count() = count;
64987 }
64988 if (irqs_disabled()) {
64989 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
64990 + msg2 = " disabled interrupts";
64991 local_irq_enable();
64992 }
64993 - if (msgbuf[0]) {
64994 - printk("initcall %pF returned with %s\n", fn, msgbuf);
64995 + if (msgbuf[0] || *msg1 || *msg2) {
64996 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
64997 }
64998
64999 return ret;
65000 @@ -817,7 +863,7 @@ static int __init kernel_init(void * unused)
65001 do_basic_setup();
65002
65003 /* Open the /dev/console on the rootfs, this should never fail */
65004 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65005 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65006 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65007
65008 (void) sys_dup(0);
65009 @@ -830,11 +876,13 @@ static int __init kernel_init(void * unused)
65010 if (!ramdisk_execute_command)
65011 ramdisk_execute_command = "/init";
65012
65013 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65014 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65015 ramdisk_execute_command = NULL;
65016 prepare_namespace();
65017 }
65018
65019 + grsecurity_init();
65020 +
65021 /*
65022 * Ok, we have completed the initial bootup, and
65023 * we're essentially up and running. Get rid of the
65024 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65025 index ed049ea..6442f7f 100644
65026 --- a/ipc/mqueue.c
65027 +++ b/ipc/mqueue.c
65028 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65029 mq_bytes = (mq_msg_tblsz +
65030 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
65031
65032 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65033 spin_lock(&mq_lock);
65034 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65035 u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
65036 diff --git a/ipc/msg.c b/ipc/msg.c
65037 index 7385de2..a8180e0 100644
65038 --- a/ipc/msg.c
65039 +++ b/ipc/msg.c
65040 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65041 return security_msg_queue_associate(msq, msgflg);
65042 }
65043
65044 +static struct ipc_ops msg_ops = {
65045 + .getnew = newque,
65046 + .associate = msg_security,
65047 + .more_checks = NULL
65048 +};
65049 +
65050 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65051 {
65052 struct ipc_namespace *ns;
65053 - struct ipc_ops msg_ops;
65054 struct ipc_params msg_params;
65055
65056 ns = current->nsproxy->ipc_ns;
65057
65058 - msg_ops.getnew = newque;
65059 - msg_ops.associate = msg_security;
65060 - msg_ops.more_checks = NULL;
65061 -
65062 msg_params.key = key;
65063 msg_params.flg = msgflg;
65064
65065 diff --git a/ipc/sem.c b/ipc/sem.c
65066 index c8e00f8..1135c4e 100644
65067 --- a/ipc/sem.c
65068 +++ b/ipc/sem.c
65069 @@ -318,10 +318,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65070 return 0;
65071 }
65072
65073 +static struct ipc_ops sem_ops = {
65074 + .getnew = newary,
65075 + .associate = sem_security,
65076 + .more_checks = sem_more_checks
65077 +};
65078 +
65079 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65080 {
65081 struct ipc_namespace *ns;
65082 - struct ipc_ops sem_ops;
65083 struct ipc_params sem_params;
65084
65085 ns = current->nsproxy->ipc_ns;
65086 @@ -329,10 +334,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65087 if (nsems < 0 || nsems > ns->sc_semmsl)
65088 return -EINVAL;
65089
65090 - sem_ops.getnew = newary;
65091 - sem_ops.associate = sem_security;
65092 - sem_ops.more_checks = sem_more_checks;
65093 -
65094 sem_params.key = key;
65095 sem_params.flg = semflg;
65096 sem_params.u.nsems = nsems;
65097 @@ -848,6 +849,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
65098 int nsems;
65099 struct list_head tasks;
65100
65101 + pax_track_stack();
65102 +
65103 sma = sem_lock_check(ns, semid);
65104 if (IS_ERR(sma))
65105 return PTR_ERR(sma);
65106 @@ -1295,6 +1298,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
65107 struct ipc_namespace *ns;
65108 struct list_head tasks;
65109
65110 + pax_track_stack();
65111 +
65112 ns = current->nsproxy->ipc_ns;
65113
65114 if (nsops < 1 || semid < 0)
65115 diff --git a/ipc/shm.c b/ipc/shm.c
65116 index 02ecf2c..c8f5627 100644
65117 --- a/ipc/shm.c
65118 +++ b/ipc/shm.c
65119 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65120 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65121 #endif
65122
65123 +#ifdef CONFIG_GRKERNSEC
65124 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65125 + const time_t shm_createtime, const uid_t cuid,
65126 + const int shmid);
65127 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65128 + const time_t shm_createtime);
65129 +#endif
65130 +
65131 void shm_init_ns(struct ipc_namespace *ns)
65132 {
65133 ns->shm_ctlmax = SHMMAX;
65134 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65135 shp->shm_lprid = 0;
65136 shp->shm_atim = shp->shm_dtim = 0;
65137 shp->shm_ctim = get_seconds();
65138 +#ifdef CONFIG_GRKERNSEC
65139 + {
65140 + struct timespec timeval;
65141 + do_posix_clock_monotonic_gettime(&timeval);
65142 +
65143 + shp->shm_createtime = timeval.tv_sec;
65144 + }
65145 +#endif
65146 shp->shm_segsz = size;
65147 shp->shm_nattch = 0;
65148 shp->shm_file = file;
65149 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65150 return 0;
65151 }
65152
65153 +static struct ipc_ops shm_ops = {
65154 + .getnew = newseg,
65155 + .associate = shm_security,
65156 + .more_checks = shm_more_checks
65157 +};
65158 +
65159 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65160 {
65161 struct ipc_namespace *ns;
65162 - struct ipc_ops shm_ops;
65163 struct ipc_params shm_params;
65164
65165 ns = current->nsproxy->ipc_ns;
65166
65167 - shm_ops.getnew = newseg;
65168 - shm_ops.associate = shm_security;
65169 - shm_ops.more_checks = shm_more_checks;
65170 -
65171 shm_params.key = key;
65172 shm_params.flg = shmflg;
65173 shm_params.u.size = size;
65174 @@ -870,8 +887,6 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)
65175 case SHM_LOCK:
65176 case SHM_UNLOCK:
65177 {
65178 - struct file *uninitialized_var(shm_file);
65179 -
65180 lru_add_drain_all(); /* drain pagevecs to lru lists */
65181
65182 shp = shm_lock_check(ns, shmid);
65183 @@ -1004,9 +1019,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65184 if (err)
65185 goto out_unlock;
65186
65187 +#ifdef CONFIG_GRKERNSEC
65188 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65189 + shp->shm_perm.cuid, shmid) ||
65190 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65191 + err = -EACCES;
65192 + goto out_unlock;
65193 + }
65194 +#endif
65195 +
65196 path = shp->shm_file->f_path;
65197 path_get(&path);
65198 shp->shm_nattch++;
65199 +#ifdef CONFIG_GRKERNSEC
65200 + shp->shm_lapid = current->pid;
65201 +#endif
65202 size = i_size_read(path.dentry->d_inode);
65203 shm_unlock(shp);
65204
65205 diff --git a/kernel/acct.c b/kernel/acct.c
65206 index fa7eb3d..7faf116 100644
65207 --- a/kernel/acct.c
65208 +++ b/kernel/acct.c
65209 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65210 */
65211 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65212 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65213 - file->f_op->write(file, (char *)&ac,
65214 + file->f_op->write(file, (char __force_user *)&ac,
65215 sizeof(acct_t), &file->f_pos);
65216 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65217 set_fs(fs);
65218 diff --git a/kernel/audit.c b/kernel/audit.c
65219 index 0a1355c..dca420f 100644
65220 --- a/kernel/audit.c
65221 +++ b/kernel/audit.c
65222 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65223 3) suppressed due to audit_rate_limit
65224 4) suppressed due to audit_backlog_limit
65225 */
65226 -static atomic_t audit_lost = ATOMIC_INIT(0);
65227 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65228
65229 /* The netlink socket. */
65230 static struct sock *audit_sock;
65231 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65232 unsigned long now;
65233 int print;
65234
65235 - atomic_inc(&audit_lost);
65236 + atomic_inc_unchecked(&audit_lost);
65237
65238 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65239
65240 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65241 printk(KERN_WARNING
65242 "audit: audit_lost=%d audit_rate_limit=%d "
65243 "audit_backlog_limit=%d\n",
65244 - atomic_read(&audit_lost),
65245 + atomic_read_unchecked(&audit_lost),
65246 audit_rate_limit,
65247 audit_backlog_limit);
65248 audit_panic(message);
65249 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65250 status_set.pid = audit_pid;
65251 status_set.rate_limit = audit_rate_limit;
65252 status_set.backlog_limit = audit_backlog_limit;
65253 - status_set.lost = atomic_read(&audit_lost);
65254 + status_set.lost = atomic_read_unchecked(&audit_lost);
65255 status_set.backlog = skb_queue_len(&audit_skb_queue);
65256 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65257 &status_set, sizeof(status_set));
65258 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65259 index ce4b054..8139ed7 100644
65260 --- a/kernel/auditsc.c
65261 +++ b/kernel/auditsc.c
65262 @@ -2118,7 +2118,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65263 }
65264
65265 /* global counter which is incremented every time something logs in */
65266 -static atomic_t session_id = ATOMIC_INIT(0);
65267 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65268
65269 /**
65270 * audit_set_loginuid - set a task's audit_context loginuid
65271 @@ -2131,7 +2131,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
65272 */
65273 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
65274 {
65275 - unsigned int sessionid = atomic_inc_return(&session_id);
65276 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
65277 struct audit_context *context = task->audit_context;
65278
65279 if (context && context->in_syscall) {
65280 diff --git a/kernel/capability.c b/kernel/capability.c
65281 index 283c529..36ac81e 100644
65282 --- a/kernel/capability.c
65283 +++ b/kernel/capability.c
65284 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65285 * before modification is attempted and the application
65286 * fails.
65287 */
65288 + if (tocopy > ARRAY_SIZE(kdata))
65289 + return -EFAULT;
65290 +
65291 if (copy_to_user(dataptr, kdata, tocopy
65292 * sizeof(struct __user_cap_data_struct))) {
65293 return -EFAULT;
65294 @@ -374,7 +377,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65295 BUG();
65296 }
65297
65298 - if (security_capable(ns, current_cred(), cap) == 0) {
65299 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
65300 current->flags |= PF_SUPERPRIV;
65301 return true;
65302 }
65303 @@ -382,6 +385,27 @@ bool ns_capable(struct user_namespace *ns, int cap)
65304 }
65305 EXPORT_SYMBOL(ns_capable);
65306
65307 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
65308 +{
65309 + if (unlikely(!cap_valid(cap))) {
65310 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65311 + BUG();
65312 + }
65313 +
65314 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
65315 + current->flags |= PF_SUPERPRIV;
65316 + return true;
65317 + }
65318 + return false;
65319 +}
65320 +EXPORT_SYMBOL(ns_capable_nolog);
65321 +
65322 +bool capable_nolog(int cap)
65323 +{
65324 + return ns_capable_nolog(&init_user_ns, cap);
65325 +}
65326 +EXPORT_SYMBOL(capable_nolog);
65327 +
65328 /**
65329 * task_ns_capable - Determine whether current task has a superior
65330 * capability targeted at a specific task's user namespace.
65331 @@ -396,6 +420,12 @@ bool task_ns_capable(struct task_struct *t, int cap)
65332 }
65333 EXPORT_SYMBOL(task_ns_capable);
65334
65335 +bool task_ns_capable_nolog(struct task_struct *t, int cap)
65336 +{
65337 + return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
65338 +}
65339 +EXPORT_SYMBOL(task_ns_capable_nolog);
65340 +
65341 /**
65342 * nsown_capable - Check superior capability to one's own user_ns
65343 * @cap: The capability in question
65344 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
65345 index b7ab0b8..b3a88d2 100644
65346 --- a/kernel/cgroup.c
65347 +++ b/kernel/cgroup.c
65348 @@ -595,6 +595,8 @@ static struct css_set *find_css_set(
65349 struct hlist_head *hhead;
65350 struct cg_cgroup_link *link;
65351
65352 + pax_track_stack();
65353 +
65354 /* First see if we already have a cgroup group that matches
65355 * the desired set */
65356 read_lock(&css_set_lock);
65357 diff --git a/kernel/compat.c b/kernel/compat.c
65358 index e2435ee..8e82199 100644
65359 --- a/kernel/compat.c
65360 +++ b/kernel/compat.c
65361 @@ -13,6 +13,7 @@
65362
65363 #include <linux/linkage.h>
65364 #include <linux/compat.h>
65365 +#include <linux/module.h>
65366 #include <linux/errno.h>
65367 #include <linux/time.h>
65368 #include <linux/signal.h>
65369 @@ -167,7 +168,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65370 mm_segment_t oldfs;
65371 long ret;
65372
65373 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65374 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65375 oldfs = get_fs();
65376 set_fs(KERNEL_DS);
65377 ret = hrtimer_nanosleep_restart(restart);
65378 @@ -199,7 +200,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65379 oldfs = get_fs();
65380 set_fs(KERNEL_DS);
65381 ret = hrtimer_nanosleep(&tu,
65382 - rmtp ? (struct timespec __user *)&rmt : NULL,
65383 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
65384 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65385 set_fs(oldfs);
65386
65387 @@ -308,7 +309,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65388 mm_segment_t old_fs = get_fs();
65389
65390 set_fs(KERNEL_DS);
65391 - ret = sys_sigpending((old_sigset_t __user *) &s);
65392 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
65393 set_fs(old_fs);
65394 if (ret == 0)
65395 ret = put_user(s, set);
65396 @@ -331,8 +332,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
65397 old_fs = get_fs();
65398 set_fs(KERNEL_DS);
65399 ret = sys_sigprocmask(how,
65400 - set ? (old_sigset_t __user *) &s : NULL,
65401 - oset ? (old_sigset_t __user *) &s : NULL);
65402 + set ? (old_sigset_t __force_user *) &s : NULL,
65403 + oset ? (old_sigset_t __force_user *) &s : NULL);
65404 set_fs(old_fs);
65405 if (ret == 0)
65406 if (oset)
65407 @@ -369,7 +370,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65408 mm_segment_t old_fs = get_fs();
65409
65410 set_fs(KERNEL_DS);
65411 - ret = sys_old_getrlimit(resource, &r);
65412 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65413 set_fs(old_fs);
65414
65415 if (!ret) {
65416 @@ -441,7 +442,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65417 mm_segment_t old_fs = get_fs();
65418
65419 set_fs(KERNEL_DS);
65420 - ret = sys_getrusage(who, (struct rusage __user *) &r);
65421 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65422 set_fs(old_fs);
65423
65424 if (ret)
65425 @@ -468,8 +469,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65426 set_fs (KERNEL_DS);
65427 ret = sys_wait4(pid,
65428 (stat_addr ?
65429 - (unsigned int __user *) &status : NULL),
65430 - options, (struct rusage __user *) &r);
65431 + (unsigned int __force_user *) &status : NULL),
65432 + options, (struct rusage __force_user *) &r);
65433 set_fs (old_fs);
65434
65435 if (ret > 0) {
65436 @@ -494,8 +495,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65437 memset(&info, 0, sizeof(info));
65438
65439 set_fs(KERNEL_DS);
65440 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65441 - uru ? (struct rusage __user *)&ru : NULL);
65442 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65443 + uru ? (struct rusage __force_user *)&ru : NULL);
65444 set_fs(old_fs);
65445
65446 if ((ret < 0) || (info.si_signo == 0))
65447 @@ -625,8 +626,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65448 oldfs = get_fs();
65449 set_fs(KERNEL_DS);
65450 err = sys_timer_settime(timer_id, flags,
65451 - (struct itimerspec __user *) &newts,
65452 - (struct itimerspec __user *) &oldts);
65453 + (struct itimerspec __force_user *) &newts,
65454 + (struct itimerspec __force_user *) &oldts);
65455 set_fs(oldfs);
65456 if (!err && old && put_compat_itimerspec(old, &oldts))
65457 return -EFAULT;
65458 @@ -643,7 +644,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65459 oldfs = get_fs();
65460 set_fs(KERNEL_DS);
65461 err = sys_timer_gettime(timer_id,
65462 - (struct itimerspec __user *) &ts);
65463 + (struct itimerspec __force_user *) &ts);
65464 set_fs(oldfs);
65465 if (!err && put_compat_itimerspec(setting, &ts))
65466 return -EFAULT;
65467 @@ -662,7 +663,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65468 oldfs = get_fs();
65469 set_fs(KERNEL_DS);
65470 err = sys_clock_settime(which_clock,
65471 - (struct timespec __user *) &ts);
65472 + (struct timespec __force_user *) &ts);
65473 set_fs(oldfs);
65474 return err;
65475 }
65476 @@ -677,7 +678,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65477 oldfs = get_fs();
65478 set_fs(KERNEL_DS);
65479 err = sys_clock_gettime(which_clock,
65480 - (struct timespec __user *) &ts);
65481 + (struct timespec __force_user *) &ts);
65482 set_fs(oldfs);
65483 if (!err && put_compat_timespec(&ts, tp))
65484 return -EFAULT;
65485 @@ -697,7 +698,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65486
65487 oldfs = get_fs();
65488 set_fs(KERNEL_DS);
65489 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65490 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65491 set_fs(oldfs);
65492
65493 err = compat_put_timex(utp, &txc);
65494 @@ -717,7 +718,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65495 oldfs = get_fs();
65496 set_fs(KERNEL_DS);
65497 err = sys_clock_getres(which_clock,
65498 - (struct timespec __user *) &ts);
65499 + (struct timespec __force_user *) &ts);
65500 set_fs(oldfs);
65501 if (!err && tp && put_compat_timespec(&ts, tp))
65502 return -EFAULT;
65503 @@ -729,9 +730,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65504 long err;
65505 mm_segment_t oldfs;
65506 struct timespec tu;
65507 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65508 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65509
65510 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65511 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65512 oldfs = get_fs();
65513 set_fs(KERNEL_DS);
65514 err = clock_nanosleep_restart(restart);
65515 @@ -763,8 +764,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65516 oldfs = get_fs();
65517 set_fs(KERNEL_DS);
65518 err = sys_clock_nanosleep(which_clock, flags,
65519 - (struct timespec __user *) &in,
65520 - (struct timespec __user *) &out);
65521 + (struct timespec __force_user *) &in,
65522 + (struct timespec __force_user *) &out);
65523 set_fs(oldfs);
65524
65525 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65526 diff --git a/kernel/configs.c b/kernel/configs.c
65527 index 42e8fa0..9e7406b 100644
65528 --- a/kernel/configs.c
65529 +++ b/kernel/configs.c
65530 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65531 struct proc_dir_entry *entry;
65532
65533 /* create the current config file */
65534 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65535 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65536 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65537 + &ikconfig_file_ops);
65538 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65539 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65540 + &ikconfig_file_ops);
65541 +#endif
65542 +#else
65543 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65544 &ikconfig_file_ops);
65545 +#endif
65546 +
65547 if (!entry)
65548 return -ENOMEM;
65549
65550 diff --git a/kernel/cred.c b/kernel/cred.c
65551 index 8ef31f5..b5620e6 100644
65552 --- a/kernel/cred.c
65553 +++ b/kernel/cred.c
65554 @@ -158,6 +158,8 @@ static void put_cred_rcu(struct rcu_head *rcu)
65555 */
65556 void __put_cred(struct cred *cred)
65557 {
65558 + pax_track_stack();
65559 +
65560 kdebug("__put_cred(%p{%d,%d})", cred,
65561 atomic_read(&cred->usage),
65562 read_cred_subscribers(cred));
65563 @@ -182,6 +184,8 @@ void exit_creds(struct task_struct *tsk)
65564 {
65565 struct cred *cred;
65566
65567 + pax_track_stack();
65568 +
65569 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
65570 atomic_read(&tsk->cred->usage),
65571 read_cred_subscribers(tsk->cred));
65572 @@ -220,6 +224,8 @@ const struct cred *get_task_cred(struct task_struct *task)
65573 {
65574 const struct cred *cred;
65575
65576 + pax_track_stack();
65577 +
65578 rcu_read_lock();
65579
65580 do {
65581 @@ -239,6 +245,8 @@ struct cred *cred_alloc_blank(void)
65582 {
65583 struct cred *new;
65584
65585 + pax_track_stack();
65586 +
65587 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
65588 if (!new)
65589 return NULL;
65590 @@ -281,13 +289,15 @@ error:
65591 *
65592 * Call commit_creds() or abort_creds() to clean up.
65593 */
65594 -struct cred *prepare_creds(void)
65595 +
65596 +static struct cred *__prepare_creds(struct task_struct *task)
65597 {
65598 - struct task_struct *task = current;
65599 const struct cred *old;
65600 struct cred *new;
65601
65602 - validate_process_creds();
65603 + pax_track_stack();
65604 +
65605 + validate_task_creds(task);
65606
65607 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
65608 if (!new)
65609 @@ -322,6 +332,11 @@ error:
65610 abort_creds(new);
65611 return NULL;
65612 }
65613 +
65614 +struct cred *prepare_creds(void)
65615 +{
65616 + return __prepare_creds(current);
65617 +}
65618 EXPORT_SYMBOL(prepare_creds);
65619
65620 /*
65621 @@ -333,6 +348,8 @@ struct cred *prepare_exec_creds(void)
65622 struct thread_group_cred *tgcred = NULL;
65623 struct cred *new;
65624
65625 + pax_track_stack();
65626 +
65627 #ifdef CONFIG_KEYS
65628 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
65629 if (!tgcred)
65630 @@ -385,6 +402,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
65631 struct cred *new;
65632 int ret;
65633
65634 + pax_track_stack();
65635 +
65636 if (
65637 #ifdef CONFIG_KEYS
65638 !p->cred->thread_keyring &&
65639 @@ -470,11 +489,12 @@ error_put:
65640 * Always returns 0 thus allowing this function to be tail-called at the end
65641 * of, say, sys_setgid().
65642 */
65643 -int commit_creds(struct cred *new)
65644 +static int __commit_creds(struct task_struct *task, struct cred *new)
65645 {
65646 - struct task_struct *task = current;
65647 const struct cred *old = task->real_cred;
65648
65649 + pax_track_stack();
65650 +
65651 kdebug("commit_creds(%p{%d,%d})", new,
65652 atomic_read(&new->usage),
65653 read_cred_subscribers(new));
65654 @@ -489,6 +509,8 @@ int commit_creds(struct cred *new)
65655
65656 get_cred(new); /* we will require a ref for the subj creds too */
65657
65658 + gr_set_role_label(task, new->uid, new->gid);
65659 +
65660 /* dumpability changes */
65661 if (old->euid != new->euid ||
65662 old->egid != new->egid ||
65663 @@ -538,6 +560,64 @@ int commit_creds(struct cred *new)
65664 put_cred(old);
65665 return 0;
65666 }
65667 +
65668 +int commit_creds(struct cred *new)
65669 +{
65670 +#ifdef CONFIG_GRKERNSEC_SETXID
65671 + struct task_struct *t;
65672 + struct cred *ncred;
65673 + const struct cred *old;
65674 +
65675 + if (grsec_enable_setxid && !current_is_single_threaded() &&
65676 + !current_uid() && new->uid) {
65677 + rcu_read_lock();
65678 + read_lock(&tasklist_lock);
65679 + for (t = next_thread(current); t != current;
65680 + t = next_thread(t)) {
65681 + old = __task_cred(t);
65682 + if (old->uid)
65683 + continue;
65684 + ncred = __prepare_creds(t);
65685 + if (!ncred)
65686 + goto die;
65687 + // uids
65688 + ncred->uid = new->uid;
65689 + ncred->euid = new->euid;
65690 + ncred->suid = new->suid;
65691 + ncred->fsuid = new->fsuid;
65692 + // gids
65693 + ncred->gid = new->gid;
65694 + ncred->egid = new->egid;
65695 + ncred->sgid = new->sgid;
65696 + ncred->fsgid = new->fsgid;
65697 + // groups
65698 + if (set_groups(ncred, new->group_info) < 0) {
65699 + abort_creds(ncred);
65700 + goto die;
65701 + }
65702 + // caps
65703 + ncred->securebits = new->securebits;
65704 + ncred->cap_inheritable = new->cap_inheritable;
65705 + ncred->cap_permitted = new->cap_permitted;
65706 + ncred->cap_effective = new->cap_effective;
65707 + ncred->cap_bset = new->cap_bset;
65708 +
65709 + __commit_creds(t, ncred);
65710 + }
65711 + read_unlock(&tasklist_lock);
65712 + rcu_read_unlock();
65713 + }
65714 +#endif
65715 + return __commit_creds(current, new);
65716 +#ifdef CONFIG_GRKERNSEC_SETXID
65717 +die:
65718 + read_unlock(&tasklist_lock);
65719 + rcu_read_unlock();
65720 + abort_creds(new);
65721 + do_group_exit(SIGKILL);
65722 +#endif
65723 +}
65724 +
65725 EXPORT_SYMBOL(commit_creds);
65726
65727 /**
65728 @@ -549,6 +629,8 @@ EXPORT_SYMBOL(commit_creds);
65729 */
65730 void abort_creds(struct cred *new)
65731 {
65732 + pax_track_stack();
65733 +
65734 kdebug("abort_creds(%p{%d,%d})", new,
65735 atomic_read(&new->usage),
65736 read_cred_subscribers(new));
65737 @@ -572,6 +654,8 @@ const struct cred *override_creds(const struct cred *new)
65738 {
65739 const struct cred *old = current->cred;
65740
65741 + pax_track_stack();
65742 +
65743 kdebug("override_creds(%p{%d,%d})", new,
65744 atomic_read(&new->usage),
65745 read_cred_subscribers(new));
65746 @@ -601,6 +685,8 @@ void revert_creds(const struct cred *old)
65747 {
65748 const struct cred *override = current->cred;
65749
65750 + pax_track_stack();
65751 +
65752 kdebug("revert_creds(%p{%d,%d})", old,
65753 atomic_read(&old->usage),
65754 read_cred_subscribers(old));
65755 @@ -647,6 +733,8 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
65756 const struct cred *old;
65757 struct cred *new;
65758
65759 + pax_track_stack();
65760 +
65761 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
65762 if (!new)
65763 return NULL;
65764 @@ -701,6 +789,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
65765 */
65766 int set_security_override(struct cred *new, u32 secid)
65767 {
65768 + pax_track_stack();
65769 +
65770 return security_kernel_act_as(new, secid);
65771 }
65772 EXPORT_SYMBOL(set_security_override);
65773 @@ -720,6 +810,8 @@ int set_security_override_from_ctx(struct cred *new, const char *secctx)
65774 u32 secid;
65775 int ret;
65776
65777 + pax_track_stack();
65778 +
65779 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
65780 if (ret < 0)
65781 return ret;
65782 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65783 index 0d7c087..01b8cef 100644
65784 --- a/kernel/debug/debug_core.c
65785 +++ b/kernel/debug/debug_core.c
65786 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65787 */
65788 static atomic_t masters_in_kgdb;
65789 static atomic_t slaves_in_kgdb;
65790 -static atomic_t kgdb_break_tasklet_var;
65791 +static atomic_unchecked_t kgdb_break_tasklet_var;
65792 atomic_t kgdb_setting_breakpoint;
65793
65794 struct task_struct *kgdb_usethread;
65795 @@ -129,7 +129,7 @@ int kgdb_single_step;
65796 static pid_t kgdb_sstep_pid;
65797
65798 /* to keep track of the CPU which is doing the single stepping*/
65799 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65800 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65801
65802 /*
65803 * If you are debugging a problem where roundup (the collection of
65804 @@ -542,7 +542,7 @@ return_normal:
65805 * kernel will only try for the value of sstep_tries before
65806 * giving up and continuing on.
65807 */
65808 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65809 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65810 (kgdb_info[cpu].task &&
65811 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65812 atomic_set(&kgdb_active, -1);
65813 @@ -636,8 +636,8 @@ cpu_master_loop:
65814 }
65815
65816 kgdb_restore:
65817 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65818 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65819 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65820 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65821 if (kgdb_info[sstep_cpu].task)
65822 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65823 else
65824 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(void)
65825 static void kgdb_tasklet_bpt(unsigned long ing)
65826 {
65827 kgdb_breakpoint();
65828 - atomic_set(&kgdb_break_tasklet_var, 0);
65829 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65830 }
65831
65832 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65833
65834 void kgdb_schedule_breakpoint(void)
65835 {
65836 - if (atomic_read(&kgdb_break_tasklet_var) ||
65837 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65838 atomic_read(&kgdb_active) != -1 ||
65839 atomic_read(&kgdb_setting_breakpoint))
65840 return;
65841 - atomic_inc(&kgdb_break_tasklet_var);
65842 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
65843 tasklet_schedule(&kgdb_tasklet_breakpoint);
65844 }
65845 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65846 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65847 index 63786e7..0780cac 100644
65848 --- a/kernel/debug/kdb/kdb_main.c
65849 +++ b/kernel/debug/kdb/kdb_main.c
65850 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
65851 list_for_each_entry(mod, kdb_modules, list) {
65852
65853 kdb_printf("%-20s%8u 0x%p ", mod->name,
65854 - mod->core_size, (void *)mod);
65855 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
65856 #ifdef CONFIG_MODULE_UNLOAD
65857 kdb_printf("%4d ", module_refcount(mod));
65858 #endif
65859 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
65860 kdb_printf(" (Loading)");
65861 else
65862 kdb_printf(" (Live)");
65863 - kdb_printf(" 0x%p", mod->module_core);
65864 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65865
65866 #ifdef CONFIG_MODULE_UNLOAD
65867 {
65868 diff --git a/kernel/events/core.c b/kernel/events/core.c
65869 index 0f85778..0d43716 100644
65870 --- a/kernel/events/core.c
65871 +++ b/kernel/events/core.c
65872 @@ -172,7 +172,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65873 return 0;
65874 }
65875
65876 -static atomic64_t perf_event_id;
65877 +static atomic64_unchecked_t perf_event_id;
65878
65879 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65880 enum event_type_t event_type);
65881 @@ -2535,7 +2535,7 @@ static void __perf_event_read(void *info)
65882
65883 static inline u64 perf_event_count(struct perf_event *event)
65884 {
65885 - return local64_read(&event->count) + atomic64_read(&event->child_count);
65886 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65887 }
65888
65889 static u64 perf_event_read(struct perf_event *event)
65890 @@ -3060,9 +3060,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65891 mutex_lock(&event->child_mutex);
65892 total += perf_event_read(event);
65893 *enabled += event->total_time_enabled +
65894 - atomic64_read(&event->child_total_time_enabled);
65895 + atomic64_read_unchecked(&event->child_total_time_enabled);
65896 *running += event->total_time_running +
65897 - atomic64_read(&event->child_total_time_running);
65898 + atomic64_read_unchecked(&event->child_total_time_running);
65899
65900 list_for_each_entry(child, &event->child_list, child_list) {
65901 total += perf_event_read(child);
65902 @@ -3448,10 +3448,10 @@ void perf_event_update_userpage(struct perf_event *event)
65903 userpg->offset -= local64_read(&event->hw.prev_count);
65904
65905 userpg->time_enabled = enabled +
65906 - atomic64_read(&event->child_total_time_enabled);
65907 + atomic64_read_unchecked(&event->child_total_time_enabled);
65908
65909 userpg->time_running = running +
65910 - atomic64_read(&event->child_total_time_running);
65911 + atomic64_read_unchecked(&event->child_total_time_running);
65912
65913 barrier();
65914 ++userpg->lock;
65915 @@ -3822,11 +3822,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65916 values[n++] = perf_event_count(event);
65917 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65918 values[n++] = enabled +
65919 - atomic64_read(&event->child_total_time_enabled);
65920 + atomic64_read_unchecked(&event->child_total_time_enabled);
65921 }
65922 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65923 values[n++] = running +
65924 - atomic64_read(&event->child_total_time_running);
65925 + atomic64_read_unchecked(&event->child_total_time_running);
65926 }
65927 if (read_format & PERF_FORMAT_ID)
65928 values[n++] = primary_event_id(event);
65929 @@ -4477,12 +4477,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65930 * need to add enough zero bytes after the string to handle
65931 * the 64bit alignment we do later.
65932 */
65933 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65934 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
65935 if (!buf) {
65936 name = strncpy(tmp, "//enomem", sizeof(tmp));
65937 goto got_name;
65938 }
65939 - name = d_path(&file->f_path, buf, PATH_MAX);
65940 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65941 if (IS_ERR(name)) {
65942 name = strncpy(tmp, "//toolong", sizeof(tmp));
65943 goto got_name;
65944 @@ -5833,7 +5833,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65945 event->parent = parent_event;
65946
65947 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65948 - event->id = atomic64_inc_return(&perf_event_id);
65949 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
65950
65951 event->state = PERF_EVENT_STATE_INACTIVE;
65952
65953 @@ -6355,10 +6355,10 @@ static void sync_child_event(struct perf_event *child_event,
65954 /*
65955 * Add back the child's count to the parent's count:
65956 */
65957 - atomic64_add(child_val, &parent_event->child_count);
65958 - atomic64_add(child_event->total_time_enabled,
65959 + atomic64_add_unchecked(child_val, &parent_event->child_count);
65960 + atomic64_add_unchecked(child_event->total_time_enabled,
65961 &parent_event->child_total_time_enabled);
65962 - atomic64_add(child_event->total_time_running,
65963 + atomic64_add_unchecked(child_event->total_time_running,
65964 &parent_event->child_total_time_running);
65965
65966 /*
65967 diff --git a/kernel/exit.c b/kernel/exit.c
65968 index 9e316ae..b3656d5 100644
65969 --- a/kernel/exit.c
65970 +++ b/kernel/exit.c
65971 @@ -57,6 +57,10 @@
65972 #include <asm/pgtable.h>
65973 #include <asm/mmu_context.h>
65974
65975 +#ifdef CONFIG_GRKERNSEC
65976 +extern rwlock_t grsec_exec_file_lock;
65977 +#endif
65978 +
65979 static void exit_mm(struct task_struct * tsk);
65980
65981 static void __unhash_process(struct task_struct *p, bool group_dead)
65982 @@ -168,6 +172,10 @@ void release_task(struct task_struct * p)
65983 struct task_struct *leader;
65984 int zap_leader;
65985 repeat:
65986 +#ifdef CONFIG_NET
65987 + gr_del_task_from_ip_table(p);
65988 +#endif
65989 +
65990 /* don't need to get the RCU readlock here - the process is dead and
65991 * can't be modifying its own credentials. But shut RCU-lockdep up */
65992 rcu_read_lock();
65993 @@ -380,7 +388,7 @@ int allow_signal(int sig)
65994 * know it'll be handled, so that they don't get converted to
65995 * SIGKILL or just silently dropped.
65996 */
65997 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65998 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65999 recalc_sigpending();
66000 spin_unlock_irq(&current->sighand->siglock);
66001 return 0;
66002 @@ -416,6 +424,17 @@ void daemonize(const char *name, ...)
66003 vsnprintf(current->comm, sizeof(current->comm), name, args);
66004 va_end(args);
66005
66006 +#ifdef CONFIG_GRKERNSEC
66007 + write_lock(&grsec_exec_file_lock);
66008 + if (current->exec_file) {
66009 + fput(current->exec_file);
66010 + current->exec_file = NULL;
66011 + }
66012 + write_unlock(&grsec_exec_file_lock);
66013 +#endif
66014 +
66015 + gr_set_kernel_label(current);
66016 +
66017 /*
66018 * If we were started as result of loading a module, close all of the
66019 * user space pages. We don't need them, and if we didn't close them
66020 @@ -895,6 +914,8 @@ NORET_TYPE void do_exit(long code)
66021 struct task_struct *tsk = current;
66022 int group_dead;
66023
66024 + set_fs(USER_DS);
66025 +
66026 profile_task_exit(tsk);
66027
66028 WARN_ON(blk_needs_flush_plug(tsk));
66029 @@ -911,7 +932,6 @@ NORET_TYPE void do_exit(long code)
66030 * mm_release()->clear_child_tid() from writing to a user-controlled
66031 * kernel address.
66032 */
66033 - set_fs(USER_DS);
66034
66035 ptrace_event(PTRACE_EVENT_EXIT, code);
66036
66037 @@ -973,6 +993,9 @@ NORET_TYPE void do_exit(long code)
66038 tsk->exit_code = code;
66039 taskstats_exit(tsk, group_dead);
66040
66041 + gr_acl_handle_psacct(tsk, code);
66042 + gr_acl_handle_exit();
66043 +
66044 exit_mm(tsk);
66045
66046 if (group_dead)
66047 diff --git a/kernel/fork.c b/kernel/fork.c
66048 index 8e6b6f4..9dccf00 100644
66049 --- a/kernel/fork.c
66050 +++ b/kernel/fork.c
66051 @@ -285,7 +285,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66052 *stackend = STACK_END_MAGIC; /* for overflow detection */
66053
66054 #ifdef CONFIG_CC_STACKPROTECTOR
66055 - tsk->stack_canary = get_random_int();
66056 + tsk->stack_canary = pax_get_random_long();
66057 #endif
66058
66059 /*
66060 @@ -309,13 +309,77 @@ out:
66061 }
66062
66063 #ifdef CONFIG_MMU
66064 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
66065 +{
66066 + struct vm_area_struct *tmp;
66067 + unsigned long charge;
66068 + struct mempolicy *pol;
66069 + struct file *file;
66070 +
66071 + charge = 0;
66072 + if (mpnt->vm_flags & VM_ACCOUNT) {
66073 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66074 + if (security_vm_enough_memory(len))
66075 + goto fail_nomem;
66076 + charge = len;
66077 + }
66078 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66079 + if (!tmp)
66080 + goto fail_nomem;
66081 + *tmp = *mpnt;
66082 + tmp->vm_mm = mm;
66083 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66084 + pol = mpol_dup(vma_policy(mpnt));
66085 + if (IS_ERR(pol))
66086 + goto fail_nomem_policy;
66087 + vma_set_policy(tmp, pol);
66088 + if (anon_vma_fork(tmp, mpnt))
66089 + goto fail_nomem_anon_vma_fork;
66090 + tmp->vm_flags &= ~VM_LOCKED;
66091 + tmp->vm_next = tmp->vm_prev = NULL;
66092 + tmp->vm_mirror = NULL;
66093 + file = tmp->vm_file;
66094 + if (file) {
66095 + struct inode *inode = file->f_path.dentry->d_inode;
66096 + struct address_space *mapping = file->f_mapping;
66097 +
66098 + get_file(file);
66099 + if (tmp->vm_flags & VM_DENYWRITE)
66100 + atomic_dec(&inode->i_writecount);
66101 + mutex_lock(&mapping->i_mmap_mutex);
66102 + if (tmp->vm_flags & VM_SHARED)
66103 + mapping->i_mmap_writable++;
66104 + flush_dcache_mmap_lock(mapping);
66105 + /* insert tmp into the share list, just after mpnt */
66106 + vma_prio_tree_add(tmp, mpnt);
66107 + flush_dcache_mmap_unlock(mapping);
66108 + mutex_unlock(&mapping->i_mmap_mutex);
66109 + }
66110 +
66111 + /*
66112 + * Clear hugetlb-related page reserves for children. This only
66113 + * affects MAP_PRIVATE mappings. Faults generated by the child
66114 + * are not guaranteed to succeed, even if read-only
66115 + */
66116 + if (is_vm_hugetlb_page(tmp))
66117 + reset_vma_resv_huge_pages(tmp);
66118 +
66119 + return tmp;
66120 +
66121 +fail_nomem_anon_vma_fork:
66122 + mpol_put(pol);
66123 +fail_nomem_policy:
66124 + kmem_cache_free(vm_area_cachep, tmp);
66125 +fail_nomem:
66126 + vm_unacct_memory(charge);
66127 + return NULL;
66128 +}
66129 +
66130 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66131 {
66132 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66133 struct rb_node **rb_link, *rb_parent;
66134 int retval;
66135 - unsigned long charge;
66136 - struct mempolicy *pol;
66137
66138 down_write(&oldmm->mmap_sem);
66139 flush_cache_dup_mm(oldmm);
66140 @@ -327,8 +391,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66141 mm->locked_vm = 0;
66142 mm->mmap = NULL;
66143 mm->mmap_cache = NULL;
66144 - mm->free_area_cache = oldmm->mmap_base;
66145 - mm->cached_hole_size = ~0UL;
66146 + mm->free_area_cache = oldmm->free_area_cache;
66147 + mm->cached_hole_size = oldmm->cached_hole_size;
66148 mm->map_count = 0;
66149 cpumask_clear(mm_cpumask(mm));
66150 mm->mm_rb = RB_ROOT;
66151 @@ -344,8 +408,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66152
66153 prev = NULL;
66154 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66155 - struct file *file;
66156 -
66157 if (mpnt->vm_flags & VM_DONTCOPY) {
66158 long pages = vma_pages(mpnt);
66159 mm->total_vm -= pages;
66160 @@ -353,53 +415,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66161 -pages);
66162 continue;
66163 }
66164 - charge = 0;
66165 - if (mpnt->vm_flags & VM_ACCOUNT) {
66166 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66167 - if (security_vm_enough_memory(len))
66168 - goto fail_nomem;
66169 - charge = len;
66170 + tmp = dup_vma(mm, mpnt);
66171 + if (!tmp) {
66172 + retval = -ENOMEM;
66173 + goto out;
66174 }
66175 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66176 - if (!tmp)
66177 - goto fail_nomem;
66178 - *tmp = *mpnt;
66179 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66180 - pol = mpol_dup(vma_policy(mpnt));
66181 - retval = PTR_ERR(pol);
66182 - if (IS_ERR(pol))
66183 - goto fail_nomem_policy;
66184 - vma_set_policy(tmp, pol);
66185 - tmp->vm_mm = mm;
66186 - if (anon_vma_fork(tmp, mpnt))
66187 - goto fail_nomem_anon_vma_fork;
66188 - tmp->vm_flags &= ~VM_LOCKED;
66189 - tmp->vm_next = tmp->vm_prev = NULL;
66190 - file = tmp->vm_file;
66191 - if (file) {
66192 - struct inode *inode = file->f_path.dentry->d_inode;
66193 - struct address_space *mapping = file->f_mapping;
66194 -
66195 - get_file(file);
66196 - if (tmp->vm_flags & VM_DENYWRITE)
66197 - atomic_dec(&inode->i_writecount);
66198 - mutex_lock(&mapping->i_mmap_mutex);
66199 - if (tmp->vm_flags & VM_SHARED)
66200 - mapping->i_mmap_writable++;
66201 - flush_dcache_mmap_lock(mapping);
66202 - /* insert tmp into the share list, just after mpnt */
66203 - vma_prio_tree_add(tmp, mpnt);
66204 - flush_dcache_mmap_unlock(mapping);
66205 - mutex_unlock(&mapping->i_mmap_mutex);
66206 - }
66207 -
66208 - /*
66209 - * Clear hugetlb-related page reserves for children. This only
66210 - * affects MAP_PRIVATE mappings. Faults generated by the child
66211 - * are not guaranteed to succeed, even if read-only
66212 - */
66213 - if (is_vm_hugetlb_page(tmp))
66214 - reset_vma_resv_huge_pages(tmp);
66215
66216 /*
66217 * Link in the new vma and copy the page table entries.
66218 @@ -422,6 +442,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66219 if (retval)
66220 goto out;
66221 }
66222 +
66223 +#ifdef CONFIG_PAX_SEGMEXEC
66224 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66225 + struct vm_area_struct *mpnt_m;
66226 +
66227 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66228 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66229 +
66230 + if (!mpnt->vm_mirror)
66231 + continue;
66232 +
66233 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66234 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66235 + mpnt->vm_mirror = mpnt_m;
66236 + } else {
66237 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66238 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66239 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66240 + mpnt->vm_mirror->vm_mirror = mpnt;
66241 + }
66242 + }
66243 + BUG_ON(mpnt_m);
66244 + }
66245 +#endif
66246 +
66247 /* a new mm has just been created */
66248 arch_dup_mmap(oldmm, mm);
66249 retval = 0;
66250 @@ -430,14 +475,6 @@ out:
66251 flush_tlb_mm(oldmm);
66252 up_write(&oldmm->mmap_sem);
66253 return retval;
66254 -fail_nomem_anon_vma_fork:
66255 - mpol_put(pol);
66256 -fail_nomem_policy:
66257 - kmem_cache_free(vm_area_cachep, tmp);
66258 -fail_nomem:
66259 - retval = -ENOMEM;
66260 - vm_unacct_memory(charge);
66261 - goto out;
66262 }
66263
66264 static inline int mm_alloc_pgd(struct mm_struct *mm)
66265 @@ -837,13 +874,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66266 spin_unlock(&fs->lock);
66267 return -EAGAIN;
66268 }
66269 - fs->users++;
66270 + atomic_inc(&fs->users);
66271 spin_unlock(&fs->lock);
66272 return 0;
66273 }
66274 tsk->fs = copy_fs_struct(fs);
66275 if (!tsk->fs)
66276 return -ENOMEM;
66277 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66278 return 0;
66279 }
66280
66281 @@ -1105,6 +1143,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66282 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66283 #endif
66284 retval = -EAGAIN;
66285 +
66286 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66287 +
66288 if (atomic_read(&p->real_cred->user->processes) >=
66289 task_rlimit(p, RLIMIT_NPROC)) {
66290 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66291 @@ -1264,6 +1305,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66292 if (clone_flags & CLONE_THREAD)
66293 p->tgid = current->tgid;
66294
66295 + gr_copy_label(p);
66296 +
66297 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
66298 /*
66299 * Clear TID on mm_release()?
66300 @@ -1428,6 +1471,8 @@ bad_fork_cleanup_count:
66301 bad_fork_free:
66302 free_task(p);
66303 fork_out:
66304 + gr_log_forkfail(retval);
66305 +
66306 return ERR_PTR(retval);
66307 }
66308
66309 @@ -1528,6 +1573,8 @@ long do_fork(unsigned long clone_flags,
66310 if (clone_flags & CLONE_PARENT_SETTID)
66311 put_user(nr, parent_tidptr);
66312
66313 + gr_handle_brute_check();
66314 +
66315 if (clone_flags & CLONE_VFORK) {
66316 p->vfork_done = &vfork;
66317 init_completion(&vfork);
66318 @@ -1637,7 +1684,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66319 return 0;
66320
66321 /* don't need lock here; in the worst case we'll do useless copy */
66322 - if (fs->users == 1)
66323 + if (atomic_read(&fs->users) == 1)
66324 return 0;
66325
66326 *new_fsp = copy_fs_struct(fs);
66327 @@ -1726,7 +1773,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66328 fs = current->fs;
66329 spin_lock(&fs->lock);
66330 current->fs = new_fs;
66331 - if (--fs->users)
66332 + gr_set_chroot_entries(current, &current->fs->root);
66333 + if (atomic_dec_return(&fs->users))
66334 new_fs = NULL;
66335 else
66336 new_fs = fs;
66337 diff --git a/kernel/futex.c b/kernel/futex.c
66338 index e6160fa..edf9565 100644
66339 --- a/kernel/futex.c
66340 +++ b/kernel/futex.c
66341 @@ -54,6 +54,7 @@
66342 #include <linux/mount.h>
66343 #include <linux/pagemap.h>
66344 #include <linux/syscalls.h>
66345 +#include <linux/ptrace.h>
66346 #include <linux/signal.h>
66347 #include <linux/module.h>
66348 #include <linux/magic.h>
66349 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66350 struct page *page, *page_head;
66351 int err, ro = 0;
66352
66353 +#ifdef CONFIG_PAX_SEGMEXEC
66354 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66355 + return -EFAULT;
66356 +#endif
66357 +
66358 /*
66359 * The futex address must be "naturally" aligned.
66360 */
66361 @@ -1875,6 +1881,8 @@ static int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val,
66362 struct futex_q q = futex_q_init;
66363 int ret;
66364
66365 + pax_track_stack();
66366 +
66367 if (!bitset)
66368 return -EINVAL;
66369 q.bitset = bitset;
66370 @@ -2271,6 +2279,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
66371 struct futex_q q = futex_q_init;
66372 int res, ret;
66373
66374 + pax_track_stack();
66375 +
66376 if (!bitset)
66377 return -EINVAL;
66378
66379 @@ -2459,6 +2469,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
66380 if (!p)
66381 goto err_unlock;
66382 ret = -EPERM;
66383 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66384 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
66385 + goto err_unlock;
66386 +#endif
66387 pcred = __task_cred(p);
66388 /* If victim is in different user_ns, then uids are not
66389 comparable, so we must have CAP_SYS_PTRACE */
66390 @@ -2724,6 +2738,7 @@ static int __init futex_init(void)
66391 {
66392 u32 curval;
66393 int i;
66394 + mm_segment_t oldfs;
66395
66396 /*
66397 * This will fail and we want it. Some arch implementations do
66398 @@ -2735,8 +2750,11 @@ static int __init futex_init(void)
66399 * implementation, the non-functional ones will return
66400 * -ENOSYS.
66401 */
66402 + oldfs = get_fs();
66403 + set_fs(USER_DS);
66404 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66405 futex_cmpxchg_enabled = 1;
66406 + set_fs(oldfs);
66407
66408 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66409 plist_head_init(&futex_queues[i].chain);
66410 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
66411 index 5f9e689..582d46d 100644
66412 --- a/kernel/futex_compat.c
66413 +++ b/kernel/futex_compat.c
66414 @@ -10,6 +10,7 @@
66415 #include <linux/compat.h>
66416 #include <linux/nsproxy.h>
66417 #include <linux/futex.h>
66418 +#include <linux/ptrace.h>
66419
66420 #include <asm/uaccess.h>
66421
66422 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
66423 {
66424 struct compat_robust_list_head __user *head;
66425 unsigned long ret;
66426 - const struct cred *cred = current_cred(), *pcred;
66427 + const struct cred *cred = current_cred();
66428 + const struct cred *pcred;
66429
66430 if (!futex_cmpxchg_enabled)
66431 return -ENOSYS;
66432 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
66433 if (!p)
66434 goto err_unlock;
66435 ret = -EPERM;
66436 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66437 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
66438 + goto err_unlock;
66439 +#endif
66440 pcred = __task_cred(p);
66441 /* If victim is in different user_ns, then uids are not
66442 comparable, so we must have CAP_SYS_PTRACE */
66443 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66444 index 9b22d03..6295b62 100644
66445 --- a/kernel/gcov/base.c
66446 +++ b/kernel/gcov/base.c
66447 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
66448 }
66449
66450 #ifdef CONFIG_MODULES
66451 -static inline int within(void *addr, void *start, unsigned long size)
66452 -{
66453 - return ((addr >= start) && (addr < start + size));
66454 -}
66455 -
66456 /* Update list and generate events when modules are unloaded. */
66457 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66458 void *data)
66459 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66460 prev = NULL;
66461 /* Remove entries located in module from linked list. */
66462 for (info = gcov_info_head; info; info = info->next) {
66463 - if (within(info, mod->module_core, mod->core_size)) {
66464 + if (within_module_core_rw((unsigned long)info, mod)) {
66465 if (prev)
66466 prev->next = info->next;
66467 else
66468 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66469 index 2043c08..ec81a69 100644
66470 --- a/kernel/hrtimer.c
66471 +++ b/kernel/hrtimer.c
66472 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
66473 local_irq_restore(flags);
66474 }
66475
66476 -static void run_hrtimer_softirq(struct softirq_action *h)
66477 +static void run_hrtimer_softirq(void)
66478 {
66479 hrtimer_peek_ahead_timers();
66480 }
66481 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66482 index e6f1f24..6c19597 100644
66483 --- a/kernel/jump_label.c
66484 +++ b/kernel/jump_label.c
66485 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66486
66487 size = (((unsigned long)stop - (unsigned long)start)
66488 / sizeof(struct jump_entry));
66489 + pax_open_kernel();
66490 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66491 + pax_close_kernel();
66492 }
66493
66494 static void jump_label_update(struct jump_label_key *key, int enable);
66495 @@ -298,10 +300,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66496 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66497 struct jump_entry *iter;
66498
66499 + pax_open_kernel();
66500 for (iter = iter_start; iter < iter_stop; iter++) {
66501 if (within_module_init(iter->code, mod))
66502 iter->code = 0;
66503 }
66504 + pax_close_kernel();
66505 }
66506
66507 static int
66508 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66509 index 079f1d3..a407562 100644
66510 --- a/kernel/kallsyms.c
66511 +++ b/kernel/kallsyms.c
66512 @@ -11,6 +11,9 @@
66513 * Changed the compression method from stem compression to "table lookup"
66514 * compression (see scripts/kallsyms.c for a more complete description)
66515 */
66516 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66517 +#define __INCLUDED_BY_HIDESYM 1
66518 +#endif
66519 #include <linux/kallsyms.h>
66520 #include <linux/module.h>
66521 #include <linux/init.h>
66522 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66523
66524 static inline int is_kernel_inittext(unsigned long addr)
66525 {
66526 + if (system_state != SYSTEM_BOOTING)
66527 + return 0;
66528 +
66529 if (addr >= (unsigned long)_sinittext
66530 && addr <= (unsigned long)_einittext)
66531 return 1;
66532 return 0;
66533 }
66534
66535 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66536 +#ifdef CONFIG_MODULES
66537 +static inline int is_module_text(unsigned long addr)
66538 +{
66539 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66540 + return 1;
66541 +
66542 + addr = ktla_ktva(addr);
66543 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66544 +}
66545 +#else
66546 +static inline int is_module_text(unsigned long addr)
66547 +{
66548 + return 0;
66549 +}
66550 +#endif
66551 +#endif
66552 +
66553 static inline int is_kernel_text(unsigned long addr)
66554 {
66555 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66556 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66557
66558 static inline int is_kernel(unsigned long addr)
66559 {
66560 +
66561 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66562 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
66563 + return 1;
66564 +
66565 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66566 +#else
66567 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66568 +#endif
66569 +
66570 return 1;
66571 return in_gate_area_no_mm(addr);
66572 }
66573
66574 static int is_ksym_addr(unsigned long addr)
66575 {
66576 +
66577 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66578 + if (is_module_text(addr))
66579 + return 0;
66580 +#endif
66581 +
66582 if (all_var)
66583 return is_kernel(addr);
66584
66585 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66586
66587 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66588 {
66589 - iter->name[0] = '\0';
66590 iter->nameoff = get_symbol_offset(new_pos);
66591 iter->pos = new_pos;
66592 }
66593 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66594 {
66595 struct kallsym_iter *iter = m->private;
66596
66597 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66598 + if (current_uid())
66599 + return 0;
66600 +#endif
66601 +
66602 /* Some debugging symbols have no name. Ignore them. */
66603 if (!iter->name[0])
66604 return 0;
66605 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66606 struct kallsym_iter *iter;
66607 int ret;
66608
66609 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66610 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66611 if (!iter)
66612 return -ENOMEM;
66613 reset_iter(iter, 0);
66614 diff --git a/kernel/kexec.c b/kernel/kexec.c
66615 index 296fbc8..84cb857 100644
66616 --- a/kernel/kexec.c
66617 +++ b/kernel/kexec.c
66618 @@ -1033,7 +1033,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66619 unsigned long flags)
66620 {
66621 struct compat_kexec_segment in;
66622 - struct kexec_segment out, __user *ksegments;
66623 + struct kexec_segment out;
66624 + struct kexec_segment __user *ksegments;
66625 unsigned long i, result;
66626
66627 /* Don't allow clients that don't understand the native
66628 diff --git a/kernel/kmod.c b/kernel/kmod.c
66629 index a4bea97..7a1ae9a 100644
66630 --- a/kernel/kmod.c
66631 +++ b/kernel/kmod.c
66632 @@ -73,13 +73,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
66633 * If module auto-loading support is disabled then this function
66634 * becomes a no-operation.
66635 */
66636 -int __request_module(bool wait, const char *fmt, ...)
66637 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
66638 {
66639 - va_list args;
66640 char module_name[MODULE_NAME_LEN];
66641 unsigned int max_modprobes;
66642 int ret;
66643 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
66644 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
66645 static char *envp[] = { "HOME=/",
66646 "TERM=linux",
66647 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
66648 @@ -88,9 +87,7 @@ int __request_module(bool wait, const char *fmt, ...)
66649 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
66650 static int kmod_loop_msg;
66651
66652 - va_start(args, fmt);
66653 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
66654 - va_end(args);
66655 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
66656 if (ret >= MODULE_NAME_LEN)
66657 return -ENAMETOOLONG;
66658
66659 @@ -98,6 +95,20 @@ int __request_module(bool wait, const char *fmt, ...)
66660 if (ret)
66661 return ret;
66662
66663 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66664 + if (!current_uid()) {
66665 + /* hack to workaround consolekit/udisks stupidity */
66666 + read_lock(&tasklist_lock);
66667 + if (!strcmp(current->comm, "mount") &&
66668 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
66669 + read_unlock(&tasklist_lock);
66670 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
66671 + return -EPERM;
66672 + }
66673 + read_unlock(&tasklist_lock);
66674 + }
66675 +#endif
66676 +
66677 /* If modprobe needs a service that is in a module, we get a recursive
66678 * loop. Limit the number of running kmod threads to max_threads/2 or
66679 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66680 @@ -133,6 +144,47 @@ int __request_module(bool wait, const char *fmt, ...)
66681 atomic_dec(&kmod_concurrent);
66682 return ret;
66683 }
66684 +
66685 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66686 +{
66687 + va_list args;
66688 + int ret;
66689 +
66690 + va_start(args, fmt);
66691 + ret = ____request_module(wait, module_param, fmt, args);
66692 + va_end(args);
66693 +
66694 + return ret;
66695 +}
66696 +
66697 +int __request_module(bool wait, const char *fmt, ...)
66698 +{
66699 + va_list args;
66700 + int ret;
66701 +
66702 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66703 + if (current_uid()) {
66704 + char module_param[MODULE_NAME_LEN];
66705 +
66706 + memset(module_param, 0, sizeof(module_param));
66707 +
66708 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66709 +
66710 + va_start(args, fmt);
66711 + ret = ____request_module(wait, module_param, fmt, args);
66712 + va_end(args);
66713 +
66714 + return ret;
66715 + }
66716 +#endif
66717 +
66718 + va_start(args, fmt);
66719 + ret = ____request_module(wait, NULL, fmt, args);
66720 + va_end(args);
66721 +
66722 + return ret;
66723 +}
66724 +
66725 EXPORT_SYMBOL(__request_module);
66726 #endif /* CONFIG_MODULES */
66727
66728 @@ -222,7 +274,7 @@ static int wait_for_helper(void *data)
66729 *
66730 * Thus the __user pointer cast is valid here.
66731 */
66732 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
66733 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66734
66735 /*
66736 * If ret is 0, either ____call_usermodehelper failed and the
66737 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66738 index b30fd54..11821ec 100644
66739 --- a/kernel/kprobes.c
66740 +++ b/kernel/kprobes.c
66741 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66742 * kernel image and loaded module images reside. This is required
66743 * so x86_64 can correctly handle the %rip-relative fixups.
66744 */
66745 - kip->insns = module_alloc(PAGE_SIZE);
66746 + kip->insns = module_alloc_exec(PAGE_SIZE);
66747 if (!kip->insns) {
66748 kfree(kip);
66749 return NULL;
66750 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66751 */
66752 if (!list_is_singular(&kip->list)) {
66753 list_del(&kip->list);
66754 - module_free(NULL, kip->insns);
66755 + module_free_exec(NULL, kip->insns);
66756 kfree(kip);
66757 }
66758 return 1;
66759 @@ -1949,7 +1949,7 @@ static int __init init_kprobes(void)
66760 {
66761 int i, err = 0;
66762 unsigned long offset = 0, size = 0;
66763 - char *modname, namebuf[128];
66764 + char *modname, namebuf[KSYM_NAME_LEN];
66765 const char *symbol_name;
66766 void *addr;
66767 struct kprobe_blackpoint *kb;
66768 @@ -2075,7 +2075,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66769 const char *sym = NULL;
66770 unsigned int i = *(loff_t *) v;
66771 unsigned long offset = 0;
66772 - char *modname, namebuf[128];
66773 + char *modname, namebuf[KSYM_NAME_LEN];
66774
66775 head = &kprobe_table[i];
66776 preempt_disable();
66777 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66778 index 4479606..4036bea 100644
66779 --- a/kernel/lockdep.c
66780 +++ b/kernel/lockdep.c
66781 @@ -584,6 +584,10 @@ static int static_obj(void *obj)
66782 end = (unsigned long) &_end,
66783 addr = (unsigned long) obj;
66784
66785 +#ifdef CONFIG_PAX_KERNEXEC
66786 + start = ktla_ktva(start);
66787 +#endif
66788 +
66789 /*
66790 * static variable?
66791 */
66792 @@ -719,6 +723,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66793 if (!static_obj(lock->key)) {
66794 debug_locks_off();
66795 printk("INFO: trying to register non-static key.\n");
66796 + printk("lock:%pS key:%pS.\n", lock, lock->key);
66797 printk("the code is fine but needs lockdep annotation.\n");
66798 printk("turning off the locking correctness validator.\n");
66799 dump_stack();
66800 @@ -2954,7 +2959,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66801 if (!class)
66802 return 0;
66803 }
66804 - atomic_inc((atomic_t *)&class->ops);
66805 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66806 if (very_verbose(class)) {
66807 printk("\nacquire class [%p] %s", class->key, class->name);
66808 if (class->name_version > 1)
66809 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66810 index 71edd2f..e0542a5 100644
66811 --- a/kernel/lockdep_proc.c
66812 +++ b/kernel/lockdep_proc.c
66813 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66814
66815 static void print_name(struct seq_file *m, struct lock_class *class)
66816 {
66817 - char str[128];
66818 + char str[KSYM_NAME_LEN];
66819 const char *name = class->name;
66820
66821 if (!name) {
66822 diff --git a/kernel/module.c b/kernel/module.c
66823 index 04379f92..fba2faf 100644
66824 --- a/kernel/module.c
66825 +++ b/kernel/module.c
66826 @@ -58,6 +58,7 @@
66827 #include <linux/jump_label.h>
66828 #include <linux/pfn.h>
66829 #include <linux/bsearch.h>
66830 +#include <linux/grsecurity.h>
66831
66832 #define CREATE_TRACE_POINTS
66833 #include <trace/events/module.h>
66834 @@ -119,7 +120,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66835
66836 /* Bounds of module allocation, for speeding __module_address.
66837 * Protected by module_mutex. */
66838 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66839 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66840 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66841
66842 int register_module_notifier(struct notifier_block * nb)
66843 {
66844 @@ -284,7 +286,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66845 return true;
66846
66847 list_for_each_entry_rcu(mod, &modules, list) {
66848 - struct symsearch arr[] = {
66849 + struct symsearch modarr[] = {
66850 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66851 NOT_GPL_ONLY, false },
66852 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66853 @@ -306,7 +308,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66854 #endif
66855 };
66856
66857 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66858 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66859 return true;
66860 }
66861 return false;
66862 @@ -438,7 +440,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66863 static int percpu_modalloc(struct module *mod,
66864 unsigned long size, unsigned long align)
66865 {
66866 - if (align > PAGE_SIZE) {
66867 + if (align-1 >= PAGE_SIZE) {
66868 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66869 mod->name, align, PAGE_SIZE);
66870 align = PAGE_SIZE;
66871 @@ -1183,7 +1185,7 @@ resolve_symbol_wait(struct module *mod,
66872 */
66873 #ifdef CONFIG_SYSFS
66874
66875 -#ifdef CONFIG_KALLSYMS
66876 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66877 static inline bool sect_empty(const Elf_Shdr *sect)
66878 {
66879 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66880 @@ -1649,21 +1651,21 @@ static void set_section_ro_nx(void *base,
66881
66882 static void unset_module_core_ro_nx(struct module *mod)
66883 {
66884 - set_page_attributes(mod->module_core + mod->core_text_size,
66885 - mod->module_core + mod->core_size,
66886 + set_page_attributes(mod->module_core_rw,
66887 + mod->module_core_rw + mod->core_size_rw,
66888 set_memory_x);
66889 - set_page_attributes(mod->module_core,
66890 - mod->module_core + mod->core_ro_size,
66891 + set_page_attributes(mod->module_core_rx,
66892 + mod->module_core_rx + mod->core_size_rx,
66893 set_memory_rw);
66894 }
66895
66896 static void unset_module_init_ro_nx(struct module *mod)
66897 {
66898 - set_page_attributes(mod->module_init + mod->init_text_size,
66899 - mod->module_init + mod->init_size,
66900 + set_page_attributes(mod->module_init_rw,
66901 + mod->module_init_rw + mod->init_size_rw,
66902 set_memory_x);
66903 - set_page_attributes(mod->module_init,
66904 - mod->module_init + mod->init_ro_size,
66905 + set_page_attributes(mod->module_init_rx,
66906 + mod->module_init_rx + mod->init_size_rx,
66907 set_memory_rw);
66908 }
66909
66910 @@ -1674,14 +1676,14 @@ void set_all_modules_text_rw(void)
66911
66912 mutex_lock(&module_mutex);
66913 list_for_each_entry_rcu(mod, &modules, list) {
66914 - if ((mod->module_core) && (mod->core_text_size)) {
66915 - set_page_attributes(mod->module_core,
66916 - mod->module_core + mod->core_text_size,
66917 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66918 + set_page_attributes(mod->module_core_rx,
66919 + mod->module_core_rx + mod->core_size_rx,
66920 set_memory_rw);
66921 }
66922 - if ((mod->module_init) && (mod->init_text_size)) {
66923 - set_page_attributes(mod->module_init,
66924 - mod->module_init + mod->init_text_size,
66925 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66926 + set_page_attributes(mod->module_init_rx,
66927 + mod->module_init_rx + mod->init_size_rx,
66928 set_memory_rw);
66929 }
66930 }
66931 @@ -1695,14 +1697,14 @@ void set_all_modules_text_ro(void)
66932
66933 mutex_lock(&module_mutex);
66934 list_for_each_entry_rcu(mod, &modules, list) {
66935 - if ((mod->module_core) && (mod->core_text_size)) {
66936 - set_page_attributes(mod->module_core,
66937 - mod->module_core + mod->core_text_size,
66938 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66939 + set_page_attributes(mod->module_core_rx,
66940 + mod->module_core_rx + mod->core_size_rx,
66941 set_memory_ro);
66942 }
66943 - if ((mod->module_init) && (mod->init_text_size)) {
66944 - set_page_attributes(mod->module_init,
66945 - mod->module_init + mod->init_text_size,
66946 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66947 + set_page_attributes(mod->module_init_rx,
66948 + mod->module_init_rx + mod->init_size_rx,
66949 set_memory_ro);
66950 }
66951 }
66952 @@ -1748,16 +1750,19 @@ static void free_module(struct module *mod)
66953
66954 /* This may be NULL, but that's OK */
66955 unset_module_init_ro_nx(mod);
66956 - module_free(mod, mod->module_init);
66957 + module_free(mod, mod->module_init_rw);
66958 + module_free_exec(mod, mod->module_init_rx);
66959 kfree(mod->args);
66960 percpu_modfree(mod);
66961
66962 /* Free lock-classes: */
66963 - lockdep_free_key_range(mod->module_core, mod->core_size);
66964 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66965 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66966
66967 /* Finally, free the core (containing the module structure) */
66968 unset_module_core_ro_nx(mod);
66969 - module_free(mod, mod->module_core);
66970 + module_free_exec(mod, mod->module_core_rx);
66971 + module_free(mod, mod->module_core_rw);
66972
66973 #ifdef CONFIG_MPU
66974 update_protections(current->mm);
66975 @@ -1826,10 +1831,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66976 unsigned int i;
66977 int ret = 0;
66978 const struct kernel_symbol *ksym;
66979 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66980 + int is_fs_load = 0;
66981 + int register_filesystem_found = 0;
66982 + char *p;
66983 +
66984 + p = strstr(mod->args, "grsec_modharden_fs");
66985 + if (p) {
66986 + char *endptr = p + strlen("grsec_modharden_fs");
66987 + /* copy \0 as well */
66988 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
66989 + is_fs_load = 1;
66990 + }
66991 +#endif
66992
66993 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
66994 const char *name = info->strtab + sym[i].st_name;
66995
66996 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66997 + /* it's a real shame this will never get ripped and copied
66998 + upstream! ;(
66999 + */
67000 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67001 + register_filesystem_found = 1;
67002 +#endif
67003 +
67004 switch (sym[i].st_shndx) {
67005 case SHN_COMMON:
67006 /* We compiled with -fno-common. These are not
67007 @@ -1850,7 +1876,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67008 ksym = resolve_symbol_wait(mod, info, name);
67009 /* Ok if resolved. */
67010 if (ksym && !IS_ERR(ksym)) {
67011 + pax_open_kernel();
67012 sym[i].st_value = ksym->value;
67013 + pax_close_kernel();
67014 break;
67015 }
67016
67017 @@ -1869,11 +1897,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67018 secbase = (unsigned long)mod_percpu(mod);
67019 else
67020 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67021 + pax_open_kernel();
67022 sym[i].st_value += secbase;
67023 + pax_close_kernel();
67024 break;
67025 }
67026 }
67027
67028 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67029 + if (is_fs_load && !register_filesystem_found) {
67030 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67031 + ret = -EPERM;
67032 + }
67033 +#endif
67034 +
67035 return ret;
67036 }
67037
67038 @@ -1977,22 +2014,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67039 || s->sh_entsize != ~0UL
67040 || strstarts(sname, ".init"))
67041 continue;
67042 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67043 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67044 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67045 + else
67046 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67047 DEBUGP("\t%s\n", name);
67048 }
67049 - switch (m) {
67050 - case 0: /* executable */
67051 - mod->core_size = debug_align(mod->core_size);
67052 - mod->core_text_size = mod->core_size;
67053 - break;
67054 - case 1: /* RO: text and ro-data */
67055 - mod->core_size = debug_align(mod->core_size);
67056 - mod->core_ro_size = mod->core_size;
67057 - break;
67058 - case 3: /* whole core */
67059 - mod->core_size = debug_align(mod->core_size);
67060 - break;
67061 - }
67062 }
67063
67064 DEBUGP("Init section allocation order:\n");
67065 @@ -2006,23 +2033,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67066 || s->sh_entsize != ~0UL
67067 || !strstarts(sname, ".init"))
67068 continue;
67069 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67070 - | INIT_OFFSET_MASK);
67071 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67072 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67073 + else
67074 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67075 + s->sh_entsize |= INIT_OFFSET_MASK;
67076 DEBUGP("\t%s\n", sname);
67077 }
67078 - switch (m) {
67079 - case 0: /* executable */
67080 - mod->init_size = debug_align(mod->init_size);
67081 - mod->init_text_size = mod->init_size;
67082 - break;
67083 - case 1: /* RO: text and ro-data */
67084 - mod->init_size = debug_align(mod->init_size);
67085 - mod->init_ro_size = mod->init_size;
67086 - break;
67087 - case 3: /* whole init */
67088 - mod->init_size = debug_align(mod->init_size);
67089 - break;
67090 - }
67091 }
67092 }
67093
67094 @@ -2187,7 +2204,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67095
67096 /* Put symbol section at end of init part of module. */
67097 symsect->sh_flags |= SHF_ALLOC;
67098 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67099 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67100 info->index.sym) | INIT_OFFSET_MASK;
67101 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
67102
67103 @@ -2204,19 +2221,19 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67104 }
67105
67106 /* Append room for core symbols at end of core part. */
67107 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67108 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67109 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67110 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67111
67112 /* Put string table section at end of init part of module. */
67113 strsect->sh_flags |= SHF_ALLOC;
67114 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67115 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67116 info->index.str) | INIT_OFFSET_MASK;
67117 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
67118
67119 /* Append room for core symbols' strings at end of core part. */
67120 - info->stroffs = mod->core_size;
67121 + info->stroffs = mod->core_size_rx;
67122 __set_bit(0, info->strmap);
67123 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
67124 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
67125 }
67126
67127 static void add_kallsyms(struct module *mod, const struct load_info *info)
67128 @@ -2232,11 +2249,13 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67129 /* Make sure we get permanent strtab: don't use info->strtab. */
67130 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67131
67132 + pax_open_kernel();
67133 +
67134 /* Set types up while we still have access to sections. */
67135 for (i = 0; i < mod->num_symtab; i++)
67136 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67137
67138 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67139 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67140 src = mod->symtab;
67141 *dst = *src;
67142 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
67143 @@ -2249,10 +2268,12 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67144 }
67145 mod->core_num_syms = ndst;
67146
67147 - mod->core_strtab = s = mod->module_core + info->stroffs;
67148 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67149 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
67150 if (test_bit(i, info->strmap))
67151 *++s = mod->strtab[i];
67152 +
67153 + pax_close_kernel();
67154 }
67155 #else
67156 static inline void layout_symtab(struct module *mod, struct load_info *info)
67157 @@ -2286,17 +2307,33 @@ void * __weak module_alloc(unsigned long size)
67158 return size == 0 ? NULL : vmalloc_exec(size);
67159 }
67160
67161 -static void *module_alloc_update_bounds(unsigned long size)
67162 +static void *module_alloc_update_bounds_rw(unsigned long size)
67163 {
67164 void *ret = module_alloc(size);
67165
67166 if (ret) {
67167 mutex_lock(&module_mutex);
67168 /* Update module bounds. */
67169 - if ((unsigned long)ret < module_addr_min)
67170 - module_addr_min = (unsigned long)ret;
67171 - if ((unsigned long)ret + size > module_addr_max)
67172 - module_addr_max = (unsigned long)ret + size;
67173 + if ((unsigned long)ret < module_addr_min_rw)
67174 + module_addr_min_rw = (unsigned long)ret;
67175 + if ((unsigned long)ret + size > module_addr_max_rw)
67176 + module_addr_max_rw = (unsigned long)ret + size;
67177 + mutex_unlock(&module_mutex);
67178 + }
67179 + return ret;
67180 +}
67181 +
67182 +static void *module_alloc_update_bounds_rx(unsigned long size)
67183 +{
67184 + void *ret = module_alloc_exec(size);
67185 +
67186 + if (ret) {
67187 + mutex_lock(&module_mutex);
67188 + /* Update module bounds. */
67189 + if ((unsigned long)ret < module_addr_min_rx)
67190 + module_addr_min_rx = (unsigned long)ret;
67191 + if ((unsigned long)ret + size > module_addr_max_rx)
67192 + module_addr_max_rx = (unsigned long)ret + size;
67193 mutex_unlock(&module_mutex);
67194 }
67195 return ret;
67196 @@ -2474,8 +2511,14 @@ static struct module *setup_load_info(struct load_info *info)
67197 static int check_modinfo(struct module *mod, struct load_info *info)
67198 {
67199 const char *modmagic = get_modinfo(info, "vermagic");
67200 + const char *license = get_modinfo(info, "license");
67201 int err;
67202
67203 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67204 + if (!license || !license_is_gpl_compatible(license))
67205 + return -ENOEXEC;
67206 +#endif
67207 +
67208 /* This is allowed: modprobe --force will invalidate it. */
67209 if (!modmagic) {
67210 err = try_to_force_load(mod, "bad vermagic");
67211 @@ -2495,7 +2538,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67212 }
67213
67214 /* Set up license info based on the info section */
67215 - set_license(mod, get_modinfo(info, "license"));
67216 + set_license(mod, license);
67217
67218 return 0;
67219 }
67220 @@ -2589,7 +2632,7 @@ static int move_module(struct module *mod, struct load_info *info)
67221 void *ptr;
67222
67223 /* Do the allocs. */
67224 - ptr = module_alloc_update_bounds(mod->core_size);
67225 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67226 /*
67227 * The pointer to this block is stored in the module structure
67228 * which is inside the block. Just mark it as not being a
67229 @@ -2599,23 +2642,50 @@ static int move_module(struct module *mod, struct load_info *info)
67230 if (!ptr)
67231 return -ENOMEM;
67232
67233 - memset(ptr, 0, mod->core_size);
67234 - mod->module_core = ptr;
67235 + memset(ptr, 0, mod->core_size_rw);
67236 + mod->module_core_rw = ptr;
67237
67238 - ptr = module_alloc_update_bounds(mod->init_size);
67239 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67240 /*
67241 * The pointer to this block is stored in the module structure
67242 * which is inside the block. This block doesn't need to be
67243 * scanned as it contains data and code that will be freed
67244 * after the module is initialized.
67245 */
67246 - kmemleak_ignore(ptr);
67247 - if (!ptr && mod->init_size) {
67248 - module_free(mod, mod->module_core);
67249 + kmemleak_not_leak(ptr);
67250 + if (!ptr && mod->init_size_rw) {
67251 + module_free(mod, mod->module_core_rw);
67252 return -ENOMEM;
67253 }
67254 - memset(ptr, 0, mod->init_size);
67255 - mod->module_init = ptr;
67256 + memset(ptr, 0, mod->init_size_rw);
67257 + mod->module_init_rw = ptr;
67258 +
67259 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67260 + kmemleak_not_leak(ptr);
67261 + if (!ptr) {
67262 + module_free(mod, mod->module_init_rw);
67263 + module_free(mod, mod->module_core_rw);
67264 + return -ENOMEM;
67265 + }
67266 +
67267 + pax_open_kernel();
67268 + memset(ptr, 0, mod->core_size_rx);
67269 + pax_close_kernel();
67270 + mod->module_core_rx = ptr;
67271 +
67272 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67273 + kmemleak_not_leak(ptr);
67274 + if (!ptr && mod->init_size_rx) {
67275 + module_free_exec(mod, mod->module_core_rx);
67276 + module_free(mod, mod->module_init_rw);
67277 + module_free(mod, mod->module_core_rw);
67278 + return -ENOMEM;
67279 + }
67280 +
67281 + pax_open_kernel();
67282 + memset(ptr, 0, mod->init_size_rx);
67283 + pax_close_kernel();
67284 + mod->module_init_rx = ptr;
67285
67286 /* Transfer each section which specifies SHF_ALLOC */
67287 DEBUGP("final section addresses:\n");
67288 @@ -2626,16 +2696,45 @@ static int move_module(struct module *mod, struct load_info *info)
67289 if (!(shdr->sh_flags & SHF_ALLOC))
67290 continue;
67291
67292 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67293 - dest = mod->module_init
67294 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67295 - else
67296 - dest = mod->module_core + shdr->sh_entsize;
67297 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67298 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67299 + dest = mod->module_init_rw
67300 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67301 + else
67302 + dest = mod->module_init_rx
67303 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67304 + } else {
67305 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67306 + dest = mod->module_core_rw + shdr->sh_entsize;
67307 + else
67308 + dest = mod->module_core_rx + shdr->sh_entsize;
67309 + }
67310 +
67311 + if (shdr->sh_type != SHT_NOBITS) {
67312 +
67313 +#ifdef CONFIG_PAX_KERNEXEC
67314 +#ifdef CONFIG_X86_64
67315 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67316 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67317 +#endif
67318 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67319 + pax_open_kernel();
67320 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67321 + pax_close_kernel();
67322 + } else
67323 +#endif
67324
67325 - if (shdr->sh_type != SHT_NOBITS)
67326 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67327 + }
67328 /* Update sh_addr to point to copy in image. */
67329 - shdr->sh_addr = (unsigned long)dest;
67330 +
67331 +#ifdef CONFIG_PAX_KERNEXEC
67332 + if (shdr->sh_flags & SHF_EXECINSTR)
67333 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
67334 + else
67335 +#endif
67336 +
67337 + shdr->sh_addr = (unsigned long)dest;
67338 DEBUGP("\t0x%lx %s\n",
67339 shdr->sh_addr, info->secstrings + shdr->sh_name);
67340 }
67341 @@ -2686,12 +2785,12 @@ static void flush_module_icache(const struct module *mod)
67342 * Do it before processing of module parameters, so the module
67343 * can provide parameter accessor functions of its own.
67344 */
67345 - if (mod->module_init)
67346 - flush_icache_range((unsigned long)mod->module_init,
67347 - (unsigned long)mod->module_init
67348 - + mod->init_size);
67349 - flush_icache_range((unsigned long)mod->module_core,
67350 - (unsigned long)mod->module_core + mod->core_size);
67351 + if (mod->module_init_rx)
67352 + flush_icache_range((unsigned long)mod->module_init_rx,
67353 + (unsigned long)mod->module_init_rx
67354 + + mod->init_size_rx);
67355 + flush_icache_range((unsigned long)mod->module_core_rx,
67356 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
67357
67358 set_fs(old_fs);
67359 }
67360 @@ -2771,8 +2870,10 @@ static void module_deallocate(struct module *mod, struct load_info *info)
67361 {
67362 kfree(info->strmap);
67363 percpu_modfree(mod);
67364 - module_free(mod, mod->module_init);
67365 - module_free(mod, mod->module_core);
67366 + module_free_exec(mod, mod->module_init_rx);
67367 + module_free_exec(mod, mod->module_core_rx);
67368 + module_free(mod, mod->module_init_rw);
67369 + module_free(mod, mod->module_core_rw);
67370 }
67371
67372 int __weak module_finalize(const Elf_Ehdr *hdr,
67373 @@ -2836,9 +2937,38 @@ static struct module *load_module(void __user *umod,
67374 if (err)
67375 goto free_unload;
67376
67377 + /* Now copy in args */
67378 + mod->args = strndup_user(uargs, ~0UL >> 1);
67379 + if (IS_ERR(mod->args)) {
67380 + err = PTR_ERR(mod->args);
67381 + goto free_unload;
67382 + }
67383 +
67384 /* Set up MODINFO_ATTR fields */
67385 setup_modinfo(mod, &info);
67386
67387 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67388 + {
67389 + char *p, *p2;
67390 +
67391 + if (strstr(mod->args, "grsec_modharden_netdev")) {
67392 + printk(KERN_ALERT "grsec: denied auto-loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%.64s instead.", mod->name);
67393 + err = -EPERM;
67394 + goto free_modinfo;
67395 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67396 + p += strlen("grsec_modharden_normal");
67397 + p2 = strstr(p, "_");
67398 + if (p2) {
67399 + *p2 = '\0';
67400 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67401 + *p2 = '_';
67402 + }
67403 + err = -EPERM;
67404 + goto free_modinfo;
67405 + }
67406 + }
67407 +#endif
67408 +
67409 /* Fix up syms, so that st_value is a pointer to location. */
67410 err = simplify_symbols(mod, &info);
67411 if (err < 0)
67412 @@ -2854,13 +2984,6 @@ static struct module *load_module(void __user *umod,
67413
67414 flush_module_icache(mod);
67415
67416 - /* Now copy in args */
67417 - mod->args = strndup_user(uargs, ~0UL >> 1);
67418 - if (IS_ERR(mod->args)) {
67419 - err = PTR_ERR(mod->args);
67420 - goto free_arch_cleanup;
67421 - }
67422 -
67423 /* Mark state as coming so strong_try_module_get() ignores us. */
67424 mod->state = MODULE_STATE_COMING;
67425
67426 @@ -2920,11 +3043,10 @@ static struct module *load_module(void __user *umod,
67427 unlock:
67428 mutex_unlock(&module_mutex);
67429 synchronize_sched();
67430 - kfree(mod->args);
67431 - free_arch_cleanup:
67432 module_arch_cleanup(mod);
67433 free_modinfo:
67434 free_modinfo(mod);
67435 + kfree(mod->args);
67436 free_unload:
67437 module_unload_free(mod);
67438 free_module:
67439 @@ -2965,16 +3087,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67440 MODULE_STATE_COMING, mod);
67441
67442 /* Set RO and NX regions for core */
67443 - set_section_ro_nx(mod->module_core,
67444 - mod->core_text_size,
67445 - mod->core_ro_size,
67446 - mod->core_size);
67447 + set_section_ro_nx(mod->module_core_rx,
67448 + mod->core_size_rx,
67449 + mod->core_size_rx,
67450 + mod->core_size_rx);
67451
67452 /* Set RO and NX regions for init */
67453 - set_section_ro_nx(mod->module_init,
67454 - mod->init_text_size,
67455 - mod->init_ro_size,
67456 - mod->init_size);
67457 + set_section_ro_nx(mod->module_init_rx,
67458 + mod->init_size_rx,
67459 + mod->init_size_rx,
67460 + mod->init_size_rx);
67461
67462 do_mod_ctors(mod);
67463 /* Start the module */
67464 @@ -3020,11 +3142,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67465 mod->strtab = mod->core_strtab;
67466 #endif
67467 unset_module_init_ro_nx(mod);
67468 - module_free(mod, mod->module_init);
67469 - mod->module_init = NULL;
67470 - mod->init_size = 0;
67471 - mod->init_ro_size = 0;
67472 - mod->init_text_size = 0;
67473 + module_free(mod, mod->module_init_rw);
67474 + module_free_exec(mod, mod->module_init_rx);
67475 + mod->module_init_rw = NULL;
67476 + mod->module_init_rx = NULL;
67477 + mod->init_size_rw = 0;
67478 + mod->init_size_rx = 0;
67479 mutex_unlock(&module_mutex);
67480
67481 return 0;
67482 @@ -3055,10 +3178,16 @@ static const char *get_ksymbol(struct module *mod,
67483 unsigned long nextval;
67484
67485 /* At worse, next value is at end of module */
67486 - if (within_module_init(addr, mod))
67487 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
67488 + if (within_module_init_rx(addr, mod))
67489 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67490 + else if (within_module_init_rw(addr, mod))
67491 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67492 + else if (within_module_core_rx(addr, mod))
67493 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67494 + else if (within_module_core_rw(addr, mod))
67495 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67496 else
67497 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
67498 + return NULL;
67499
67500 /* Scan for closest preceding symbol, and next symbol. (ELF
67501 starts real symbols at 1). */
67502 @@ -3304,7 +3433,7 @@ static int m_show(struct seq_file *m, void *p)
67503 char buf[8];
67504
67505 seq_printf(m, "%s %u",
67506 - mod->name, mod->init_size + mod->core_size);
67507 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67508 print_unload_info(m, mod);
67509
67510 /* Informative for users. */
67511 @@ -3313,7 +3442,7 @@ static int m_show(struct seq_file *m, void *p)
67512 mod->state == MODULE_STATE_COMING ? "Loading":
67513 "Live");
67514 /* Used by oprofile and other similar tools. */
67515 - seq_printf(m, " 0x%pK", mod->module_core);
67516 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67517
67518 /* Taints info */
67519 if (mod->taints)
67520 @@ -3349,7 +3478,17 @@ static const struct file_operations proc_modules_operations = {
67521
67522 static int __init proc_modules_init(void)
67523 {
67524 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67525 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67526 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67527 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67528 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67529 +#else
67530 proc_create("modules", 0, NULL, &proc_modules_operations);
67531 +#endif
67532 +#else
67533 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67534 +#endif
67535 return 0;
67536 }
67537 module_init(proc_modules_init);
67538 @@ -3408,12 +3547,12 @@ struct module *__module_address(unsigned long addr)
67539 {
67540 struct module *mod;
67541
67542 - if (addr < module_addr_min || addr > module_addr_max)
67543 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67544 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
67545 return NULL;
67546
67547 list_for_each_entry_rcu(mod, &modules, list)
67548 - if (within_module_core(addr, mod)
67549 - || within_module_init(addr, mod))
67550 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
67551 return mod;
67552 return NULL;
67553 }
67554 @@ -3447,11 +3586,20 @@ bool is_module_text_address(unsigned long addr)
67555 */
67556 struct module *__module_text_address(unsigned long addr)
67557 {
67558 - struct module *mod = __module_address(addr);
67559 + struct module *mod;
67560 +
67561 +#ifdef CONFIG_X86_32
67562 + addr = ktla_ktva(addr);
67563 +#endif
67564 +
67565 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67566 + return NULL;
67567 +
67568 + mod = __module_address(addr);
67569 +
67570 if (mod) {
67571 /* Make sure it's within the text section. */
67572 - if (!within(addr, mod->module_init, mod->init_text_size)
67573 - && !within(addr, mod->module_core, mod->core_text_size))
67574 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67575 mod = NULL;
67576 }
67577 return mod;
67578 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67579 index 73da83a..fe46e99 100644
67580 --- a/kernel/mutex-debug.c
67581 +++ b/kernel/mutex-debug.c
67582 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67583 }
67584
67585 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67586 - struct thread_info *ti)
67587 + struct task_struct *task)
67588 {
67589 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67590
67591 /* Mark the current thread as blocked on the lock: */
67592 - ti->task->blocked_on = waiter;
67593 + task->blocked_on = waiter;
67594 }
67595
67596 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67597 - struct thread_info *ti)
67598 + struct task_struct *task)
67599 {
67600 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
67601 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
67602 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
67603 - ti->task->blocked_on = NULL;
67604 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
67605 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
67606 + task->blocked_on = NULL;
67607
67608 list_del_init(&waiter->list);
67609 waiter->task = NULL;
67610 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
67611 index 0799fd3..d06ae3b 100644
67612 --- a/kernel/mutex-debug.h
67613 +++ b/kernel/mutex-debug.h
67614 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
67615 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
67616 extern void debug_mutex_add_waiter(struct mutex *lock,
67617 struct mutex_waiter *waiter,
67618 - struct thread_info *ti);
67619 + struct task_struct *task);
67620 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67621 - struct thread_info *ti);
67622 + struct task_struct *task);
67623 extern void debug_mutex_unlock(struct mutex *lock);
67624 extern void debug_mutex_init(struct mutex *lock, const char *name,
67625 struct lock_class_key *key);
67626 diff --git a/kernel/mutex.c b/kernel/mutex.c
67627 index d607ed5..58d0a52 100644
67628 --- a/kernel/mutex.c
67629 +++ b/kernel/mutex.c
67630 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67631 spin_lock_mutex(&lock->wait_lock, flags);
67632
67633 debug_mutex_lock_common(lock, &waiter);
67634 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
67635 + debug_mutex_add_waiter(lock, &waiter, task);
67636
67637 /* add waiting tasks to the end of the waitqueue (FIFO): */
67638 list_add_tail(&waiter.list, &lock->wait_list);
67639 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67640 * TASK_UNINTERRUPTIBLE case.)
67641 */
67642 if (unlikely(signal_pending_state(state, task))) {
67643 - mutex_remove_waiter(lock, &waiter,
67644 - task_thread_info(task));
67645 + mutex_remove_waiter(lock, &waiter, task);
67646 mutex_release(&lock->dep_map, 1, ip);
67647 spin_unlock_mutex(&lock->wait_lock, flags);
67648
67649 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67650 done:
67651 lock_acquired(&lock->dep_map, ip);
67652 /* got the lock - rejoice! */
67653 - mutex_remove_waiter(lock, &waiter, current_thread_info());
67654 + mutex_remove_waiter(lock, &waiter, task);
67655 mutex_set_owner(lock);
67656
67657 /* set it to 0 if there are no waiters left: */
67658 diff --git a/kernel/padata.c b/kernel/padata.c
67659 index b91941d..0871d60 100644
67660 --- a/kernel/padata.c
67661 +++ b/kernel/padata.c
67662 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
67663 padata->pd = pd;
67664 padata->cb_cpu = cb_cpu;
67665
67666 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
67667 - atomic_set(&pd->seq_nr, -1);
67668 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
67669 + atomic_set_unchecked(&pd->seq_nr, -1);
67670
67671 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
67672 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
67673
67674 target_cpu = padata_cpu_hash(padata);
67675 queue = per_cpu_ptr(pd->pqueue, target_cpu);
67676 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
67677 padata_init_pqueues(pd);
67678 padata_init_squeues(pd);
67679 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
67680 - atomic_set(&pd->seq_nr, -1);
67681 + atomic_set_unchecked(&pd->seq_nr, -1);
67682 atomic_set(&pd->reorder_objects, 0);
67683 atomic_set(&pd->refcnt, 0);
67684 pd->pinst = pinst;
67685 diff --git a/kernel/panic.c b/kernel/panic.c
67686 index d7bb697..9ef9f19 100644
67687 --- a/kernel/panic.c
67688 +++ b/kernel/panic.c
67689 @@ -371,7 +371,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67690 const char *board;
67691
67692 printk(KERN_WARNING "------------[ cut here ]------------\n");
67693 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67694 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67695 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67696 if (board)
67697 printk(KERN_WARNING "Hardware name: %s\n", board);
67698 @@ -426,7 +426,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67699 */
67700 void __stack_chk_fail(void)
67701 {
67702 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
67703 + dump_stack();
67704 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67705 __builtin_return_address(0));
67706 }
67707 EXPORT_SYMBOL(__stack_chk_fail);
67708 diff --git a/kernel/pid.c b/kernel/pid.c
67709 index e432057..a2b2ac5 100644
67710 --- a/kernel/pid.c
67711 +++ b/kernel/pid.c
67712 @@ -33,6 +33,7 @@
67713 #include <linux/rculist.h>
67714 #include <linux/bootmem.h>
67715 #include <linux/hash.h>
67716 +#include <linux/security.h>
67717 #include <linux/pid_namespace.h>
67718 #include <linux/init_task.h>
67719 #include <linux/syscalls.h>
67720 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67721
67722 int pid_max = PID_MAX_DEFAULT;
67723
67724 -#define RESERVED_PIDS 300
67725 +#define RESERVED_PIDS 500
67726
67727 int pid_max_min = RESERVED_PIDS + 1;
67728 int pid_max_max = PID_MAX_LIMIT;
67729 @@ -418,8 +419,15 @@ EXPORT_SYMBOL(pid_task);
67730 */
67731 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67732 {
67733 + struct task_struct *task;
67734 +
67735 rcu_lockdep_assert(rcu_read_lock_held());
67736 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67737 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67738 +
67739 + if (gr_pid_is_chrooted(task))
67740 + return NULL;
67741 +
67742 + return task;
67743 }
67744
67745 struct task_struct *find_task_by_vpid(pid_t vnr)
67746 @@ -427,6 +435,12 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67747 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67748 }
67749
67750 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67751 +{
67752 + rcu_lockdep_assert(rcu_read_lock_held());
67753 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67754 +}
67755 +
67756 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67757 {
67758 struct pid *pid;
67759 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67760 index 640ded8..3dafb85 100644
67761 --- a/kernel/posix-cpu-timers.c
67762 +++ b/kernel/posix-cpu-timers.c
67763 @@ -6,6 +6,7 @@
67764 #include <linux/posix-timers.h>
67765 #include <linux/errno.h>
67766 #include <linux/math64.h>
67767 +#include <linux/security.h>
67768 #include <asm/uaccess.h>
67769 #include <linux/kernel_stat.h>
67770 #include <trace/events/timer.h>
67771 @@ -1606,14 +1607,14 @@ struct k_clock clock_posix_cpu = {
67772
67773 static __init int init_posix_cpu_timers(void)
67774 {
67775 - struct k_clock process = {
67776 + static struct k_clock process = {
67777 .clock_getres = process_cpu_clock_getres,
67778 .clock_get = process_cpu_clock_get,
67779 .timer_create = process_cpu_timer_create,
67780 .nsleep = process_cpu_nsleep,
67781 .nsleep_restart = process_cpu_nsleep_restart,
67782 };
67783 - struct k_clock thread = {
67784 + static struct k_clock thread = {
67785 .clock_getres = thread_cpu_clock_getres,
67786 .clock_get = thread_cpu_clock_get,
67787 .timer_create = thread_cpu_timer_create,
67788 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67789 index 4556182..9335419 100644
67790 --- a/kernel/posix-timers.c
67791 +++ b/kernel/posix-timers.c
67792 @@ -43,6 +43,7 @@
67793 #include <linux/idr.h>
67794 #include <linux/posix-clock.h>
67795 #include <linux/posix-timers.h>
67796 +#include <linux/grsecurity.h>
67797 #include <linux/syscalls.h>
67798 #include <linux/wait.h>
67799 #include <linux/workqueue.h>
67800 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67801 * which we beg off on and pass to do_sys_settimeofday().
67802 */
67803
67804 -static struct k_clock posix_clocks[MAX_CLOCKS];
67805 +static struct k_clock *posix_clocks[MAX_CLOCKS];
67806
67807 /*
67808 * These ones are defined below.
67809 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67810 */
67811 static __init int init_posix_timers(void)
67812 {
67813 - struct k_clock clock_realtime = {
67814 + static struct k_clock clock_realtime = {
67815 .clock_getres = hrtimer_get_res,
67816 .clock_get = posix_clock_realtime_get,
67817 .clock_set = posix_clock_realtime_set,
67818 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67819 .timer_get = common_timer_get,
67820 .timer_del = common_timer_del,
67821 };
67822 - struct k_clock clock_monotonic = {
67823 + static struct k_clock clock_monotonic = {
67824 .clock_getres = hrtimer_get_res,
67825 .clock_get = posix_ktime_get_ts,
67826 .nsleep = common_nsleep,
67827 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67828 .timer_get = common_timer_get,
67829 .timer_del = common_timer_del,
67830 };
67831 - struct k_clock clock_monotonic_raw = {
67832 + static struct k_clock clock_monotonic_raw = {
67833 .clock_getres = hrtimer_get_res,
67834 .clock_get = posix_get_monotonic_raw,
67835 };
67836 - struct k_clock clock_realtime_coarse = {
67837 + static struct k_clock clock_realtime_coarse = {
67838 .clock_getres = posix_get_coarse_res,
67839 .clock_get = posix_get_realtime_coarse,
67840 };
67841 - struct k_clock clock_monotonic_coarse = {
67842 + static struct k_clock clock_monotonic_coarse = {
67843 .clock_getres = posix_get_coarse_res,
67844 .clock_get = posix_get_monotonic_coarse,
67845 };
67846 - struct k_clock clock_boottime = {
67847 + static struct k_clock clock_boottime = {
67848 .clock_getres = hrtimer_get_res,
67849 .clock_get = posix_get_boottime,
67850 .nsleep = common_nsleep,
67851 @@ -272,6 +273,8 @@ static __init int init_posix_timers(void)
67852 .timer_del = common_timer_del,
67853 };
67854
67855 + pax_track_stack();
67856 +
67857 posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime);
67858 posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic);
67859 posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
67860 @@ -473,7 +476,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67861 return;
67862 }
67863
67864 - posix_clocks[clock_id] = *new_clock;
67865 + posix_clocks[clock_id] = new_clock;
67866 }
67867 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67868
67869 @@ -519,9 +522,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67870 return (id & CLOCKFD_MASK) == CLOCKFD ?
67871 &clock_posix_dynamic : &clock_posix_cpu;
67872
67873 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67874 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67875 return NULL;
67876 - return &posix_clocks[id];
67877 + return posix_clocks[id];
67878 }
67879
67880 static int common_timer_create(struct k_itimer *new_timer)
67881 @@ -959,6 +962,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67882 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67883 return -EFAULT;
67884
67885 + /* only the CLOCK_REALTIME clock can be set, all other clocks
67886 + have their clock_set fptr set to a nosettime dummy function
67887 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67888 + call common_clock_set, which calls do_sys_settimeofday, which
67889 + we hook
67890 + */
67891 +
67892 return kc->clock_set(which_clock, &new_tp);
67893 }
67894
67895 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67896 index d523593..68197a4 100644
67897 --- a/kernel/power/poweroff.c
67898 +++ b/kernel/power/poweroff.c
67899 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67900 .enable_mask = SYSRQ_ENABLE_BOOT,
67901 };
67902
67903 -static int pm_sysrq_init(void)
67904 +static int __init pm_sysrq_init(void)
67905 {
67906 register_sysrq_key('o', &sysrq_poweroff_op);
67907 return 0;
67908 diff --git a/kernel/power/process.c b/kernel/power/process.c
67909 index 0cf3a27..5481be4 100644
67910 --- a/kernel/power/process.c
67911 +++ b/kernel/power/process.c
67912 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_only)
67913 u64 elapsed_csecs64;
67914 unsigned int elapsed_csecs;
67915 bool wakeup = false;
67916 + bool timedout = false;
67917
67918 do_gettimeofday(&start);
67919
67920 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_only)
67921
67922 while (true) {
67923 todo = 0;
67924 + if (time_after(jiffies, end_time))
67925 + timedout = true;
67926 read_lock(&tasklist_lock);
67927 do_each_thread(g, p) {
67928 if (frozen(p) || !freezable(p))
67929 @@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_only)
67930 * try_to_stop() after schedule() in ptrace/signal
67931 * stop sees TIF_FREEZE.
67932 */
67933 - if (!task_is_stopped_or_traced(p) &&
67934 - !freezer_should_skip(p))
67935 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67936 todo++;
67937 + if (timedout) {
67938 + printk(KERN_ERR "Task refusing to freeze:\n");
67939 + sched_show_task(p);
67940 + }
67941 + }
67942 } while_each_thread(g, p);
67943 read_unlock(&tasklist_lock);
67944
67945 @@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_only)
67946 todo += wq_busy;
67947 }
67948
67949 - if (!todo || time_after(jiffies, end_time))
67950 + if (!todo || timedout)
67951 break;
67952
67953 if (pm_wakeup_pending()) {
67954 diff --git a/kernel/printk.c b/kernel/printk.c
67955 index 28a40d8..2411bec 100644
67956 --- a/kernel/printk.c
67957 +++ b/kernel/printk.c
67958 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
67959 if (from_file && type != SYSLOG_ACTION_OPEN)
67960 return 0;
67961
67962 +#ifdef CONFIG_GRKERNSEC_DMESG
67963 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67964 + return -EPERM;
67965 +#endif
67966 +
67967 if (syslog_action_restricted(type)) {
67968 if (capable(CAP_SYSLOG))
67969 return 0;
67970 diff --git a/kernel/profile.c b/kernel/profile.c
67971 index 961b389..c451353 100644
67972 --- a/kernel/profile.c
67973 +++ b/kernel/profile.c
67974 @@ -39,7 +39,7 @@ struct profile_hit {
67975 /* Oprofile timer tick hook */
67976 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67977
67978 -static atomic_t *prof_buffer;
67979 +static atomic_unchecked_t *prof_buffer;
67980 static unsigned long prof_len, prof_shift;
67981
67982 int prof_on __read_mostly;
67983 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67984 hits[i].pc = 0;
67985 continue;
67986 }
67987 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67988 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67989 hits[i].hits = hits[i].pc = 0;
67990 }
67991 }
67992 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67993 * Add the current hit(s) and flush the write-queue out
67994 * to the global buffer:
67995 */
67996 - atomic_add(nr_hits, &prof_buffer[pc]);
67997 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67998 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67999 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68000 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68001 hits[i].pc = hits[i].hits = 0;
68002 }
68003 out:
68004 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68005 {
68006 unsigned long pc;
68007 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68008 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68009 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68010 }
68011 #endif /* !CONFIG_SMP */
68012
68013 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68014 return -EFAULT;
68015 buf++; p++; count--; read++;
68016 }
68017 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68018 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68019 if (copy_to_user(buf, (void *)pnt, count))
68020 return -EFAULT;
68021 read += count;
68022 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68023 }
68024 #endif
68025 profile_discard_flip_buffers();
68026 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68027 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68028 return count;
68029 }
68030
68031 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68032 index 67d1fdd..1af21e2 100644
68033 --- a/kernel/ptrace.c
68034 +++ b/kernel/ptrace.c
68035 @@ -172,7 +172,8 @@ int ptrace_check_attach(struct task_struct *child, bool ignore_state)
68036 return ret;
68037 }
68038
68039 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
68040 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
68041 + unsigned int log)
68042 {
68043 const struct cred *cred = current_cred(), *tcred;
68044
68045 @@ -198,7 +199,8 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
68046 cred->gid == tcred->sgid &&
68047 cred->gid == tcred->gid))
68048 goto ok;
68049 - if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
68050 + if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
68051 + (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
68052 goto ok;
68053 rcu_read_unlock();
68054 return -EPERM;
68055 @@ -207,7 +209,9 @@ ok:
68056 smp_rmb();
68057 if (task->mm)
68058 dumpable = get_dumpable(task->mm);
68059 - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
68060 + if (!dumpable &&
68061 + ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
68062 + (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
68063 return -EPERM;
68064
68065 return security_ptrace_access_check(task, mode);
68066 @@ -217,7 +221,16 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
68067 {
68068 int err;
68069 task_lock(task);
68070 - err = __ptrace_may_access(task, mode);
68071 + err = __ptrace_may_access(task, mode, 0);
68072 + task_unlock(task);
68073 + return !err;
68074 +}
68075 +
68076 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
68077 +{
68078 + int err;
68079 + task_lock(task);
68080 + err = __ptrace_may_access(task, mode, 1);
68081 task_unlock(task);
68082 return !err;
68083 }
68084 @@ -262,7 +275,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68085 goto out;
68086
68087 task_lock(task);
68088 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
68089 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
68090 task_unlock(task);
68091 if (retval)
68092 goto unlock_creds;
68093 @@ -277,7 +290,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68094 task->ptrace = PT_PTRACED;
68095 if (seize)
68096 task->ptrace |= PT_SEIZED;
68097 - if (task_ns_capable(task, CAP_SYS_PTRACE))
68098 + if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
68099 task->ptrace |= PT_PTRACE_CAP;
68100
68101 __ptrace_link(task, current);
68102 @@ -472,6 +485,8 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68103 {
68104 int copied = 0;
68105
68106 + pax_track_stack();
68107 +
68108 while (len > 0) {
68109 char buf[128];
68110 int this_len, retval;
68111 @@ -483,7 +498,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68112 break;
68113 return -EIO;
68114 }
68115 - if (copy_to_user(dst, buf, retval))
68116 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68117 return -EFAULT;
68118 copied += retval;
68119 src += retval;
68120 @@ -497,6 +512,8 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds
68121 {
68122 int copied = 0;
68123
68124 + pax_track_stack();
68125 +
68126 while (len > 0) {
68127 char buf[128];
68128 int this_len, retval;
68129 @@ -680,10 +697,12 @@ int ptrace_request(struct task_struct *child, long request,
68130 bool seized = child->ptrace & PT_SEIZED;
68131 int ret = -EIO;
68132 siginfo_t siginfo, *si;
68133 - void __user *datavp = (void __user *) data;
68134 + void __user *datavp = (__force void __user *) data;
68135 unsigned long __user *datalp = datavp;
68136 unsigned long flags;
68137
68138 + pax_track_stack();
68139 +
68140 switch (request) {
68141 case PTRACE_PEEKTEXT:
68142 case PTRACE_PEEKDATA:
68143 @@ -882,14 +901,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68144 goto out;
68145 }
68146
68147 + if (gr_handle_ptrace(child, request)) {
68148 + ret = -EPERM;
68149 + goto out_put_task_struct;
68150 + }
68151 +
68152 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68153 ret = ptrace_attach(child, request, data);
68154 /*
68155 * Some architectures need to do book-keeping after
68156 * a ptrace attach.
68157 */
68158 - if (!ret)
68159 + if (!ret) {
68160 arch_ptrace_attach(child);
68161 + gr_audit_ptrace(child);
68162 + }
68163 goto out_put_task_struct;
68164 }
68165
68166 @@ -915,7 +941,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68167 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68168 if (copied != sizeof(tmp))
68169 return -EIO;
68170 - return put_user(tmp, (unsigned long __user *)data);
68171 + return put_user(tmp, (__force unsigned long __user *)data);
68172 }
68173
68174 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68175 @@ -938,6 +964,8 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
68176 siginfo_t siginfo;
68177 int ret;
68178
68179 + pax_track_stack();
68180 +
68181 switch (request) {
68182 case PTRACE_PEEKTEXT:
68183 case PTRACE_PEEKDATA:
68184 @@ -1025,14 +1053,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68185 goto out;
68186 }
68187
68188 + if (gr_handle_ptrace(child, request)) {
68189 + ret = -EPERM;
68190 + goto out_put_task_struct;
68191 + }
68192 +
68193 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68194 ret = ptrace_attach(child, request, data);
68195 /*
68196 * Some architectures need to do book-keeping after
68197 * a ptrace attach.
68198 */
68199 - if (!ret)
68200 + if (!ret) {
68201 arch_ptrace_attach(child);
68202 + gr_audit_ptrace(child);
68203 + }
68204 goto out_put_task_struct;
68205 }
68206
68207 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68208 index 98f51b1..30b950c 100644
68209 --- a/kernel/rcutorture.c
68210 +++ b/kernel/rcutorture.c
68211 @@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68212 { 0 };
68213 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68214 { 0 };
68215 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68216 -static atomic_t n_rcu_torture_alloc;
68217 -static atomic_t n_rcu_torture_alloc_fail;
68218 -static atomic_t n_rcu_torture_free;
68219 -static atomic_t n_rcu_torture_mberror;
68220 -static atomic_t n_rcu_torture_error;
68221 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68222 +static atomic_unchecked_t n_rcu_torture_alloc;
68223 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68224 +static atomic_unchecked_t n_rcu_torture_free;
68225 +static atomic_unchecked_t n_rcu_torture_mberror;
68226 +static atomic_unchecked_t n_rcu_torture_error;
68227 static long n_rcu_torture_boost_ktrerror;
68228 static long n_rcu_torture_boost_rterror;
68229 static long n_rcu_torture_boost_failure;
68230 @@ -223,11 +223,11 @@ rcu_torture_alloc(void)
68231
68232 spin_lock_bh(&rcu_torture_lock);
68233 if (list_empty(&rcu_torture_freelist)) {
68234 - atomic_inc(&n_rcu_torture_alloc_fail);
68235 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68236 spin_unlock_bh(&rcu_torture_lock);
68237 return NULL;
68238 }
68239 - atomic_inc(&n_rcu_torture_alloc);
68240 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68241 p = rcu_torture_freelist.next;
68242 list_del_init(p);
68243 spin_unlock_bh(&rcu_torture_lock);
68244 @@ -240,7 +240,7 @@ rcu_torture_alloc(void)
68245 static void
68246 rcu_torture_free(struct rcu_torture *p)
68247 {
68248 - atomic_inc(&n_rcu_torture_free);
68249 + atomic_inc_unchecked(&n_rcu_torture_free);
68250 spin_lock_bh(&rcu_torture_lock);
68251 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68252 spin_unlock_bh(&rcu_torture_lock);
68253 @@ -360,7 +360,7 @@ rcu_torture_cb(struct rcu_head *p)
68254 i = rp->rtort_pipe_count;
68255 if (i > RCU_TORTURE_PIPE_LEN)
68256 i = RCU_TORTURE_PIPE_LEN;
68257 - atomic_inc(&rcu_torture_wcount[i]);
68258 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68259 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68260 rp->rtort_mbtest = 0;
68261 rcu_torture_free(rp);
68262 @@ -407,7 +407,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68263 i = rp->rtort_pipe_count;
68264 if (i > RCU_TORTURE_PIPE_LEN)
68265 i = RCU_TORTURE_PIPE_LEN;
68266 - atomic_inc(&rcu_torture_wcount[i]);
68267 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68268 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68269 rp->rtort_mbtest = 0;
68270 list_del(&rp->rtort_free);
68271 @@ -882,7 +882,7 @@ rcu_torture_writer(void *arg)
68272 i = old_rp->rtort_pipe_count;
68273 if (i > RCU_TORTURE_PIPE_LEN)
68274 i = RCU_TORTURE_PIPE_LEN;
68275 - atomic_inc(&rcu_torture_wcount[i]);
68276 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68277 old_rp->rtort_pipe_count++;
68278 cur_ops->deferred_free(old_rp);
68279 }
68280 @@ -950,7 +950,7 @@ static void rcu_torture_timer(unsigned long unused)
68281 return;
68282 }
68283 if (p->rtort_mbtest == 0)
68284 - atomic_inc(&n_rcu_torture_mberror);
68285 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68286 spin_lock(&rand_lock);
68287 cur_ops->read_delay(&rand);
68288 n_rcu_torture_timers++;
68289 @@ -1011,7 +1011,7 @@ rcu_torture_reader(void *arg)
68290 continue;
68291 }
68292 if (p->rtort_mbtest == 0)
68293 - atomic_inc(&n_rcu_torture_mberror);
68294 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68295 cur_ops->read_delay(&rand);
68296 preempt_disable();
68297 pipe_count = p->rtort_pipe_count;
68298 @@ -1070,16 +1070,16 @@ rcu_torture_printk(char *page)
68299 rcu_torture_current,
68300 rcu_torture_current_version,
68301 list_empty(&rcu_torture_freelist),
68302 - atomic_read(&n_rcu_torture_alloc),
68303 - atomic_read(&n_rcu_torture_alloc_fail),
68304 - atomic_read(&n_rcu_torture_free),
68305 - atomic_read(&n_rcu_torture_mberror),
68306 + atomic_read_unchecked(&n_rcu_torture_alloc),
68307 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68308 + atomic_read_unchecked(&n_rcu_torture_free),
68309 + atomic_read_unchecked(&n_rcu_torture_mberror),
68310 n_rcu_torture_boost_ktrerror,
68311 n_rcu_torture_boost_rterror,
68312 n_rcu_torture_boost_failure,
68313 n_rcu_torture_boosts,
68314 n_rcu_torture_timers);
68315 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68316 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68317 n_rcu_torture_boost_ktrerror != 0 ||
68318 n_rcu_torture_boost_rterror != 0 ||
68319 n_rcu_torture_boost_failure != 0)
68320 @@ -1087,7 +1087,7 @@ rcu_torture_printk(char *page)
68321 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68322 if (i > 1) {
68323 cnt += sprintf(&page[cnt], "!!! ");
68324 - atomic_inc(&n_rcu_torture_error);
68325 + atomic_inc_unchecked(&n_rcu_torture_error);
68326 WARN_ON_ONCE(1);
68327 }
68328 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68329 @@ -1101,7 +1101,7 @@ rcu_torture_printk(char *page)
68330 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68331 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68332 cnt += sprintf(&page[cnt], " %d",
68333 - atomic_read(&rcu_torture_wcount[i]));
68334 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68335 }
68336 cnt += sprintf(&page[cnt], "\n");
68337 if (cur_ops->stats)
68338 @@ -1410,7 +1410,7 @@ rcu_torture_cleanup(void)
68339
68340 if (cur_ops->cleanup)
68341 cur_ops->cleanup();
68342 - if (atomic_read(&n_rcu_torture_error))
68343 + if (atomic_read_unchecked(&n_rcu_torture_error))
68344 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68345 else
68346 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
68347 @@ -1474,17 +1474,17 @@ rcu_torture_init(void)
68348
68349 rcu_torture_current = NULL;
68350 rcu_torture_current_version = 0;
68351 - atomic_set(&n_rcu_torture_alloc, 0);
68352 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68353 - atomic_set(&n_rcu_torture_free, 0);
68354 - atomic_set(&n_rcu_torture_mberror, 0);
68355 - atomic_set(&n_rcu_torture_error, 0);
68356 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68357 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68358 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68359 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68360 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68361 n_rcu_torture_boost_ktrerror = 0;
68362 n_rcu_torture_boost_rterror = 0;
68363 n_rcu_torture_boost_failure = 0;
68364 n_rcu_torture_boosts = 0;
68365 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68366 - atomic_set(&rcu_torture_wcount[i], 0);
68367 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68368 for_each_possible_cpu(cpu) {
68369 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68370 per_cpu(rcu_torture_count, cpu)[i] = 0;
68371 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68372 index ba06207..85d8ba8 100644
68373 --- a/kernel/rcutree.c
68374 +++ b/kernel/rcutree.c
68375 @@ -356,9 +356,9 @@ void rcu_enter_nohz(void)
68376 }
68377 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68378 smp_mb__before_atomic_inc(); /* See above. */
68379 - atomic_inc(&rdtp->dynticks);
68380 + atomic_inc_unchecked(&rdtp->dynticks);
68381 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68382 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68383 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68384 local_irq_restore(flags);
68385
68386 /* If the interrupt queued a callback, get out of dyntick mode. */
68387 @@ -387,10 +387,10 @@ void rcu_exit_nohz(void)
68388 return;
68389 }
68390 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68391 - atomic_inc(&rdtp->dynticks);
68392 + atomic_inc_unchecked(&rdtp->dynticks);
68393 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68394 smp_mb__after_atomic_inc(); /* See above. */
68395 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68396 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68397 local_irq_restore(flags);
68398 }
68399
68400 @@ -406,14 +406,14 @@ void rcu_nmi_enter(void)
68401 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68402
68403 if (rdtp->dynticks_nmi_nesting == 0 &&
68404 - (atomic_read(&rdtp->dynticks) & 0x1))
68405 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68406 return;
68407 rdtp->dynticks_nmi_nesting++;
68408 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68409 - atomic_inc(&rdtp->dynticks);
68410 + atomic_inc_unchecked(&rdtp->dynticks);
68411 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68412 smp_mb__after_atomic_inc(); /* See above. */
68413 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68414 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68415 }
68416
68417 /**
68418 @@ -432,9 +432,9 @@ void rcu_nmi_exit(void)
68419 return;
68420 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68421 smp_mb__before_atomic_inc(); /* See above. */
68422 - atomic_inc(&rdtp->dynticks);
68423 + atomic_inc_unchecked(&rdtp->dynticks);
68424 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68425 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68426 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68427 }
68428
68429 /**
68430 @@ -469,7 +469,7 @@ void rcu_irq_exit(void)
68431 */
68432 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68433 {
68434 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68435 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68436 return 0;
68437 }
68438
68439 @@ -484,7 +484,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68440 unsigned long curr;
68441 unsigned long snap;
68442
68443 - curr = (unsigned long)atomic_add_return(0, &rdp->dynticks->dynticks);
68444 + curr = (unsigned long)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68445 snap = (unsigned long)rdp->dynticks_snap;
68446
68447 /*
68448 @@ -1470,7 +1470,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68449 /*
68450 * Do softirq processing for the current CPU.
68451 */
68452 -static void rcu_process_callbacks(struct softirq_action *unused)
68453 +static void rcu_process_callbacks(void)
68454 {
68455 __rcu_process_callbacks(&rcu_sched_state,
68456 &__get_cpu_var(rcu_sched_data));
68457 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68458 index 01b2ccd..4f5d80a 100644
68459 --- a/kernel/rcutree.h
68460 +++ b/kernel/rcutree.h
68461 @@ -86,7 +86,7 @@
68462 struct rcu_dynticks {
68463 int dynticks_nesting; /* Track irq/process nesting level. */
68464 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68465 - atomic_t dynticks; /* Even value for dynticks-idle, else odd. */
68466 + atomic_unchecked_t dynticks; /* Even value for dynticks-idle, else odd. */
68467 };
68468
68469 /* RCU's kthread states for tracing. */
68470 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68471 index 8aafbb8..2fca109 100644
68472 --- a/kernel/rcutree_plugin.h
68473 +++ b/kernel/rcutree_plugin.h
68474 @@ -822,7 +822,7 @@ void synchronize_rcu_expedited(void)
68475
68476 /* Clean up and exit. */
68477 smp_mb(); /* ensure expedited GP seen before counter increment. */
68478 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68479 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68480 unlock_mb_ret:
68481 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68482 mb_ret:
68483 @@ -1774,8 +1774,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
68484
68485 #else /* #ifndef CONFIG_SMP */
68486
68487 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68488 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68489 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68490 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68491
68492 static int synchronize_sched_expedited_cpu_stop(void *data)
68493 {
68494 @@ -1830,7 +1830,7 @@ void synchronize_sched_expedited(void)
68495 int firstsnap, s, snap, trycount = 0;
68496
68497 /* Note that atomic_inc_return() implies full memory barrier. */
68498 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68499 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68500 get_online_cpus();
68501
68502 /*
68503 @@ -1851,7 +1851,7 @@ void synchronize_sched_expedited(void)
68504 }
68505
68506 /* Check to see if someone else did our work for us. */
68507 - s = atomic_read(&sync_sched_expedited_done);
68508 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68509 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68510 smp_mb(); /* ensure test happens before caller kfree */
68511 return;
68512 @@ -1866,7 +1866,7 @@ void synchronize_sched_expedited(void)
68513 * grace period works for us.
68514 */
68515 get_online_cpus();
68516 - snap = atomic_read(&sync_sched_expedited_started) - 1;
68517 + snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
68518 smp_mb(); /* ensure read is before try_stop_cpus(). */
68519 }
68520
68521 @@ -1877,12 +1877,12 @@ void synchronize_sched_expedited(void)
68522 * than we did beat us to the punch.
68523 */
68524 do {
68525 - s = atomic_read(&sync_sched_expedited_done);
68526 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68527 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68528 smp_mb(); /* ensure test happens before caller kfree */
68529 break;
68530 }
68531 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68532 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68533
68534 put_online_cpus();
68535 }
68536 @@ -1953,7 +1953,7 @@ int rcu_needs_cpu(int cpu)
68537 for_each_online_cpu(thatcpu) {
68538 if (thatcpu == cpu)
68539 continue;
68540 - snap = atomic_add_return(0, &per_cpu(rcu_dynticks,
68541 + snap = atomic_add_return_unchecked(0, &per_cpu(rcu_dynticks,
68542 thatcpu).dynticks);
68543 smp_mb(); /* Order sampling of snap with end of grace period. */
68544 if ((snap & 0x1) != 0) {
68545 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68546 index 3b0c098..43ba2d8 100644
68547 --- a/kernel/rcutree_trace.c
68548 +++ b/kernel/rcutree_trace.c
68549 @@ -74,7 +74,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68550 rdp->qs_pending);
68551 #ifdef CONFIG_NO_HZ
68552 seq_printf(m, " dt=%d/%d/%d df=%lu",
68553 - atomic_read(&rdp->dynticks->dynticks),
68554 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68555 rdp->dynticks->dynticks_nesting,
68556 rdp->dynticks->dynticks_nmi_nesting,
68557 rdp->dynticks_fqs);
68558 @@ -148,7 +148,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68559 rdp->qs_pending);
68560 #ifdef CONFIG_NO_HZ
68561 seq_printf(m, ",%d,%d,%d,%lu",
68562 - atomic_read(&rdp->dynticks->dynticks),
68563 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68564 rdp->dynticks->dynticks_nesting,
68565 rdp->dynticks->dynticks_nmi_nesting,
68566 rdp->dynticks_fqs);
68567 diff --git a/kernel/relay.c b/kernel/relay.c
68568 index 859ea5a..096e2fe 100644
68569 --- a/kernel/relay.c
68570 +++ b/kernel/relay.c
68571 @@ -1236,6 +1236,8 @@ static ssize_t subbuf_splice_actor(struct file *in,
68572 };
68573 ssize_t ret;
68574
68575 + pax_track_stack();
68576 +
68577 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
68578 return 0;
68579 if (splice_grow_spd(pipe, &spd))
68580 diff --git a/kernel/resource.c b/kernel/resource.c
68581 index c8dc249..f1e2359 100644
68582 --- a/kernel/resource.c
68583 +++ b/kernel/resource.c
68584 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68585
68586 static int __init ioresources_init(void)
68587 {
68588 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68589 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68590 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68591 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68592 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68593 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68594 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68595 +#endif
68596 +#else
68597 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68598 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68599 +#endif
68600 return 0;
68601 }
68602 __initcall(ioresources_init);
68603 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68604 index 5c9ccd3..a35e22b 100644
68605 --- a/kernel/rtmutex-tester.c
68606 +++ b/kernel/rtmutex-tester.c
68607 @@ -20,7 +20,7 @@
68608 #define MAX_RT_TEST_MUTEXES 8
68609
68610 static spinlock_t rttest_lock;
68611 -static atomic_t rttest_event;
68612 +static atomic_unchecked_t rttest_event;
68613
68614 struct test_thread_data {
68615 int opcode;
68616 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68617
68618 case RTTEST_LOCKCONT:
68619 td->mutexes[td->opdata] = 1;
68620 - td->event = atomic_add_return(1, &rttest_event);
68621 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68622 return 0;
68623
68624 case RTTEST_RESET:
68625 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68626 return 0;
68627
68628 case RTTEST_RESETEVENT:
68629 - atomic_set(&rttest_event, 0);
68630 + atomic_set_unchecked(&rttest_event, 0);
68631 return 0;
68632
68633 default:
68634 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68635 return ret;
68636
68637 td->mutexes[id] = 1;
68638 - td->event = atomic_add_return(1, &rttest_event);
68639 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68640 rt_mutex_lock(&mutexes[id]);
68641 - td->event = atomic_add_return(1, &rttest_event);
68642 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68643 td->mutexes[id] = 4;
68644 return 0;
68645
68646 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68647 return ret;
68648
68649 td->mutexes[id] = 1;
68650 - td->event = atomic_add_return(1, &rttest_event);
68651 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68652 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
68653 - td->event = atomic_add_return(1, &rttest_event);
68654 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68655 td->mutexes[id] = ret ? 0 : 4;
68656 return ret ? -EINTR : 0;
68657
68658 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68659 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
68660 return ret;
68661
68662 - td->event = atomic_add_return(1, &rttest_event);
68663 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68664 rt_mutex_unlock(&mutexes[id]);
68665 - td->event = atomic_add_return(1, &rttest_event);
68666 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68667 td->mutexes[id] = 0;
68668 return 0;
68669
68670 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68671 break;
68672
68673 td->mutexes[dat] = 2;
68674 - td->event = atomic_add_return(1, &rttest_event);
68675 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68676 break;
68677
68678 default:
68679 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68680 return;
68681
68682 td->mutexes[dat] = 3;
68683 - td->event = atomic_add_return(1, &rttest_event);
68684 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68685 break;
68686
68687 case RTTEST_LOCKNOWAIT:
68688 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68689 return;
68690
68691 td->mutexes[dat] = 1;
68692 - td->event = atomic_add_return(1, &rttest_event);
68693 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68694 return;
68695
68696 default:
68697 diff --git a/kernel/sched.c b/kernel/sched.c
68698 index b50b0f0..1c6c591 100644
68699 --- a/kernel/sched.c
68700 +++ b/kernel/sched.c
68701 @@ -4264,6 +4264,8 @@ static void __sched __schedule(void)
68702 struct rq *rq;
68703 int cpu;
68704
68705 + pax_track_stack();
68706 +
68707 need_resched:
68708 preempt_disable();
68709 cpu = smp_processor_id();
68710 @@ -4950,6 +4952,8 @@ int can_nice(const struct task_struct *p, const int nice)
68711 /* convert nice value [19,-20] to rlimit style value [1,40] */
68712 int nice_rlim = 20 - nice;
68713
68714 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68715 +
68716 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68717 capable(CAP_SYS_NICE));
68718 }
68719 @@ -4983,7 +4987,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68720 if (nice > 19)
68721 nice = 19;
68722
68723 - if (increment < 0 && !can_nice(current, nice))
68724 + if (increment < 0 && (!can_nice(current, nice) ||
68725 + gr_handle_chroot_nice()))
68726 return -EPERM;
68727
68728 retval = security_task_setnice(current, nice);
68729 @@ -5127,6 +5132,7 @@ recheck:
68730 unsigned long rlim_rtprio =
68731 task_rlimit(p, RLIMIT_RTPRIO);
68732
68733 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68734 /* can't set/change the rt policy */
68735 if (policy != p->policy && !rlim_rtprio)
68736 return -EPERM;
68737 diff --git a/kernel/sched_autogroup.c b/kernel/sched_autogroup.c
68738 index 429242f..d7cca82 100644
68739 --- a/kernel/sched_autogroup.c
68740 +++ b/kernel/sched_autogroup.c
68741 @@ -7,7 +7,7 @@
68742
68743 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
68744 static struct autogroup autogroup_default;
68745 -static atomic_t autogroup_seq_nr;
68746 +static atomic_unchecked_t autogroup_seq_nr;
68747
68748 static void __init autogroup_init(struct task_struct *init_task)
68749 {
68750 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
68751
68752 kref_init(&ag->kref);
68753 init_rwsem(&ag->lock);
68754 - ag->id = atomic_inc_return(&autogroup_seq_nr);
68755 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
68756 ag->tg = tg;
68757 #ifdef CONFIG_RT_GROUP_SCHED
68758 /*
68759 diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
68760 index bc8ee99..b6f6492 100644
68761 --- a/kernel/sched_fair.c
68762 +++ b/kernel/sched_fair.c
68763 @@ -4062,7 +4062,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
68764 * run_rebalance_domains is triggered when needed from the scheduler tick.
68765 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
68766 */
68767 -static void run_rebalance_domains(struct softirq_action *h)
68768 +static void run_rebalance_domains(void)
68769 {
68770 int this_cpu = smp_processor_id();
68771 struct rq *this_rq = cpu_rq(this_cpu);
68772 diff --git a/kernel/signal.c b/kernel/signal.c
68773 index 195331c..e89634ce 100644
68774 --- a/kernel/signal.c
68775 +++ b/kernel/signal.c
68776 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cachep;
68777
68778 int print_fatal_signals __read_mostly;
68779
68780 -static void __user *sig_handler(struct task_struct *t, int sig)
68781 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
68782 {
68783 return t->sighand->action[sig - 1].sa.sa_handler;
68784 }
68785
68786 -static int sig_handler_ignored(void __user *handler, int sig)
68787 +static int sig_handler_ignored(__sighandler_t handler, int sig)
68788 {
68789 /* Is it explicitly or implicitly ignored? */
68790 return handler == SIG_IGN ||
68791 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68792 static int sig_task_ignored(struct task_struct *t, int sig,
68793 int from_ancestor_ns)
68794 {
68795 - void __user *handler;
68796 + __sighandler_t handler;
68797
68798 handler = sig_handler(t, sig);
68799
68800 @@ -364,6 +364,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68801 atomic_inc(&user->sigpending);
68802 rcu_read_unlock();
68803
68804 + if (!override_rlimit)
68805 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68806 +
68807 if (override_rlimit ||
68808 atomic_read(&user->sigpending) <=
68809 task_rlimit(t, RLIMIT_SIGPENDING)) {
68810 @@ -488,7 +491,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68811
68812 int unhandled_signal(struct task_struct *tsk, int sig)
68813 {
68814 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68815 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68816 if (is_global_init(tsk))
68817 return 1;
68818 if (handler != SIG_IGN && handler != SIG_DFL)
68819 @@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68820 }
68821 }
68822
68823 + /* allow glibc communication via tgkill to other threads in our
68824 + thread group */
68825 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68826 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68827 + && gr_handle_signal(t, sig))
68828 + return -EPERM;
68829 +
68830 return security_task_kill(t, info, sig, 0);
68831 }
68832
68833 @@ -1165,7 +1175,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68834 return send_signal(sig, info, p, 1);
68835 }
68836
68837 -static int
68838 +int
68839 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68840 {
68841 return send_signal(sig, info, t, 0);
68842 @@ -1202,6 +1212,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68843 unsigned long int flags;
68844 int ret, blocked, ignored;
68845 struct k_sigaction *action;
68846 + int is_unhandled = 0;
68847
68848 spin_lock_irqsave(&t->sighand->siglock, flags);
68849 action = &t->sighand->action[sig-1];
68850 @@ -1216,9 +1227,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68851 }
68852 if (action->sa.sa_handler == SIG_DFL)
68853 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68854 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68855 + is_unhandled = 1;
68856 ret = specific_send_sig_info(sig, info, t);
68857 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68858
68859 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
68860 + normal operation */
68861 + if (is_unhandled) {
68862 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68863 + gr_handle_crash(t, sig);
68864 + }
68865 +
68866 return ret;
68867 }
68868
68869 @@ -1285,8 +1305,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68870 ret = check_kill_permission(sig, info, p);
68871 rcu_read_unlock();
68872
68873 - if (!ret && sig)
68874 + if (!ret && sig) {
68875 ret = do_send_sig_info(sig, info, p, true);
68876 + if (!ret)
68877 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68878 + }
68879
68880 return ret;
68881 }
68882 @@ -1909,6 +1932,8 @@ static void ptrace_do_notify(int signr, int exit_code, int why)
68883 {
68884 siginfo_t info;
68885
68886 + pax_track_stack();
68887 +
68888 memset(&info, 0, sizeof info);
68889 info.si_signo = signr;
68890 info.si_code = exit_code;
68891 @@ -2746,7 +2771,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68892 int error = -ESRCH;
68893
68894 rcu_read_lock();
68895 - p = find_task_by_vpid(pid);
68896 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68897 + /* allow glibc communication via tgkill to other threads in our
68898 + thread group */
68899 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68900 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
68901 + p = find_task_by_vpid_unrestricted(pid);
68902 + else
68903 +#endif
68904 + p = find_task_by_vpid(pid);
68905 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68906 error = check_kill_permission(sig, info, p);
68907 /*
68908 diff --git a/kernel/smp.c b/kernel/smp.c
68909 index fb67dfa..f819e2e 100644
68910 --- a/kernel/smp.c
68911 +++ b/kernel/smp.c
68912 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68913 }
68914 EXPORT_SYMBOL(smp_call_function);
68915
68916 -void ipi_call_lock(void)
68917 +void ipi_call_lock(void) __acquires(call_function.lock)
68918 {
68919 raw_spin_lock(&call_function.lock);
68920 }
68921
68922 -void ipi_call_unlock(void)
68923 +void ipi_call_unlock(void) __releases(call_function.lock)
68924 {
68925 raw_spin_unlock(&call_function.lock);
68926 }
68927
68928 -void ipi_call_lock_irq(void)
68929 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
68930 {
68931 raw_spin_lock_irq(&call_function.lock);
68932 }
68933
68934 -void ipi_call_unlock_irq(void)
68935 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
68936 {
68937 raw_spin_unlock_irq(&call_function.lock);
68938 }
68939 diff --git a/kernel/softirq.c b/kernel/softirq.c
68940 index fca82c3..1db9690 100644
68941 --- a/kernel/softirq.c
68942 +++ b/kernel/softirq.c
68943 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68944
68945 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68946
68947 -char *softirq_to_name[NR_SOFTIRQS] = {
68948 +const char * const softirq_to_name[NR_SOFTIRQS] = {
68949 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68950 "TASKLET", "SCHED", "HRTIMER", "RCU"
68951 };
68952 @@ -235,7 +235,7 @@ restart:
68953 kstat_incr_softirqs_this_cpu(vec_nr);
68954
68955 trace_softirq_entry(vec_nr);
68956 - h->action(h);
68957 + h->action();
68958 trace_softirq_exit(vec_nr);
68959 if (unlikely(prev_count != preempt_count())) {
68960 printk(KERN_ERR "huh, entered softirq %u %s %p"
68961 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
68962 local_irq_restore(flags);
68963 }
68964
68965 -void open_softirq(int nr, void (*action)(struct softirq_action *))
68966 +void open_softirq(int nr, void (*action)(void))
68967 {
68968 - softirq_vec[nr].action = action;
68969 + pax_open_kernel();
68970 + *(void **)&softirq_vec[nr].action = action;
68971 + pax_close_kernel();
68972 }
68973
68974 /*
68975 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68976
68977 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68978
68979 -static void tasklet_action(struct softirq_action *a)
68980 +static void tasklet_action(void)
68981 {
68982 struct tasklet_struct *list;
68983
68984 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
68985 }
68986 }
68987
68988 -static void tasklet_hi_action(struct softirq_action *a)
68989 +static void tasklet_hi_action(void)
68990 {
68991 struct tasklet_struct *list;
68992
68993 diff --git a/kernel/sys.c b/kernel/sys.c
68994 index 1dbbe69..e96e1dd 100644
68995 --- a/kernel/sys.c
68996 +++ b/kernel/sys.c
68997 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68998 error = -EACCES;
68999 goto out;
69000 }
69001 +
69002 + if (gr_handle_chroot_setpriority(p, niceval)) {
69003 + error = -EACCES;
69004 + goto out;
69005 + }
69006 +
69007 no_nice = security_task_setnice(p, niceval);
69008 if (no_nice) {
69009 error = no_nice;
69010 @@ -571,6 +577,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69011 goto error;
69012 }
69013
69014 + if (gr_check_group_change(new->gid, new->egid, -1))
69015 + goto error;
69016 +
69017 if (rgid != (gid_t) -1 ||
69018 (egid != (gid_t) -1 && egid != old->gid))
69019 new->sgid = new->egid;
69020 @@ -600,6 +609,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69021 old = current_cred();
69022
69023 retval = -EPERM;
69024 +
69025 + if (gr_check_group_change(gid, gid, gid))
69026 + goto error;
69027 +
69028 if (nsown_capable(CAP_SETGID))
69029 new->gid = new->egid = new->sgid = new->fsgid = gid;
69030 else if (gid == old->gid || gid == old->sgid)
69031 @@ -687,6 +700,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69032 goto error;
69033 }
69034
69035 + if (gr_check_user_change(new->uid, new->euid, -1))
69036 + goto error;
69037 +
69038 if (new->uid != old->uid) {
69039 retval = set_user(new);
69040 if (retval < 0)
69041 @@ -731,6 +747,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69042 old = current_cred();
69043
69044 retval = -EPERM;
69045 +
69046 + if (gr_check_crash_uid(uid))
69047 + goto error;
69048 + if (gr_check_user_change(uid, uid, uid))
69049 + goto error;
69050 +
69051 if (nsown_capable(CAP_SETUID)) {
69052 new->suid = new->uid = uid;
69053 if (uid != old->uid) {
69054 @@ -785,6 +807,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69055 goto error;
69056 }
69057
69058 + if (gr_check_user_change(ruid, euid, -1))
69059 + goto error;
69060 +
69061 if (ruid != (uid_t) -1) {
69062 new->uid = ruid;
69063 if (ruid != old->uid) {
69064 @@ -849,6 +874,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69065 goto error;
69066 }
69067
69068 + if (gr_check_group_change(rgid, egid, -1))
69069 + goto error;
69070 +
69071 if (rgid != (gid_t) -1)
69072 new->gid = rgid;
69073 if (egid != (gid_t) -1)
69074 @@ -895,6 +923,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69075 old = current_cred();
69076 old_fsuid = old->fsuid;
69077
69078 + if (gr_check_user_change(-1, -1, uid))
69079 + goto error;
69080 +
69081 if (uid == old->uid || uid == old->euid ||
69082 uid == old->suid || uid == old->fsuid ||
69083 nsown_capable(CAP_SETUID)) {
69084 @@ -905,6 +936,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69085 }
69086 }
69087
69088 +error:
69089 abort_creds(new);
69090 return old_fsuid;
69091
69092 @@ -931,12 +963,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69093 if (gid == old->gid || gid == old->egid ||
69094 gid == old->sgid || gid == old->fsgid ||
69095 nsown_capable(CAP_SETGID)) {
69096 + if (gr_check_group_change(-1, -1, gid))
69097 + goto error;
69098 +
69099 if (gid != old_fsgid) {
69100 new->fsgid = gid;
69101 goto change_okay;
69102 }
69103 }
69104
69105 +error:
69106 abort_creds(new);
69107 return old_fsgid;
69108
69109 @@ -1188,7 +1224,10 @@ static int override_release(char __user *release, int len)
69110 }
69111 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69112 snprintf(buf, len, "2.6.%u%s", v, rest);
69113 - ret = copy_to_user(release, buf, len);
69114 + if (len > sizeof(buf))
69115 + ret = -EFAULT;
69116 + else
69117 + ret = copy_to_user(release, buf, len);
69118 }
69119 return ret;
69120 }
69121 @@ -1242,19 +1281,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69122 return -EFAULT;
69123
69124 down_read(&uts_sem);
69125 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69126 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69127 __OLD_UTS_LEN);
69128 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69129 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69130 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69131 __OLD_UTS_LEN);
69132 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69133 - error |= __copy_to_user(&name->release, &utsname()->release,
69134 + error |= __copy_to_user(name->release, &utsname()->release,
69135 __OLD_UTS_LEN);
69136 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69137 - error |= __copy_to_user(&name->version, &utsname()->version,
69138 + error |= __copy_to_user(name->version, &utsname()->version,
69139 __OLD_UTS_LEN);
69140 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69141 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69142 + error |= __copy_to_user(name->machine, &utsname()->machine,
69143 __OLD_UTS_LEN);
69144 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69145 up_read(&uts_sem);
69146 @@ -1717,7 +1756,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69147 error = get_dumpable(me->mm);
69148 break;
69149 case PR_SET_DUMPABLE:
69150 - if (arg2 < 0 || arg2 > 1) {
69151 + if (arg2 > 1) {
69152 error = -EINVAL;
69153 break;
69154 }
69155 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69156 index 11d65b5..6957b37 100644
69157 --- a/kernel/sysctl.c
69158 +++ b/kernel/sysctl.c
69159 @@ -85,6 +85,13 @@
69160
69161
69162 #if defined(CONFIG_SYSCTL)
69163 +#include <linux/grsecurity.h>
69164 +#include <linux/grinternal.h>
69165 +
69166 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
69167 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
69168 + const int op);
69169 +extern int gr_handle_chroot_sysctl(const int op);
69170
69171 /* External variables not in a header file. */
69172 extern int sysctl_overcommit_memory;
69173 @@ -197,6 +204,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69174 }
69175
69176 #endif
69177 +extern struct ctl_table grsecurity_table[];
69178
69179 static struct ctl_table root_table[];
69180 static struct ctl_table_root sysctl_table_root;
69181 @@ -226,6 +234,20 @@ extern struct ctl_table epoll_table[];
69182 int sysctl_legacy_va_layout;
69183 #endif
69184
69185 +#ifdef CONFIG_PAX_SOFTMODE
69186 +static ctl_table pax_table[] = {
69187 + {
69188 + .procname = "softmode",
69189 + .data = &pax_softmode,
69190 + .maxlen = sizeof(unsigned int),
69191 + .mode = 0600,
69192 + .proc_handler = &proc_dointvec,
69193 + },
69194 +
69195 + { }
69196 +};
69197 +#endif
69198 +
69199 /* The default sysctl tables: */
69200
69201 static struct ctl_table root_table[] = {
69202 @@ -272,6 +294,22 @@ static int max_extfrag_threshold = 1000;
69203 #endif
69204
69205 static struct ctl_table kern_table[] = {
69206 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69207 + {
69208 + .procname = "grsecurity",
69209 + .mode = 0500,
69210 + .child = grsecurity_table,
69211 + },
69212 +#endif
69213 +
69214 +#ifdef CONFIG_PAX_SOFTMODE
69215 + {
69216 + .procname = "pax",
69217 + .mode = 0500,
69218 + .child = pax_table,
69219 + },
69220 +#endif
69221 +
69222 {
69223 .procname = "sched_child_runs_first",
69224 .data = &sysctl_sched_child_runs_first,
69225 @@ -546,7 +584,7 @@ static struct ctl_table kern_table[] = {
69226 .data = &modprobe_path,
69227 .maxlen = KMOD_PATH_LEN,
69228 .mode = 0644,
69229 - .proc_handler = proc_dostring,
69230 + .proc_handler = proc_dostring_modpriv,
69231 },
69232 {
69233 .procname = "modules_disabled",
69234 @@ -713,16 +751,20 @@ static struct ctl_table kern_table[] = {
69235 .extra1 = &zero,
69236 .extra2 = &one,
69237 },
69238 +#endif
69239 {
69240 .procname = "kptr_restrict",
69241 .data = &kptr_restrict,
69242 .maxlen = sizeof(int),
69243 .mode = 0644,
69244 .proc_handler = proc_dmesg_restrict,
69245 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69246 + .extra1 = &two,
69247 +#else
69248 .extra1 = &zero,
69249 +#endif
69250 .extra2 = &two,
69251 },
69252 -#endif
69253 {
69254 .procname = "ngroups_max",
69255 .data = &ngroups_max,
69256 @@ -1205,6 +1247,13 @@ static struct ctl_table vm_table[] = {
69257 .proc_handler = proc_dointvec_minmax,
69258 .extra1 = &zero,
69259 },
69260 + {
69261 + .procname = "heap_stack_gap",
69262 + .data = &sysctl_heap_stack_gap,
69263 + .maxlen = sizeof(sysctl_heap_stack_gap),
69264 + .mode = 0644,
69265 + .proc_handler = proc_doulongvec_minmax,
69266 + },
69267 #else
69268 {
69269 .procname = "nr_trim_pages",
69270 @@ -1709,6 +1758,17 @@ static int test_perm(int mode, int op)
69271 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
69272 {
69273 int mode;
69274 + int error;
69275 +
69276 + if (table->parent != NULL && table->parent->procname != NULL &&
69277 + table->procname != NULL &&
69278 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
69279 + return -EACCES;
69280 + if (gr_handle_chroot_sysctl(op))
69281 + return -EACCES;
69282 + error = gr_handle_sysctl(table, op);
69283 + if (error)
69284 + return error;
69285
69286 if (root->permissions)
69287 mode = root->permissions(root, current->nsproxy, table);
69288 @@ -2113,6 +2173,16 @@ int proc_dostring(struct ctl_table *table, int write,
69289 buffer, lenp, ppos);
69290 }
69291
69292 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69293 + void __user *buffer, size_t *lenp, loff_t *ppos)
69294 +{
69295 + if (write && !capable(CAP_SYS_MODULE))
69296 + return -EPERM;
69297 +
69298 + return _proc_do_string(table->data, table->maxlen, write,
69299 + buffer, lenp, ppos);
69300 +}
69301 +
69302 static size_t proc_skip_spaces(char **buf)
69303 {
69304 size_t ret;
69305 @@ -2218,6 +2288,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69306 len = strlen(tmp);
69307 if (len > *size)
69308 len = *size;
69309 + if (len > sizeof(tmp))
69310 + len = sizeof(tmp);
69311 if (copy_to_user(*buf, tmp, len))
69312 return -EFAULT;
69313 *size -= len;
69314 @@ -2534,8 +2606,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69315 *i = val;
69316 } else {
69317 val = convdiv * (*i) / convmul;
69318 - if (!first)
69319 + if (!first) {
69320 err = proc_put_char(&buffer, &left, '\t');
69321 + if (err)
69322 + break;
69323 + }
69324 err = proc_put_long(&buffer, &left, val, false);
69325 if (err)
69326 break;
69327 @@ -2930,6 +3005,12 @@ int proc_dostring(struct ctl_table *table, int write,
69328 return -ENOSYS;
69329 }
69330
69331 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69332 + void __user *buffer, size_t *lenp, loff_t *ppos)
69333 +{
69334 + return -ENOSYS;
69335 +}
69336 +
69337 int proc_dointvec(struct ctl_table *table, int write,
69338 void __user *buffer, size_t *lenp, loff_t *ppos)
69339 {
69340 @@ -2986,6 +3067,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69341 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69342 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69343 EXPORT_SYMBOL(proc_dostring);
69344 +EXPORT_SYMBOL(proc_dostring_modpriv);
69345 EXPORT_SYMBOL(proc_doulongvec_minmax);
69346 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69347 EXPORT_SYMBOL(register_sysctl_table);
69348 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69349 index 2ce1b30..82bf0a4 100644
69350 --- a/kernel/sysctl_binary.c
69351 +++ b/kernel/sysctl_binary.c
69352 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69353 int i;
69354
69355 set_fs(KERNEL_DS);
69356 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69357 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69358 set_fs(old_fs);
69359 if (result < 0)
69360 goto out_kfree;
69361 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69362 }
69363
69364 set_fs(KERNEL_DS);
69365 - result = vfs_write(file, buffer, str - buffer, &pos);
69366 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69367 set_fs(old_fs);
69368 if (result < 0)
69369 goto out_kfree;
69370 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69371 int i;
69372
69373 set_fs(KERNEL_DS);
69374 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69375 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69376 set_fs(old_fs);
69377 if (result < 0)
69378 goto out_kfree;
69379 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69380 }
69381
69382 set_fs(KERNEL_DS);
69383 - result = vfs_write(file, buffer, str - buffer, &pos);
69384 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69385 set_fs(old_fs);
69386 if (result < 0)
69387 goto out_kfree;
69388 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69389 int i;
69390
69391 set_fs(KERNEL_DS);
69392 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69393 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69394 set_fs(old_fs);
69395 if (result < 0)
69396 goto out;
69397 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69398 __le16 dnaddr;
69399
69400 set_fs(KERNEL_DS);
69401 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69402 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69403 set_fs(old_fs);
69404 if (result < 0)
69405 goto out;
69406 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69407 le16_to_cpu(dnaddr) & 0x3ff);
69408
69409 set_fs(KERNEL_DS);
69410 - result = vfs_write(file, buf, len, &pos);
69411 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69412 set_fs(old_fs);
69413 if (result < 0)
69414 goto out;
69415 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
69416 index 362da65..ab8ef8c 100644
69417 --- a/kernel/sysctl_check.c
69418 +++ b/kernel/sysctl_check.c
69419 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
69420 set_fail(&fail, table, "Directory with extra2");
69421 } else {
69422 if ((table->proc_handler == proc_dostring) ||
69423 + (table->proc_handler == proc_dostring_modpriv) ||
69424 (table->proc_handler == proc_dointvec) ||
69425 (table->proc_handler == proc_dointvec_minmax) ||
69426 (table->proc_handler == proc_dointvec_jiffies) ||
69427 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69428 index e660464..c8b9e67 100644
69429 --- a/kernel/taskstats.c
69430 +++ b/kernel/taskstats.c
69431 @@ -27,9 +27,12 @@
69432 #include <linux/cgroup.h>
69433 #include <linux/fs.h>
69434 #include <linux/file.h>
69435 +#include <linux/grsecurity.h>
69436 #include <net/genetlink.h>
69437 #include <linux/atomic.h>
69438
69439 +extern int gr_is_taskstats_denied(int pid);
69440 +
69441 /*
69442 * Maximum length of a cpumask that can be specified in
69443 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69444 @@ -556,6 +559,9 @@ err:
69445
69446 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69447 {
69448 + if (gr_is_taskstats_denied(current->pid))
69449 + return -EACCES;
69450 +
69451 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69452 return cmd_attr_register_cpumask(info);
69453 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69454 diff --git a/kernel/time.c b/kernel/time.c
69455 index d776062..fa8d186 100644
69456 --- a/kernel/time.c
69457 +++ b/kernel/time.c
69458 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69459 return error;
69460
69461 if (tz) {
69462 + /* we log in do_settimeofday called below, so don't log twice
69463 + */
69464 + if (!tv)
69465 + gr_log_timechange();
69466 +
69467 /* SMP safe, global irq locking makes it work. */
69468 sys_tz = *tz;
69469 update_vsyscall_tz();
69470 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69471 index 8b70c76..923e9f5 100644
69472 --- a/kernel/time/alarmtimer.c
69473 +++ b/kernel/time/alarmtimer.c
69474 @@ -693,7 +693,7 @@ static int __init alarmtimer_init(void)
69475 {
69476 int error = 0;
69477 int i;
69478 - struct k_clock alarm_clock = {
69479 + static struct k_clock alarm_clock = {
69480 .clock_getres = alarm_clock_getres,
69481 .clock_get = alarm_clock_get,
69482 .timer_create = alarm_timer_create,
69483 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69484 index 7a90d02..6d8585a 100644
69485 --- a/kernel/time/tick-broadcast.c
69486 +++ b/kernel/time/tick-broadcast.c
69487 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69488 * then clear the broadcast bit.
69489 */
69490 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69491 - int cpu = smp_processor_id();
69492 + cpu = smp_processor_id();
69493
69494 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69495 tick_broadcast_clear_oneshot(cpu);
69496 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69497 index 6f9798b..f8c4087 100644
69498 --- a/kernel/time/timekeeping.c
69499 +++ b/kernel/time/timekeeping.c
69500 @@ -14,6 +14,7 @@
69501 #include <linux/init.h>
69502 #include <linux/mm.h>
69503 #include <linux/sched.h>
69504 +#include <linux/grsecurity.h>
69505 #include <linux/syscore_ops.h>
69506 #include <linux/clocksource.h>
69507 #include <linux/jiffies.h>
69508 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
69509 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69510 return -EINVAL;
69511
69512 + gr_log_timechange();
69513 +
69514 write_seqlock_irqsave(&xtime_lock, flags);
69515
69516 timekeeping_forward_now();
69517 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69518 index 3258455..f35227d 100644
69519 --- a/kernel/time/timer_list.c
69520 +++ b/kernel/time/timer_list.c
69521 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69522
69523 static void print_name_offset(struct seq_file *m, void *sym)
69524 {
69525 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69526 + SEQ_printf(m, "<%p>", NULL);
69527 +#else
69528 char symname[KSYM_NAME_LEN];
69529
69530 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69531 SEQ_printf(m, "<%pK>", sym);
69532 else
69533 SEQ_printf(m, "%s", symname);
69534 +#endif
69535 }
69536
69537 static void
69538 @@ -112,7 +116,11 @@ next_one:
69539 static void
69540 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69541 {
69542 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69543 + SEQ_printf(m, " .base: %p\n", NULL);
69544 +#else
69545 SEQ_printf(m, " .base: %pK\n", base);
69546 +#endif
69547 SEQ_printf(m, " .index: %d\n",
69548 base->index);
69549 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69550 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69551 {
69552 struct proc_dir_entry *pe;
69553
69554 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69555 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69556 +#else
69557 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69558 +#endif
69559 if (!pe)
69560 return -ENOMEM;
69561 return 0;
69562 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69563 index a5d0a3a..60c7948 100644
69564 --- a/kernel/time/timer_stats.c
69565 +++ b/kernel/time/timer_stats.c
69566 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69567 static unsigned long nr_entries;
69568 static struct entry entries[MAX_ENTRIES];
69569
69570 -static atomic_t overflow_count;
69571 +static atomic_unchecked_t overflow_count;
69572
69573 /*
69574 * The entries are in a hash-table, for fast lookup:
69575 @@ -140,7 +140,7 @@ static void reset_entries(void)
69576 nr_entries = 0;
69577 memset(entries, 0, sizeof(entries));
69578 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
69579 - atomic_set(&overflow_count, 0);
69580 + atomic_set_unchecked(&overflow_count, 0);
69581 }
69582
69583 static struct entry *alloc_entry(void)
69584 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69585 if (likely(entry))
69586 entry->count++;
69587 else
69588 - atomic_inc(&overflow_count);
69589 + atomic_inc_unchecked(&overflow_count);
69590
69591 out_unlock:
69592 raw_spin_unlock_irqrestore(lock, flags);
69593 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69594
69595 static void print_name_offset(struct seq_file *m, unsigned long addr)
69596 {
69597 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69598 + seq_printf(m, "<%p>", NULL);
69599 +#else
69600 char symname[KSYM_NAME_LEN];
69601
69602 if (lookup_symbol_name(addr, symname) < 0)
69603 seq_printf(m, "<%p>", (void *)addr);
69604 else
69605 seq_printf(m, "%s", symname);
69606 +#endif
69607 }
69608
69609 static int tstats_show(struct seq_file *m, void *v)
69610 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69611
69612 seq_puts(m, "Timer Stats Version: v0.2\n");
69613 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69614 - if (atomic_read(&overflow_count))
69615 + if (atomic_read_unchecked(&overflow_count))
69616 seq_printf(m, "Overflow: %d entries\n",
69617 - atomic_read(&overflow_count));
69618 + atomic_read_unchecked(&overflow_count));
69619
69620 for (i = 0; i < nr_entries; i++) {
69621 entry = entries + i;
69622 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
69623 {
69624 struct proc_dir_entry *pe;
69625
69626 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69627 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
69628 +#else
69629 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
69630 +#endif
69631 if (!pe)
69632 return -ENOMEM;
69633 return 0;
69634 diff --git a/kernel/timer.c b/kernel/timer.c
69635 index 8cff361..0fb5cd8 100644
69636 --- a/kernel/timer.c
69637 +++ b/kernel/timer.c
69638 @@ -1304,7 +1304,7 @@ void update_process_times(int user_tick)
69639 /*
69640 * This function runs timers and the timer-tq in bottom half context.
69641 */
69642 -static void run_timer_softirq(struct softirq_action *h)
69643 +static void run_timer_softirq(void)
69644 {
69645 struct tvec_base *base = __this_cpu_read(tvec_bases);
69646
69647 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
69648 index 7c910a5..8b72104 100644
69649 --- a/kernel/trace/blktrace.c
69650 +++ b/kernel/trace/blktrace.c
69651 @@ -323,7 +323,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
69652 struct blk_trace *bt = filp->private_data;
69653 char buf[16];
69654
69655 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
69656 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
69657
69658 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
69659 }
69660 @@ -388,7 +388,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
69661 return 1;
69662
69663 bt = buf->chan->private_data;
69664 - atomic_inc(&bt->dropped);
69665 + atomic_inc_unchecked(&bt->dropped);
69666 return 0;
69667 }
69668
69669 @@ -489,7 +489,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
69670
69671 bt->dir = dir;
69672 bt->dev = dev;
69673 - atomic_set(&bt->dropped, 0);
69674 + atomic_set_unchecked(&bt->dropped, 0);
69675
69676 ret = -EIO;
69677 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
69678 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
69679 index 48d3762..3b61fce 100644
69680 --- a/kernel/trace/ftrace.c
69681 +++ b/kernel/trace/ftrace.c
69682 @@ -1584,12 +1584,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
69683 if (unlikely(ftrace_disabled))
69684 return 0;
69685
69686 + ret = ftrace_arch_code_modify_prepare();
69687 + FTRACE_WARN_ON(ret);
69688 + if (ret)
69689 + return 0;
69690 +
69691 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
69692 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
69693 if (ret) {
69694 ftrace_bug(ret, ip);
69695 - return 0;
69696 }
69697 - return 1;
69698 + return ret ? 0 : 1;
69699 }
69700
69701 /*
69702 @@ -2606,7 +2611,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
69703
69704 int
69705 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
69706 - void *data)
69707 + void *data)
69708 {
69709 struct ftrace_func_probe *entry;
69710 struct ftrace_page *pg;
69711 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
69712 index 17a2d44..85907e2 100644
69713 --- a/kernel/trace/trace.c
69714 +++ b/kernel/trace/trace.c
69715 @@ -3451,6 +3451,8 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
69716 size_t rem;
69717 unsigned int i;
69718
69719 + pax_track_stack();
69720 +
69721 if (splice_grow_spd(pipe, &spd))
69722 return -ENOMEM;
69723
69724 @@ -3926,6 +3928,8 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
69725 int entries, size, i;
69726 size_t ret;
69727
69728 + pax_track_stack();
69729 +
69730 if (splice_grow_spd(pipe, &spd))
69731 return -ENOMEM;
69732
69733 @@ -4093,10 +4097,9 @@ static const struct file_operations tracing_dyn_info_fops = {
69734 };
69735 #endif
69736
69737 -static struct dentry *d_tracer;
69738 -
69739 struct dentry *tracing_init_dentry(void)
69740 {
69741 + static struct dentry *d_tracer;
69742 static int once;
69743
69744 if (d_tracer)
69745 @@ -4116,10 +4119,9 @@ struct dentry *tracing_init_dentry(void)
69746 return d_tracer;
69747 }
69748
69749 -static struct dentry *d_percpu;
69750 -
69751 struct dentry *tracing_dentry_percpu(void)
69752 {
69753 + static struct dentry *d_percpu;
69754 static int once;
69755 struct dentry *d_tracer;
69756
69757 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69758 index c212a7f..7b02394 100644
69759 --- a/kernel/trace/trace_events.c
69760 +++ b/kernel/trace/trace_events.c
69761 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
69762 struct ftrace_module_file_ops {
69763 struct list_head list;
69764 struct module *mod;
69765 - struct file_operations id;
69766 - struct file_operations enable;
69767 - struct file_operations format;
69768 - struct file_operations filter;
69769 };
69770
69771 static struct ftrace_module_file_ops *
69772 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
69773
69774 file_ops->mod = mod;
69775
69776 - file_ops->id = ftrace_event_id_fops;
69777 - file_ops->id.owner = mod;
69778 -
69779 - file_ops->enable = ftrace_enable_fops;
69780 - file_ops->enable.owner = mod;
69781 -
69782 - file_ops->filter = ftrace_event_filter_fops;
69783 - file_ops->filter.owner = mod;
69784 -
69785 - file_ops->format = ftrace_event_format_fops;
69786 - file_ops->format.owner = mod;
69787 + pax_open_kernel();
69788 + *(void **)&mod->trace_id.owner = mod;
69789 + *(void **)&mod->trace_enable.owner = mod;
69790 + *(void **)&mod->trace_filter.owner = mod;
69791 + *(void **)&mod->trace_format.owner = mod;
69792 + pax_close_kernel();
69793
69794 list_add(&file_ops->list, &ftrace_module_file_list);
69795
69796 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
69797
69798 for_each_event(call, start, end) {
69799 __trace_add_event_call(*call, mod,
69800 - &file_ops->id, &file_ops->enable,
69801 - &file_ops->filter, &file_ops->format);
69802 + &mod->trace_id, &mod->trace_enable,
69803 + &mod->trace_filter, &mod->trace_format);
69804 }
69805 }
69806
69807 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69808 index 00d527c..7c5b1a3 100644
69809 --- a/kernel/trace/trace_kprobe.c
69810 +++ b/kernel/trace/trace_kprobe.c
69811 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69812 long ret;
69813 int maxlen = get_rloc_len(*(u32 *)dest);
69814 u8 *dst = get_rloc_data(dest);
69815 - u8 *src = addr;
69816 + const u8 __user *src = (const u8 __force_user *)addr;
69817 mm_segment_t old_fs = get_fs();
69818 if (!maxlen)
69819 return;
69820 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69821 pagefault_disable();
69822 do
69823 ret = __copy_from_user_inatomic(dst++, src++, 1);
69824 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69825 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69826 dst[-1] = '\0';
69827 pagefault_enable();
69828 set_fs(old_fs);
69829 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69830 ((u8 *)get_rloc_data(dest))[0] = '\0';
69831 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69832 } else
69833 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69834 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69835 get_rloc_offs(*(u32 *)dest));
69836 }
69837 /* Return the length of string -- including null terminal byte */
69838 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69839 set_fs(KERNEL_DS);
69840 pagefault_disable();
69841 do {
69842 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69843 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69844 len++;
69845 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69846 pagefault_enable();
69847 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69848 index fd3c8aa..5f324a6 100644
69849 --- a/kernel/trace/trace_mmiotrace.c
69850 +++ b/kernel/trace/trace_mmiotrace.c
69851 @@ -24,7 +24,7 @@ struct header_iter {
69852 static struct trace_array *mmio_trace_array;
69853 static bool overrun_detected;
69854 static unsigned long prev_overruns;
69855 -static atomic_t dropped_count;
69856 +static atomic_unchecked_t dropped_count;
69857
69858 static void mmio_reset_data(struct trace_array *tr)
69859 {
69860 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69861
69862 static unsigned long count_overruns(struct trace_iterator *iter)
69863 {
69864 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
69865 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69866 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69867
69868 if (over > prev_overruns)
69869 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69870 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69871 sizeof(*entry), 0, pc);
69872 if (!event) {
69873 - atomic_inc(&dropped_count);
69874 + atomic_inc_unchecked(&dropped_count);
69875 return;
69876 }
69877 entry = ring_buffer_event_data(event);
69878 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69879 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69880 sizeof(*entry), 0, pc);
69881 if (!event) {
69882 - atomic_inc(&dropped_count);
69883 + atomic_inc_unchecked(&dropped_count);
69884 return;
69885 }
69886 entry = ring_buffer_event_data(event);
69887 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69888 index 5199930..26c73a0 100644
69889 --- a/kernel/trace/trace_output.c
69890 +++ b/kernel/trace/trace_output.c
69891 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
69892
69893 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69894 if (!IS_ERR(p)) {
69895 - p = mangle_path(s->buffer + s->len, p, "\n");
69896 + p = mangle_path(s->buffer + s->len, p, "\n\\");
69897 if (p) {
69898 s->len = p - s->buffer;
69899 return 1;
69900 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69901 index 77575b3..6e623d1 100644
69902 --- a/kernel/trace/trace_stack.c
69903 +++ b/kernel/trace/trace_stack.c
69904 @@ -50,7 +50,7 @@ static inline void check_stack(void)
69905 return;
69906
69907 /* we do not handle interrupt stacks yet */
69908 - if (!object_is_on_stack(&this_size))
69909 + if (!object_starts_on_stack(&this_size))
69910 return;
69911
69912 local_irq_save(flags);
69913 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69914 index 209b379..7f76423 100644
69915 --- a/kernel/trace/trace_workqueue.c
69916 +++ b/kernel/trace/trace_workqueue.c
69917 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69918 int cpu;
69919 pid_t pid;
69920 /* Can be inserted from interrupt or user context, need to be atomic */
69921 - atomic_t inserted;
69922 + atomic_unchecked_t inserted;
69923 /*
69924 * Don't need to be atomic, works are serialized in a single workqueue thread
69925 * on a single CPU.
69926 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69927 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69928 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69929 if (node->pid == wq_thread->pid) {
69930 - atomic_inc(&node->inserted);
69931 + atomic_inc_unchecked(&node->inserted);
69932 goto found;
69933 }
69934 }
69935 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69936 tsk = get_pid_task(pid, PIDTYPE_PID);
69937 if (tsk) {
69938 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69939 - atomic_read(&cws->inserted), cws->executed,
69940 + atomic_read_unchecked(&cws->inserted), cws->executed,
69941 tsk->comm);
69942 put_task_struct(tsk);
69943 }
69944 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69945 index c0cb9c4..f33aa89 100644
69946 --- a/lib/Kconfig.debug
69947 +++ b/lib/Kconfig.debug
69948 @@ -1091,6 +1091,7 @@ config LATENCYTOP
69949 depends on DEBUG_KERNEL
69950 depends on STACKTRACE_SUPPORT
69951 depends on PROC_FS
69952 + depends on !GRKERNSEC_HIDESYM
69953 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE
69954 select KALLSYMS
69955 select KALLSYMS_ALL
69956 diff --git a/lib/bitmap.c b/lib/bitmap.c
69957 index 2f4412e..a557e27 100644
69958 --- a/lib/bitmap.c
69959 +++ b/lib/bitmap.c
69960 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69961 {
69962 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69963 u32 chunk;
69964 - const char __user *ubuf = buf;
69965 + const char __user *ubuf = (const char __force_user *)buf;
69966
69967 bitmap_zero(maskp, nmaskbits);
69968
69969 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
69970 {
69971 if (!access_ok(VERIFY_READ, ubuf, ulen))
69972 return -EFAULT;
69973 - return __bitmap_parse((const char *)ubuf, ulen, 1, maskp, nmaskbits);
69974 + return __bitmap_parse((const char __force_kernel *)ubuf, ulen, 1, maskp, nmaskbits);
69975 }
69976 EXPORT_SYMBOL(bitmap_parse_user);
69977
69978 @@ -594,7 +594,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69979 {
69980 unsigned a, b;
69981 int c, old_c, totaldigits;
69982 - const char __user *ubuf = buf;
69983 + const char __user *ubuf = (const char __force_user *)buf;
69984 int exp_digit, in_range;
69985
69986 totaldigits = c = 0;
69987 @@ -694,7 +694,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69988 {
69989 if (!access_ok(VERIFY_READ, ubuf, ulen))
69990 return -EFAULT;
69991 - return __bitmap_parselist((const char *)ubuf,
69992 + return __bitmap_parselist((const char __force_kernel *)ubuf,
69993 ulen, 1, maskp, nmaskbits);
69994 }
69995 EXPORT_SYMBOL(bitmap_parselist_user);
69996 diff --git a/lib/bug.c b/lib/bug.c
69997 index 1955209..cbbb2ad 100644
69998 --- a/lib/bug.c
69999 +++ b/lib/bug.c
70000 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70001 return BUG_TRAP_TYPE_NONE;
70002
70003 bug = find_bug(bugaddr);
70004 + if (!bug)
70005 + return BUG_TRAP_TYPE_NONE;
70006
70007 file = NULL;
70008 line = 0;
70009 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70010 index a78b7c6..2c73084 100644
70011 --- a/lib/debugobjects.c
70012 +++ b/lib/debugobjects.c
70013 @@ -284,7 +284,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70014 if (limit > 4)
70015 return;
70016
70017 - is_on_stack = object_is_on_stack(addr);
70018 + is_on_stack = object_starts_on_stack(addr);
70019 if (is_on_stack == onstack)
70020 return;
70021
70022 diff --git a/lib/devres.c b/lib/devres.c
70023 index 7c0e953..f642b5c 100644
70024 --- a/lib/devres.c
70025 +++ b/lib/devres.c
70026 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70027 void devm_iounmap(struct device *dev, void __iomem *addr)
70028 {
70029 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70030 - (void *)addr));
70031 + (void __force *)addr));
70032 iounmap(addr);
70033 }
70034 EXPORT_SYMBOL(devm_iounmap);
70035 @@ -141,7 +141,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70036 {
70037 ioport_unmap(addr);
70038 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70039 - devm_ioport_map_match, (void *)addr));
70040 + devm_ioport_map_match, (void __force *)addr));
70041 }
70042 EXPORT_SYMBOL(devm_ioport_unmap);
70043
70044 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70045 index db07bfd..719b5ab 100644
70046 --- a/lib/dma-debug.c
70047 +++ b/lib/dma-debug.c
70048 @@ -870,7 +870,7 @@ out:
70049
70050 static void check_for_stack(struct device *dev, void *addr)
70051 {
70052 - if (object_is_on_stack(addr))
70053 + if (object_starts_on_stack(addr))
70054 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70055 "stack [addr=%p]\n", addr);
70056 }
70057 diff --git a/lib/extable.c b/lib/extable.c
70058 index 4cac81e..63e9b8f 100644
70059 --- a/lib/extable.c
70060 +++ b/lib/extable.c
70061 @@ -13,6 +13,7 @@
70062 #include <linux/init.h>
70063 #include <linux/sort.h>
70064 #include <asm/uaccess.h>
70065 +#include <asm/pgtable.h>
70066
70067 #ifndef ARCH_HAS_SORT_EXTABLE
70068 /*
70069 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
70070 void sort_extable(struct exception_table_entry *start,
70071 struct exception_table_entry *finish)
70072 {
70073 + pax_open_kernel();
70074 sort(start, finish - start, sizeof(struct exception_table_entry),
70075 cmp_ex, NULL);
70076 + pax_close_kernel();
70077 }
70078
70079 #ifdef CONFIG_MODULES
70080 diff --git a/lib/inflate.c b/lib/inflate.c
70081 index 013a761..c28f3fc 100644
70082 --- a/lib/inflate.c
70083 +++ b/lib/inflate.c
70084 @@ -269,7 +269,7 @@ static void free(void *where)
70085 malloc_ptr = free_mem_ptr;
70086 }
70087 #else
70088 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70089 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70090 #define free(a) kfree(a)
70091 #endif
70092
70093 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70094 index bd2bea9..6b3c95e 100644
70095 --- a/lib/is_single_threaded.c
70096 +++ b/lib/is_single_threaded.c
70097 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70098 struct task_struct *p, *t;
70099 bool ret;
70100
70101 + if (!mm)
70102 + return true;
70103 +
70104 if (atomic_read(&task->signal->live) != 1)
70105 return false;
70106
70107 diff --git a/lib/kref.c b/lib/kref.c
70108 index 3efb882..8492f4c 100644
70109 --- a/lib/kref.c
70110 +++ b/lib/kref.c
70111 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
70112 */
70113 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
70114 {
70115 - WARN_ON(release == NULL);
70116 + BUG_ON(release == NULL);
70117 WARN_ON(release == (void (*)(struct kref *))kfree);
70118
70119 if (atomic_dec_and_test(&kref->refcount)) {
70120 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70121 index a2f9da5..3bcadb6 100644
70122 --- a/lib/radix-tree.c
70123 +++ b/lib/radix-tree.c
70124 @@ -80,7 +80,7 @@ struct radix_tree_preload {
70125 int nr;
70126 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
70127 };
70128 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70129 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70130
70131 static inline void *ptr_to_indirect(void *ptr)
70132 {
70133 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70134 index d7222a9..2172edc 100644
70135 --- a/lib/vsprintf.c
70136 +++ b/lib/vsprintf.c
70137 @@ -16,6 +16,9 @@
70138 * - scnprintf and vscnprintf
70139 */
70140
70141 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70142 +#define __INCLUDED_BY_HIDESYM 1
70143 +#endif
70144 #include <stdarg.h>
70145 #include <linux/module.h>
70146 #include <linux/types.h>
70147 @@ -432,7 +435,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70148 char sym[KSYM_SYMBOL_LEN];
70149 if (ext == 'B')
70150 sprint_backtrace(sym, value);
70151 - else if (ext != 'f' && ext != 's')
70152 + else if (ext != 'f' && ext != 's' && ext != 'a')
70153 sprint_symbol(sym, value);
70154 else
70155 kallsyms_lookup(value, NULL, NULL, NULL, sym);
70156 @@ -796,7 +799,11 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
70157 return string(buf, end, uuid, spec);
70158 }
70159
70160 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70161 +int kptr_restrict __read_mostly = 2;
70162 +#else
70163 int kptr_restrict __read_mostly;
70164 +#endif
70165
70166 /*
70167 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70168 @@ -810,6 +817,8 @@ int kptr_restrict __read_mostly;
70169 * - 'S' For symbolic direct pointers with offset
70170 * - 's' For symbolic direct pointers without offset
70171 * - 'B' For backtraced symbolic direct pointers with offset
70172 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70173 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70174 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70175 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70176 * - 'M' For a 6-byte MAC address, it prints the address in the
70177 @@ -854,12 +863,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70178 {
70179 if (!ptr && *fmt != 'K') {
70180 /*
70181 - * Print (null) with the same width as a pointer so it makes
70182 + * Print (nil) with the same width as a pointer so it makes
70183 * tabular output look nice.
70184 */
70185 if (spec.field_width == -1)
70186 spec.field_width = 2 * sizeof(void *);
70187 - return string(buf, end, "(null)", spec);
70188 + return string(buf, end, "(nil)", spec);
70189 }
70190
70191 switch (*fmt) {
70192 @@ -869,6 +878,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70193 /* Fallthrough */
70194 case 'S':
70195 case 's':
70196 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70197 + break;
70198 +#else
70199 + return symbol_string(buf, end, ptr, spec, *fmt);
70200 +#endif
70201 + case 'A':
70202 + case 'a':
70203 case 'B':
70204 return symbol_string(buf, end, ptr, spec, *fmt);
70205 case 'R':
70206 @@ -1627,11 +1643,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70207 typeof(type) value; \
70208 if (sizeof(type) == 8) { \
70209 args = PTR_ALIGN(args, sizeof(u32)); \
70210 - *(u32 *)&value = *(u32 *)args; \
70211 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70212 + *(u32 *)&value = *(const u32 *)args; \
70213 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70214 } else { \
70215 args = PTR_ALIGN(args, sizeof(type)); \
70216 - value = *(typeof(type) *)args; \
70217 + value = *(const typeof(type) *)args; \
70218 } \
70219 args += sizeof(type); \
70220 value; \
70221 @@ -1694,7 +1710,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70222 case FORMAT_TYPE_STR: {
70223 const char *str_arg = args;
70224 args += strlen(str_arg) + 1;
70225 - str = string(str, end, (char *)str_arg, spec);
70226 + str = string(str, end, str_arg, spec);
70227 break;
70228 }
70229
70230 diff --git a/localversion-grsec b/localversion-grsec
70231 new file mode 100644
70232 index 0000000..7cd6065
70233 --- /dev/null
70234 +++ b/localversion-grsec
70235 @@ -0,0 +1 @@
70236 +-grsec
70237 diff --git a/mm/Kconfig b/mm/Kconfig
70238 index f2f1ca1..0645f06 100644
70239 --- a/mm/Kconfig
70240 +++ b/mm/Kconfig
70241 @@ -238,10 +238,10 @@ config KSM
70242 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70243
70244 config DEFAULT_MMAP_MIN_ADDR
70245 - int "Low address space to protect from user allocation"
70246 + int "Low address space to protect from user allocation"
70247 depends on MMU
70248 - default 4096
70249 - help
70250 + default 65536
70251 + help
70252 This is the portion of low virtual memory which should be protected
70253 from userspace allocation. Keeping a user from writing to low pages
70254 can help reduce the impact of kernel NULL pointer bugs.
70255 diff --git a/mm/filemap.c b/mm/filemap.c
70256 index b91f3aa..d0ac1d4 100644
70257 --- a/mm/filemap.c
70258 +++ b/mm/filemap.c
70259 @@ -1784,7 +1784,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70260 struct address_space *mapping = file->f_mapping;
70261
70262 if (!mapping->a_ops->readpage)
70263 - return -ENOEXEC;
70264 + return -ENODEV;
70265 file_accessed(file);
70266 vma->vm_ops = &generic_file_vm_ops;
70267 vma->vm_flags |= VM_CAN_NONLINEAR;
70268 @@ -2187,6 +2187,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70269 *pos = i_size_read(inode);
70270
70271 if (limit != RLIM_INFINITY) {
70272 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70273 if (*pos >= limit) {
70274 send_sig(SIGXFSZ, current, 0);
70275 return -EFBIG;
70276 diff --git a/mm/fremap.c b/mm/fremap.c
70277 index b8e0e2d..076e171 100644
70278 --- a/mm/fremap.c
70279 +++ b/mm/fremap.c
70280 @@ -156,6 +156,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70281 retry:
70282 vma = find_vma(mm, start);
70283
70284 +#ifdef CONFIG_PAX_SEGMEXEC
70285 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70286 + goto out;
70287 +#endif
70288 +
70289 /*
70290 * Make sure the vma is shared, that it supports prefaulting,
70291 * and that the remapped range is valid and fully within
70292 diff --git a/mm/highmem.c b/mm/highmem.c
70293 index 5ef672c..d7660f4 100644
70294 --- a/mm/highmem.c
70295 +++ b/mm/highmem.c
70296 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70297 * So no dangers, even with speculative execution.
70298 */
70299 page = pte_page(pkmap_page_table[i]);
70300 + pax_open_kernel();
70301 pte_clear(&init_mm, (unsigned long)page_address(page),
70302 &pkmap_page_table[i]);
70303 -
70304 + pax_close_kernel();
70305 set_page_address(page, NULL);
70306 need_flush = 1;
70307 }
70308 @@ -186,9 +187,11 @@ start:
70309 }
70310 }
70311 vaddr = PKMAP_ADDR(last_pkmap_nr);
70312 +
70313 + pax_open_kernel();
70314 set_pte_at(&init_mm, vaddr,
70315 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70316 -
70317 + pax_close_kernel();
70318 pkmap_count[last_pkmap_nr] = 1;
70319 set_page_address(page, (void *)vaddr);
70320
70321 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70322 index d819d93..468e18f 100644
70323 --- a/mm/huge_memory.c
70324 +++ b/mm/huge_memory.c
70325 @@ -702,7 +702,7 @@ out:
70326 * run pte_offset_map on the pmd, if an huge pmd could
70327 * materialize from under us from a different thread.
70328 */
70329 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70330 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70331 return VM_FAULT_OOM;
70332 /* if an huge pmd materialized from under us just retry later */
70333 if (unlikely(pmd_trans_huge(*pmd)))
70334 @@ -829,7 +829,7 @@ static int do_huge_pmd_wp_page_fallback(struct mm_struct *mm,
70335
70336 for (i = 0; i < HPAGE_PMD_NR; i++) {
70337 copy_user_highpage(pages[i], page + i,
70338 - haddr + PAGE_SHIFT*i, vma);
70339 + haddr + PAGE_SIZE*i, vma);
70340 __SetPageUptodate(pages[i]);
70341 cond_resched();
70342 }
70343 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70344 index 2316840..b418671 100644
70345 --- a/mm/hugetlb.c
70346 +++ b/mm/hugetlb.c
70347 @@ -2347,6 +2347,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70348 return 1;
70349 }
70350
70351 +#ifdef CONFIG_PAX_SEGMEXEC
70352 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70353 +{
70354 + struct mm_struct *mm = vma->vm_mm;
70355 + struct vm_area_struct *vma_m;
70356 + unsigned long address_m;
70357 + pte_t *ptep_m;
70358 +
70359 + vma_m = pax_find_mirror_vma(vma);
70360 + if (!vma_m)
70361 + return;
70362 +
70363 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70364 + address_m = address + SEGMEXEC_TASK_SIZE;
70365 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70366 + get_page(page_m);
70367 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
70368 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70369 +}
70370 +#endif
70371 +
70372 /*
70373 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70374 */
70375 @@ -2450,6 +2471,11 @@ retry_avoidcopy:
70376 make_huge_pte(vma, new_page, 1));
70377 page_remove_rmap(old_page);
70378 hugepage_add_new_anon_rmap(new_page, vma, address);
70379 +
70380 +#ifdef CONFIG_PAX_SEGMEXEC
70381 + pax_mirror_huge_pte(vma, address, new_page);
70382 +#endif
70383 +
70384 /* Make the old page be freed below */
70385 new_page = old_page;
70386 mmu_notifier_invalidate_range_end(mm,
70387 @@ -2601,6 +2627,10 @@ retry:
70388 && (vma->vm_flags & VM_SHARED)));
70389 set_huge_pte_at(mm, address, ptep, new_pte);
70390
70391 +#ifdef CONFIG_PAX_SEGMEXEC
70392 + pax_mirror_huge_pte(vma, address, page);
70393 +#endif
70394 +
70395 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70396 /* Optimization, do the COW without a second fault */
70397 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70398 @@ -2630,6 +2660,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70399 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70400 struct hstate *h = hstate_vma(vma);
70401
70402 +#ifdef CONFIG_PAX_SEGMEXEC
70403 + struct vm_area_struct *vma_m;
70404 +#endif
70405 +
70406 ptep = huge_pte_offset(mm, address);
70407 if (ptep) {
70408 entry = huge_ptep_get(ptep);
70409 @@ -2641,6 +2675,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70410 VM_FAULT_SET_HINDEX(h - hstates);
70411 }
70412
70413 +#ifdef CONFIG_PAX_SEGMEXEC
70414 + vma_m = pax_find_mirror_vma(vma);
70415 + if (vma_m) {
70416 + unsigned long address_m;
70417 +
70418 + if (vma->vm_start > vma_m->vm_start) {
70419 + address_m = address;
70420 + address -= SEGMEXEC_TASK_SIZE;
70421 + vma = vma_m;
70422 + h = hstate_vma(vma);
70423 + } else
70424 + address_m = address + SEGMEXEC_TASK_SIZE;
70425 +
70426 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70427 + return VM_FAULT_OOM;
70428 + address_m &= HPAGE_MASK;
70429 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70430 + }
70431 +#endif
70432 +
70433 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70434 if (!ptep)
70435 return VM_FAULT_OOM;
70436 diff --git a/mm/internal.h b/mm/internal.h
70437 index 2189af4..f2ca332 100644
70438 --- a/mm/internal.h
70439 +++ b/mm/internal.h
70440 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70441 * in mm/page_alloc.c
70442 */
70443 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70444 +extern void free_compound_page(struct page *page);
70445 extern void prep_compound_page(struct page *page, unsigned long order);
70446 #ifdef CONFIG_MEMORY_FAILURE
70447 extern bool is_free_buddy_page(struct page *page);
70448 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70449 index d6880f5..ed77913 100644
70450 --- a/mm/kmemleak.c
70451 +++ b/mm/kmemleak.c
70452 @@ -357,7 +357,7 @@ static void print_unreferenced(struct seq_file *seq,
70453
70454 for (i = 0; i < object->trace_len; i++) {
70455 void *ptr = (void *)object->trace[i];
70456 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70457 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70458 }
70459 }
70460
70461 diff --git a/mm/maccess.c b/mm/maccess.c
70462 index 4cee182..e00511d 100644
70463 --- a/mm/maccess.c
70464 +++ b/mm/maccess.c
70465 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70466 set_fs(KERNEL_DS);
70467 pagefault_disable();
70468 ret = __copy_from_user_inatomic(dst,
70469 - (__force const void __user *)src, size);
70470 + (const void __force_user *)src, size);
70471 pagefault_enable();
70472 set_fs(old_fs);
70473
70474 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70475
70476 set_fs(KERNEL_DS);
70477 pagefault_disable();
70478 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70479 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70480 pagefault_enable();
70481 set_fs(old_fs);
70482
70483 diff --git a/mm/madvise.c b/mm/madvise.c
70484 index 74bf193..feb6fd3 100644
70485 --- a/mm/madvise.c
70486 +++ b/mm/madvise.c
70487 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70488 pgoff_t pgoff;
70489 unsigned long new_flags = vma->vm_flags;
70490
70491 +#ifdef CONFIG_PAX_SEGMEXEC
70492 + struct vm_area_struct *vma_m;
70493 +#endif
70494 +
70495 switch (behavior) {
70496 case MADV_NORMAL:
70497 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70498 @@ -110,6 +114,13 @@ success:
70499 /*
70500 * vm_flags is protected by the mmap_sem held in write mode.
70501 */
70502 +
70503 +#ifdef CONFIG_PAX_SEGMEXEC
70504 + vma_m = pax_find_mirror_vma(vma);
70505 + if (vma_m)
70506 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70507 +#endif
70508 +
70509 vma->vm_flags = new_flags;
70510
70511 out:
70512 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70513 struct vm_area_struct ** prev,
70514 unsigned long start, unsigned long end)
70515 {
70516 +
70517 +#ifdef CONFIG_PAX_SEGMEXEC
70518 + struct vm_area_struct *vma_m;
70519 +#endif
70520 +
70521 *prev = vma;
70522 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70523 return -EINVAL;
70524 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70525 zap_page_range(vma, start, end - start, &details);
70526 } else
70527 zap_page_range(vma, start, end - start, NULL);
70528 +
70529 +#ifdef CONFIG_PAX_SEGMEXEC
70530 + vma_m = pax_find_mirror_vma(vma);
70531 + if (vma_m) {
70532 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70533 + struct zap_details details = {
70534 + .nonlinear_vma = vma_m,
70535 + .last_index = ULONG_MAX,
70536 + };
70537 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70538 + } else
70539 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70540 + }
70541 +#endif
70542 +
70543 return 0;
70544 }
70545
70546 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70547 if (end < start)
70548 goto out;
70549
70550 +#ifdef CONFIG_PAX_SEGMEXEC
70551 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70552 + if (end > SEGMEXEC_TASK_SIZE)
70553 + goto out;
70554 + } else
70555 +#endif
70556 +
70557 + if (end > TASK_SIZE)
70558 + goto out;
70559 +
70560 error = 0;
70561 if (end == start)
70562 goto out;
70563 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70564 index 2b43ba0..fc09657 100644
70565 --- a/mm/memory-failure.c
70566 +++ b/mm/memory-failure.c
70567 @@ -60,7 +60,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70568
70569 int sysctl_memory_failure_recovery __read_mostly = 1;
70570
70571 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70572 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70573
70574 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70575
70576 @@ -201,7 +201,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
70577 si.si_signo = SIGBUS;
70578 si.si_errno = 0;
70579 si.si_code = BUS_MCEERR_AO;
70580 - si.si_addr = (void *)addr;
70581 + si.si_addr = (void __user *)addr;
70582 #ifdef __ARCH_SI_TRAPNO
70583 si.si_trapno = trapno;
70584 #endif
70585 @@ -1009,7 +1009,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70586 }
70587
70588 nr_pages = 1 << compound_trans_order(hpage);
70589 - atomic_long_add(nr_pages, &mce_bad_pages);
70590 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70591
70592 /*
70593 * We need/can do nothing about count=0 pages.
70594 @@ -1039,7 +1039,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70595 if (!PageHWPoison(hpage)
70596 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70597 || (p != hpage && TestSetPageHWPoison(hpage))) {
70598 - atomic_long_sub(nr_pages, &mce_bad_pages);
70599 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70600 return 0;
70601 }
70602 set_page_hwpoison_huge_page(hpage);
70603 @@ -1097,7 +1097,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70604 }
70605 if (hwpoison_filter(p)) {
70606 if (TestClearPageHWPoison(p))
70607 - atomic_long_sub(nr_pages, &mce_bad_pages);
70608 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70609 unlock_page(hpage);
70610 put_page(hpage);
70611 return 0;
70612 @@ -1314,7 +1314,7 @@ int unpoison_memory(unsigned long pfn)
70613 return 0;
70614 }
70615 if (TestClearPageHWPoison(p))
70616 - atomic_long_sub(nr_pages, &mce_bad_pages);
70617 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70618 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70619 return 0;
70620 }
70621 @@ -1328,7 +1328,7 @@ int unpoison_memory(unsigned long pfn)
70622 */
70623 if (TestClearPageHWPoison(page)) {
70624 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70625 - atomic_long_sub(nr_pages, &mce_bad_pages);
70626 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70627 freeit = 1;
70628 if (PageHuge(page))
70629 clear_page_hwpoison_huge_page(page);
70630 @@ -1441,7 +1441,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70631 }
70632 done:
70633 if (!PageHWPoison(hpage))
70634 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70635 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70636 set_page_hwpoison_huge_page(hpage);
70637 dequeue_hwpoisoned_huge_page(hpage);
70638 /* keep elevated page count for bad page */
70639 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
70640 return ret;
70641
70642 done:
70643 - atomic_long_add(1, &mce_bad_pages);
70644 + atomic_long_add_unchecked(1, &mce_bad_pages);
70645 SetPageHWPoison(page);
70646 /* keep elevated page count for bad page */
70647 return ret;
70648 diff --git a/mm/memory.c b/mm/memory.c
70649 index b2b8731..6080174 100644
70650 --- a/mm/memory.c
70651 +++ b/mm/memory.c
70652 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
70653 return;
70654
70655 pmd = pmd_offset(pud, start);
70656 +
70657 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
70658 pud_clear(pud);
70659 pmd_free_tlb(tlb, pmd, start);
70660 +#endif
70661 +
70662 }
70663
70664 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70665 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70666 if (end - 1 > ceiling - 1)
70667 return;
70668
70669 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
70670 pud = pud_offset(pgd, start);
70671 pgd_clear(pgd);
70672 pud_free_tlb(tlb, pud, start);
70673 +#endif
70674 +
70675 }
70676
70677 /*
70678 @@ -1566,12 +1573,6 @@ no_page_table:
70679 return page;
70680 }
70681
70682 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
70683 -{
70684 - return stack_guard_page_start(vma, addr) ||
70685 - stack_guard_page_end(vma, addr+PAGE_SIZE);
70686 -}
70687 -
70688 /**
70689 * __get_user_pages() - pin user pages in memory
70690 * @tsk: task_struct of target task
70691 @@ -1644,10 +1645,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70692 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
70693 i = 0;
70694
70695 - do {
70696 + while (nr_pages) {
70697 struct vm_area_struct *vma;
70698
70699 - vma = find_extend_vma(mm, start);
70700 + vma = find_vma(mm, start);
70701 if (!vma && in_gate_area(mm, start)) {
70702 unsigned long pg = start & PAGE_MASK;
70703 pgd_t *pgd;
70704 @@ -1695,7 +1696,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70705 goto next_page;
70706 }
70707
70708 - if (!vma ||
70709 + if (!vma || start < vma->vm_start ||
70710 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
70711 !(vm_flags & vma->vm_flags))
70712 return i ? : -EFAULT;
70713 @@ -1722,11 +1723,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70714 int ret;
70715 unsigned int fault_flags = 0;
70716
70717 - /* For mlock, just skip the stack guard page. */
70718 - if (foll_flags & FOLL_MLOCK) {
70719 - if (stack_guard_page(vma, start))
70720 - goto next_page;
70721 - }
70722 if (foll_flags & FOLL_WRITE)
70723 fault_flags |= FAULT_FLAG_WRITE;
70724 if (nonblocking)
70725 @@ -1800,7 +1796,7 @@ next_page:
70726 start += PAGE_SIZE;
70727 nr_pages--;
70728 } while (nr_pages && start < vma->vm_end);
70729 - } while (nr_pages);
70730 + }
70731 return i;
70732 }
70733 EXPORT_SYMBOL(__get_user_pages);
70734 @@ -2007,6 +2003,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
70735 page_add_file_rmap(page);
70736 set_pte_at(mm, addr, pte, mk_pte(page, prot));
70737
70738 +#ifdef CONFIG_PAX_SEGMEXEC
70739 + pax_mirror_file_pte(vma, addr, page, ptl);
70740 +#endif
70741 +
70742 retval = 0;
70743 pte_unmap_unlock(pte, ptl);
70744 return retval;
70745 @@ -2041,10 +2041,22 @@ out:
70746 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70747 struct page *page)
70748 {
70749 +
70750 +#ifdef CONFIG_PAX_SEGMEXEC
70751 + struct vm_area_struct *vma_m;
70752 +#endif
70753 +
70754 if (addr < vma->vm_start || addr >= vma->vm_end)
70755 return -EFAULT;
70756 if (!page_count(page))
70757 return -EINVAL;
70758 +
70759 +#ifdef CONFIG_PAX_SEGMEXEC
70760 + vma_m = pax_find_mirror_vma(vma);
70761 + if (vma_m)
70762 + vma_m->vm_flags |= VM_INSERTPAGE;
70763 +#endif
70764 +
70765 vma->vm_flags |= VM_INSERTPAGE;
70766 return insert_page(vma, addr, page, vma->vm_page_prot);
70767 }
70768 @@ -2130,6 +2142,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70769 unsigned long pfn)
70770 {
70771 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70772 + BUG_ON(vma->vm_mirror);
70773
70774 if (addr < vma->vm_start || addr >= vma->vm_end)
70775 return -EFAULT;
70776 @@ -2445,6 +2458,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70777 copy_user_highpage(dst, src, va, vma);
70778 }
70779
70780 +#ifdef CONFIG_PAX_SEGMEXEC
70781 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70782 +{
70783 + struct mm_struct *mm = vma->vm_mm;
70784 + spinlock_t *ptl;
70785 + pte_t *pte, entry;
70786 +
70787 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70788 + entry = *pte;
70789 + if (!pte_present(entry)) {
70790 + if (!pte_none(entry)) {
70791 + BUG_ON(pte_file(entry));
70792 + free_swap_and_cache(pte_to_swp_entry(entry));
70793 + pte_clear_not_present_full(mm, address, pte, 0);
70794 + }
70795 + } else {
70796 + struct page *page;
70797 +
70798 + flush_cache_page(vma, address, pte_pfn(entry));
70799 + entry = ptep_clear_flush(vma, address, pte);
70800 + BUG_ON(pte_dirty(entry));
70801 + page = vm_normal_page(vma, address, entry);
70802 + if (page) {
70803 + update_hiwater_rss(mm);
70804 + if (PageAnon(page))
70805 + dec_mm_counter_fast(mm, MM_ANONPAGES);
70806 + else
70807 + dec_mm_counter_fast(mm, MM_FILEPAGES);
70808 + page_remove_rmap(page);
70809 + page_cache_release(page);
70810 + }
70811 + }
70812 + pte_unmap_unlock(pte, ptl);
70813 +}
70814 +
70815 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
70816 + *
70817 + * the ptl of the lower mapped page is held on entry and is not released on exit
70818 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70819 + */
70820 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70821 +{
70822 + struct mm_struct *mm = vma->vm_mm;
70823 + unsigned long address_m;
70824 + spinlock_t *ptl_m;
70825 + struct vm_area_struct *vma_m;
70826 + pmd_t *pmd_m;
70827 + pte_t *pte_m, entry_m;
70828 +
70829 + BUG_ON(!page_m || !PageAnon(page_m));
70830 +
70831 + vma_m = pax_find_mirror_vma(vma);
70832 + if (!vma_m)
70833 + return;
70834 +
70835 + BUG_ON(!PageLocked(page_m));
70836 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70837 + address_m = address + SEGMEXEC_TASK_SIZE;
70838 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70839 + pte_m = pte_offset_map(pmd_m, address_m);
70840 + ptl_m = pte_lockptr(mm, pmd_m);
70841 + if (ptl != ptl_m) {
70842 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70843 + if (!pte_none(*pte_m))
70844 + goto out;
70845 + }
70846 +
70847 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70848 + page_cache_get(page_m);
70849 + page_add_anon_rmap(page_m, vma_m, address_m);
70850 + inc_mm_counter_fast(mm, MM_ANONPAGES);
70851 + set_pte_at(mm, address_m, pte_m, entry_m);
70852 + update_mmu_cache(vma_m, address_m, entry_m);
70853 +out:
70854 + if (ptl != ptl_m)
70855 + spin_unlock(ptl_m);
70856 + pte_unmap(pte_m);
70857 + unlock_page(page_m);
70858 +}
70859 +
70860 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70861 +{
70862 + struct mm_struct *mm = vma->vm_mm;
70863 + unsigned long address_m;
70864 + spinlock_t *ptl_m;
70865 + struct vm_area_struct *vma_m;
70866 + pmd_t *pmd_m;
70867 + pte_t *pte_m, entry_m;
70868 +
70869 + BUG_ON(!page_m || PageAnon(page_m));
70870 +
70871 + vma_m = pax_find_mirror_vma(vma);
70872 + if (!vma_m)
70873 + return;
70874 +
70875 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70876 + address_m = address + SEGMEXEC_TASK_SIZE;
70877 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70878 + pte_m = pte_offset_map(pmd_m, address_m);
70879 + ptl_m = pte_lockptr(mm, pmd_m);
70880 + if (ptl != ptl_m) {
70881 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70882 + if (!pte_none(*pte_m))
70883 + goto out;
70884 + }
70885 +
70886 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70887 + page_cache_get(page_m);
70888 + page_add_file_rmap(page_m);
70889 + inc_mm_counter_fast(mm, MM_FILEPAGES);
70890 + set_pte_at(mm, address_m, pte_m, entry_m);
70891 + update_mmu_cache(vma_m, address_m, entry_m);
70892 +out:
70893 + if (ptl != ptl_m)
70894 + spin_unlock(ptl_m);
70895 + pte_unmap(pte_m);
70896 +}
70897 +
70898 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70899 +{
70900 + struct mm_struct *mm = vma->vm_mm;
70901 + unsigned long address_m;
70902 + spinlock_t *ptl_m;
70903 + struct vm_area_struct *vma_m;
70904 + pmd_t *pmd_m;
70905 + pte_t *pte_m, entry_m;
70906 +
70907 + vma_m = pax_find_mirror_vma(vma);
70908 + if (!vma_m)
70909 + return;
70910 +
70911 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70912 + address_m = address + SEGMEXEC_TASK_SIZE;
70913 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70914 + pte_m = pte_offset_map(pmd_m, address_m);
70915 + ptl_m = pte_lockptr(mm, pmd_m);
70916 + if (ptl != ptl_m) {
70917 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70918 + if (!pte_none(*pte_m))
70919 + goto out;
70920 + }
70921 +
70922 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70923 + set_pte_at(mm, address_m, pte_m, entry_m);
70924 +out:
70925 + if (ptl != ptl_m)
70926 + spin_unlock(ptl_m);
70927 + pte_unmap(pte_m);
70928 +}
70929 +
70930 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70931 +{
70932 + struct page *page_m;
70933 + pte_t entry;
70934 +
70935 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70936 + goto out;
70937 +
70938 + entry = *pte;
70939 + page_m = vm_normal_page(vma, address, entry);
70940 + if (!page_m)
70941 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70942 + else if (PageAnon(page_m)) {
70943 + if (pax_find_mirror_vma(vma)) {
70944 + pte_unmap_unlock(pte, ptl);
70945 + lock_page(page_m);
70946 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70947 + if (pte_same(entry, *pte))
70948 + pax_mirror_anon_pte(vma, address, page_m, ptl);
70949 + else
70950 + unlock_page(page_m);
70951 + }
70952 + } else
70953 + pax_mirror_file_pte(vma, address, page_m, ptl);
70954 +
70955 +out:
70956 + pte_unmap_unlock(pte, ptl);
70957 +}
70958 +#endif
70959 +
70960 /*
70961 * This routine handles present pages, when users try to write
70962 * to a shared page. It is done by copying the page to a new address
70963 @@ -2656,6 +2849,12 @@ gotten:
70964 */
70965 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70966 if (likely(pte_same(*page_table, orig_pte))) {
70967 +
70968 +#ifdef CONFIG_PAX_SEGMEXEC
70969 + if (pax_find_mirror_vma(vma))
70970 + BUG_ON(!trylock_page(new_page));
70971 +#endif
70972 +
70973 if (old_page) {
70974 if (!PageAnon(old_page)) {
70975 dec_mm_counter_fast(mm, MM_FILEPAGES);
70976 @@ -2707,6 +2906,10 @@ gotten:
70977 page_remove_rmap(old_page);
70978 }
70979
70980 +#ifdef CONFIG_PAX_SEGMEXEC
70981 + pax_mirror_anon_pte(vma, address, new_page, ptl);
70982 +#endif
70983 +
70984 /* Free the old page.. */
70985 new_page = old_page;
70986 ret |= VM_FAULT_WRITE;
70987 @@ -2986,6 +3189,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70988 swap_free(entry);
70989 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70990 try_to_free_swap(page);
70991 +
70992 +#ifdef CONFIG_PAX_SEGMEXEC
70993 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70994 +#endif
70995 +
70996 unlock_page(page);
70997 if (swapcache) {
70998 /*
70999 @@ -3009,6 +3217,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71000
71001 /* No need to invalidate - it was non-present before */
71002 update_mmu_cache(vma, address, page_table);
71003 +
71004 +#ifdef CONFIG_PAX_SEGMEXEC
71005 + pax_mirror_anon_pte(vma, address, page, ptl);
71006 +#endif
71007 +
71008 unlock:
71009 pte_unmap_unlock(page_table, ptl);
71010 out:
71011 @@ -3028,40 +3241,6 @@ out_release:
71012 }
71013
71014 /*
71015 - * This is like a special single-page "expand_{down|up}wards()",
71016 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
71017 - * doesn't hit another vma.
71018 - */
71019 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71020 -{
71021 - address &= PAGE_MASK;
71022 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71023 - struct vm_area_struct *prev = vma->vm_prev;
71024 -
71025 - /*
71026 - * Is there a mapping abutting this one below?
71027 - *
71028 - * That's only ok if it's the same stack mapping
71029 - * that has gotten split..
71030 - */
71031 - if (prev && prev->vm_end == address)
71032 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71033 -
71034 - expand_downwards(vma, address - PAGE_SIZE);
71035 - }
71036 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71037 - struct vm_area_struct *next = vma->vm_next;
71038 -
71039 - /* As VM_GROWSDOWN but s/below/above/ */
71040 - if (next && next->vm_start == address + PAGE_SIZE)
71041 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71042 -
71043 - expand_upwards(vma, address + PAGE_SIZE);
71044 - }
71045 - return 0;
71046 -}
71047 -
71048 -/*
71049 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71050 * but allow concurrent faults), and pte mapped but not yet locked.
71051 * We return with mmap_sem still held, but pte unmapped and unlocked.
71052 @@ -3070,27 +3249,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71053 unsigned long address, pte_t *page_table, pmd_t *pmd,
71054 unsigned int flags)
71055 {
71056 - struct page *page;
71057 + struct page *page = NULL;
71058 spinlock_t *ptl;
71059 pte_t entry;
71060
71061 - pte_unmap(page_table);
71062 -
71063 - /* Check if we need to add a guard page to the stack */
71064 - if (check_stack_guard_page(vma, address) < 0)
71065 - return VM_FAULT_SIGBUS;
71066 -
71067 - /* Use the zero-page for reads */
71068 if (!(flags & FAULT_FLAG_WRITE)) {
71069 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71070 vma->vm_page_prot));
71071 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71072 + ptl = pte_lockptr(mm, pmd);
71073 + spin_lock(ptl);
71074 if (!pte_none(*page_table))
71075 goto unlock;
71076 goto setpte;
71077 }
71078
71079 /* Allocate our own private page. */
71080 + pte_unmap(page_table);
71081 +
71082 if (unlikely(anon_vma_prepare(vma)))
71083 goto oom;
71084 page = alloc_zeroed_user_highpage_movable(vma, address);
71085 @@ -3109,6 +3284,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71086 if (!pte_none(*page_table))
71087 goto release;
71088
71089 +#ifdef CONFIG_PAX_SEGMEXEC
71090 + if (pax_find_mirror_vma(vma))
71091 + BUG_ON(!trylock_page(page));
71092 +#endif
71093 +
71094 inc_mm_counter_fast(mm, MM_ANONPAGES);
71095 page_add_new_anon_rmap(page, vma, address);
71096 setpte:
71097 @@ -3116,6 +3296,12 @@ setpte:
71098
71099 /* No need to invalidate - it was non-present before */
71100 update_mmu_cache(vma, address, page_table);
71101 +
71102 +#ifdef CONFIG_PAX_SEGMEXEC
71103 + if (page)
71104 + pax_mirror_anon_pte(vma, address, page, ptl);
71105 +#endif
71106 +
71107 unlock:
71108 pte_unmap_unlock(page_table, ptl);
71109 return 0;
71110 @@ -3259,6 +3445,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71111 */
71112 /* Only go through if we didn't race with anybody else... */
71113 if (likely(pte_same(*page_table, orig_pte))) {
71114 +
71115 +#ifdef CONFIG_PAX_SEGMEXEC
71116 + if (anon && pax_find_mirror_vma(vma))
71117 + BUG_ON(!trylock_page(page));
71118 +#endif
71119 +
71120 flush_icache_page(vma, page);
71121 entry = mk_pte(page, vma->vm_page_prot);
71122 if (flags & FAULT_FLAG_WRITE)
71123 @@ -3278,6 +3470,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71124
71125 /* no need to invalidate: a not-present page won't be cached */
71126 update_mmu_cache(vma, address, page_table);
71127 +
71128 +#ifdef CONFIG_PAX_SEGMEXEC
71129 + if (anon)
71130 + pax_mirror_anon_pte(vma, address, page, ptl);
71131 + else
71132 + pax_mirror_file_pte(vma, address, page, ptl);
71133 +#endif
71134 +
71135 } else {
71136 if (cow_page)
71137 mem_cgroup_uncharge_page(cow_page);
71138 @@ -3431,6 +3631,12 @@ int handle_pte_fault(struct mm_struct *mm,
71139 if (flags & FAULT_FLAG_WRITE)
71140 flush_tlb_fix_spurious_fault(vma, address);
71141 }
71142 +
71143 +#ifdef CONFIG_PAX_SEGMEXEC
71144 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71145 + return 0;
71146 +#endif
71147 +
71148 unlock:
71149 pte_unmap_unlock(pte, ptl);
71150 return 0;
71151 @@ -3447,6 +3653,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71152 pmd_t *pmd;
71153 pte_t *pte;
71154
71155 +#ifdef CONFIG_PAX_SEGMEXEC
71156 + struct vm_area_struct *vma_m;
71157 +#endif
71158 +
71159 __set_current_state(TASK_RUNNING);
71160
71161 count_vm_event(PGFAULT);
71162 @@ -3458,6 +3668,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71163 if (unlikely(is_vm_hugetlb_page(vma)))
71164 return hugetlb_fault(mm, vma, address, flags);
71165
71166 +#ifdef CONFIG_PAX_SEGMEXEC
71167 + vma_m = pax_find_mirror_vma(vma);
71168 + if (vma_m) {
71169 + unsigned long address_m;
71170 + pgd_t *pgd_m;
71171 + pud_t *pud_m;
71172 + pmd_t *pmd_m;
71173 +
71174 + if (vma->vm_start > vma_m->vm_start) {
71175 + address_m = address;
71176 + address -= SEGMEXEC_TASK_SIZE;
71177 + vma = vma_m;
71178 + } else
71179 + address_m = address + SEGMEXEC_TASK_SIZE;
71180 +
71181 + pgd_m = pgd_offset(mm, address_m);
71182 + pud_m = pud_alloc(mm, pgd_m, address_m);
71183 + if (!pud_m)
71184 + return VM_FAULT_OOM;
71185 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71186 + if (!pmd_m)
71187 + return VM_FAULT_OOM;
71188 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71189 + return VM_FAULT_OOM;
71190 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71191 + }
71192 +#endif
71193 +
71194 pgd = pgd_offset(mm, address);
71195 pud = pud_alloc(mm, pgd, address);
71196 if (!pud)
71197 @@ -3487,7 +3725,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71198 * run pte_offset_map on the pmd, if an huge pmd could
71199 * materialize from under us from a different thread.
71200 */
71201 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71202 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71203 return VM_FAULT_OOM;
71204 /* if an huge pmd materialized from under us just retry later */
71205 if (unlikely(pmd_trans_huge(*pmd)))
71206 @@ -3591,7 +3829,7 @@ static int __init gate_vma_init(void)
71207 gate_vma.vm_start = FIXADDR_USER_START;
71208 gate_vma.vm_end = FIXADDR_USER_END;
71209 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71210 - gate_vma.vm_page_prot = __P101;
71211 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71212 /*
71213 * Make sure the vDSO gets into every core dump.
71214 * Dumping its contents makes post-mortem fully interpretable later
71215 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71216 index 2775fd0..f2b1c49 100644
71217 --- a/mm/mempolicy.c
71218 +++ b/mm/mempolicy.c
71219 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71220 unsigned long vmstart;
71221 unsigned long vmend;
71222
71223 +#ifdef CONFIG_PAX_SEGMEXEC
71224 + struct vm_area_struct *vma_m;
71225 +#endif
71226 +
71227 vma = find_vma_prev(mm, start, &prev);
71228 if (!vma || vma->vm_start > start)
71229 return -EFAULT;
71230 @@ -678,6 +682,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71231 err = policy_vma(vma, new_pol);
71232 if (err)
71233 goto out;
71234 +
71235 +#ifdef CONFIG_PAX_SEGMEXEC
71236 + vma_m = pax_find_mirror_vma(vma);
71237 + if (vma_m) {
71238 + err = policy_vma(vma_m, new_pol);
71239 + if (err)
71240 + goto out;
71241 + }
71242 +#endif
71243 +
71244 }
71245
71246 out:
71247 @@ -1111,6 +1125,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71248
71249 if (end < start)
71250 return -EINVAL;
71251 +
71252 +#ifdef CONFIG_PAX_SEGMEXEC
71253 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71254 + if (end > SEGMEXEC_TASK_SIZE)
71255 + return -EINVAL;
71256 + } else
71257 +#endif
71258 +
71259 + if (end > TASK_SIZE)
71260 + return -EINVAL;
71261 +
71262 if (end == start)
71263 return 0;
71264
71265 @@ -1329,6 +1354,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71266 if (!mm)
71267 goto out;
71268
71269 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71270 + if (mm != current->mm &&
71271 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71272 + err = -EPERM;
71273 + goto out;
71274 + }
71275 +#endif
71276 +
71277 /*
71278 * Check if this process has the right to modify the specified
71279 * process. The right exists if the process has administrative
71280 @@ -1338,8 +1371,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71281 rcu_read_lock();
71282 tcred = __task_cred(task);
71283 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71284 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71285 - !capable(CAP_SYS_NICE)) {
71286 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71287 rcu_read_unlock();
71288 err = -EPERM;
71289 goto out;
71290 diff --git a/mm/migrate.c b/mm/migrate.c
71291 index 14d0a6a..0360908 100644
71292 --- a/mm/migrate.c
71293 +++ b/mm/migrate.c
71294 @@ -866,9 +866,9 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
71295
71296 if (anon_vma)
71297 put_anon_vma(anon_vma);
71298 -out:
71299 unlock_page(hpage);
71300
71301 +out:
71302 if (rc != -EAGAIN) {
71303 list_del(&hpage->lru);
71304 put_page(hpage);
71305 @@ -1124,6 +1124,8 @@ static int do_pages_move(struct mm_struct *mm, struct task_struct *task,
71306 unsigned long chunk_start;
71307 int err;
71308
71309 + pax_track_stack();
71310 +
71311 task_nodes = cpuset_mems_allowed(task);
71312
71313 err = -ENOMEM;
71314 @@ -1308,6 +1310,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71315 if (!mm)
71316 return -EINVAL;
71317
71318 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71319 + if (mm != current->mm &&
71320 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71321 + err = -EPERM;
71322 + goto out;
71323 + }
71324 +#endif
71325 +
71326 /*
71327 * Check if this process has the right to modify the specified
71328 * process. The right exists if the process has administrative
71329 @@ -1317,8 +1327,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71330 rcu_read_lock();
71331 tcred = __task_cred(task);
71332 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71333 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71334 - !capable(CAP_SYS_NICE)) {
71335 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71336 rcu_read_unlock();
71337 err = -EPERM;
71338 goto out;
71339 diff --git a/mm/mlock.c b/mm/mlock.c
71340 index 048260c..57f4a4e 100644
71341 --- a/mm/mlock.c
71342 +++ b/mm/mlock.c
71343 @@ -13,6 +13,7 @@
71344 #include <linux/pagemap.h>
71345 #include <linux/mempolicy.h>
71346 #include <linux/syscalls.h>
71347 +#include <linux/security.h>
71348 #include <linux/sched.h>
71349 #include <linux/module.h>
71350 #include <linux/rmap.h>
71351 @@ -377,6 +378,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71352 return -EINVAL;
71353 if (end == start)
71354 return 0;
71355 + if (end > TASK_SIZE)
71356 + return -EINVAL;
71357 +
71358 vma = find_vma_prev(current->mm, start, &prev);
71359 if (!vma || vma->vm_start > start)
71360 return -ENOMEM;
71361 @@ -387,6 +391,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71362 for (nstart = start ; ; ) {
71363 vm_flags_t newflags;
71364
71365 +#ifdef CONFIG_PAX_SEGMEXEC
71366 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71367 + break;
71368 +#endif
71369 +
71370 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71371
71372 newflags = vma->vm_flags | VM_LOCKED;
71373 @@ -492,6 +501,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71374 lock_limit >>= PAGE_SHIFT;
71375
71376 /* check against resource limits */
71377 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71378 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71379 error = do_mlock(start, len, 1);
71380 up_write(&current->mm->mmap_sem);
71381 @@ -515,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71382 static int do_mlockall(int flags)
71383 {
71384 struct vm_area_struct * vma, * prev = NULL;
71385 - unsigned int def_flags = 0;
71386
71387 if (flags & MCL_FUTURE)
71388 - def_flags = VM_LOCKED;
71389 - current->mm->def_flags = def_flags;
71390 + current->mm->def_flags |= VM_LOCKED;
71391 + else
71392 + current->mm->def_flags &= ~VM_LOCKED;
71393 if (flags == MCL_FUTURE)
71394 goto out;
71395
71396 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71397 vm_flags_t newflags;
71398
71399 +#ifdef CONFIG_PAX_SEGMEXEC
71400 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71401 + break;
71402 +#endif
71403 +
71404 + BUG_ON(vma->vm_end > TASK_SIZE);
71405 newflags = vma->vm_flags | VM_LOCKED;
71406 if (!(flags & MCL_CURRENT))
71407 newflags &= ~VM_LOCKED;
71408 @@ -557,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71409 lock_limit >>= PAGE_SHIFT;
71410
71411 ret = -ENOMEM;
71412 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71413 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71414 capable(CAP_IPC_LOCK))
71415 ret = do_mlockall(flags);
71416 diff --git a/mm/mmap.c b/mm/mmap.c
71417 index a65efd4..17d61ff 100644
71418 --- a/mm/mmap.c
71419 +++ b/mm/mmap.c
71420 @@ -46,6 +46,16 @@
71421 #define arch_rebalance_pgtables(addr, len) (addr)
71422 #endif
71423
71424 +static inline void verify_mm_writelocked(struct mm_struct *mm)
71425 +{
71426 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71427 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71428 + up_read(&mm->mmap_sem);
71429 + BUG();
71430 + }
71431 +#endif
71432 +}
71433 +
71434 static void unmap_region(struct mm_struct *mm,
71435 struct vm_area_struct *vma, struct vm_area_struct *prev,
71436 unsigned long start, unsigned long end);
71437 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
71438 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71439 *
71440 */
71441 -pgprot_t protection_map[16] = {
71442 +pgprot_t protection_map[16] __read_only = {
71443 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71444 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71445 };
71446
71447 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
71448 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71449 {
71450 - return __pgprot(pgprot_val(protection_map[vm_flags &
71451 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71452 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71453 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71454 +
71455 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71456 + if (!(__supported_pte_mask & _PAGE_NX) &&
71457 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71458 + (vm_flags & (VM_READ | VM_WRITE)))
71459 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71460 +#endif
71461 +
71462 + return prot;
71463 }
71464 EXPORT_SYMBOL(vm_get_page_prot);
71465
71466 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71467 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71468 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71469 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71470 /*
71471 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71472 * other variables. It can be updated by several CPUs frequently.
71473 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71474 struct vm_area_struct *next = vma->vm_next;
71475
71476 might_sleep();
71477 + BUG_ON(vma->vm_mirror);
71478 if (vma->vm_ops && vma->vm_ops->close)
71479 vma->vm_ops->close(vma);
71480 if (vma->vm_file) {
71481 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71482 * not page aligned -Ram Gupta
71483 */
71484 rlim = rlimit(RLIMIT_DATA);
71485 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71486 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71487 (mm->end_data - mm->start_data) > rlim)
71488 goto out;
71489 @@ -689,6 +711,12 @@ static int
71490 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71491 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71492 {
71493 +
71494 +#ifdef CONFIG_PAX_SEGMEXEC
71495 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71496 + return 0;
71497 +#endif
71498 +
71499 if (is_mergeable_vma(vma, file, vm_flags) &&
71500 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71501 if (vma->vm_pgoff == vm_pgoff)
71502 @@ -708,6 +736,12 @@ static int
71503 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71504 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71505 {
71506 +
71507 +#ifdef CONFIG_PAX_SEGMEXEC
71508 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71509 + return 0;
71510 +#endif
71511 +
71512 if (is_mergeable_vma(vma, file, vm_flags) &&
71513 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71514 pgoff_t vm_pglen;
71515 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71516 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71517 struct vm_area_struct *prev, unsigned long addr,
71518 unsigned long end, unsigned long vm_flags,
71519 - struct anon_vma *anon_vma, struct file *file,
71520 + struct anon_vma *anon_vma, struct file *file,
71521 pgoff_t pgoff, struct mempolicy *policy)
71522 {
71523 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71524 struct vm_area_struct *area, *next;
71525 int err;
71526
71527 +#ifdef CONFIG_PAX_SEGMEXEC
71528 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71529 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71530 +
71531 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71532 +#endif
71533 +
71534 /*
71535 * We later require that vma->vm_flags == vm_flags,
71536 * so this tests vma->vm_flags & VM_SPECIAL, too.
71537 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71538 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71539 next = next->vm_next;
71540
71541 +#ifdef CONFIG_PAX_SEGMEXEC
71542 + if (prev)
71543 + prev_m = pax_find_mirror_vma(prev);
71544 + if (area)
71545 + area_m = pax_find_mirror_vma(area);
71546 + if (next)
71547 + next_m = pax_find_mirror_vma(next);
71548 +#endif
71549 +
71550 /*
71551 * Can it merge with the predecessor?
71552 */
71553 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71554 /* cases 1, 6 */
71555 err = vma_adjust(prev, prev->vm_start,
71556 next->vm_end, prev->vm_pgoff, NULL);
71557 - } else /* cases 2, 5, 7 */
71558 +
71559 +#ifdef CONFIG_PAX_SEGMEXEC
71560 + if (!err && prev_m)
71561 + err = vma_adjust(prev_m, prev_m->vm_start,
71562 + next_m->vm_end, prev_m->vm_pgoff, NULL);
71563 +#endif
71564 +
71565 + } else { /* cases 2, 5, 7 */
71566 err = vma_adjust(prev, prev->vm_start,
71567 end, prev->vm_pgoff, NULL);
71568 +
71569 +#ifdef CONFIG_PAX_SEGMEXEC
71570 + if (!err && prev_m)
71571 + err = vma_adjust(prev_m, prev_m->vm_start,
71572 + end_m, prev_m->vm_pgoff, NULL);
71573 +#endif
71574 +
71575 + }
71576 if (err)
71577 return NULL;
71578 khugepaged_enter_vma_merge(prev);
71579 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71580 mpol_equal(policy, vma_policy(next)) &&
71581 can_vma_merge_before(next, vm_flags,
71582 anon_vma, file, pgoff+pglen)) {
71583 - if (prev && addr < prev->vm_end) /* case 4 */
71584 + if (prev && addr < prev->vm_end) { /* case 4 */
71585 err = vma_adjust(prev, prev->vm_start,
71586 addr, prev->vm_pgoff, NULL);
71587 - else /* cases 3, 8 */
71588 +
71589 +#ifdef CONFIG_PAX_SEGMEXEC
71590 + if (!err && prev_m)
71591 + err = vma_adjust(prev_m, prev_m->vm_start,
71592 + addr_m, prev_m->vm_pgoff, NULL);
71593 +#endif
71594 +
71595 + } else { /* cases 3, 8 */
71596 err = vma_adjust(area, addr, next->vm_end,
71597 next->vm_pgoff - pglen, NULL);
71598 +
71599 +#ifdef CONFIG_PAX_SEGMEXEC
71600 + if (!err && area_m)
71601 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
71602 + next_m->vm_pgoff - pglen, NULL);
71603 +#endif
71604 +
71605 + }
71606 if (err)
71607 return NULL;
71608 khugepaged_enter_vma_merge(area);
71609 @@ -921,14 +1001,11 @@ none:
71610 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
71611 struct file *file, long pages)
71612 {
71613 - const unsigned long stack_flags
71614 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
71615 -
71616 if (file) {
71617 mm->shared_vm += pages;
71618 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
71619 mm->exec_vm += pages;
71620 - } else if (flags & stack_flags)
71621 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
71622 mm->stack_vm += pages;
71623 if (flags & (VM_RESERVED|VM_IO))
71624 mm->reserved_vm += pages;
71625 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71626 * (the exception is when the underlying filesystem is noexec
71627 * mounted, in which case we dont add PROT_EXEC.)
71628 */
71629 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71630 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71631 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
71632 prot |= PROT_EXEC;
71633
71634 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71635 /* Obtain the address to map to. we verify (or select) it and ensure
71636 * that it represents a valid section of the address space.
71637 */
71638 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
71639 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
71640 if (addr & ~PAGE_MASK)
71641 return addr;
71642
71643 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71644 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
71645 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
71646
71647 +#ifdef CONFIG_PAX_MPROTECT
71648 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71649 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71650 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
71651 + gr_log_rwxmmap(file);
71652 +
71653 +#ifdef CONFIG_PAX_EMUPLT
71654 + vm_flags &= ~VM_EXEC;
71655 +#else
71656 + return -EPERM;
71657 +#endif
71658 +
71659 + }
71660 +
71661 + if (!(vm_flags & VM_EXEC))
71662 + vm_flags &= ~VM_MAYEXEC;
71663 +#else
71664 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71665 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71666 +#endif
71667 + else
71668 + vm_flags &= ~VM_MAYWRITE;
71669 + }
71670 +#endif
71671 +
71672 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71673 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
71674 + vm_flags &= ~VM_PAGEEXEC;
71675 +#endif
71676 +
71677 if (flags & MAP_LOCKED)
71678 if (!can_do_mlock())
71679 return -EPERM;
71680 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71681 locked += mm->locked_vm;
71682 lock_limit = rlimit(RLIMIT_MEMLOCK);
71683 lock_limit >>= PAGE_SHIFT;
71684 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71685 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
71686 return -EAGAIN;
71687 }
71688 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71689 if (error)
71690 return error;
71691
71692 + if (!gr_acl_handle_mmap(file, prot))
71693 + return -EACCES;
71694 +
71695 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
71696 }
71697 EXPORT_SYMBOL(do_mmap_pgoff);
71698 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
71699 vm_flags_t vm_flags = vma->vm_flags;
71700
71701 /* If it was private or non-writable, the write bit is already clear */
71702 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
71703 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
71704 return 0;
71705
71706 /* The backer wishes to know when pages are first written to? */
71707 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
71708 unsigned long charged = 0;
71709 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71710
71711 +#ifdef CONFIG_PAX_SEGMEXEC
71712 + struct vm_area_struct *vma_m = NULL;
71713 +#endif
71714 +
71715 + /*
71716 + * mm->mmap_sem is required to protect against another thread
71717 + * changing the mappings in case we sleep.
71718 + */
71719 + verify_mm_writelocked(mm);
71720 +
71721 /* Clear old maps */
71722 error = -ENOMEM;
71723 -munmap_back:
71724 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71725 if (vma && vma->vm_start < addr + len) {
71726 if (do_munmap(mm, addr, len))
71727 return -ENOMEM;
71728 - goto munmap_back;
71729 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71730 + BUG_ON(vma && vma->vm_start < addr + len);
71731 }
71732
71733 /* Check against address space limit. */
71734 @@ -1258,6 +1379,16 @@ munmap_back:
71735 goto unacct_error;
71736 }
71737
71738 +#ifdef CONFIG_PAX_SEGMEXEC
71739 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71740 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71741 + if (!vma_m) {
71742 + error = -ENOMEM;
71743 + goto free_vma;
71744 + }
71745 + }
71746 +#endif
71747 +
71748 vma->vm_mm = mm;
71749 vma->vm_start = addr;
71750 vma->vm_end = addr + len;
71751 @@ -1281,6 +1412,19 @@ munmap_back:
71752 error = file->f_op->mmap(file, vma);
71753 if (error)
71754 goto unmap_and_free_vma;
71755 +
71756 +#ifdef CONFIG_PAX_SEGMEXEC
71757 + if (vma_m && (vm_flags & VM_EXECUTABLE))
71758 + added_exe_file_vma(mm);
71759 +#endif
71760 +
71761 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71762 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71763 + vma->vm_flags |= VM_PAGEEXEC;
71764 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71765 + }
71766 +#endif
71767 +
71768 if (vm_flags & VM_EXECUTABLE)
71769 added_exe_file_vma(mm);
71770
71771 @@ -1316,6 +1460,11 @@ munmap_back:
71772 vma_link(mm, vma, prev, rb_link, rb_parent);
71773 file = vma->vm_file;
71774
71775 +#ifdef CONFIG_PAX_SEGMEXEC
71776 + if (vma_m)
71777 + BUG_ON(pax_mirror_vma(vma_m, vma));
71778 +#endif
71779 +
71780 /* Once vma denies write, undo our temporary denial count */
71781 if (correct_wcount)
71782 atomic_inc(&inode->i_writecount);
71783 @@ -1324,6 +1473,7 @@ out:
71784
71785 mm->total_vm += len >> PAGE_SHIFT;
71786 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71787 + track_exec_limit(mm, addr, addr + len, vm_flags);
71788 if (vm_flags & VM_LOCKED) {
71789 if (!mlock_vma_pages_range(vma, addr, addr + len))
71790 mm->locked_vm += (len >> PAGE_SHIFT);
71791 @@ -1341,6 +1491,12 @@ unmap_and_free_vma:
71792 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71793 charged = 0;
71794 free_vma:
71795 +
71796 +#ifdef CONFIG_PAX_SEGMEXEC
71797 + if (vma_m)
71798 + kmem_cache_free(vm_area_cachep, vma_m);
71799 +#endif
71800 +
71801 kmem_cache_free(vm_area_cachep, vma);
71802 unacct_error:
71803 if (charged)
71804 @@ -1348,6 +1504,44 @@ unacct_error:
71805 return error;
71806 }
71807
71808 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71809 +{
71810 + if (!vma) {
71811 +#ifdef CONFIG_STACK_GROWSUP
71812 + if (addr > sysctl_heap_stack_gap)
71813 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71814 + else
71815 + vma = find_vma(current->mm, 0);
71816 + if (vma && (vma->vm_flags & VM_GROWSUP))
71817 + return false;
71818 +#endif
71819 + return true;
71820 + }
71821 +
71822 + if (addr + len > vma->vm_start)
71823 + return false;
71824 +
71825 + if (vma->vm_flags & VM_GROWSDOWN)
71826 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71827 +#ifdef CONFIG_STACK_GROWSUP
71828 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71829 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71830 +#endif
71831 +
71832 + return true;
71833 +}
71834 +
71835 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71836 +{
71837 + if (vma->vm_start < len)
71838 + return -ENOMEM;
71839 + if (!(vma->vm_flags & VM_GROWSDOWN))
71840 + return vma->vm_start - len;
71841 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
71842 + return vma->vm_start - len - sysctl_heap_stack_gap;
71843 + return -ENOMEM;
71844 +}
71845 +
71846 /* Get an address range which is currently unmapped.
71847 * For shmat() with addr=0.
71848 *
71849 @@ -1374,18 +1568,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71850 if (flags & MAP_FIXED)
71851 return addr;
71852
71853 +#ifdef CONFIG_PAX_RANDMMAP
71854 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71855 +#endif
71856 +
71857 if (addr) {
71858 addr = PAGE_ALIGN(addr);
71859 - vma = find_vma(mm, addr);
71860 - if (TASK_SIZE - len >= addr &&
71861 - (!vma || addr + len <= vma->vm_start))
71862 - return addr;
71863 + if (TASK_SIZE - len >= addr) {
71864 + vma = find_vma(mm, addr);
71865 + if (check_heap_stack_gap(vma, addr, len))
71866 + return addr;
71867 + }
71868 }
71869 if (len > mm->cached_hole_size) {
71870 - start_addr = addr = mm->free_area_cache;
71871 + start_addr = addr = mm->free_area_cache;
71872 } else {
71873 - start_addr = addr = TASK_UNMAPPED_BASE;
71874 - mm->cached_hole_size = 0;
71875 + start_addr = addr = mm->mmap_base;
71876 + mm->cached_hole_size = 0;
71877 }
71878
71879 full_search:
71880 @@ -1396,34 +1595,40 @@ full_search:
71881 * Start a new search - just in case we missed
71882 * some holes.
71883 */
71884 - if (start_addr != TASK_UNMAPPED_BASE) {
71885 - addr = TASK_UNMAPPED_BASE;
71886 - start_addr = addr;
71887 + if (start_addr != mm->mmap_base) {
71888 + start_addr = addr = mm->mmap_base;
71889 mm->cached_hole_size = 0;
71890 goto full_search;
71891 }
71892 return -ENOMEM;
71893 }
71894 - if (!vma || addr + len <= vma->vm_start) {
71895 - /*
71896 - * Remember the place where we stopped the search:
71897 - */
71898 - mm->free_area_cache = addr + len;
71899 - return addr;
71900 - }
71901 + if (check_heap_stack_gap(vma, addr, len))
71902 + break;
71903 if (addr + mm->cached_hole_size < vma->vm_start)
71904 mm->cached_hole_size = vma->vm_start - addr;
71905 addr = vma->vm_end;
71906 }
71907 +
71908 + /*
71909 + * Remember the place where we stopped the search:
71910 + */
71911 + mm->free_area_cache = addr + len;
71912 + return addr;
71913 }
71914 #endif
71915
71916 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71917 {
71918 +
71919 +#ifdef CONFIG_PAX_SEGMEXEC
71920 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71921 + return;
71922 +#endif
71923 +
71924 /*
71925 * Is this a new hole at the lowest possible address?
71926 */
71927 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
71928 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
71929 mm->free_area_cache = addr;
71930 mm->cached_hole_size = ~0UL;
71931 }
71932 @@ -1441,7 +1646,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71933 {
71934 struct vm_area_struct *vma;
71935 struct mm_struct *mm = current->mm;
71936 - unsigned long addr = addr0;
71937 + unsigned long base = mm->mmap_base, addr = addr0;
71938
71939 /* requested length too big for entire address space */
71940 if (len > TASK_SIZE)
71941 @@ -1450,13 +1655,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71942 if (flags & MAP_FIXED)
71943 return addr;
71944
71945 +#ifdef CONFIG_PAX_RANDMMAP
71946 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71947 +#endif
71948 +
71949 /* requesting a specific address */
71950 if (addr) {
71951 addr = PAGE_ALIGN(addr);
71952 - vma = find_vma(mm, addr);
71953 - if (TASK_SIZE - len >= addr &&
71954 - (!vma || addr + len <= vma->vm_start))
71955 - return addr;
71956 + if (TASK_SIZE - len >= addr) {
71957 + vma = find_vma(mm, addr);
71958 + if (check_heap_stack_gap(vma, addr, len))
71959 + return addr;
71960 + }
71961 }
71962
71963 /* check if free_area_cache is useful for us */
71964 @@ -1471,7 +1681,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71965 /* make sure it can fit in the remaining address space */
71966 if (addr > len) {
71967 vma = find_vma(mm, addr-len);
71968 - if (!vma || addr <= vma->vm_start)
71969 + if (check_heap_stack_gap(vma, addr - len, len))
71970 /* remember the address as a hint for next time */
71971 return (mm->free_area_cache = addr-len);
71972 }
71973 @@ -1488,7 +1698,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71974 * return with success:
71975 */
71976 vma = find_vma(mm, addr);
71977 - if (!vma || addr+len <= vma->vm_start)
71978 + if (check_heap_stack_gap(vma, addr, len))
71979 /* remember the address as a hint for next time */
71980 return (mm->free_area_cache = addr);
71981
71982 @@ -1497,8 +1707,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71983 mm->cached_hole_size = vma->vm_start - addr;
71984
71985 /* try just below the current vma->vm_start */
71986 - addr = vma->vm_start-len;
71987 - } while (len < vma->vm_start);
71988 + addr = skip_heap_stack_gap(vma, len);
71989 + } while (!IS_ERR_VALUE(addr));
71990
71991 bottomup:
71992 /*
71993 @@ -1507,13 +1717,21 @@ bottomup:
71994 * can happen with large stack limits and large mmap()
71995 * allocations.
71996 */
71997 + mm->mmap_base = TASK_UNMAPPED_BASE;
71998 +
71999 +#ifdef CONFIG_PAX_RANDMMAP
72000 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72001 + mm->mmap_base += mm->delta_mmap;
72002 +#endif
72003 +
72004 + mm->free_area_cache = mm->mmap_base;
72005 mm->cached_hole_size = ~0UL;
72006 - mm->free_area_cache = TASK_UNMAPPED_BASE;
72007 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72008 /*
72009 * Restore the topdown base:
72010 */
72011 - mm->free_area_cache = mm->mmap_base;
72012 + mm->mmap_base = base;
72013 + mm->free_area_cache = base;
72014 mm->cached_hole_size = ~0UL;
72015
72016 return addr;
72017 @@ -1522,6 +1740,12 @@ bottomup:
72018
72019 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72020 {
72021 +
72022 +#ifdef CONFIG_PAX_SEGMEXEC
72023 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72024 + return;
72025 +#endif
72026 +
72027 /*
72028 * Is this a new hole at the highest possible address?
72029 */
72030 @@ -1529,8 +1753,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72031 mm->free_area_cache = addr;
72032
72033 /* dont allow allocations above current base */
72034 - if (mm->free_area_cache > mm->mmap_base)
72035 + if (mm->free_area_cache > mm->mmap_base) {
72036 mm->free_area_cache = mm->mmap_base;
72037 + mm->cached_hole_size = ~0UL;
72038 + }
72039 }
72040
72041 unsigned long
72042 @@ -1638,6 +1864,28 @@ out:
72043 return prev ? prev->vm_next : vma;
72044 }
72045
72046 +#ifdef CONFIG_PAX_SEGMEXEC
72047 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72048 +{
72049 + struct vm_area_struct *vma_m;
72050 +
72051 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72052 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72053 + BUG_ON(vma->vm_mirror);
72054 + return NULL;
72055 + }
72056 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72057 + vma_m = vma->vm_mirror;
72058 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72059 + BUG_ON(vma->vm_file != vma_m->vm_file);
72060 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72061 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72062 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72063 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72064 + return vma_m;
72065 +}
72066 +#endif
72067 +
72068 /*
72069 * Verify that the stack growth is acceptable and
72070 * update accounting. This is shared with both the
72071 @@ -1654,6 +1902,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72072 return -ENOMEM;
72073
72074 /* Stack limit test */
72075 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
72076 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72077 return -ENOMEM;
72078
72079 @@ -1664,6 +1913,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72080 locked = mm->locked_vm + grow;
72081 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72082 limit >>= PAGE_SHIFT;
72083 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72084 if (locked > limit && !capable(CAP_IPC_LOCK))
72085 return -ENOMEM;
72086 }
72087 @@ -1694,37 +1944,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72088 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72089 * vma is the last one with address > vma->vm_end. Have to extend vma.
72090 */
72091 +#ifndef CONFIG_IA64
72092 +static
72093 +#endif
72094 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72095 {
72096 int error;
72097 + bool locknext;
72098
72099 if (!(vma->vm_flags & VM_GROWSUP))
72100 return -EFAULT;
72101
72102 + /* Also guard against wrapping around to address 0. */
72103 + if (address < PAGE_ALIGN(address+1))
72104 + address = PAGE_ALIGN(address+1);
72105 + else
72106 + return -ENOMEM;
72107 +
72108 /*
72109 * We must make sure the anon_vma is allocated
72110 * so that the anon_vma locking is not a noop.
72111 */
72112 if (unlikely(anon_vma_prepare(vma)))
72113 return -ENOMEM;
72114 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72115 + if (locknext && anon_vma_prepare(vma->vm_next))
72116 + return -ENOMEM;
72117 vma_lock_anon_vma(vma);
72118 + if (locknext)
72119 + vma_lock_anon_vma(vma->vm_next);
72120
72121 /*
72122 * vma->vm_start/vm_end cannot change under us because the caller
72123 * is required to hold the mmap_sem in read mode. We need the
72124 - * anon_vma lock to serialize against concurrent expand_stacks.
72125 - * Also guard against wrapping around to address 0.
72126 + * anon_vma locks to serialize against concurrent expand_stacks
72127 + * and expand_upwards.
72128 */
72129 - if (address < PAGE_ALIGN(address+4))
72130 - address = PAGE_ALIGN(address+4);
72131 - else {
72132 - vma_unlock_anon_vma(vma);
72133 - return -ENOMEM;
72134 - }
72135 error = 0;
72136
72137 /* Somebody else might have raced and expanded it already */
72138 - if (address > vma->vm_end) {
72139 + if (vma->vm_next && (vma->vm_next->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && vma->vm_next->vm_start - address < sysctl_heap_stack_gap)
72140 + error = -ENOMEM;
72141 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72142 unsigned long size, grow;
72143
72144 size = address - vma->vm_start;
72145 @@ -1739,6 +2000,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72146 }
72147 }
72148 }
72149 + if (locknext)
72150 + vma_unlock_anon_vma(vma->vm_next);
72151 vma_unlock_anon_vma(vma);
72152 khugepaged_enter_vma_merge(vma);
72153 return error;
72154 @@ -1752,6 +2015,8 @@ int expand_downwards(struct vm_area_struct *vma,
72155 unsigned long address)
72156 {
72157 int error;
72158 + bool lockprev = false;
72159 + struct vm_area_struct *prev;
72160
72161 /*
72162 * We must make sure the anon_vma is allocated
72163 @@ -1765,6 +2030,15 @@ int expand_downwards(struct vm_area_struct *vma,
72164 if (error)
72165 return error;
72166
72167 + prev = vma->vm_prev;
72168 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72169 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72170 +#endif
72171 + if (lockprev && anon_vma_prepare(prev))
72172 + return -ENOMEM;
72173 + if (lockprev)
72174 + vma_lock_anon_vma(prev);
72175 +
72176 vma_lock_anon_vma(vma);
72177
72178 /*
72179 @@ -1774,9 +2048,17 @@ int expand_downwards(struct vm_area_struct *vma,
72180 */
72181
72182 /* Somebody else might have raced and expanded it already */
72183 - if (address < vma->vm_start) {
72184 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72185 + error = -ENOMEM;
72186 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72187 unsigned long size, grow;
72188
72189 +#ifdef CONFIG_PAX_SEGMEXEC
72190 + struct vm_area_struct *vma_m;
72191 +
72192 + vma_m = pax_find_mirror_vma(vma);
72193 +#endif
72194 +
72195 size = vma->vm_end - address;
72196 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72197
72198 @@ -1786,11 +2068,22 @@ int expand_downwards(struct vm_area_struct *vma,
72199 if (!error) {
72200 vma->vm_start = address;
72201 vma->vm_pgoff -= grow;
72202 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72203 +
72204 +#ifdef CONFIG_PAX_SEGMEXEC
72205 + if (vma_m) {
72206 + vma_m->vm_start -= grow << PAGE_SHIFT;
72207 + vma_m->vm_pgoff -= grow;
72208 + }
72209 +#endif
72210 +
72211 perf_event_mmap(vma);
72212 }
72213 }
72214 }
72215 vma_unlock_anon_vma(vma);
72216 + if (lockprev)
72217 + vma_unlock_anon_vma(prev);
72218 khugepaged_enter_vma_merge(vma);
72219 return error;
72220 }
72221 @@ -1860,6 +2153,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72222 do {
72223 long nrpages = vma_pages(vma);
72224
72225 +#ifdef CONFIG_PAX_SEGMEXEC
72226 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72227 + vma = remove_vma(vma);
72228 + continue;
72229 + }
72230 +#endif
72231 +
72232 mm->total_vm -= nrpages;
72233 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
72234 vma = remove_vma(vma);
72235 @@ -1905,6 +2205,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72236 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72237 vma->vm_prev = NULL;
72238 do {
72239 +
72240 +#ifdef CONFIG_PAX_SEGMEXEC
72241 + if (vma->vm_mirror) {
72242 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72243 + vma->vm_mirror->vm_mirror = NULL;
72244 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72245 + vma->vm_mirror = NULL;
72246 + }
72247 +#endif
72248 +
72249 rb_erase(&vma->vm_rb, &mm->mm_rb);
72250 mm->map_count--;
72251 tail_vma = vma;
72252 @@ -1933,14 +2243,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72253 struct vm_area_struct *new;
72254 int err = -ENOMEM;
72255
72256 +#ifdef CONFIG_PAX_SEGMEXEC
72257 + struct vm_area_struct *vma_m, *new_m = NULL;
72258 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72259 +#endif
72260 +
72261 if (is_vm_hugetlb_page(vma) && (addr &
72262 ~(huge_page_mask(hstate_vma(vma)))))
72263 return -EINVAL;
72264
72265 +#ifdef CONFIG_PAX_SEGMEXEC
72266 + vma_m = pax_find_mirror_vma(vma);
72267 +#endif
72268 +
72269 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72270 if (!new)
72271 goto out_err;
72272
72273 +#ifdef CONFIG_PAX_SEGMEXEC
72274 + if (vma_m) {
72275 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72276 + if (!new_m) {
72277 + kmem_cache_free(vm_area_cachep, new);
72278 + goto out_err;
72279 + }
72280 + }
72281 +#endif
72282 +
72283 /* most fields are the same, copy all, and then fixup */
72284 *new = *vma;
72285
72286 @@ -1953,6 +2282,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72287 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72288 }
72289
72290 +#ifdef CONFIG_PAX_SEGMEXEC
72291 + if (vma_m) {
72292 + *new_m = *vma_m;
72293 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72294 + new_m->vm_mirror = new;
72295 + new->vm_mirror = new_m;
72296 +
72297 + if (new_below)
72298 + new_m->vm_end = addr_m;
72299 + else {
72300 + new_m->vm_start = addr_m;
72301 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72302 + }
72303 + }
72304 +#endif
72305 +
72306 pol = mpol_dup(vma_policy(vma));
72307 if (IS_ERR(pol)) {
72308 err = PTR_ERR(pol);
72309 @@ -1978,6 +2323,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72310 else
72311 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72312
72313 +#ifdef CONFIG_PAX_SEGMEXEC
72314 + if (!err && vma_m) {
72315 + if (anon_vma_clone(new_m, vma_m))
72316 + goto out_free_mpol;
72317 +
72318 + mpol_get(pol);
72319 + vma_set_policy(new_m, pol);
72320 +
72321 + if (new_m->vm_file) {
72322 + get_file(new_m->vm_file);
72323 + if (vma_m->vm_flags & VM_EXECUTABLE)
72324 + added_exe_file_vma(mm);
72325 + }
72326 +
72327 + if (new_m->vm_ops && new_m->vm_ops->open)
72328 + new_m->vm_ops->open(new_m);
72329 +
72330 + if (new_below)
72331 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72332 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72333 + else
72334 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72335 +
72336 + if (err) {
72337 + if (new_m->vm_ops && new_m->vm_ops->close)
72338 + new_m->vm_ops->close(new_m);
72339 + if (new_m->vm_file) {
72340 + if (vma_m->vm_flags & VM_EXECUTABLE)
72341 + removed_exe_file_vma(mm);
72342 + fput(new_m->vm_file);
72343 + }
72344 + mpol_put(pol);
72345 + }
72346 + }
72347 +#endif
72348 +
72349 /* Success. */
72350 if (!err)
72351 return 0;
72352 @@ -1990,10 +2371,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72353 removed_exe_file_vma(mm);
72354 fput(new->vm_file);
72355 }
72356 - unlink_anon_vmas(new);
72357 out_free_mpol:
72358 mpol_put(pol);
72359 out_free_vma:
72360 +
72361 +#ifdef CONFIG_PAX_SEGMEXEC
72362 + if (new_m) {
72363 + unlink_anon_vmas(new_m);
72364 + kmem_cache_free(vm_area_cachep, new_m);
72365 + }
72366 +#endif
72367 +
72368 + unlink_anon_vmas(new);
72369 kmem_cache_free(vm_area_cachep, new);
72370 out_err:
72371 return err;
72372 @@ -2006,6 +2395,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72373 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72374 unsigned long addr, int new_below)
72375 {
72376 +
72377 +#ifdef CONFIG_PAX_SEGMEXEC
72378 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72379 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72380 + if (mm->map_count >= sysctl_max_map_count-1)
72381 + return -ENOMEM;
72382 + } else
72383 +#endif
72384 +
72385 if (mm->map_count >= sysctl_max_map_count)
72386 return -ENOMEM;
72387
72388 @@ -2017,11 +2415,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72389 * work. This now handles partial unmappings.
72390 * Jeremy Fitzhardinge <jeremy@goop.org>
72391 */
72392 +#ifdef CONFIG_PAX_SEGMEXEC
72393 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72394 {
72395 + int ret = __do_munmap(mm, start, len);
72396 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72397 + return ret;
72398 +
72399 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72400 +}
72401 +
72402 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72403 +#else
72404 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72405 +#endif
72406 +{
72407 unsigned long end;
72408 struct vm_area_struct *vma, *prev, *last;
72409
72410 + /*
72411 + * mm->mmap_sem is required to protect against another thread
72412 + * changing the mappings in case we sleep.
72413 + */
72414 + verify_mm_writelocked(mm);
72415 +
72416 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72417 return -EINVAL;
72418
72419 @@ -2096,6 +2513,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72420 /* Fix up all other VM information */
72421 remove_vma_list(mm, vma);
72422
72423 + track_exec_limit(mm, start, end, 0UL);
72424 +
72425 return 0;
72426 }
72427
72428 @@ -2108,22 +2527,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72429
72430 profile_munmap(addr);
72431
72432 +#ifdef CONFIG_PAX_SEGMEXEC
72433 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72434 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
72435 + return -EINVAL;
72436 +#endif
72437 +
72438 down_write(&mm->mmap_sem);
72439 ret = do_munmap(mm, addr, len);
72440 up_write(&mm->mmap_sem);
72441 return ret;
72442 }
72443
72444 -static inline void verify_mm_writelocked(struct mm_struct *mm)
72445 -{
72446 -#ifdef CONFIG_DEBUG_VM
72447 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72448 - WARN_ON(1);
72449 - up_read(&mm->mmap_sem);
72450 - }
72451 -#endif
72452 -}
72453 -
72454 /*
72455 * this is really a simplified "do_mmap". it only handles
72456 * anonymous maps. eventually we may be able to do some
72457 @@ -2137,6 +2552,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72458 struct rb_node ** rb_link, * rb_parent;
72459 pgoff_t pgoff = addr >> PAGE_SHIFT;
72460 int error;
72461 + unsigned long charged;
72462
72463 len = PAGE_ALIGN(len);
72464 if (!len)
72465 @@ -2148,16 +2564,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72466
72467 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72468
72469 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72470 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72471 + flags &= ~VM_EXEC;
72472 +
72473 +#ifdef CONFIG_PAX_MPROTECT
72474 + if (mm->pax_flags & MF_PAX_MPROTECT)
72475 + flags &= ~VM_MAYEXEC;
72476 +#endif
72477 +
72478 + }
72479 +#endif
72480 +
72481 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72482 if (error & ~PAGE_MASK)
72483 return error;
72484
72485 + charged = len >> PAGE_SHIFT;
72486 +
72487 /*
72488 * mlock MCL_FUTURE?
72489 */
72490 if (mm->def_flags & VM_LOCKED) {
72491 unsigned long locked, lock_limit;
72492 - locked = len >> PAGE_SHIFT;
72493 + locked = charged;
72494 locked += mm->locked_vm;
72495 lock_limit = rlimit(RLIMIT_MEMLOCK);
72496 lock_limit >>= PAGE_SHIFT;
72497 @@ -2174,22 +2604,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72498 /*
72499 * Clear old maps. this also does some error checking for us
72500 */
72501 - munmap_back:
72502 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72503 if (vma && vma->vm_start < addr + len) {
72504 if (do_munmap(mm, addr, len))
72505 return -ENOMEM;
72506 - goto munmap_back;
72507 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72508 + BUG_ON(vma && vma->vm_start < addr + len);
72509 }
72510
72511 /* Check against address space limits *after* clearing old maps... */
72512 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72513 + if (!may_expand_vm(mm, charged))
72514 return -ENOMEM;
72515
72516 if (mm->map_count > sysctl_max_map_count)
72517 return -ENOMEM;
72518
72519 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
72520 + if (security_vm_enough_memory(charged))
72521 return -ENOMEM;
72522
72523 /* Can we just expand an old private anonymous mapping? */
72524 @@ -2203,7 +2633,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72525 */
72526 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72527 if (!vma) {
72528 - vm_unacct_memory(len >> PAGE_SHIFT);
72529 + vm_unacct_memory(charged);
72530 return -ENOMEM;
72531 }
72532
72533 @@ -2217,11 +2647,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72534 vma_link(mm, vma, prev, rb_link, rb_parent);
72535 out:
72536 perf_event_mmap(vma);
72537 - mm->total_vm += len >> PAGE_SHIFT;
72538 + mm->total_vm += charged;
72539 if (flags & VM_LOCKED) {
72540 if (!mlock_vma_pages_range(vma, addr, addr + len))
72541 - mm->locked_vm += (len >> PAGE_SHIFT);
72542 + mm->locked_vm += charged;
72543 }
72544 + track_exec_limit(mm, addr, addr + len, flags);
72545 return addr;
72546 }
72547
72548 @@ -2268,8 +2699,10 @@ void exit_mmap(struct mm_struct *mm)
72549 * Walk the list again, actually closing and freeing it,
72550 * with preemption enabled, without holding any MM locks.
72551 */
72552 - while (vma)
72553 + while (vma) {
72554 + vma->vm_mirror = NULL;
72555 vma = remove_vma(vma);
72556 + }
72557
72558 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
72559 }
72560 @@ -2283,6 +2716,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72561 struct vm_area_struct * __vma, * prev;
72562 struct rb_node ** rb_link, * rb_parent;
72563
72564 +#ifdef CONFIG_PAX_SEGMEXEC
72565 + struct vm_area_struct *vma_m = NULL;
72566 +#endif
72567 +
72568 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
72569 + return -EPERM;
72570 +
72571 /*
72572 * The vm_pgoff of a purely anonymous vma should be irrelevant
72573 * until its first write fault, when page's anon_vma and index
72574 @@ -2305,7 +2745,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72575 if ((vma->vm_flags & VM_ACCOUNT) &&
72576 security_vm_enough_memory_mm(mm, vma_pages(vma)))
72577 return -ENOMEM;
72578 +
72579 +#ifdef CONFIG_PAX_SEGMEXEC
72580 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72581 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72582 + if (!vma_m)
72583 + return -ENOMEM;
72584 + }
72585 +#endif
72586 +
72587 vma_link(mm, vma, prev, rb_link, rb_parent);
72588 +
72589 +#ifdef CONFIG_PAX_SEGMEXEC
72590 + if (vma_m)
72591 + BUG_ON(pax_mirror_vma(vma_m, vma));
72592 +#endif
72593 +
72594 return 0;
72595 }
72596
72597 @@ -2323,6 +2778,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72598 struct rb_node **rb_link, *rb_parent;
72599 struct mempolicy *pol;
72600
72601 + BUG_ON(vma->vm_mirror);
72602 +
72603 /*
72604 * If anonymous vma has not yet been faulted, update new pgoff
72605 * to match new location, to increase its chance of merging.
72606 @@ -2373,6 +2830,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72607 return NULL;
72608 }
72609
72610 +#ifdef CONFIG_PAX_SEGMEXEC
72611 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
72612 +{
72613 + struct vm_area_struct *prev_m;
72614 + struct rb_node **rb_link_m, *rb_parent_m;
72615 + struct mempolicy *pol_m;
72616 +
72617 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
72618 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
72619 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
72620 + *vma_m = *vma;
72621 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
72622 + if (anon_vma_clone(vma_m, vma))
72623 + return -ENOMEM;
72624 + pol_m = vma_policy(vma_m);
72625 + mpol_get(pol_m);
72626 + vma_set_policy(vma_m, pol_m);
72627 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
72628 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
72629 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
72630 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
72631 + if (vma_m->vm_file)
72632 + get_file(vma_m->vm_file);
72633 + if (vma_m->vm_ops && vma_m->vm_ops->open)
72634 + vma_m->vm_ops->open(vma_m);
72635 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
72636 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
72637 + vma_m->vm_mirror = vma;
72638 + vma->vm_mirror = vma_m;
72639 + return 0;
72640 +}
72641 +#endif
72642 +
72643 /*
72644 * Return true if the calling process may expand its vm space by the passed
72645 * number of pages
72646 @@ -2383,7 +2873,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
72647 unsigned long lim;
72648
72649 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
72650 -
72651 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
72652 if (cur + npages > lim)
72653 return 0;
72654 return 1;
72655 @@ -2454,6 +2944,22 @@ int install_special_mapping(struct mm_struct *mm,
72656 vma->vm_start = addr;
72657 vma->vm_end = addr + len;
72658
72659 +#ifdef CONFIG_PAX_MPROTECT
72660 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72661 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72662 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
72663 + return -EPERM;
72664 + if (!(vm_flags & VM_EXEC))
72665 + vm_flags &= ~VM_MAYEXEC;
72666 +#else
72667 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72668 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72669 +#endif
72670 + else
72671 + vm_flags &= ~VM_MAYWRITE;
72672 + }
72673 +#endif
72674 +
72675 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
72676 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72677
72678 diff --git a/mm/mprotect.c b/mm/mprotect.c
72679 index 5a688a2..27e031c 100644
72680 --- a/mm/mprotect.c
72681 +++ b/mm/mprotect.c
72682 @@ -23,10 +23,16 @@
72683 #include <linux/mmu_notifier.h>
72684 #include <linux/migrate.h>
72685 #include <linux/perf_event.h>
72686 +
72687 +#ifdef CONFIG_PAX_MPROTECT
72688 +#include <linux/elf.h>
72689 +#endif
72690 +
72691 #include <asm/uaccess.h>
72692 #include <asm/pgtable.h>
72693 #include <asm/cacheflush.h>
72694 #include <asm/tlbflush.h>
72695 +#include <asm/mmu_context.h>
72696
72697 #ifndef pgprot_modify
72698 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
72699 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
72700 flush_tlb_range(vma, start, end);
72701 }
72702
72703 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72704 +/* called while holding the mmap semaphor for writing except stack expansion */
72705 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
72706 +{
72707 + unsigned long oldlimit, newlimit = 0UL;
72708 +
72709 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72710 + return;
72711 +
72712 + spin_lock(&mm->page_table_lock);
72713 + oldlimit = mm->context.user_cs_limit;
72714 + if ((prot & VM_EXEC) && oldlimit < end)
72715 + /* USER_CS limit moved up */
72716 + newlimit = end;
72717 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72718 + /* USER_CS limit moved down */
72719 + newlimit = start;
72720 +
72721 + if (newlimit) {
72722 + mm->context.user_cs_limit = newlimit;
72723 +
72724 +#ifdef CONFIG_SMP
72725 + wmb();
72726 + cpus_clear(mm->context.cpu_user_cs_mask);
72727 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72728 +#endif
72729 +
72730 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72731 + }
72732 + spin_unlock(&mm->page_table_lock);
72733 + if (newlimit == end) {
72734 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
72735 +
72736 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
72737 + if (is_vm_hugetlb_page(vma))
72738 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72739 + else
72740 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72741 + }
72742 +}
72743 +#endif
72744 +
72745 int
72746 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72747 unsigned long start, unsigned long end, unsigned long newflags)
72748 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72749 int error;
72750 int dirty_accountable = 0;
72751
72752 +#ifdef CONFIG_PAX_SEGMEXEC
72753 + struct vm_area_struct *vma_m = NULL;
72754 + unsigned long start_m, end_m;
72755 +
72756 + start_m = start + SEGMEXEC_TASK_SIZE;
72757 + end_m = end + SEGMEXEC_TASK_SIZE;
72758 +#endif
72759 +
72760 if (newflags == oldflags) {
72761 *pprev = vma;
72762 return 0;
72763 }
72764
72765 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72766 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72767 +
72768 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72769 + return -ENOMEM;
72770 +
72771 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72772 + return -ENOMEM;
72773 + }
72774 +
72775 /*
72776 * If we make a private mapping writable we increase our commit;
72777 * but (without finer accounting) cannot reduce our commit if we
72778 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72779 }
72780 }
72781
72782 +#ifdef CONFIG_PAX_SEGMEXEC
72783 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72784 + if (start != vma->vm_start) {
72785 + error = split_vma(mm, vma, start, 1);
72786 + if (error)
72787 + goto fail;
72788 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72789 + *pprev = (*pprev)->vm_next;
72790 + }
72791 +
72792 + if (end != vma->vm_end) {
72793 + error = split_vma(mm, vma, end, 0);
72794 + if (error)
72795 + goto fail;
72796 + }
72797 +
72798 + if (pax_find_mirror_vma(vma)) {
72799 + error = __do_munmap(mm, start_m, end_m - start_m);
72800 + if (error)
72801 + goto fail;
72802 + } else {
72803 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72804 + if (!vma_m) {
72805 + error = -ENOMEM;
72806 + goto fail;
72807 + }
72808 + vma->vm_flags = newflags;
72809 + error = pax_mirror_vma(vma_m, vma);
72810 + if (error) {
72811 + vma->vm_flags = oldflags;
72812 + goto fail;
72813 + }
72814 + }
72815 + }
72816 +#endif
72817 +
72818 /*
72819 * First try to merge with previous and/or next vma.
72820 */
72821 @@ -204,9 +306,21 @@ success:
72822 * vm_flags and vm_page_prot are protected by the mmap_sem
72823 * held in write mode.
72824 */
72825 +
72826 +#ifdef CONFIG_PAX_SEGMEXEC
72827 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72828 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72829 +#endif
72830 +
72831 vma->vm_flags = newflags;
72832 +
72833 +#ifdef CONFIG_PAX_MPROTECT
72834 + if (mm->binfmt && mm->binfmt->handle_mprotect)
72835 + mm->binfmt->handle_mprotect(vma, newflags);
72836 +#endif
72837 +
72838 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72839 - vm_get_page_prot(newflags));
72840 + vm_get_page_prot(vma->vm_flags));
72841
72842 if (vma_wants_writenotify(vma)) {
72843 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72844 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72845 end = start + len;
72846 if (end <= start)
72847 return -ENOMEM;
72848 +
72849 +#ifdef CONFIG_PAX_SEGMEXEC
72850 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72851 + if (end > SEGMEXEC_TASK_SIZE)
72852 + return -EINVAL;
72853 + } else
72854 +#endif
72855 +
72856 + if (end > TASK_SIZE)
72857 + return -EINVAL;
72858 +
72859 if (!arch_validate_prot(prot))
72860 return -EINVAL;
72861
72862 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72863 /*
72864 * Does the application expect PROT_READ to imply PROT_EXEC:
72865 */
72866 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72867 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72868 prot |= PROT_EXEC;
72869
72870 vm_flags = calc_vm_prot_bits(prot);
72871 @@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72872 if (start > vma->vm_start)
72873 prev = vma;
72874
72875 +#ifdef CONFIG_PAX_MPROTECT
72876 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72877 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
72878 +#endif
72879 +
72880 for (nstart = start ; ; ) {
72881 unsigned long newflags;
72882
72883 @@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72884
72885 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72886 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72887 + if (prot & (PROT_WRITE | PROT_EXEC))
72888 + gr_log_rwxmprotect(vma->vm_file);
72889 +
72890 + error = -EACCES;
72891 + goto out;
72892 + }
72893 +
72894 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72895 error = -EACCES;
72896 goto out;
72897 }
72898 @@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72899 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72900 if (error)
72901 goto out;
72902 +
72903 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
72904 +
72905 nstart = tmp;
72906
72907 if (nstart < prev->vm_end)
72908 diff --git a/mm/mremap.c b/mm/mremap.c
72909 index 506fa44..ccc0ba9 100644
72910 --- a/mm/mremap.c
72911 +++ b/mm/mremap.c
72912 @@ -113,6 +113,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72913 continue;
72914 pte = ptep_clear_flush(vma, old_addr, old_pte);
72915 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72916 +
72917 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72918 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72919 + pte = pte_exprotect(pte);
72920 +#endif
72921 +
72922 set_pte_at(mm, new_addr, new_pte, pte);
72923 }
72924
72925 @@ -272,6 +278,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72926 if (is_vm_hugetlb_page(vma))
72927 goto Einval;
72928
72929 +#ifdef CONFIG_PAX_SEGMEXEC
72930 + if (pax_find_mirror_vma(vma))
72931 + goto Einval;
72932 +#endif
72933 +
72934 /* We can't remap across vm area boundaries */
72935 if (old_len > vma->vm_end - addr)
72936 goto Efault;
72937 @@ -328,20 +339,25 @@ static unsigned long mremap_to(unsigned long addr,
72938 unsigned long ret = -EINVAL;
72939 unsigned long charged = 0;
72940 unsigned long map_flags;
72941 + unsigned long pax_task_size = TASK_SIZE;
72942
72943 if (new_addr & ~PAGE_MASK)
72944 goto out;
72945
72946 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72947 +#ifdef CONFIG_PAX_SEGMEXEC
72948 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72949 + pax_task_size = SEGMEXEC_TASK_SIZE;
72950 +#endif
72951 +
72952 + pax_task_size -= PAGE_SIZE;
72953 +
72954 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72955 goto out;
72956
72957 /* Check if the location we're moving into overlaps the
72958 * old location at all, and fail if it does.
72959 */
72960 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
72961 - goto out;
72962 -
72963 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
72964 + if (addr + old_len > new_addr && new_addr + new_len > addr)
72965 goto out;
72966
72967 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72968 @@ -413,6 +429,7 @@ unsigned long do_mremap(unsigned long addr,
72969 struct vm_area_struct *vma;
72970 unsigned long ret = -EINVAL;
72971 unsigned long charged = 0;
72972 + unsigned long pax_task_size = TASK_SIZE;
72973
72974 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72975 goto out;
72976 @@ -431,6 +448,17 @@ unsigned long do_mremap(unsigned long addr,
72977 if (!new_len)
72978 goto out;
72979
72980 +#ifdef CONFIG_PAX_SEGMEXEC
72981 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72982 + pax_task_size = SEGMEXEC_TASK_SIZE;
72983 +#endif
72984 +
72985 + pax_task_size -= PAGE_SIZE;
72986 +
72987 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
72988 + old_len > pax_task_size || addr > pax_task_size-old_len)
72989 + goto out;
72990 +
72991 if (flags & MREMAP_FIXED) {
72992 if (flags & MREMAP_MAYMOVE)
72993 ret = mremap_to(addr, old_len, new_addr, new_len);
72994 @@ -480,6 +508,7 @@ unsigned long do_mremap(unsigned long addr,
72995 addr + new_len);
72996 }
72997 ret = addr;
72998 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
72999 goto out;
73000 }
73001 }
73002 @@ -506,7 +535,13 @@ unsigned long do_mremap(unsigned long addr,
73003 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73004 if (ret)
73005 goto out;
73006 +
73007 + map_flags = vma->vm_flags;
73008 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73009 + if (!(ret & ~PAGE_MASK)) {
73010 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73011 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73012 + }
73013 }
73014 out:
73015 if (ret & ~PAGE_MASK)
73016 diff --git a/mm/nobootmem.c b/mm/nobootmem.c
73017 index 6e93dc7..c98df0c 100644
73018 --- a/mm/nobootmem.c
73019 +++ b/mm/nobootmem.c
73020 @@ -110,19 +110,30 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
73021 unsigned long __init free_all_memory_core_early(int nodeid)
73022 {
73023 int i;
73024 - u64 start, end;
73025 + u64 start, end, startrange, endrange;
73026 unsigned long count = 0;
73027 - struct range *range = NULL;
73028 + struct range *range = NULL, rangerange = { 0, 0 };
73029 int nr_range;
73030
73031 nr_range = get_free_all_memory_range(&range, nodeid);
73032 + startrange = __pa(range) >> PAGE_SHIFT;
73033 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
73034
73035 for (i = 0; i < nr_range; i++) {
73036 start = range[i].start;
73037 end = range[i].end;
73038 + if (start <= endrange && startrange < end) {
73039 + BUG_ON(rangerange.start | rangerange.end);
73040 + rangerange = range[i];
73041 + continue;
73042 + }
73043 count += end - start;
73044 __free_pages_memory(start, end);
73045 }
73046 + start = rangerange.start;
73047 + end = rangerange.end;
73048 + count += end - start;
73049 + __free_pages_memory(start, end);
73050
73051 return count;
73052 }
73053 diff --git a/mm/nommu.c b/mm/nommu.c
73054 index 4358032..e79b99f 100644
73055 --- a/mm/nommu.c
73056 +++ b/mm/nommu.c
73057 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73058 int sysctl_overcommit_ratio = 50; /* default is 50% */
73059 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73060 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73061 -int heap_stack_gap = 0;
73062
73063 atomic_long_t mmap_pages_allocated;
73064
73065 @@ -825,15 +824,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73066 EXPORT_SYMBOL(find_vma);
73067
73068 /*
73069 - * find a VMA
73070 - * - we don't extend stack VMAs under NOMMU conditions
73071 - */
73072 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73073 -{
73074 - return find_vma(mm, addr);
73075 -}
73076 -
73077 -/*
73078 * expand a stack to a given address
73079 * - not supported under NOMMU conditions
73080 */
73081 @@ -1553,6 +1543,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73082
73083 /* most fields are the same, copy all, and then fixup */
73084 *new = *vma;
73085 + INIT_LIST_HEAD(&new->anon_vma_chain);
73086 *region = *vma->vm_region;
73087 new->vm_region = region;
73088
73089 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73090 index e8fae15..18c0442 100644
73091 --- a/mm/page_alloc.c
73092 +++ b/mm/page_alloc.c
73093 @@ -340,7 +340,7 @@ out:
73094 * This usage means that zero-order pages may not be compound.
73095 */
73096
73097 -static void free_compound_page(struct page *page)
73098 +void free_compound_page(struct page *page)
73099 {
73100 __free_pages_ok(page, compound_order(page));
73101 }
73102 @@ -653,6 +653,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73103 int i;
73104 int bad = 0;
73105
73106 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73107 + unsigned long index = 1UL << order;
73108 +#endif
73109 +
73110 trace_mm_page_free_direct(page, order);
73111 kmemcheck_free_shadow(page, order);
73112
73113 @@ -668,6 +672,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73114 debug_check_no_obj_freed(page_address(page),
73115 PAGE_SIZE << order);
73116 }
73117 +
73118 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73119 + for (; index; --index)
73120 + sanitize_highpage(page + index - 1);
73121 +#endif
73122 +
73123 arch_free_page(page, order);
73124 kernel_map_pages(page, 1 << order, 0);
73125
73126 @@ -783,8 +793,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73127 arch_alloc_page(page, order);
73128 kernel_map_pages(page, 1 << order, 1);
73129
73130 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73131 if (gfp_flags & __GFP_ZERO)
73132 prep_zero_page(page, order, gfp_flags);
73133 +#endif
73134
73135 if (order && (gfp_flags & __GFP_COMP))
73136 prep_compound_page(page, order);
73137 @@ -2539,6 +2551,8 @@ void show_free_areas(unsigned int filter)
73138 int cpu;
73139 struct zone *zone;
73140
73141 + pax_track_stack();
73142 +
73143 for_each_populated_zone(zone) {
73144 if (skip_free_areas_node(filter, zone_to_nid(zone)))
73145 continue;
73146 @@ -3350,7 +3364,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73147 unsigned long pfn;
73148
73149 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73150 +#ifdef CONFIG_X86_32
73151 + /* boot failures in VMware 8 on 32bit vanilla since
73152 + this change */
73153 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73154 +#else
73155 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73156 +#endif
73157 return 1;
73158 }
73159 return 0;
73160 diff --git a/mm/percpu.c b/mm/percpu.c
73161 index 0ae7a09..613118e 100644
73162 --- a/mm/percpu.c
73163 +++ b/mm/percpu.c
73164 @@ -121,7 +121,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73165 static unsigned int pcpu_high_unit_cpu __read_mostly;
73166
73167 /* the address of the first chunk which starts with the kernel static area */
73168 -void *pcpu_base_addr __read_mostly;
73169 +void *pcpu_base_addr __read_only;
73170 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73171
73172 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73173 diff --git a/mm/rmap.c b/mm/rmap.c
73174 index 8005080..198c2cd 100644
73175 --- a/mm/rmap.c
73176 +++ b/mm/rmap.c
73177 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73178 struct anon_vma *anon_vma = vma->anon_vma;
73179 struct anon_vma_chain *avc;
73180
73181 +#ifdef CONFIG_PAX_SEGMEXEC
73182 + struct anon_vma_chain *avc_m = NULL;
73183 +#endif
73184 +
73185 might_sleep();
73186 if (unlikely(!anon_vma)) {
73187 struct mm_struct *mm = vma->vm_mm;
73188 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73189 if (!avc)
73190 goto out_enomem;
73191
73192 +#ifdef CONFIG_PAX_SEGMEXEC
73193 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73194 + if (!avc_m)
73195 + goto out_enomem_free_avc;
73196 +#endif
73197 +
73198 anon_vma = find_mergeable_anon_vma(vma);
73199 allocated = NULL;
73200 if (!anon_vma) {
73201 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73202 /* page_table_lock to protect against threads */
73203 spin_lock(&mm->page_table_lock);
73204 if (likely(!vma->anon_vma)) {
73205 +
73206 +#ifdef CONFIG_PAX_SEGMEXEC
73207 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73208 +
73209 + if (vma_m) {
73210 + BUG_ON(vma_m->anon_vma);
73211 + vma_m->anon_vma = anon_vma;
73212 + avc_m->anon_vma = anon_vma;
73213 + avc_m->vma = vma;
73214 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
73215 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
73216 + avc_m = NULL;
73217 + }
73218 +#endif
73219 +
73220 vma->anon_vma = anon_vma;
73221 avc->anon_vma = anon_vma;
73222 avc->vma = vma;
73223 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73224
73225 if (unlikely(allocated))
73226 put_anon_vma(allocated);
73227 +
73228 +#ifdef CONFIG_PAX_SEGMEXEC
73229 + if (unlikely(avc_m))
73230 + anon_vma_chain_free(avc_m);
73231 +#endif
73232 +
73233 if (unlikely(avc))
73234 anon_vma_chain_free(avc);
73235 }
73236 return 0;
73237
73238 out_enomem_free_avc:
73239 +
73240 +#ifdef CONFIG_PAX_SEGMEXEC
73241 + if (avc_m)
73242 + anon_vma_chain_free(avc_m);
73243 +#endif
73244 +
73245 anon_vma_chain_free(avc);
73246 out_enomem:
73247 return -ENOMEM;
73248 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
73249 * Attach the anon_vmas from src to dst.
73250 * Returns 0 on success, -ENOMEM on failure.
73251 */
73252 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73253 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73254 {
73255 struct anon_vma_chain *avc, *pavc;
73256 struct anon_vma *root = NULL;
73257 @@ -276,7 +313,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73258 * the corresponding VMA in the parent process is attached to.
73259 * Returns 0 on success, non-zero on failure.
73260 */
73261 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73262 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73263 {
73264 struct anon_vma_chain *avc;
73265 struct anon_vma *anon_vma;
73266 diff --git a/mm/shmem.c b/mm/shmem.c
73267 index 32f6763..431c405 100644
73268 --- a/mm/shmem.c
73269 +++ b/mm/shmem.c
73270 @@ -31,7 +31,7 @@
73271 #include <linux/module.h>
73272 #include <linux/swap.h>
73273
73274 -static struct vfsmount *shm_mnt;
73275 +struct vfsmount *shm_mnt;
73276
73277 #ifdef CONFIG_SHMEM
73278 /*
73279 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
73280 #define BOGO_DIRENT_SIZE 20
73281
73282 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73283 -#define SHORT_SYMLINK_LEN 128
73284 +#define SHORT_SYMLINK_LEN 64
73285
73286 struct shmem_xattr {
73287 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73288 @@ -769,6 +769,8 @@ static struct page *shmem_swapin(swp_entry_t swap, gfp_t gfp,
73289 struct mempolicy mpol, *spol;
73290 struct vm_area_struct pvma;
73291
73292 + pax_track_stack();
73293 +
73294 spol = mpol_cond_copy(&mpol,
73295 mpol_shared_policy_lookup(&info->policy, index));
73296
73297 @@ -2149,8 +2151,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73298 int err = -ENOMEM;
73299
73300 /* Round up to L1_CACHE_BYTES to resist false sharing */
73301 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73302 - L1_CACHE_BYTES), GFP_KERNEL);
73303 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73304 if (!sbinfo)
73305 return -ENOMEM;
73306
73307 diff --git a/mm/slab.c b/mm/slab.c
73308 index 893c76d..a742de2 100644
73309 --- a/mm/slab.c
73310 +++ b/mm/slab.c
73311 @@ -151,7 +151,7 @@
73312
73313 /* Legal flag mask for kmem_cache_create(). */
73314 #if DEBUG
73315 -# define CREATE_MASK (SLAB_RED_ZONE | \
73316 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73317 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73318 SLAB_CACHE_DMA | \
73319 SLAB_STORE_USER | \
73320 @@ -159,7 +159,7 @@
73321 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73322 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73323 #else
73324 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73325 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73326 SLAB_CACHE_DMA | \
73327 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73328 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73329 @@ -288,7 +288,7 @@ struct kmem_list3 {
73330 * Need this for bootstrapping a per node allocator.
73331 */
73332 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73333 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73334 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73335 #define CACHE_CACHE 0
73336 #define SIZE_AC MAX_NUMNODES
73337 #define SIZE_L3 (2 * MAX_NUMNODES)
73338 @@ -389,10 +389,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73339 if ((x)->max_freeable < i) \
73340 (x)->max_freeable = i; \
73341 } while (0)
73342 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73343 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73344 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73345 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73346 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73347 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73348 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73349 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73350 #else
73351 #define STATS_INC_ACTIVE(x) do { } while (0)
73352 #define STATS_DEC_ACTIVE(x) do { } while (0)
73353 @@ -538,7 +538,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73354 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73355 */
73356 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73357 - const struct slab *slab, void *obj)
73358 + const struct slab *slab, const void *obj)
73359 {
73360 u32 offset = (obj - slab->s_mem);
73361 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73362 @@ -564,7 +564,7 @@ struct cache_names {
73363 static struct cache_names __initdata cache_names[] = {
73364 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73365 #include <linux/kmalloc_sizes.h>
73366 - {NULL,}
73367 + {NULL}
73368 #undef CACHE
73369 };
73370
73371 @@ -1572,7 +1572,7 @@ void __init kmem_cache_init(void)
73372 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73373 sizes[INDEX_AC].cs_size,
73374 ARCH_KMALLOC_MINALIGN,
73375 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73376 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73377 NULL);
73378
73379 if (INDEX_AC != INDEX_L3) {
73380 @@ -1580,7 +1580,7 @@ void __init kmem_cache_init(void)
73381 kmem_cache_create(names[INDEX_L3].name,
73382 sizes[INDEX_L3].cs_size,
73383 ARCH_KMALLOC_MINALIGN,
73384 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73385 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73386 NULL);
73387 }
73388
73389 @@ -1598,7 +1598,7 @@ void __init kmem_cache_init(void)
73390 sizes->cs_cachep = kmem_cache_create(names->name,
73391 sizes->cs_size,
73392 ARCH_KMALLOC_MINALIGN,
73393 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73394 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73395 NULL);
73396 }
73397 #ifdef CONFIG_ZONE_DMA
73398 @@ -4327,10 +4327,10 @@ static int s_show(struct seq_file *m, void *p)
73399 }
73400 /* cpu stats */
73401 {
73402 - unsigned long allochit = atomic_read(&cachep->allochit);
73403 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73404 - unsigned long freehit = atomic_read(&cachep->freehit);
73405 - unsigned long freemiss = atomic_read(&cachep->freemiss);
73406 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73407 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73408 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73409 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73410
73411 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73412 allochit, allocmiss, freehit, freemiss);
73413 @@ -4587,15 +4587,70 @@ static const struct file_operations proc_slabstats_operations = {
73414
73415 static int __init slab_proc_init(void)
73416 {
73417 - proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
73418 + mode_t gr_mode = S_IRUGO;
73419 +
73420 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73421 + gr_mode = S_IRUSR;
73422 +#endif
73423 +
73424 + proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
73425 #ifdef CONFIG_DEBUG_SLAB_LEAK
73426 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73427 + proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
73428 #endif
73429 return 0;
73430 }
73431 module_init(slab_proc_init);
73432 #endif
73433
73434 +void check_object_size(const void *ptr, unsigned long n, bool to)
73435 +{
73436 +
73437 +#ifdef CONFIG_PAX_USERCOPY
73438 + struct page *page;
73439 + struct kmem_cache *cachep = NULL;
73440 + struct slab *slabp;
73441 + unsigned int objnr;
73442 + unsigned long offset;
73443 + const char *type;
73444 +
73445 + if (!n)
73446 + return;
73447 +
73448 + type = "<null>";
73449 + if (ZERO_OR_NULL_PTR(ptr))
73450 + goto report;
73451 +
73452 + if (!virt_addr_valid(ptr))
73453 + return;
73454 +
73455 + page = virt_to_head_page(ptr);
73456 +
73457 + type = "<process stack>";
73458 + if (!PageSlab(page)) {
73459 + if (object_is_on_stack(ptr, n) == -1)
73460 + goto report;
73461 + return;
73462 + }
73463 +
73464 + cachep = page_get_cache(page);
73465 + type = cachep->name;
73466 + if (!(cachep->flags & SLAB_USERCOPY))
73467 + goto report;
73468 +
73469 + slabp = page_get_slab(page);
73470 + objnr = obj_to_index(cachep, slabp, ptr);
73471 + BUG_ON(objnr >= cachep->num);
73472 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73473 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73474 + return;
73475 +
73476 +report:
73477 + pax_report_usercopy(ptr, n, to, type);
73478 +#endif
73479 +
73480 +}
73481 +EXPORT_SYMBOL(check_object_size);
73482 +
73483 /**
73484 * ksize - get the actual amount of memory allocated for a given object
73485 * @objp: Pointer to the object
73486 diff --git a/mm/slob.c b/mm/slob.c
73487 index bf39181..727f7a3 100644
73488 --- a/mm/slob.c
73489 +++ b/mm/slob.c
73490 @@ -29,7 +29,7 @@
73491 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73492 * alloc_pages() directly, allocating compound pages so the page order
73493 * does not have to be separately tracked, and also stores the exact
73494 - * allocation size in page->private so that it can be used to accurately
73495 + * allocation size in slob_page->size so that it can be used to accurately
73496 * provide ksize(). These objects are detected in kfree() because slob_page()
73497 * is false for them.
73498 *
73499 @@ -58,6 +58,7 @@
73500 */
73501
73502 #include <linux/kernel.h>
73503 +#include <linux/sched.h>
73504 #include <linux/slab.h>
73505 #include <linux/mm.h>
73506 #include <linux/swap.h> /* struct reclaim_state */
73507 @@ -102,7 +103,8 @@ struct slob_page {
73508 unsigned long flags; /* mandatory */
73509 atomic_t _count; /* mandatory */
73510 slobidx_t units; /* free units left in page */
73511 - unsigned long pad[2];
73512 + unsigned long pad[1];
73513 + unsigned long size; /* size when >=PAGE_SIZE */
73514 slob_t *free; /* first free slob_t in page */
73515 struct list_head list; /* linked list of free pages */
73516 };
73517 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73518 */
73519 static inline int is_slob_page(struct slob_page *sp)
73520 {
73521 - return PageSlab((struct page *)sp);
73522 + return PageSlab((struct page *)sp) && !sp->size;
73523 }
73524
73525 static inline void set_slob_page(struct slob_page *sp)
73526 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73527
73528 static inline struct slob_page *slob_page(const void *addr)
73529 {
73530 - return (struct slob_page *)virt_to_page(addr);
73531 + return (struct slob_page *)virt_to_head_page(addr);
73532 }
73533
73534 /*
73535 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73536 /*
73537 * Return the size of a slob block.
73538 */
73539 -static slobidx_t slob_units(slob_t *s)
73540 +static slobidx_t slob_units(const slob_t *s)
73541 {
73542 if (s->units > 0)
73543 return s->units;
73544 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73545 /*
73546 * Return the next free slob block pointer after this one.
73547 */
73548 -static slob_t *slob_next(slob_t *s)
73549 +static slob_t *slob_next(const slob_t *s)
73550 {
73551 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73552 slobidx_t next;
73553 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73554 /*
73555 * Returns true if s is the last free block in its page.
73556 */
73557 -static int slob_last(slob_t *s)
73558 +static int slob_last(const slob_t *s)
73559 {
73560 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73561 }
73562 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73563 if (!page)
73564 return NULL;
73565
73566 + set_slob_page(page);
73567 return page_address(page);
73568 }
73569
73570 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73571 if (!b)
73572 return NULL;
73573 sp = slob_page(b);
73574 - set_slob_page(sp);
73575
73576 spin_lock_irqsave(&slob_lock, flags);
73577 sp->units = SLOB_UNITS(PAGE_SIZE);
73578 sp->free = b;
73579 + sp->size = 0;
73580 INIT_LIST_HEAD(&sp->list);
73581 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
73582 set_slob_page_free(sp, slob_list);
73583 @@ -476,10 +479,9 @@ out:
73584 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
73585 */
73586
73587 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73588 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
73589 {
73590 - unsigned int *m;
73591 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73592 + slob_t *m;
73593 void *ret;
73594
73595 gfp &= gfp_allowed_mask;
73596 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73597
73598 if (!m)
73599 return NULL;
73600 - *m = size;
73601 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
73602 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
73603 + m[0].units = size;
73604 + m[1].units = align;
73605 ret = (void *)m + align;
73606
73607 trace_kmalloc_node(_RET_IP_, ret,
73608 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73609 gfp |= __GFP_COMP;
73610 ret = slob_new_pages(gfp, order, node);
73611 if (ret) {
73612 - struct page *page;
73613 - page = virt_to_page(ret);
73614 - page->private = size;
73615 + struct slob_page *sp;
73616 + sp = slob_page(ret);
73617 + sp->size = size;
73618 }
73619
73620 trace_kmalloc_node(_RET_IP_, ret,
73621 size, PAGE_SIZE << order, gfp, node);
73622 }
73623
73624 - kmemleak_alloc(ret, size, 1, gfp);
73625 + return ret;
73626 +}
73627 +
73628 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73629 +{
73630 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73631 + void *ret = __kmalloc_node_align(size, gfp, node, align);
73632 +
73633 + if (!ZERO_OR_NULL_PTR(ret))
73634 + kmemleak_alloc(ret, size, 1, gfp);
73635 return ret;
73636 }
73637 EXPORT_SYMBOL(__kmalloc_node);
73638 @@ -533,13 +547,92 @@ void kfree(const void *block)
73639 sp = slob_page(block);
73640 if (is_slob_page(sp)) {
73641 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73642 - unsigned int *m = (unsigned int *)(block - align);
73643 - slob_free(m, *m + align);
73644 - } else
73645 + slob_t *m = (slob_t *)(block - align);
73646 + slob_free(m, m[0].units + align);
73647 + } else {
73648 + clear_slob_page(sp);
73649 + free_slob_page(sp);
73650 + sp->size = 0;
73651 put_page(&sp->page);
73652 + }
73653 }
73654 EXPORT_SYMBOL(kfree);
73655
73656 +void check_object_size(const void *ptr, unsigned long n, bool to)
73657 +{
73658 +
73659 +#ifdef CONFIG_PAX_USERCOPY
73660 + struct slob_page *sp;
73661 + const slob_t *free;
73662 + const void *base;
73663 + unsigned long flags;
73664 + const char *type;
73665 +
73666 + if (!n)
73667 + return;
73668 +
73669 + type = "<null>";
73670 + if (ZERO_OR_NULL_PTR(ptr))
73671 + goto report;
73672 +
73673 + if (!virt_addr_valid(ptr))
73674 + return;
73675 +
73676 + type = "<process stack>";
73677 + sp = slob_page(ptr);
73678 + if (!PageSlab((struct page*)sp)) {
73679 + if (object_is_on_stack(ptr, n) == -1)
73680 + goto report;
73681 + return;
73682 + }
73683 +
73684 + type = "<slob>";
73685 + if (sp->size) {
73686 + base = page_address(&sp->page);
73687 + if (base <= ptr && n <= sp->size - (ptr - base))
73688 + return;
73689 + goto report;
73690 + }
73691 +
73692 + /* some tricky double walking to find the chunk */
73693 + spin_lock_irqsave(&slob_lock, flags);
73694 + base = (void *)((unsigned long)ptr & PAGE_MASK);
73695 + free = sp->free;
73696 +
73697 + while (!slob_last(free) && (void *)free <= ptr) {
73698 + base = free + slob_units(free);
73699 + free = slob_next(free);
73700 + }
73701 +
73702 + while (base < (void *)free) {
73703 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
73704 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
73705 + int offset;
73706 +
73707 + if (ptr < base + align)
73708 + break;
73709 +
73710 + offset = ptr - base - align;
73711 + if (offset >= m) {
73712 + base += size;
73713 + continue;
73714 + }
73715 +
73716 + if (n > m - offset)
73717 + break;
73718 +
73719 + spin_unlock_irqrestore(&slob_lock, flags);
73720 + return;
73721 + }
73722 +
73723 + spin_unlock_irqrestore(&slob_lock, flags);
73724 +report:
73725 + pax_report_usercopy(ptr, n, to, type);
73726 +#endif
73727 +
73728 +}
73729 +EXPORT_SYMBOL(check_object_size);
73730 +
73731 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
73732 size_t ksize(const void *block)
73733 {
73734 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
73735 sp = slob_page(block);
73736 if (is_slob_page(sp)) {
73737 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73738 - unsigned int *m = (unsigned int *)(block - align);
73739 - return SLOB_UNITS(*m) * SLOB_UNIT;
73740 + slob_t *m = (slob_t *)(block - align);
73741 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73742 } else
73743 - return sp->page.private;
73744 + return sp->size;
73745 }
73746 EXPORT_SYMBOL(ksize);
73747
73748 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73749 {
73750 struct kmem_cache *c;
73751
73752 +#ifdef CONFIG_PAX_USERCOPY
73753 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
73754 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73755 +#else
73756 c = slob_alloc(sizeof(struct kmem_cache),
73757 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73758 +#endif
73759
73760 if (c) {
73761 c->name = name;
73762 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73763
73764 lockdep_trace_alloc(flags);
73765
73766 +#ifdef CONFIG_PAX_USERCOPY
73767 + b = __kmalloc_node_align(c->size, flags, node, c->align);
73768 +#else
73769 if (c->size < PAGE_SIZE) {
73770 b = slob_alloc(c->size, flags, c->align, node);
73771 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73772 SLOB_UNITS(c->size) * SLOB_UNIT,
73773 flags, node);
73774 } else {
73775 + struct slob_page *sp;
73776 +
73777 b = slob_new_pages(flags, get_order(c->size), node);
73778 + sp = slob_page(b);
73779 + sp->size = c->size;
73780 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73781 PAGE_SIZE << get_order(c->size),
73782 flags, node);
73783 }
73784 +#endif
73785
73786 if (c->ctor)
73787 c->ctor(b);
73788 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73789
73790 static void __kmem_cache_free(void *b, int size)
73791 {
73792 - if (size < PAGE_SIZE)
73793 + struct slob_page *sp = slob_page(b);
73794 +
73795 + if (is_slob_page(sp))
73796 slob_free(b, size);
73797 - else
73798 + else {
73799 + clear_slob_page(sp);
73800 + free_slob_page(sp);
73801 + sp->size = 0;
73802 slob_free_pages(b, get_order(size));
73803 + }
73804 }
73805
73806 static void kmem_rcu_free(struct rcu_head *head)
73807 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73808
73809 void kmem_cache_free(struct kmem_cache *c, void *b)
73810 {
73811 + int size = c->size;
73812 +
73813 +#ifdef CONFIG_PAX_USERCOPY
73814 + if (size + c->align < PAGE_SIZE) {
73815 + size += c->align;
73816 + b -= c->align;
73817 + }
73818 +#endif
73819 +
73820 kmemleak_free_recursive(b, c->flags);
73821 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73822 struct slob_rcu *slob_rcu;
73823 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73824 - slob_rcu->size = c->size;
73825 + slob_rcu = b + (size - sizeof(struct slob_rcu));
73826 + slob_rcu->size = size;
73827 call_rcu(&slob_rcu->head, kmem_rcu_free);
73828 } else {
73829 - __kmem_cache_free(b, c->size);
73830 + __kmem_cache_free(b, size);
73831 }
73832
73833 +#ifdef CONFIG_PAX_USERCOPY
73834 + trace_kfree(_RET_IP_, b);
73835 +#else
73836 trace_kmem_cache_free(_RET_IP_, b);
73837 +#endif
73838 +
73839 }
73840 EXPORT_SYMBOL(kmem_cache_free);
73841
73842 diff --git a/mm/slub.c b/mm/slub.c
73843 index 7c54fe8..ce9940d 100644
73844 --- a/mm/slub.c
73845 +++ b/mm/slub.c
73846 @@ -208,7 +208,7 @@ struct track {
73847
73848 enum track_item { TRACK_ALLOC, TRACK_FREE };
73849
73850 -#ifdef CONFIG_SYSFS
73851 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73852 static int sysfs_slab_add(struct kmem_cache *);
73853 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73854 static void sysfs_slab_remove(struct kmem_cache *);
73855 @@ -556,7 +556,7 @@ static void print_track(const char *s, struct track *t)
73856 if (!t->addr)
73857 return;
73858
73859 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73860 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73861 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73862 #ifdef CONFIG_STACKTRACE
73863 {
73864 @@ -2077,6 +2077,11 @@ static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
73865 goto new_slab;
73866 }
73867
73868 + /* must check again c->freelist in case of cpu migration or IRQ */
73869 + object = c->freelist;
73870 + if (object)
73871 + goto load_freelist;
73872 +
73873 stat(s, ALLOC_SLOWPATH);
73874
73875 do {
73876 @@ -2456,6 +2461,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73877
73878 page = virt_to_head_page(x);
73879
73880 + BUG_ON(!PageSlab(page));
73881 +
73882 slab_free(s, page, x, _RET_IP_);
73883
73884 trace_kmem_cache_free(_RET_IP_, x);
73885 @@ -2489,7 +2496,7 @@ static int slub_min_objects;
73886 * Merge control. If this is set then no merging of slab caches will occur.
73887 * (Could be removed. This was introduced to pacify the merge skeptics.)
73888 */
73889 -static int slub_nomerge;
73890 +static int slub_nomerge = 1;
73891
73892 /*
73893 * Calculate the order of allocation given an slab object size.
73894 @@ -2912,7 +2919,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73895 * list to avoid pounding the page allocator excessively.
73896 */
73897 set_min_partial(s, ilog2(s->size));
73898 - s->refcount = 1;
73899 + atomic_set(&s->refcount, 1);
73900 #ifdef CONFIG_NUMA
73901 s->remote_node_defrag_ratio = 1000;
73902 #endif
73903 @@ -3017,8 +3024,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73904 void kmem_cache_destroy(struct kmem_cache *s)
73905 {
73906 down_write(&slub_lock);
73907 - s->refcount--;
73908 - if (!s->refcount) {
73909 + if (atomic_dec_and_test(&s->refcount)) {
73910 list_del(&s->list);
73911 if (kmem_cache_close(s)) {
73912 printk(KERN_ERR "SLUB %s: %s called for cache that "
73913 @@ -3228,6 +3234,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73914 EXPORT_SYMBOL(__kmalloc_node);
73915 #endif
73916
73917 +void check_object_size(const void *ptr, unsigned long n, bool to)
73918 +{
73919 +
73920 +#ifdef CONFIG_PAX_USERCOPY
73921 + struct page *page;
73922 + struct kmem_cache *s = NULL;
73923 + unsigned long offset;
73924 + const char *type;
73925 +
73926 + if (!n)
73927 + return;
73928 +
73929 + type = "<null>";
73930 + if (ZERO_OR_NULL_PTR(ptr))
73931 + goto report;
73932 +
73933 + if (!virt_addr_valid(ptr))
73934 + return;
73935 +
73936 + page = virt_to_head_page(ptr);
73937 +
73938 + type = "<process stack>";
73939 + if (!PageSlab(page)) {
73940 + if (object_is_on_stack(ptr, n) == -1)
73941 + goto report;
73942 + return;
73943 + }
73944 +
73945 + s = page->slab;
73946 + type = s->name;
73947 + if (!(s->flags & SLAB_USERCOPY))
73948 + goto report;
73949 +
73950 + offset = (ptr - page_address(page)) % s->size;
73951 + if (offset <= s->objsize && n <= s->objsize - offset)
73952 + return;
73953 +
73954 +report:
73955 + pax_report_usercopy(ptr, n, to, type);
73956 +#endif
73957 +
73958 +}
73959 +EXPORT_SYMBOL(check_object_size);
73960 +
73961 size_t ksize(const void *object)
73962 {
73963 struct page *page;
73964 @@ -3502,7 +3552,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73965 int node;
73966
73967 list_add(&s->list, &slab_caches);
73968 - s->refcount = -1;
73969 + atomic_set(&s->refcount, -1);
73970
73971 for_each_node_state(node, N_NORMAL_MEMORY) {
73972 struct kmem_cache_node *n = get_node(s, node);
73973 @@ -3619,17 +3669,17 @@ void __init kmem_cache_init(void)
73974
73975 /* Caches that are not of the two-to-the-power-of size */
73976 if (KMALLOC_MIN_SIZE <= 32) {
73977 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73978 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73979 caches++;
73980 }
73981
73982 if (KMALLOC_MIN_SIZE <= 64) {
73983 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73984 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73985 caches++;
73986 }
73987
73988 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73989 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73990 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73991 caches++;
73992 }
73993
73994 @@ -3697,7 +3747,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73995 /*
73996 * We may have set a slab to be unmergeable during bootstrap.
73997 */
73998 - if (s->refcount < 0)
73999 + if (atomic_read(&s->refcount) < 0)
74000 return 1;
74001
74002 return 0;
74003 @@ -3756,7 +3806,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74004 down_write(&slub_lock);
74005 s = find_mergeable(size, align, flags, name, ctor);
74006 if (s) {
74007 - s->refcount++;
74008 + atomic_inc(&s->refcount);
74009 /*
74010 * Adjust the object sizes so that we clear
74011 * the complete object on kzalloc.
74012 @@ -3765,7 +3815,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74013 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74014
74015 if (sysfs_slab_alias(s, name)) {
74016 - s->refcount--;
74017 + atomic_dec(&s->refcount);
74018 goto err;
74019 }
74020 up_write(&slub_lock);
74021 @@ -3893,7 +3943,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74022 }
74023 #endif
74024
74025 -#ifdef CONFIG_SYSFS
74026 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74027 static int count_inuse(struct page *page)
74028 {
74029 return page->inuse;
74030 @@ -4280,12 +4330,12 @@ static void resiliency_test(void)
74031 validate_slab_cache(kmalloc_caches[9]);
74032 }
74033 #else
74034 -#ifdef CONFIG_SYSFS
74035 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74036 static void resiliency_test(void) {};
74037 #endif
74038 #endif
74039
74040 -#ifdef CONFIG_SYSFS
74041 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74042 enum slab_stat_type {
74043 SL_ALL, /* All slabs */
74044 SL_PARTIAL, /* Only partially allocated slabs */
74045 @@ -4495,7 +4545,7 @@ SLAB_ATTR_RO(ctor);
74046
74047 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74048 {
74049 - return sprintf(buf, "%d\n", s->refcount - 1);
74050 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74051 }
74052 SLAB_ATTR_RO(aliases);
74053
74054 @@ -5025,6 +5075,7 @@ static char *create_unique_id(struct kmem_cache *s)
74055 return name;
74056 }
74057
74058 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74059 static int sysfs_slab_add(struct kmem_cache *s)
74060 {
74061 int err;
74062 @@ -5087,6 +5138,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74063 kobject_del(&s->kobj);
74064 kobject_put(&s->kobj);
74065 }
74066 +#endif
74067
74068 /*
74069 * Need to buffer aliases during bootup until sysfs becomes
74070 @@ -5100,6 +5152,7 @@ struct saved_alias {
74071
74072 static struct saved_alias *alias_list;
74073
74074 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74075 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74076 {
74077 struct saved_alias *al;
74078 @@ -5122,6 +5175,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74079 alias_list = al;
74080 return 0;
74081 }
74082 +#endif
74083
74084 static int __init slab_sysfs_init(void)
74085 {
74086 @@ -5257,7 +5311,13 @@ static const struct file_operations proc_slabinfo_operations = {
74087
74088 static int __init slab_proc_init(void)
74089 {
74090 - proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
74091 + mode_t gr_mode = S_IRUGO;
74092 +
74093 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74094 + gr_mode = S_IRUSR;
74095 +#endif
74096 +
74097 + proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
74098 return 0;
74099 }
74100 module_init(slab_proc_init);
74101 diff --git a/mm/swap.c b/mm/swap.c
74102 index 87627f1..8a9eb34 100644
74103 --- a/mm/swap.c
74104 +++ b/mm/swap.c
74105 @@ -31,6 +31,7 @@
74106 #include <linux/backing-dev.h>
74107 #include <linux/memcontrol.h>
74108 #include <linux/gfp.h>
74109 +#include <linux/hugetlb.h>
74110
74111 #include "internal.h"
74112
74113 @@ -71,6 +72,8 @@ static void __put_compound_page(struct page *page)
74114
74115 __page_cache_release(page);
74116 dtor = get_compound_page_dtor(page);
74117 + if (!PageHuge(page))
74118 + BUG_ON(dtor != free_compound_page);
74119 (*dtor)(page);
74120 }
74121
74122 diff --git a/mm/swapfile.c b/mm/swapfile.c
74123 index 17bc224..1677059 100644
74124 --- a/mm/swapfile.c
74125 +++ b/mm/swapfile.c
74126 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(swapon_mutex);
74127
74128 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74129 /* Activity counter to indicate that a swapon or swapoff has occurred */
74130 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74131 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74132
74133 static inline unsigned char swap_count(unsigned char ent)
74134 {
74135 @@ -1671,7 +1671,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74136 }
74137 filp_close(swap_file, NULL);
74138 err = 0;
74139 - atomic_inc(&proc_poll_event);
74140 + atomic_inc_unchecked(&proc_poll_event);
74141 wake_up_interruptible(&proc_poll_wait);
74142
74143 out_dput:
74144 @@ -1687,8 +1687,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74145
74146 poll_wait(file, &proc_poll_wait, wait);
74147
74148 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74149 - seq->poll_event = atomic_read(&proc_poll_event);
74150 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74151 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74152 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74153 }
74154
74155 @@ -1786,7 +1786,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74156 return ret;
74157
74158 seq = file->private_data;
74159 - seq->poll_event = atomic_read(&proc_poll_event);
74160 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74161 return 0;
74162 }
74163
74164 @@ -2124,7 +2124,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74165 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74166
74167 mutex_unlock(&swapon_mutex);
74168 - atomic_inc(&proc_poll_event);
74169 + atomic_inc_unchecked(&proc_poll_event);
74170 wake_up_interruptible(&proc_poll_wait);
74171
74172 if (S_ISREG(inode->i_mode))
74173 diff --git a/mm/util.c b/mm/util.c
74174 index 88ea1bd..0f1dfdb 100644
74175 --- a/mm/util.c
74176 +++ b/mm/util.c
74177 @@ -114,6 +114,7 @@ EXPORT_SYMBOL(memdup_user);
74178 * allocated buffer. Use this if you don't want to free the buffer immediately
74179 * like, for example, with RCU.
74180 */
74181 +#undef __krealloc
74182 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
74183 {
74184 void *ret;
74185 @@ -147,6 +148,7 @@ EXPORT_SYMBOL(__krealloc);
74186 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
74187 * %NULL pointer, the object pointed to is freed.
74188 */
74189 +#undef krealloc
74190 void *krealloc(const void *p, size_t new_size, gfp_t flags)
74191 {
74192 void *ret;
74193 @@ -243,6 +245,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
74194 void arch_pick_mmap_layout(struct mm_struct *mm)
74195 {
74196 mm->mmap_base = TASK_UNMAPPED_BASE;
74197 +
74198 +#ifdef CONFIG_PAX_RANDMMAP
74199 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74200 + mm->mmap_base += mm->delta_mmap;
74201 +#endif
74202 +
74203 mm->get_unmapped_area = arch_get_unmapped_area;
74204 mm->unmap_area = arch_unmap_area;
74205 }
74206 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74207 index 3a65d6f7..39d5e33 100644
74208 --- a/mm/vmalloc.c
74209 +++ b/mm/vmalloc.c
74210 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74211
74212 pte = pte_offset_kernel(pmd, addr);
74213 do {
74214 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74215 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74216 +
74217 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74218 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74219 + BUG_ON(!pte_exec(*pte));
74220 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74221 + continue;
74222 + }
74223 +#endif
74224 +
74225 + {
74226 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74227 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74228 + }
74229 } while (pte++, addr += PAGE_SIZE, addr != end);
74230 }
74231
74232 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74233 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74234 {
74235 pte_t *pte;
74236 + int ret = -ENOMEM;
74237
74238 /*
74239 * nr is a running index into the array which helps higher level
74240 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74241 pte = pte_alloc_kernel(pmd, addr);
74242 if (!pte)
74243 return -ENOMEM;
74244 +
74245 + pax_open_kernel();
74246 do {
74247 struct page *page = pages[*nr];
74248
74249 - if (WARN_ON(!pte_none(*pte)))
74250 - return -EBUSY;
74251 - if (WARN_ON(!page))
74252 - return -ENOMEM;
74253 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74254 + if (pgprot_val(prot) & _PAGE_NX)
74255 +#endif
74256 +
74257 + if (WARN_ON(!pte_none(*pte))) {
74258 + ret = -EBUSY;
74259 + goto out;
74260 + }
74261 + if (WARN_ON(!page)) {
74262 + ret = -ENOMEM;
74263 + goto out;
74264 + }
74265 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74266 (*nr)++;
74267 } while (pte++, addr += PAGE_SIZE, addr != end);
74268 - return 0;
74269 + ret = 0;
74270 +out:
74271 + pax_close_kernel();
74272 + return ret;
74273 }
74274
74275 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74276 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74277 * and fall back on vmalloc() if that fails. Others
74278 * just put it in the vmalloc space.
74279 */
74280 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74281 +#ifdef CONFIG_MODULES
74282 +#ifdef MODULES_VADDR
74283 unsigned long addr = (unsigned long)x;
74284 if (addr >= MODULES_VADDR && addr < MODULES_END)
74285 return 1;
74286 #endif
74287 +
74288 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74289 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74290 + return 1;
74291 +#endif
74292 +
74293 +#endif
74294 +
74295 return is_vmalloc_addr(x);
74296 }
74297
74298 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74299
74300 if (!pgd_none(*pgd)) {
74301 pud_t *pud = pud_offset(pgd, addr);
74302 +#ifdef CONFIG_X86
74303 + if (!pud_large(*pud))
74304 +#endif
74305 if (!pud_none(*pud)) {
74306 pmd_t *pmd = pmd_offset(pud, addr);
74307 +#ifdef CONFIG_X86
74308 + if (!pmd_large(*pmd))
74309 +#endif
74310 if (!pmd_none(*pmd)) {
74311 pte_t *ptep, pte;
74312
74313 @@ -1290,10 +1330,20 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74314 unsigned long align, unsigned long flags, unsigned long start,
74315 unsigned long end, int node, gfp_t gfp_mask, void *caller)
74316 {
74317 - static struct vmap_area *va;
74318 + struct vmap_area *va;
74319 struct vm_struct *area;
74320
74321 BUG_ON(in_interrupt());
74322 +
74323 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74324 + if (flags & VM_KERNEXEC) {
74325 + if (start != VMALLOC_START || end != VMALLOC_END)
74326 + return NULL;
74327 + start = (unsigned long)MODULES_EXEC_VADDR;
74328 + end = (unsigned long)MODULES_EXEC_END;
74329 + }
74330 +#endif
74331 +
74332 if (flags & VM_IOREMAP) {
74333 int bit = fls(size);
74334
74335 @@ -1526,6 +1576,11 @@ void *vmap(struct page **pages, unsigned int count,
74336 if (count > totalram_pages)
74337 return NULL;
74338
74339 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74340 + if (!(pgprot_val(prot) & _PAGE_NX))
74341 + flags |= VM_KERNEXEC;
74342 +#endif
74343 +
74344 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74345 __builtin_return_address(0));
74346 if (!area)
74347 @@ -1627,6 +1682,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74348 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74349 return NULL;
74350
74351 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74352 + if (!(pgprot_val(prot) & _PAGE_NX))
74353 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74354 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74355 + else
74356 +#endif
74357 +
74358 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74359 start, end, node, gfp_mask, caller);
74360
74361 @@ -1674,6 +1736,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
74362 gfp_mask, prot, node, caller);
74363 }
74364
74365 +#undef __vmalloc
74366 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
74367 {
74368 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
74369 @@ -1697,6 +1760,7 @@ static inline void *__vmalloc_node_flags(unsigned long size,
74370 * For tight control over page level allocator and protection flags
74371 * use __vmalloc() instead.
74372 */
74373 +#undef vmalloc
74374 void *vmalloc(unsigned long size)
74375 {
74376 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
74377 @@ -1713,6 +1777,7 @@ EXPORT_SYMBOL(vmalloc);
74378 * For tight control over page level allocator and protection flags
74379 * use __vmalloc() instead.
74380 */
74381 +#undef vzalloc
74382 void *vzalloc(unsigned long size)
74383 {
74384 return __vmalloc_node_flags(size, -1,
74385 @@ -1727,6 +1792,7 @@ EXPORT_SYMBOL(vzalloc);
74386 * The resulting memory area is zeroed so it can be mapped to userspace
74387 * without leaking data.
74388 */
74389 +#undef vmalloc_user
74390 void *vmalloc_user(unsigned long size)
74391 {
74392 struct vm_struct *area;
74393 @@ -1754,6 +1820,7 @@ EXPORT_SYMBOL(vmalloc_user);
74394 * For tight control over page level allocator and protection flags
74395 * use __vmalloc() instead.
74396 */
74397 +#undef vmalloc_node
74398 void *vmalloc_node(unsigned long size, int node)
74399 {
74400 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
74401 @@ -1773,6 +1840,7 @@ EXPORT_SYMBOL(vmalloc_node);
74402 * For tight control over page level allocator and protection flags
74403 * use __vmalloc_node() instead.
74404 */
74405 +#undef vzalloc_node
74406 void *vzalloc_node(unsigned long size, int node)
74407 {
74408 return __vmalloc_node_flags(size, node,
74409 @@ -1795,10 +1863,10 @@ EXPORT_SYMBOL(vzalloc_node);
74410 * For tight control over page level allocator and protection flags
74411 * use __vmalloc() instead.
74412 */
74413 -
74414 +#undef vmalloc_exec
74415 void *vmalloc_exec(unsigned long size)
74416 {
74417 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74418 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74419 -1, __builtin_return_address(0));
74420 }
74421
74422 @@ -1817,6 +1885,7 @@ void *vmalloc_exec(unsigned long size)
74423 * Allocate enough 32bit PA addressable pages to cover @size from the
74424 * page level allocator and map them into contiguous kernel virtual space.
74425 */
74426 +#undef vmalloc_32
74427 void *vmalloc_32(unsigned long size)
74428 {
74429 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
74430 @@ -1831,6 +1900,7 @@ EXPORT_SYMBOL(vmalloc_32);
74431 * The resulting memory area is 32bit addressable and zeroed so it can be
74432 * mapped to userspace without leaking data.
74433 */
74434 +#undef vmalloc_32_user
74435 void *vmalloc_32_user(unsigned long size)
74436 {
74437 struct vm_struct *area;
74438 @@ -2093,6 +2163,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74439 unsigned long uaddr = vma->vm_start;
74440 unsigned long usize = vma->vm_end - vma->vm_start;
74441
74442 + BUG_ON(vma->vm_mirror);
74443 +
74444 if ((PAGE_SIZE-1) & (unsigned long)addr)
74445 return -EINVAL;
74446
74447 diff --git a/mm/vmstat.c b/mm/vmstat.c
74448 index d52b13d..381d1ac 100644
74449 --- a/mm/vmstat.c
74450 +++ b/mm/vmstat.c
74451 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74452 *
74453 * vm_stat contains the global counters
74454 */
74455 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
74456 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
74457 EXPORT_SYMBOL(vm_stat);
74458
74459 #ifdef CONFIG_SMP
74460 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74461 v = p->vm_stat_diff[i];
74462 p->vm_stat_diff[i] = 0;
74463 local_irq_restore(flags);
74464 - atomic_long_add(v, &zone->vm_stat[i]);
74465 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74466 global_diff[i] += v;
74467 #ifdef CONFIG_NUMA
74468 /* 3 seconds idle till flush */
74469 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74470
74471 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74472 if (global_diff[i])
74473 - atomic_long_add(global_diff[i], &vm_stat[i]);
74474 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74475 }
74476
74477 #endif
74478 @@ -1207,10 +1207,20 @@ static int __init setup_vmstat(void)
74479 start_cpu_timer(cpu);
74480 #endif
74481 #ifdef CONFIG_PROC_FS
74482 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74483 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74484 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74485 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74486 + {
74487 + mode_t gr_mode = S_IRUGO;
74488 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74489 + gr_mode = S_IRUSR;
74490 +#endif
74491 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74492 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74493 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74494 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74495 +#else
74496 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74497 +#endif
74498 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74499 + }
74500 #endif
74501 return 0;
74502 }
74503 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74504 index 8970ba1..e3361fe 100644
74505 --- a/net/8021q/vlan.c
74506 +++ b/net/8021q/vlan.c
74507 @@ -588,8 +588,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74508 err = -EPERM;
74509 if (!capable(CAP_NET_ADMIN))
74510 break;
74511 - if ((args.u.name_type >= 0) &&
74512 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74513 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74514 struct vlan_net *vn;
74515
74516 vn = net_generic(net, vlan_net_id);
74517 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74518 index fdfdb57..38d368c 100644
74519 --- a/net/9p/trans_fd.c
74520 +++ b/net/9p/trans_fd.c
74521 @@ -423,7 +423,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74522 oldfs = get_fs();
74523 set_fs(get_ds());
74524 /* The cast to a user pointer is valid due to the set_fs() */
74525 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74526 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74527 set_fs(oldfs);
74528
74529 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74530 diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
74531 index e317583..3c8aeaf 100644
74532 --- a/net/9p/trans_virtio.c
74533 +++ b/net/9p/trans_virtio.c
74534 @@ -327,7 +327,7 @@ req_retry_pinned:
74535 } else {
74536 char *pbuf;
74537 if (req->tc->pubuf)
74538 - pbuf = (__force char *) req->tc->pubuf;
74539 + pbuf = (char __force_kernel *) req->tc->pubuf;
74540 else
74541 pbuf = req->tc->pkbuf;
74542 outp = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM, pbuf,
74543 @@ -357,7 +357,7 @@ req_retry_pinned:
74544 } else {
74545 char *pbuf;
74546 if (req->tc->pubuf)
74547 - pbuf = (__force char *) req->tc->pubuf;
74548 + pbuf = (char __force_kernel *) req->tc->pubuf;
74549 else
74550 pbuf = req->tc->pkbuf;
74551
74552 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74553 index f41f026..fe76ea8 100644
74554 --- a/net/atm/atm_misc.c
74555 +++ b/net/atm/atm_misc.c
74556 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74557 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74558 return 1;
74559 atm_return(vcc, truesize);
74560 - atomic_inc(&vcc->stats->rx_drop);
74561 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74562 return 0;
74563 }
74564 EXPORT_SYMBOL(atm_charge);
74565 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74566 }
74567 }
74568 atm_return(vcc, guess);
74569 - atomic_inc(&vcc->stats->rx_drop);
74570 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74571 return NULL;
74572 }
74573 EXPORT_SYMBOL(atm_alloc_charge);
74574 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74575
74576 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74577 {
74578 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74579 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74580 __SONET_ITEMS
74581 #undef __HANDLE_ITEM
74582 }
74583 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74584
74585 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74586 {
74587 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74588 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74589 __SONET_ITEMS
74590 #undef __HANDLE_ITEM
74591 }
74592 diff --git a/net/atm/lec.h b/net/atm/lec.h
74593 index dfc0719..47c5322 100644
74594 --- a/net/atm/lec.h
74595 +++ b/net/atm/lec.h
74596 @@ -48,7 +48,7 @@ struct lane2_ops {
74597 const u8 *tlvs, u32 sizeoftlvs);
74598 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74599 const u8 *tlvs, u32 sizeoftlvs);
74600 -};
74601 +} __no_const;
74602
74603 /*
74604 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74605 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74606 index 0919a88..a23d54e 100644
74607 --- a/net/atm/mpc.h
74608 +++ b/net/atm/mpc.h
74609 @@ -33,7 +33,7 @@ struct mpoa_client {
74610 struct mpc_parameters parameters; /* parameters for this client */
74611
74612 const struct net_device_ops *old_ops;
74613 - struct net_device_ops new_ops;
74614 + net_device_ops_no_const new_ops;
74615 };
74616
74617
74618 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
74619 index d1b2d9a..7cc2219 100644
74620 --- a/net/atm/mpoa_caches.c
74621 +++ b/net/atm/mpoa_caches.c
74622 @@ -255,6 +255,8 @@ static void check_resolving_entries(struct mpoa_client *client)
74623 struct timeval now;
74624 struct k_message msg;
74625
74626 + pax_track_stack();
74627 +
74628 do_gettimeofday(&now);
74629
74630 read_lock_bh(&client->ingress_lock);
74631 diff --git a/net/atm/proc.c b/net/atm/proc.c
74632 index 0d020de..011c7bb 100644
74633 --- a/net/atm/proc.c
74634 +++ b/net/atm/proc.c
74635 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
74636 const struct k_atm_aal_stats *stats)
74637 {
74638 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
74639 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
74640 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
74641 - atomic_read(&stats->rx_drop));
74642 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
74643 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
74644 + atomic_read_unchecked(&stats->rx_drop));
74645 }
74646
74647 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
74648 diff --git a/net/atm/resources.c b/net/atm/resources.c
74649 index 23f45ce..c748f1a 100644
74650 --- a/net/atm/resources.c
74651 +++ b/net/atm/resources.c
74652 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
74653 static void copy_aal_stats(struct k_atm_aal_stats *from,
74654 struct atm_aal_stats *to)
74655 {
74656 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74657 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74658 __AAL_STAT_ITEMS
74659 #undef __HANDLE_ITEM
74660 }
74661 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
74662 static void subtract_aal_stats(struct k_atm_aal_stats *from,
74663 struct atm_aal_stats *to)
74664 {
74665 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74666 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
74667 __AAL_STAT_ITEMS
74668 #undef __HANDLE_ITEM
74669 }
74670 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
74671 index db7aacf..991e539 100644
74672 --- a/net/batman-adv/hard-interface.c
74673 +++ b/net/batman-adv/hard-interface.c
74674 @@ -347,8 +347,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
74675 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
74676 dev_add_pack(&hard_iface->batman_adv_ptype);
74677
74678 - atomic_set(&hard_iface->seqno, 1);
74679 - atomic_set(&hard_iface->frag_seqno, 1);
74680 + atomic_set_unchecked(&hard_iface->seqno, 1);
74681 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
74682 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
74683 hard_iface->net_dev->name);
74684
74685 diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
74686 index 0f32c81..82d1895 100644
74687 --- a/net/batman-adv/routing.c
74688 +++ b/net/batman-adv/routing.c
74689 @@ -656,7 +656,7 @@ void receive_bat_packet(const struct ethhdr *ethhdr,
74690 return;
74691
74692 /* could be changed by schedule_own_packet() */
74693 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
74694 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
74695
74696 has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0);
74697
74698 diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
74699 index 58d1447..2a66c8c 100644
74700 --- a/net/batman-adv/send.c
74701 +++ b/net/batman-adv/send.c
74702 @@ -326,7 +326,7 @@ void schedule_own_packet(struct hard_iface *hard_iface)
74703
74704 /* change sequence number to network order */
74705 batman_packet->seqno =
74706 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
74707 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
74708
74709 batman_packet->ttvn = atomic_read(&bat_priv->ttvn);
74710 batman_packet->tt_crc = htons((uint16_t)atomic_read(&bat_priv->tt_crc));
74711 @@ -343,7 +343,7 @@ void schedule_own_packet(struct hard_iface *hard_iface)
74712 else
74713 batman_packet->gw_flags = NO_FLAGS;
74714
74715 - atomic_inc(&hard_iface->seqno);
74716 + atomic_inc_unchecked(&hard_iface->seqno);
74717
74718 slide_own_bcast_window(hard_iface);
74719 send_time = own_send_time(bat_priv);
74720 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
74721 index 05dd351..2ecd19b 100644
74722 --- a/net/batman-adv/soft-interface.c
74723 +++ b/net/batman-adv/soft-interface.c
74724 @@ -632,7 +632,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
74725
74726 /* set broadcast sequence number */
74727 bcast_packet->seqno =
74728 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
74729 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
74730
74731 add_bcast_packet_to_list(bat_priv, skb, 1);
74732
74733 @@ -824,7 +824,7 @@ struct net_device *softif_create(const char *name)
74734 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
74735
74736 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
74737 - atomic_set(&bat_priv->bcast_seqno, 1);
74738 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
74739 atomic_set(&bat_priv->ttvn, 0);
74740 atomic_set(&bat_priv->tt_local_changes, 0);
74741 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
74742 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
74743 index 51a0db7..b8a62be 100644
74744 --- a/net/batman-adv/types.h
74745 +++ b/net/batman-adv/types.h
74746 @@ -38,8 +38,8 @@ struct hard_iface {
74747 int16_t if_num;
74748 char if_status;
74749 struct net_device *net_dev;
74750 - atomic_t seqno;
74751 - atomic_t frag_seqno;
74752 + atomic_unchecked_t seqno;
74753 + atomic_unchecked_t frag_seqno;
74754 unsigned char *packet_buff;
74755 int packet_len;
74756 struct kobject *hardif_obj;
74757 @@ -153,7 +153,7 @@ struct bat_priv {
74758 atomic_t orig_interval; /* uint */
74759 atomic_t hop_penalty; /* uint */
74760 atomic_t log_level; /* uint */
74761 - atomic_t bcast_seqno;
74762 + atomic_unchecked_t bcast_seqno;
74763 atomic_t bcast_queue_left;
74764 atomic_t batman_queue_left;
74765 atomic_t ttvn; /* tranlation table version number */
74766 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
74767 index 32b125f..f1447e0 100644
74768 --- a/net/batman-adv/unicast.c
74769 +++ b/net/batman-adv/unicast.c
74770 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
74771 frag1->flags = UNI_FRAG_HEAD | large_tail;
74772 frag2->flags = large_tail;
74773
74774 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
74775 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
74776 frag1->seqno = htons(seqno - 1);
74777 frag2->seqno = htons(seqno);
74778
74779 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
74780 index ea7f031..0615edc 100644
74781 --- a/net/bluetooth/hci_conn.c
74782 +++ b/net/bluetooth/hci_conn.c
74783 @@ -218,7 +218,7 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
74784 cp.handle = cpu_to_le16(conn->handle);
74785 memcpy(cp.ltk, ltk, sizeof(cp.ltk));
74786 cp.ediv = ediv;
74787 - memcpy(cp.rand, rand, sizeof(rand));
74788 + memcpy(cp.rand, rand, sizeof(cp.rand));
74789
74790 hci_send_cmd(hdev, HCI_OP_LE_START_ENC, sizeof(cp), &cp);
74791 }
74792 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
74793 memset(&cp, 0, sizeof(cp));
74794
74795 cp.handle = cpu_to_le16(conn->handle);
74796 - memcpy(cp.ltk, ltk, sizeof(ltk));
74797 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
74798
74799 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
74800 }
74801 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
74802 index b3bdb48..7ad90ac 100644
74803 --- a/net/bluetooth/l2cap_core.c
74804 +++ b/net/bluetooth/l2cap_core.c
74805 @@ -2145,7 +2145,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
74806 void *ptr = req->data;
74807 int type, olen;
74808 unsigned long val;
74809 - struct l2cap_conf_rfc rfc;
74810 + struct l2cap_conf_rfc rfc = { .mode = L2CAP_MODE_BASIC };
74811
74812 BT_DBG("chan %p, rsp %p, len %d, req %p", chan, rsp, len, data);
74813
74814 @@ -2169,8 +2169,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
74815 break;
74816
74817 case L2CAP_CONF_RFC:
74818 - if (olen == sizeof(rfc))
74819 - memcpy(&rfc, (void *)val, olen);
74820 + if (olen != sizeof(rfc))
74821 + break;
74822 +
74823 + memcpy(&rfc, (void *)val, olen);
74824
74825 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
74826 rfc.mode != chan->mode)
74827 @@ -2258,12 +2260,24 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
74828
74829 switch (type) {
74830 case L2CAP_CONF_RFC:
74831 - if (olen == sizeof(rfc))
74832 - memcpy(&rfc, (void *)val, olen);
74833 + if (olen != sizeof(rfc))
74834 + break;
74835 +
74836 + memcpy(&rfc, (void *)val, olen);
74837 goto done;
74838 }
74839 }
74840
74841 + /* Use sane default values in case a misbehaving remote device
74842 + * did not send an RFC option.
74843 + */
74844 + rfc.mode = chan->mode;
74845 + rfc.retrans_timeout = cpu_to_le16(L2CAP_DEFAULT_RETRANS_TO);
74846 + rfc.monitor_timeout = cpu_to_le16(L2CAP_DEFAULT_MONITOR_TO);
74847 + rfc.max_pdu_size = cpu_to_le16(chan->imtu);
74848 +
74849 + BT_ERR("Expected RFC option was not found, using defaults");
74850 +
74851 done:
74852 switch (rfc.mode) {
74853 case L2CAP_MODE_ERTM:
74854 diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
74855 index e79ff75..215b57d 100644
74856 --- a/net/bridge/br_multicast.c
74857 +++ b/net/bridge/br_multicast.c
74858 @@ -1485,7 +1485,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
74859 nexthdr = ip6h->nexthdr;
74860 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
74861
74862 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
74863 + if (nexthdr != IPPROTO_ICMPV6)
74864 return 0;
74865
74866 /* Okay, we found ICMPv6 header */
74867 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
74868 index 5864cc4..94cab18 100644
74869 --- a/net/bridge/netfilter/ebtables.c
74870 +++ b/net/bridge/netfilter/ebtables.c
74871 @@ -1513,7 +1513,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74872 tmp.valid_hooks = t->table->valid_hooks;
74873 }
74874 mutex_unlock(&ebt_mutex);
74875 - if (copy_to_user(user, &tmp, *len) != 0){
74876 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74877 BUGPRINT("c2u Didn't work\n");
74878 ret = -EFAULT;
74879 break;
74880 @@ -1781,6 +1781,8 @@ static int compat_copy_everything_to_user(struct ebt_table *t,
74881 int ret;
74882 void __user *pos;
74883
74884 + pax_track_stack();
74885 +
74886 memset(&tinfo, 0, sizeof(tinfo));
74887
74888 if (cmd == EBT_SO_GET_ENTRIES) {
74889 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
74890 index a986280..13444a1 100644
74891 --- a/net/caif/caif_socket.c
74892 +++ b/net/caif/caif_socket.c
74893 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
74894 #ifdef CONFIG_DEBUG_FS
74895 struct debug_fs_counter {
74896 atomic_t caif_nr_socks;
74897 - atomic_t caif_sock_create;
74898 - atomic_t num_connect_req;
74899 - atomic_t num_connect_resp;
74900 - atomic_t num_connect_fail_resp;
74901 - atomic_t num_disconnect;
74902 - atomic_t num_remote_shutdown_ind;
74903 - atomic_t num_tx_flow_off_ind;
74904 - atomic_t num_tx_flow_on_ind;
74905 - atomic_t num_rx_flow_off;
74906 - atomic_t num_rx_flow_on;
74907 + atomic_unchecked_t caif_sock_create;
74908 + atomic_unchecked_t num_connect_req;
74909 + atomic_unchecked_t num_connect_resp;
74910 + atomic_unchecked_t num_connect_fail_resp;
74911 + atomic_unchecked_t num_disconnect;
74912 + atomic_unchecked_t num_remote_shutdown_ind;
74913 + atomic_unchecked_t num_tx_flow_off_ind;
74914 + atomic_unchecked_t num_tx_flow_on_ind;
74915 + atomic_unchecked_t num_rx_flow_off;
74916 + atomic_unchecked_t num_rx_flow_on;
74917 };
74918 static struct debug_fs_counter cnt;
74919 #define dbfs_atomic_inc(v) atomic_inc_return(v)
74920 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
74921 #define dbfs_atomic_dec(v) atomic_dec_return(v)
74922 #else
74923 #define dbfs_atomic_inc(v) 0
74924 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74925 atomic_read(&cf_sk->sk.sk_rmem_alloc),
74926 sk_rcvbuf_lowwater(cf_sk));
74927 set_rx_flow_off(cf_sk);
74928 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74929 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74930 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74931 }
74932
74933 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74934 set_rx_flow_off(cf_sk);
74935 if (net_ratelimit())
74936 pr_debug("sending flow OFF due to rmem_schedule\n");
74937 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74938 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74939 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74940 }
74941 skb->dev = NULL;
74942 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
74943 switch (flow) {
74944 case CAIF_CTRLCMD_FLOW_ON_IND:
74945 /* OK from modem to start sending again */
74946 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
74947 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
74948 set_tx_flow_on(cf_sk);
74949 cf_sk->sk.sk_state_change(&cf_sk->sk);
74950 break;
74951
74952 case CAIF_CTRLCMD_FLOW_OFF_IND:
74953 /* Modem asks us to shut up */
74954 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
74955 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
74956 set_tx_flow_off(cf_sk);
74957 cf_sk->sk.sk_state_change(&cf_sk->sk);
74958 break;
74959 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74960 /* We're now connected */
74961 caif_client_register_refcnt(&cf_sk->layer,
74962 cfsk_hold, cfsk_put);
74963 - dbfs_atomic_inc(&cnt.num_connect_resp);
74964 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
74965 cf_sk->sk.sk_state = CAIF_CONNECTED;
74966 set_tx_flow_on(cf_sk);
74967 cf_sk->sk.sk_state_change(&cf_sk->sk);
74968 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74969
74970 case CAIF_CTRLCMD_INIT_FAIL_RSP:
74971 /* Connect request failed */
74972 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
74973 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
74974 cf_sk->sk.sk_err = ECONNREFUSED;
74975 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
74976 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74977 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74978
74979 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
74980 /* Modem has closed this connection, or device is down. */
74981 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
74982 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
74983 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74984 cf_sk->sk.sk_err = ECONNRESET;
74985 set_rx_flow_on(cf_sk);
74986 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
74987 return;
74988
74989 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
74990 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
74991 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
74992 set_rx_flow_on(cf_sk);
74993 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
74994 }
74995 @@ -854,7 +855,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
74996 /*ifindex = id of the interface.*/
74997 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
74998
74999 - dbfs_atomic_inc(&cnt.num_connect_req);
75000 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
75001 cf_sk->layer.receive = caif_sktrecv_cb;
75002
75003 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
75004 @@ -943,7 +944,7 @@ static int caif_release(struct socket *sock)
75005 spin_unlock_bh(&sk->sk_receive_queue.lock);
75006 sock->sk = NULL;
75007
75008 - dbfs_atomic_inc(&cnt.num_disconnect);
75009 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
75010
75011 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
75012 if (cf_sk->debugfs_socket_dir != NULL)
75013 @@ -1122,7 +1123,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
75014 cf_sk->conn_req.protocol = protocol;
75015 /* Increase the number of sockets created. */
75016 dbfs_atomic_inc(&cnt.caif_nr_socks);
75017 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
75018 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
75019 #ifdef CONFIG_DEBUG_FS
75020 if (!IS_ERR(debugfsdir)) {
75021
75022 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75023 index e22671b..6598ea0 100644
75024 --- a/net/caif/cfctrl.c
75025 +++ b/net/caif/cfctrl.c
75026 @@ -9,6 +9,7 @@
75027 #include <linux/stddef.h>
75028 #include <linux/spinlock.h>
75029 #include <linux/slab.h>
75030 +#include <linux/sched.h>
75031 #include <net/caif/caif_layer.h>
75032 #include <net/caif/cfpkt.h>
75033 #include <net/caif/cfctrl.h>
75034 @@ -45,8 +46,8 @@ struct cflayer *cfctrl_create(void)
75035 dev_info.id = 0xff;
75036 memset(this, 0, sizeof(*this));
75037 cfsrvl_init(&this->serv, 0, &dev_info, false);
75038 - atomic_set(&this->req_seq_no, 1);
75039 - atomic_set(&this->rsp_seq_no, 1);
75040 + atomic_set_unchecked(&this->req_seq_no, 1);
75041 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75042 this->serv.layer.receive = cfctrl_recv;
75043 sprintf(this->serv.layer.name, "ctrl");
75044 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75045 @@ -132,8 +133,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75046 struct cfctrl_request_info *req)
75047 {
75048 spin_lock_bh(&ctrl->info_list_lock);
75049 - atomic_inc(&ctrl->req_seq_no);
75050 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75051 + atomic_inc_unchecked(&ctrl->req_seq_no);
75052 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75053 list_add_tail(&req->list, &ctrl->list);
75054 spin_unlock_bh(&ctrl->info_list_lock);
75055 }
75056 @@ -151,7 +152,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75057 if (p != first)
75058 pr_warn("Requests are not received in order\n");
75059
75060 - atomic_set(&ctrl->rsp_seq_no,
75061 + atomic_set_unchecked(&ctrl->rsp_seq_no,
75062 p->sequence_no);
75063 list_del(&p->list);
75064 goto out;
75065 @@ -364,6 +365,7 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
75066 struct cfctrl *cfctrl = container_obj(layer);
75067 struct cfctrl_request_info rsp, *req;
75068
75069 + pax_track_stack();
75070
75071 cfpkt_extr_head(pkt, &cmdrsp, 1);
75072 cmd = cmdrsp & CFCTRL_CMD_MASK;
75073 diff --git a/net/compat.c b/net/compat.c
75074 index c578d93..257fab7 100644
75075 --- a/net/compat.c
75076 +++ b/net/compat.c
75077 @@ -70,9 +70,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75078 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75079 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75080 return -EFAULT;
75081 - kmsg->msg_name = compat_ptr(tmp1);
75082 - kmsg->msg_iov = compat_ptr(tmp2);
75083 - kmsg->msg_control = compat_ptr(tmp3);
75084 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75085 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75086 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75087 return 0;
75088 }
75089
75090 @@ -84,7 +84,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75091
75092 if (kern_msg->msg_namelen) {
75093 if (mode == VERIFY_READ) {
75094 - int err = move_addr_to_kernel(kern_msg->msg_name,
75095 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75096 kern_msg->msg_namelen,
75097 kern_address);
75098 if (err < 0)
75099 @@ -95,7 +95,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75100 kern_msg->msg_name = NULL;
75101
75102 tot_len = iov_from_user_compat_to_kern(kern_iov,
75103 - (struct compat_iovec __user *)kern_msg->msg_iov,
75104 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
75105 kern_msg->msg_iovlen);
75106 if (tot_len >= 0)
75107 kern_msg->msg_iov = kern_iov;
75108 @@ -115,20 +115,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75109
75110 #define CMSG_COMPAT_FIRSTHDR(msg) \
75111 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75112 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75113 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75114 (struct compat_cmsghdr __user *)NULL)
75115
75116 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75117 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75118 (ucmlen) <= (unsigned long) \
75119 ((mhdr)->msg_controllen - \
75120 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75121 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75122
75123 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75124 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75125 {
75126 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75127 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75128 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75129 msg->msg_controllen)
75130 return NULL;
75131 return (struct compat_cmsghdr __user *)ptr;
75132 @@ -220,7 +220,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75133 {
75134 struct compat_timeval ctv;
75135 struct compat_timespec cts[3];
75136 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75137 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75138 struct compat_cmsghdr cmhdr;
75139 int cmlen;
75140
75141 @@ -272,7 +272,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75142
75143 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75144 {
75145 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75146 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75147 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75148 int fdnum = scm->fp->count;
75149 struct file **fp = scm->fp->fp;
75150 @@ -369,7 +369,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75151 return -EFAULT;
75152 old_fs = get_fs();
75153 set_fs(KERNEL_DS);
75154 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75155 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75156 set_fs(old_fs);
75157
75158 return err;
75159 @@ -430,7 +430,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75160 len = sizeof(ktime);
75161 old_fs = get_fs();
75162 set_fs(KERNEL_DS);
75163 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75164 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75165 set_fs(old_fs);
75166
75167 if (!err) {
75168 @@ -565,7 +565,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75169 case MCAST_JOIN_GROUP:
75170 case MCAST_LEAVE_GROUP:
75171 {
75172 - struct compat_group_req __user *gr32 = (void *)optval;
75173 + struct compat_group_req __user *gr32 = (void __user *)optval;
75174 struct group_req __user *kgr =
75175 compat_alloc_user_space(sizeof(struct group_req));
75176 u32 interface;
75177 @@ -586,7 +586,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75178 case MCAST_BLOCK_SOURCE:
75179 case MCAST_UNBLOCK_SOURCE:
75180 {
75181 - struct compat_group_source_req __user *gsr32 = (void *)optval;
75182 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75183 struct group_source_req __user *kgsr = compat_alloc_user_space(
75184 sizeof(struct group_source_req));
75185 u32 interface;
75186 @@ -607,7 +607,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75187 }
75188 case MCAST_MSFILTER:
75189 {
75190 - struct compat_group_filter __user *gf32 = (void *)optval;
75191 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75192 struct group_filter __user *kgf;
75193 u32 interface, fmode, numsrc;
75194
75195 @@ -645,7 +645,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75196 char __user *optval, int __user *optlen,
75197 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75198 {
75199 - struct compat_group_filter __user *gf32 = (void *)optval;
75200 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75201 struct group_filter __user *kgf;
75202 int __user *koptlen;
75203 u32 interface, fmode, numsrc;
75204 diff --git a/net/core/datagram.c b/net/core/datagram.c
75205 index 18ac112..fe95ed9 100644
75206 --- a/net/core/datagram.c
75207 +++ b/net/core/datagram.c
75208 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75209 }
75210
75211 kfree_skb(skb);
75212 - atomic_inc(&sk->sk_drops);
75213 + atomic_inc_unchecked(&sk->sk_drops);
75214 sk_mem_reclaim_partial(sk);
75215
75216 return err;
75217 diff --git a/net/core/dev.c b/net/core/dev.c
75218 index ae5cf2d..2c950a1 100644
75219 --- a/net/core/dev.c
75220 +++ b/net/core/dev.c
75221 @@ -1135,10 +1135,14 @@ void dev_load(struct net *net, const char *name)
75222 if (no_module && capable(CAP_NET_ADMIN))
75223 no_module = request_module("netdev-%s", name);
75224 if (no_module && capable(CAP_SYS_MODULE)) {
75225 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75226 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75227 +#else
75228 if (!request_module("%s", name))
75229 pr_err("Loading kernel module for a network device "
75230 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
75231 "instead\n", name);
75232 +#endif
75233 }
75234 }
75235 EXPORT_SYMBOL(dev_load);
75236 @@ -1977,7 +1981,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75237
75238 struct dev_gso_cb {
75239 void (*destructor)(struct sk_buff *skb);
75240 -};
75241 +} __no_const;
75242
75243 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75244
75245 @@ -2930,7 +2934,7 @@ int netif_rx_ni(struct sk_buff *skb)
75246 }
75247 EXPORT_SYMBOL(netif_rx_ni);
75248
75249 -static void net_tx_action(struct softirq_action *h)
75250 +static void net_tx_action(void)
75251 {
75252 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75253
75254 @@ -3779,7 +3783,7 @@ void netif_napi_del(struct napi_struct *napi)
75255 }
75256 EXPORT_SYMBOL(netif_napi_del);
75257
75258 -static void net_rx_action(struct softirq_action *h)
75259 +static void net_rx_action(void)
75260 {
75261 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75262 unsigned long time_limit = jiffies + 2;
75263 diff --git a/net/core/flow.c b/net/core/flow.c
75264 index d6968e5..1690d9d 100644
75265 --- a/net/core/flow.c
75266 +++ b/net/core/flow.c
75267 @@ -61,7 +61,7 @@ struct flow_cache {
75268 struct timer_list rnd_timer;
75269 };
75270
75271 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75272 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75273 EXPORT_SYMBOL(flow_cache_genid);
75274 static struct flow_cache flow_cache_global;
75275 static struct kmem_cache *flow_cachep __read_mostly;
75276 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75277
75278 static int flow_entry_valid(struct flow_cache_entry *fle)
75279 {
75280 - if (atomic_read(&flow_cache_genid) != fle->genid)
75281 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75282 return 0;
75283 if (fle->object && !fle->object->ops->check(fle->object))
75284 return 0;
75285 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75286 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75287 fcp->hash_count++;
75288 }
75289 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75290 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75291 flo = fle->object;
75292 if (!flo)
75293 goto ret_object;
75294 @@ -280,7 +280,7 @@ nocache:
75295 }
75296 flo = resolver(net, key, family, dir, flo, ctx);
75297 if (fle) {
75298 - fle->genid = atomic_read(&flow_cache_genid);
75299 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75300 if (!IS_ERR(flo))
75301 fle->object = flo;
75302 else
75303 diff --git a/net/core/iovec.c b/net/core/iovec.c
75304 index c40f27e..7f49254 100644
75305 --- a/net/core/iovec.c
75306 +++ b/net/core/iovec.c
75307 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75308 if (m->msg_namelen) {
75309 if (mode == VERIFY_READ) {
75310 void __user *namep;
75311 - namep = (void __user __force *) m->msg_name;
75312 + namep = (void __force_user *) m->msg_name;
75313 err = move_addr_to_kernel(namep, m->msg_namelen,
75314 address);
75315 if (err < 0)
75316 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75317 }
75318
75319 size = m->msg_iovlen * sizeof(struct iovec);
75320 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75321 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75322 return -EFAULT;
75323
75324 m->msg_iov = iov;
75325 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
75326 index 1683e5d..f3621f6 100644
75327 --- a/net/core/net-sysfs.c
75328 +++ b/net/core/net-sysfs.c
75329 @@ -664,11 +664,14 @@ static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
75330 if (count) {
75331 int i;
75332
75333 - if (count > 1<<30) {
75334 - /* Enforce a limit to prevent overflow */
75335 + if (count > INT_MAX)
75336 return -EINVAL;
75337 - }
75338 count = roundup_pow_of_two(count);
75339 + if (count > (ULONG_MAX - sizeof(struct rps_dev_flow_table))
75340 + / sizeof(struct rps_dev_flow)) {
75341 + /* Enforce a limit to prevent overflow */
75342 + return -EINVAL;
75343 + }
75344 table = vmalloc(RPS_DEV_FLOW_TABLE_SIZE(count));
75345 if (!table)
75346 return -ENOMEM;
75347 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75348 index 99d9e95..209bae2 100644
75349 --- a/net/core/rtnetlink.c
75350 +++ b/net/core/rtnetlink.c
75351 @@ -57,7 +57,7 @@ struct rtnl_link {
75352 rtnl_doit_func doit;
75353 rtnl_dumpit_func dumpit;
75354 rtnl_calcit_func calcit;
75355 -};
75356 +} __no_const;
75357
75358 static DEFINE_MUTEX(rtnl_mutex);
75359 static u16 min_ifinfo_dump_size;
75360 diff --git a/net/core/scm.c b/net/core/scm.c
75361 index 811b53f..5d6c343 100644
75362 --- a/net/core/scm.c
75363 +++ b/net/core/scm.c
75364 @@ -218,7 +218,7 @@ EXPORT_SYMBOL(__scm_send);
75365 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75366 {
75367 struct cmsghdr __user *cm
75368 - = (__force struct cmsghdr __user *)msg->msg_control;
75369 + = (struct cmsghdr __force_user *)msg->msg_control;
75370 struct cmsghdr cmhdr;
75371 int cmlen = CMSG_LEN(len);
75372 int err;
75373 @@ -241,7 +241,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75374 err = -EFAULT;
75375 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75376 goto out;
75377 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75378 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75379 goto out;
75380 cmlen = CMSG_SPACE(len);
75381 if (msg->msg_controllen < cmlen)
75382 @@ -257,7 +257,7 @@ EXPORT_SYMBOL(put_cmsg);
75383 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75384 {
75385 struct cmsghdr __user *cm
75386 - = (__force struct cmsghdr __user*)msg->msg_control;
75387 + = (struct cmsghdr __force_user *)msg->msg_control;
75388
75389 int fdmax = 0;
75390 int fdnum = scm->fp->count;
75391 @@ -277,7 +277,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75392 if (fdnum < fdmax)
75393 fdmax = fdnum;
75394
75395 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75396 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75397 i++, cmfptr++)
75398 {
75399 int new_fd;
75400 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
75401 index 387703f..035abcf 100644
75402 --- a/net/core/skbuff.c
75403 +++ b/net/core/skbuff.c
75404 @@ -1650,6 +1650,8 @@ int skb_splice_bits(struct sk_buff *skb, unsigned int offset,
75405 struct sock *sk = skb->sk;
75406 int ret = 0;
75407
75408 + pax_track_stack();
75409 +
75410 if (splice_grow_spd(pipe, &spd))
75411 return -ENOMEM;
75412
75413 diff --git a/net/core/sock.c b/net/core/sock.c
75414 index 11d67b3..df26d4b 100644
75415 --- a/net/core/sock.c
75416 +++ b/net/core/sock.c
75417 @@ -293,7 +293,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75418 */
75419 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
75420 (unsigned)sk->sk_rcvbuf) {
75421 - atomic_inc(&sk->sk_drops);
75422 + atomic_inc_unchecked(&sk->sk_drops);
75423 trace_sock_rcvqueue_full(sk, skb);
75424 return -ENOMEM;
75425 }
75426 @@ -303,7 +303,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75427 return err;
75428
75429 if (!sk_rmem_schedule(sk, skb->truesize)) {
75430 - atomic_inc(&sk->sk_drops);
75431 + atomic_inc_unchecked(&sk->sk_drops);
75432 return -ENOBUFS;
75433 }
75434
75435 @@ -323,7 +323,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75436 skb_dst_force(skb);
75437
75438 spin_lock_irqsave(&list->lock, flags);
75439 - skb->dropcount = atomic_read(&sk->sk_drops);
75440 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75441 __skb_queue_tail(list, skb);
75442 spin_unlock_irqrestore(&list->lock, flags);
75443
75444 @@ -343,7 +343,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75445 skb->dev = NULL;
75446
75447 if (sk_rcvqueues_full(sk, skb)) {
75448 - atomic_inc(&sk->sk_drops);
75449 + atomic_inc_unchecked(&sk->sk_drops);
75450 goto discard_and_relse;
75451 }
75452 if (nested)
75453 @@ -361,7 +361,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75454 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75455 } else if (sk_add_backlog(sk, skb)) {
75456 bh_unlock_sock(sk);
75457 - atomic_inc(&sk->sk_drops);
75458 + atomic_inc_unchecked(&sk->sk_drops);
75459 goto discard_and_relse;
75460 }
75461
75462 @@ -924,7 +924,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75463 if (len > sizeof(peercred))
75464 len = sizeof(peercred);
75465 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75466 - if (copy_to_user(optval, &peercred, len))
75467 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75468 return -EFAULT;
75469 goto lenout;
75470 }
75471 @@ -937,7 +937,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75472 return -ENOTCONN;
75473 if (lv < len)
75474 return -EINVAL;
75475 - if (copy_to_user(optval, address, len))
75476 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75477 return -EFAULT;
75478 goto lenout;
75479 }
75480 @@ -970,7 +970,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75481
75482 if (len > lv)
75483 len = lv;
75484 - if (copy_to_user(optval, &v, len))
75485 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75486 return -EFAULT;
75487 lenout:
75488 if (put_user(len, optlen))
75489 @@ -2029,7 +2029,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75490 */
75491 smp_wmb();
75492 atomic_set(&sk->sk_refcnt, 1);
75493 - atomic_set(&sk->sk_drops, 0);
75494 + atomic_set_unchecked(&sk->sk_drops, 0);
75495 }
75496 EXPORT_SYMBOL(sock_init_data);
75497
75498 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75499 index 02e75d1..9a57a7c 100644
75500 --- a/net/decnet/sysctl_net_decnet.c
75501 +++ b/net/decnet/sysctl_net_decnet.c
75502 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75503
75504 if (len > *lenp) len = *lenp;
75505
75506 - if (copy_to_user(buffer, addr, len))
75507 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75508 return -EFAULT;
75509
75510 *lenp = len;
75511 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75512
75513 if (len > *lenp) len = *lenp;
75514
75515 - if (copy_to_user(buffer, devname, len))
75516 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75517 return -EFAULT;
75518
75519 *lenp = len;
75520 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
75521 index 39a2d29..f39c0fe 100644
75522 --- a/net/econet/Kconfig
75523 +++ b/net/econet/Kconfig
75524 @@ -4,7 +4,7 @@
75525
75526 config ECONET
75527 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75528 - depends on EXPERIMENTAL && INET
75529 + depends on EXPERIMENTAL && INET && BROKEN
75530 ---help---
75531 Econet is a fairly old and slow networking protocol mainly used by
75532 Acorn computers to access file and print servers. It uses native
75533 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75534 index 92fc5f6..b790d91 100644
75535 --- a/net/ipv4/fib_frontend.c
75536 +++ b/net/ipv4/fib_frontend.c
75537 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75538 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75539 fib_sync_up(dev);
75540 #endif
75541 - atomic_inc(&net->ipv4.dev_addr_genid);
75542 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75543 rt_cache_flush(dev_net(dev), -1);
75544 break;
75545 case NETDEV_DOWN:
75546 fib_del_ifaddr(ifa, NULL);
75547 - atomic_inc(&net->ipv4.dev_addr_genid);
75548 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75549 if (ifa->ifa_dev->ifa_list == NULL) {
75550 /* Last address was deleted from this interface.
75551 * Disable IP.
75552 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75553 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75554 fib_sync_up(dev);
75555 #endif
75556 - atomic_inc(&net->ipv4.dev_addr_genid);
75557 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75558 rt_cache_flush(dev_net(dev), -1);
75559 break;
75560 case NETDEV_DOWN:
75561 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75562 index 80106d8..232e898 100644
75563 --- a/net/ipv4/fib_semantics.c
75564 +++ b/net/ipv4/fib_semantics.c
75565 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75566 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75567 nh->nh_gw,
75568 nh->nh_parent->fib_scope);
75569 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75570 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75571
75572 return nh->nh_saddr;
75573 }
75574 diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
75575 index 389a2e6..ac1c1de 100644
75576 --- a/net/ipv4/inet_diag.c
75577 +++ b/net/ipv4/inet_diag.c
75578 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct sock *sk,
75579 r->idiag_retrans = 0;
75580
75581 r->id.idiag_if = sk->sk_bound_dev_if;
75582 +
75583 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75584 + r->id.idiag_cookie[0] = 0;
75585 + r->id.idiag_cookie[1] = 0;
75586 +#else
75587 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
75588 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75589 +#endif
75590
75591 r->id.idiag_sport = inet->inet_sport;
75592 r->id.idiag_dport = inet->inet_dport;
75593 @@ -201,8 +207,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
75594 r->idiag_family = tw->tw_family;
75595 r->idiag_retrans = 0;
75596 r->id.idiag_if = tw->tw_bound_dev_if;
75597 +
75598 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75599 + r->id.idiag_cookie[0] = 0;
75600 + r->id.idiag_cookie[1] = 0;
75601 +#else
75602 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
75603 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
75604 +#endif
75605 +
75606 r->id.idiag_sport = tw->tw_sport;
75607 r->id.idiag_dport = tw->tw_dport;
75608 r->id.idiag_src[0] = tw->tw_rcv_saddr;
75609 @@ -285,12 +298,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
75610 if (sk == NULL)
75611 goto unlock;
75612
75613 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75614 err = -ESTALE;
75615 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
75616 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
75617 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
75618 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
75619 goto out;
75620 +#endif
75621
75622 err = -ENOMEM;
75623 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
75624 @@ -580,8 +595,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
75625 r->idiag_retrans = req->retrans;
75626
75627 r->id.idiag_if = sk->sk_bound_dev_if;
75628 +
75629 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75630 + r->id.idiag_cookie[0] = 0;
75631 + r->id.idiag_cookie[1] = 0;
75632 +#else
75633 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
75634 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
75635 +#endif
75636
75637 tmo = req->expires - jiffies;
75638 if (tmo < 0)
75639 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75640 index 984ec65..97ac518 100644
75641 --- a/net/ipv4/inet_hashtables.c
75642 +++ b/net/ipv4/inet_hashtables.c
75643 @@ -18,12 +18,15 @@
75644 #include <linux/sched.h>
75645 #include <linux/slab.h>
75646 #include <linux/wait.h>
75647 +#include <linux/security.h>
75648
75649 #include <net/inet_connection_sock.h>
75650 #include <net/inet_hashtables.h>
75651 #include <net/secure_seq.h>
75652 #include <net/ip.h>
75653
75654 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75655 +
75656 /*
75657 * Allocate and initialize a new local port bind bucket.
75658 * The bindhash mutex for snum's hash chain must be held here.
75659 @@ -530,6 +533,8 @@ ok:
75660 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75661 spin_unlock(&head->lock);
75662
75663 + gr_update_task_in_ip_table(current, inet_sk(sk));
75664 +
75665 if (tw) {
75666 inet_twsk_deschedule(tw, death_row);
75667 while (twrefcnt) {
75668 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75669 index 86f13c67..0bce60f 100644
75670 --- a/net/ipv4/inetpeer.c
75671 +++ b/net/ipv4/inetpeer.c
75672 @@ -400,6 +400,8 @@ struct inet_peer *inet_getpeer(const struct inetpeer_addr *daddr, int create)
75673 unsigned int sequence;
75674 int invalidated, gccnt = 0;
75675
75676 + pax_track_stack();
75677 +
75678 /* Attempt a lockless lookup first.
75679 * Because of a concurrent writer, we might not find an existing entry.
75680 */
75681 @@ -436,8 +438,8 @@ relookup:
75682 if (p) {
75683 p->daddr = *daddr;
75684 atomic_set(&p->refcnt, 1);
75685 - atomic_set(&p->rid, 0);
75686 - atomic_set(&p->ip_id_count,
75687 + atomic_set_unchecked(&p->rid, 0);
75688 + atomic_set_unchecked(&p->ip_id_count,
75689 (daddr->family == AF_INET) ?
75690 secure_ip_id(daddr->addr.a4) :
75691 secure_ipv6_id(daddr->addr.a6));
75692 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75693 index 0e0ab98..2ed7dd5 100644
75694 --- a/net/ipv4/ip_fragment.c
75695 +++ b/net/ipv4/ip_fragment.c
75696 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75697 return 0;
75698
75699 start = qp->rid;
75700 - end = atomic_inc_return(&peer->rid);
75701 + end = atomic_inc_return_unchecked(&peer->rid);
75702 qp->rid = end;
75703
75704 rc = qp->q.fragments && (end - start) > max;
75705 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75706 index 8905e92..0b179fb 100644
75707 --- a/net/ipv4/ip_sockglue.c
75708 +++ b/net/ipv4/ip_sockglue.c
75709 @@ -1073,6 +1073,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75710 int val;
75711 int len;
75712
75713 + pax_track_stack();
75714 +
75715 if (level != SOL_IP)
75716 return -EOPNOTSUPP;
75717
75718 @@ -1110,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75719 len = min_t(unsigned int, len, opt->optlen);
75720 if (put_user(len, optlen))
75721 return -EFAULT;
75722 - if (copy_to_user(optval, opt->__data, len))
75723 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75724 + copy_to_user(optval, opt->__data, len))
75725 return -EFAULT;
75726 return 0;
75727 }
75728 @@ -1238,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75729 if (sk->sk_type != SOCK_STREAM)
75730 return -ENOPROTOOPT;
75731
75732 - msg.msg_control = optval;
75733 + msg.msg_control = (void __force_kernel *)optval;
75734 msg.msg_controllen = len;
75735 msg.msg_flags = flags;
75736
75737 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75738 index 004bb74..8d4a58c 100644
75739 --- a/net/ipv4/ipconfig.c
75740 +++ b/net/ipv4/ipconfig.c
75741 @@ -317,7 +317,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75742
75743 mm_segment_t oldfs = get_fs();
75744 set_fs(get_ds());
75745 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75746 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75747 set_fs(oldfs);
75748 return res;
75749 }
75750 @@ -328,7 +328,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75751
75752 mm_segment_t oldfs = get_fs();
75753 set_fs(get_ds());
75754 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75755 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75756 set_fs(oldfs);
75757 return res;
75758 }
75759 @@ -339,7 +339,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75760
75761 mm_segment_t oldfs = get_fs();
75762 set_fs(get_ds());
75763 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75764 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75765 set_fs(oldfs);
75766 return res;
75767 }
75768 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
75769 index 076b7c8..9c8d038 100644
75770 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
75771 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
75772 @@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
75773
75774 *len = 0;
75775
75776 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
75777 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
75778 if (*octets == NULL) {
75779 if (net_ratelimit())
75780 pr_notice("OOM in bsalg (%d)\n", __LINE__);
75781 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75782 index 39b403f..8e6a0a8 100644
75783 --- a/net/ipv4/ping.c
75784 +++ b/net/ipv4/ping.c
75785 @@ -837,7 +837,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75786 sk_rmem_alloc_get(sp),
75787 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75788 atomic_read(&sp->sk_refcnt), sp,
75789 - atomic_read(&sp->sk_drops), len);
75790 + atomic_read_unchecked(&sp->sk_drops), len);
75791 }
75792
75793 static int ping_seq_show(struct seq_file *seq, void *v)
75794 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75795 index 61714bd..c9cee6d 100644
75796 --- a/net/ipv4/raw.c
75797 +++ b/net/ipv4/raw.c
75798 @@ -302,7 +302,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
75799 int raw_rcv(struct sock *sk, struct sk_buff *skb)
75800 {
75801 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
75802 - atomic_inc(&sk->sk_drops);
75803 + atomic_inc_unchecked(&sk->sk_drops);
75804 kfree_skb(skb);
75805 return NET_RX_DROP;
75806 }
75807 @@ -737,16 +737,20 @@ static int raw_init(struct sock *sk)
75808
75809 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
75810 {
75811 + struct icmp_filter filter;
75812 +
75813 if (optlen > sizeof(struct icmp_filter))
75814 optlen = sizeof(struct icmp_filter);
75815 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
75816 + if (copy_from_user(&filter, optval, optlen))
75817 return -EFAULT;
75818 + raw_sk(sk)->filter = filter;
75819 return 0;
75820 }
75821
75822 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
75823 {
75824 int len, ret = -EFAULT;
75825 + struct icmp_filter filter;
75826
75827 if (get_user(len, optlen))
75828 goto out;
75829 @@ -756,8 +760,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
75830 if (len > sizeof(struct icmp_filter))
75831 len = sizeof(struct icmp_filter);
75832 ret = -EFAULT;
75833 - if (put_user(len, optlen) ||
75834 - copy_to_user(optval, &raw_sk(sk)->filter, len))
75835 + filter = raw_sk(sk)->filter;
75836 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
75837 goto out;
75838 ret = 0;
75839 out: return ret;
75840 @@ -985,7 +989,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75841 sk_wmem_alloc_get(sp),
75842 sk_rmem_alloc_get(sp),
75843 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75844 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75845 + atomic_read(&sp->sk_refcnt),
75846 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75847 + NULL,
75848 +#else
75849 + sp,
75850 +#endif
75851 + atomic_read_unchecked(&sp->sk_drops));
75852 }
75853
75854 static int raw_seq_show(struct seq_file *seq, void *v)
75855 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
75856 index b563854..e03f8a6 100644
75857 --- a/net/ipv4/route.c
75858 +++ b/net/ipv4/route.c
75859 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
75860
75861 static inline int rt_genid(struct net *net)
75862 {
75863 - return atomic_read(&net->ipv4.rt_genid);
75864 + return atomic_read_unchecked(&net->ipv4.rt_genid);
75865 }
75866
75867 #ifdef CONFIG_PROC_FS
75868 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
75869 unsigned char shuffle;
75870
75871 get_random_bytes(&shuffle, sizeof(shuffle));
75872 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
75873 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
75874 redirect_genid++;
75875 }
75876
75877 @@ -3015,7 +3015,7 @@ static int rt_fill_info(struct net *net,
75878 error = rt->dst.error;
75879 if (peer) {
75880 inet_peer_refcheck(rt->peer);
75881 - id = atomic_read(&peer->ip_id_count) & 0xffff;
75882 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
75883 if (peer->tcp_ts_stamp) {
75884 ts = peer->tcp_ts;
75885 tsage = get_seconds() - peer->tcp_ts_stamp;
75886 diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
75887 index 46febca..98b73a4 100644
75888 --- a/net/ipv4/tcp.c
75889 +++ b/net/ipv4/tcp.c
75890 @@ -2122,6 +2122,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
75891 int val;
75892 int err = 0;
75893
75894 + pax_track_stack();
75895 +
75896 /* These are data/string values, all the others are ints */
75897 switch (optname) {
75898 case TCP_CONGESTION: {
75899 @@ -2501,6 +2503,8 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
75900 struct tcp_sock *tp = tcp_sk(sk);
75901 int val, len;
75902
75903 + pax_track_stack();
75904 +
75905 if (get_user(len, optlen))
75906 return -EFAULT;
75907
75908 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
75909 index 7963e03..c44f5d0 100644
75910 --- a/net/ipv4/tcp_ipv4.c
75911 +++ b/net/ipv4/tcp_ipv4.c
75912 @@ -87,6 +87,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
75913 int sysctl_tcp_low_latency __read_mostly;
75914 EXPORT_SYMBOL(sysctl_tcp_low_latency);
75915
75916 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75917 +extern int grsec_enable_blackhole;
75918 +#endif
75919
75920 #ifdef CONFIG_TCP_MD5SIG
75921 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
75922 @@ -1622,6 +1625,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
75923 return 0;
75924
75925 reset:
75926 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75927 + if (!grsec_enable_blackhole)
75928 +#endif
75929 tcp_v4_send_reset(rsk, skb);
75930 discard:
75931 kfree_skb(skb);
75932 @@ -1684,12 +1690,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
75933 TCP_SKB_CB(skb)->sacked = 0;
75934
75935 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75936 - if (!sk)
75937 + if (!sk) {
75938 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75939 + ret = 1;
75940 +#endif
75941 goto no_tcp_socket;
75942 -
75943 + }
75944 process:
75945 - if (sk->sk_state == TCP_TIME_WAIT)
75946 + if (sk->sk_state == TCP_TIME_WAIT) {
75947 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75948 + ret = 2;
75949 +#endif
75950 goto do_time_wait;
75951 + }
75952
75953 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
75954 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75955 @@ -1739,6 +1752,10 @@ no_tcp_socket:
75956 bad_packet:
75957 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75958 } else {
75959 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75960 + if (!grsec_enable_blackhole || (ret == 1 &&
75961 + (skb->dev->flags & IFF_LOOPBACK)))
75962 +#endif
75963 tcp_v4_send_reset(NULL, skb);
75964 }
75965
75966 @@ -2403,7 +2420,11 @@ static void get_openreq4(struct sock *sk, struct request_sock *req,
75967 0, /* non standard timer */
75968 0, /* open_requests have no inode */
75969 atomic_read(&sk->sk_refcnt),
75970 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75971 + NULL,
75972 +#else
75973 req,
75974 +#endif
75975 len);
75976 }
75977
75978 @@ -2453,7 +2474,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
75979 sock_i_uid(sk),
75980 icsk->icsk_probes_out,
75981 sock_i_ino(sk),
75982 - atomic_read(&sk->sk_refcnt), sk,
75983 + atomic_read(&sk->sk_refcnt),
75984 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75985 + NULL,
75986 +#else
75987 + sk,
75988 +#endif
75989 jiffies_to_clock_t(icsk->icsk_rto),
75990 jiffies_to_clock_t(icsk->icsk_ack.ato),
75991 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
75992 @@ -2481,7 +2507,13 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
75993 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
75994 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
75995 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75996 - atomic_read(&tw->tw_refcnt), tw, len);
75997 + atomic_read(&tw->tw_refcnt),
75998 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75999 + NULL,
76000 +#else
76001 + tw,
76002 +#endif
76003 + len);
76004 }
76005
76006 #define TMPSZ 150
76007 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76008 index 0ce3d06..e182e59 100644
76009 --- a/net/ipv4/tcp_minisocks.c
76010 +++ b/net/ipv4/tcp_minisocks.c
76011 @@ -27,6 +27,10 @@
76012 #include <net/inet_common.h>
76013 #include <net/xfrm.h>
76014
76015 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76016 +extern int grsec_enable_blackhole;
76017 +#endif
76018 +
76019 int sysctl_tcp_syncookies __read_mostly = 1;
76020 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76021
76022 @@ -750,6 +754,10 @@ listen_overflow:
76023
76024 embryonic_reset:
76025 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76026 +
76027 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76028 + if (!grsec_enable_blackhole)
76029 +#endif
76030 if (!(flg & TCP_FLAG_RST))
76031 req->rsk_ops->send_reset(sk, skb);
76032
76033 diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
76034 index 882e0b0..2eba47f 100644
76035 --- a/net/ipv4/tcp_output.c
76036 +++ b/net/ipv4/tcp_output.c
76037 @@ -2421,6 +2421,8 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
76038 int mss;
76039 int s_data_desired = 0;
76040
76041 + pax_track_stack();
76042 +
76043 if (cvp != NULL && cvp->s_data_constant && cvp->s_data_desired)
76044 s_data_desired = cvp->s_data_desired;
76045 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15 + s_data_desired, 1, GFP_ATOMIC);
76046 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76047 index 85ee7eb..53277ab 100644
76048 --- a/net/ipv4/tcp_probe.c
76049 +++ b/net/ipv4/tcp_probe.c
76050 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76051 if (cnt + width >= len)
76052 break;
76053
76054 - if (copy_to_user(buf + cnt, tbuf, width))
76055 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76056 return -EFAULT;
76057 cnt += width;
76058 }
76059 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76060 index ecd44b0..b32fba6 100644
76061 --- a/net/ipv4/tcp_timer.c
76062 +++ b/net/ipv4/tcp_timer.c
76063 @@ -22,6 +22,10 @@
76064 #include <linux/gfp.h>
76065 #include <net/tcp.h>
76066
76067 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76068 +extern int grsec_lastack_retries;
76069 +#endif
76070 +
76071 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76072 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76073 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76074 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock *sk)
76075 }
76076 }
76077
76078 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76079 + if ((sk->sk_state == TCP_LAST_ACK) &&
76080 + (grsec_lastack_retries > 0) &&
76081 + (grsec_lastack_retries < retry_until))
76082 + retry_until = grsec_lastack_retries;
76083 +#endif
76084 +
76085 if (retransmits_timed_out(sk, retry_until,
76086 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76087 /* Has it gone just too far? */
76088 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76089 index 1b5a193..bd354b0 100644
76090 --- a/net/ipv4/udp.c
76091 +++ b/net/ipv4/udp.c
76092 @@ -86,6 +86,7 @@
76093 #include <linux/types.h>
76094 #include <linux/fcntl.h>
76095 #include <linux/module.h>
76096 +#include <linux/security.h>
76097 #include <linux/socket.h>
76098 #include <linux/sockios.h>
76099 #include <linux/igmp.h>
76100 @@ -108,6 +109,10 @@
76101 #include <trace/events/udp.h>
76102 #include "udp_impl.h"
76103
76104 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76105 +extern int grsec_enable_blackhole;
76106 +#endif
76107 +
76108 struct udp_table udp_table __read_mostly;
76109 EXPORT_SYMBOL(udp_table);
76110
76111 @@ -565,6 +570,9 @@ found:
76112 return s;
76113 }
76114
76115 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76116 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76117 +
76118 /*
76119 * This routine is called by the ICMP module when it gets some
76120 * sort of error condition. If err < 0 then the socket should
76121 @@ -856,9 +864,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76122 dport = usin->sin_port;
76123 if (dport == 0)
76124 return -EINVAL;
76125 +
76126 + err = gr_search_udp_sendmsg(sk, usin);
76127 + if (err)
76128 + return err;
76129 } else {
76130 if (sk->sk_state != TCP_ESTABLISHED)
76131 return -EDESTADDRREQ;
76132 +
76133 + err = gr_search_udp_sendmsg(sk, NULL);
76134 + if (err)
76135 + return err;
76136 +
76137 daddr = inet->inet_daddr;
76138 dport = inet->inet_dport;
76139 /* Open fast path for connected socket.
76140 @@ -1099,7 +1116,7 @@ static unsigned int first_packet_length(struct sock *sk)
76141 udp_lib_checksum_complete(skb)) {
76142 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76143 IS_UDPLITE(sk));
76144 - atomic_inc(&sk->sk_drops);
76145 + atomic_inc_unchecked(&sk->sk_drops);
76146 __skb_unlink(skb, rcvq);
76147 __skb_queue_tail(&list_kill, skb);
76148 }
76149 @@ -1185,6 +1202,10 @@ try_again:
76150 if (!skb)
76151 goto out;
76152
76153 + err = gr_search_udp_recvmsg(sk, skb);
76154 + if (err)
76155 + goto out_free;
76156 +
76157 ulen = skb->len - sizeof(struct udphdr);
76158 if (len > ulen)
76159 len = ulen;
76160 @@ -1485,7 +1506,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76161
76162 drop:
76163 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76164 - atomic_inc(&sk->sk_drops);
76165 + atomic_inc_unchecked(&sk->sk_drops);
76166 kfree_skb(skb);
76167 return -1;
76168 }
76169 @@ -1504,7 +1525,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76170 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76171
76172 if (!skb1) {
76173 - atomic_inc(&sk->sk_drops);
76174 + atomic_inc_unchecked(&sk->sk_drops);
76175 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76176 IS_UDPLITE(sk));
76177 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76178 @@ -1673,6 +1694,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76179 goto csum_error;
76180
76181 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76182 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76183 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76184 +#endif
76185 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76186
76187 /*
76188 @@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76189 sk_wmem_alloc_get(sp),
76190 sk_rmem_alloc_get(sp),
76191 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76192 - atomic_read(&sp->sk_refcnt), sp,
76193 - atomic_read(&sp->sk_drops), len);
76194 + atomic_read(&sp->sk_refcnt),
76195 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76196 + NULL,
76197 +#else
76198 + sp,
76199 +#endif
76200 + atomic_read_unchecked(&sp->sk_drops), len);
76201 }
76202
76203 int udp4_seq_show(struct seq_file *seq, void *v)
76204 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76205 index 12368c5..fbf899f 100644
76206 --- a/net/ipv6/addrconf.c
76207 +++ b/net/ipv6/addrconf.c
76208 @@ -2083,7 +2083,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76209 p.iph.ihl = 5;
76210 p.iph.protocol = IPPROTO_IPV6;
76211 p.iph.ttl = 64;
76212 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76213 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76214
76215 if (ops->ndo_do_ioctl) {
76216 mm_segment_t oldfs = get_fs();
76217 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76218 index 8a58e8c..8b5e631 100644
76219 --- a/net/ipv6/inet6_connection_sock.c
76220 +++ b/net/ipv6/inet6_connection_sock.c
76221 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76222 #ifdef CONFIG_XFRM
76223 {
76224 struct rt6_info *rt = (struct rt6_info *)dst;
76225 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76226 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76227 }
76228 #endif
76229 }
76230 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76231 #ifdef CONFIG_XFRM
76232 if (dst) {
76233 struct rt6_info *rt = (struct rt6_info *)dst;
76234 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76235 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76236 __sk_dst_reset(sk);
76237 dst = NULL;
76238 }
76239 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76240 index 2fbda5f..26ed683 100644
76241 --- a/net/ipv6/ipv6_sockglue.c
76242 +++ b/net/ipv6/ipv6_sockglue.c
76243 @@ -129,6 +129,8 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
76244 int val, valbool;
76245 int retv = -ENOPROTOOPT;
76246
76247 + pax_track_stack();
76248 +
76249 if (optval == NULL)
76250 val=0;
76251 else {
76252 @@ -919,6 +921,8 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76253 int len;
76254 int val;
76255
76256 + pax_track_stack();
76257 +
76258 if (ip6_mroute_opt(optname))
76259 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
76260
76261 @@ -960,7 +964,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76262 if (sk->sk_type != SOCK_STREAM)
76263 return -ENOPROTOOPT;
76264
76265 - msg.msg_control = optval;
76266 + msg.msg_control = (void __force_kernel *)optval;
76267 msg.msg_controllen = len;
76268 msg.msg_flags = flags;
76269
76270 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76271 index 343852e..c92bd15 100644
76272 --- a/net/ipv6/raw.c
76273 +++ b/net/ipv6/raw.c
76274 @@ -376,7 +376,7 @@ static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
76275 {
76276 if ((raw6_sk(sk)->checksum || rcu_dereference_raw(sk->sk_filter)) &&
76277 skb_checksum_complete(skb)) {
76278 - atomic_inc(&sk->sk_drops);
76279 + atomic_inc_unchecked(&sk->sk_drops);
76280 kfree_skb(skb);
76281 return NET_RX_DROP;
76282 }
76283 @@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76284 struct raw6_sock *rp = raw6_sk(sk);
76285
76286 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76287 - atomic_inc(&sk->sk_drops);
76288 + atomic_inc_unchecked(&sk->sk_drops);
76289 kfree_skb(skb);
76290 return NET_RX_DROP;
76291 }
76292 @@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76293
76294 if (inet->hdrincl) {
76295 if (skb_checksum_complete(skb)) {
76296 - atomic_inc(&sk->sk_drops);
76297 + atomic_inc_unchecked(&sk->sk_drops);
76298 kfree_skb(skb);
76299 return NET_RX_DROP;
76300 }
76301 @@ -601,7 +601,7 @@ out:
76302 return err;
76303 }
76304
76305 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76306 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76307 struct flowi6 *fl6, struct dst_entry **dstp,
76308 unsigned int flags)
76309 {
76310 @@ -742,6 +742,8 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
76311 u16 proto;
76312 int err;
76313
76314 + pax_track_stack();
76315 +
76316 /* Rough check on arithmetic overflow,
76317 better check is made in ip6_append_data().
76318 */
76319 @@ -909,12 +911,15 @@ do_confirm:
76320 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76321 char __user *optval, int optlen)
76322 {
76323 + struct icmp6_filter filter;
76324 +
76325 switch (optname) {
76326 case ICMPV6_FILTER:
76327 if (optlen > sizeof(struct icmp6_filter))
76328 optlen = sizeof(struct icmp6_filter);
76329 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76330 + if (copy_from_user(&filter, optval, optlen))
76331 return -EFAULT;
76332 + raw6_sk(sk)->filter = filter;
76333 return 0;
76334 default:
76335 return -ENOPROTOOPT;
76336 @@ -927,6 +932,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76337 char __user *optval, int __user *optlen)
76338 {
76339 int len;
76340 + struct icmp6_filter filter;
76341
76342 switch (optname) {
76343 case ICMPV6_FILTER:
76344 @@ -938,7 +944,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76345 len = sizeof(struct icmp6_filter);
76346 if (put_user(len, optlen))
76347 return -EFAULT;
76348 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76349 + filter = raw6_sk(sk)->filter;
76350 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76351 return -EFAULT;
76352 return 0;
76353 default:
76354 @@ -1245,7 +1252,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76355 0, 0L, 0,
76356 sock_i_uid(sp), 0,
76357 sock_i_ino(sp),
76358 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76359 + atomic_read(&sp->sk_refcnt),
76360 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76361 + NULL,
76362 +#else
76363 + sp,
76364 +#endif
76365 + atomic_read_unchecked(&sp->sk_drops));
76366 }
76367
76368 static int raw6_seq_show(struct seq_file *seq, void *v)
76369 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76370 index 7b8fc57..c6185da 100644
76371 --- a/net/ipv6/tcp_ipv6.c
76372 +++ b/net/ipv6/tcp_ipv6.c
76373 @@ -93,6 +93,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76374 }
76375 #endif
76376
76377 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76378 +extern int grsec_enable_blackhole;
76379 +#endif
76380 +
76381 static void tcp_v6_hash(struct sock *sk)
76382 {
76383 if (sk->sk_state != TCP_CLOSE) {
76384 @@ -1647,6 +1651,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76385 return 0;
76386
76387 reset:
76388 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76389 + if (!grsec_enable_blackhole)
76390 +#endif
76391 tcp_v6_send_reset(sk, skb);
76392 discard:
76393 if (opt_skb)
76394 @@ -1726,12 +1733,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76395 TCP_SKB_CB(skb)->sacked = 0;
76396
76397 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76398 - if (!sk)
76399 + if (!sk) {
76400 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76401 + ret = 1;
76402 +#endif
76403 goto no_tcp_socket;
76404 + }
76405
76406 process:
76407 - if (sk->sk_state == TCP_TIME_WAIT)
76408 + if (sk->sk_state == TCP_TIME_WAIT) {
76409 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76410 + ret = 2;
76411 +#endif
76412 goto do_time_wait;
76413 + }
76414
76415 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76416 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76417 @@ -1779,6 +1794,10 @@ no_tcp_socket:
76418 bad_packet:
76419 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76420 } else {
76421 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76422 + if (!grsec_enable_blackhole || (ret == 1 &&
76423 + (skb->dev->flags & IFF_LOOPBACK)))
76424 +#endif
76425 tcp_v6_send_reset(NULL, skb);
76426 }
76427
76428 @@ -2039,7 +2058,13 @@ static void get_openreq6(struct seq_file *seq,
76429 uid,
76430 0, /* non standard timer */
76431 0, /* open_requests have no inode */
76432 - 0, req);
76433 + 0,
76434 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76435 + NULL
76436 +#else
76437 + req
76438 +#endif
76439 + );
76440 }
76441
76442 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76443 @@ -2089,7 +2114,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76444 sock_i_uid(sp),
76445 icsk->icsk_probes_out,
76446 sock_i_ino(sp),
76447 - atomic_read(&sp->sk_refcnt), sp,
76448 + atomic_read(&sp->sk_refcnt),
76449 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76450 + NULL,
76451 +#else
76452 + sp,
76453 +#endif
76454 jiffies_to_clock_t(icsk->icsk_rto),
76455 jiffies_to_clock_t(icsk->icsk_ack.ato),
76456 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76457 @@ -2124,7 +2154,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76458 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76459 tw->tw_substate, 0, 0,
76460 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76461 - atomic_read(&tw->tw_refcnt), tw);
76462 + atomic_read(&tw->tw_refcnt),
76463 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76464 + NULL
76465 +#else
76466 + tw
76467 +#endif
76468 + );
76469 }
76470
76471 static int tcp6_seq_show(struct seq_file *seq, void *v)
76472 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76473 index bb95e8e..ae0ee80 100644
76474 --- a/net/ipv6/udp.c
76475 +++ b/net/ipv6/udp.c
76476 @@ -50,6 +50,10 @@
76477 #include <linux/seq_file.h>
76478 #include "udp_impl.h"
76479
76480 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76481 +extern int grsec_enable_blackhole;
76482 +#endif
76483 +
76484 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76485 {
76486 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76487 @@ -548,7 +552,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
76488
76489 return 0;
76490 drop:
76491 - atomic_inc(&sk->sk_drops);
76492 + atomic_inc_unchecked(&sk->sk_drops);
76493 drop_no_sk_drops_inc:
76494 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76495 kfree_skb(skb);
76496 @@ -624,7 +628,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76497 continue;
76498 }
76499 drop:
76500 - atomic_inc(&sk->sk_drops);
76501 + atomic_inc_unchecked(&sk->sk_drops);
76502 UDP6_INC_STATS_BH(sock_net(sk),
76503 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76504 UDP6_INC_STATS_BH(sock_net(sk),
76505 @@ -779,6 +783,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76506 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76507 proto == IPPROTO_UDPLITE);
76508
76509 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76510 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76511 +#endif
76512 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76513
76514 kfree_skb(skb);
76515 @@ -795,7 +802,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76516 if (!sock_owned_by_user(sk))
76517 udpv6_queue_rcv_skb(sk, skb);
76518 else if (sk_add_backlog(sk, skb)) {
76519 - atomic_inc(&sk->sk_drops);
76520 + atomic_inc_unchecked(&sk->sk_drops);
76521 bh_unlock_sock(sk);
76522 sock_put(sk);
76523 goto discard;
76524 @@ -1406,8 +1413,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76525 0, 0L, 0,
76526 sock_i_uid(sp), 0,
76527 sock_i_ino(sp),
76528 - atomic_read(&sp->sk_refcnt), sp,
76529 - atomic_read(&sp->sk_drops));
76530 + atomic_read(&sp->sk_refcnt),
76531 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76532 + NULL,
76533 +#else
76534 + sp,
76535 +#endif
76536 + atomic_read_unchecked(&sp->sk_drops));
76537 }
76538
76539 int udp6_seq_show(struct seq_file *seq, void *v)
76540 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76541 index b3cc8b3..baa02d0 100644
76542 --- a/net/irda/ircomm/ircomm_tty.c
76543 +++ b/net/irda/ircomm/ircomm_tty.c
76544 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76545 add_wait_queue(&self->open_wait, &wait);
76546
76547 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76548 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76549 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76550
76551 /* As far as I can see, we protect open_count - Jean II */
76552 spin_lock_irqsave(&self->spinlock, flags);
76553 if (!tty_hung_up_p(filp)) {
76554 extra_count = 1;
76555 - self->open_count--;
76556 + local_dec(&self->open_count);
76557 }
76558 spin_unlock_irqrestore(&self->spinlock, flags);
76559 - self->blocked_open++;
76560 + local_inc(&self->blocked_open);
76561
76562 while (1) {
76563 if (tty->termios->c_cflag & CBAUD) {
76564 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76565 }
76566
76567 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76568 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76569 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76570
76571 schedule();
76572 }
76573 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76574 if (extra_count) {
76575 /* ++ is not atomic, so this should be protected - Jean II */
76576 spin_lock_irqsave(&self->spinlock, flags);
76577 - self->open_count++;
76578 + local_inc(&self->open_count);
76579 spin_unlock_irqrestore(&self->spinlock, flags);
76580 }
76581 - self->blocked_open--;
76582 + local_dec(&self->blocked_open);
76583
76584 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76585 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76586 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76587
76588 if (!retval)
76589 self->flags |= ASYNC_NORMAL_ACTIVE;
76590 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76591 }
76592 /* ++ is not atomic, so this should be protected - Jean II */
76593 spin_lock_irqsave(&self->spinlock, flags);
76594 - self->open_count++;
76595 + local_inc(&self->open_count);
76596
76597 tty->driver_data = self;
76598 self->tty = tty;
76599 spin_unlock_irqrestore(&self->spinlock, flags);
76600
76601 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76602 - self->line, self->open_count);
76603 + self->line, local_read(&self->open_count));
76604
76605 /* Not really used by us, but lets do it anyway */
76606 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76607 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76608 return;
76609 }
76610
76611 - if ((tty->count == 1) && (self->open_count != 1)) {
76612 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76613 /*
76614 * Uh, oh. tty->count is 1, which means that the tty
76615 * structure will be freed. state->count should always
76616 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76617 */
76618 IRDA_DEBUG(0, "%s(), bad serial port count; "
76619 "tty->count is 1, state->count is %d\n", __func__ ,
76620 - self->open_count);
76621 - self->open_count = 1;
76622 + local_read(&self->open_count));
76623 + local_set(&self->open_count, 1);
76624 }
76625
76626 - if (--self->open_count < 0) {
76627 + if (local_dec_return(&self->open_count) < 0) {
76628 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76629 - __func__, self->line, self->open_count);
76630 - self->open_count = 0;
76631 + __func__, self->line, local_read(&self->open_count));
76632 + local_set(&self->open_count, 0);
76633 }
76634 - if (self->open_count) {
76635 + if (local_read(&self->open_count)) {
76636 spin_unlock_irqrestore(&self->spinlock, flags);
76637
76638 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76639 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76640 tty->closing = 0;
76641 self->tty = NULL;
76642
76643 - if (self->blocked_open) {
76644 + if (local_read(&self->blocked_open)) {
76645 if (self->close_delay)
76646 schedule_timeout_interruptible(self->close_delay);
76647 wake_up_interruptible(&self->open_wait);
76648 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76649 spin_lock_irqsave(&self->spinlock, flags);
76650 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76651 self->tty = NULL;
76652 - self->open_count = 0;
76653 + local_set(&self->open_count, 0);
76654 spin_unlock_irqrestore(&self->spinlock, flags);
76655
76656 wake_up_interruptible(&self->open_wait);
76657 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76658 seq_putc(m, '\n');
76659
76660 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76661 - seq_printf(m, "Open count: %d\n", self->open_count);
76662 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76663 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76664 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76665
76666 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76667 index e2013e4..edfc1e3 100644
76668 --- a/net/iucv/af_iucv.c
76669 +++ b/net/iucv/af_iucv.c
76670 @@ -648,10 +648,10 @@ static int iucv_sock_autobind(struct sock *sk)
76671
76672 write_lock_bh(&iucv_sk_list.lock);
76673
76674 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76675 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76676 while (__iucv_get_sock_by_name(name)) {
76677 sprintf(name, "%08x",
76678 - atomic_inc_return(&iucv_sk_list.autobind_name));
76679 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76680 }
76681
76682 write_unlock_bh(&iucv_sk_list.lock);
76683 diff --git a/net/key/af_key.c b/net/key/af_key.c
76684 index 1e733e9..c84de2f 100644
76685 --- a/net/key/af_key.c
76686 +++ b/net/key/af_key.c
76687 @@ -2481,6 +2481,8 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
76688 struct xfrm_migrate m[XFRM_MAX_DEPTH];
76689 struct xfrm_kmaddress k;
76690
76691 + pax_track_stack();
76692 +
76693 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
76694 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
76695 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
76696 @@ -3016,10 +3018,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76697 static u32 get_acqseq(void)
76698 {
76699 u32 res;
76700 - static atomic_t acqseq;
76701 + static atomic_unchecked_t acqseq;
76702
76703 do {
76704 - res = atomic_inc_return(&acqseq);
76705 + res = atomic_inc_return_unchecked(&acqseq);
76706 } while (!res);
76707 return res;
76708 }
76709 diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
76710 index 956b7e4..f01d328 100644
76711 --- a/net/lapb/lapb_iface.c
76712 +++ b/net/lapb/lapb_iface.c
76713 @@ -158,7 +158,7 @@ int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks
76714 goto out;
76715
76716 lapb->dev = dev;
76717 - lapb->callbacks = *callbacks;
76718 + lapb->callbacks = callbacks;
76719
76720 __lapb_insert_cb(lapb);
76721
76722 @@ -380,32 +380,32 @@ int lapb_data_received(struct net_device *dev, struct sk_buff *skb)
76723
76724 void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
76725 {
76726 - if (lapb->callbacks.connect_confirmation)
76727 - lapb->callbacks.connect_confirmation(lapb->dev, reason);
76728 + if (lapb->callbacks->connect_confirmation)
76729 + lapb->callbacks->connect_confirmation(lapb->dev, reason);
76730 }
76731
76732 void lapb_connect_indication(struct lapb_cb *lapb, int reason)
76733 {
76734 - if (lapb->callbacks.connect_indication)
76735 - lapb->callbacks.connect_indication(lapb->dev, reason);
76736 + if (lapb->callbacks->connect_indication)
76737 + lapb->callbacks->connect_indication(lapb->dev, reason);
76738 }
76739
76740 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
76741 {
76742 - if (lapb->callbacks.disconnect_confirmation)
76743 - lapb->callbacks.disconnect_confirmation(lapb->dev, reason);
76744 + if (lapb->callbacks->disconnect_confirmation)
76745 + lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
76746 }
76747
76748 void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
76749 {
76750 - if (lapb->callbacks.disconnect_indication)
76751 - lapb->callbacks.disconnect_indication(lapb->dev, reason);
76752 + if (lapb->callbacks->disconnect_indication)
76753 + lapb->callbacks->disconnect_indication(lapb->dev, reason);
76754 }
76755
76756 int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
76757 {
76758 - if (lapb->callbacks.data_indication)
76759 - return lapb->callbacks.data_indication(lapb->dev, skb);
76760 + if (lapb->callbacks->data_indication)
76761 + return lapb->callbacks->data_indication(lapb->dev, skb);
76762
76763 kfree_skb(skb);
76764 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
76765 @@ -415,8 +415,8 @@ int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)
76766 {
76767 int used = 0;
76768
76769 - if (lapb->callbacks.data_transmit) {
76770 - lapb->callbacks.data_transmit(lapb->dev, skb);
76771 + if (lapb->callbacks->data_transmit) {
76772 + lapb->callbacks->data_transmit(lapb->dev, skb);
76773 used = 1;
76774 }
76775
76776 diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
76777 index a01d213..6a1f1ab 100644
76778 --- a/net/mac80211/debugfs_sta.c
76779 +++ b/net/mac80211/debugfs_sta.c
76780 @@ -140,6 +140,8 @@ static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
76781 struct tid_ampdu_rx *tid_rx;
76782 struct tid_ampdu_tx *tid_tx;
76783
76784 + pax_track_stack();
76785 +
76786 rcu_read_lock();
76787
76788 p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
76789 @@ -240,6 +242,8 @@ static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
76790 struct sta_info *sta = file->private_data;
76791 struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
76792
76793 + pax_track_stack();
76794 +
76795 p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
76796 htc->ht_supported ? "" : "not ");
76797 if (htc->ht_supported) {
76798 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76799 index 9fab144..7f0fc14 100644
76800 --- a/net/mac80211/ieee80211_i.h
76801 +++ b/net/mac80211/ieee80211_i.h
76802 @@ -27,6 +27,7 @@
76803 #include <net/ieee80211_radiotap.h>
76804 #include <net/cfg80211.h>
76805 #include <net/mac80211.h>
76806 +#include <asm/local.h>
76807 #include "key.h"
76808 #include "sta_info.h"
76809
76810 @@ -754,7 +755,7 @@ struct ieee80211_local {
76811 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76812 spinlock_t queue_stop_reason_lock;
76813
76814 - int open_count;
76815 + local_t open_count;
76816 int monitors, cooked_mntrs;
76817 /* number of interfaces with corresponding FIF_ flags */
76818 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76819 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76820 index 556e7e6..120dcaf 100644
76821 --- a/net/mac80211/iface.c
76822 +++ b/net/mac80211/iface.c
76823 @@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76824 break;
76825 }
76826
76827 - if (local->open_count == 0) {
76828 + if (local_read(&local->open_count) == 0) {
76829 res = drv_start(local);
76830 if (res)
76831 goto err_del_bss;
76832 @@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76833 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
76834
76835 if (!is_valid_ether_addr(dev->dev_addr)) {
76836 - if (!local->open_count)
76837 + if (!local_read(&local->open_count))
76838 drv_stop(local);
76839 return -EADDRNOTAVAIL;
76840 }
76841 @@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76842 mutex_unlock(&local->mtx);
76843
76844 if (coming_up)
76845 - local->open_count++;
76846 + local_inc(&local->open_count);
76847
76848 if (hw_reconf_flags) {
76849 ieee80211_hw_config(local, hw_reconf_flags);
76850 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76851 err_del_interface:
76852 drv_remove_interface(local, &sdata->vif);
76853 err_stop:
76854 - if (!local->open_count)
76855 + if (!local_read(&local->open_count))
76856 drv_stop(local);
76857 err_del_bss:
76858 sdata->bss = NULL;
76859 @@ -474,7 +474,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76860 }
76861
76862 if (going_down)
76863 - local->open_count--;
76864 + local_dec(&local->open_count);
76865
76866 switch (sdata->vif.type) {
76867 case NL80211_IFTYPE_AP_VLAN:
76868 @@ -533,7 +533,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76869
76870 ieee80211_recalc_ps(local, -1);
76871
76872 - if (local->open_count == 0) {
76873 + if (local_read(&local->open_count) == 0) {
76874 if (local->ops->napi_poll)
76875 napi_disable(&local->napi);
76876 ieee80211_clear_tx_pending(local);
76877 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76878 index 3d90dad..36884d5 100644
76879 --- a/net/mac80211/main.c
76880 +++ b/net/mac80211/main.c
76881 @@ -209,7 +209,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76882 local->hw.conf.power_level = power;
76883 }
76884
76885 - if (changed && local->open_count) {
76886 + if (changed && local_read(&local->open_count)) {
76887 ret = drv_config(local, changed);
76888 /*
76889 * Goal:
76890 diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
76891 index 0f48368..d48e688 100644
76892 --- a/net/mac80211/mlme.c
76893 +++ b/net/mac80211/mlme.c
76894 @@ -1464,6 +1464,8 @@ static bool ieee80211_assoc_success(struct ieee80211_work *wk,
76895 bool have_higher_than_11mbit = false;
76896 u16 ap_ht_cap_flags;
76897
76898 + pax_track_stack();
76899 +
76900 /* AssocResp and ReassocResp have identical structure */
76901
76902 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
76903 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76904 index 6326d34..7225f61 100644
76905 --- a/net/mac80211/pm.c
76906 +++ b/net/mac80211/pm.c
76907 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76908 struct ieee80211_sub_if_data *sdata;
76909 struct sta_info *sta;
76910
76911 - if (!local->open_count)
76912 + if (!local_read(&local->open_count))
76913 goto suspend;
76914
76915 ieee80211_scan_cancel(local);
76916 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76917 cancel_work_sync(&local->dynamic_ps_enable_work);
76918 del_timer_sync(&local->dynamic_ps_timer);
76919
76920 - local->wowlan = wowlan && local->open_count;
76921 + local->wowlan = wowlan && local_read(&local->open_count);
76922 if (local->wowlan) {
76923 int err = drv_suspend(local, wowlan);
76924 if (err < 0) {
76925 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76926 }
76927
76928 /* stop hardware - this must stop RX */
76929 - if (local->open_count)
76930 + if (local_read(&local->open_count))
76931 ieee80211_stop_device(local);
76932
76933 suspend:
76934 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76935 index 3d5a2cb..b17ad48 100644
76936 --- a/net/mac80211/rate.c
76937 +++ b/net/mac80211/rate.c
76938 @@ -371,7 +371,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76939
76940 ASSERT_RTNL();
76941
76942 - if (local->open_count)
76943 + if (local_read(&local->open_count))
76944 return -EBUSY;
76945
76946 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
76947 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
76948 index 4851e9e..d860e05 100644
76949 --- a/net/mac80211/rc80211_pid_debugfs.c
76950 +++ b/net/mac80211/rc80211_pid_debugfs.c
76951 @@ -192,7 +192,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
76952
76953 spin_unlock_irqrestore(&events->lock, status);
76954
76955 - if (copy_to_user(buf, pb, p))
76956 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
76957 return -EFAULT;
76958
76959 return p;
76960 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
76961 index fd031e8..84fbfcf 100644
76962 --- a/net/mac80211/util.c
76963 +++ b/net/mac80211/util.c
76964 @@ -1170,7 +1170,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
76965 drv_set_coverage_class(local, hw->wiphy->coverage_class);
76966
76967 /* everything else happens only if HW was up & running */
76968 - if (!local->open_count)
76969 + if (!local_read(&local->open_count))
76970 goto wake_up;
76971
76972 /*
76973 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
76974 index 32bff6d..d0cf986 100644
76975 --- a/net/netfilter/Kconfig
76976 +++ b/net/netfilter/Kconfig
76977 @@ -781,6 +781,16 @@ config NETFILTER_XT_MATCH_ESP
76978
76979 To compile it as a module, choose M here. If unsure, say N.
76980
76981 +config NETFILTER_XT_MATCH_GRADM
76982 + tristate '"gradm" match support'
76983 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
76984 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
76985 + ---help---
76986 + The gradm match allows to match on grsecurity RBAC being enabled.
76987 + It is useful when iptables rules are applied early on bootup to
76988 + prevent connections to the machine (except from a trusted host)
76989 + while the RBAC system is disabled.
76990 +
76991 config NETFILTER_XT_MATCH_HASHLIMIT
76992 tristate '"hashlimit" match support'
76993 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
76994 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
76995 index 1a02853..5d8c22e 100644
76996 --- a/net/netfilter/Makefile
76997 +++ b/net/netfilter/Makefile
76998 @@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
76999 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77000 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77001 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77002 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77003 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77004 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77005 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77006 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77007 index 12571fb..fb73976 100644
77008 --- a/net/netfilter/ipvs/ip_vs_conn.c
77009 +++ b/net/netfilter/ipvs/ip_vs_conn.c
77010 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77011 /* Increase the refcnt counter of the dest */
77012 atomic_inc(&dest->refcnt);
77013
77014 - conn_flags = atomic_read(&dest->conn_flags);
77015 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77016 if (cp->protocol != IPPROTO_UDP)
77017 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77018 /* Bind with the destination and its corresponding transmitter */
77019 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77020 atomic_set(&cp->refcnt, 1);
77021
77022 atomic_set(&cp->n_control, 0);
77023 - atomic_set(&cp->in_pkts, 0);
77024 + atomic_set_unchecked(&cp->in_pkts, 0);
77025
77026 atomic_inc(&ipvs->conn_count);
77027 if (flags & IP_VS_CONN_F_NO_CPORT)
77028 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77029
77030 /* Don't drop the entry if its number of incoming packets is not
77031 located in [0, 8] */
77032 - i = atomic_read(&cp->in_pkts);
77033 + i = atomic_read_unchecked(&cp->in_pkts);
77034 if (i > 8 || i < 0) return 0;
77035
77036 if (!todrop_rate[i]) return 0;
77037 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77038 index 4f77bb1..5d0bc26 100644
77039 --- a/net/netfilter/ipvs/ip_vs_core.c
77040 +++ b/net/netfilter/ipvs/ip_vs_core.c
77041 @@ -563,7 +563,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77042 ret = cp->packet_xmit(skb, cp, pd->pp);
77043 /* do not touch skb anymore */
77044
77045 - atomic_inc(&cp->in_pkts);
77046 + atomic_inc_unchecked(&cp->in_pkts);
77047 ip_vs_conn_put(cp);
77048 return ret;
77049 }
77050 @@ -1612,7 +1612,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77051 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77052 pkts = sysctl_sync_threshold(ipvs);
77053 else
77054 - pkts = atomic_add_return(1, &cp->in_pkts);
77055 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77056
77057 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
77058 cp->protocol == IPPROTO_SCTP) {
77059 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77060 index e3be48b..d658c8c 100644
77061 --- a/net/netfilter/ipvs/ip_vs_ctl.c
77062 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
77063 @@ -782,7 +782,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77064 ip_vs_rs_hash(ipvs, dest);
77065 write_unlock_bh(&ipvs->rs_lock);
77066 }
77067 - atomic_set(&dest->conn_flags, conn_flags);
77068 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77069
77070 /* bind the service */
77071 if (!dest->svc) {
77072 @@ -2027,7 +2027,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77073 " %-7s %-6d %-10d %-10d\n",
77074 &dest->addr.in6,
77075 ntohs(dest->port),
77076 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77077 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77078 atomic_read(&dest->weight),
77079 atomic_read(&dest->activeconns),
77080 atomic_read(&dest->inactconns));
77081 @@ -2038,7 +2038,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77082 "%-7s %-6d %-10d %-10d\n",
77083 ntohl(dest->addr.ip),
77084 ntohs(dest->port),
77085 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77086 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77087 atomic_read(&dest->weight),
77088 atomic_read(&dest->activeconns),
77089 atomic_read(&dest->inactconns));
77090 @@ -2285,6 +2285,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
77091 struct ip_vs_dest_user_kern udest;
77092 struct netns_ipvs *ipvs = net_ipvs(net);
77093
77094 + pax_track_stack();
77095 +
77096 if (!capable(CAP_NET_ADMIN))
77097 return -EPERM;
77098
77099 @@ -2508,7 +2510,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77100
77101 entry.addr = dest->addr.ip;
77102 entry.port = dest->port;
77103 - entry.conn_flags = atomic_read(&dest->conn_flags);
77104 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77105 entry.weight = atomic_read(&dest->weight);
77106 entry.u_threshold = dest->u_threshold;
77107 entry.l_threshold = dest->l_threshold;
77108 @@ -3041,7 +3043,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77109 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
77110
77111 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77112 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77113 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77114 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
77115 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
77116 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
77117 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77118 index 3cdd479..116afa8 100644
77119 --- a/net/netfilter/ipvs/ip_vs_sync.c
77120 +++ b/net/netfilter/ipvs/ip_vs_sync.c
77121 @@ -649,7 +649,7 @@ control:
77122 * i.e only increment in_pkts for Templates.
77123 */
77124 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
77125 - int pkts = atomic_add_return(1, &cp->in_pkts);
77126 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77127
77128 if (pkts % sysctl_sync_period(ipvs) != 1)
77129 return;
77130 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77131
77132 if (opt)
77133 memcpy(&cp->in_seq, opt, sizeof(*opt));
77134 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77135 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77136 cp->state = state;
77137 cp->old_state = cp->state;
77138 /*
77139 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77140 index ee319a4..8a285ee 100644
77141 --- a/net/netfilter/ipvs/ip_vs_xmit.c
77142 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
77143 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77144 else
77145 rc = NF_ACCEPT;
77146 /* do not touch skb anymore */
77147 - atomic_inc(&cp->in_pkts);
77148 + atomic_inc_unchecked(&cp->in_pkts);
77149 goto out;
77150 }
77151
77152 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77153 else
77154 rc = NF_ACCEPT;
77155 /* do not touch skb anymore */
77156 - atomic_inc(&cp->in_pkts);
77157 + atomic_inc_unchecked(&cp->in_pkts);
77158 goto out;
77159 }
77160
77161 diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
77162 index 7dec88a..0996ce3 100644
77163 --- a/net/netfilter/nf_conntrack_netlink.c
77164 +++ b/net/netfilter/nf_conntrack_netlink.c
77165 @@ -135,7 +135,7 @@ nla_put_failure:
77166 static inline int
77167 ctnetlink_dump_timeout(struct sk_buff *skb, const struct nf_conn *ct)
77168 {
77169 - long timeout = (ct->timeout.expires - jiffies) / HZ;
77170 + long timeout = ((long)ct->timeout.expires - (long)jiffies) / HZ;
77171
77172 if (timeout < 0)
77173 timeout = 0;
77174 @@ -1638,7 +1638,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,
77175 const struct nf_conntrack_expect *exp)
77176 {
77177 struct nf_conn *master = exp->master;
77178 - long timeout = (exp->timeout.expires - jiffies) / HZ;
77179 + long timeout = ((long)exp->timeout.expires - (long)jiffies) / HZ;
77180 struct nf_conn_help *help;
77181
77182 if (timeout < 0)
77183 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77184 index 2d8158a..5dca296 100644
77185 --- a/net/netfilter/nfnetlink_log.c
77186 +++ b/net/netfilter/nfnetlink_log.c
77187 @@ -70,7 +70,7 @@ struct nfulnl_instance {
77188 };
77189
77190 static DEFINE_SPINLOCK(instances_lock);
77191 -static atomic_t global_seq;
77192 +static atomic_unchecked_t global_seq;
77193
77194 #define INSTANCE_BUCKETS 16
77195 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77196 @@ -505,7 +505,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77197 /* global sequence number */
77198 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
77199 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
77200 - htonl(atomic_inc_return(&global_seq)));
77201 + htonl(atomic_inc_return_unchecked(&global_seq)));
77202
77203 if (data_len) {
77204 struct nlattr *nla;
77205 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77206 new file mode 100644
77207 index 0000000..6905327
77208 --- /dev/null
77209 +++ b/net/netfilter/xt_gradm.c
77210 @@ -0,0 +1,51 @@
77211 +/*
77212 + * gradm match for netfilter
77213 + * Copyright © Zbigniew Krzystolik, 2010
77214 + *
77215 + * This program is free software; you can redistribute it and/or modify
77216 + * it under the terms of the GNU General Public License; either version
77217 + * 2 or 3 as published by the Free Software Foundation.
77218 + */
77219 +#include <linux/module.h>
77220 +#include <linux/moduleparam.h>
77221 +#include <linux/skbuff.h>
77222 +#include <linux/netfilter/x_tables.h>
77223 +#include <linux/grsecurity.h>
77224 +#include <linux/netfilter/xt_gradm.h>
77225 +
77226 +static bool
77227 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
77228 +{
77229 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77230 + bool retval = false;
77231 + if (gr_acl_is_enabled())
77232 + retval = true;
77233 + return retval ^ info->invflags;
77234 +}
77235 +
77236 +static struct xt_match gradm_mt_reg __read_mostly = {
77237 + .name = "gradm",
77238 + .revision = 0,
77239 + .family = NFPROTO_UNSPEC,
77240 + .match = gradm_mt,
77241 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77242 + .me = THIS_MODULE,
77243 +};
77244 +
77245 +static int __init gradm_mt_init(void)
77246 +{
77247 + return xt_register_match(&gradm_mt_reg);
77248 +}
77249 +
77250 +static void __exit gradm_mt_exit(void)
77251 +{
77252 + xt_unregister_match(&gradm_mt_reg);
77253 +}
77254 +
77255 +module_init(gradm_mt_init);
77256 +module_exit(gradm_mt_exit);
77257 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77258 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77259 +MODULE_LICENSE("GPL");
77260 +MODULE_ALIAS("ipt_gradm");
77261 +MODULE_ALIAS("ip6t_gradm");
77262 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
77263 index 42ecb71..8d687c0 100644
77264 --- a/net/netfilter/xt_statistic.c
77265 +++ b/net/netfilter/xt_statistic.c
77266 @@ -18,7 +18,7 @@
77267 #include <linux/netfilter/x_tables.h>
77268
77269 struct xt_statistic_priv {
77270 - atomic_t count;
77271 + atomic_unchecked_t count;
77272 } ____cacheline_aligned_in_smp;
77273
77274 MODULE_LICENSE("GPL");
77275 @@ -41,9 +41,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
77276 break;
77277 case XT_STATISTIC_MODE_NTH:
77278 do {
77279 - oval = atomic_read(&info->master->count);
77280 + oval = atomic_read_unchecked(&info->master->count);
77281 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77282 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77283 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77284 if (nval == 0)
77285 ret = !ret;
77286 break;
77287 @@ -63,7 +63,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
77288 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77289 if (info->master == NULL)
77290 return -ENOMEM;
77291 - atomic_set(&info->master->count, info->u.nth.count);
77292 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77293
77294 return 0;
77295 }
77296 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
77297 index 0a4db02..604f748 100644
77298 --- a/net/netlink/af_netlink.c
77299 +++ b/net/netlink/af_netlink.c
77300 @@ -742,7 +742,7 @@ static void netlink_overrun(struct sock *sk)
77301 sk->sk_error_report(sk);
77302 }
77303 }
77304 - atomic_inc(&sk->sk_drops);
77305 + atomic_inc_unchecked(&sk->sk_drops);
77306 }
77307
77308 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77309 @@ -2000,7 +2000,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
77310 sk_wmem_alloc_get(s),
77311 nlk->cb,
77312 atomic_read(&s->sk_refcnt),
77313 - atomic_read(&s->sk_drops),
77314 + atomic_read_unchecked(&s->sk_drops),
77315 sock_i_ino(s)
77316 );
77317
77318 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77319 index 732152f..60bb09e 100644
77320 --- a/net/netrom/af_netrom.c
77321 +++ b/net/netrom/af_netrom.c
77322 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77323 struct sock *sk = sock->sk;
77324 struct nr_sock *nr = nr_sk(sk);
77325
77326 + memset(sax, 0, sizeof(*sax));
77327 lock_sock(sk);
77328 if (peer != 0) {
77329 if (sk->sk_state != TCP_ESTABLISHED) {
77330 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77331 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77332 } else {
77333 sax->fsa_ax25.sax25_family = AF_NETROM;
77334 - sax->fsa_ax25.sax25_ndigis = 0;
77335 sax->fsa_ax25.sax25_call = nr->source_addr;
77336 *uaddr_len = sizeof(struct sockaddr_ax25);
77337 }
77338 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77339 index fabb4fa..37aaea0 100644
77340 --- a/net/packet/af_packet.c
77341 +++ b/net/packet/af_packet.c
77342 @@ -954,7 +954,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77343
77344 spin_lock(&sk->sk_receive_queue.lock);
77345 po->stats.tp_packets++;
77346 - skb->dropcount = atomic_read(&sk->sk_drops);
77347 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77348 __skb_queue_tail(&sk->sk_receive_queue, skb);
77349 spin_unlock(&sk->sk_receive_queue.lock);
77350 sk->sk_data_ready(sk, skb->len);
77351 @@ -963,7 +963,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77352 drop_n_acct:
77353 spin_lock(&sk->sk_receive_queue.lock);
77354 po->stats.tp_drops++;
77355 - atomic_inc(&sk->sk_drops);
77356 + atomic_inc_unchecked(&sk->sk_drops);
77357 spin_unlock(&sk->sk_receive_queue.lock);
77358
77359 drop_n_restore:
77360 @@ -1691,8 +1691,12 @@ static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 protoc
77361 {
77362 struct packet_sock *po = pkt_sk(sk);
77363
77364 - if (po->fanout)
77365 + if (po->fanout) {
77366 + if (dev)
77367 + dev_put(dev);
77368 +
77369 return -EINVAL;
77370 + }
77371
77372 lock_sock(sk);
77373
77374 @@ -2479,7 +2483,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77375 case PACKET_HDRLEN:
77376 if (len > sizeof(int))
77377 len = sizeof(int);
77378 - if (copy_from_user(&val, optval, len))
77379 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77380 return -EFAULT;
77381 switch (val) {
77382 case TPACKET_V1:
77383 @@ -2526,7 +2530,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77384
77385 if (put_user(len, optlen))
77386 return -EFAULT;
77387 - if (copy_to_user(optval, data, len))
77388 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77389 return -EFAULT;
77390 return 0;
77391 }
77392 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77393 index c6fffd9..a7ffa0c 100644
77394 --- a/net/phonet/af_phonet.c
77395 +++ b/net/phonet/af_phonet.c
77396 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77397 {
77398 struct phonet_protocol *pp;
77399
77400 - if (protocol >= PHONET_NPROTO)
77401 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77402 return NULL;
77403
77404 rcu_read_lock();
77405 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77406 {
77407 int err = 0;
77408
77409 - if (protocol >= PHONET_NPROTO)
77410 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77411 return -EINVAL;
77412
77413 err = proto_register(pp->prot, 1);
77414 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77415 index f17fd84..edffce8 100644
77416 --- a/net/phonet/pep.c
77417 +++ b/net/phonet/pep.c
77418 @@ -387,7 +387,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77419
77420 case PNS_PEP_CTRL_REQ:
77421 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77422 - atomic_inc(&sk->sk_drops);
77423 + atomic_inc_unchecked(&sk->sk_drops);
77424 break;
77425 }
77426 __skb_pull(skb, 4);
77427 @@ -408,7 +408,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77428 }
77429
77430 if (pn->rx_credits == 0) {
77431 - atomic_inc(&sk->sk_drops);
77432 + atomic_inc_unchecked(&sk->sk_drops);
77433 err = -ENOBUFS;
77434 break;
77435 }
77436 @@ -556,7 +556,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77437 }
77438
77439 if (pn->rx_credits == 0) {
77440 - atomic_inc(&sk->sk_drops);
77441 + atomic_inc_unchecked(&sk->sk_drops);
77442 err = NET_RX_DROP;
77443 break;
77444 }
77445 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77446 index ab07711..9d4ac5d 100644
77447 --- a/net/phonet/socket.c
77448 +++ b/net/phonet/socket.c
77449 @@ -612,8 +612,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77450 pn->resource, sk->sk_state,
77451 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77452 sock_i_uid(sk), sock_i_ino(sk),
77453 - atomic_read(&sk->sk_refcnt), sk,
77454 - atomic_read(&sk->sk_drops), &len);
77455 + atomic_read(&sk->sk_refcnt),
77456 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77457 + NULL,
77458 +#else
77459 + sk,
77460 +#endif
77461 + atomic_read_unchecked(&sk->sk_drops), &len);
77462 }
77463 seq_printf(seq, "%*s\n", 127 - len, "");
77464 return 0;
77465 diff --git a/net/rds/cong.c b/net/rds/cong.c
77466 index 6daaa49..fbf6af5 100644
77467 --- a/net/rds/cong.c
77468 +++ b/net/rds/cong.c
77469 @@ -77,7 +77,7 @@
77470 * finds that the saved generation number is smaller than the global generation
77471 * number, it wakes up the process.
77472 */
77473 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77474 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77475
77476 /*
77477 * Congestion monitoring
77478 @@ -232,7 +232,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
77479 rdsdebug("waking map %p for %pI4\n",
77480 map, &map->m_addr);
77481 rds_stats_inc(s_cong_update_received);
77482 - atomic_inc(&rds_cong_generation);
77483 + atomic_inc_unchecked(&rds_cong_generation);
77484 if (waitqueue_active(&map->m_waitq))
77485 wake_up(&map->m_waitq);
77486 if (waitqueue_active(&rds_poll_waitq))
77487 @@ -258,7 +258,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77488
77489 int rds_cong_updated_since(unsigned long *recent)
77490 {
77491 - unsigned long gen = atomic_read(&rds_cong_generation);
77492 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77493
77494 if (likely(*recent == gen))
77495 return 0;
77496 diff --git a/net/rds/ib.h b/net/rds/ib.h
77497 index edfaaaf..8c89879 100644
77498 --- a/net/rds/ib.h
77499 +++ b/net/rds/ib.h
77500 @@ -128,7 +128,7 @@ struct rds_ib_connection {
77501 /* sending acks */
77502 unsigned long i_ack_flags;
77503 #ifdef KERNEL_HAS_ATOMIC64
77504 - atomic64_t i_ack_next; /* next ACK to send */
77505 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77506 #else
77507 spinlock_t i_ack_lock; /* protect i_ack_next */
77508 u64 i_ack_next; /* next ACK to send */
77509 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
77510 index cd67026..0b9a54a 100644
77511 --- a/net/rds/ib_cm.c
77512 +++ b/net/rds/ib_cm.c
77513 @@ -720,7 +720,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
77514 /* Clear the ACK state */
77515 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77516 #ifdef KERNEL_HAS_ATOMIC64
77517 - atomic64_set(&ic->i_ack_next, 0);
77518 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77519 #else
77520 ic->i_ack_next = 0;
77521 #endif
77522 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
77523 index e29e0ca..fa3a6a3 100644
77524 --- a/net/rds/ib_recv.c
77525 +++ b/net/rds/ib_recv.c
77526 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77527 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77528 int ack_required)
77529 {
77530 - atomic64_set(&ic->i_ack_next, seq);
77531 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77532 if (ack_required) {
77533 smp_mb__before_clear_bit();
77534 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77535 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77536 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77537 smp_mb__after_clear_bit();
77538
77539 - return atomic64_read(&ic->i_ack_next);
77540 + return atomic64_read_unchecked(&ic->i_ack_next);
77541 }
77542 #endif
77543
77544 diff --git a/net/rds/iw.h b/net/rds/iw.h
77545 index 04ce3b1..48119a6 100644
77546 --- a/net/rds/iw.h
77547 +++ b/net/rds/iw.h
77548 @@ -134,7 +134,7 @@ struct rds_iw_connection {
77549 /* sending acks */
77550 unsigned long i_ack_flags;
77551 #ifdef KERNEL_HAS_ATOMIC64
77552 - atomic64_t i_ack_next; /* next ACK to send */
77553 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77554 #else
77555 spinlock_t i_ack_lock; /* protect i_ack_next */
77556 u64 i_ack_next; /* next ACK to send */
77557 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
77558 index 9556d28..f046d0e 100644
77559 --- a/net/rds/iw_cm.c
77560 +++ b/net/rds/iw_cm.c
77561 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
77562 /* Clear the ACK state */
77563 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77564 #ifdef KERNEL_HAS_ATOMIC64
77565 - atomic64_set(&ic->i_ack_next, 0);
77566 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77567 #else
77568 ic->i_ack_next = 0;
77569 #endif
77570 diff --git a/net/rds/iw_rdma.c b/net/rds/iw_rdma.c
77571 index 4e1de17..d121708 100644
77572 --- a/net/rds/iw_rdma.c
77573 +++ b/net/rds/iw_rdma.c
77574 @@ -184,6 +184,8 @@ int rds_iw_update_cm_id(struct rds_iw_device *rds_iwdev, struct rdma_cm_id *cm_i
77575 struct rdma_cm_id *pcm_id;
77576 int rc;
77577
77578 + pax_track_stack();
77579 +
77580 src_addr = (struct sockaddr_in *)&cm_id->route.addr.src_addr;
77581 dst_addr = (struct sockaddr_in *)&cm_id->route.addr.dst_addr;
77582
77583 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
77584 index 5e57347..3916042 100644
77585 --- a/net/rds/iw_recv.c
77586 +++ b/net/rds/iw_recv.c
77587 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77588 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77589 int ack_required)
77590 {
77591 - atomic64_set(&ic->i_ack_next, seq);
77592 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77593 if (ack_required) {
77594 smp_mb__before_clear_bit();
77595 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77596 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77597 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77598 smp_mb__after_clear_bit();
77599
77600 - return atomic64_read(&ic->i_ack_next);
77601 + return atomic64_read_unchecked(&ic->i_ack_next);
77602 }
77603 #endif
77604
77605 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
77606 index 8e0a320..ee8e38f 100644
77607 --- a/net/rds/tcp.c
77608 +++ b/net/rds/tcp.c
77609 @@ -58,7 +58,7 @@ void rds_tcp_nonagle(struct socket *sock)
77610 int val = 1;
77611
77612 set_fs(KERNEL_DS);
77613 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77614 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77615 sizeof(val));
77616 set_fs(oldfs);
77617 }
77618 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
77619 index 1b4fd68..2234175 100644
77620 --- a/net/rds/tcp_send.c
77621 +++ b/net/rds/tcp_send.c
77622 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
77623
77624 oldfs = get_fs();
77625 set_fs(KERNEL_DS);
77626 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77627 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77628 sizeof(val));
77629 set_fs(oldfs);
77630 }
77631 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
77632 index 74c064c..fdec26f 100644
77633 --- a/net/rxrpc/af_rxrpc.c
77634 +++ b/net/rxrpc/af_rxrpc.c
77635 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
77636 __be32 rxrpc_epoch;
77637
77638 /* current debugging ID */
77639 -atomic_t rxrpc_debug_id;
77640 +atomic_unchecked_t rxrpc_debug_id;
77641
77642 /* count of skbs currently in use */
77643 atomic_t rxrpc_n_skbs;
77644 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
77645 index f99cfce..3682692 100644
77646 --- a/net/rxrpc/ar-ack.c
77647 +++ b/net/rxrpc/ar-ack.c
77648 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77649
77650 _enter("{%d,%d,%d,%d},",
77651 call->acks_hard, call->acks_unacked,
77652 - atomic_read(&call->sequence),
77653 + atomic_read_unchecked(&call->sequence),
77654 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77655
77656 stop = 0;
77657 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77658
77659 /* each Tx packet has a new serial number */
77660 sp->hdr.serial =
77661 - htonl(atomic_inc_return(&call->conn->serial));
77662 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77663
77664 hdr = (struct rxrpc_header *) txb->head;
77665 hdr->serial = sp->hdr.serial;
77666 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
77667 */
77668 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77669 {
77670 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77671 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77672 }
77673
77674 /*
77675 @@ -629,7 +629,7 @@ process_further:
77676
77677 latest = ntohl(sp->hdr.serial);
77678 hard = ntohl(ack.firstPacket);
77679 - tx = atomic_read(&call->sequence);
77680 + tx = atomic_read_unchecked(&call->sequence);
77681
77682 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77683 latest,
77684 @@ -842,6 +842,8 @@ void rxrpc_process_call(struct work_struct *work)
77685 u32 abort_code = RX_PROTOCOL_ERROR;
77686 u8 *acks = NULL;
77687
77688 + pax_track_stack();
77689 +
77690 //printk("\n--------------------\n");
77691 _enter("{%d,%s,%lx} [%lu]",
77692 call->debug_id, rxrpc_call_states[call->state], call->events,
77693 @@ -1161,7 +1163,7 @@ void rxrpc_process_call(struct work_struct *work)
77694 goto maybe_reschedule;
77695
77696 send_ACK_with_skew:
77697 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77698 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77699 ntohl(ack.serial));
77700 send_ACK:
77701 mtu = call->conn->trans->peer->if_mtu;
77702 @@ -1173,7 +1175,7 @@ send_ACK:
77703 ackinfo.rxMTU = htonl(5692);
77704 ackinfo.jumbo_max = htonl(4);
77705
77706 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77707 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77708 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77709 ntohl(hdr.serial),
77710 ntohs(ack.maxSkew),
77711 @@ -1191,7 +1193,7 @@ send_ACK:
77712 send_message:
77713 _debug("send message");
77714
77715 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77716 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77717 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
77718 send_message_2:
77719
77720 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
77721 index bf656c2..48f9d27 100644
77722 --- a/net/rxrpc/ar-call.c
77723 +++ b/net/rxrpc/ar-call.c
77724 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
77725 spin_lock_init(&call->lock);
77726 rwlock_init(&call->state_lock);
77727 atomic_set(&call->usage, 1);
77728 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
77729 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77730 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
77731
77732 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
77733 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
77734 index 4106ca9..a338d7a 100644
77735 --- a/net/rxrpc/ar-connection.c
77736 +++ b/net/rxrpc/ar-connection.c
77737 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
77738 rwlock_init(&conn->lock);
77739 spin_lock_init(&conn->state_lock);
77740 atomic_set(&conn->usage, 1);
77741 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
77742 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77743 conn->avail_calls = RXRPC_MAXCALLS;
77744 conn->size_align = 4;
77745 conn->header_size = sizeof(struct rxrpc_header);
77746 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
77747 index e7ed43a..6afa140 100644
77748 --- a/net/rxrpc/ar-connevent.c
77749 +++ b/net/rxrpc/ar-connevent.c
77750 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
77751
77752 len = iov[0].iov_len + iov[1].iov_len;
77753
77754 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77755 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77756 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
77757
77758 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77759 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
77760 index 1a2b0633..e8d1382 100644
77761 --- a/net/rxrpc/ar-input.c
77762 +++ b/net/rxrpc/ar-input.c
77763 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
77764 /* track the latest serial number on this connection for ACK packet
77765 * information */
77766 serial = ntohl(sp->hdr.serial);
77767 - hi_serial = atomic_read(&call->conn->hi_serial);
77768 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
77769 while (serial > hi_serial)
77770 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
77771 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
77772 serial);
77773
77774 /* request ACK generation for any ACK or DATA packet that requests
77775 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
77776 index 8e22bd3..f66d1c0 100644
77777 --- a/net/rxrpc/ar-internal.h
77778 +++ b/net/rxrpc/ar-internal.h
77779 @@ -272,8 +272,8 @@ struct rxrpc_connection {
77780 int error; /* error code for local abort */
77781 int debug_id; /* debug ID for printks */
77782 unsigned call_counter; /* call ID counter */
77783 - atomic_t serial; /* packet serial number counter */
77784 - atomic_t hi_serial; /* highest serial number received */
77785 + atomic_unchecked_t serial; /* packet serial number counter */
77786 + atomic_unchecked_t hi_serial; /* highest serial number received */
77787 u8 avail_calls; /* number of calls available */
77788 u8 size_align; /* data size alignment (for security) */
77789 u8 header_size; /* rxrpc + security header size */
77790 @@ -346,7 +346,7 @@ struct rxrpc_call {
77791 spinlock_t lock;
77792 rwlock_t state_lock; /* lock for state transition */
77793 atomic_t usage;
77794 - atomic_t sequence; /* Tx data packet sequence counter */
77795 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
77796 u32 abort_code; /* local/remote abort code */
77797 enum { /* current state of call */
77798 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
77799 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
77800 */
77801 extern atomic_t rxrpc_n_skbs;
77802 extern __be32 rxrpc_epoch;
77803 -extern atomic_t rxrpc_debug_id;
77804 +extern atomic_unchecked_t rxrpc_debug_id;
77805 extern struct workqueue_struct *rxrpc_workqueue;
77806
77807 /*
77808 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
77809 index 87f7135..74d3703 100644
77810 --- a/net/rxrpc/ar-local.c
77811 +++ b/net/rxrpc/ar-local.c
77812 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
77813 spin_lock_init(&local->lock);
77814 rwlock_init(&local->services_lock);
77815 atomic_set(&local->usage, 1);
77816 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
77817 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77818 memcpy(&local->srx, srx, sizeof(*srx));
77819 }
77820
77821 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
77822 index 5f22e26..e5bd20f 100644
77823 --- a/net/rxrpc/ar-output.c
77824 +++ b/net/rxrpc/ar-output.c
77825 @@ -681,9 +681,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
77826 sp->hdr.cid = call->cid;
77827 sp->hdr.callNumber = call->call_id;
77828 sp->hdr.seq =
77829 - htonl(atomic_inc_return(&call->sequence));
77830 + htonl(atomic_inc_return_unchecked(&call->sequence));
77831 sp->hdr.serial =
77832 - htonl(atomic_inc_return(&conn->serial));
77833 + htonl(atomic_inc_return_unchecked(&conn->serial));
77834 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
77835 sp->hdr.userStatus = 0;
77836 sp->hdr.securityIndex = conn->security_ix;
77837 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
77838 index 2754f09..b20e38f 100644
77839 --- a/net/rxrpc/ar-peer.c
77840 +++ b/net/rxrpc/ar-peer.c
77841 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
77842 INIT_LIST_HEAD(&peer->error_targets);
77843 spin_lock_init(&peer->lock);
77844 atomic_set(&peer->usage, 1);
77845 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
77846 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77847 memcpy(&peer->srx, srx, sizeof(*srx));
77848
77849 rxrpc_assess_MTU_size(peer);
77850 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
77851 index 38047f7..9f48511 100644
77852 --- a/net/rxrpc/ar-proc.c
77853 +++ b/net/rxrpc/ar-proc.c
77854 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
77855 atomic_read(&conn->usage),
77856 rxrpc_conn_states[conn->state],
77857 key_serial(conn->key),
77858 - atomic_read(&conn->serial),
77859 - atomic_read(&conn->hi_serial));
77860 + atomic_read_unchecked(&conn->serial),
77861 + atomic_read_unchecked(&conn->hi_serial));
77862
77863 return 0;
77864 }
77865 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
77866 index 92df566..87ec1bf 100644
77867 --- a/net/rxrpc/ar-transport.c
77868 +++ b/net/rxrpc/ar-transport.c
77869 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
77870 spin_lock_init(&trans->client_lock);
77871 rwlock_init(&trans->conn_lock);
77872 atomic_set(&trans->usage, 1);
77873 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
77874 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77875
77876 if (peer->srx.transport.family == AF_INET) {
77877 switch (peer->srx.transport_type) {
77878 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
77879 index 7635107..5000b71 100644
77880 --- a/net/rxrpc/rxkad.c
77881 +++ b/net/rxrpc/rxkad.c
77882 @@ -211,6 +211,8 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
77883 u16 check;
77884 int nsg;
77885
77886 + pax_track_stack();
77887 +
77888 sp = rxrpc_skb(skb);
77889
77890 _enter("");
77891 @@ -338,6 +340,8 @@ static int rxkad_verify_packet_auth(const struct rxrpc_call *call,
77892 u16 check;
77893 int nsg;
77894
77895 + pax_track_stack();
77896 +
77897 _enter("");
77898
77899 sp = rxrpc_skb(skb);
77900 @@ -610,7 +614,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
77901
77902 len = iov[0].iov_len + iov[1].iov_len;
77903
77904 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77905 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77906 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
77907
77908 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77909 @@ -660,7 +664,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
77910
77911 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
77912
77913 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
77914 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77915 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
77916
77917 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
77918 diff --git a/net/sctp/auth.c b/net/sctp/auth.c
77919 index 865e68f..bf81204 100644
77920 --- a/net/sctp/auth.c
77921 +++ b/net/sctp/auth.c
77922 @@ -82,7 +82,7 @@ static struct sctp_auth_bytes *sctp_auth_create_key(__u32 key_len, gfp_t gfp)
77923 struct sctp_auth_bytes *key;
77924
77925 /* Verify that we are not going to overflow INT_MAX */
77926 - if ((INT_MAX - key_len) < sizeof(struct sctp_auth_bytes))
77927 + if (key_len > (INT_MAX - sizeof(struct sctp_auth_bytes)))
77928 return NULL;
77929
77930 /* Allocate the shared key */
77931 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
77932 index 05a6ce2..c8bf836 100644
77933 --- a/net/sctp/proc.c
77934 +++ b/net/sctp/proc.c
77935 @@ -318,7 +318,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
77936 seq_printf(seq,
77937 "%8pK %8pK %-3d %-3d %-2d %-4d "
77938 "%4d %8d %8d %7d %5lu %-5d %5d ",
77939 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
77940 + assoc, sk,
77941 + sctp_sk(sk)->type, sk->sk_state,
77942 assoc->state, hash,
77943 assoc->assoc_id,
77944 assoc->sndbuf_used,
77945 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
77946 index 4760f4e..e44d3fb 100644
77947 --- a/net/sctp/socket.c
77948 +++ b/net/sctp/socket.c
77949 @@ -4573,7 +4573,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
77950 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
77951 if (space_left < addrlen)
77952 return -ENOMEM;
77953 - if (copy_to_user(to, &temp, addrlen))
77954 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
77955 return -EFAULT;
77956 to += addrlen;
77957 cnt++;
77958 diff --git a/net/socket.c b/net/socket.c
77959 index ffe92ca..8057b85 100644
77960 --- a/net/socket.c
77961 +++ b/net/socket.c
77962 @@ -88,6 +88,7 @@
77963 #include <linux/nsproxy.h>
77964 #include <linux/magic.h>
77965 #include <linux/slab.h>
77966 +#include <linux/in.h>
77967
77968 #include <asm/uaccess.h>
77969 #include <asm/unistd.h>
77970 @@ -105,6 +106,8 @@
77971 #include <linux/sockios.h>
77972 #include <linux/atalk.h>
77973
77974 +#include <linux/grsock.h>
77975 +
77976 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
77977 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
77978 unsigned long nr_segs, loff_t pos);
77979 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
77980 &sockfs_dentry_operations, SOCKFS_MAGIC);
77981 }
77982
77983 -static struct vfsmount *sock_mnt __read_mostly;
77984 +struct vfsmount *sock_mnt __read_mostly;
77985
77986 static struct file_system_type sock_fs_type = {
77987 .name = "sockfs",
77988 @@ -1187,6 +1190,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
77989 return -EAFNOSUPPORT;
77990 if (type < 0 || type >= SOCK_MAX)
77991 return -EINVAL;
77992 + if (protocol < 0)
77993 + return -EINVAL;
77994
77995 /* Compatibility.
77996
77997 @@ -1319,6 +1324,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
77998 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
77999 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78000
78001 + if(!gr_search_socket(family, type, protocol)) {
78002 + retval = -EACCES;
78003 + goto out;
78004 + }
78005 +
78006 + if (gr_handle_sock_all(family, type, protocol)) {
78007 + retval = -EACCES;
78008 + goto out;
78009 + }
78010 +
78011 retval = sock_create(family, type, protocol, &sock);
78012 if (retval < 0)
78013 goto out;
78014 @@ -1431,6 +1446,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78015 if (sock) {
78016 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
78017 if (err >= 0) {
78018 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78019 + err = -EACCES;
78020 + goto error;
78021 + }
78022 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78023 + if (err)
78024 + goto error;
78025 +
78026 err = security_socket_bind(sock,
78027 (struct sockaddr *)&address,
78028 addrlen);
78029 @@ -1439,6 +1462,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78030 (struct sockaddr *)
78031 &address, addrlen);
78032 }
78033 +error:
78034 fput_light(sock->file, fput_needed);
78035 }
78036 return err;
78037 @@ -1462,10 +1486,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
78038 if ((unsigned)backlog > somaxconn)
78039 backlog = somaxconn;
78040
78041 + if (gr_handle_sock_server_other(sock->sk)) {
78042 + err = -EPERM;
78043 + goto error;
78044 + }
78045 +
78046 + err = gr_search_listen(sock);
78047 + if (err)
78048 + goto error;
78049 +
78050 err = security_socket_listen(sock, backlog);
78051 if (!err)
78052 err = sock->ops->listen(sock, backlog);
78053
78054 +error:
78055 fput_light(sock->file, fput_needed);
78056 }
78057 return err;
78058 @@ -1509,6 +1543,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78059 newsock->type = sock->type;
78060 newsock->ops = sock->ops;
78061
78062 + if (gr_handle_sock_server_other(sock->sk)) {
78063 + err = -EPERM;
78064 + sock_release(newsock);
78065 + goto out_put;
78066 + }
78067 +
78068 + err = gr_search_accept(sock);
78069 + if (err) {
78070 + sock_release(newsock);
78071 + goto out_put;
78072 + }
78073 +
78074 /*
78075 * We don't need try_module_get here, as the listening socket (sock)
78076 * has the protocol module (sock->ops->owner) held.
78077 @@ -1547,6 +1593,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78078 fd_install(newfd, newfile);
78079 err = newfd;
78080
78081 + gr_attach_curr_ip(newsock->sk);
78082 +
78083 out_put:
78084 fput_light(sock->file, fput_needed);
78085 out:
78086 @@ -1579,6 +1627,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78087 int, addrlen)
78088 {
78089 struct socket *sock;
78090 + struct sockaddr *sck;
78091 struct sockaddr_storage address;
78092 int err, fput_needed;
78093
78094 @@ -1589,6 +1638,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78095 if (err < 0)
78096 goto out_put;
78097
78098 + sck = (struct sockaddr *)&address;
78099 +
78100 + if (gr_handle_sock_client(sck)) {
78101 + err = -EACCES;
78102 + goto out_put;
78103 + }
78104 +
78105 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78106 + if (err)
78107 + goto out_put;
78108 +
78109 err =
78110 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78111 if (err)
78112 @@ -1890,6 +1950,8 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
78113 unsigned char *ctl_buf = ctl;
78114 int err, ctl_len, iov_size, total_len;
78115
78116 + pax_track_stack();
78117 +
78118 err = -EFAULT;
78119 if (MSG_CMSG_COMPAT & flags) {
78120 if (get_compat_msghdr(msg_sys, msg_compat))
78121 @@ -1950,7 +2012,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
78122 * checking falls down on this.
78123 */
78124 if (copy_from_user(ctl_buf,
78125 - (void __user __force *)msg_sys->msg_control,
78126 + (void __force_user *)msg_sys->msg_control,
78127 ctl_len))
78128 goto out_freectl;
78129 msg_sys->msg_control = ctl_buf;
78130 @@ -2120,7 +2182,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
78131 * kernel msghdr to use the kernel address space)
78132 */
78133
78134 - uaddr = (__force void __user *)msg_sys->msg_name;
78135 + uaddr = (void __force_user *)msg_sys->msg_name;
78136 uaddr_len = COMPAT_NAMELEN(msg);
78137 if (MSG_CMSG_COMPAT & flags) {
78138 err = verify_compat_iovec(msg_sys, iov,
78139 @@ -2748,7 +2810,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78140 }
78141
78142 ifr = compat_alloc_user_space(buf_size);
78143 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
78144 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
78145
78146 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
78147 return -EFAULT;
78148 @@ -2772,12 +2834,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78149 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
78150
78151 if (copy_in_user(rxnfc, compat_rxnfc,
78152 - (void *)(&rxnfc->fs.m_ext + 1) -
78153 - (void *)rxnfc) ||
78154 + (void __user *)(&rxnfc->fs.m_ext + 1) -
78155 + (void __user *)rxnfc) ||
78156 copy_in_user(&rxnfc->fs.ring_cookie,
78157 &compat_rxnfc->fs.ring_cookie,
78158 - (void *)(&rxnfc->fs.location + 1) -
78159 - (void *)&rxnfc->fs.ring_cookie) ||
78160 + (void __user *)(&rxnfc->fs.location + 1) -
78161 + (void __user *)&rxnfc->fs.ring_cookie) ||
78162 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
78163 sizeof(rxnfc->rule_cnt)))
78164 return -EFAULT;
78165 @@ -2789,12 +2851,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78166
78167 if (convert_out) {
78168 if (copy_in_user(compat_rxnfc, rxnfc,
78169 - (const void *)(&rxnfc->fs.m_ext + 1) -
78170 - (const void *)rxnfc) ||
78171 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
78172 + (const void __user *)rxnfc) ||
78173 copy_in_user(&compat_rxnfc->fs.ring_cookie,
78174 &rxnfc->fs.ring_cookie,
78175 - (const void *)(&rxnfc->fs.location + 1) -
78176 - (const void *)&rxnfc->fs.ring_cookie) ||
78177 + (const void __user *)(&rxnfc->fs.location + 1) -
78178 + (const void __user *)&rxnfc->fs.ring_cookie) ||
78179 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
78180 sizeof(rxnfc->rule_cnt)))
78181 return -EFAULT;
78182 @@ -2864,7 +2926,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
78183 old_fs = get_fs();
78184 set_fs(KERNEL_DS);
78185 err = dev_ioctl(net, cmd,
78186 - (struct ifreq __user __force *) &kifr);
78187 + (struct ifreq __force_user *) &kifr);
78188 set_fs(old_fs);
78189
78190 return err;
78191 @@ -2973,7 +3035,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
78192
78193 old_fs = get_fs();
78194 set_fs(KERNEL_DS);
78195 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
78196 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
78197 set_fs(old_fs);
78198
78199 if (cmd == SIOCGIFMAP && !err) {
78200 @@ -3078,7 +3140,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
78201 ret |= __get_user(rtdev, &(ur4->rt_dev));
78202 if (rtdev) {
78203 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
78204 - r4.rt_dev = (char __user __force *)devname;
78205 + r4.rt_dev = (char __force_user *)devname;
78206 devname[15] = 0;
78207 } else
78208 r4.rt_dev = NULL;
78209 @@ -3318,8 +3380,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
78210 int __user *uoptlen;
78211 int err;
78212
78213 - uoptval = (char __user __force *) optval;
78214 - uoptlen = (int __user __force *) optlen;
78215 + uoptval = (char __force_user *) optval;
78216 + uoptlen = (int __force_user *) optlen;
78217
78218 set_fs(KERNEL_DS);
78219 if (level == SOL_SOCKET)
78220 @@ -3339,7 +3401,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
78221 char __user *uoptval;
78222 int err;
78223
78224 - uoptval = (char __user __force *) optval;
78225 + uoptval = (char __force_user *) optval;
78226
78227 set_fs(KERNEL_DS);
78228 if (level == SOL_SOCKET)
78229 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
78230 index d12ffa5..0b5a6e2 100644
78231 --- a/net/sunrpc/sched.c
78232 +++ b/net/sunrpc/sched.c
78233 @@ -238,9 +238,9 @@ static int rpc_wait_bit_killable(void *word)
78234 #ifdef RPC_DEBUG
78235 static void rpc_task_set_debuginfo(struct rpc_task *task)
78236 {
78237 - static atomic_t rpc_pid;
78238 + static atomic_unchecked_t rpc_pid;
78239
78240 - task->tk_pid = atomic_inc_return(&rpc_pid);
78241 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78242 }
78243 #else
78244 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78245 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
78246 index 767d494..fe17e9d 100644
78247 --- a/net/sunrpc/svcsock.c
78248 +++ b/net/sunrpc/svcsock.c
78249 @@ -394,7 +394,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
78250 int buflen, unsigned int base)
78251 {
78252 size_t save_iovlen;
78253 - void __user *save_iovbase;
78254 + void *save_iovbase;
78255 unsigned int i;
78256 int ret;
78257
78258 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
78259 index 09af4fa..77110a9 100644
78260 --- a/net/sunrpc/xprtrdma/svc_rdma.c
78261 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
78262 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
78263 static unsigned int min_max_inline = 4096;
78264 static unsigned int max_max_inline = 65536;
78265
78266 -atomic_t rdma_stat_recv;
78267 -atomic_t rdma_stat_read;
78268 -atomic_t rdma_stat_write;
78269 -atomic_t rdma_stat_sq_starve;
78270 -atomic_t rdma_stat_rq_starve;
78271 -atomic_t rdma_stat_rq_poll;
78272 -atomic_t rdma_stat_rq_prod;
78273 -atomic_t rdma_stat_sq_poll;
78274 -atomic_t rdma_stat_sq_prod;
78275 +atomic_unchecked_t rdma_stat_recv;
78276 +atomic_unchecked_t rdma_stat_read;
78277 +atomic_unchecked_t rdma_stat_write;
78278 +atomic_unchecked_t rdma_stat_sq_starve;
78279 +atomic_unchecked_t rdma_stat_rq_starve;
78280 +atomic_unchecked_t rdma_stat_rq_poll;
78281 +atomic_unchecked_t rdma_stat_rq_prod;
78282 +atomic_unchecked_t rdma_stat_sq_poll;
78283 +atomic_unchecked_t rdma_stat_sq_prod;
78284
78285 /* Temporary NFS request map and context caches */
78286 struct kmem_cache *svc_rdma_map_cachep;
78287 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
78288 len -= *ppos;
78289 if (len > *lenp)
78290 len = *lenp;
78291 - if (len && copy_to_user(buffer, str_buf, len))
78292 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78293 return -EFAULT;
78294 *lenp = len;
78295 *ppos += len;
78296 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
78297 {
78298 .procname = "rdma_stat_read",
78299 .data = &rdma_stat_read,
78300 - .maxlen = sizeof(atomic_t),
78301 + .maxlen = sizeof(atomic_unchecked_t),
78302 .mode = 0644,
78303 .proc_handler = read_reset_stat,
78304 },
78305 {
78306 .procname = "rdma_stat_recv",
78307 .data = &rdma_stat_recv,
78308 - .maxlen = sizeof(atomic_t),
78309 + .maxlen = sizeof(atomic_unchecked_t),
78310 .mode = 0644,
78311 .proc_handler = read_reset_stat,
78312 },
78313 {
78314 .procname = "rdma_stat_write",
78315 .data = &rdma_stat_write,
78316 - .maxlen = sizeof(atomic_t),
78317 + .maxlen = sizeof(atomic_unchecked_t),
78318 .mode = 0644,
78319 .proc_handler = read_reset_stat,
78320 },
78321 {
78322 .procname = "rdma_stat_sq_starve",
78323 .data = &rdma_stat_sq_starve,
78324 - .maxlen = sizeof(atomic_t),
78325 + .maxlen = sizeof(atomic_unchecked_t),
78326 .mode = 0644,
78327 .proc_handler = read_reset_stat,
78328 },
78329 {
78330 .procname = "rdma_stat_rq_starve",
78331 .data = &rdma_stat_rq_starve,
78332 - .maxlen = sizeof(atomic_t),
78333 + .maxlen = sizeof(atomic_unchecked_t),
78334 .mode = 0644,
78335 .proc_handler = read_reset_stat,
78336 },
78337 {
78338 .procname = "rdma_stat_rq_poll",
78339 .data = &rdma_stat_rq_poll,
78340 - .maxlen = sizeof(atomic_t),
78341 + .maxlen = sizeof(atomic_unchecked_t),
78342 .mode = 0644,
78343 .proc_handler = read_reset_stat,
78344 },
78345 {
78346 .procname = "rdma_stat_rq_prod",
78347 .data = &rdma_stat_rq_prod,
78348 - .maxlen = sizeof(atomic_t),
78349 + .maxlen = sizeof(atomic_unchecked_t),
78350 .mode = 0644,
78351 .proc_handler = read_reset_stat,
78352 },
78353 {
78354 .procname = "rdma_stat_sq_poll",
78355 .data = &rdma_stat_sq_poll,
78356 - .maxlen = sizeof(atomic_t),
78357 + .maxlen = sizeof(atomic_unchecked_t),
78358 .mode = 0644,
78359 .proc_handler = read_reset_stat,
78360 },
78361 {
78362 .procname = "rdma_stat_sq_prod",
78363 .data = &rdma_stat_sq_prod,
78364 - .maxlen = sizeof(atomic_t),
78365 + .maxlen = sizeof(atomic_unchecked_t),
78366 .mode = 0644,
78367 .proc_handler = read_reset_stat,
78368 },
78369 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78370 index df67211..c354b13 100644
78371 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78372 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78373 @@ -499,7 +499,7 @@ next_sge:
78374 svc_rdma_put_context(ctxt, 0);
78375 goto out;
78376 }
78377 - atomic_inc(&rdma_stat_read);
78378 + atomic_inc_unchecked(&rdma_stat_read);
78379
78380 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78381 chl_map->ch[ch_no].count -= read_wr.num_sge;
78382 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78383 dto_q);
78384 list_del_init(&ctxt->dto_q);
78385 } else {
78386 - atomic_inc(&rdma_stat_rq_starve);
78387 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78388 clear_bit(XPT_DATA, &xprt->xpt_flags);
78389 ctxt = NULL;
78390 }
78391 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78392 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78393 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78394 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78395 - atomic_inc(&rdma_stat_recv);
78396 + atomic_inc_unchecked(&rdma_stat_recv);
78397
78398 /* Build up the XDR from the receive buffers. */
78399 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78400 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78401 index 249a835..fb2794b 100644
78402 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78403 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78404 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78405 write_wr.wr.rdma.remote_addr = to;
78406
78407 /* Post It */
78408 - atomic_inc(&rdma_stat_write);
78409 + atomic_inc_unchecked(&rdma_stat_write);
78410 if (svc_rdma_send(xprt, &write_wr))
78411 goto err;
78412 return 0;
78413 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78414 index a385430..32254ea 100644
78415 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78416 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78417 @@ -299,7 +299,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78418 return;
78419
78420 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78421 - atomic_inc(&rdma_stat_rq_poll);
78422 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78423
78424 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78425 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78426 @@ -321,7 +321,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78427 }
78428
78429 if (ctxt)
78430 - atomic_inc(&rdma_stat_rq_prod);
78431 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78432
78433 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78434 /*
78435 @@ -393,7 +393,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78436 return;
78437
78438 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78439 - atomic_inc(&rdma_stat_sq_poll);
78440 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78441 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78442 if (wc.status != IB_WC_SUCCESS)
78443 /* Close the transport */
78444 @@ -411,7 +411,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78445 }
78446
78447 if (ctxt)
78448 - atomic_inc(&rdma_stat_sq_prod);
78449 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78450 }
78451
78452 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78453 @@ -1273,7 +1273,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78454 spin_lock_bh(&xprt->sc_lock);
78455 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78456 spin_unlock_bh(&xprt->sc_lock);
78457 - atomic_inc(&rdma_stat_sq_starve);
78458 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78459
78460 /* See if we can opportunistically reap SQ WR to make room */
78461 sq_cq_reap(xprt);
78462 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78463 index ca84212..3aa338f 100644
78464 --- a/net/sysctl_net.c
78465 +++ b/net/sysctl_net.c
78466 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78467 struct ctl_table *table)
78468 {
78469 /* Allow network administrator to have same access as root. */
78470 - if (capable(CAP_NET_ADMIN)) {
78471 + if (capable_nolog(CAP_NET_ADMIN)) {
78472 int mode = (table->mode >> 6) & 7;
78473 return (mode << 6) | (mode << 3) | mode;
78474 }
78475 diff --git a/net/tipc/link.c b/net/tipc/link.c
78476 index f89570c..016cf63 100644
78477 --- a/net/tipc/link.c
78478 +++ b/net/tipc/link.c
78479 @@ -1170,7 +1170,7 @@ static int link_send_sections_long(struct tipc_port *sender,
78480 struct tipc_msg fragm_hdr;
78481 struct sk_buff *buf, *buf_chain, *prev;
78482 u32 fragm_crs, fragm_rest, hsz, sect_rest;
78483 - const unchar *sect_crs;
78484 + const unchar __user *sect_crs;
78485 int curr_sect;
78486 u32 fragm_no;
78487
78488 @@ -1214,7 +1214,7 @@ again:
78489
78490 if (!sect_rest) {
78491 sect_rest = msg_sect[++curr_sect].iov_len;
78492 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78493 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78494 }
78495
78496 if (sect_rest < fragm_rest)
78497 @@ -1233,7 +1233,7 @@ error:
78498 }
78499 } else
78500 skb_copy_to_linear_data_offset(buf, fragm_crs,
78501 - sect_crs, sz);
78502 + (const void __force_kernel *)sect_crs, sz);
78503 sect_crs += sz;
78504 sect_rest -= sz;
78505 fragm_crs += sz;
78506 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
78507 index 83d5096..dcba497 100644
78508 --- a/net/tipc/msg.c
78509 +++ b/net/tipc/msg.c
78510 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
78511 msg_sect[cnt].iov_len);
78512 else
78513 skb_copy_to_linear_data_offset(*buf, pos,
78514 - msg_sect[cnt].iov_base,
78515 + (const void __force_kernel *)msg_sect[cnt].iov_base,
78516 msg_sect[cnt].iov_len);
78517 pos += msg_sect[cnt].iov_len;
78518 }
78519 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
78520 index 6cf7268..7a488ce 100644
78521 --- a/net/tipc/subscr.c
78522 +++ b/net/tipc/subscr.c
78523 @@ -101,7 +101,7 @@ static void subscr_send_event(struct subscription *sub,
78524 {
78525 struct iovec msg_sect;
78526
78527 - msg_sect.iov_base = (void *)&sub->evt;
78528 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78529 msg_sect.iov_len = sizeof(struct tipc_event);
78530
78531 sub->evt.event = htohl(event, sub->swap);
78532 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
78533 index ec68e1c..fdd792f 100644
78534 --- a/net/unix/af_unix.c
78535 +++ b/net/unix/af_unix.c
78536 @@ -767,6 +767,12 @@ static struct sock *unix_find_other(struct net *net,
78537 err = -ECONNREFUSED;
78538 if (!S_ISSOCK(inode->i_mode))
78539 goto put_fail;
78540 +
78541 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78542 + err = -EACCES;
78543 + goto put_fail;
78544 + }
78545 +
78546 u = unix_find_socket_byinode(inode);
78547 if (!u)
78548 goto put_fail;
78549 @@ -787,6 +793,13 @@ static struct sock *unix_find_other(struct net *net,
78550 if (u) {
78551 struct dentry *dentry;
78552 dentry = unix_sk(u)->dentry;
78553 +
78554 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
78555 + err = -EPERM;
78556 + sock_put(u);
78557 + goto fail;
78558 + }
78559 +
78560 if (dentry)
78561 touch_atime(unix_sk(u)->mnt, dentry);
78562 } else
78563 @@ -869,11 +882,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
78564 err = security_path_mknod(&path, dentry, mode, 0);
78565 if (err)
78566 goto out_mknod_drop_write;
78567 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
78568 + err = -EACCES;
78569 + goto out_mknod_drop_write;
78570 + }
78571 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
78572 out_mknod_drop_write:
78573 mnt_drop_write(path.mnt);
78574 if (err)
78575 goto out_mknod_dput;
78576 +
78577 + gr_handle_create(dentry, path.mnt);
78578 +
78579 mutex_unlock(&path.dentry->d_inode->i_mutex);
78580 dput(path.dentry);
78581 path.dentry = dentry;
78582 diff --git a/net/wireless/core.h b/net/wireless/core.h
78583 index 8672e02..48782dd 100644
78584 --- a/net/wireless/core.h
78585 +++ b/net/wireless/core.h
78586 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78587 struct mutex mtx;
78588
78589 /* rfkill support */
78590 - struct rfkill_ops rfkill_ops;
78591 + rfkill_ops_no_const rfkill_ops;
78592 struct rfkill *rfkill;
78593 struct work_struct rfkill_sync;
78594
78595 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
78596 index fdbc23c..212d53e 100644
78597 --- a/net/wireless/wext-core.c
78598 +++ b/net/wireless/wext-core.c
78599 @@ -746,8 +746,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78600 */
78601
78602 /* Support for very large requests */
78603 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78604 - (user_length > descr->max_tokens)) {
78605 + if (user_length > descr->max_tokens) {
78606 /* Allow userspace to GET more than max so
78607 * we can support any size GET requests.
78608 * There is still a limit : -ENOMEM.
78609 @@ -784,22 +783,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78610 }
78611 }
78612
78613 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78614 - /*
78615 - * If this is a GET, but not NOMAX, it means that the extra
78616 - * data is not bounded by userspace, but by max_tokens. Thus
78617 - * set the length to max_tokens. This matches the extra data
78618 - * allocation.
78619 - * The driver should fill it with the number of tokens it
78620 - * provided, and it may check iwp->length rather than having
78621 - * knowledge of max_tokens. If the driver doesn't change the
78622 - * iwp->length, this ioctl just copies back max_token tokens
78623 - * filled with zeroes. Hopefully the driver isn't claiming
78624 - * them to be valid data.
78625 - */
78626 - iwp->length = descr->max_tokens;
78627 - }
78628 -
78629 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78630
78631 iwp->length += essid_compat;
78632 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
78633 index 7e088c0..dd3f206 100644
78634 --- a/net/xfrm/xfrm_policy.c
78635 +++ b/net/xfrm/xfrm_policy.c
78636 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
78637 {
78638 policy->walk.dead = 1;
78639
78640 - atomic_inc(&policy->genid);
78641 + atomic_inc_unchecked(&policy->genid);
78642
78643 if (del_timer(&policy->timer))
78644 xfrm_pol_put(policy);
78645 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
78646 hlist_add_head(&policy->bydst, chain);
78647 xfrm_pol_hold(policy);
78648 net->xfrm.policy_count[dir]++;
78649 - atomic_inc(&flow_cache_genid);
78650 + atomic_inc_unchecked(&flow_cache_genid);
78651 if (delpol)
78652 __xfrm_policy_unlink(delpol, dir);
78653 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78654 @@ -1530,7 +1530,7 @@ free_dst:
78655 goto out;
78656 }
78657
78658 -static int inline
78659 +static inline int
78660 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78661 {
78662 if (!*target) {
78663 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
78664 return 0;
78665 }
78666
78667 -static int inline
78668 +static inline int
78669 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78670 {
78671 #ifdef CONFIG_XFRM_SUB_POLICY
78672 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78673 #endif
78674 }
78675
78676 -static int inline
78677 +static inline int
78678 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78679 {
78680 #ifdef CONFIG_XFRM_SUB_POLICY
78681 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
78682
78683 xdst->num_pols = num_pols;
78684 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78685 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78686 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78687
78688 return xdst;
78689 }
78690 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
78691 if (xdst->xfrm_genid != dst->xfrm->genid)
78692 return 0;
78693 if (xdst->num_pols > 0 &&
78694 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78695 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78696 return 0;
78697
78698 mtu = dst_mtu(dst->child);
78699 @@ -2880,7 +2880,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
78700 sizeof(pol->xfrm_vec[i].saddr));
78701 pol->xfrm_vec[i].encap_family = mp->new_family;
78702 /* flush bundles */
78703 - atomic_inc(&pol->genid);
78704 + atomic_inc_unchecked(&pol->genid);
78705 }
78706 }
78707
78708 diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
78709 index 0256b8a..9341ef6 100644
78710 --- a/net/xfrm/xfrm_user.c
78711 +++ b/net/xfrm/xfrm_user.c
78712 @@ -1394,6 +1394,8 @@ static int copy_to_user_tmpl(struct xfrm_policy *xp, struct sk_buff *skb)
78713 struct xfrm_user_tmpl vec[XFRM_MAX_DEPTH];
78714 int i;
78715
78716 + pax_track_stack();
78717 +
78718 if (xp->xfrm_nr == 0)
78719 return 0;
78720
78721 @@ -2062,6 +2064,8 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
78722 int err;
78723 int n = 0;
78724
78725 + pax_track_stack();
78726 +
78727 if (attrs[XFRMA_MIGRATE] == NULL)
78728 return -EINVAL;
78729
78730 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
78731 index a0fd502..a8e6e83 100644
78732 --- a/scripts/Makefile.build
78733 +++ b/scripts/Makefile.build
78734 @@ -109,7 +109,7 @@ endif
78735 endif
78736
78737 # Do not include host rules unless needed
78738 -ifneq ($(hostprogs-y)$(hostprogs-m),)
78739 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
78740 include scripts/Makefile.host
78741 endif
78742
78743 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
78744 index 686cb0d..9d653bf 100644
78745 --- a/scripts/Makefile.clean
78746 +++ b/scripts/Makefile.clean
78747 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
78748 __clean-files := $(extra-y) $(always) \
78749 $(targets) $(clean-files) \
78750 $(host-progs) \
78751 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
78752 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
78753 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
78754
78755 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
78756
78757 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
78758 index 1ac414f..a1c1451 100644
78759 --- a/scripts/Makefile.host
78760 +++ b/scripts/Makefile.host
78761 @@ -31,6 +31,7 @@
78762 # Note: Shared libraries consisting of C++ files are not supported
78763
78764 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
78765 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
78766
78767 # C code
78768 # Executables compiled from a single .c file
78769 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
78770 # Shared libaries (only .c supported)
78771 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
78772 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
78773 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
78774 # Remove .so files from "xxx-objs"
78775 host-cobjs := $(filter-out %.so,$(host-cobjs))
78776
78777 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
78778 index 291228e..6c55203 100644
78779 --- a/scripts/basic/fixdep.c
78780 +++ b/scripts/basic/fixdep.c
78781 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
78782 /*
78783 * Lookup a value in the configuration string.
78784 */
78785 -static int is_defined_config(const char *name, int len, unsigned int hash)
78786 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
78787 {
78788 struct item *aux;
78789
78790 @@ -211,10 +211,10 @@ static void clear_config(void)
78791 /*
78792 * Record the use of a CONFIG_* word.
78793 */
78794 -static void use_config(const char *m, int slen)
78795 +static void use_config(const char *m, unsigned int slen)
78796 {
78797 unsigned int hash = strhash(m, slen);
78798 - int c, i;
78799 + unsigned int c, i;
78800
78801 if (is_defined_config(m, slen, hash))
78802 return;
78803 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
78804
78805 static void parse_config_file(const char *map, size_t len)
78806 {
78807 - const int *end = (const int *) (map + len);
78808 + const unsigned int *end = (const unsigned int *) (map + len);
78809 /* start at +1, so that p can never be < map */
78810 - const int *m = (const int *) map + 1;
78811 + const unsigned int *m = (const unsigned int *) map + 1;
78812 const char *p, *q;
78813
78814 for (; m < end; m++) {
78815 @@ -405,7 +405,7 @@ static void print_deps(void)
78816 static void traps(void)
78817 {
78818 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78819 - int *p = (int *)test;
78820 + unsigned int *p = (unsigned int *)test;
78821
78822 if (*p != INT_CONF) {
78823 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78824 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
78825 new file mode 100644
78826 index 0000000..8729101
78827 --- /dev/null
78828 +++ b/scripts/gcc-plugin.sh
78829 @@ -0,0 +1,2 @@
78830 +#!/bin/sh
78831 +echo -e "#include \"gcc-plugin.h\"\n#include \"tree.h\"\n#include \"tm.h\"\n#include \"rtl.h\"" | $1 -x c -shared - -o /dev/null -I`$2 -print-file-name=plugin`/include >/dev/null 2>&1 && echo "y"
78832 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
78833 index e26e2fb..f84937b 100644
78834 --- a/scripts/mod/file2alias.c
78835 +++ b/scripts/mod/file2alias.c
78836 @@ -72,7 +72,7 @@ static void device_id_check(const char *modname, const char *device_id,
78837 unsigned long size, unsigned long id_size,
78838 void *symval)
78839 {
78840 - int i;
78841 + unsigned int i;
78842
78843 if (size % id_size || size < id_size) {
78844 if (cross_build != 0)
78845 @@ -102,7 +102,7 @@ static void device_id_check(const char *modname, const char *device_id,
78846 /* USB is special because the bcdDevice can be matched against a numeric range */
78847 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
78848 static void do_usb_entry(struct usb_device_id *id,
78849 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
78850 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
78851 unsigned char range_lo, unsigned char range_hi,
78852 unsigned char max, struct module *mod)
78853 {
78854 @@ -203,7 +203,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
78855 {
78856 unsigned int devlo, devhi;
78857 unsigned char chi, clo, max;
78858 - int ndigits;
78859 + unsigned int ndigits;
78860
78861 id->match_flags = TO_NATIVE(id->match_flags);
78862 id->idVendor = TO_NATIVE(id->idVendor);
78863 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
78864 for (i = 0; i < count; i++) {
78865 const char *id = (char *)devs[i].id;
78866 char acpi_id[sizeof(devs[0].id)];
78867 - int j;
78868 + unsigned int j;
78869
78870 buf_printf(&mod->dev_table_buf,
78871 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78872 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78873
78874 for (j = 0; j < PNP_MAX_DEVICES; j++) {
78875 const char *id = (char *)card->devs[j].id;
78876 - int i2, j2;
78877 + unsigned int i2, j2;
78878 int dup = 0;
78879
78880 if (!id[0])
78881 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78882 /* add an individual alias for every device entry */
78883 if (!dup) {
78884 char acpi_id[sizeof(card->devs[0].id)];
78885 - int k;
78886 + unsigned int k;
78887
78888 buf_printf(&mod->dev_table_buf,
78889 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78890 @@ -786,7 +786,7 @@ static void dmi_ascii_filter(char *d, const char *s)
78891 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
78892 char *alias)
78893 {
78894 - int i, j;
78895 + unsigned int i, j;
78896
78897 sprintf(alias, "dmi*");
78898
78899 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
78900 index a509ff8..5822633 100644
78901 --- a/scripts/mod/modpost.c
78902 +++ b/scripts/mod/modpost.c
78903 @@ -919,6 +919,7 @@ enum mismatch {
78904 ANY_INIT_TO_ANY_EXIT,
78905 ANY_EXIT_TO_ANY_INIT,
78906 EXPORT_TO_INIT_EXIT,
78907 + DATA_TO_TEXT
78908 };
78909
78910 struct sectioncheck {
78911 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
78912 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
78913 .mismatch = EXPORT_TO_INIT_EXIT,
78914 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
78915 +},
78916 +/* Do not reference code from writable data */
78917 +{
78918 + .fromsec = { DATA_SECTIONS, NULL },
78919 + .tosec = { TEXT_SECTIONS, NULL },
78920 + .mismatch = DATA_TO_TEXT
78921 }
78922 };
78923
78924 @@ -1149,10 +1156,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
78925 continue;
78926 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
78927 continue;
78928 - if (sym->st_value == addr)
78929 - return sym;
78930 /* Find a symbol nearby - addr are maybe negative */
78931 d = sym->st_value - addr;
78932 + if (d == 0)
78933 + return sym;
78934 if (d < 0)
78935 d = addr - sym->st_value;
78936 if (d < distance) {
78937 @@ -1431,6 +1438,14 @@ static void report_sec_mismatch(const char *modname,
78938 tosym, prl_to, prl_to, tosym);
78939 free(prl_to);
78940 break;
78941 + case DATA_TO_TEXT:
78942 +/*
78943 + fprintf(stderr,
78944 + "The variable %s references\n"
78945 + "the %s %s%s%s\n",
78946 + fromsym, to, sec2annotation(tosec), tosym, to_p);
78947 +*/
78948 + break;
78949 }
78950 fprintf(stderr, "\n");
78951 }
78952 @@ -1656,7 +1671,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
78953 static void check_sec_ref(struct module *mod, const char *modname,
78954 struct elf_info *elf)
78955 {
78956 - int i;
78957 + unsigned int i;
78958 Elf_Shdr *sechdrs = elf->sechdrs;
78959
78960 /* Walk through all sections */
78961 @@ -1754,7 +1769,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
78962 va_end(ap);
78963 }
78964
78965 -void buf_write(struct buffer *buf, const char *s, int len)
78966 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
78967 {
78968 if (buf->size - buf->pos < len) {
78969 buf->size += len + SZ;
78970 @@ -1966,7 +1981,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
78971 if (fstat(fileno(file), &st) < 0)
78972 goto close_write;
78973
78974 - if (st.st_size != b->pos)
78975 + if (st.st_size != (off_t)b->pos)
78976 goto close_write;
78977
78978 tmp = NOFAIL(malloc(b->pos));
78979 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
78980 index 2031119..b5433af 100644
78981 --- a/scripts/mod/modpost.h
78982 +++ b/scripts/mod/modpost.h
78983 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
78984
78985 struct buffer {
78986 char *p;
78987 - int pos;
78988 - int size;
78989 + unsigned int pos;
78990 + unsigned int size;
78991 };
78992
78993 void __attribute__((format(printf, 2, 3)))
78994 buf_printf(struct buffer *buf, const char *fmt, ...);
78995
78996 void
78997 -buf_write(struct buffer *buf, const char *s, int len);
78998 +buf_write(struct buffer *buf, const char *s, unsigned int len);
78999
79000 struct module {
79001 struct module *next;
79002 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
79003 index 9dfcd6d..099068e 100644
79004 --- a/scripts/mod/sumversion.c
79005 +++ b/scripts/mod/sumversion.c
79006 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
79007 goto out;
79008 }
79009
79010 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79011 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79012 warn("writing sum in %s failed: %s\n",
79013 filename, strerror(errno));
79014 goto out;
79015 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
79016 index 5c11312..72742b5 100644
79017 --- a/scripts/pnmtologo.c
79018 +++ b/scripts/pnmtologo.c
79019 @@ -237,14 +237,14 @@ static void write_header(void)
79020 fprintf(out, " * Linux logo %s\n", logoname);
79021 fputs(" */\n\n", out);
79022 fputs("#include <linux/linux_logo.h>\n\n", out);
79023 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79024 + fprintf(out, "static unsigned char %s_data[] = {\n",
79025 logoname);
79026 }
79027
79028 static void write_footer(void)
79029 {
79030 fputs("\n};\n\n", out);
79031 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79032 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79033 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79034 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79035 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79036 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79037 fputs("\n};\n\n", out);
79038
79039 /* write logo clut */
79040 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79041 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79042 logoname);
79043 write_hex_cnt = 0;
79044 for (i = 0; i < logo_clutsize; i++) {
79045 diff --git a/security/Kconfig b/security/Kconfig
79046 index e0f08b5..649220f 100644
79047 --- a/security/Kconfig
79048 +++ b/security/Kconfig
79049 @@ -4,6 +4,626 @@
79050
79051 menu "Security options"
79052
79053 +source grsecurity/Kconfig
79054 +
79055 +menu "PaX"
79056 +
79057 + config ARCH_TRACK_EXEC_LIMIT
79058 + bool
79059 +
79060 + config PAX_KERNEXEC_PLUGIN
79061 + bool
79062 +
79063 + config PAX_PER_CPU_PGD
79064 + bool
79065 +
79066 + config TASK_SIZE_MAX_SHIFT
79067 + int
79068 + depends on X86_64
79069 + default 47 if !PAX_PER_CPU_PGD
79070 + default 42 if PAX_PER_CPU_PGD
79071 +
79072 + config PAX_ENABLE_PAE
79073 + bool
79074 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79075 +
79076 +config PAX
79077 + bool "Enable various PaX features"
79078 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79079 + help
79080 + This allows you to enable various PaX features. PaX adds
79081 + intrusion prevention mechanisms to the kernel that reduce
79082 + the risks posed by exploitable memory corruption bugs.
79083 +
79084 +menu "PaX Control"
79085 + depends on PAX
79086 +
79087 +config PAX_SOFTMODE
79088 + bool 'Support soft mode'
79089 + help
79090 + Enabling this option will allow you to run PaX in soft mode, that
79091 + is, PaX features will not be enforced by default, only on executables
79092 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
79093 + support as they are the only way to mark executables for soft mode use.
79094 +
79095 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79096 + line option on boot. Furthermore you can control various PaX features
79097 + at runtime via the entries in /proc/sys/kernel/pax.
79098 +
79099 +config PAX_EI_PAX
79100 + bool 'Use legacy ELF header marking'
79101 + help
79102 + Enabling this option will allow you to control PaX features on
79103 + a per executable basis via the 'chpax' utility available at
79104 + http://pax.grsecurity.net/. The control flags will be read from
79105 + an otherwise reserved part of the ELF header. This marking has
79106 + numerous drawbacks (no support for soft-mode, toolchain does not
79107 + know about the non-standard use of the ELF header) therefore it
79108 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
79109 + support.
79110 +
79111 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79112 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
79113 + option otherwise they will not get any protection.
79114 +
79115 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
79116 + support as well, they will override the legacy EI_PAX marks.
79117 +
79118 +config PAX_PT_PAX_FLAGS
79119 + bool 'Use ELF program header marking'
79120 + help
79121 + Enabling this option will allow you to control PaX features on
79122 + a per executable basis via the 'paxctl' utility available at
79123 + http://pax.grsecurity.net/. The control flags will be read from
79124 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79125 + has the benefits of supporting both soft mode and being fully
79126 + integrated into the toolchain (the binutils patch is available
79127 + from http://pax.grsecurity.net).
79128 +
79129 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79130 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
79131 + support otherwise they will not get any protection.
79132 +
79133 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79134 + must make sure that the marks are the same if a binary has both marks.
79135 +
79136 + Note that if you enable the legacy EI_PAX marking support as well,
79137 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79138 +
79139 +config PAX_XATTR_PAX_FLAGS
79140 + bool 'Use filesystem extended attributes marking'
79141 + depends on EXPERT
79142 + select CIFS_XATTR if CIFS
79143 + select EXT2_FS_XATTR if EXT2_FS
79144 + select EXT3_FS_XATTR if EXT3_FS
79145 + select EXT4_FS_XATTR if EXT4_FS
79146 + select JFFS2_FS_XATTR if JFFS2_FS
79147 + select REISERFS_FS_XATTR if REISERFS_FS
79148 + select SQUASHFS_XATTR if SQUASHFS
79149 + select TMPFS_XATTR if TMPFS
79150 + select UBIFS_FS_XATTR if UBIFS_FS
79151 + help
79152 + Enabling this option will allow you to control PaX features on
79153 + a per executable basis via the 'setfattr' utility. The control
79154 + flags will be read from the user.pax.flags extended attribute of
79155 + the file. This marking has the benefit of supporting binary-only
79156 + applications that self-check themselves (e.g., skype) and would
79157 + not tolerate chpax/paxctl changes. The main drawback is that
79158 + extended attributes are not supported by some filesystems (e.g.,
79159 + isofs, udf, vfat) so copying files through such filesystems will
79160 + lose the extended attributes and these PaX markings.
79161 +
79162 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79163 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
79164 + support otherwise they will not get any protection.
79165 +
79166 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79167 + must make sure that the marks are the same if a binary has both marks.
79168 +
79169 + Note that if you enable the legacy EI_PAX marking support as well,
79170 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
79171 +
79172 +choice
79173 + prompt 'MAC system integration'
79174 + default PAX_HAVE_ACL_FLAGS
79175 + help
79176 + Mandatory Access Control systems have the option of controlling
79177 + PaX flags on a per executable basis, choose the method supported
79178 + by your particular system.
79179 +
79180 + - "none": if your MAC system does not interact with PaX,
79181 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79182 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79183 +
79184 + NOTE: this option is for developers/integrators only.
79185 +
79186 + config PAX_NO_ACL_FLAGS
79187 + bool 'none'
79188 +
79189 + config PAX_HAVE_ACL_FLAGS
79190 + bool 'direct'
79191 +
79192 + config PAX_HOOK_ACL_FLAGS
79193 + bool 'hook'
79194 +endchoice
79195 +
79196 +endmenu
79197 +
79198 +menu "Non-executable pages"
79199 + depends on PAX
79200 +
79201 +config PAX_NOEXEC
79202 + bool "Enforce non-executable pages"
79203 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
79204 + help
79205 + By design some architectures do not allow for protecting memory
79206 + pages against execution or even if they do, Linux does not make
79207 + use of this feature. In practice this means that if a page is
79208 + readable (such as the stack or heap) it is also executable.
79209 +
79210 + There is a well known exploit technique that makes use of this
79211 + fact and a common programming mistake where an attacker can
79212 + introduce code of his choice somewhere in the attacked program's
79213 + memory (typically the stack or the heap) and then execute it.
79214 +
79215 + If the attacked program was running with different (typically
79216 + higher) privileges than that of the attacker, then he can elevate
79217 + his own privilege level (e.g. get a root shell, write to files for
79218 + which he does not have write access to, etc).
79219 +
79220 + Enabling this option will let you choose from various features
79221 + that prevent the injection and execution of 'foreign' code in
79222 + a program.
79223 +
79224 + This will also break programs that rely on the old behaviour and
79225 + expect that dynamically allocated memory via the malloc() family
79226 + of functions is executable (which it is not). Notable examples
79227 + are the XFree86 4.x server, the java runtime and wine.
79228 +
79229 +config PAX_PAGEEXEC
79230 + bool "Paging based non-executable pages"
79231 + depends on PAX_NOEXEC && (!X86_32 || M586 || M586TSC || M586MMX || M686 || MPENTIUMII || MPENTIUMIII || MPENTIUMM || MCORE2 || MATOM || MPENTIUM4 || MPSC || MK7 || MK8 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MVIAC3_2 || MVIAC7)
79232 + select S390_SWITCH_AMODE if S390
79233 + select S390_EXEC_PROTECT if S390
79234 + select ARCH_TRACK_EXEC_LIMIT if X86_32
79235 + help
79236 + This implementation is based on the paging feature of the CPU.
79237 + On i386 without hardware non-executable bit support there is a
79238 + variable but usually low performance impact, however on Intel's
79239 + P4 core based CPUs it is very high so you should not enable this
79240 + for kernels meant to be used on such CPUs.
79241 +
79242 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
79243 + with hardware non-executable bit support there is no performance
79244 + impact, on ppc the impact is negligible.
79245 +
79246 + Note that several architectures require various emulations due to
79247 + badly designed userland ABIs, this will cause a performance impact
79248 + but will disappear as soon as userland is fixed. For example, ppc
79249 + userland MUST have been built with secure-plt by a recent toolchain.
79250 +
79251 +config PAX_SEGMEXEC
79252 + bool "Segmentation based non-executable pages"
79253 + depends on PAX_NOEXEC && X86_32
79254 + help
79255 + This implementation is based on the segmentation feature of the
79256 + CPU and has a very small performance impact, however applications
79257 + will be limited to a 1.5 GB address space instead of the normal
79258 + 3 GB.
79259 +
79260 +config PAX_EMUTRAMP
79261 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
79262 + default y if PARISC
79263 + help
79264 + There are some programs and libraries that for one reason or
79265 + another attempt to execute special small code snippets from
79266 + non-executable memory pages. Most notable examples are the
79267 + signal handler return code generated by the kernel itself and
79268 + the GCC trampolines.
79269 +
79270 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
79271 + such programs will no longer work under your kernel.
79272 +
79273 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
79274 + utilities to enable trampoline emulation for the affected programs
79275 + yet still have the protection provided by the non-executable pages.
79276 +
79277 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
79278 + your system will not even boot.
79279 +
79280 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
79281 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
79282 + for the affected files.
79283 +
79284 + NOTE: enabling this feature *may* open up a loophole in the
79285 + protection provided by non-executable pages that an attacker
79286 + could abuse. Therefore the best solution is to not have any
79287 + files on your system that would require this option. This can
79288 + be achieved by not using libc5 (which relies on the kernel
79289 + signal handler return code) and not using or rewriting programs
79290 + that make use of the nested function implementation of GCC.
79291 + Skilled users can just fix GCC itself so that it implements
79292 + nested function calls in a way that does not interfere with PaX.
79293 +
79294 +config PAX_EMUSIGRT
79295 + bool "Automatically emulate sigreturn trampolines"
79296 + depends on PAX_EMUTRAMP && PARISC
79297 + default y
79298 + help
79299 + Enabling this option will have the kernel automatically detect
79300 + and emulate signal return trampolines executing on the stack
79301 + that would otherwise lead to task termination.
79302 +
79303 + This solution is intended as a temporary one for users with
79304 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
79305 + Modula-3 runtime, etc) or executables linked to such, basically
79306 + everything that does not specify its own SA_RESTORER function in
79307 + normal executable memory like glibc 2.1+ does.
79308 +
79309 + On parisc you MUST enable this option, otherwise your system will
79310 + not even boot.
79311 +
79312 + NOTE: this feature cannot be disabled on a per executable basis
79313 + and since it *does* open up a loophole in the protection provided
79314 + by non-executable pages, the best solution is to not have any
79315 + files on your system that would require this option.
79316 +
79317 +config PAX_MPROTECT
79318 + bool "Restrict mprotect()"
79319 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
79320 + help
79321 + Enabling this option will prevent programs from
79322 + - changing the executable status of memory pages that were
79323 + not originally created as executable,
79324 + - making read-only executable pages writable again,
79325 + - creating executable pages from anonymous memory,
79326 + - making read-only-after-relocations (RELRO) data pages writable again.
79327 +
79328 + You should say Y here to complete the protection provided by
79329 + the enforcement of non-executable pages.
79330 +
79331 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79332 + this feature on a per file basis.
79333 +
79334 +config PAX_MPROTECT_COMPAT
79335 + bool "Use legacy/compat protection demoting (read help)"
79336 + depends on PAX_MPROTECT
79337 + default n
79338 + help
79339 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
79340 + by sending the proper error code to the application. For some broken
79341 + userland, this can cause problems with Python or other applications. The
79342 + current implementation however allows for applications like clamav to
79343 + detect if JIT compilation/execution is allowed and to fall back gracefully
79344 + to an interpreter-based mode if it does not. While we encourage everyone
79345 + to use the current implementation as-is and push upstream to fix broken
79346 + userland (note that the RWX logging option can assist with this), in some
79347 + environments this may not be possible. Having to disable MPROTECT
79348 + completely on certain binaries reduces the security benefit of PaX,
79349 + so this option is provided for those environments to revert to the old
79350 + behavior.
79351 +
79352 +config PAX_ELFRELOCS
79353 + bool "Allow ELF text relocations (read help)"
79354 + depends on PAX_MPROTECT
79355 + default n
79356 + help
79357 + Non-executable pages and mprotect() restrictions are effective
79358 + in preventing the introduction of new executable code into an
79359 + attacked task's address space. There remain only two venues
79360 + for this kind of attack: if the attacker can execute already
79361 + existing code in the attacked task then he can either have it
79362 + create and mmap() a file containing his code or have it mmap()
79363 + an already existing ELF library that does not have position
79364 + independent code in it and use mprotect() on it to make it
79365 + writable and copy his code there. While protecting against
79366 + the former approach is beyond PaX, the latter can be prevented
79367 + by having only PIC ELF libraries on one's system (which do not
79368 + need to relocate their code). If you are sure this is your case,
79369 + as is the case with all modern Linux distributions, then leave
79370 + this option disabled. You should say 'n' here.
79371 +
79372 +config PAX_ETEXECRELOCS
79373 + bool "Allow ELF ET_EXEC text relocations"
79374 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
79375 + select PAX_ELFRELOCS
79376 + default y
79377 + help
79378 + On some architectures there are incorrectly created applications
79379 + that require text relocations and would not work without enabling
79380 + this option. If you are an alpha, ia64 or parisc user, you should
79381 + enable this option and disable it once you have made sure that
79382 + none of your applications need it.
79383 +
79384 +config PAX_EMUPLT
79385 + bool "Automatically emulate ELF PLT"
79386 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79387 + default y
79388 + help
79389 + Enabling this option will have the kernel automatically detect
79390 + and emulate the Procedure Linkage Table entries in ELF files.
79391 + On some architectures such entries are in writable memory, and
79392 + become non-executable leading to task termination. Therefore
79393 + it is mandatory that you enable this option on alpha, parisc,
79394 + sparc and sparc64, otherwise your system would not even boot.
79395 +
79396 + NOTE: this feature *does* open up a loophole in the protection
79397 + provided by the non-executable pages, therefore the proper
79398 + solution is to modify the toolchain to produce a PLT that does
79399 + not need to be writable.
79400 +
79401 +config PAX_DLRESOLVE
79402 + bool 'Emulate old glibc resolver stub'
79403 + depends on PAX_EMUPLT && SPARC
79404 + default n
79405 + help
79406 + This option is needed if userland has an old glibc (before 2.4)
79407 + that puts a 'save' instruction into the runtime generated resolver
79408 + stub that needs special emulation.
79409 +
79410 +config PAX_KERNEXEC
79411 + bool "Enforce non-executable kernel pages"
79412 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79413 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79414 + select PAX_KERNEXEC_PLUGIN if X86_64
79415 + help
79416 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79417 + that is, enabling this option will make it harder to inject
79418 + and execute 'foreign' code in kernel memory itself.
79419 +
79420 + Note that on x86_64 kernels there is a known regression when
79421 + this feature and KVM/VMX are both enabled in the host kernel.
79422 +
79423 +choice
79424 + prompt "Return Address Instrumentation Method"
79425 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
79426 + depends on PAX_KERNEXEC_PLUGIN
79427 + help
79428 + Select the method used to instrument function pointer dereferences.
79429 + Note that binary modules cannot be instrumented by this approach.
79430 +
79431 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
79432 + bool "bts"
79433 + help
79434 + This method is compatible with binary only modules but has
79435 + a higher runtime overhead.
79436 +
79437 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
79438 + bool "or"
79439 + depends on !PARAVIRT
79440 + help
79441 + This method is incompatible with binary only modules but has
79442 + a lower runtime overhead.
79443 +endchoice
79444 +
79445 +config PAX_KERNEXEC_PLUGIN_METHOD
79446 + string
79447 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
79448 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
79449 + default ""
79450 +
79451 +config PAX_KERNEXEC_MODULE_TEXT
79452 + int "Minimum amount of memory reserved for module code"
79453 + default "4"
79454 + depends on PAX_KERNEXEC && X86_32 && MODULES
79455 + help
79456 + Due to implementation details the kernel must reserve a fixed
79457 + amount of memory for module code at compile time that cannot be
79458 + changed at runtime. Here you can specify the minimum amount
79459 + in MB that will be reserved. Due to the same implementation
79460 + details this size will always be rounded up to the next 2/4 MB
79461 + boundary (depends on PAE) so the actually available memory for
79462 + module code will usually be more than this minimum.
79463 +
79464 + The default 4 MB should be enough for most users but if you have
79465 + an excessive number of modules (e.g., most distribution configs
79466 + compile many drivers as modules) or use huge modules such as
79467 + nvidia's kernel driver, you will need to adjust this amount.
79468 + A good rule of thumb is to look at your currently loaded kernel
79469 + modules and add up their sizes.
79470 +
79471 +endmenu
79472 +
79473 +menu "Address Space Layout Randomization"
79474 + depends on PAX
79475 +
79476 +config PAX_ASLR
79477 + bool "Address Space Layout Randomization"
79478 + help
79479 + Many if not most exploit techniques rely on the knowledge of
79480 + certain addresses in the attacked program. The following options
79481 + will allow the kernel to apply a certain amount of randomization
79482 + to specific parts of the program thereby forcing an attacker to
79483 + guess them in most cases. Any failed guess will most likely crash
79484 + the attacked program which allows the kernel to detect such attempts
79485 + and react on them. PaX itself provides no reaction mechanisms,
79486 + instead it is strongly encouraged that you make use of Nergal's
79487 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79488 + (http://www.grsecurity.net/) built-in crash detection features or
79489 + develop one yourself.
79490 +
79491 + By saying Y here you can choose to randomize the following areas:
79492 + - top of the task's kernel stack
79493 + - top of the task's userland stack
79494 + - base address for mmap() requests that do not specify one
79495 + (this includes all libraries)
79496 + - base address of the main executable
79497 +
79498 + It is strongly recommended to say Y here as address space layout
79499 + randomization has negligible impact on performance yet it provides
79500 + a very effective protection.
79501 +
79502 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79503 + this feature on a per file basis.
79504 +
79505 +config PAX_RANDKSTACK
79506 + bool "Randomize kernel stack base"
79507 + depends on X86_TSC && X86
79508 + help
79509 + By saying Y here the kernel will randomize every task's kernel
79510 + stack on every system call. This will not only force an attacker
79511 + to guess it but also prevent him from making use of possible
79512 + leaked information about it.
79513 +
79514 + Since the kernel stack is a rather scarce resource, randomization
79515 + may cause unexpected stack overflows, therefore you should very
79516 + carefully test your system. Note that once enabled in the kernel
79517 + configuration, this feature cannot be disabled on a per file basis.
79518 +
79519 +config PAX_RANDUSTACK
79520 + bool "Randomize user stack base"
79521 + depends on PAX_ASLR
79522 + help
79523 + By saying Y here the kernel will randomize every task's userland
79524 + stack. The randomization is done in two steps where the second
79525 + one may apply a big amount of shift to the top of the stack and
79526 + cause problems for programs that want to use lots of memory (more
79527 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79528 + For this reason the second step can be controlled by 'chpax' or
79529 + 'paxctl' on a per file basis.
79530 +
79531 +config PAX_RANDMMAP
79532 + bool "Randomize mmap() base"
79533 + depends on PAX_ASLR
79534 + help
79535 + By saying Y here the kernel will use a randomized base address for
79536 + mmap() requests that do not specify one themselves. As a result
79537 + all dynamically loaded libraries will appear at random addresses
79538 + and therefore be harder to exploit by a technique where an attacker
79539 + attempts to execute library code for his purposes (e.g. spawn a
79540 + shell from an exploited program that is running at an elevated
79541 + privilege level).
79542 +
79543 + Furthermore, if a program is relinked as a dynamic ELF file, its
79544 + base address will be randomized as well, completing the full
79545 + randomization of the address space layout. Attacking such programs
79546 + becomes a guess game. You can find an example of doing this at
79547 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79548 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79549 +
79550 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79551 + feature on a per file basis.
79552 +
79553 +endmenu
79554 +
79555 +menu "Miscellaneous hardening features"
79556 +
79557 +config PAX_MEMORY_SANITIZE
79558 + bool "Sanitize all freed memory"
79559 + help
79560 + By saying Y here the kernel will erase memory pages as soon as they
79561 + are freed. This in turn reduces the lifetime of data stored in the
79562 + pages, making it less likely that sensitive information such as
79563 + passwords, cryptographic secrets, etc stay in memory for too long.
79564 +
79565 + This is especially useful for programs whose runtime is short, long
79566 + lived processes and the kernel itself benefit from this as long as
79567 + they operate on whole memory pages and ensure timely freeing of pages
79568 + that may hold sensitive information.
79569 +
79570 + The tradeoff is performance impact, on a single CPU system kernel
79571 + compilation sees a 3% slowdown, other systems and workloads may vary
79572 + and you are advised to test this feature on your expected workload
79573 + before deploying it.
79574 +
79575 + Note that this feature does not protect data stored in live pages,
79576 + e.g., process memory swapped to disk may stay there for a long time.
79577 +
79578 +config PAX_MEMORY_STACKLEAK
79579 + bool "Sanitize kernel stack"
79580 + depends on X86
79581 + help
79582 + By saying Y here the kernel will erase the kernel stack before it
79583 + returns from a system call. This in turn reduces the information
79584 + that a kernel stack leak bug can reveal.
79585 +
79586 + Note that such a bug can still leak information that was put on
79587 + the stack by the current system call (the one eventually triggering
79588 + the bug) but traces of earlier system calls on the kernel stack
79589 + cannot leak anymore.
79590 +
79591 + The tradeoff is performance impact: on a single CPU system kernel
79592 + compilation sees a 1% slowdown, other systems and workloads may vary
79593 + and you are advised to test this feature on your expected workload
79594 + before deploying it.
79595 +
79596 + Note: full support for this feature requires gcc with plugin support
79597 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
79598 + versions means that functions with large enough stack frames may
79599 + leave uninitialized memory behind that may be exposed to a later
79600 + syscall leaking the stack.
79601 +
79602 +config PAX_MEMORY_UDEREF
79603 + bool "Prevent invalid userland pointer dereference"
79604 + depends on X86 && !UML_X86 && !XEN
79605 + select PAX_PER_CPU_PGD if X86_64
79606 + help
79607 + By saying Y here the kernel will be prevented from dereferencing
79608 + userland pointers in contexts where the kernel expects only kernel
79609 + pointers. This is both a useful runtime debugging feature and a
79610 + security measure that prevents exploiting a class of kernel bugs.
79611 +
79612 + The tradeoff is that some virtualization solutions may experience
79613 + a huge slowdown and therefore you should not enable this feature
79614 + for kernels meant to run in such environments. Whether a given VM
79615 + solution is affected or not is best determined by simply trying it
79616 + out, the performance impact will be obvious right on boot as this
79617 + mechanism engages from very early on. A good rule of thumb is that
79618 + VMs running on CPUs without hardware virtualization support (i.e.,
79619 + the majority of IA-32 CPUs) will likely experience the slowdown.
79620 +
79621 +config PAX_REFCOUNT
79622 + bool "Prevent various kernel object reference counter overflows"
79623 + depends on GRKERNSEC && (X86 || SPARC64)
79624 + help
79625 + By saying Y here the kernel will detect and prevent overflowing
79626 + various (but not all) kinds of object reference counters. Such
79627 + overflows can normally occur due to bugs only and are often, if
79628 + not always, exploitable.
79629 +
79630 + The tradeoff is that data structures protected by an overflowed
79631 + refcount will never be freed and therefore will leak memory. Note
79632 + that this leak also happens even without this protection but in
79633 + that case the overflow can eventually trigger the freeing of the
79634 + data structure while it is still being used elsewhere, resulting
79635 + in the exploitable situation that this feature prevents.
79636 +
79637 + Since this has a negligible performance impact, you should enable
79638 + this feature.
79639 +
79640 +config PAX_USERCOPY
79641 + bool "Harden heap object copies between kernel and userland"
79642 + depends on X86 || PPC || SPARC || ARM
79643 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79644 + help
79645 + By saying Y here the kernel will enforce the size of heap objects
79646 + when they are copied in either direction between the kernel and
79647 + userland, even if only a part of the heap object is copied.
79648 +
79649 + Specifically, this checking prevents information leaking from the
79650 + kernel heap during kernel to userland copies (if the kernel heap
79651 + object is otherwise fully initialized) and prevents kernel heap
79652 + overflows during userland to kernel copies.
79653 +
79654 + Note that the current implementation provides the strictest bounds
79655 + checks for the SLUB allocator.
79656 +
79657 + Enabling this option also enables per-slab cache protection against
79658 + data in a given cache being copied into/out of via userland
79659 + accessors. Though the whitelist of regions will be reduced over
79660 + time, it notably protects important data structures like task structs.
79661 +
79662 + If frame pointers are enabled on x86, this option will also restrict
79663 + copies into and out of the kernel stack to local variables within a
79664 + single frame.
79665 +
79666 + Since this has a negligible performance impact, you should enable
79667 + this feature.
79668 +
79669 +endmenu
79670 +
79671 +endmenu
79672 +
79673 config KEYS
79674 bool "Enable access key retention support"
79675 help
79676 @@ -167,7 +787,7 @@ config INTEL_TXT
79677 config LSM_MMAP_MIN_ADDR
79678 int "Low address space for LSM to protect from user allocation"
79679 depends on SECURITY && SECURITY_SELINUX
79680 - default 32768 if ARM
79681 + default 32768 if ALPHA || ARM || PARISC || SPARC32
79682 default 65536
79683 help
79684 This is the portion of low virtual memory which should be protected
79685 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
79686 index 3783202..1852837 100644
79687 --- a/security/apparmor/lsm.c
79688 +++ b/security/apparmor/lsm.c
79689 @@ -621,7 +621,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
79690 return error;
79691 }
79692
79693 -static struct security_operations apparmor_ops = {
79694 +static struct security_operations apparmor_ops __read_only = {
79695 .name = "apparmor",
79696
79697 .ptrace_access_check = apparmor_ptrace_access_check,
79698 diff --git a/security/commoncap.c b/security/commoncap.c
79699 index a93b3b7..4410df9 100644
79700 --- a/security/commoncap.c
79701 +++ b/security/commoncap.c
79702 @@ -28,6 +28,7 @@
79703 #include <linux/prctl.h>
79704 #include <linux/securebits.h>
79705 #include <linux/user_namespace.h>
79706 +#include <net/sock.h>
79707
79708 /*
79709 * If a non-root user executes a setuid-root binary in
79710 @@ -58,7 +59,7 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
79711
79712 int cap_netlink_recv(struct sk_buff *skb, int cap)
79713 {
79714 - if (!cap_raised(current_cap(), cap))
79715 + if (!cap_raised(current_cap(), cap) || !gr_is_capable(cap))
79716 return -EPERM;
79717 return 0;
79718 }
79719 @@ -575,6 +576,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
79720 {
79721 const struct cred *cred = current_cred();
79722
79723 + if (gr_acl_enable_at_secure())
79724 + return 1;
79725 +
79726 if (cred->uid != 0) {
79727 if (bprm->cap_effective)
79728 return 1;
79729 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
79730 index 08408bd..67e6e78 100644
79731 --- a/security/integrity/ima/ima.h
79732 +++ b/security/integrity/ima/ima.h
79733 @@ -85,8 +85,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79734 extern spinlock_t ima_queue_lock;
79735
79736 struct ima_h_table {
79737 - atomic_long_t len; /* number of stored measurements in the list */
79738 - atomic_long_t violations;
79739 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79740 + atomic_long_unchecked_t violations;
79741 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79742 };
79743 extern struct ima_h_table ima_htable;
79744 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
79745 index da36d2c..e1e1965 100644
79746 --- a/security/integrity/ima/ima_api.c
79747 +++ b/security/integrity/ima/ima_api.c
79748 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79749 int result;
79750
79751 /* can overflow, only indicator */
79752 - atomic_long_inc(&ima_htable.violations);
79753 + atomic_long_inc_unchecked(&ima_htable.violations);
79754
79755 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79756 if (!entry) {
79757 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
79758 index ef21b96..d53e674 100644
79759 --- a/security/integrity/ima/ima_fs.c
79760 +++ b/security/integrity/ima/ima_fs.c
79761 @@ -28,12 +28,12 @@
79762 static int valid_policy = 1;
79763 #define TMPBUFLEN 12
79764 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79765 - loff_t *ppos, atomic_long_t *val)
79766 + loff_t *ppos, atomic_long_unchecked_t *val)
79767 {
79768 char tmpbuf[TMPBUFLEN];
79769 ssize_t len;
79770
79771 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79772 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79773 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79774 }
79775
79776 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
79777 index 8e28f04..d5951b1 100644
79778 --- a/security/integrity/ima/ima_queue.c
79779 +++ b/security/integrity/ima/ima_queue.c
79780 @@ -79,7 +79,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
79781 INIT_LIST_HEAD(&qe->later);
79782 list_add_tail_rcu(&qe->later, &ima_measurements);
79783
79784 - atomic_long_inc(&ima_htable.len);
79785 + atomic_long_inc_unchecked(&ima_htable.len);
79786 key = ima_hash_key(entry->digest);
79787 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
79788 return 0;
79789 diff --git a/security/keys/compat.c b/security/keys/compat.c
79790 index 338b510..a235861 100644
79791 --- a/security/keys/compat.c
79792 +++ b/security/keys/compat.c
79793 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
79794 if (ret == 0)
79795 goto no_payload_free;
79796
79797 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79798 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79799
79800 if (iov != iovstack)
79801 kfree(iov);
79802 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
79803 index eca5191..da9c7f0 100644
79804 --- a/security/keys/keyctl.c
79805 +++ b/security/keys/keyctl.c
79806 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
79807 /*
79808 * Copy the iovec data from userspace
79809 */
79810 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79811 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
79812 unsigned ioc)
79813 {
79814 for (; ioc > 0; ioc--) {
79815 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79816 * If successful, 0 will be returned.
79817 */
79818 long keyctl_instantiate_key_common(key_serial_t id,
79819 - const struct iovec *payload_iov,
79820 + const struct iovec __user *payload_iov,
79821 unsigned ioc,
79822 size_t plen,
79823 key_serial_t ringid)
79824 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
79825 [0].iov_len = plen
79826 };
79827
79828 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
79829 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
79830 }
79831
79832 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
79833 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
79834 if (ret == 0)
79835 goto no_payload_free;
79836
79837 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79838 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79839
79840 if (iov != iovstack)
79841 kfree(iov);
79842 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
79843 index 30e242f..ec111ab 100644
79844 --- a/security/keys/keyring.c
79845 +++ b/security/keys/keyring.c
79846 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
79847 ret = -EFAULT;
79848
79849 for (loop = 0; loop < klist->nkeys; loop++) {
79850 + key_serial_t serial;
79851 key = klist->keys[loop];
79852 + serial = key->serial;
79853
79854 tmp = sizeof(key_serial_t);
79855 if (tmp > buflen)
79856 tmp = buflen;
79857
79858 - if (copy_to_user(buffer,
79859 - &key->serial,
79860 - tmp) != 0)
79861 + if (copy_to_user(buffer, &serial, tmp))
79862 goto error;
79863
79864 buflen -= tmp;
79865 diff --git a/security/min_addr.c b/security/min_addr.c
79866 index f728728..6457a0c 100644
79867 --- a/security/min_addr.c
79868 +++ b/security/min_addr.c
79869 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
79870 */
79871 static void update_mmap_min_addr(void)
79872 {
79873 +#ifndef SPARC
79874 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
79875 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
79876 mmap_min_addr = dac_mmap_min_addr;
79877 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
79878 #else
79879 mmap_min_addr = dac_mmap_min_addr;
79880 #endif
79881 +#endif
79882 }
79883
79884 /*
79885 diff --git a/security/security.c b/security/security.c
79886 index d9e1533..91427f2 100644
79887 --- a/security/security.c
79888 +++ b/security/security.c
79889 @@ -25,8 +25,8 @@ static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
79890 /* things that live in capability.c */
79891 extern void __init security_fixup_ops(struct security_operations *ops);
79892
79893 -static struct security_operations *security_ops;
79894 -static struct security_operations default_security_ops = {
79895 +static struct security_operations *security_ops __read_only;
79896 +static struct security_operations default_security_ops __read_only = {
79897 .name = "default",
79898 };
79899
79900 @@ -67,7 +67,9 @@ int __init security_init(void)
79901
79902 void reset_security_ops(void)
79903 {
79904 + pax_open_kernel();
79905 security_ops = &default_security_ops;
79906 + pax_close_kernel();
79907 }
79908
79909 /* Save user chosen LSM */
79910 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
79911 index 266a229..61bd553 100644
79912 --- a/security/selinux/hooks.c
79913 +++ b/security/selinux/hooks.c
79914 @@ -93,7 +93,6 @@
79915 #define NUM_SEL_MNT_OPTS 5
79916
79917 extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm);
79918 -extern struct security_operations *security_ops;
79919
79920 /* SECMARK reference count */
79921 atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
79922 @@ -5455,7 +5454,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
79923
79924 #endif
79925
79926 -static struct security_operations selinux_ops = {
79927 +static struct security_operations selinux_ops __read_only = {
79928 .name = "selinux",
79929
79930 .ptrace_access_check = selinux_ptrace_access_check,
79931 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
79932 index b43813c..74be837 100644
79933 --- a/security/selinux/include/xfrm.h
79934 +++ b/security/selinux/include/xfrm.h
79935 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
79936
79937 static inline void selinux_xfrm_notify_policyload(void)
79938 {
79939 - atomic_inc(&flow_cache_genid);
79940 + atomic_inc_unchecked(&flow_cache_genid);
79941 }
79942 #else
79943 static inline int selinux_xfrm_enabled(void)
79944 diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
79945 index f6917bc..8e8713e 100644
79946 --- a/security/selinux/ss/services.c
79947 +++ b/security/selinux/ss/services.c
79948 @@ -1814,6 +1814,8 @@ int security_load_policy(void *data, size_t len)
79949 int rc = 0;
79950 struct policy_file file = { data, len }, *fp = &file;
79951
79952 + pax_track_stack();
79953 +
79954 if (!ss_initialized) {
79955 avtab_cache_init();
79956 rc = policydb_read(&policydb, fp);
79957 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
79958 index b9c5e14..20ab779 100644
79959 --- a/security/smack/smack_lsm.c
79960 +++ b/security/smack/smack_lsm.c
79961 @@ -3393,7 +3393,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
79962 return 0;
79963 }
79964
79965 -struct security_operations smack_ops = {
79966 +struct security_operations smack_ops __read_only = {
79967 .name = "smack",
79968
79969 .ptrace_access_check = smack_ptrace_access_check,
79970 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
79971 index f776400..f95b158c 100644
79972 --- a/security/tomoyo/tomoyo.c
79973 +++ b/security/tomoyo/tomoyo.c
79974 @@ -446,7 +446,7 @@ static int tomoyo_sb_pivotroot(struct path *old_path, struct path *new_path)
79975 * tomoyo_security_ops is a "struct security_operations" which is used for
79976 * registering TOMOYO.
79977 */
79978 -static struct security_operations tomoyo_security_ops = {
79979 +static struct security_operations tomoyo_security_ops __read_only = {
79980 .name = "tomoyo",
79981 .cred_alloc_blank = tomoyo_cred_alloc_blank,
79982 .cred_prepare = tomoyo_cred_prepare,
79983 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
79984 index 3687a6c..652565e 100644
79985 --- a/sound/aoa/codecs/onyx.c
79986 +++ b/sound/aoa/codecs/onyx.c
79987 @@ -54,7 +54,7 @@ struct onyx {
79988 spdif_locked:1,
79989 analog_locked:1,
79990 original_mute:2;
79991 - int open_count;
79992 + local_t open_count;
79993 struct codec_info *codec_info;
79994
79995 /* mutex serializes concurrent access to the device
79996 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
79997 struct onyx *onyx = cii->codec_data;
79998
79999 mutex_lock(&onyx->mutex);
80000 - onyx->open_count++;
80001 + local_inc(&onyx->open_count);
80002 mutex_unlock(&onyx->mutex);
80003
80004 return 0;
80005 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
80006 struct onyx *onyx = cii->codec_data;
80007
80008 mutex_lock(&onyx->mutex);
80009 - onyx->open_count--;
80010 - if (!onyx->open_count)
80011 + if (local_dec_and_test(&onyx->open_count))
80012 onyx->spdif_locked = onyx->analog_locked = 0;
80013 mutex_unlock(&onyx->mutex);
80014
80015 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
80016 index ffd2025..df062c9 100644
80017 --- a/sound/aoa/codecs/onyx.h
80018 +++ b/sound/aoa/codecs/onyx.h
80019 @@ -11,6 +11,7 @@
80020 #include <linux/i2c.h>
80021 #include <asm/pmac_low_i2c.h>
80022 #include <asm/prom.h>
80023 +#include <asm/local.h>
80024
80025 /* PCM3052 register definitions */
80026
80027 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
80028 index 23c34a0..a2673a5 100644
80029 --- a/sound/core/oss/pcm_oss.c
80030 +++ b/sound/core/oss/pcm_oss.c
80031 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
80032 if (in_kernel) {
80033 mm_segment_t fs;
80034 fs = snd_enter_user();
80035 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80036 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80037 snd_leave_user(fs);
80038 } else {
80039 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80040 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80041 }
80042 if (ret != -EPIPE && ret != -ESTRPIPE)
80043 break;
80044 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
80045 if (in_kernel) {
80046 mm_segment_t fs;
80047 fs = snd_enter_user();
80048 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80049 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80050 snd_leave_user(fs);
80051 } else {
80052 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80053 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80054 }
80055 if (ret == -EPIPE) {
80056 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
80057 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
80058 struct snd_pcm_plugin_channel *channels;
80059 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
80060 if (!in_kernel) {
80061 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
80062 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
80063 return -EFAULT;
80064 buf = runtime->oss.buffer;
80065 }
80066 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
80067 }
80068 } else {
80069 tmp = snd_pcm_oss_write2(substream,
80070 - (const char __force *)buf,
80071 + (const char __force_kernel *)buf,
80072 runtime->oss.period_bytes, 0);
80073 if (tmp <= 0)
80074 goto err;
80075 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
80076 struct snd_pcm_runtime *runtime = substream->runtime;
80077 snd_pcm_sframes_t frames, frames1;
80078 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
80079 - char __user *final_dst = (char __force __user *)buf;
80080 + char __user *final_dst = (char __force_user *)buf;
80081 if (runtime->oss.plugin_first) {
80082 struct snd_pcm_plugin_channel *channels;
80083 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
80084 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
80085 xfer += tmp;
80086 runtime->oss.buffer_used -= tmp;
80087 } else {
80088 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
80089 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
80090 runtime->oss.period_bytes, 0);
80091 if (tmp <= 0)
80092 goto err;
80093 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
80094 size1);
80095 size1 /= runtime->channels; /* frames */
80096 fs = snd_enter_user();
80097 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
80098 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
80099 snd_leave_user(fs);
80100 }
80101 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
80102 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
80103 index 91cdf94..4085161 100644
80104 --- a/sound/core/pcm_compat.c
80105 +++ b/sound/core/pcm_compat.c
80106 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
80107 int err;
80108
80109 fs = snd_enter_user();
80110 - err = snd_pcm_delay(substream, &delay);
80111 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
80112 snd_leave_user(fs);
80113 if (err < 0)
80114 return err;
80115 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
80116 index 1c6be91..c761a59 100644
80117 --- a/sound/core/pcm_native.c
80118 +++ b/sound/core/pcm_native.c
80119 @@ -2770,11 +2770,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
80120 switch (substream->stream) {
80121 case SNDRV_PCM_STREAM_PLAYBACK:
80122 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
80123 - (void __user *)arg);
80124 + (void __force_user *)arg);
80125 break;
80126 case SNDRV_PCM_STREAM_CAPTURE:
80127 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
80128 - (void __user *)arg);
80129 + (void __force_user *)arg);
80130 break;
80131 default:
80132 result = -EINVAL;
80133 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
80134 index 1f99767..14636533 100644
80135 --- a/sound/core/seq/seq_device.c
80136 +++ b/sound/core/seq/seq_device.c
80137 @@ -63,7 +63,7 @@ struct ops_list {
80138 int argsize; /* argument size */
80139
80140 /* operators */
80141 - struct snd_seq_dev_ops ops;
80142 + struct snd_seq_dev_ops *ops;
80143
80144 /* registred devices */
80145 struct list_head dev_list; /* list of devices */
80146 @@ -332,7 +332,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
80147
80148 mutex_lock(&ops->reg_mutex);
80149 /* copy driver operators */
80150 - ops->ops = *entry;
80151 + ops->ops = entry;
80152 ops->driver |= DRIVER_LOADED;
80153 ops->argsize = argsize;
80154
80155 @@ -462,7 +462,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
80156 dev->name, ops->id, ops->argsize, dev->argsize);
80157 return -EINVAL;
80158 }
80159 - if (ops->ops.init_device(dev) >= 0) {
80160 + if (ops->ops->init_device(dev) >= 0) {
80161 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
80162 ops->num_init_devices++;
80163 } else {
80164 @@ -489,7 +489,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
80165 dev->name, ops->id, ops->argsize, dev->argsize);
80166 return -EINVAL;
80167 }
80168 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
80169 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
80170 dev->status = SNDRV_SEQ_DEVICE_FREE;
80171 dev->driver_data = NULL;
80172 ops->num_init_devices--;
80173 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
80174 index 8539ab0..be8a121 100644
80175 --- a/sound/drivers/mts64.c
80176 +++ b/sound/drivers/mts64.c
80177 @@ -28,6 +28,7 @@
80178 #include <sound/initval.h>
80179 #include <sound/rawmidi.h>
80180 #include <sound/control.h>
80181 +#include <asm/local.h>
80182
80183 #define CARD_NAME "Miditerminal 4140"
80184 #define DRIVER_NAME "MTS64"
80185 @@ -66,7 +67,7 @@ struct mts64 {
80186 struct pardevice *pardev;
80187 int pardev_claimed;
80188
80189 - int open_count;
80190 + local_t open_count;
80191 int current_midi_output_port;
80192 int current_midi_input_port;
80193 u8 mode[MTS64_NUM_INPUT_PORTS];
80194 @@ -696,7 +697,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80195 {
80196 struct mts64 *mts = substream->rmidi->private_data;
80197
80198 - if (mts->open_count == 0) {
80199 + if (local_read(&mts->open_count) == 0) {
80200 /* We don't need a spinlock here, because this is just called
80201 if the device has not been opened before.
80202 So there aren't any IRQs from the device */
80203 @@ -704,7 +705,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80204
80205 msleep(50);
80206 }
80207 - ++(mts->open_count);
80208 + local_inc(&mts->open_count);
80209
80210 return 0;
80211 }
80212 @@ -714,8 +715,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80213 struct mts64 *mts = substream->rmidi->private_data;
80214 unsigned long flags;
80215
80216 - --(mts->open_count);
80217 - if (mts->open_count == 0) {
80218 + if (local_dec_return(&mts->open_count) == 0) {
80219 /* We need the spinlock_irqsave here because we can still
80220 have IRQs at this point */
80221 spin_lock_irqsave(&mts->lock, flags);
80222 @@ -724,8 +724,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80223
80224 msleep(500);
80225
80226 - } else if (mts->open_count < 0)
80227 - mts->open_count = 0;
80228 + } else if (local_read(&mts->open_count) < 0)
80229 + local_set(&mts->open_count, 0);
80230
80231 return 0;
80232 }
80233 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
80234 index f07e38d..7aae69a 100644
80235 --- a/sound/drivers/opl4/opl4_lib.c
80236 +++ b/sound/drivers/opl4/opl4_lib.c
80237 @@ -28,7 +28,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
80238 MODULE_DESCRIPTION("OPL4 driver");
80239 MODULE_LICENSE("GPL");
80240
80241 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
80242 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
80243 {
80244 int timeout = 10;
80245 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
80246 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
80247 index f2b0ba2..429efc5 100644
80248 --- a/sound/drivers/portman2x4.c
80249 +++ b/sound/drivers/portman2x4.c
80250 @@ -47,6 +47,7 @@
80251 #include <sound/initval.h>
80252 #include <sound/rawmidi.h>
80253 #include <sound/control.h>
80254 +#include <asm/local.h>
80255
80256 #define CARD_NAME "Portman 2x4"
80257 #define DRIVER_NAME "portman"
80258 @@ -84,7 +85,7 @@ struct portman {
80259 struct pardevice *pardev;
80260 int pardev_claimed;
80261
80262 - int open_count;
80263 + local_t open_count;
80264 int mode[PORTMAN_NUM_INPUT_PORTS];
80265 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
80266 };
80267 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
80268 index 87657dd..a8268d4 100644
80269 --- a/sound/firewire/amdtp.c
80270 +++ b/sound/firewire/amdtp.c
80271 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
80272 ptr = s->pcm_buffer_pointer + data_blocks;
80273 if (ptr >= pcm->runtime->buffer_size)
80274 ptr -= pcm->runtime->buffer_size;
80275 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
80276 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
80277
80278 s->pcm_period_pointer += data_blocks;
80279 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
80280 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
80281 */
80282 void amdtp_out_stream_update(struct amdtp_out_stream *s)
80283 {
80284 - ACCESS_ONCE(s->source_node_id_field) =
80285 + ACCESS_ONCE_RW(s->source_node_id_field) =
80286 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
80287 }
80288 EXPORT_SYMBOL(amdtp_out_stream_update);
80289 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
80290 index 537a9cb..8e8c8e9 100644
80291 --- a/sound/firewire/amdtp.h
80292 +++ b/sound/firewire/amdtp.h
80293 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
80294 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
80295 struct snd_pcm_substream *pcm)
80296 {
80297 - ACCESS_ONCE(s->pcm) = pcm;
80298 + ACCESS_ONCE_RW(s->pcm) = pcm;
80299 }
80300
80301 /**
80302 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
80303 index 4400308..261e9f3 100644
80304 --- a/sound/firewire/isight.c
80305 +++ b/sound/firewire/isight.c
80306 @@ -97,7 +97,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
80307 ptr += count;
80308 if (ptr >= runtime->buffer_size)
80309 ptr -= runtime->buffer_size;
80310 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
80311 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
80312
80313 isight->period_counter += count;
80314 if (isight->period_counter >= runtime->period_size) {
80315 @@ -308,7 +308,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
80316 if (err < 0)
80317 return err;
80318
80319 - ACCESS_ONCE(isight->pcm_active) = true;
80320 + ACCESS_ONCE_RW(isight->pcm_active) = true;
80321
80322 return 0;
80323 }
80324 @@ -341,7 +341,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
80325 {
80326 struct isight *isight = substream->private_data;
80327
80328 - ACCESS_ONCE(isight->pcm_active) = false;
80329 + ACCESS_ONCE_RW(isight->pcm_active) = false;
80330
80331 mutex_lock(&isight->mutex);
80332 isight_stop_streaming(isight);
80333 @@ -434,10 +434,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
80334
80335 switch (cmd) {
80336 case SNDRV_PCM_TRIGGER_START:
80337 - ACCESS_ONCE(isight->pcm_running) = true;
80338 + ACCESS_ONCE_RW(isight->pcm_running) = true;
80339 break;
80340 case SNDRV_PCM_TRIGGER_STOP:
80341 - ACCESS_ONCE(isight->pcm_running) = false;
80342 + ACCESS_ONCE_RW(isight->pcm_running) = false;
80343 break;
80344 default:
80345 return -EINVAL;
80346 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
80347 index fe79a16..4d9714e 100644
80348 --- a/sound/isa/cmi8330.c
80349 +++ b/sound/isa/cmi8330.c
80350 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
80351
80352 struct snd_pcm *pcm;
80353 struct snd_cmi8330_stream {
80354 - struct snd_pcm_ops ops;
80355 + snd_pcm_ops_no_const ops;
80356 snd_pcm_open_callback_t open;
80357 void *private_data; /* sb or wss */
80358 } streams[2];
80359 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
80360 index 733b014..56ce96f 100644
80361 --- a/sound/oss/sb_audio.c
80362 +++ b/sound/oss/sb_audio.c
80363 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
80364 buf16 = (signed short *)(localbuf + localoffs);
80365 while (c)
80366 {
80367 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80368 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80369 if (copy_from_user(lbuf8,
80370 userbuf+useroffs + p,
80371 locallen))
80372 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
80373 index 09d4648..cf234c7 100644
80374 --- a/sound/oss/swarm_cs4297a.c
80375 +++ b/sound/oss/swarm_cs4297a.c
80376 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
80377 {
80378 struct cs4297a_state *s;
80379 u32 pwr, id;
80380 - mm_segment_t fs;
80381 int rval;
80382 #ifndef CONFIG_BCM_CS4297A_CSWARM
80383 u64 cfg;
80384 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
80385 if (!rval) {
80386 char *sb1250_duart_present;
80387
80388 +#if 0
80389 + mm_segment_t fs;
80390 fs = get_fs();
80391 set_fs(KERNEL_DS);
80392 -#if 0
80393 val = SOUND_MASK_LINE;
80394 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
80395 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
80396 val = initvol[i].vol;
80397 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
80398 }
80399 + set_fs(fs);
80400 // cs4297a_write_ac97(s, 0x18, 0x0808);
80401 #else
80402 // cs4297a_write_ac97(s, 0x5e, 0x180);
80403 cs4297a_write_ac97(s, 0x02, 0x0808);
80404 cs4297a_write_ac97(s, 0x18, 0x0808);
80405 #endif
80406 - set_fs(fs);
80407
80408 list_add(&s->list, &cs4297a_devs);
80409
80410 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
80411 index 755f2b0..5c12361 100644
80412 --- a/sound/pci/hda/hda_codec.h
80413 +++ b/sound/pci/hda/hda_codec.h
80414 @@ -611,7 +611,7 @@ struct hda_bus_ops {
80415 /* notify power-up/down from codec to controller */
80416 void (*pm_notify)(struct hda_bus *bus);
80417 #endif
80418 -};
80419 +} __no_const;
80420
80421 /* template to pass to the bus constructor */
80422 struct hda_bus_template {
80423 @@ -713,6 +713,7 @@ struct hda_codec_ops {
80424 #endif
80425 void (*reboot_notify)(struct hda_codec *codec);
80426 };
80427 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
80428
80429 /* record for amp information cache */
80430 struct hda_cache_head {
80431 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
80432 struct snd_pcm_substream *substream);
80433 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
80434 struct snd_pcm_substream *substream);
80435 -};
80436 +} __no_const;
80437
80438 /* PCM information for each substream */
80439 struct hda_pcm_stream {
80440 @@ -801,7 +802,7 @@ struct hda_codec {
80441 const char *modelname; /* model name for preset */
80442
80443 /* set by patch */
80444 - struct hda_codec_ops patch_ops;
80445 + hda_codec_ops_no_const patch_ops;
80446
80447 /* PCM to create, set by patch_ops.build_pcms callback */
80448 unsigned int num_pcms;
80449 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
80450 index 0da778a..bc38b84 100644
80451 --- a/sound/pci/ice1712/ice1712.h
80452 +++ b/sound/pci/ice1712/ice1712.h
80453 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
80454 unsigned int mask_flags; /* total mask bits */
80455 struct snd_akm4xxx_ops {
80456 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
80457 - } ops;
80458 + } __no_const ops;
80459 };
80460
80461 struct snd_ice1712_spdif {
80462 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
80463 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80464 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80465 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80466 - } ops;
80467 + } __no_const ops;
80468 };
80469
80470
80471 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
80472 index f3260e6..4a285d8 100644
80473 --- a/sound/pci/ymfpci/ymfpci_main.c
80474 +++ b/sound/pci/ymfpci/ymfpci_main.c
80475 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
80476 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
80477 break;
80478 }
80479 - if (atomic_read(&chip->interrupt_sleep_count)) {
80480 - atomic_set(&chip->interrupt_sleep_count, 0);
80481 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80482 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80483 wake_up(&chip->interrupt_sleep);
80484 }
80485 __end:
80486 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
80487 continue;
80488 init_waitqueue_entry(&wait, current);
80489 add_wait_queue(&chip->interrupt_sleep, &wait);
80490 - atomic_inc(&chip->interrupt_sleep_count);
80491 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
80492 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
80493 remove_wait_queue(&chip->interrupt_sleep, &wait);
80494 }
80495 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
80496 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
80497 spin_unlock(&chip->reg_lock);
80498
80499 - if (atomic_read(&chip->interrupt_sleep_count)) {
80500 - atomic_set(&chip->interrupt_sleep_count, 0);
80501 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80502 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80503 wake_up(&chip->interrupt_sleep);
80504 }
80505 }
80506 @@ -2363,7 +2363,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
80507 spin_lock_init(&chip->reg_lock);
80508 spin_lock_init(&chip->voice_lock);
80509 init_waitqueue_head(&chip->interrupt_sleep);
80510 - atomic_set(&chip->interrupt_sleep_count, 0);
80511 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80512 chip->card = card;
80513 chip->pci = pci;
80514 chip->irq = -1;
80515 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
80516 index 2879c88..224159e 100644
80517 --- a/sound/soc/soc-pcm.c
80518 +++ b/sound/soc/soc-pcm.c
80519 @@ -568,7 +568,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
80520 }
80521
80522 /* ASoC PCM operations */
80523 -static struct snd_pcm_ops soc_pcm_ops = {
80524 +static snd_pcm_ops_no_const soc_pcm_ops = {
80525 .open = soc_pcm_open,
80526 .close = soc_pcm_close,
80527 .hw_params = soc_pcm_hw_params,
80528 diff --git a/sound/usb/card.h b/sound/usb/card.h
80529 index ae4251d..0961361 100644
80530 --- a/sound/usb/card.h
80531 +++ b/sound/usb/card.h
80532 @@ -44,6 +44,7 @@ struct snd_urb_ops {
80533 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80534 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80535 };
80536 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
80537
80538 struct snd_usb_substream {
80539 struct snd_usb_stream *stream;
80540 @@ -93,7 +94,7 @@ struct snd_usb_substream {
80541 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
80542 spinlock_t lock;
80543
80544 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
80545 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
80546 };
80547
80548 struct snd_usb_stream {
80549 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
80550 new file mode 100644
80551 index 0000000..b044b80
80552 --- /dev/null
80553 +++ b/tools/gcc/Makefile
80554 @@ -0,0 +1,21 @@
80555 +#CC := gcc
80556 +#PLUGIN_SOURCE_FILES := pax_plugin.c
80557 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
80558 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
80559 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W
80560 +
80561 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include
80562 +
80563 +hostlibs-y := constify_plugin.so
80564 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
80565 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
80566 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
80567 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
80568 +
80569 +always := $(hostlibs-y)
80570 +
80571 +constify_plugin-objs := constify_plugin.o
80572 +stackleak_plugin-objs := stackleak_plugin.o
80573 +kallocstat_plugin-objs := kallocstat_plugin.o
80574 +kernexec_plugin-objs := kernexec_plugin.o
80575 +checker_plugin-objs := checker_plugin.o
80576 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
80577 new file mode 100644
80578 index 0000000..d41b5af
80579 --- /dev/null
80580 +++ b/tools/gcc/checker_plugin.c
80581 @@ -0,0 +1,171 @@
80582 +/*
80583 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80584 + * Licensed under the GPL v2
80585 + *
80586 + * Note: the choice of the license means that the compilation process is
80587 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80588 + * but for the kernel it doesn't matter since it doesn't link against
80589 + * any of the gcc libraries
80590 + *
80591 + * gcc plugin to implement various sparse (source code checker) features
80592 + *
80593 + * TODO:
80594 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
80595 + *
80596 + * BUGS:
80597 + * - none known
80598 + */
80599 +#include "gcc-plugin.h"
80600 +#include "config.h"
80601 +#include "system.h"
80602 +#include "coretypes.h"
80603 +#include "tree.h"
80604 +#include "tree-pass.h"
80605 +#include "flags.h"
80606 +#include "intl.h"
80607 +#include "toplev.h"
80608 +#include "plugin.h"
80609 +//#include "expr.h" where are you...
80610 +#include "diagnostic.h"
80611 +#include "plugin-version.h"
80612 +#include "tm.h"
80613 +#include "function.h"
80614 +#include "basic-block.h"
80615 +#include "gimple.h"
80616 +#include "rtl.h"
80617 +#include "emit-rtl.h"
80618 +#include "tree-flow.h"
80619 +#include "target.h"
80620 +
80621 +extern void c_register_addr_space (const char *str, addr_space_t as);
80622 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
80623 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
80624 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
80625 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
80626 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
80627 +
80628 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80629 +extern rtx emit_move_insn(rtx x, rtx y);
80630 +
80631 +int plugin_is_GPL_compatible;
80632 +
80633 +static struct plugin_info checker_plugin_info = {
80634 + .version = "201111150100",
80635 +};
80636 +
80637 +#define ADDR_SPACE_KERNEL 0
80638 +#define ADDR_SPACE_FORCE_KERNEL 1
80639 +#define ADDR_SPACE_USER 2
80640 +#define ADDR_SPACE_FORCE_USER 3
80641 +#define ADDR_SPACE_IOMEM 0
80642 +#define ADDR_SPACE_FORCE_IOMEM 0
80643 +#define ADDR_SPACE_PERCPU 0
80644 +#define ADDR_SPACE_FORCE_PERCPU 0
80645 +#define ADDR_SPACE_RCU 0
80646 +#define ADDR_SPACE_FORCE_RCU 0
80647 +
80648 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
80649 +{
80650 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
80651 +}
80652 +
80653 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
80654 +{
80655 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
80656 +}
80657 +
80658 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
80659 +{
80660 + return default_addr_space_valid_pointer_mode(mode, as);
80661 +}
80662 +
80663 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
80664 +{
80665 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
80666 +}
80667 +
80668 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
80669 +{
80670 + return default_addr_space_legitimize_address(x, oldx, mode, as);
80671 +}
80672 +
80673 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
80674 +{
80675 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
80676 + return true;
80677 +
80678 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
80679 + return true;
80680 +
80681 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
80682 + return true;
80683 +
80684 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
80685 + return true;
80686 +
80687 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
80688 + return true;
80689 +
80690 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
80691 + return true;
80692 +
80693 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
80694 + return true;
80695 +
80696 + return subset == superset;
80697 +}
80698 +
80699 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
80700 +{
80701 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
80702 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
80703 +
80704 + return op;
80705 +}
80706 +
80707 +static void register_checker_address_spaces(void *event_data, void *data)
80708 +{
80709 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
80710 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
80711 + c_register_addr_space("__user", ADDR_SPACE_USER);
80712 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
80713 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
80714 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
80715 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
80716 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
80717 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
80718 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
80719 +
80720 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
80721 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
80722 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
80723 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
80724 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
80725 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
80726 + targetm.addr_space.convert = checker_addr_space_convert;
80727 +}
80728 +
80729 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80730 +{
80731 + const char * const plugin_name = plugin_info->base_name;
80732 + const int argc = plugin_info->argc;
80733 + const struct plugin_argument * const argv = plugin_info->argv;
80734 + int i;
80735 +
80736 + if (!plugin_default_version_check(version, &gcc_version)) {
80737 + error(G_("incompatible gcc/plugin versions"));
80738 + return 1;
80739 + }
80740 +
80741 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
80742 +
80743 + for (i = 0; i < argc; ++i)
80744 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80745 +
80746 + if (TARGET_64BIT == 0)
80747 + return 0;
80748 +
80749 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
80750 +
80751 + return 0;
80752 +}
80753 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
80754 new file mode 100644
80755 index 0000000..704a564
80756 --- /dev/null
80757 +++ b/tools/gcc/constify_plugin.c
80758 @@ -0,0 +1,303 @@
80759 +/*
80760 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
80761 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
80762 + * Licensed under the GPL v2, or (at your option) v3
80763 + *
80764 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
80765 + *
80766 + * Homepage:
80767 + * http://www.grsecurity.net/~ephox/const_plugin/
80768 + *
80769 + * Usage:
80770 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
80771 + * $ gcc -fplugin=constify_plugin.so test.c -O2
80772 + */
80773 +
80774 +#include "gcc-plugin.h"
80775 +#include "config.h"
80776 +#include "system.h"
80777 +#include "coretypes.h"
80778 +#include "tree.h"
80779 +#include "tree-pass.h"
80780 +#include "flags.h"
80781 +#include "intl.h"
80782 +#include "toplev.h"
80783 +#include "plugin.h"
80784 +#include "diagnostic.h"
80785 +#include "plugin-version.h"
80786 +#include "tm.h"
80787 +#include "function.h"
80788 +#include "basic-block.h"
80789 +#include "gimple.h"
80790 +#include "rtl.h"
80791 +#include "emit-rtl.h"
80792 +#include "tree-flow.h"
80793 +
80794 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
80795 +
80796 +int plugin_is_GPL_compatible;
80797 +
80798 +static struct plugin_info const_plugin_info = {
80799 + .version = "201111150100",
80800 + .help = "no-constify\tturn off constification\n",
80801 +};
80802 +
80803 +static void constify_type(tree type);
80804 +static bool walk_struct(tree node);
80805 +
80806 +static tree deconstify_type(tree old_type)
80807 +{
80808 + tree new_type, field;
80809 +
80810 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
80811 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
80812 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
80813 + DECL_FIELD_CONTEXT(field) = new_type;
80814 + TYPE_READONLY(new_type) = 0;
80815 + C_TYPE_FIELDS_READONLY(new_type) = 0;
80816 + return new_type;
80817 +}
80818 +
80819 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80820 +{
80821 + tree type;
80822 +
80823 + *no_add_attrs = true;
80824 + if (TREE_CODE(*node) == FUNCTION_DECL) {
80825 + error("%qE attribute does not apply to functions", name);
80826 + return NULL_TREE;
80827 + }
80828 +
80829 + if (TREE_CODE(*node) == VAR_DECL) {
80830 + error("%qE attribute does not apply to variables", name);
80831 + return NULL_TREE;
80832 + }
80833 +
80834 + if (TYPE_P(*node)) {
80835 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
80836 + *no_add_attrs = false;
80837 + else
80838 + error("%qE attribute applies to struct and union types only", name);
80839 + return NULL_TREE;
80840 + }
80841 +
80842 + type = TREE_TYPE(*node);
80843 +
80844 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
80845 + error("%qE attribute applies to struct and union types only", name);
80846 + return NULL_TREE;
80847 + }
80848 +
80849 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
80850 + error("%qE attribute is already applied to the type", name);
80851 + return NULL_TREE;
80852 + }
80853 +
80854 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
80855 + error("%qE attribute used on type that is not constified", name);
80856 + return NULL_TREE;
80857 + }
80858 +
80859 + if (TREE_CODE(*node) == TYPE_DECL) {
80860 + TREE_TYPE(*node) = deconstify_type(type);
80861 + TREE_READONLY(*node) = 0;
80862 + return NULL_TREE;
80863 + }
80864 +
80865 + return NULL_TREE;
80866 +}
80867 +
80868 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80869 +{
80870 + *no_add_attrs = true;
80871 + if (!TYPE_P(*node)) {
80872 + error("%qE attribute applies to types only", name);
80873 + return NULL_TREE;
80874 + }
80875 +
80876 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
80877 + error("%qE attribute applies to struct and union types only", name);
80878 + return NULL_TREE;
80879 + }
80880 +
80881 + *no_add_attrs = false;
80882 + constify_type(*node);
80883 + return NULL_TREE;
80884 +}
80885 +
80886 +static struct attribute_spec no_const_attr = {
80887 + .name = "no_const",
80888 + .min_length = 0,
80889 + .max_length = 0,
80890 + .decl_required = false,
80891 + .type_required = false,
80892 + .function_type_required = false,
80893 + .handler = handle_no_const_attribute,
80894 +#if BUILDING_GCC_VERSION >= 4007
80895 + .affects_type_identity = true
80896 +#endif
80897 +};
80898 +
80899 +static struct attribute_spec do_const_attr = {
80900 + .name = "do_const",
80901 + .min_length = 0,
80902 + .max_length = 0,
80903 + .decl_required = false,
80904 + .type_required = false,
80905 + .function_type_required = false,
80906 + .handler = handle_do_const_attribute,
80907 +#if BUILDING_GCC_VERSION >= 4007
80908 + .affects_type_identity = true
80909 +#endif
80910 +};
80911 +
80912 +static void register_attributes(void *event_data, void *data)
80913 +{
80914 + register_attribute(&no_const_attr);
80915 + register_attribute(&do_const_attr);
80916 +}
80917 +
80918 +static void constify_type(tree type)
80919 +{
80920 + TYPE_READONLY(type) = 1;
80921 + C_TYPE_FIELDS_READONLY(type) = 1;
80922 +}
80923 +
80924 +static bool is_fptr(tree field)
80925 +{
80926 + tree ptr = TREE_TYPE(field);
80927 +
80928 + if (TREE_CODE(ptr) != POINTER_TYPE)
80929 + return false;
80930 +
80931 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
80932 +}
80933 +
80934 +static bool walk_struct(tree node)
80935 +{
80936 + tree field;
80937 +
80938 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
80939 + return false;
80940 +
80941 + if (TYPE_FIELDS(node) == NULL_TREE)
80942 + return false;
80943 +
80944 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
80945 + tree type = TREE_TYPE(field);
80946 + enum tree_code code = TREE_CODE(type);
80947 + if (code == RECORD_TYPE || code == UNION_TYPE) {
80948 + if (!(walk_struct(type)))
80949 + return false;
80950 + } else if (!is_fptr(field) && !TREE_READONLY(field))
80951 + return false;
80952 + }
80953 + return true;
80954 +}
80955 +
80956 +static void finish_type(void *event_data, void *data)
80957 +{
80958 + tree type = (tree)event_data;
80959 +
80960 + if (type == NULL_TREE)
80961 + return;
80962 +
80963 + if (TYPE_READONLY(type))
80964 + return;
80965 +
80966 + if (walk_struct(type))
80967 + constify_type(type);
80968 +}
80969 +
80970 +static unsigned int check_local_variables(void);
80971 +
80972 +struct gimple_opt_pass pass_local_variable = {
80973 + {
80974 + .type = GIMPLE_PASS,
80975 + .name = "check_local_variables",
80976 + .gate = NULL,
80977 + .execute = check_local_variables,
80978 + .sub = NULL,
80979 + .next = NULL,
80980 + .static_pass_number = 0,
80981 + .tv_id = TV_NONE,
80982 + .properties_required = 0,
80983 + .properties_provided = 0,
80984 + .properties_destroyed = 0,
80985 + .todo_flags_start = 0,
80986 + .todo_flags_finish = 0
80987 + }
80988 +};
80989 +
80990 +static unsigned int check_local_variables(void)
80991 +{
80992 + tree var;
80993 + referenced_var_iterator rvi;
80994 +
80995 +#if BUILDING_GCC_VERSION == 4005
80996 + FOR_EACH_REFERENCED_VAR(var, rvi) {
80997 +#else
80998 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
80999 +#endif
81000 + tree type = TREE_TYPE(var);
81001 +
81002 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
81003 + continue;
81004 +
81005 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81006 + continue;
81007 +
81008 + if (!TYPE_READONLY(type))
81009 + continue;
81010 +
81011 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
81012 +// continue;
81013 +
81014 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
81015 +// continue;
81016 +
81017 + if (walk_struct(type)) {
81018 + error("constified variable %qE cannot be local", var);
81019 + return 1;
81020 + }
81021 + }
81022 + return 0;
81023 +}
81024 +
81025 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81026 +{
81027 + const char * const plugin_name = plugin_info->base_name;
81028 + const int argc = plugin_info->argc;
81029 + const struct plugin_argument * const argv = plugin_info->argv;
81030 + int i;
81031 + bool constify = true;
81032 +
81033 + struct register_pass_info local_variable_pass_info = {
81034 + .pass = &pass_local_variable.pass,
81035 + .reference_pass_name = "*referenced_vars",
81036 + .ref_pass_instance_number = 0,
81037 + .pos_op = PASS_POS_INSERT_AFTER
81038 + };
81039 +
81040 + if (!plugin_default_version_check(version, &gcc_version)) {
81041 + error(G_("incompatible gcc/plugin versions"));
81042 + return 1;
81043 + }
81044 +
81045 + for (i = 0; i < argc; ++i) {
81046 + if (!(strcmp(argv[i].key, "no-constify"))) {
81047 + constify = false;
81048 + continue;
81049 + }
81050 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81051 + }
81052 +
81053 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
81054 + if (constify) {
81055 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
81056 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
81057 + }
81058 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
81059 +
81060 + return 0;
81061 +}
81062 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
81063 new file mode 100644
81064 index 0000000..a5eabce
81065 --- /dev/null
81066 +++ b/tools/gcc/kallocstat_plugin.c
81067 @@ -0,0 +1,167 @@
81068 +/*
81069 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81070 + * Licensed under the GPL v2
81071 + *
81072 + * Note: the choice of the license means that the compilation process is
81073 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81074 + * but for the kernel it doesn't matter since it doesn't link against
81075 + * any of the gcc libraries
81076 + *
81077 + * gcc plugin to find the distribution of k*alloc sizes
81078 + *
81079 + * TODO:
81080 + *
81081 + * BUGS:
81082 + * - none known
81083 + */
81084 +#include "gcc-plugin.h"
81085 +#include "config.h"
81086 +#include "system.h"
81087 +#include "coretypes.h"
81088 +#include "tree.h"
81089 +#include "tree-pass.h"
81090 +#include "flags.h"
81091 +#include "intl.h"
81092 +#include "toplev.h"
81093 +#include "plugin.h"
81094 +//#include "expr.h" where are you...
81095 +#include "diagnostic.h"
81096 +#include "plugin-version.h"
81097 +#include "tm.h"
81098 +#include "function.h"
81099 +#include "basic-block.h"
81100 +#include "gimple.h"
81101 +#include "rtl.h"
81102 +#include "emit-rtl.h"
81103 +
81104 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81105 +
81106 +int plugin_is_GPL_compatible;
81107 +
81108 +static const char * const kalloc_functions[] = {
81109 + "__kmalloc",
81110 + "kmalloc",
81111 + "kmalloc_large",
81112 + "kmalloc_node",
81113 + "kmalloc_order",
81114 + "kmalloc_order_trace",
81115 + "kmalloc_slab",
81116 + "kzalloc",
81117 + "kzalloc_node",
81118 +};
81119 +
81120 +static struct plugin_info kallocstat_plugin_info = {
81121 + .version = "201111150100",
81122 +};
81123 +
81124 +static unsigned int execute_kallocstat(void);
81125 +
81126 +static struct gimple_opt_pass kallocstat_pass = {
81127 + .pass = {
81128 + .type = GIMPLE_PASS,
81129 + .name = "kallocstat",
81130 + .gate = NULL,
81131 + .execute = execute_kallocstat,
81132 + .sub = NULL,
81133 + .next = NULL,
81134 + .static_pass_number = 0,
81135 + .tv_id = TV_NONE,
81136 + .properties_required = 0,
81137 + .properties_provided = 0,
81138 + .properties_destroyed = 0,
81139 + .todo_flags_start = 0,
81140 + .todo_flags_finish = 0
81141 + }
81142 +};
81143 +
81144 +static bool is_kalloc(const char *fnname)
81145 +{
81146 + size_t i;
81147 +
81148 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
81149 + if (!strcmp(fnname, kalloc_functions[i]))
81150 + return true;
81151 + return false;
81152 +}
81153 +
81154 +static unsigned int execute_kallocstat(void)
81155 +{
81156 + basic_block bb;
81157 +
81158 + // 1. loop through BBs and GIMPLE statements
81159 + FOR_EACH_BB(bb) {
81160 + gimple_stmt_iterator gsi;
81161 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81162 + // gimple match:
81163 + tree fndecl, size;
81164 + gimple call_stmt;
81165 + const char *fnname;
81166 +
81167 + // is it a call
81168 + call_stmt = gsi_stmt(gsi);
81169 + if (!is_gimple_call(call_stmt))
81170 + continue;
81171 + fndecl = gimple_call_fndecl(call_stmt);
81172 + if (fndecl == NULL_TREE)
81173 + continue;
81174 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
81175 + continue;
81176 +
81177 + // is it a call to k*alloc
81178 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
81179 + if (!is_kalloc(fnname))
81180 + continue;
81181 +
81182 + // is the size arg the result of a simple const assignment
81183 + size = gimple_call_arg(call_stmt, 0);
81184 + while (true) {
81185 + gimple def_stmt;
81186 + expanded_location xloc;
81187 + size_t size_val;
81188 +
81189 + if (TREE_CODE(size) != SSA_NAME)
81190 + break;
81191 + def_stmt = SSA_NAME_DEF_STMT(size);
81192 + if (!def_stmt || !is_gimple_assign(def_stmt))
81193 + break;
81194 + if (gimple_num_ops(def_stmt) != 2)
81195 + break;
81196 + size = gimple_assign_rhs1(def_stmt);
81197 + if (!TREE_CONSTANT(size))
81198 + continue;
81199 + xloc = expand_location(gimple_location(def_stmt));
81200 + if (!xloc.file)
81201 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
81202 + size_val = TREE_INT_CST_LOW(size);
81203 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
81204 + break;
81205 + }
81206 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81207 +//debug_tree(gimple_call_fn(call_stmt));
81208 +//print_node(stderr, "pax", fndecl, 4);
81209 + }
81210 + }
81211 +
81212 + return 0;
81213 +}
81214 +
81215 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81216 +{
81217 + const char * const plugin_name = plugin_info->base_name;
81218 + struct register_pass_info kallocstat_pass_info = {
81219 + .pass = &kallocstat_pass.pass,
81220 + .reference_pass_name = "ssa",
81221 + .ref_pass_instance_number = 0,
81222 + .pos_op = PASS_POS_INSERT_AFTER
81223 + };
81224 +
81225 + if (!plugin_default_version_check(version, &gcc_version)) {
81226 + error(G_("incompatible gcc/plugin versions"));
81227 + return 1;
81228 + }
81229 +
81230 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
81231 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
81232 +
81233 + return 0;
81234 +}
81235 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
81236 new file mode 100644
81237 index 0000000..51f747e
81238 --- /dev/null
81239 +++ b/tools/gcc/kernexec_plugin.c
81240 @@ -0,0 +1,348 @@
81241 +/*
81242 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81243 + * Licensed under the GPL v2
81244 + *
81245 + * Note: the choice of the license means that the compilation process is
81246 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81247 + * but for the kernel it doesn't matter since it doesn't link against
81248 + * any of the gcc libraries
81249 + *
81250 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
81251 + *
81252 + * TODO:
81253 + *
81254 + * BUGS:
81255 + * - none known
81256 + */
81257 +#include "gcc-plugin.h"
81258 +#include "config.h"
81259 +#include "system.h"
81260 +#include "coretypes.h"
81261 +#include "tree.h"
81262 +#include "tree-pass.h"
81263 +#include "flags.h"
81264 +#include "intl.h"
81265 +#include "toplev.h"
81266 +#include "plugin.h"
81267 +//#include "expr.h" where are you...
81268 +#include "diagnostic.h"
81269 +#include "plugin-version.h"
81270 +#include "tm.h"
81271 +#include "function.h"
81272 +#include "basic-block.h"
81273 +#include "gimple.h"
81274 +#include "rtl.h"
81275 +#include "emit-rtl.h"
81276 +#include "tree-flow.h"
81277 +
81278 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81279 +extern rtx emit_move_insn(rtx x, rtx y);
81280 +
81281 +int plugin_is_GPL_compatible;
81282 +
81283 +static struct plugin_info kernexec_plugin_info = {
81284 + .version = "201111291120",
81285 + .help = "method=[bts|or]\tinstrumentation method\n"
81286 +};
81287 +
81288 +static unsigned int execute_kernexec_fptr(void);
81289 +static unsigned int execute_kernexec_retaddr(void);
81290 +static bool kernexec_cmodel_check(void);
81291 +
81292 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator);
81293 +static void (*kernexec_instrument_retaddr)(rtx);
81294 +
81295 +static struct gimple_opt_pass kernexec_fptr_pass = {
81296 + .pass = {
81297 + .type = GIMPLE_PASS,
81298 + .name = "kernexec_fptr",
81299 + .gate = kernexec_cmodel_check,
81300 + .execute = execute_kernexec_fptr,
81301 + .sub = NULL,
81302 + .next = NULL,
81303 + .static_pass_number = 0,
81304 + .tv_id = TV_NONE,
81305 + .properties_required = 0,
81306 + .properties_provided = 0,
81307 + .properties_destroyed = 0,
81308 + .todo_flags_start = 0,
81309 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81310 + }
81311 +};
81312 +
81313 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81314 + .pass = {
81315 + .type = RTL_PASS,
81316 + .name = "kernexec_retaddr",
81317 + .gate = kernexec_cmodel_check,
81318 + .execute = execute_kernexec_retaddr,
81319 + .sub = NULL,
81320 + .next = NULL,
81321 + .static_pass_number = 0,
81322 + .tv_id = TV_NONE,
81323 + .properties_required = 0,
81324 + .properties_provided = 0,
81325 + .properties_destroyed = 0,
81326 + .todo_flags_start = 0,
81327 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81328 + }
81329 +};
81330 +
81331 +static bool kernexec_cmodel_check(void)
81332 +{
81333 + tree section;
81334 +
81335 + if (ix86_cmodel != CM_KERNEL)
81336 + return false;
81337 +
81338 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
81339 + if (!section || !TREE_VALUE(section))
81340 + return true;
81341 +
81342 + section = TREE_VALUE(TREE_VALUE(section));
81343 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
81344 + return true;
81345 +
81346 + return false;
81347 +}
81348 +
81349 +/*
81350 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
81351 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
81352 + */
81353 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator gsi)
81354 +{
81355 + gimple assign_intptr, assign_new_fptr, call_stmt;
81356 + tree intptr, old_fptr, new_fptr, kernexec_mask;
81357 +
81358 + call_stmt = gsi_stmt(gsi);
81359 + old_fptr = gimple_call_fn(call_stmt);
81360 +
81361 + // create temporary unsigned long variable used for bitops and cast fptr to it
81362 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
81363 + add_referenced_var(intptr);
81364 + mark_sym_for_renaming(intptr);
81365 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
81366 + gsi_insert_before(&gsi, assign_intptr, GSI_SAME_STMT);
81367 + update_stmt(assign_intptr);
81368 +
81369 + // apply logical or to temporary unsigned long and bitmask
81370 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
81371 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
81372 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
81373 + gsi_insert_before(&gsi, assign_intptr, GSI_SAME_STMT);
81374 + update_stmt(assign_intptr);
81375 +
81376 + // cast temporary unsigned long back to a temporary fptr variable
81377 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec");
81378 + add_referenced_var(new_fptr);
81379 + mark_sym_for_renaming(new_fptr);
81380 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
81381 + gsi_insert_before(&gsi, assign_new_fptr, GSI_SAME_STMT);
81382 + update_stmt(assign_new_fptr);
81383 +
81384 + // replace call stmt fn with the new fptr
81385 + gimple_call_set_fn(call_stmt, new_fptr);
81386 + update_stmt(call_stmt);
81387 +}
81388 +
81389 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator gsi)
81390 +{
81391 + gimple asm_or_stmt, call_stmt;
81392 + tree old_fptr, new_fptr, input, output;
81393 + VEC(tree, gc) *inputs = NULL;
81394 + VEC(tree, gc) *outputs = NULL;
81395 +
81396 + call_stmt = gsi_stmt(gsi);
81397 + old_fptr = gimple_call_fn(call_stmt);
81398 +
81399 + // create temporary fptr variable
81400 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
81401 + add_referenced_var(new_fptr);
81402 + mark_sym_for_renaming(new_fptr);
81403 +
81404 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
81405 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
81406 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
81407 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
81408 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
81409 + VEC_safe_push(tree, gc, inputs, input);
81410 + VEC_safe_push(tree, gc, outputs, output);
81411 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
81412 + gimple_asm_set_volatile(asm_or_stmt, true);
81413 + gsi_insert_before(&gsi, asm_or_stmt, GSI_SAME_STMT);
81414 + update_stmt(asm_or_stmt);
81415 +
81416 + // replace call stmt fn with the new fptr
81417 + gimple_call_set_fn(call_stmt, new_fptr);
81418 + update_stmt(call_stmt);
81419 +}
81420 +
81421 +/*
81422 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
81423 + */
81424 +static unsigned int execute_kernexec_fptr(void)
81425 +{
81426 + basic_block bb;
81427 + gimple_stmt_iterator gsi;
81428 +
81429 + // 1. loop through BBs and GIMPLE statements
81430 + FOR_EACH_BB(bb) {
81431 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81432 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
81433 + tree fn;
81434 + gimple call_stmt;
81435 +
81436 + // is it a call ...
81437 + call_stmt = gsi_stmt(gsi);
81438 + if (!is_gimple_call(call_stmt))
81439 + continue;
81440 + fn = gimple_call_fn(call_stmt);
81441 + if (TREE_CODE(fn) == ADDR_EXPR)
81442 + continue;
81443 + if (TREE_CODE(fn) != SSA_NAME)
81444 + gcc_unreachable();
81445 +
81446 + // ... through a function pointer
81447 + fn = SSA_NAME_VAR(fn);
81448 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
81449 + continue;
81450 + fn = TREE_TYPE(fn);
81451 + if (TREE_CODE(fn) != POINTER_TYPE)
81452 + continue;
81453 + fn = TREE_TYPE(fn);
81454 + if (TREE_CODE(fn) != FUNCTION_TYPE)
81455 + continue;
81456 +
81457 + kernexec_instrument_fptr(gsi);
81458 +
81459 +//debug_tree(gimple_call_fn(call_stmt));
81460 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81461 + }
81462 + }
81463 +
81464 + return 0;
81465 +}
81466 +
81467 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
81468 +static void kernexec_instrument_retaddr_bts(rtx insn)
81469 +{
81470 + rtx btsq;
81471 + rtvec argvec, constraintvec, labelvec;
81472 + int line;
81473 +
81474 + // create asm volatile("btsq $63,(%%rsp)":::)
81475 + argvec = rtvec_alloc(0);
81476 + constraintvec = rtvec_alloc(0);
81477 + labelvec = rtvec_alloc(0);
81478 + line = expand_location(RTL_LOCATION(insn)).line;
81479 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81480 + MEM_VOLATILE_P(btsq) = 1;
81481 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
81482 + emit_insn_before(btsq, insn);
81483 +}
81484 +
81485 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
81486 +static void kernexec_instrument_retaddr_or(rtx insn)
81487 +{
81488 + rtx orq;
81489 + rtvec argvec, constraintvec, labelvec;
81490 + int line;
81491 +
81492 + // create asm volatile("orq %%r10,(%%rsp)":::)
81493 + argvec = rtvec_alloc(0);
81494 + constraintvec = rtvec_alloc(0);
81495 + labelvec = rtvec_alloc(0);
81496 + line = expand_location(RTL_LOCATION(insn)).line;
81497 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81498 + MEM_VOLATILE_P(orq) = 1;
81499 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
81500 + emit_insn_before(orq, insn);
81501 +}
81502 +
81503 +/*
81504 + * find all asm level function returns and forcibly set the highest bit of the return address
81505 + */
81506 +static unsigned int execute_kernexec_retaddr(void)
81507 +{
81508 + rtx insn;
81509 +
81510 + // 1. find function returns
81511 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
81512 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
81513 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
81514 + rtx body;
81515 +
81516 + // is it a retn
81517 + if (!JUMP_P(insn))
81518 + continue;
81519 + body = PATTERN(insn);
81520 + if (GET_CODE(body) == PARALLEL)
81521 + body = XVECEXP(body, 0, 0);
81522 + if (GET_CODE(body) != RETURN)
81523 + continue;
81524 + kernexec_instrument_retaddr(insn);
81525 + }
81526 +
81527 +// print_simple_rtl(stderr, get_insns());
81528 +// print_rtl(stderr, get_insns());
81529 +
81530 + return 0;
81531 +}
81532 +
81533 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81534 +{
81535 + const char * const plugin_name = plugin_info->base_name;
81536 + const int argc = plugin_info->argc;
81537 + const struct plugin_argument * const argv = plugin_info->argv;
81538 + int i;
81539 + struct register_pass_info kernexec_fptr_pass_info = {
81540 + .pass = &kernexec_fptr_pass.pass,
81541 + .reference_pass_name = "ssa",
81542 + .ref_pass_instance_number = 0,
81543 + .pos_op = PASS_POS_INSERT_AFTER
81544 + };
81545 + struct register_pass_info kernexec_retaddr_pass_info = {
81546 + .pass = &kernexec_retaddr_pass.pass,
81547 + .reference_pass_name = "pro_and_epilogue",
81548 + .ref_pass_instance_number = 0,
81549 + .pos_op = PASS_POS_INSERT_AFTER
81550 + };
81551 +
81552 + if (!plugin_default_version_check(version, &gcc_version)) {
81553 + error(G_("incompatible gcc/plugin versions"));
81554 + return 1;
81555 + }
81556 +
81557 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
81558 +
81559 + if (TARGET_64BIT == 0)
81560 + return 0;
81561 +
81562 + for (i = 0; i < argc; ++i) {
81563 + if (!strcmp(argv[i].key, "method")) {
81564 + if (!argv[i].value) {
81565 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81566 + continue;
81567 + }
81568 + if (!strcmp(argv[i].value, "bts")) {
81569 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
81570 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
81571 + } else if (!strcmp(argv[i].value, "or")) {
81572 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
81573 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
81574 + fix_register("r10", 1, 1);
81575 + } else
81576 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
81577 + continue;
81578 + }
81579 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81580 + }
81581 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
81582 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
81583 +
81584 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
81585 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
81586 +
81587 + return 0;
81588 +}
81589 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
81590 new file mode 100644
81591 index 0000000..d44f37c
81592 --- /dev/null
81593 +++ b/tools/gcc/stackleak_plugin.c
81594 @@ -0,0 +1,291 @@
81595 +/*
81596 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81597 + * Licensed under the GPL v2
81598 + *
81599 + * Note: the choice of the license means that the compilation process is
81600 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81601 + * but for the kernel it doesn't matter since it doesn't link against
81602 + * any of the gcc libraries
81603 + *
81604 + * gcc plugin to help implement various PaX features
81605 + *
81606 + * - track lowest stack pointer
81607 + *
81608 + * TODO:
81609 + * - initialize all local variables
81610 + *
81611 + * BUGS:
81612 + * - none known
81613 + */
81614 +#include "gcc-plugin.h"
81615 +#include "config.h"
81616 +#include "system.h"
81617 +#include "coretypes.h"
81618 +#include "tree.h"
81619 +#include "tree-pass.h"
81620 +#include "flags.h"
81621 +#include "intl.h"
81622 +#include "toplev.h"
81623 +#include "plugin.h"
81624 +//#include "expr.h" where are you...
81625 +#include "diagnostic.h"
81626 +#include "plugin-version.h"
81627 +#include "tm.h"
81628 +#include "function.h"
81629 +#include "basic-block.h"
81630 +#include "gimple.h"
81631 +#include "rtl.h"
81632 +#include "emit-rtl.h"
81633 +
81634 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81635 +
81636 +int plugin_is_GPL_compatible;
81637 +
81638 +static int track_frame_size = -1;
81639 +static const char track_function[] = "pax_track_stack";
81640 +static const char check_function[] = "pax_check_alloca";
81641 +static bool init_locals;
81642 +
81643 +static struct plugin_info stackleak_plugin_info = {
81644 + .version = "201111150100",
81645 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
81646 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
81647 +};
81648 +
81649 +static bool gate_stackleak_track_stack(void);
81650 +static unsigned int execute_stackleak_tree_instrument(void);
81651 +static unsigned int execute_stackleak_final(void);
81652 +
81653 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
81654 + .pass = {
81655 + .type = GIMPLE_PASS,
81656 + .name = "stackleak_tree_instrument",
81657 + .gate = gate_stackleak_track_stack,
81658 + .execute = execute_stackleak_tree_instrument,
81659 + .sub = NULL,
81660 + .next = NULL,
81661 + .static_pass_number = 0,
81662 + .tv_id = TV_NONE,
81663 + .properties_required = PROP_gimple_leh | PROP_cfg,
81664 + .properties_provided = 0,
81665 + .properties_destroyed = 0,
81666 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
81667 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
81668 + }
81669 +};
81670 +
81671 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
81672 + .pass = {
81673 + .type = RTL_PASS,
81674 + .name = "stackleak_final",
81675 + .gate = gate_stackleak_track_stack,
81676 + .execute = execute_stackleak_final,
81677 + .sub = NULL,
81678 + .next = NULL,
81679 + .static_pass_number = 0,
81680 + .tv_id = TV_NONE,
81681 + .properties_required = 0,
81682 + .properties_provided = 0,
81683 + .properties_destroyed = 0,
81684 + .todo_flags_start = 0,
81685 + .todo_flags_finish = TODO_dump_func
81686 + }
81687 +};
81688 +
81689 +static bool gate_stackleak_track_stack(void)
81690 +{
81691 + return track_frame_size >= 0;
81692 +}
81693 +
81694 +static void stackleak_check_alloca(gimple_stmt_iterator gsi)
81695 +{
81696 + gimple check_alloca;
81697 + tree fndecl, fntype, alloca_size;
81698 +
81699 + // insert call to void pax_check_alloca(unsigned long size)
81700 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
81701 + fndecl = build_fn_decl(check_function, fntype);
81702 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
81703 + alloca_size = gimple_call_arg(gsi_stmt(gsi), 0);
81704 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
81705 + gsi_insert_before(&gsi, check_alloca, GSI_CONTINUE_LINKING);
81706 +}
81707 +
81708 +static void stackleak_add_instrumentation(gimple_stmt_iterator gsi)
81709 +{
81710 + gimple track_stack;
81711 + tree fndecl, fntype;
81712 +
81713 + // insert call to void pax_track_stack(void)
81714 + fntype = build_function_type_list(void_type_node, NULL_TREE);
81715 + fndecl = build_fn_decl(track_function, fntype);
81716 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
81717 + track_stack = gimple_build_call(fndecl, 0);
81718 + gsi_insert_after(&gsi, track_stack, GSI_CONTINUE_LINKING);
81719 +}
81720 +
81721 +#if BUILDING_GCC_VERSION == 4005
81722 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
81723 +{
81724 + tree fndecl;
81725 +
81726 + if (!is_gimple_call(stmt))
81727 + return false;
81728 + fndecl = gimple_call_fndecl(stmt);
81729 + if (!fndecl)
81730 + return false;
81731 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
81732 + return false;
81733 +// print_node(stderr, "pax", fndecl, 4);
81734 + return DECL_FUNCTION_CODE(fndecl) == code;
81735 +}
81736 +#endif
81737 +
81738 +static bool is_alloca(gimple stmt)
81739 +{
81740 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
81741 + return true;
81742 +
81743 +#if BUILDING_GCC_VERSION >= 4007
81744 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
81745 + return true;
81746 +#endif
81747 +
81748 + return false;
81749 +}
81750 +
81751 +static unsigned int execute_stackleak_tree_instrument(void)
81752 +{
81753 + basic_block bb, entry_bb;
81754 + bool prologue_instrumented = false;
81755 +
81756 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
81757 +
81758 + // 1. loop through BBs and GIMPLE statements
81759 + FOR_EACH_BB(bb) {
81760 + gimple_stmt_iterator gsi;
81761 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81762 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
81763 + if (!is_alloca(gsi_stmt(gsi)))
81764 + continue;
81765 +
81766 + // 2. insert stack overflow check before each __builtin_alloca call
81767 + stackleak_check_alloca(gsi);
81768 +
81769 + // 3. insert track call after each __builtin_alloca call
81770 + stackleak_add_instrumentation(gsi);
81771 + if (bb == entry_bb)
81772 + prologue_instrumented = true;
81773 + }
81774 + }
81775 +
81776 + // 4. insert track call at the beginning
81777 + if (!prologue_instrumented) {
81778 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
81779 + if (dom_info_available_p(CDI_DOMINATORS))
81780 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
81781 + stackleak_add_instrumentation(gsi_start_bb(bb));
81782 + }
81783 +
81784 + return 0;
81785 +}
81786 +
81787 +static unsigned int execute_stackleak_final(void)
81788 +{
81789 + rtx insn;
81790 +
81791 + if (cfun->calls_alloca)
81792 + return 0;
81793 +
81794 + // keep calls only if function frame is big enough
81795 + if (get_frame_size() >= track_frame_size)
81796 + return 0;
81797 +
81798 + // 1. find pax_track_stack calls
81799 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
81800 + // rtl match: (call_insn 8 7 9 3 (call (mem (symbol_ref ("pax_track_stack") [flags 0x41] <function_decl 0xb7470e80 pax_track_stack>) [0 S1 A8]) (4)) -1 (nil) (nil))
81801 + rtx body;
81802 +
81803 + if (!CALL_P(insn))
81804 + continue;
81805 + body = PATTERN(insn);
81806 + if (GET_CODE(body) != CALL)
81807 + continue;
81808 + body = XEXP(body, 0);
81809 + if (GET_CODE(body) != MEM)
81810 + continue;
81811 + body = XEXP(body, 0);
81812 + if (GET_CODE(body) != SYMBOL_REF)
81813 + continue;
81814 + if (strcmp(XSTR(body, 0), track_function))
81815 + continue;
81816 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
81817 + // 2. delete call
81818 + insn = delete_insn_and_edges(insn);
81819 +#if BUILDING_GCC_VERSION >= 4007
81820 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
81821 + insn = delete_insn_and_edges(insn);
81822 +#endif
81823 + }
81824 +
81825 +// print_simple_rtl(stderr, get_insns());
81826 +// print_rtl(stderr, get_insns());
81827 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
81828 +
81829 + return 0;
81830 +}
81831 +
81832 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81833 +{
81834 + const char * const plugin_name = plugin_info->base_name;
81835 + const int argc = plugin_info->argc;
81836 + const struct plugin_argument * const argv = plugin_info->argv;
81837 + int i;
81838 + struct register_pass_info stackleak_tree_instrument_pass_info = {
81839 + .pass = &stackleak_tree_instrument_pass.pass,
81840 +// .reference_pass_name = "tree_profile",
81841 + .reference_pass_name = "optimized",
81842 + .ref_pass_instance_number = 0,
81843 + .pos_op = PASS_POS_INSERT_AFTER
81844 + };
81845 + struct register_pass_info stackleak_final_pass_info = {
81846 + .pass = &stackleak_final_rtl_opt_pass.pass,
81847 + .reference_pass_name = "final",
81848 + .ref_pass_instance_number = 0,
81849 + .pos_op = PASS_POS_INSERT_BEFORE
81850 + };
81851 +
81852 + if (!plugin_default_version_check(version, &gcc_version)) {
81853 + error(G_("incompatible gcc/plugin versions"));
81854 + return 1;
81855 + }
81856 +
81857 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
81858 +
81859 + for (i = 0; i < argc; ++i) {
81860 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
81861 + if (!argv[i].value) {
81862 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81863 + continue;
81864 + }
81865 + track_frame_size = atoi(argv[i].value);
81866 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
81867 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
81868 + continue;
81869 + }
81870 + if (!strcmp(argv[i].key, "initialize-locals")) {
81871 + if (argv[i].value) {
81872 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
81873 + continue;
81874 + }
81875 + init_locals = true;
81876 + continue;
81877 + }
81878 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81879 + }
81880 +
81881 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
81882 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
81883 +
81884 + return 0;
81885 +}
81886 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
81887 index 6789d78..4afd019 100644
81888 --- a/tools/perf/util/include/asm/alternative-asm.h
81889 +++ b/tools/perf/util/include/asm/alternative-asm.h
81890 @@ -5,4 +5,7 @@
81891
81892 #define altinstruction_entry #
81893
81894 + .macro pax_force_retaddr rip=0, reload=0
81895 + .endm
81896 +
81897 #endif
81898 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
81899 index af0f22f..9a7d479 100644
81900 --- a/usr/gen_init_cpio.c
81901 +++ b/usr/gen_init_cpio.c
81902 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
81903 int retval;
81904 int rc = -1;
81905 int namesize;
81906 - int i;
81907 + unsigned int i;
81908
81909 mode |= S_IFREG;
81910
81911 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
81912 *env_var = *expanded = '\0';
81913 strncat(env_var, start + 2, end - start - 2);
81914 strncat(expanded, new_location, start - new_location);
81915 - strncat(expanded, getenv(env_var), PATH_MAX);
81916 - strncat(expanded, end + 1, PATH_MAX);
81917 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
81918 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
81919 strncpy(new_location, expanded, PATH_MAX);
81920 + new_location[PATH_MAX] = 0;
81921 } else
81922 break;
81923 }
81924 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
81925 index aefdda3..8e8fbb9 100644
81926 --- a/virt/kvm/kvm_main.c
81927 +++ b/virt/kvm/kvm_main.c
81928 @@ -73,7 +73,7 @@ LIST_HEAD(vm_list);
81929
81930 static cpumask_var_t cpus_hardware_enabled;
81931 static int kvm_usage_count = 0;
81932 -static atomic_t hardware_enable_failed;
81933 +static atomic_unchecked_t hardware_enable_failed;
81934
81935 struct kmem_cache *kvm_vcpu_cache;
81936 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
81937 @@ -2266,7 +2266,7 @@ static void hardware_enable_nolock(void *junk)
81938
81939 if (r) {
81940 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
81941 - atomic_inc(&hardware_enable_failed);
81942 + atomic_inc_unchecked(&hardware_enable_failed);
81943 printk(KERN_INFO "kvm: enabling virtualization on "
81944 "CPU%d failed\n", cpu);
81945 }
81946 @@ -2320,10 +2320,10 @@ static int hardware_enable_all(void)
81947
81948 kvm_usage_count++;
81949 if (kvm_usage_count == 1) {
81950 - atomic_set(&hardware_enable_failed, 0);
81951 + atomic_set_unchecked(&hardware_enable_failed, 0);
81952 on_each_cpu(hardware_enable_nolock, NULL, 1);
81953
81954 - if (atomic_read(&hardware_enable_failed)) {
81955 + if (atomic_read_unchecked(&hardware_enable_failed)) {
81956 hardware_disable_all_nolock();
81957 r = -EBUSY;
81958 }
81959 @@ -2588,7 +2588,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
81960 kvm_arch_vcpu_put(vcpu);
81961 }
81962
81963 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
81964 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
81965 struct module *module)
81966 {
81967 int r;
81968 @@ -2651,7 +2651,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
81969 if (!vcpu_align)
81970 vcpu_align = __alignof__(struct kvm_vcpu);
81971 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
81972 - 0, NULL);
81973 + SLAB_USERCOPY, NULL);
81974 if (!kvm_vcpu_cache) {
81975 r = -ENOMEM;
81976 goto out_free_3;
81977 @@ -2661,9 +2661,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
81978 if (r)
81979 goto out_free;
81980
81981 - kvm_chardev_ops.owner = module;
81982 - kvm_vm_fops.owner = module;
81983 - kvm_vcpu_fops.owner = module;
81984 + pax_open_kernel();
81985 + *(void **)&kvm_chardev_ops.owner = module;
81986 + *(void **)&kvm_vm_fops.owner = module;
81987 + *(void **)&kvm_vcpu_fops.owner = module;
81988 + pax_close_kernel();
81989
81990 r = misc_register(&kvm_dev);
81991 if (r) {