]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.2.2-3.1.10-201201182132.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-3.1.10-201201182132.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 7c8f52a..371cd76 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 f927429..39c2947 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..2ac96e7 100644
24953 --- a/block/scsi_ioctl.c
24954 +++ b/block/scsi_ioctl.c
24955 @@ -24,6 +24,7 @@
24956 #include <linux/capability.h>
24957 #include <linux/completion.h>
24958 #include <linux/cdrom.h>
24959 +#include <linux/ratelimit.h>
24960 #include <linux/slab.h>
24961 #include <linux/times.h>
24962 #include <asm/uaccess.h>
24963 @@ -222,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
24964 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
24965 struct sg_io_hdr *hdr, fmode_t mode)
24966 {
24967 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
24968 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24969 + unsigned char *cmdptr;
24970 +
24971 + if (rq->cmd != rq->__cmd)
24972 + cmdptr = rq->cmd;
24973 + else
24974 + cmdptr = tmpcmd;
24975 +
24976 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
24977 return -EFAULT;
24978 +
24979 + if (cmdptr != rq->cmd)
24980 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
24981 +
24982 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
24983 return -EPERM;
24984
24985 @@ -432,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
24986 int err;
24987 unsigned int in_len, out_len, bytes, opcode, cmdlen;
24988 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
24989 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24990 + unsigned char *cmdptr;
24991
24992 if (!sic)
24993 return -EINVAL;
24994 @@ -465,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
24995 */
24996 err = -EFAULT;
24997 rq->cmd_len = cmdlen;
24998 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
24999 +
25000 + if (rq->cmd != rq->__cmd)
25001 + cmdptr = rq->cmd;
25002 + else
25003 + cmdptr = tmpcmd;
25004 +
25005 + if (copy_from_user(cmdptr, sic->data, cmdlen))
25006 goto error;
25007
25008 + if (rq->cmd != cmdptr)
25009 + memcpy(rq->cmd, cmdptr, cmdlen);
25010 +
25011 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
25012 goto error;
25013
25014 @@ -691,6 +715,57 @@ int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t mod
25015 }
25016 EXPORT_SYMBOL(scsi_cmd_ioctl);
25017
25018 +int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd)
25019 +{
25020 + if (bd && bd == bd->bd_contains)
25021 + return 0;
25022 +
25023 + /* Actually none of these is particularly useful on a partition,
25024 + * but they are safe.
25025 + */
25026 + switch (cmd) {
25027 + case SCSI_IOCTL_GET_IDLUN:
25028 + case SCSI_IOCTL_GET_BUS_NUMBER:
25029 + case SCSI_IOCTL_GET_PCI:
25030 + case SCSI_IOCTL_PROBE_HOST:
25031 + case SG_GET_VERSION_NUM:
25032 + case SG_SET_TIMEOUT:
25033 + case SG_GET_TIMEOUT:
25034 + case SG_GET_RESERVED_SIZE:
25035 + case SG_SET_RESERVED_SIZE:
25036 + case SG_EMULATED_HOST:
25037 + return 0;
25038 + case CDROM_GET_CAPABILITY:
25039 + /* Keep this until we remove the printk below. udev sends it
25040 + * and we do not want to spam dmesg about it. CD-ROMs do
25041 + * not have partitions, so we get here only for disks.
25042 + */
25043 + return -ENOIOCTLCMD;
25044 + default:
25045 + break;
25046 + }
25047 +
25048 + /* In particular, rule out all resets and host-specific ioctls. */
25049 + printk_ratelimited(KERN_WARNING
25050 + "%s: sending ioctl %x to a partition!\n", current->comm, cmd);
25051 +
25052 + return capable(CAP_SYS_RAWIO) ? 0 : -ENOIOCTLCMD;
25053 +}
25054 +EXPORT_SYMBOL(scsi_verify_blk_ioctl);
25055 +
25056 +int scsi_cmd_blk_ioctl(struct block_device *bd, fmode_t mode,
25057 + unsigned int cmd, void __user *arg)
25058 +{
25059 + int ret;
25060 +
25061 + ret = scsi_verify_blk_ioctl(bd, cmd);
25062 + if (ret < 0)
25063 + return ret;
25064 +
25065 + return scsi_cmd_ioctl(bd->bd_disk->queue, bd->bd_disk, mode, cmd, arg);
25066 +}
25067 +EXPORT_SYMBOL(scsi_cmd_blk_ioctl);
25068 +
25069 static int __init blk_scsi_ioctl_init(void)
25070 {
25071 blk_set_cmd_filter_defaults(&blk_default_cmd_filter);
25072 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
25073 index 671d4d6..5f24030 100644
25074 --- a/crypto/cryptd.c
25075 +++ b/crypto/cryptd.c
25076 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
25077
25078 struct cryptd_blkcipher_request_ctx {
25079 crypto_completion_t complete;
25080 -};
25081 +} __no_const;
25082
25083 struct cryptd_hash_ctx {
25084 struct crypto_shash *child;
25085 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
25086
25087 struct cryptd_aead_request_ctx {
25088 crypto_completion_t complete;
25089 -};
25090 +} __no_const;
25091
25092 static void cryptd_queue_worker(struct work_struct *work);
25093
25094 diff --git a/crypto/serpent.c b/crypto/serpent.c
25095 index b651a55..a9ddd79b 100644
25096 --- a/crypto/serpent.c
25097 +++ b/crypto/serpent.c
25098 @@ -224,6 +224,8 @@ static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key,
25099 u32 r0,r1,r2,r3,r4;
25100 int i;
25101
25102 + pax_track_stack();
25103 +
25104 /* Copy key, add padding */
25105
25106 for (i = 0; i < keylen; ++i)
25107 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
25108 index 5d41894..22021e4 100644
25109 --- a/drivers/acpi/apei/cper.c
25110 +++ b/drivers/acpi/apei/cper.c
25111 @@ -38,12 +38,12 @@
25112 */
25113 u64 cper_next_record_id(void)
25114 {
25115 - static atomic64_t seq;
25116 + static atomic64_unchecked_t seq;
25117
25118 - if (!atomic64_read(&seq))
25119 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
25120 + if (!atomic64_read_unchecked(&seq))
25121 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
25122
25123 - return atomic64_inc_return(&seq);
25124 + return atomic64_inc_return_unchecked(&seq);
25125 }
25126 EXPORT_SYMBOL_GPL(cper_next_record_id);
25127
25128 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
25129 index 22f918b..9fafb84 100644
25130 --- a/drivers/acpi/ec_sys.c
25131 +++ b/drivers/acpi/ec_sys.c
25132 @@ -11,6 +11,7 @@
25133 #include <linux/kernel.h>
25134 #include <linux/acpi.h>
25135 #include <linux/debugfs.h>
25136 +#include <asm/uaccess.h>
25137 #include "internal.h"
25138
25139 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
25140 @@ -39,7 +40,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
25141 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
25142 */
25143 unsigned int size = EC_SPACE_SIZE;
25144 - u8 *data = (u8 *) buf;
25145 + u8 data;
25146 loff_t init_off = *off;
25147 int err = 0;
25148
25149 @@ -52,9 +53,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
25150 size = count;
25151
25152 while (size) {
25153 - err = ec_read(*off, &data[*off - init_off]);
25154 + err = ec_read(*off, &data);
25155 if (err)
25156 return err;
25157 + if (put_user(data, &buf[*off - init_off]))
25158 + return -EFAULT;
25159 *off += 1;
25160 size--;
25161 }
25162 @@ -70,7 +73,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
25163
25164 unsigned int size = count;
25165 loff_t init_off = *off;
25166 - u8 *data = (u8 *) buf;
25167 int err = 0;
25168
25169 if (*off >= EC_SPACE_SIZE)
25170 @@ -81,7 +83,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
25171 }
25172
25173 while (size) {
25174 - u8 byte_write = data[*off - init_off];
25175 + u8 byte_write;
25176 + if (get_user(byte_write, &buf[*off - init_off]))
25177 + return -EFAULT;
25178 err = ec_write(*off, byte_write);
25179 if (err)
25180 return err;
25181 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
25182 index f5f9869..da87aeb 100644
25183 --- a/drivers/acpi/proc.c
25184 +++ b/drivers/acpi/proc.c
25185 @@ -342,19 +342,13 @@ acpi_system_write_wakeup_device(struct file *file,
25186 size_t count, loff_t * ppos)
25187 {
25188 struct list_head *node, *next;
25189 - char strbuf[5];
25190 - char str[5] = "";
25191 - unsigned int len = count;
25192 + char strbuf[5] = {0};
25193
25194 - if (len > 4)
25195 - len = 4;
25196 - if (len < 0)
25197 + if (count > 4)
25198 + count = 4;
25199 + if (copy_from_user(strbuf, buffer, count))
25200 return -EFAULT;
25201 -
25202 - if (copy_from_user(strbuf, buffer, len))
25203 - return -EFAULT;
25204 - strbuf[len] = '\0';
25205 - sscanf(strbuf, "%s", str);
25206 + strbuf[count] = '\0';
25207
25208 mutex_lock(&acpi_device_lock);
25209 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
25210 @@ -363,7 +357,7 @@ acpi_system_write_wakeup_device(struct file *file,
25211 if (!dev->wakeup.flags.valid)
25212 continue;
25213
25214 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
25215 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
25216 if (device_can_wakeup(&dev->dev)) {
25217 bool enable = !device_may_wakeup(&dev->dev);
25218 device_set_wakeup_enable(&dev->dev, enable);
25219 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
25220 index a4e0f1b..9793b28 100644
25221 --- a/drivers/acpi/processor_driver.c
25222 +++ b/drivers/acpi/processor_driver.c
25223 @@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
25224 return 0;
25225 #endif
25226
25227 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
25228 + BUG_ON(pr->id >= nr_cpu_ids);
25229
25230 /*
25231 * Buggy BIOS check
25232 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
25233 index 4a3a5ae..cbee192 100644
25234 --- a/drivers/ata/libata-core.c
25235 +++ b/drivers/ata/libata-core.c
25236 @@ -4733,7 +4733,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
25237 struct ata_port *ap;
25238 unsigned int tag;
25239
25240 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25241 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25242 ap = qc->ap;
25243
25244 qc->flags = 0;
25245 @@ -4749,7 +4749,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
25246 struct ata_port *ap;
25247 struct ata_link *link;
25248
25249 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25250 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25251 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
25252 ap = qc->ap;
25253 link = qc->dev->link;
25254 @@ -5754,6 +5754,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
25255 return;
25256
25257 spin_lock(&lock);
25258 + pax_open_kernel();
25259
25260 for (cur = ops->inherits; cur; cur = cur->inherits) {
25261 void **inherit = (void **)cur;
25262 @@ -5767,8 +5768,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
25263 if (IS_ERR(*pp))
25264 *pp = NULL;
25265
25266 - ops->inherits = NULL;
25267 + *(struct ata_port_operations **)&ops->inherits = NULL;
25268
25269 + pax_close_kernel();
25270 spin_unlock(&lock);
25271 }
25272
25273 diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
25274 index ed16fbe..fc92cb8 100644
25275 --- a/drivers/ata/libata-eh.c
25276 +++ b/drivers/ata/libata-eh.c
25277 @@ -2515,6 +2515,8 @@ void ata_eh_report(struct ata_port *ap)
25278 {
25279 struct ata_link *link;
25280
25281 + pax_track_stack();
25282 +
25283 ata_for_each_link(link, ap, HOST_FIRST)
25284 ata_eh_link_report(link);
25285 }
25286 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
25287 index 719bb73..79ce858 100644
25288 --- a/drivers/ata/pata_arasan_cf.c
25289 +++ b/drivers/ata/pata_arasan_cf.c
25290 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
25291 /* Handle platform specific quirks */
25292 if (pdata->quirk) {
25293 if (pdata->quirk & CF_BROKEN_PIO) {
25294 - ap->ops->set_piomode = NULL;
25295 + pax_open_kernel();
25296 + *(void **)&ap->ops->set_piomode = NULL;
25297 + pax_close_kernel();
25298 ap->pio_mask = 0;
25299 }
25300 if (pdata->quirk & CF_BROKEN_MWDMA)
25301 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
25302 index f9b983a..887b9d8 100644
25303 --- a/drivers/atm/adummy.c
25304 +++ b/drivers/atm/adummy.c
25305 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
25306 vcc->pop(vcc, skb);
25307 else
25308 dev_kfree_skb_any(skb);
25309 - atomic_inc(&vcc->stats->tx);
25310 + atomic_inc_unchecked(&vcc->stats->tx);
25311
25312 return 0;
25313 }
25314 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
25315 index f8f41e0..1f987dd 100644
25316 --- a/drivers/atm/ambassador.c
25317 +++ b/drivers/atm/ambassador.c
25318 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
25319 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
25320
25321 // VC layer stats
25322 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25323 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25324
25325 // free the descriptor
25326 kfree (tx_descr);
25327 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
25328 dump_skb ("<<<", vc, skb);
25329
25330 // VC layer stats
25331 - atomic_inc(&atm_vcc->stats->rx);
25332 + atomic_inc_unchecked(&atm_vcc->stats->rx);
25333 __net_timestamp(skb);
25334 // end of our responsibility
25335 atm_vcc->push (atm_vcc, skb);
25336 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
25337 } else {
25338 PRINTK (KERN_INFO, "dropped over-size frame");
25339 // should we count this?
25340 - atomic_inc(&atm_vcc->stats->rx_drop);
25341 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25342 }
25343
25344 } else {
25345 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
25346 }
25347
25348 if (check_area (skb->data, skb->len)) {
25349 - atomic_inc(&atm_vcc->stats->tx_err);
25350 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
25351 return -ENOMEM; // ?
25352 }
25353
25354 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
25355 index b22d71c..d6e1049 100644
25356 --- a/drivers/atm/atmtcp.c
25357 +++ b/drivers/atm/atmtcp.c
25358 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25359 if (vcc->pop) vcc->pop(vcc,skb);
25360 else dev_kfree_skb(skb);
25361 if (dev_data) return 0;
25362 - atomic_inc(&vcc->stats->tx_err);
25363 + atomic_inc_unchecked(&vcc->stats->tx_err);
25364 return -ENOLINK;
25365 }
25366 size = skb->len+sizeof(struct atmtcp_hdr);
25367 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25368 if (!new_skb) {
25369 if (vcc->pop) vcc->pop(vcc,skb);
25370 else dev_kfree_skb(skb);
25371 - atomic_inc(&vcc->stats->tx_err);
25372 + atomic_inc_unchecked(&vcc->stats->tx_err);
25373 return -ENOBUFS;
25374 }
25375 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
25376 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25377 if (vcc->pop) vcc->pop(vcc,skb);
25378 else dev_kfree_skb(skb);
25379 out_vcc->push(out_vcc,new_skb);
25380 - atomic_inc(&vcc->stats->tx);
25381 - atomic_inc(&out_vcc->stats->rx);
25382 + atomic_inc_unchecked(&vcc->stats->tx);
25383 + atomic_inc_unchecked(&out_vcc->stats->rx);
25384 return 0;
25385 }
25386
25387 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
25388 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
25389 read_unlock(&vcc_sklist_lock);
25390 if (!out_vcc) {
25391 - atomic_inc(&vcc->stats->tx_err);
25392 + atomic_inc_unchecked(&vcc->stats->tx_err);
25393 goto done;
25394 }
25395 skb_pull(skb,sizeof(struct atmtcp_hdr));
25396 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
25397 __net_timestamp(new_skb);
25398 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
25399 out_vcc->push(out_vcc,new_skb);
25400 - atomic_inc(&vcc->stats->tx);
25401 - atomic_inc(&out_vcc->stats->rx);
25402 + atomic_inc_unchecked(&vcc->stats->tx);
25403 + atomic_inc_unchecked(&out_vcc->stats->rx);
25404 done:
25405 if (vcc->pop) vcc->pop(vcc,skb);
25406 else dev_kfree_skb(skb);
25407 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
25408 index 9307141..d8521bf 100644
25409 --- a/drivers/atm/eni.c
25410 +++ b/drivers/atm/eni.c
25411 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
25412 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
25413 vcc->dev->number);
25414 length = 0;
25415 - atomic_inc(&vcc->stats->rx_err);
25416 + atomic_inc_unchecked(&vcc->stats->rx_err);
25417 }
25418 else {
25419 length = ATM_CELL_SIZE-1; /* no HEC */
25420 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25421 size);
25422 }
25423 eff = length = 0;
25424 - atomic_inc(&vcc->stats->rx_err);
25425 + atomic_inc_unchecked(&vcc->stats->rx_err);
25426 }
25427 else {
25428 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
25429 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25430 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
25431 vcc->dev->number,vcc->vci,length,size << 2,descr);
25432 length = eff = 0;
25433 - atomic_inc(&vcc->stats->rx_err);
25434 + atomic_inc_unchecked(&vcc->stats->rx_err);
25435 }
25436 }
25437 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
25438 @@ -771,7 +771,7 @@ rx_dequeued++;
25439 vcc->push(vcc,skb);
25440 pushed++;
25441 }
25442 - atomic_inc(&vcc->stats->rx);
25443 + atomic_inc_unchecked(&vcc->stats->rx);
25444 }
25445 wake_up(&eni_dev->rx_wait);
25446 }
25447 @@ -1228,7 +1228,7 @@ static void dequeue_tx(struct atm_dev *dev)
25448 PCI_DMA_TODEVICE);
25449 if (vcc->pop) vcc->pop(vcc,skb);
25450 else dev_kfree_skb_irq(skb);
25451 - atomic_inc(&vcc->stats->tx);
25452 + atomic_inc_unchecked(&vcc->stats->tx);
25453 wake_up(&eni_dev->tx_wait);
25454 dma_complete++;
25455 }
25456 @@ -1568,7 +1568,7 @@ tx_complete++;
25457 /*--------------------------------- entries ---------------------------------*/
25458
25459
25460 -static const char *media_name[] __devinitdata = {
25461 +static const char *media_name[] __devinitconst = {
25462 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
25463 "UTP", "05?", "06?", "07?", /* 4- 7 */
25464 "TAXI","09?", "10?", "11?", /* 8-11 */
25465 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
25466 index 5072f8a..fa52520d 100644
25467 --- a/drivers/atm/firestream.c
25468 +++ b/drivers/atm/firestream.c
25469 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
25470 }
25471 }
25472
25473 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25474 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25475
25476 fs_dprintk (FS_DEBUG_TXMEM, "i");
25477 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
25478 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
25479 #endif
25480 skb_put (skb, qe->p1 & 0xffff);
25481 ATM_SKB(skb)->vcc = atm_vcc;
25482 - atomic_inc(&atm_vcc->stats->rx);
25483 + atomic_inc_unchecked(&atm_vcc->stats->rx);
25484 __net_timestamp(skb);
25485 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
25486 atm_vcc->push (atm_vcc, skb);
25487 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
25488 kfree (pe);
25489 }
25490 if (atm_vcc)
25491 - atomic_inc(&atm_vcc->stats->rx_drop);
25492 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25493 break;
25494 case 0x1f: /* Reassembly abort: no buffers. */
25495 /* Silently increment error counter. */
25496 if (atm_vcc)
25497 - atomic_inc(&atm_vcc->stats->rx_drop);
25498 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25499 break;
25500 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
25501 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
25502 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
25503 index 361f5ae..7fc552d 100644
25504 --- a/drivers/atm/fore200e.c
25505 +++ b/drivers/atm/fore200e.c
25506 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
25507 #endif
25508 /* check error condition */
25509 if (*entry->status & STATUS_ERROR)
25510 - atomic_inc(&vcc->stats->tx_err);
25511 + atomic_inc_unchecked(&vcc->stats->tx_err);
25512 else
25513 - atomic_inc(&vcc->stats->tx);
25514 + atomic_inc_unchecked(&vcc->stats->tx);
25515 }
25516 }
25517
25518 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
25519 if (skb == NULL) {
25520 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
25521
25522 - atomic_inc(&vcc->stats->rx_drop);
25523 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25524 return -ENOMEM;
25525 }
25526
25527 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
25528
25529 dev_kfree_skb_any(skb);
25530
25531 - atomic_inc(&vcc->stats->rx_drop);
25532 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25533 return -ENOMEM;
25534 }
25535
25536 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25537
25538 vcc->push(vcc, skb);
25539 - atomic_inc(&vcc->stats->rx);
25540 + atomic_inc_unchecked(&vcc->stats->rx);
25541
25542 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25543
25544 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
25545 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
25546 fore200e->atm_dev->number,
25547 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
25548 - atomic_inc(&vcc->stats->rx_err);
25549 + atomic_inc_unchecked(&vcc->stats->rx_err);
25550 }
25551 }
25552
25553 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
25554 goto retry_here;
25555 }
25556
25557 - atomic_inc(&vcc->stats->tx_err);
25558 + atomic_inc_unchecked(&vcc->stats->tx_err);
25559
25560 fore200e->tx_sat++;
25561 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
25562 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
25563 index 9a51df4..f3bb5f8 100644
25564 --- a/drivers/atm/he.c
25565 +++ b/drivers/atm/he.c
25566 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25567
25568 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
25569 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
25570 - atomic_inc(&vcc->stats->rx_drop);
25571 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25572 goto return_host_buffers;
25573 }
25574
25575 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25576 RBRQ_LEN_ERR(he_dev->rbrq_head)
25577 ? "LEN_ERR" : "",
25578 vcc->vpi, vcc->vci);
25579 - atomic_inc(&vcc->stats->rx_err);
25580 + atomic_inc_unchecked(&vcc->stats->rx_err);
25581 goto return_host_buffers;
25582 }
25583
25584 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25585 vcc->push(vcc, skb);
25586 spin_lock(&he_dev->global_lock);
25587
25588 - atomic_inc(&vcc->stats->rx);
25589 + atomic_inc_unchecked(&vcc->stats->rx);
25590
25591 return_host_buffers:
25592 ++pdus_assembled;
25593 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
25594 tpd->vcc->pop(tpd->vcc, tpd->skb);
25595 else
25596 dev_kfree_skb_any(tpd->skb);
25597 - atomic_inc(&tpd->vcc->stats->tx_err);
25598 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
25599 }
25600 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
25601 return;
25602 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25603 vcc->pop(vcc, skb);
25604 else
25605 dev_kfree_skb_any(skb);
25606 - atomic_inc(&vcc->stats->tx_err);
25607 + atomic_inc_unchecked(&vcc->stats->tx_err);
25608 return -EINVAL;
25609 }
25610
25611 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25612 vcc->pop(vcc, skb);
25613 else
25614 dev_kfree_skb_any(skb);
25615 - atomic_inc(&vcc->stats->tx_err);
25616 + atomic_inc_unchecked(&vcc->stats->tx_err);
25617 return -EINVAL;
25618 }
25619 #endif
25620 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25621 vcc->pop(vcc, skb);
25622 else
25623 dev_kfree_skb_any(skb);
25624 - atomic_inc(&vcc->stats->tx_err);
25625 + atomic_inc_unchecked(&vcc->stats->tx_err);
25626 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25627 return -ENOMEM;
25628 }
25629 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25630 vcc->pop(vcc, skb);
25631 else
25632 dev_kfree_skb_any(skb);
25633 - atomic_inc(&vcc->stats->tx_err);
25634 + atomic_inc_unchecked(&vcc->stats->tx_err);
25635 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25636 return -ENOMEM;
25637 }
25638 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25639 __enqueue_tpd(he_dev, tpd, cid);
25640 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25641
25642 - atomic_inc(&vcc->stats->tx);
25643 + atomic_inc_unchecked(&vcc->stats->tx);
25644
25645 return 0;
25646 }
25647 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
25648 index b812103..e391a49 100644
25649 --- a/drivers/atm/horizon.c
25650 +++ b/drivers/atm/horizon.c
25651 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
25652 {
25653 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
25654 // VC layer stats
25655 - atomic_inc(&vcc->stats->rx);
25656 + atomic_inc_unchecked(&vcc->stats->rx);
25657 __net_timestamp(skb);
25658 // end of our responsibility
25659 vcc->push (vcc, skb);
25660 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
25661 dev->tx_iovec = NULL;
25662
25663 // VC layer stats
25664 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25665 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25666
25667 // free the skb
25668 hrz_kfree_skb (skb);
25669 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
25670 index db06f34..dcebb61 100644
25671 --- a/drivers/atm/idt77252.c
25672 +++ b/drivers/atm/idt77252.c
25673 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
25674 else
25675 dev_kfree_skb(skb);
25676
25677 - atomic_inc(&vcc->stats->tx);
25678 + atomic_inc_unchecked(&vcc->stats->tx);
25679 }
25680
25681 atomic_dec(&scq->used);
25682 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25683 if ((sb = dev_alloc_skb(64)) == NULL) {
25684 printk("%s: Can't allocate buffers for aal0.\n",
25685 card->name);
25686 - atomic_add(i, &vcc->stats->rx_drop);
25687 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
25688 break;
25689 }
25690 if (!atm_charge(vcc, sb->truesize)) {
25691 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
25692 card->name);
25693 - atomic_add(i - 1, &vcc->stats->rx_drop);
25694 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
25695 dev_kfree_skb(sb);
25696 break;
25697 }
25698 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25699 ATM_SKB(sb)->vcc = vcc;
25700 __net_timestamp(sb);
25701 vcc->push(vcc, sb);
25702 - atomic_inc(&vcc->stats->rx);
25703 + atomic_inc_unchecked(&vcc->stats->rx);
25704
25705 cell += ATM_CELL_PAYLOAD;
25706 }
25707 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25708 "(CDC: %08x)\n",
25709 card->name, len, rpp->len, readl(SAR_REG_CDC));
25710 recycle_rx_pool_skb(card, rpp);
25711 - atomic_inc(&vcc->stats->rx_err);
25712 + atomic_inc_unchecked(&vcc->stats->rx_err);
25713 return;
25714 }
25715 if (stat & SAR_RSQE_CRC) {
25716 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
25717 recycle_rx_pool_skb(card, rpp);
25718 - atomic_inc(&vcc->stats->rx_err);
25719 + atomic_inc_unchecked(&vcc->stats->rx_err);
25720 return;
25721 }
25722 if (skb_queue_len(&rpp->queue) > 1) {
25723 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25724 RXPRINTK("%s: Can't alloc RX skb.\n",
25725 card->name);
25726 recycle_rx_pool_skb(card, rpp);
25727 - atomic_inc(&vcc->stats->rx_err);
25728 + atomic_inc_unchecked(&vcc->stats->rx_err);
25729 return;
25730 }
25731 if (!atm_charge(vcc, skb->truesize)) {
25732 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25733 __net_timestamp(skb);
25734
25735 vcc->push(vcc, skb);
25736 - atomic_inc(&vcc->stats->rx);
25737 + atomic_inc_unchecked(&vcc->stats->rx);
25738
25739 return;
25740 }
25741 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25742 __net_timestamp(skb);
25743
25744 vcc->push(vcc, skb);
25745 - atomic_inc(&vcc->stats->rx);
25746 + atomic_inc_unchecked(&vcc->stats->rx);
25747
25748 if (skb->truesize > SAR_FB_SIZE_3)
25749 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
25750 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
25751 if (vcc->qos.aal != ATM_AAL0) {
25752 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
25753 card->name, vpi, vci);
25754 - atomic_inc(&vcc->stats->rx_drop);
25755 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25756 goto drop;
25757 }
25758
25759 if ((sb = dev_alloc_skb(64)) == NULL) {
25760 printk("%s: Can't allocate buffers for AAL0.\n",
25761 card->name);
25762 - atomic_inc(&vcc->stats->rx_err);
25763 + atomic_inc_unchecked(&vcc->stats->rx_err);
25764 goto drop;
25765 }
25766
25767 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
25768 ATM_SKB(sb)->vcc = vcc;
25769 __net_timestamp(sb);
25770 vcc->push(vcc, sb);
25771 - atomic_inc(&vcc->stats->rx);
25772 + atomic_inc_unchecked(&vcc->stats->rx);
25773
25774 drop:
25775 skb_pull(queue, 64);
25776 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25777
25778 if (vc == NULL) {
25779 printk("%s: NULL connection in send().\n", card->name);
25780 - atomic_inc(&vcc->stats->tx_err);
25781 + atomic_inc_unchecked(&vcc->stats->tx_err);
25782 dev_kfree_skb(skb);
25783 return -EINVAL;
25784 }
25785 if (!test_bit(VCF_TX, &vc->flags)) {
25786 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
25787 - atomic_inc(&vcc->stats->tx_err);
25788 + atomic_inc_unchecked(&vcc->stats->tx_err);
25789 dev_kfree_skb(skb);
25790 return -EINVAL;
25791 }
25792 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25793 break;
25794 default:
25795 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
25796 - atomic_inc(&vcc->stats->tx_err);
25797 + atomic_inc_unchecked(&vcc->stats->tx_err);
25798 dev_kfree_skb(skb);
25799 return -EINVAL;
25800 }
25801
25802 if (skb_shinfo(skb)->nr_frags != 0) {
25803 printk("%s: No scatter-gather yet.\n", card->name);
25804 - atomic_inc(&vcc->stats->tx_err);
25805 + atomic_inc_unchecked(&vcc->stats->tx_err);
25806 dev_kfree_skb(skb);
25807 return -EINVAL;
25808 }
25809 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25810
25811 err = queue_skb(card, vc, skb, oam);
25812 if (err) {
25813 - atomic_inc(&vcc->stats->tx_err);
25814 + atomic_inc_unchecked(&vcc->stats->tx_err);
25815 dev_kfree_skb(skb);
25816 return err;
25817 }
25818 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
25819 skb = dev_alloc_skb(64);
25820 if (!skb) {
25821 printk("%s: Out of memory in send_oam().\n", card->name);
25822 - atomic_inc(&vcc->stats->tx_err);
25823 + atomic_inc_unchecked(&vcc->stats->tx_err);
25824 return -ENOMEM;
25825 }
25826 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
25827 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
25828 index cb90f7a..bd33566 100644
25829 --- a/drivers/atm/iphase.c
25830 +++ b/drivers/atm/iphase.c
25831 @@ -1121,7 +1121,7 @@ static int rx_pkt(struct atm_dev *dev)
25832 status = (u_short) (buf_desc_ptr->desc_mode);
25833 if (status & (RX_CER | RX_PTE | RX_OFL))
25834 {
25835 - atomic_inc(&vcc->stats->rx_err);
25836 + atomic_inc_unchecked(&vcc->stats->rx_err);
25837 IF_ERR(printk("IA: bad packet, dropping it");)
25838 if (status & RX_CER) {
25839 IF_ERR(printk(" cause: packet CRC error\n");)
25840 @@ -1144,7 +1144,7 @@ static int rx_pkt(struct atm_dev *dev)
25841 len = dma_addr - buf_addr;
25842 if (len > iadev->rx_buf_sz) {
25843 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
25844 - atomic_inc(&vcc->stats->rx_err);
25845 + atomic_inc_unchecked(&vcc->stats->rx_err);
25846 goto out_free_desc;
25847 }
25848
25849 @@ -1294,7 +1294,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25850 ia_vcc = INPH_IA_VCC(vcc);
25851 if (ia_vcc == NULL)
25852 {
25853 - atomic_inc(&vcc->stats->rx_err);
25854 + atomic_inc_unchecked(&vcc->stats->rx_err);
25855 dev_kfree_skb_any(skb);
25856 atm_return(vcc, atm_guess_pdu2truesize(len));
25857 goto INCR_DLE;
25858 @@ -1306,7 +1306,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25859 if ((length > iadev->rx_buf_sz) || (length >
25860 (skb->len - sizeof(struct cpcs_trailer))))
25861 {
25862 - atomic_inc(&vcc->stats->rx_err);
25863 + atomic_inc_unchecked(&vcc->stats->rx_err);
25864 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
25865 length, skb->len);)
25866 dev_kfree_skb_any(skb);
25867 @@ -1322,7 +1322,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25868
25869 IF_RX(printk("rx_dle_intr: skb push");)
25870 vcc->push(vcc,skb);
25871 - atomic_inc(&vcc->stats->rx);
25872 + atomic_inc_unchecked(&vcc->stats->rx);
25873 iadev->rx_pkt_cnt++;
25874 }
25875 INCR_DLE:
25876 @@ -2802,15 +2802,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
25877 {
25878 struct k_sonet_stats *stats;
25879 stats = &PRIV(_ia_dev[board])->sonet_stats;
25880 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
25881 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
25882 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
25883 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
25884 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
25885 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
25886 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
25887 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
25888 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
25889 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
25890 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
25891 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
25892 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
25893 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
25894 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
25895 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
25896 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
25897 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
25898 }
25899 ia_cmds.status = 0;
25900 break;
25901 @@ -2915,7 +2915,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
25902 if ((desc == 0) || (desc > iadev->num_tx_desc))
25903 {
25904 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
25905 - atomic_inc(&vcc->stats->tx);
25906 + atomic_inc_unchecked(&vcc->stats->tx);
25907 if (vcc->pop)
25908 vcc->pop(vcc, skb);
25909 else
25910 @@ -3020,14 +3020,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
25911 ATM_DESC(skb) = vcc->vci;
25912 skb_queue_tail(&iadev->tx_dma_q, skb);
25913
25914 - atomic_inc(&vcc->stats->tx);
25915 + atomic_inc_unchecked(&vcc->stats->tx);
25916 iadev->tx_pkt_cnt++;
25917 /* Increment transaction counter */
25918 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
25919
25920 #if 0
25921 /* add flow control logic */
25922 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
25923 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
25924 if (iavcc->vc_desc_cnt > 10) {
25925 vcc->tx_quota = vcc->tx_quota * 3 / 4;
25926 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
25927 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
25928 index e828c54..ae83976 100644
25929 --- a/drivers/atm/lanai.c
25930 +++ b/drivers/atm/lanai.c
25931 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
25932 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
25933 lanai_endtx(lanai, lvcc);
25934 lanai_free_skb(lvcc->tx.atmvcc, skb);
25935 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
25936 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
25937 }
25938
25939 /* Try to fill the buffer - don't call unless there is backlog */
25940 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
25941 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
25942 __net_timestamp(skb);
25943 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
25944 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
25945 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
25946 out:
25947 lvcc->rx.buf.ptr = end;
25948 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
25949 @@ -1668,7 +1668,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25950 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
25951 "vcc %d\n", lanai->number, (unsigned int) s, vci);
25952 lanai->stats.service_rxnotaal5++;
25953 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25954 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25955 return 0;
25956 }
25957 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
25958 @@ -1680,7 +1680,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25959 int bytes;
25960 read_unlock(&vcc_sklist_lock);
25961 DPRINTK("got trashed rx pdu on vci %d\n", vci);
25962 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25963 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25964 lvcc->stats.x.aal5.service_trash++;
25965 bytes = (SERVICE_GET_END(s) * 16) -
25966 (((unsigned long) lvcc->rx.buf.ptr) -
25967 @@ -1692,7 +1692,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25968 }
25969 if (s & SERVICE_STREAM) {
25970 read_unlock(&vcc_sklist_lock);
25971 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25972 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25973 lvcc->stats.x.aal5.service_stream++;
25974 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
25975 "PDU on VCI %d!\n", lanai->number, vci);
25976 @@ -1700,7 +1700,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25977 return 0;
25978 }
25979 DPRINTK("got rx crc error on vci %d\n", vci);
25980 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25981 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25982 lvcc->stats.x.aal5.service_rxcrc++;
25983 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
25984 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
25985 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
25986 index 1c70c45..300718d 100644
25987 --- a/drivers/atm/nicstar.c
25988 +++ b/drivers/atm/nicstar.c
25989 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25990 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
25991 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
25992 card->index);
25993 - atomic_inc(&vcc->stats->tx_err);
25994 + atomic_inc_unchecked(&vcc->stats->tx_err);
25995 dev_kfree_skb_any(skb);
25996 return -EINVAL;
25997 }
25998 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25999 if (!vc->tx) {
26000 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
26001 card->index);
26002 - atomic_inc(&vcc->stats->tx_err);
26003 + atomic_inc_unchecked(&vcc->stats->tx_err);
26004 dev_kfree_skb_any(skb);
26005 return -EINVAL;
26006 }
26007 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
26008 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
26009 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
26010 card->index);
26011 - atomic_inc(&vcc->stats->tx_err);
26012 + atomic_inc_unchecked(&vcc->stats->tx_err);
26013 dev_kfree_skb_any(skb);
26014 return -EINVAL;
26015 }
26016
26017 if (skb_shinfo(skb)->nr_frags != 0) {
26018 printk("nicstar%d: No scatter-gather yet.\n", card->index);
26019 - atomic_inc(&vcc->stats->tx_err);
26020 + atomic_inc_unchecked(&vcc->stats->tx_err);
26021 dev_kfree_skb_any(skb);
26022 return -EINVAL;
26023 }
26024 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
26025 }
26026
26027 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
26028 - atomic_inc(&vcc->stats->tx_err);
26029 + atomic_inc_unchecked(&vcc->stats->tx_err);
26030 dev_kfree_skb_any(skb);
26031 return -EIO;
26032 }
26033 - atomic_inc(&vcc->stats->tx);
26034 + atomic_inc_unchecked(&vcc->stats->tx);
26035
26036 return 0;
26037 }
26038 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26039 printk
26040 ("nicstar%d: Can't allocate buffers for aal0.\n",
26041 card->index);
26042 - atomic_add(i, &vcc->stats->rx_drop);
26043 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
26044 break;
26045 }
26046 if (!atm_charge(vcc, sb->truesize)) {
26047 RXPRINTK
26048 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
26049 card->index);
26050 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
26051 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
26052 dev_kfree_skb_any(sb);
26053 break;
26054 }
26055 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26056 ATM_SKB(sb)->vcc = vcc;
26057 __net_timestamp(sb);
26058 vcc->push(vcc, sb);
26059 - atomic_inc(&vcc->stats->rx);
26060 + atomic_inc_unchecked(&vcc->stats->rx);
26061 cell += ATM_CELL_PAYLOAD;
26062 }
26063
26064 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26065 if (iovb == NULL) {
26066 printk("nicstar%d: Out of iovec buffers.\n",
26067 card->index);
26068 - atomic_inc(&vcc->stats->rx_drop);
26069 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26070 recycle_rx_buf(card, skb);
26071 return;
26072 }
26073 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26074 small or large buffer itself. */
26075 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
26076 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
26077 - atomic_inc(&vcc->stats->rx_err);
26078 + atomic_inc_unchecked(&vcc->stats->rx_err);
26079 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26080 NS_MAX_IOVECS);
26081 NS_PRV_IOVCNT(iovb) = 0;
26082 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26083 ("nicstar%d: Expected a small buffer, and this is not one.\n",
26084 card->index);
26085 which_list(card, skb);
26086 - atomic_inc(&vcc->stats->rx_err);
26087 + atomic_inc_unchecked(&vcc->stats->rx_err);
26088 recycle_rx_buf(card, skb);
26089 vc->rx_iov = NULL;
26090 recycle_iov_buf(card, iovb);
26091 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26092 ("nicstar%d: Expected a large buffer, and this is not one.\n",
26093 card->index);
26094 which_list(card, skb);
26095 - atomic_inc(&vcc->stats->rx_err);
26096 + atomic_inc_unchecked(&vcc->stats->rx_err);
26097 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26098 NS_PRV_IOVCNT(iovb));
26099 vc->rx_iov = NULL;
26100 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26101 printk(" - PDU size mismatch.\n");
26102 else
26103 printk(".\n");
26104 - atomic_inc(&vcc->stats->rx_err);
26105 + atomic_inc_unchecked(&vcc->stats->rx_err);
26106 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26107 NS_PRV_IOVCNT(iovb));
26108 vc->rx_iov = NULL;
26109 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26110 /* skb points to a small buffer */
26111 if (!atm_charge(vcc, skb->truesize)) {
26112 push_rxbufs(card, skb);
26113 - atomic_inc(&vcc->stats->rx_drop);
26114 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26115 } else {
26116 skb_put(skb, len);
26117 dequeue_sm_buf(card, skb);
26118 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26119 ATM_SKB(skb)->vcc = vcc;
26120 __net_timestamp(skb);
26121 vcc->push(vcc, skb);
26122 - atomic_inc(&vcc->stats->rx);
26123 + atomic_inc_unchecked(&vcc->stats->rx);
26124 }
26125 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
26126 struct sk_buff *sb;
26127 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26128 if (len <= NS_SMBUFSIZE) {
26129 if (!atm_charge(vcc, sb->truesize)) {
26130 push_rxbufs(card, sb);
26131 - atomic_inc(&vcc->stats->rx_drop);
26132 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26133 } else {
26134 skb_put(sb, len);
26135 dequeue_sm_buf(card, sb);
26136 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26137 ATM_SKB(sb)->vcc = vcc;
26138 __net_timestamp(sb);
26139 vcc->push(vcc, sb);
26140 - atomic_inc(&vcc->stats->rx);
26141 + atomic_inc_unchecked(&vcc->stats->rx);
26142 }
26143
26144 push_rxbufs(card, skb);
26145 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26146
26147 if (!atm_charge(vcc, skb->truesize)) {
26148 push_rxbufs(card, skb);
26149 - atomic_inc(&vcc->stats->rx_drop);
26150 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26151 } else {
26152 dequeue_lg_buf(card, skb);
26153 #ifdef NS_USE_DESTRUCTORS
26154 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26155 ATM_SKB(skb)->vcc = vcc;
26156 __net_timestamp(skb);
26157 vcc->push(vcc, skb);
26158 - atomic_inc(&vcc->stats->rx);
26159 + atomic_inc_unchecked(&vcc->stats->rx);
26160 }
26161
26162 push_rxbufs(card, sb);
26163 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26164 printk
26165 ("nicstar%d: Out of huge buffers.\n",
26166 card->index);
26167 - atomic_inc(&vcc->stats->rx_drop);
26168 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26169 recycle_iovec_rx_bufs(card,
26170 (struct iovec *)
26171 iovb->data,
26172 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26173 card->hbpool.count++;
26174 } else
26175 dev_kfree_skb_any(hb);
26176 - atomic_inc(&vcc->stats->rx_drop);
26177 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26178 } else {
26179 /* Copy the small buffer to the huge buffer */
26180 sb = (struct sk_buff *)iov->iov_base;
26181 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26182 #endif /* NS_USE_DESTRUCTORS */
26183 __net_timestamp(hb);
26184 vcc->push(vcc, hb);
26185 - atomic_inc(&vcc->stats->rx);
26186 + atomic_inc_unchecked(&vcc->stats->rx);
26187 }
26188 }
26189
26190 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
26191 index 5d1d076..4f31f42 100644
26192 --- a/drivers/atm/solos-pci.c
26193 +++ b/drivers/atm/solos-pci.c
26194 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
26195 }
26196 atm_charge(vcc, skb->truesize);
26197 vcc->push(vcc, skb);
26198 - atomic_inc(&vcc->stats->rx);
26199 + atomic_inc_unchecked(&vcc->stats->rx);
26200 break;
26201
26202 case PKT_STATUS:
26203 @@ -899,6 +899,8 @@ static int print_buffer(struct sk_buff *buf)
26204 char msg[500];
26205 char item[10];
26206
26207 + pax_track_stack();
26208 +
26209 len = buf->len;
26210 for (i = 0; i < len; i++){
26211 if(i % 8 == 0)
26212 @@ -1008,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_card *card)
26213 vcc = SKB_CB(oldskb)->vcc;
26214
26215 if (vcc) {
26216 - atomic_inc(&vcc->stats->tx);
26217 + atomic_inc_unchecked(&vcc->stats->tx);
26218 solos_pop(vcc, oldskb);
26219 } else
26220 dev_kfree_skb_irq(oldskb);
26221 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
26222 index 90f1ccc..04c4a1e 100644
26223 --- a/drivers/atm/suni.c
26224 +++ b/drivers/atm/suni.c
26225 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
26226
26227
26228 #define ADD_LIMITED(s,v) \
26229 - atomic_add((v),&stats->s); \
26230 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
26231 + atomic_add_unchecked((v),&stats->s); \
26232 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
26233
26234
26235 static void suni_hz(unsigned long from_timer)
26236 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
26237 index 5120a96..e2572bd 100644
26238 --- a/drivers/atm/uPD98402.c
26239 +++ b/drivers/atm/uPD98402.c
26240 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
26241 struct sonet_stats tmp;
26242 int error = 0;
26243
26244 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26245 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26246 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
26247 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
26248 if (zero && !error) {
26249 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
26250
26251
26252 #define ADD_LIMITED(s,v) \
26253 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
26254 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
26255 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26256 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
26257 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
26258 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26259
26260
26261 static void stat_event(struct atm_dev *dev)
26262 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
26263 if (reason & uPD98402_INT_PFM) stat_event(dev);
26264 if (reason & uPD98402_INT_PCO) {
26265 (void) GET(PCOCR); /* clear interrupt cause */
26266 - atomic_add(GET(HECCT),
26267 + atomic_add_unchecked(GET(HECCT),
26268 &PRIV(dev)->sonet_stats.uncorr_hcs);
26269 }
26270 if ((reason & uPD98402_INT_RFO) &&
26271 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
26272 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
26273 uPD98402_INT_LOS),PIMR); /* enable them */
26274 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
26275 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26276 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
26277 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
26278 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26279 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
26280 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
26281 return 0;
26282 }
26283
26284 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
26285 index d889f56..17eb71e 100644
26286 --- a/drivers/atm/zatm.c
26287 +++ b/drivers/atm/zatm.c
26288 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
26289 }
26290 if (!size) {
26291 dev_kfree_skb_irq(skb);
26292 - if (vcc) atomic_inc(&vcc->stats->rx_err);
26293 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
26294 continue;
26295 }
26296 if (!atm_charge(vcc,skb->truesize)) {
26297 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
26298 skb->len = size;
26299 ATM_SKB(skb)->vcc = vcc;
26300 vcc->push(vcc,skb);
26301 - atomic_inc(&vcc->stats->rx);
26302 + atomic_inc_unchecked(&vcc->stats->rx);
26303 }
26304 zout(pos & 0xffff,MTA(mbx));
26305 #if 0 /* probably a stupid idea */
26306 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
26307 skb_queue_head(&zatm_vcc->backlog,skb);
26308 break;
26309 }
26310 - atomic_inc(&vcc->stats->tx);
26311 + atomic_inc_unchecked(&vcc->stats->tx);
26312 wake_up(&zatm_vcc->tx_wait);
26313 }
26314
26315 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
26316 index a4760e0..51283cf 100644
26317 --- a/drivers/base/devtmpfs.c
26318 +++ b/drivers/base/devtmpfs.c
26319 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
26320 if (!thread)
26321 return 0;
26322
26323 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
26324 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
26325 if (err)
26326 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
26327 else
26328 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
26329 index 84f7c7d..37cfd87 100644
26330 --- a/drivers/base/power/wakeup.c
26331 +++ b/drivers/base/power/wakeup.c
26332 @@ -29,14 +29,14 @@ bool events_check_enabled;
26333 * They need to be modified together atomically, so it's better to use one
26334 * atomic variable to hold them both.
26335 */
26336 -static atomic_t combined_event_count = ATOMIC_INIT(0);
26337 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
26338
26339 #define IN_PROGRESS_BITS (sizeof(int) * 4)
26340 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
26341
26342 static void split_counters(unsigned int *cnt, unsigned int *inpr)
26343 {
26344 - unsigned int comb = atomic_read(&combined_event_count);
26345 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
26346
26347 *cnt = (comb >> IN_PROGRESS_BITS);
26348 *inpr = comb & MAX_IN_PROGRESS;
26349 @@ -350,7 +350,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
26350 ws->last_time = ktime_get();
26351
26352 /* Increment the counter of events in progress. */
26353 - atomic_inc(&combined_event_count);
26354 + atomic_inc_unchecked(&combined_event_count);
26355 }
26356
26357 /**
26358 @@ -440,7 +440,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
26359 * Increment the counter of registered wakeup events and decrement the
26360 * couter of wakeup events in progress simultaneously.
26361 */
26362 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
26363 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
26364 }
26365
26366 /**
26367 diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
26368 index e086fbb..398e1fe 100644
26369 --- a/drivers/block/DAC960.c
26370 +++ b/drivers/block/DAC960.c
26371 @@ -1980,6 +1980,8 @@ static bool DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
26372 unsigned long flags;
26373 int Channel, TargetID;
26374
26375 + pax_track_stack();
26376 +
26377 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
26378 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
26379 sizeof(DAC960_SCSI_Inquiry_T) +
26380 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
26381 index c2f9b3e..11b8693 100644
26382 --- a/drivers/block/cciss.c
26383 +++ b/drivers/block/cciss.c
26384 @@ -1179,6 +1179,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
26385 int err;
26386 u32 cp;
26387
26388 + memset(&arg64, 0, sizeof(arg64));
26389 +
26390 err = 0;
26391 err |=
26392 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
26393 @@ -1716,7 +1718,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
26394 case CCISS_BIG_PASSTHRU:
26395 return cciss_bigpassthru(h, argp);
26396
26397 - /* scsi_cmd_ioctl handles these, below, though some are not */
26398 + /* scsi_cmd_blk_ioctl handles these, below, though some are not */
26399 /* very meaningful for cciss. SG_IO is the main one people want. */
26400
26401 case SG_GET_VERSION_NUM:
26402 @@ -1727,9 +1729,9 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
26403 case SG_EMULATED_HOST:
26404 case SG_IO:
26405 case SCSI_IOCTL_SEND_COMMAND:
26406 - return scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp);
26407 + return scsi_cmd_blk_ioctl(bdev, mode, cmd, argp);
26408
26409 - /* scsi_cmd_ioctl would normally handle these, below, but */
26410 + /* scsi_cmd_blk_ioctl would normally handle these, below, but */
26411 /* they aren't a good fit for cciss, as CD-ROMs are */
26412 /* not supported, and we don't have any bus/target/lun */
26413 /* which we present to the kernel. */
26414 @@ -2986,7 +2988,7 @@ static void start_io(ctlr_info_t *h)
26415 while (!list_empty(&h->reqQ)) {
26416 c = list_entry(h->reqQ.next, CommandList_struct, list);
26417 /* can't do anything if fifo is full */
26418 - if ((h->access.fifo_full(h))) {
26419 + if ((h->access->fifo_full(h))) {
26420 dev_warn(&h->pdev->dev, "fifo full\n");
26421 break;
26422 }
26423 @@ -2996,7 +2998,7 @@ static void start_io(ctlr_info_t *h)
26424 h->Qdepth--;
26425
26426 /* Tell the controller execute command */
26427 - h->access.submit_command(h, c);
26428 + h->access->submit_command(h, c);
26429
26430 /* Put job onto the completed Q */
26431 addQ(&h->cmpQ, c);
26432 @@ -3422,17 +3424,17 @@ startio:
26433
26434 static inline unsigned long get_next_completion(ctlr_info_t *h)
26435 {
26436 - return h->access.command_completed(h);
26437 + return h->access->command_completed(h);
26438 }
26439
26440 static inline int interrupt_pending(ctlr_info_t *h)
26441 {
26442 - return h->access.intr_pending(h);
26443 + return h->access->intr_pending(h);
26444 }
26445
26446 static inline long interrupt_not_for_us(ctlr_info_t *h)
26447 {
26448 - return ((h->access.intr_pending(h) == 0) ||
26449 + return ((h->access->intr_pending(h) == 0) ||
26450 (h->interrupts_enabled == 0));
26451 }
26452
26453 @@ -3465,7 +3467,7 @@ static inline u32 next_command(ctlr_info_t *h)
26454 u32 a;
26455
26456 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
26457 - return h->access.command_completed(h);
26458 + return h->access->command_completed(h);
26459
26460 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
26461 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
26462 @@ -4020,7 +4022,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
26463 trans_support & CFGTBL_Trans_use_short_tags);
26464
26465 /* Change the access methods to the performant access methods */
26466 - h->access = SA5_performant_access;
26467 + h->access = &SA5_performant_access;
26468 h->transMethod = CFGTBL_Trans_Performant;
26469
26470 return;
26471 @@ -4292,7 +4294,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
26472 if (prod_index < 0)
26473 return -ENODEV;
26474 h->product_name = products[prod_index].product_name;
26475 - h->access = *(products[prod_index].access);
26476 + h->access = products[prod_index].access;
26477
26478 if (cciss_board_disabled(h)) {
26479 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
26480 @@ -5009,7 +5011,7 @@ reinit_after_soft_reset:
26481 }
26482
26483 /* make sure the board interrupts are off */
26484 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26485 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26486 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
26487 if (rc)
26488 goto clean2;
26489 @@ -5061,7 +5063,7 @@ reinit_after_soft_reset:
26490 * fake ones to scoop up any residual completions.
26491 */
26492 spin_lock_irqsave(&h->lock, flags);
26493 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26494 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26495 spin_unlock_irqrestore(&h->lock, flags);
26496 free_irq(h->intr[PERF_MODE_INT], h);
26497 rc = cciss_request_irq(h, cciss_msix_discard_completions,
26498 @@ -5081,9 +5083,9 @@ reinit_after_soft_reset:
26499 dev_info(&h->pdev->dev, "Board READY.\n");
26500 dev_info(&h->pdev->dev,
26501 "Waiting for stale completions to drain.\n");
26502 - h->access.set_intr_mask(h, CCISS_INTR_ON);
26503 + h->access->set_intr_mask(h, CCISS_INTR_ON);
26504 msleep(10000);
26505 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26506 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26507
26508 rc = controller_reset_failed(h->cfgtable);
26509 if (rc)
26510 @@ -5106,7 +5108,7 @@ reinit_after_soft_reset:
26511 cciss_scsi_setup(h);
26512
26513 /* Turn the interrupts on so we can service requests */
26514 - h->access.set_intr_mask(h, CCISS_INTR_ON);
26515 + h->access->set_intr_mask(h, CCISS_INTR_ON);
26516
26517 /* Get the firmware version */
26518 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
26519 @@ -5178,7 +5180,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
26520 kfree(flush_buf);
26521 if (return_code != IO_OK)
26522 dev_warn(&h->pdev->dev, "Error flushing cache\n");
26523 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26524 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26525 free_irq(h->intr[PERF_MODE_INT], h);
26526 }
26527
26528 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
26529 index c049548..a09cb6e 100644
26530 --- a/drivers/block/cciss.h
26531 +++ b/drivers/block/cciss.h
26532 @@ -100,7 +100,7 @@ struct ctlr_info
26533 /* information about each logical volume */
26534 drive_info_struct *drv[CISS_MAX_LUN];
26535
26536 - struct access_method access;
26537 + struct access_method *access;
26538
26539 /* queue and queue Info */
26540 struct list_head reqQ;
26541 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
26542 index b2fceb5..87fec83 100644
26543 --- a/drivers/block/cpqarray.c
26544 +++ b/drivers/block/cpqarray.c
26545 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
26546 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
26547 goto Enomem4;
26548 }
26549 - hba[i]->access.set_intr_mask(hba[i], 0);
26550 + hba[i]->access->set_intr_mask(hba[i], 0);
26551 if (request_irq(hba[i]->intr, do_ida_intr,
26552 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
26553 {
26554 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
26555 add_timer(&hba[i]->timer);
26556
26557 /* Enable IRQ now that spinlock and rate limit timer are set up */
26558 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
26559 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
26560
26561 for(j=0; j<NWD; j++) {
26562 struct gendisk *disk = ida_gendisk[i][j];
26563 @@ -694,7 +694,7 @@ DBGINFO(
26564 for(i=0; i<NR_PRODUCTS; i++) {
26565 if (board_id == products[i].board_id) {
26566 c->product_name = products[i].product_name;
26567 - c->access = *(products[i].access);
26568 + c->access = products[i].access;
26569 break;
26570 }
26571 }
26572 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
26573 hba[ctlr]->intr = intr;
26574 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
26575 hba[ctlr]->product_name = products[j].product_name;
26576 - hba[ctlr]->access = *(products[j].access);
26577 + hba[ctlr]->access = products[j].access;
26578 hba[ctlr]->ctlr = ctlr;
26579 hba[ctlr]->board_id = board_id;
26580 hba[ctlr]->pci_dev = NULL; /* not PCI */
26581 @@ -911,6 +911,8 @@ static void do_ida_request(struct request_queue *q)
26582 struct scatterlist tmp_sg[SG_MAX];
26583 int i, dir, seg;
26584
26585 + pax_track_stack();
26586 +
26587 queue_next:
26588 creq = blk_peek_request(q);
26589 if (!creq)
26590 @@ -980,7 +982,7 @@ static void start_io(ctlr_info_t *h)
26591
26592 while((c = h->reqQ) != NULL) {
26593 /* Can't do anything if we're busy */
26594 - if (h->access.fifo_full(h) == 0)
26595 + if (h->access->fifo_full(h) == 0)
26596 return;
26597
26598 /* Get the first entry from the request Q */
26599 @@ -988,7 +990,7 @@ static void start_io(ctlr_info_t *h)
26600 h->Qdepth--;
26601
26602 /* Tell the controller to do our bidding */
26603 - h->access.submit_command(h, c);
26604 + h->access->submit_command(h, c);
26605
26606 /* Get onto the completion Q */
26607 addQ(&h->cmpQ, c);
26608 @@ -1050,7 +1052,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
26609 unsigned long flags;
26610 __u32 a,a1;
26611
26612 - istat = h->access.intr_pending(h);
26613 + istat = h->access->intr_pending(h);
26614 /* Is this interrupt for us? */
26615 if (istat == 0)
26616 return IRQ_NONE;
26617 @@ -1061,7 +1063,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
26618 */
26619 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
26620 if (istat & FIFO_NOT_EMPTY) {
26621 - while((a = h->access.command_completed(h))) {
26622 + while((a = h->access->command_completed(h))) {
26623 a1 = a; a &= ~3;
26624 if ((c = h->cmpQ) == NULL)
26625 {
26626 @@ -1449,11 +1451,11 @@ static int sendcmd(
26627 /*
26628 * Disable interrupt
26629 */
26630 - info_p->access.set_intr_mask(info_p, 0);
26631 + info_p->access->set_intr_mask(info_p, 0);
26632 /* Make sure there is room in the command FIFO */
26633 /* Actually it should be completely empty at this time. */
26634 for (i = 200000; i > 0; i--) {
26635 - temp = info_p->access.fifo_full(info_p);
26636 + temp = info_p->access->fifo_full(info_p);
26637 if (temp != 0) {
26638 break;
26639 }
26640 @@ -1466,7 +1468,7 @@ DBG(
26641 /*
26642 * Send the cmd
26643 */
26644 - info_p->access.submit_command(info_p, c);
26645 + info_p->access->submit_command(info_p, c);
26646 complete = pollcomplete(ctlr);
26647
26648 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
26649 @@ -1549,9 +1551,9 @@ static int revalidate_allvol(ctlr_info_t *host)
26650 * we check the new geometry. Then turn interrupts back on when
26651 * we're done.
26652 */
26653 - host->access.set_intr_mask(host, 0);
26654 + host->access->set_intr_mask(host, 0);
26655 getgeometry(ctlr);
26656 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
26657 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
26658
26659 for(i=0; i<NWD; i++) {
26660 struct gendisk *disk = ida_gendisk[ctlr][i];
26661 @@ -1591,7 +1593,7 @@ static int pollcomplete(int ctlr)
26662 /* Wait (up to 2 seconds) for a command to complete */
26663
26664 for (i = 200000; i > 0; i--) {
26665 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
26666 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
26667 if (done == 0) {
26668 udelay(10); /* a short fixed delay */
26669 } else
26670 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
26671 index be73e9d..7fbf140 100644
26672 --- a/drivers/block/cpqarray.h
26673 +++ b/drivers/block/cpqarray.h
26674 @@ -99,7 +99,7 @@ struct ctlr_info {
26675 drv_info_t drv[NWD];
26676 struct proc_dir_entry *proc;
26677
26678 - struct access_method access;
26679 + struct access_method *access;
26680
26681 cmdlist_t *reqQ;
26682 cmdlist_t *cmpQ;
26683 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
26684 index ef2ceed..c9cb18e 100644
26685 --- a/drivers/block/drbd/drbd_int.h
26686 +++ b/drivers/block/drbd/drbd_int.h
26687 @@ -737,7 +737,7 @@ struct drbd_request;
26688 struct drbd_epoch {
26689 struct list_head list;
26690 unsigned int barrier_nr;
26691 - atomic_t epoch_size; /* increased on every request added. */
26692 + atomic_unchecked_t epoch_size; /* increased on every request added. */
26693 atomic_t active; /* increased on every req. added, and dec on every finished. */
26694 unsigned long flags;
26695 };
26696 @@ -1109,7 +1109,7 @@ struct drbd_conf {
26697 void *int_dig_in;
26698 void *int_dig_vv;
26699 wait_queue_head_t seq_wait;
26700 - atomic_t packet_seq;
26701 + atomic_unchecked_t packet_seq;
26702 unsigned int peer_seq;
26703 spinlock_t peer_seq_lock;
26704 unsigned int minor;
26705 @@ -1618,30 +1618,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
26706
26707 static inline void drbd_tcp_cork(struct socket *sock)
26708 {
26709 - int __user val = 1;
26710 + int val = 1;
26711 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
26712 - (char __user *)&val, sizeof(val));
26713 + (char __force_user *)&val, sizeof(val));
26714 }
26715
26716 static inline void drbd_tcp_uncork(struct socket *sock)
26717 {
26718 - int __user val = 0;
26719 + int val = 0;
26720 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
26721 - (char __user *)&val, sizeof(val));
26722 + (char __force_user *)&val, sizeof(val));
26723 }
26724
26725 static inline void drbd_tcp_nodelay(struct socket *sock)
26726 {
26727 - int __user val = 1;
26728 + int val = 1;
26729 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
26730 - (char __user *)&val, sizeof(val));
26731 + (char __force_user *)&val, sizeof(val));
26732 }
26733
26734 static inline void drbd_tcp_quickack(struct socket *sock)
26735 {
26736 - int __user val = 2;
26737 + int val = 2;
26738 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
26739 - (char __user *)&val, sizeof(val));
26740 + (char __force_user *)&val, sizeof(val));
26741 }
26742
26743 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
26744 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
26745 index 0358e55..bc33689 100644
26746 --- a/drivers/block/drbd/drbd_main.c
26747 +++ b/drivers/block/drbd/drbd_main.c
26748 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
26749 p.sector = sector;
26750 p.block_id = block_id;
26751 p.blksize = blksize;
26752 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
26753 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
26754
26755 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
26756 return false;
26757 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
26758 p.sector = cpu_to_be64(req->sector);
26759 p.block_id = (unsigned long)req;
26760 p.seq_num = cpu_to_be32(req->seq_num =
26761 - atomic_add_return(1, &mdev->packet_seq));
26762 + atomic_add_return_unchecked(1, &mdev->packet_seq));
26763
26764 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
26765
26766 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
26767 atomic_set(&mdev->unacked_cnt, 0);
26768 atomic_set(&mdev->local_cnt, 0);
26769 atomic_set(&mdev->net_cnt, 0);
26770 - atomic_set(&mdev->packet_seq, 0);
26771 + atomic_set_unchecked(&mdev->packet_seq, 0);
26772 atomic_set(&mdev->pp_in_use, 0);
26773 atomic_set(&mdev->pp_in_use_by_net, 0);
26774 atomic_set(&mdev->rs_sect_in, 0);
26775 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
26776 mdev->receiver.t_state);
26777
26778 /* no need to lock it, I'm the only thread alive */
26779 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
26780 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
26781 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
26782 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
26783 mdev->al_writ_cnt =
26784 mdev->bm_writ_cnt =
26785 mdev->read_cnt =
26786 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
26787 index 0feab26..5d9b3dd 100644
26788 --- a/drivers/block/drbd/drbd_nl.c
26789 +++ b/drivers/block/drbd/drbd_nl.c
26790 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
26791 module_put(THIS_MODULE);
26792 }
26793
26794 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
26795 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
26796
26797 static unsigned short *
26798 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
26799 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
26800 cn_reply->id.idx = CN_IDX_DRBD;
26801 cn_reply->id.val = CN_VAL_DRBD;
26802
26803 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26804 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26805 cn_reply->ack = 0; /* not used here. */
26806 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26807 (int)((char *)tl - (char *)reply->tag_list);
26808 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
26809 cn_reply->id.idx = CN_IDX_DRBD;
26810 cn_reply->id.val = CN_VAL_DRBD;
26811
26812 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26813 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26814 cn_reply->ack = 0; /* not used here. */
26815 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26816 (int)((char *)tl - (char *)reply->tag_list);
26817 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
26818 cn_reply->id.idx = CN_IDX_DRBD;
26819 cn_reply->id.val = CN_VAL_DRBD;
26820
26821 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
26822 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
26823 cn_reply->ack = 0; // not used here.
26824 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26825 (int)((char*)tl - (char*)reply->tag_list);
26826 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
26827 cn_reply->id.idx = CN_IDX_DRBD;
26828 cn_reply->id.val = CN_VAL_DRBD;
26829
26830 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26831 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26832 cn_reply->ack = 0; /* not used here. */
26833 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26834 (int)((char *)tl - (char *)reply->tag_list);
26835 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
26836 index 43beaca..4a5b1dd 100644
26837 --- a/drivers/block/drbd/drbd_receiver.c
26838 +++ b/drivers/block/drbd/drbd_receiver.c
26839 @@ -894,7 +894,7 @@ retry:
26840 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
26841 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
26842
26843 - atomic_set(&mdev->packet_seq, 0);
26844 + atomic_set_unchecked(&mdev->packet_seq, 0);
26845 mdev->peer_seq = 0;
26846
26847 drbd_thread_start(&mdev->asender);
26848 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
26849 do {
26850 next_epoch = NULL;
26851
26852 - epoch_size = atomic_read(&epoch->epoch_size);
26853 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
26854
26855 switch (ev & ~EV_CLEANUP) {
26856 case EV_PUT:
26857 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
26858 rv = FE_DESTROYED;
26859 } else {
26860 epoch->flags = 0;
26861 - atomic_set(&epoch->epoch_size, 0);
26862 + atomic_set_unchecked(&epoch->epoch_size, 0);
26863 /* atomic_set(&epoch->active, 0); is already zero */
26864 if (rv == FE_STILL_LIVE)
26865 rv = FE_RECYCLED;
26866 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
26867 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
26868 drbd_flush(mdev);
26869
26870 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
26871 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
26872 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
26873 if (epoch)
26874 break;
26875 }
26876
26877 epoch = mdev->current_epoch;
26878 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
26879 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
26880
26881 D_ASSERT(atomic_read(&epoch->active) == 0);
26882 D_ASSERT(epoch->flags == 0);
26883 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
26884 }
26885
26886 epoch->flags = 0;
26887 - atomic_set(&epoch->epoch_size, 0);
26888 + atomic_set_unchecked(&epoch->epoch_size, 0);
26889 atomic_set(&epoch->active, 0);
26890
26891 spin_lock(&mdev->epoch_lock);
26892 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
26893 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
26894 list_add(&epoch->list, &mdev->current_epoch->list);
26895 mdev->current_epoch = epoch;
26896 mdev->epochs++;
26897 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
26898 spin_unlock(&mdev->peer_seq_lock);
26899
26900 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
26901 - atomic_inc(&mdev->current_epoch->epoch_size);
26902 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
26903 return drbd_drain_block(mdev, data_size);
26904 }
26905
26906 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
26907
26908 spin_lock(&mdev->epoch_lock);
26909 e->epoch = mdev->current_epoch;
26910 - atomic_inc(&e->epoch->epoch_size);
26911 + atomic_inc_unchecked(&e->epoch->epoch_size);
26912 atomic_inc(&e->epoch->active);
26913 spin_unlock(&mdev->epoch_lock);
26914
26915 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
26916 D_ASSERT(list_empty(&mdev->done_ee));
26917
26918 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
26919 - atomic_set(&mdev->current_epoch->epoch_size, 0);
26920 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
26921 D_ASSERT(list_empty(&mdev->current_epoch->list));
26922 }
26923
26924 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
26925 index 4720c7a..2c49af1 100644
26926 --- a/drivers/block/loop.c
26927 +++ b/drivers/block/loop.c
26928 @@ -283,7 +283,7 @@ static int __do_lo_send_write(struct file *file,
26929 mm_segment_t old_fs = get_fs();
26930
26931 set_fs(get_ds());
26932 - bw = file->f_op->write(file, buf, len, &pos);
26933 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
26934 set_fs(old_fs);
26935 if (likely(bw == len))
26936 return 0;
26937 diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
26938 index f533f33..6177bcb 100644
26939 --- a/drivers/block/nbd.c
26940 +++ b/drivers/block/nbd.c
26941 @@ -157,6 +157,8 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size,
26942 struct kvec iov;
26943 sigset_t blocked, oldset;
26944
26945 + pax_track_stack();
26946 +
26947 if (unlikely(!sock)) {
26948 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
26949 lo->disk->disk_name, (send ? "send" : "recv"));
26950 @@ -572,6 +574,8 @@ static void do_nbd_request(struct request_queue *q)
26951 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
26952 unsigned int cmd, unsigned long arg)
26953 {
26954 + pax_track_stack();
26955 +
26956 switch (cmd) {
26957 case NBD_DISCONNECT: {
26958 struct request sreq;
26959 diff --git a/drivers/block/ub.c b/drivers/block/ub.c
26960 index 0e376d4..7333b9e 100644
26961 --- a/drivers/block/ub.c
26962 +++ b/drivers/block/ub.c
26963 @@ -1744,12 +1744,11 @@ static int ub_bd_release(struct gendisk *disk, fmode_t mode)
26964 static int ub_bd_ioctl(struct block_device *bdev, fmode_t mode,
26965 unsigned int cmd, unsigned long arg)
26966 {
26967 - struct gendisk *disk = bdev->bd_disk;
26968 void __user *usermem = (void __user *) arg;
26969 int ret;
26970
26971 mutex_lock(&ub_mutex);
26972 - ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, usermem);
26973 + ret = scsi_cmd_blk_ioctl(bdev, mode, cmd, usermem);
26974 mutex_unlock(&ub_mutex);
26975
26976 return ret;
26977 diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
26978 index 079c088..5d7a934 100644
26979 --- a/drivers/block/virtio_blk.c
26980 +++ b/drivers/block/virtio_blk.c
26981 @@ -236,8 +236,8 @@ static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
26982 if (!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_SCSI))
26983 return -ENOTTY;
26984
26985 - return scsi_cmd_ioctl(disk->queue, disk, mode, cmd,
26986 - (void __user *)data);
26987 + return scsi_cmd_blk_ioctl(bdev, mode, cmd,
26988 + (void __user *)data);
26989 }
26990
26991 /* We provide getgeo only to please some old bootloader/partitioning tools */
26992 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
26993 index f997c27..cedb231 100644
26994 --- a/drivers/cdrom/cdrom.c
26995 +++ b/drivers/cdrom/cdrom.c
26996 @@ -2747,12 +2747,11 @@ int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
26997 {
26998 void __user *argp = (void __user *)arg;
26999 int ret;
27000 - struct gendisk *disk = bdev->bd_disk;
27001
27002 /*
27003 * Try the generic SCSI command ioctl's first.
27004 */
27005 - ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp);
27006 + ret = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp);
27007 if (ret != -ENOTTY)
27008 return ret;
27009
27010 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
27011 index 423fd56..06d3be0 100644
27012 --- a/drivers/char/Kconfig
27013 +++ b/drivers/char/Kconfig
27014 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
27015
27016 config DEVKMEM
27017 bool "/dev/kmem virtual device support"
27018 - default y
27019 + default n
27020 + depends on !GRKERNSEC_KMEM
27021 help
27022 Say Y here if you want to support the /dev/kmem device. The
27023 /dev/kmem device is rarely used, but can be used for certain
27024 @@ -596,6 +597,7 @@ config DEVPORT
27025 bool
27026 depends on !M68K
27027 depends on ISA || PCI
27028 + depends on !GRKERNSEC_KMEM
27029 default y
27030
27031 source "drivers/s390/char/Kconfig"
27032 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
27033 index 2e04433..22afc64 100644
27034 --- a/drivers/char/agp/frontend.c
27035 +++ b/drivers/char/agp/frontend.c
27036 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
27037 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
27038 return -EFAULT;
27039
27040 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
27041 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
27042 return -EFAULT;
27043
27044 client = agp_find_client_by_pid(reserve.pid);
27045 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
27046 index 095ab90..afad0a4 100644
27047 --- a/drivers/char/briq_panel.c
27048 +++ b/drivers/char/briq_panel.c
27049 @@ -9,6 +9,7 @@
27050 #include <linux/types.h>
27051 #include <linux/errno.h>
27052 #include <linux/tty.h>
27053 +#include <linux/mutex.h>
27054 #include <linux/timer.h>
27055 #include <linux/kernel.h>
27056 #include <linux/wait.h>
27057 @@ -34,6 +35,7 @@ static int vfd_is_open;
27058 static unsigned char vfd[40];
27059 static int vfd_cursor;
27060 static unsigned char ledpb, led;
27061 +static DEFINE_MUTEX(vfd_mutex);
27062
27063 static void update_vfd(void)
27064 {
27065 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
27066 if (!vfd_is_open)
27067 return -EBUSY;
27068
27069 + mutex_lock(&vfd_mutex);
27070 for (;;) {
27071 char c;
27072 if (!indx)
27073 break;
27074 - if (get_user(c, buf))
27075 + if (get_user(c, buf)) {
27076 + mutex_unlock(&vfd_mutex);
27077 return -EFAULT;
27078 + }
27079 if (esc) {
27080 set_led(c);
27081 esc = 0;
27082 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
27083 buf++;
27084 }
27085 update_vfd();
27086 + mutex_unlock(&vfd_mutex);
27087
27088 return len;
27089 }
27090 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
27091 index f773a9d..65cd683 100644
27092 --- a/drivers/char/genrtc.c
27093 +++ b/drivers/char/genrtc.c
27094 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
27095 switch (cmd) {
27096
27097 case RTC_PLL_GET:
27098 + memset(&pll, 0, sizeof(pll));
27099 if (get_rtc_pll(&pll))
27100 return -EINVAL;
27101 else
27102 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
27103 index 0833896..cccce52 100644
27104 --- a/drivers/char/hpet.c
27105 +++ b/drivers/char/hpet.c
27106 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
27107 }
27108
27109 static int
27110 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
27111 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
27112 struct hpet_info *info)
27113 {
27114 struct hpet_timer __iomem *timer;
27115 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
27116 index 58c0e63..25aed94 100644
27117 --- a/drivers/char/ipmi/ipmi_msghandler.c
27118 +++ b/drivers/char/ipmi/ipmi_msghandler.c
27119 @@ -415,7 +415,7 @@ struct ipmi_smi {
27120 struct proc_dir_entry *proc_dir;
27121 char proc_dir_name[10];
27122
27123 - atomic_t stats[IPMI_NUM_STATS];
27124 + atomic_unchecked_t stats[IPMI_NUM_STATS];
27125
27126 /*
27127 * run_to_completion duplicate of smb_info, smi_info
27128 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
27129
27130
27131 #define ipmi_inc_stat(intf, stat) \
27132 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
27133 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
27134 #define ipmi_get_stat(intf, stat) \
27135 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
27136 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
27137
27138 static int is_lan_addr(struct ipmi_addr *addr)
27139 {
27140 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
27141 INIT_LIST_HEAD(&intf->cmd_rcvrs);
27142 init_waitqueue_head(&intf->waitq);
27143 for (i = 0; i < IPMI_NUM_STATS; i++)
27144 - atomic_set(&intf->stats[i], 0);
27145 + atomic_set_unchecked(&intf->stats[i], 0);
27146
27147 intf->proc_dir = NULL;
27148
27149 @@ -4220,6 +4220,8 @@ static void send_panic_events(char *str)
27150 struct ipmi_smi_msg smi_msg;
27151 struct ipmi_recv_msg recv_msg;
27152
27153 + pax_track_stack();
27154 +
27155 si = (struct ipmi_system_interface_addr *) &addr;
27156 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
27157 si->channel = IPMI_BMC_CHANNEL;
27158 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
27159 index 9397ab4..d01bee1 100644
27160 --- a/drivers/char/ipmi/ipmi_si_intf.c
27161 +++ b/drivers/char/ipmi/ipmi_si_intf.c
27162 @@ -277,7 +277,7 @@ struct smi_info {
27163 unsigned char slave_addr;
27164
27165 /* Counters and things for the proc filesystem. */
27166 - atomic_t stats[SI_NUM_STATS];
27167 + atomic_unchecked_t stats[SI_NUM_STATS];
27168
27169 struct task_struct *thread;
27170
27171 @@ -286,9 +286,9 @@ struct smi_info {
27172 };
27173
27174 #define smi_inc_stat(smi, stat) \
27175 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
27176 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
27177 #define smi_get_stat(smi, stat) \
27178 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
27179 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
27180
27181 #define SI_MAX_PARMS 4
27182
27183 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
27184 atomic_set(&new_smi->req_events, 0);
27185 new_smi->run_to_completion = 0;
27186 for (i = 0; i < SI_NUM_STATS; i++)
27187 - atomic_set(&new_smi->stats[i], 0);
27188 + atomic_set_unchecked(&new_smi->stats[i], 0);
27189
27190 new_smi->interrupt_disabled = 1;
27191 atomic_set(&new_smi->stop_operation, 0);
27192 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
27193 index 1aeaaba..e018570 100644
27194 --- a/drivers/char/mbcs.c
27195 +++ b/drivers/char/mbcs.c
27196 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
27197 return 0;
27198 }
27199
27200 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
27201 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
27202 {
27203 .part_num = MBCS_PART_NUM,
27204 .mfg_num = MBCS_MFG_NUM,
27205 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
27206 index 8fc04b4..cebdeec 100644
27207 --- a/drivers/char/mem.c
27208 +++ b/drivers/char/mem.c
27209 @@ -18,6 +18,7 @@
27210 #include <linux/raw.h>
27211 #include <linux/tty.h>
27212 #include <linux/capability.h>
27213 +#include <linux/security.h>
27214 #include <linux/ptrace.h>
27215 #include <linux/device.h>
27216 #include <linux/highmem.h>
27217 @@ -34,6 +35,10 @@
27218 # include <linux/efi.h>
27219 #endif
27220
27221 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27222 +extern const struct file_operations grsec_fops;
27223 +#endif
27224 +
27225 static inline unsigned long size_inside_page(unsigned long start,
27226 unsigned long size)
27227 {
27228 @@ -65,9 +70,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27229
27230 while (cursor < to) {
27231 if (!devmem_is_allowed(pfn)) {
27232 +#ifdef CONFIG_GRKERNSEC_KMEM
27233 + gr_handle_mem_readwrite(from, to);
27234 +#else
27235 printk(KERN_INFO
27236 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
27237 current->comm, from, to);
27238 +#endif
27239 return 0;
27240 }
27241 cursor += PAGE_SIZE;
27242 @@ -75,6 +84,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27243 }
27244 return 1;
27245 }
27246 +#elif defined(CONFIG_GRKERNSEC_KMEM)
27247 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27248 +{
27249 + return 0;
27250 +}
27251 #else
27252 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27253 {
27254 @@ -117,6 +131,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
27255
27256 while (count > 0) {
27257 unsigned long remaining;
27258 + char *temp;
27259
27260 sz = size_inside_page(p, count);
27261
27262 @@ -132,7 +147,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
27263 if (!ptr)
27264 return -EFAULT;
27265
27266 - remaining = copy_to_user(buf, ptr, sz);
27267 +#ifdef CONFIG_PAX_USERCOPY
27268 + temp = kmalloc(sz, GFP_KERNEL);
27269 + if (!temp) {
27270 + unxlate_dev_mem_ptr(p, ptr);
27271 + return -ENOMEM;
27272 + }
27273 + memcpy(temp, ptr, sz);
27274 +#else
27275 + temp = ptr;
27276 +#endif
27277 +
27278 + remaining = copy_to_user(buf, temp, sz);
27279 +
27280 +#ifdef CONFIG_PAX_USERCOPY
27281 + kfree(temp);
27282 +#endif
27283 +
27284 unxlate_dev_mem_ptr(p, ptr);
27285 if (remaining)
27286 return -EFAULT;
27287 @@ -395,9 +426,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27288 size_t count, loff_t *ppos)
27289 {
27290 unsigned long p = *ppos;
27291 - ssize_t low_count, read, sz;
27292 + ssize_t low_count, read, sz, err = 0;
27293 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
27294 - int err = 0;
27295
27296 read = 0;
27297 if (p < (unsigned long) high_memory) {
27298 @@ -419,6 +449,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27299 }
27300 #endif
27301 while (low_count > 0) {
27302 + char *temp;
27303 +
27304 sz = size_inside_page(p, low_count);
27305
27306 /*
27307 @@ -428,7 +460,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27308 */
27309 kbuf = xlate_dev_kmem_ptr((char *)p);
27310
27311 - if (copy_to_user(buf, kbuf, sz))
27312 +#ifdef CONFIG_PAX_USERCOPY
27313 + temp = kmalloc(sz, GFP_KERNEL);
27314 + if (!temp)
27315 + return -ENOMEM;
27316 + memcpy(temp, kbuf, sz);
27317 +#else
27318 + temp = kbuf;
27319 +#endif
27320 +
27321 + err = copy_to_user(buf, temp, sz);
27322 +
27323 +#ifdef CONFIG_PAX_USERCOPY
27324 + kfree(temp);
27325 +#endif
27326 +
27327 + if (err)
27328 return -EFAULT;
27329 buf += sz;
27330 p += sz;
27331 @@ -866,6 +913,9 @@ static const struct memdev {
27332 #ifdef CONFIG_CRASH_DUMP
27333 [12] = { "oldmem", 0, &oldmem_fops, NULL },
27334 #endif
27335 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27336 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
27337 +#endif
27338 };
27339
27340 static int memory_open(struct inode *inode, struct file *filp)
27341 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
27342 index da3cfee..a5a6606 100644
27343 --- a/drivers/char/nvram.c
27344 +++ b/drivers/char/nvram.c
27345 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
27346
27347 spin_unlock_irq(&rtc_lock);
27348
27349 - if (copy_to_user(buf, contents, tmp - contents))
27350 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
27351 return -EFAULT;
27352
27353 *ppos = i;
27354 diff --git a/drivers/char/random.c b/drivers/char/random.c
27355 index c35a785..6d82202 100644
27356 --- a/drivers/char/random.c
27357 +++ b/drivers/char/random.c
27358 @@ -261,8 +261,13 @@
27359 /*
27360 * Configuration information
27361 */
27362 +#ifdef CONFIG_GRKERNSEC_RANDNET
27363 +#define INPUT_POOL_WORDS 512
27364 +#define OUTPUT_POOL_WORDS 128
27365 +#else
27366 #define INPUT_POOL_WORDS 128
27367 #define OUTPUT_POOL_WORDS 32
27368 +#endif
27369 #define SEC_XFER_SIZE 512
27370 #define EXTRACT_SIZE 10
27371
27372 @@ -300,10 +305,17 @@ static struct poolinfo {
27373 int poolwords;
27374 int tap1, tap2, tap3, tap4, tap5;
27375 } poolinfo_table[] = {
27376 +#ifdef CONFIG_GRKERNSEC_RANDNET
27377 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
27378 + { 512, 411, 308, 208, 104, 1 },
27379 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
27380 + { 128, 103, 76, 51, 25, 1 },
27381 +#else
27382 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
27383 { 128, 103, 76, 51, 25, 1 },
27384 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
27385 { 32, 26, 20, 14, 7, 1 },
27386 +#endif
27387 #if 0
27388 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
27389 { 2048, 1638, 1231, 819, 411, 1 },
27390 @@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
27391
27392 extract_buf(r, tmp);
27393 i = min_t(int, nbytes, EXTRACT_SIZE);
27394 - if (copy_to_user(buf, tmp, i)) {
27395 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
27396 ret = -EFAULT;
27397 break;
27398 }
27399 @@ -1214,7 +1226,7 @@ EXPORT_SYMBOL(generate_random_uuid);
27400 #include <linux/sysctl.h>
27401
27402 static int min_read_thresh = 8, min_write_thresh;
27403 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
27404 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
27405 static int max_write_thresh = INPUT_POOL_WORDS * 32;
27406 static char sysctl_bootid[16];
27407
27408 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
27409 index 1ee8ce7..b778bef 100644
27410 --- a/drivers/char/sonypi.c
27411 +++ b/drivers/char/sonypi.c
27412 @@ -55,6 +55,7 @@
27413 #include <asm/uaccess.h>
27414 #include <asm/io.h>
27415 #include <asm/system.h>
27416 +#include <asm/local.h>
27417
27418 #include <linux/sonypi.h>
27419
27420 @@ -491,7 +492,7 @@ static struct sonypi_device {
27421 spinlock_t fifo_lock;
27422 wait_queue_head_t fifo_proc_list;
27423 struct fasync_struct *fifo_async;
27424 - int open_count;
27425 + local_t open_count;
27426 int model;
27427 struct input_dev *input_jog_dev;
27428 struct input_dev *input_key_dev;
27429 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
27430 static int sonypi_misc_release(struct inode *inode, struct file *file)
27431 {
27432 mutex_lock(&sonypi_device.lock);
27433 - sonypi_device.open_count--;
27434 + local_dec(&sonypi_device.open_count);
27435 mutex_unlock(&sonypi_device.lock);
27436 return 0;
27437 }
27438 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
27439 {
27440 mutex_lock(&sonypi_device.lock);
27441 /* Flush input queue on first open */
27442 - if (!sonypi_device.open_count)
27443 + if (!local_read(&sonypi_device.open_count))
27444 kfifo_reset(&sonypi_device.fifo);
27445 - sonypi_device.open_count++;
27446 + local_inc(&sonypi_device.open_count);
27447 mutex_unlock(&sonypi_device.lock);
27448
27449 return 0;
27450 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
27451 index 9ca5c02..7ce352c 100644
27452 --- a/drivers/char/tpm/tpm.c
27453 +++ b/drivers/char/tpm/tpm.c
27454 @@ -414,7 +414,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
27455 chip->vendor.req_complete_val)
27456 goto out_recv;
27457
27458 - if ((status == chip->vendor.req_canceled)) {
27459 + if (status == chip->vendor.req_canceled) {
27460 dev_err(chip->dev, "Operation Canceled\n");
27461 rc = -ECANCELED;
27462 goto out;
27463 @@ -862,6 +862,8 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
27464
27465 struct tpm_chip *chip = dev_get_drvdata(dev);
27466
27467 + pax_track_stack();
27468 +
27469 tpm_cmd.header.in = tpm_readpubek_header;
27470 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
27471 "attempting to read the PUBEK");
27472 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
27473 index 0636520..169c1d0 100644
27474 --- a/drivers/char/tpm/tpm_bios.c
27475 +++ b/drivers/char/tpm/tpm_bios.c
27476 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
27477 event = addr;
27478
27479 if ((event->event_type == 0 && event->event_size == 0) ||
27480 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
27481 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
27482 return NULL;
27483
27484 return addr;
27485 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
27486 return NULL;
27487
27488 if ((event->event_type == 0 && event->event_size == 0) ||
27489 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
27490 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
27491 return NULL;
27492
27493 (*pos)++;
27494 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
27495 int i;
27496
27497 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
27498 - seq_putc(m, data[i]);
27499 + if (!seq_putc(m, data[i]))
27500 + return -EFAULT;
27501
27502 return 0;
27503 }
27504 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
27505 log->bios_event_log_end = log->bios_event_log + len;
27506
27507 virt = acpi_os_map_memory(start, len);
27508 + if (!virt) {
27509 + kfree(log->bios_event_log);
27510 + log->bios_event_log = NULL;
27511 + return -EFAULT;
27512 + }
27513
27514 - memcpy(log->bios_event_log, virt, len);
27515 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
27516
27517 acpi_os_unmap_memory(virt, len);
27518 return 0;
27519 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
27520 index fb68b12..0f6c6ca 100644
27521 --- a/drivers/char/virtio_console.c
27522 +++ b/drivers/char/virtio_console.c
27523 @@ -555,7 +555,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
27524 if (to_user) {
27525 ssize_t ret;
27526
27527 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
27528 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
27529 if (ret)
27530 return -EFAULT;
27531 } else {
27532 @@ -654,7 +654,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
27533 if (!port_has_data(port) && !port->host_connected)
27534 return 0;
27535
27536 - return fill_readbuf(port, ubuf, count, true);
27537 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
27538 }
27539
27540 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
27541 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
27542 index a84250a..68c725e 100644
27543 --- a/drivers/crypto/hifn_795x.c
27544 +++ b/drivers/crypto/hifn_795x.c
27545 @@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device *dev, int encdec, u8 snum)
27546 0xCA, 0x34, 0x2B, 0x2E};
27547 struct scatterlist sg;
27548
27549 + pax_track_stack();
27550 +
27551 memset(src, 0, sizeof(src));
27552 memset(ctx.key, 0, sizeof(ctx.key));
27553
27554 diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
27555 index db33d30..7823369 100644
27556 --- a/drivers/crypto/padlock-aes.c
27557 +++ b/drivers/crypto/padlock-aes.c
27558 @@ -109,6 +109,8 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
27559 struct crypto_aes_ctx gen_aes;
27560 int cpu;
27561
27562 + pax_track_stack();
27563 +
27564 if (key_len % 8) {
27565 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
27566 return -EINVAL;
27567 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
27568 index 9a8bebc..b1e4989 100644
27569 --- a/drivers/edac/amd64_edac.c
27570 +++ b/drivers/edac/amd64_edac.c
27571 @@ -2670,7 +2670,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
27572 * PCI core identifies what devices are on a system during boot, and then
27573 * inquiry this table to see if this driver is for a given device found.
27574 */
27575 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
27576 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
27577 {
27578 .vendor = PCI_VENDOR_ID_AMD,
27579 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
27580 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
27581 index e47e73b..348e0bd 100644
27582 --- a/drivers/edac/amd76x_edac.c
27583 +++ b/drivers/edac/amd76x_edac.c
27584 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
27585 edac_mc_free(mci);
27586 }
27587
27588 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
27589 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
27590 {
27591 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27592 AMD762},
27593 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
27594 index 1af531a..3a8ff27 100644
27595 --- a/drivers/edac/e752x_edac.c
27596 +++ b/drivers/edac/e752x_edac.c
27597 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
27598 edac_mc_free(mci);
27599 }
27600
27601 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
27602 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
27603 {
27604 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27605 E7520},
27606 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
27607 index 6ffb6d2..383d8d7 100644
27608 --- a/drivers/edac/e7xxx_edac.c
27609 +++ b/drivers/edac/e7xxx_edac.c
27610 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
27611 edac_mc_free(mci);
27612 }
27613
27614 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
27615 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
27616 {
27617 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27618 E7205},
27619 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
27620 index 495198a..ac08c85 100644
27621 --- a/drivers/edac/edac_pci_sysfs.c
27622 +++ b/drivers/edac/edac_pci_sysfs.c
27623 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
27624 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
27625 static int edac_pci_poll_msec = 1000; /* one second workq period */
27626
27627 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
27628 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
27629 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
27630 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
27631
27632 static struct kobject *edac_pci_top_main_kobj;
27633 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
27634 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27635 edac_printk(KERN_CRIT, EDAC_PCI,
27636 "Signaled System Error on %s\n",
27637 pci_name(dev));
27638 - atomic_inc(&pci_nonparity_count);
27639 + atomic_inc_unchecked(&pci_nonparity_count);
27640 }
27641
27642 if (status & (PCI_STATUS_PARITY)) {
27643 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27644 "Master Data Parity Error on %s\n",
27645 pci_name(dev));
27646
27647 - atomic_inc(&pci_parity_count);
27648 + atomic_inc_unchecked(&pci_parity_count);
27649 }
27650
27651 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27652 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27653 "Detected Parity Error on %s\n",
27654 pci_name(dev));
27655
27656 - atomic_inc(&pci_parity_count);
27657 + atomic_inc_unchecked(&pci_parity_count);
27658 }
27659 }
27660
27661 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27662 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
27663 "Signaled System Error on %s\n",
27664 pci_name(dev));
27665 - atomic_inc(&pci_nonparity_count);
27666 + atomic_inc_unchecked(&pci_nonparity_count);
27667 }
27668
27669 if (status & (PCI_STATUS_PARITY)) {
27670 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27671 "Master Data Parity Error on "
27672 "%s\n", pci_name(dev));
27673
27674 - atomic_inc(&pci_parity_count);
27675 + atomic_inc_unchecked(&pci_parity_count);
27676 }
27677
27678 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27679 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27680 "Detected Parity Error on %s\n",
27681 pci_name(dev));
27682
27683 - atomic_inc(&pci_parity_count);
27684 + atomic_inc_unchecked(&pci_parity_count);
27685 }
27686 }
27687 }
27688 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
27689 if (!check_pci_errors)
27690 return;
27691
27692 - before_count = atomic_read(&pci_parity_count);
27693 + before_count = atomic_read_unchecked(&pci_parity_count);
27694
27695 /* scan all PCI devices looking for a Parity Error on devices and
27696 * bridges.
27697 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
27698 /* Only if operator has selected panic on PCI Error */
27699 if (edac_pci_get_panic_on_pe()) {
27700 /* If the count is different 'after' from 'before' */
27701 - if (before_count != atomic_read(&pci_parity_count))
27702 + if (before_count != atomic_read_unchecked(&pci_parity_count))
27703 panic("EDAC: PCI Parity Error");
27704 }
27705 }
27706 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
27707 index c0510b3..6e2a954 100644
27708 --- a/drivers/edac/i3000_edac.c
27709 +++ b/drivers/edac/i3000_edac.c
27710 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
27711 edac_mc_free(mci);
27712 }
27713
27714 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
27715 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
27716 {
27717 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27718 I3000},
27719 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
27720 index aa08497..7e6822a 100644
27721 --- a/drivers/edac/i3200_edac.c
27722 +++ b/drivers/edac/i3200_edac.c
27723 @@ -456,7 +456,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
27724 edac_mc_free(mci);
27725 }
27726
27727 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
27728 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
27729 {
27730 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27731 I3200},
27732 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
27733 index 4dc3ac2..67d05a6 100644
27734 --- a/drivers/edac/i5000_edac.c
27735 +++ b/drivers/edac/i5000_edac.c
27736 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
27737 *
27738 * The "E500P" device is the first device supported.
27739 */
27740 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
27741 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
27742 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
27743 .driver_data = I5000P},
27744
27745 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
27746 index bcbdeec..9886d16 100644
27747 --- a/drivers/edac/i5100_edac.c
27748 +++ b/drivers/edac/i5100_edac.c
27749 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
27750 edac_mc_free(mci);
27751 }
27752
27753 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
27754 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
27755 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
27756 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
27757 { 0, }
27758 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
27759 index 74d6ec34..baff517 100644
27760 --- a/drivers/edac/i5400_edac.c
27761 +++ b/drivers/edac/i5400_edac.c
27762 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
27763 *
27764 * The "E500P" device is the first device supported.
27765 */
27766 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
27767 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
27768 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
27769 {0,} /* 0 terminated list. */
27770 };
27771 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
27772 index a76fe83..15479e6 100644
27773 --- a/drivers/edac/i7300_edac.c
27774 +++ b/drivers/edac/i7300_edac.c
27775 @@ -1191,7 +1191,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
27776 *
27777 * Has only 8086:360c PCI ID
27778 */
27779 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
27780 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
27781 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
27782 {0,} /* 0 terminated list. */
27783 };
27784 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
27785 index f6cf448..3f612e9 100644
27786 --- a/drivers/edac/i7core_edac.c
27787 +++ b/drivers/edac/i7core_edac.c
27788 @@ -359,7 +359,7 @@ static const struct pci_id_table pci_dev_table[] = {
27789 /*
27790 * pci_device_id table for which devices we are looking for
27791 */
27792 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
27793 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
27794 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
27795 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
27796 {0,} /* 0 terminated list. */
27797 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
27798 index 4329d39..f3022ef 100644
27799 --- a/drivers/edac/i82443bxgx_edac.c
27800 +++ b/drivers/edac/i82443bxgx_edac.c
27801 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
27802
27803 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
27804
27805 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
27806 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
27807 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
27808 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
27809 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
27810 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
27811 index 931a057..fd28340 100644
27812 --- a/drivers/edac/i82860_edac.c
27813 +++ b/drivers/edac/i82860_edac.c
27814 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
27815 edac_mc_free(mci);
27816 }
27817
27818 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
27819 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
27820 {
27821 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27822 I82860},
27823 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
27824 index 33864c6..01edc61 100644
27825 --- a/drivers/edac/i82875p_edac.c
27826 +++ b/drivers/edac/i82875p_edac.c
27827 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
27828 edac_mc_free(mci);
27829 }
27830
27831 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
27832 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
27833 {
27834 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27835 I82875P},
27836 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
27837 index a5da732..983363b 100644
27838 --- a/drivers/edac/i82975x_edac.c
27839 +++ b/drivers/edac/i82975x_edac.c
27840 @@ -604,7 +604,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
27841 edac_mc_free(mci);
27842 }
27843
27844 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
27845 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
27846 {
27847 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27848 I82975X
27849 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
27850 index 795a320..3bbc3d3 100644
27851 --- a/drivers/edac/mce_amd.h
27852 +++ b/drivers/edac/mce_amd.h
27853 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
27854 bool (*dc_mce)(u16, u8);
27855 bool (*ic_mce)(u16, u8);
27856 bool (*nb_mce)(u16, u8);
27857 -};
27858 +} __no_const;
27859
27860 void amd_report_gart_errors(bool);
27861 void amd_register_ecc_decoder(void (*f)(int, struct mce *, u32));
27862 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
27863 index b153674..ad2ba9b 100644
27864 --- a/drivers/edac/r82600_edac.c
27865 +++ b/drivers/edac/r82600_edac.c
27866 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
27867 edac_mc_free(mci);
27868 }
27869
27870 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
27871 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
27872 {
27873 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
27874 },
27875 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
27876 index b6f47de..c5acf3a 100644
27877 --- a/drivers/edac/x38_edac.c
27878 +++ b/drivers/edac/x38_edac.c
27879 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
27880 edac_mc_free(mci);
27881 }
27882
27883 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
27884 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
27885 {
27886 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27887 X38},
27888 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
27889 index 85661b0..c784559a 100644
27890 --- a/drivers/firewire/core-card.c
27891 +++ b/drivers/firewire/core-card.c
27892 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
27893
27894 void fw_core_remove_card(struct fw_card *card)
27895 {
27896 - struct fw_card_driver dummy_driver = dummy_driver_template;
27897 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
27898
27899 card->driver->update_phy_reg(card, 4,
27900 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
27901 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
27902 index 4799393..37bd3ab 100644
27903 --- a/drivers/firewire/core-cdev.c
27904 +++ b/drivers/firewire/core-cdev.c
27905 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
27906 int ret;
27907
27908 if ((request->channels == 0 && request->bandwidth == 0) ||
27909 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
27910 - request->bandwidth < 0)
27911 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
27912 return -EINVAL;
27913
27914 r = kmalloc(sizeof(*r), GFP_KERNEL);
27915 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
27916 index 334b82a..ea5261d 100644
27917 --- a/drivers/firewire/core-transaction.c
27918 +++ b/drivers/firewire/core-transaction.c
27919 @@ -37,6 +37,7 @@
27920 #include <linux/timer.h>
27921 #include <linux/types.h>
27922 #include <linux/workqueue.h>
27923 +#include <linux/sched.h>
27924
27925 #include <asm/byteorder.h>
27926
27927 @@ -422,6 +423,8 @@ int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
27928 struct transaction_callback_data d;
27929 struct fw_transaction t;
27930
27931 + pax_track_stack();
27932 +
27933 init_timer_on_stack(&t.split_timeout_timer);
27934 init_completion(&d.done);
27935 d.payload = payload;
27936 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
27937 index b45be57..5fad18b 100644
27938 --- a/drivers/firewire/core.h
27939 +++ b/drivers/firewire/core.h
27940 @@ -101,6 +101,7 @@ struct fw_card_driver {
27941
27942 int (*stop_iso)(struct fw_iso_context *ctx);
27943 };
27944 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
27945
27946 void fw_card_initialize(struct fw_card *card,
27947 const struct fw_card_driver *driver, struct device *device);
27948 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
27949 index bcb1126..2cc2121 100644
27950 --- a/drivers/firmware/dmi_scan.c
27951 +++ b/drivers/firmware/dmi_scan.c
27952 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
27953 }
27954 }
27955 else {
27956 - /*
27957 - * no iounmap() for that ioremap(); it would be a no-op, but
27958 - * it's so early in setup that sucker gets confused into doing
27959 - * what it shouldn't if we actually call it.
27960 - */
27961 p = dmi_ioremap(0xF0000, 0x10000);
27962 if (p == NULL)
27963 goto error;
27964 @@ -725,7 +720,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
27965 if (buf == NULL)
27966 return -1;
27967
27968 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
27969 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
27970
27971 iounmap(buf);
27972 return 0;
27973 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
27974 index 98723cb..10ca85b 100644
27975 --- a/drivers/gpio/gpio-vr41xx.c
27976 +++ b/drivers/gpio/gpio-vr41xx.c
27977 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
27978 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
27979 maskl, pendl, maskh, pendh);
27980
27981 - atomic_inc(&irq_err_count);
27982 + atomic_inc_unchecked(&irq_err_count);
27983
27984 return -EINVAL;
27985 }
27986 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
27987 index 2410c40..2d03563 100644
27988 --- a/drivers/gpu/drm/drm_crtc.c
27989 +++ b/drivers/gpu/drm/drm_crtc.c
27990 @@ -1374,7 +1374,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27991 */
27992 if ((out_resp->count_modes >= mode_count) && mode_count) {
27993 copied = 0;
27994 - mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
27995 + mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
27996 list_for_each_entry(mode, &connector->modes, head) {
27997 drm_crtc_convert_to_umode(&u_mode, mode);
27998 if (copy_to_user(mode_ptr + copied,
27999 @@ -1389,8 +1389,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
28000
28001 if ((out_resp->count_props >= props_count) && props_count) {
28002 copied = 0;
28003 - prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
28004 - prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
28005 + prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
28006 + prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
28007 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
28008 if (connector->property_ids[i] != 0) {
28009 if (put_user(connector->property_ids[i],
28010 @@ -1412,7 +1412,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
28011
28012 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
28013 copied = 0;
28014 - encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
28015 + encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
28016 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
28017 if (connector->encoder_ids[i] != 0) {
28018 if (put_user(connector->encoder_ids[i],
28019 @@ -1571,7 +1571,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
28020 }
28021
28022 for (i = 0; i < crtc_req->count_connectors; i++) {
28023 - set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
28024 + set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
28025 if (get_user(out_id, &set_connectors_ptr[i])) {
28026 ret = -EFAULT;
28027 goto out;
28028 @@ -1852,7 +1852,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
28029 fb = obj_to_fb(obj);
28030
28031 num_clips = r->num_clips;
28032 - clips_ptr = (struct drm_clip_rect *)(unsigned long)r->clips_ptr;
28033 + clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
28034
28035 if (!num_clips != !clips_ptr) {
28036 ret = -EINVAL;
28037 @@ -2276,7 +2276,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
28038 out_resp->flags = property->flags;
28039
28040 if ((out_resp->count_values >= value_count) && value_count) {
28041 - values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
28042 + values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
28043 for (i = 0; i < value_count; i++) {
28044 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
28045 ret = -EFAULT;
28046 @@ -2289,7 +2289,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
28047 if (property->flags & DRM_MODE_PROP_ENUM) {
28048 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
28049 copied = 0;
28050 - enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
28051 + enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
28052 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
28053
28054 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
28055 @@ -2312,7 +2312,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
28056 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
28057 copied = 0;
28058 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
28059 - blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
28060 + blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
28061
28062 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
28063 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
28064 @@ -2373,7 +2373,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
28065 struct drm_mode_get_blob *out_resp = data;
28066 struct drm_property_blob *blob;
28067 int ret = 0;
28068 - void *blob_ptr;
28069 + void __user *blob_ptr;
28070
28071 if (!drm_core_check_feature(dev, DRIVER_MODESET))
28072 return -EINVAL;
28073 @@ -2387,7 +2387,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
28074 blob = obj_to_blob(obj);
28075
28076 if (out_resp->length == blob->length) {
28077 - blob_ptr = (void *)(unsigned long)out_resp->data;
28078 + blob_ptr = (void __user *)(unsigned long)out_resp->data;
28079 if (copy_to_user(blob_ptr, blob->data, blob->length)){
28080 ret = -EFAULT;
28081 goto done;
28082 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
28083 index f88a9b2..8f4078f 100644
28084 --- a/drivers/gpu/drm/drm_crtc_helper.c
28085 +++ b/drivers/gpu/drm/drm_crtc_helper.c
28086 @@ -276,7 +276,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
28087 struct drm_crtc *tmp;
28088 int crtc_mask = 1;
28089
28090 - WARN(!crtc, "checking null crtc?\n");
28091 + BUG_ON(!crtc);
28092
28093 dev = crtc->dev;
28094
28095 @@ -343,6 +343,8 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
28096 struct drm_encoder *encoder;
28097 bool ret = true;
28098
28099 + pax_track_stack();
28100 +
28101 crtc->enabled = drm_helper_crtc_in_use(crtc);
28102 if (!crtc->enabled)
28103 return true;
28104 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
28105 index 93a112d..c8b065d 100644
28106 --- a/drivers/gpu/drm/drm_drv.c
28107 +++ b/drivers/gpu/drm/drm_drv.c
28108 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
28109 /**
28110 * Copy and IOCTL return string to user space
28111 */
28112 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
28113 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
28114 {
28115 int len;
28116
28117 @@ -386,7 +386,7 @@ long drm_ioctl(struct file *filp,
28118
28119 dev = file_priv->minor->dev;
28120 atomic_inc(&dev->ioctl_count);
28121 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
28122 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
28123 ++file_priv->ioctl_count;
28124
28125 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
28126 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
28127 index 2ec7d48..be14bb1 100644
28128 --- a/drivers/gpu/drm/drm_fops.c
28129 +++ b/drivers/gpu/drm/drm_fops.c
28130 @@ -70,7 +70,7 @@ static int drm_setup(struct drm_device * dev)
28131 }
28132
28133 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
28134 - atomic_set(&dev->counts[i], 0);
28135 + atomic_set_unchecked(&dev->counts[i], 0);
28136
28137 dev->sigdata.lock = NULL;
28138
28139 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct file *filp)
28140
28141 retcode = drm_open_helper(inode, filp, dev);
28142 if (!retcode) {
28143 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
28144 - if (!dev->open_count++)
28145 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
28146 + if (local_inc_return(&dev->open_count) == 1)
28147 retcode = drm_setup(dev);
28148 }
28149 if (!retcode) {
28150 @@ -472,7 +472,7 @@ int drm_release(struct inode *inode, struct file *filp)
28151
28152 mutex_lock(&drm_global_mutex);
28153
28154 - DRM_DEBUG("open_count = %d\n", dev->open_count);
28155 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
28156
28157 if (dev->driver->preclose)
28158 dev->driver->preclose(dev, file_priv);
28159 @@ -484,7 +484,7 @@ int drm_release(struct inode *inode, struct file *filp)
28160 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
28161 task_pid_nr(current),
28162 (long)old_encode_dev(file_priv->minor->device),
28163 - dev->open_count);
28164 + local_read(&dev->open_count));
28165
28166 /* if the master has gone away we can't do anything with the lock */
28167 if (file_priv->minor->master)
28168 @@ -565,8 +565,8 @@ int drm_release(struct inode *inode, struct file *filp)
28169 * End inline drm_release
28170 */
28171
28172 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
28173 - if (!--dev->open_count) {
28174 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
28175 + if (local_dec_and_test(&dev->open_count)) {
28176 if (atomic_read(&dev->ioctl_count)) {
28177 DRM_ERROR("Device busy: %d\n",
28178 atomic_read(&dev->ioctl_count));
28179 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
28180 index c87dc96..326055d 100644
28181 --- a/drivers/gpu/drm/drm_global.c
28182 +++ b/drivers/gpu/drm/drm_global.c
28183 @@ -36,7 +36,7 @@
28184 struct drm_global_item {
28185 struct mutex mutex;
28186 void *object;
28187 - int refcount;
28188 + atomic_t refcount;
28189 };
28190
28191 static struct drm_global_item glob[DRM_GLOBAL_NUM];
28192 @@ -49,7 +49,7 @@ void drm_global_init(void)
28193 struct drm_global_item *item = &glob[i];
28194 mutex_init(&item->mutex);
28195 item->object = NULL;
28196 - item->refcount = 0;
28197 + atomic_set(&item->refcount, 0);
28198 }
28199 }
28200
28201 @@ -59,7 +59,7 @@ void drm_global_release(void)
28202 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
28203 struct drm_global_item *item = &glob[i];
28204 BUG_ON(item->object != NULL);
28205 - BUG_ON(item->refcount != 0);
28206 + BUG_ON(atomic_read(&item->refcount) != 0);
28207 }
28208 }
28209
28210 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
28211 void *object;
28212
28213 mutex_lock(&item->mutex);
28214 - if (item->refcount == 0) {
28215 + if (atomic_read(&item->refcount) == 0) {
28216 item->object = kzalloc(ref->size, GFP_KERNEL);
28217 if (unlikely(item->object == NULL)) {
28218 ret = -ENOMEM;
28219 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
28220 goto out_err;
28221
28222 }
28223 - ++item->refcount;
28224 + atomic_inc(&item->refcount);
28225 ref->object = item->object;
28226 object = item->object;
28227 mutex_unlock(&item->mutex);
28228 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
28229 struct drm_global_item *item = &glob[ref->global_type];
28230
28231 mutex_lock(&item->mutex);
28232 - BUG_ON(item->refcount == 0);
28233 + BUG_ON(atomic_read(&item->refcount) == 0);
28234 BUG_ON(ref->object != item->object);
28235 - if (--item->refcount == 0) {
28236 + if (atomic_dec_and_test(&item->refcount)) {
28237 ref->release(ref);
28238 item->object = NULL;
28239 }
28240 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
28241 index ab1162d..42587b2 100644
28242 --- a/drivers/gpu/drm/drm_info.c
28243 +++ b/drivers/gpu/drm/drm_info.c
28244 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
28245 struct drm_local_map *map;
28246 struct drm_map_list *r_list;
28247
28248 - /* Hardcoded from _DRM_FRAME_BUFFER,
28249 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
28250 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
28251 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
28252 + static const char * const types[] = {
28253 + [_DRM_FRAME_BUFFER] = "FB",
28254 + [_DRM_REGISTERS] = "REG",
28255 + [_DRM_SHM] = "SHM",
28256 + [_DRM_AGP] = "AGP",
28257 + [_DRM_SCATTER_GATHER] = "SG",
28258 + [_DRM_CONSISTENT] = "PCI",
28259 + [_DRM_GEM] = "GEM" };
28260 const char *type;
28261 int i;
28262
28263 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
28264 map = r_list->map;
28265 if (!map)
28266 continue;
28267 - if (map->type < 0 || map->type > 5)
28268 + if (map->type >= ARRAY_SIZE(types))
28269 type = "??";
28270 else
28271 type = types[map->type];
28272 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
28273 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
28274 vma->vm_flags & VM_LOCKED ? 'l' : '-',
28275 vma->vm_flags & VM_IO ? 'i' : '-',
28276 +#ifdef CONFIG_GRKERNSEC_HIDESYM
28277 + 0);
28278 +#else
28279 vma->vm_pgoff);
28280 +#endif
28281
28282 #if defined(__i386__)
28283 pgprot = pgprot_val(vma->vm_page_prot);
28284 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
28285 index 4a058c7..b42cd92 100644
28286 --- a/drivers/gpu/drm/drm_ioc32.c
28287 +++ b/drivers/gpu/drm/drm_ioc32.c
28288 @@ -455,7 +455,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
28289 request = compat_alloc_user_space(nbytes);
28290 if (!access_ok(VERIFY_WRITE, request, nbytes))
28291 return -EFAULT;
28292 - list = (struct drm_buf_desc *) (request + 1);
28293 + list = (struct drm_buf_desc __user *) (request + 1);
28294
28295 if (__put_user(count, &request->count)
28296 || __put_user(list, &request->list))
28297 @@ -516,7 +516,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
28298 request = compat_alloc_user_space(nbytes);
28299 if (!access_ok(VERIFY_WRITE, request, nbytes))
28300 return -EFAULT;
28301 - list = (struct drm_buf_pub *) (request + 1);
28302 + list = (struct drm_buf_pub __user *) (request + 1);
28303
28304 if (__put_user(count, &request->count)
28305 || __put_user(list, &request->list))
28306 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
28307 index 904d7e9..ab88581 100644
28308 --- a/drivers/gpu/drm/drm_ioctl.c
28309 +++ b/drivers/gpu/drm/drm_ioctl.c
28310 @@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev, void *data,
28311 stats->data[i].value =
28312 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
28313 else
28314 - stats->data[i].value = atomic_read(&dev->counts[i]);
28315 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
28316 stats->data[i].type = dev->types[i];
28317 }
28318
28319 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
28320 index 632ae24..244cf4a 100644
28321 --- a/drivers/gpu/drm/drm_lock.c
28322 +++ b/drivers/gpu/drm/drm_lock.c
28323 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
28324 if (drm_lock_take(&master->lock, lock->context)) {
28325 master->lock.file_priv = file_priv;
28326 master->lock.lock_time = jiffies;
28327 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
28328 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
28329 break; /* Got lock */
28330 }
28331
28332 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
28333 return -EINVAL;
28334 }
28335
28336 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
28337 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
28338
28339 if (drm_lock_free(&master->lock, lock->context)) {
28340 /* FIXME: Should really bail out here. */
28341 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
28342 index 8f371e8..9f85d52 100644
28343 --- a/drivers/gpu/drm/i810/i810_dma.c
28344 +++ b/drivers/gpu/drm/i810/i810_dma.c
28345 @@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
28346 dma->buflist[vertex->idx],
28347 vertex->discard, vertex->used);
28348
28349 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28350 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28351 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28352 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28353 sarea_priv->last_enqueue = dev_priv->counter - 1;
28354 sarea_priv->last_dispatch = (int)hw_status[5];
28355
28356 @@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
28357 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
28358 mc->last_render);
28359
28360 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28361 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28362 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28363 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28364 sarea_priv->last_enqueue = dev_priv->counter - 1;
28365 sarea_priv->last_dispatch = (int)hw_status[5];
28366
28367 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
28368 index c9339f4..f5e1b9d 100644
28369 --- a/drivers/gpu/drm/i810/i810_drv.h
28370 +++ b/drivers/gpu/drm/i810/i810_drv.h
28371 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
28372 int page_flipping;
28373
28374 wait_queue_head_t irq_queue;
28375 - atomic_t irq_received;
28376 - atomic_t irq_emitted;
28377 + atomic_unchecked_t irq_received;
28378 + atomic_unchecked_t irq_emitted;
28379
28380 int front_offset;
28381 } drm_i810_private_t;
28382 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
28383 index 3c395a5..02889c2 100644
28384 --- a/drivers/gpu/drm/i915/i915_debugfs.c
28385 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
28386 @@ -497,7 +497,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
28387 I915_READ(GTIMR));
28388 }
28389 seq_printf(m, "Interrupts received: %d\n",
28390 - atomic_read(&dev_priv->irq_received));
28391 + atomic_read_unchecked(&dev_priv->irq_received));
28392 for (i = 0; i < I915_NUM_RINGS; i++) {
28393 if (IS_GEN6(dev) || IS_GEN7(dev)) {
28394 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
28395 @@ -1185,7 +1185,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
28396 return ret;
28397
28398 if (opregion->header)
28399 - seq_write(m, opregion->header, OPREGION_SIZE);
28400 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
28401
28402 mutex_unlock(&dev->struct_mutex);
28403
28404 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
28405 index c72b590..aa86f0a 100644
28406 --- a/drivers/gpu/drm/i915/i915_dma.c
28407 +++ b/drivers/gpu/drm/i915/i915_dma.c
28408 @@ -1171,7 +1171,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
28409 bool can_switch;
28410
28411 spin_lock(&dev->count_lock);
28412 - can_switch = (dev->open_count == 0);
28413 + can_switch = (local_read(&dev->open_count) == 0);
28414 spin_unlock(&dev->count_lock);
28415 return can_switch;
28416 }
28417 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
28418 index 1a2a2d1..f280182 100644
28419 --- a/drivers/gpu/drm/i915/i915_drv.h
28420 +++ b/drivers/gpu/drm/i915/i915_drv.h
28421 @@ -222,7 +222,7 @@ struct drm_i915_display_funcs {
28422 /* render clock increase/decrease */
28423 /* display clock increase/decrease */
28424 /* pll clock increase/decrease */
28425 -};
28426 +} __no_const;
28427
28428 struct intel_device_info {
28429 u8 gen;
28430 @@ -305,7 +305,7 @@ typedef struct drm_i915_private {
28431 int current_page;
28432 int page_flipping;
28433
28434 - atomic_t irq_received;
28435 + atomic_unchecked_t irq_received;
28436
28437 /* protects the irq masks */
28438 spinlock_t irq_lock;
28439 @@ -883,7 +883,7 @@ struct drm_i915_gem_object {
28440 * will be page flipped away on the next vblank. When it
28441 * reaches 0, dev_priv->pending_flip_queue will be woken up.
28442 */
28443 - atomic_t pending_flip;
28444 + atomic_unchecked_t pending_flip;
28445 };
28446
28447 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
28448 @@ -1263,7 +1263,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
28449 extern void intel_teardown_gmbus(struct drm_device *dev);
28450 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
28451 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
28452 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
28453 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
28454 {
28455 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
28456 }
28457 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28458 index 4934cf8..1da9c84 100644
28459 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28460 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28461 @@ -188,7 +188,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
28462 i915_gem_clflush_object(obj);
28463
28464 if (obj->base.pending_write_domain)
28465 - cd->flips |= atomic_read(&obj->pending_flip);
28466 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
28467
28468 /* The actual obj->write_domain will be updated with
28469 * pending_write_domain after we emit the accumulated flush for all
28470 @@ -864,9 +864,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
28471
28472 static int
28473 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
28474 - int count)
28475 + unsigned int count)
28476 {
28477 - int i;
28478 + unsigned int i;
28479
28480 for (i = 0; i < count; i++) {
28481 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
28482 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
28483 index 73248d0..f7bac29 100644
28484 --- a/drivers/gpu/drm/i915/i915_irq.c
28485 +++ b/drivers/gpu/drm/i915/i915_irq.c
28486 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
28487 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
28488 struct drm_i915_master_private *master_priv;
28489
28490 - atomic_inc(&dev_priv->irq_received);
28491 + atomic_inc_unchecked(&dev_priv->irq_received);
28492
28493 /* disable master interrupt before clearing iir */
28494 de_ier = I915_READ(DEIER);
28495 @@ -565,7 +565,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
28496 struct drm_i915_master_private *master_priv;
28497 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
28498
28499 - atomic_inc(&dev_priv->irq_received);
28500 + atomic_inc_unchecked(&dev_priv->irq_received);
28501
28502 if (IS_GEN6(dev))
28503 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
28504 @@ -1229,7 +1229,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
28505 int ret = IRQ_NONE, pipe;
28506 bool blc_event = false;
28507
28508 - atomic_inc(&dev_priv->irq_received);
28509 + atomic_inc_unchecked(&dev_priv->irq_received);
28510
28511 iir = I915_READ(IIR);
28512
28513 @@ -1741,7 +1741,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
28514 {
28515 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28516
28517 - atomic_set(&dev_priv->irq_received, 0);
28518 + atomic_set_unchecked(&dev_priv->irq_received, 0);
28519
28520 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28521 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28522 @@ -1905,7 +1905,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
28523 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28524 int pipe;
28525
28526 - atomic_set(&dev_priv->irq_received, 0);
28527 + atomic_set_unchecked(&dev_priv->irq_received, 0);
28528
28529 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28530 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28531 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
28532 index 07e7cf3..c75f312 100644
28533 --- a/drivers/gpu/drm/i915/intel_display.c
28534 +++ b/drivers/gpu/drm/i915/intel_display.c
28535 @@ -2205,7 +2205,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
28536
28537 wait_event(dev_priv->pending_flip_queue,
28538 atomic_read(&dev_priv->mm.wedged) ||
28539 - atomic_read(&obj->pending_flip) == 0);
28540 + atomic_read_unchecked(&obj->pending_flip) == 0);
28541
28542 /* Big Hammer, we also need to ensure that any pending
28543 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
28544 @@ -2826,7 +2826,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
28545 obj = to_intel_framebuffer(crtc->fb)->obj;
28546 dev_priv = crtc->dev->dev_private;
28547 wait_event(dev_priv->pending_flip_queue,
28548 - atomic_read(&obj->pending_flip) == 0);
28549 + atomic_read_unchecked(&obj->pending_flip) == 0);
28550 }
28551
28552 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
28553 @@ -6676,7 +6676,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
28554
28555 atomic_clear_mask(1 << intel_crtc->plane,
28556 &obj->pending_flip.counter);
28557 - if (atomic_read(&obj->pending_flip) == 0)
28558 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
28559 wake_up(&dev_priv->pending_flip_queue);
28560
28561 schedule_work(&work->work);
28562 @@ -6965,7 +6965,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
28563 /* Block clients from rendering to the new back buffer until
28564 * the flip occurs and the object is no longer visible.
28565 */
28566 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28567 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28568
28569 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
28570 if (ret)
28571 @@ -6979,7 +6979,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
28572 return 0;
28573
28574 cleanup_pending:
28575 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28576 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28577 cleanup_objs:
28578 drm_gem_object_unreference(&work->old_fb_obj->base);
28579 drm_gem_object_unreference(&obj->base);
28580 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
28581 index 54558a0..2d97005 100644
28582 --- a/drivers/gpu/drm/mga/mga_drv.h
28583 +++ b/drivers/gpu/drm/mga/mga_drv.h
28584 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
28585 u32 clear_cmd;
28586 u32 maccess;
28587
28588 - atomic_t vbl_received; /**< Number of vblanks received. */
28589 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
28590 wait_queue_head_t fence_queue;
28591 - atomic_t last_fence_retired;
28592 + atomic_unchecked_t last_fence_retired;
28593 u32 next_fence_to_post;
28594
28595 unsigned int fb_cpp;
28596 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
28597 index 2581202..f230a8d9 100644
28598 --- a/drivers/gpu/drm/mga/mga_irq.c
28599 +++ b/drivers/gpu/drm/mga/mga_irq.c
28600 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
28601 if (crtc != 0)
28602 return 0;
28603
28604 - return atomic_read(&dev_priv->vbl_received);
28605 + return atomic_read_unchecked(&dev_priv->vbl_received);
28606 }
28607
28608
28609 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
28610 /* VBLANK interrupt */
28611 if (status & MGA_VLINEPEN) {
28612 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
28613 - atomic_inc(&dev_priv->vbl_received);
28614 + atomic_inc_unchecked(&dev_priv->vbl_received);
28615 drm_handle_vblank(dev, 0);
28616 handled = 1;
28617 }
28618 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
28619 if ((prim_start & ~0x03) != (prim_end & ~0x03))
28620 MGA_WRITE(MGA_PRIMEND, prim_end);
28621
28622 - atomic_inc(&dev_priv->last_fence_retired);
28623 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
28624 DRM_WAKEUP(&dev_priv->fence_queue);
28625 handled = 1;
28626 }
28627 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
28628 * using fences.
28629 */
28630 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
28631 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
28632 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
28633 - *sequence) <= (1 << 23)));
28634
28635 *sequence = cur_fence;
28636 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
28637 index b311fab..dc11d6a 100644
28638 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
28639 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
28640 @@ -201,7 +201,7 @@ struct methods {
28641 const char desc[8];
28642 void (*loadbios)(struct drm_device *, uint8_t *);
28643 const bool rw;
28644 -};
28645 +} __do_const;
28646
28647 static struct methods shadow_methods[] = {
28648 { "PRAMIN", load_vbios_pramin, true },
28649 @@ -5489,7 +5489,7 @@ parse_bit_displayport_tbl_entry(struct drm_device *dev, struct nvbios *bios,
28650 struct bit_table {
28651 const char id;
28652 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
28653 -};
28654 +} __no_const;
28655
28656 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
28657
28658 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
28659 index d7d51de..7c6a7f1 100644
28660 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
28661 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
28662 @@ -238,7 +238,7 @@ struct nouveau_channel {
28663 struct list_head pending;
28664 uint32_t sequence;
28665 uint32_t sequence_ack;
28666 - atomic_t last_sequence_irq;
28667 + atomic_unchecked_t last_sequence_irq;
28668 struct nouveau_vma vma;
28669 } fence;
28670
28671 @@ -319,7 +319,7 @@ struct nouveau_exec_engine {
28672 u32 handle, u16 class);
28673 void (*set_tile_region)(struct drm_device *dev, int i);
28674 void (*tlb_flush)(struct drm_device *, int engine);
28675 -};
28676 +} __no_const;
28677
28678 struct nouveau_instmem_engine {
28679 void *priv;
28680 @@ -341,13 +341,13 @@ struct nouveau_instmem_engine {
28681 struct nouveau_mc_engine {
28682 int (*init)(struct drm_device *dev);
28683 void (*takedown)(struct drm_device *dev);
28684 -};
28685 +} __no_const;
28686
28687 struct nouveau_timer_engine {
28688 int (*init)(struct drm_device *dev);
28689 void (*takedown)(struct drm_device *dev);
28690 uint64_t (*read)(struct drm_device *dev);
28691 -};
28692 +} __no_const;
28693
28694 struct nouveau_fb_engine {
28695 int num_tiles;
28696 @@ -513,7 +513,7 @@ struct nouveau_vram_engine {
28697 void (*put)(struct drm_device *, struct nouveau_mem **);
28698
28699 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
28700 -};
28701 +} __no_const;
28702
28703 struct nouveau_engine {
28704 struct nouveau_instmem_engine instmem;
28705 @@ -660,7 +660,7 @@ struct drm_nouveau_private {
28706 struct drm_global_reference mem_global_ref;
28707 struct ttm_bo_global_ref bo_global_ref;
28708 struct ttm_bo_device bdev;
28709 - atomic_t validate_sequence;
28710 + atomic_unchecked_t validate_sequence;
28711 } ttm;
28712
28713 struct {
28714 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
28715 index ae22dfa..4f09960 100644
28716 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
28717 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
28718 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
28719 if (USE_REFCNT(dev))
28720 sequence = nvchan_rd32(chan, 0x48);
28721 else
28722 - sequence = atomic_read(&chan->fence.last_sequence_irq);
28723 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
28724
28725 if (chan->fence.sequence_ack == sequence)
28726 goto out;
28727 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
28728 return ret;
28729 }
28730
28731 - atomic_set(&chan->fence.last_sequence_irq, 0);
28732 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
28733 return 0;
28734 }
28735
28736 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
28737 index 5f0bc57..eb9fac8 100644
28738 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
28739 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
28740 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
28741 int trycnt = 0;
28742 int ret, i;
28743
28744 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
28745 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
28746 retry:
28747 if (++trycnt > 100000) {
28748 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
28749 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
28750 index 10656e4..59bf2a4 100644
28751 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
28752 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
28753 @@ -496,7 +496,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
28754 bool can_switch;
28755
28756 spin_lock(&dev->count_lock);
28757 - can_switch = (dev->open_count == 0);
28758 + can_switch = (local_read(&dev->open_count) == 0);
28759 spin_unlock(&dev->count_lock);
28760 return can_switch;
28761 }
28762 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
28763 index dbdea8e..cd6eeeb 100644
28764 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
28765 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
28766 @@ -554,7 +554,7 @@ static int
28767 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
28768 u32 class, u32 mthd, u32 data)
28769 {
28770 - atomic_set(&chan->fence.last_sequence_irq, data);
28771 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
28772 return 0;
28773 }
28774
28775 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
28776 index 570e190..084a31a 100644
28777 --- a/drivers/gpu/drm/r128/r128_cce.c
28778 +++ b/drivers/gpu/drm/r128/r128_cce.c
28779 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
28780
28781 /* GH: Simple idle check.
28782 */
28783 - atomic_set(&dev_priv->idle_count, 0);
28784 + atomic_set_unchecked(&dev_priv->idle_count, 0);
28785
28786 /* We don't support anything other than bus-mastering ring mode,
28787 * but the ring can be in either AGP or PCI space for the ring
28788 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
28789 index 930c71b..499aded 100644
28790 --- a/drivers/gpu/drm/r128/r128_drv.h
28791 +++ b/drivers/gpu/drm/r128/r128_drv.h
28792 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
28793 int is_pci;
28794 unsigned long cce_buffers_offset;
28795
28796 - atomic_t idle_count;
28797 + atomic_unchecked_t idle_count;
28798
28799 int page_flipping;
28800 int current_page;
28801 u32 crtc_offset;
28802 u32 crtc_offset_cntl;
28803
28804 - atomic_t vbl_received;
28805 + atomic_unchecked_t vbl_received;
28806
28807 u32 color_fmt;
28808 unsigned int front_offset;
28809 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
28810 index 429d5a0..7e899ed 100644
28811 --- a/drivers/gpu/drm/r128/r128_irq.c
28812 +++ b/drivers/gpu/drm/r128/r128_irq.c
28813 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
28814 if (crtc != 0)
28815 return 0;
28816
28817 - return atomic_read(&dev_priv->vbl_received);
28818 + return atomic_read_unchecked(&dev_priv->vbl_received);
28819 }
28820
28821 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28822 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28823 /* VBLANK interrupt */
28824 if (status & R128_CRTC_VBLANK_INT) {
28825 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
28826 - atomic_inc(&dev_priv->vbl_received);
28827 + atomic_inc_unchecked(&dev_priv->vbl_received);
28828 drm_handle_vblank(dev, 0);
28829 return IRQ_HANDLED;
28830 }
28831 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
28832 index a9e33ce..09edd4b 100644
28833 --- a/drivers/gpu/drm/r128/r128_state.c
28834 +++ b/drivers/gpu/drm/r128/r128_state.c
28835 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
28836
28837 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
28838 {
28839 - if (atomic_read(&dev_priv->idle_count) == 0)
28840 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
28841 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
28842 else
28843 - atomic_set(&dev_priv->idle_count, 0);
28844 + atomic_set_unchecked(&dev_priv->idle_count, 0);
28845 }
28846
28847 #endif
28848 diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
28849 index 14cc88a..cc7b3a5 100644
28850 --- a/drivers/gpu/drm/radeon/atom.c
28851 +++ b/drivers/gpu/drm/radeon/atom.c
28852 @@ -1254,6 +1254,8 @@ struct atom_context *atom_parse(struct card_info *card, void *bios)
28853 char name[512];
28854 int i;
28855
28856 + pax_track_stack();
28857 +
28858 if (!ctx)
28859 return NULL;
28860
28861 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
28862 index 5a82b6b..9e69c73 100644
28863 --- a/drivers/gpu/drm/radeon/mkregtable.c
28864 +++ b/drivers/gpu/drm/radeon/mkregtable.c
28865 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
28866 regex_t mask_rex;
28867 regmatch_t match[4];
28868 char buf[1024];
28869 - size_t end;
28870 + long end;
28871 int len;
28872 int done = 0;
28873 int r;
28874 unsigned o;
28875 struct offset *offset;
28876 char last_reg_s[10];
28877 - int last_reg;
28878 + unsigned long last_reg;
28879
28880 if (regcomp
28881 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
28882 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
28883 index 184628c..30e1725 100644
28884 --- a/drivers/gpu/drm/radeon/radeon.h
28885 +++ b/drivers/gpu/drm/radeon/radeon.h
28886 @@ -192,7 +192,7 @@ extern int sumo_get_temp(struct radeon_device *rdev);
28887 */
28888 struct radeon_fence_driver {
28889 uint32_t scratch_reg;
28890 - atomic_t seq;
28891 + atomic_unchecked_t seq;
28892 uint32_t last_seq;
28893 unsigned long last_jiffies;
28894 unsigned long last_timeout;
28895 @@ -962,7 +962,7 @@ struct radeon_asic {
28896 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
28897 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
28898 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
28899 -};
28900 +} __no_const;
28901
28902 /*
28903 * Asic structures
28904 diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
28905 index a098edc..d001c09 100644
28906 --- a/drivers/gpu/drm/radeon/radeon_atombios.c
28907 +++ b/drivers/gpu/drm/radeon/radeon_atombios.c
28908 @@ -569,6 +569,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
28909 struct radeon_gpio_rec gpio;
28910 struct radeon_hpd hpd;
28911
28912 + pax_track_stack();
28913 +
28914 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
28915 return false;
28916
28917 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
28918 index 50d105a..355cf8d 100644
28919 --- a/drivers/gpu/drm/radeon/radeon_device.c
28920 +++ b/drivers/gpu/drm/radeon/radeon_device.c
28921 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
28922 bool can_switch;
28923
28924 spin_lock(&dev->count_lock);
28925 - can_switch = (dev->open_count == 0);
28926 + can_switch = (local_read(&dev->open_count) == 0);
28927 spin_unlock(&dev->count_lock);
28928 return can_switch;
28929 }
28930 diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
28931 index 07ac481..41cb437 100644
28932 --- a/drivers/gpu/drm/radeon/radeon_display.c
28933 +++ b/drivers/gpu/drm/radeon/radeon_display.c
28934 @@ -926,6 +926,8 @@ void radeon_compute_pll_legacy(struct radeon_pll *pll,
28935 uint32_t post_div;
28936 u32 pll_out_min, pll_out_max;
28937
28938 + pax_track_stack();
28939 +
28940 DRM_DEBUG_KMS("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div);
28941 freq = freq * 1000;
28942
28943 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
28944 index a1b59ca..86f2d44 100644
28945 --- a/drivers/gpu/drm/radeon/radeon_drv.h
28946 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
28947 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
28948
28949 /* SW interrupt */
28950 wait_queue_head_t swi_queue;
28951 - atomic_t swi_emitted;
28952 + atomic_unchecked_t swi_emitted;
28953 int vblank_crtc;
28954 uint32_t irq_enable_reg;
28955 uint32_t r500_disp_irq_reg;
28956 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
28957 index 7fd4e3e..9748ab5 100644
28958 --- a/drivers/gpu/drm/radeon/radeon_fence.c
28959 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
28960 @@ -78,7 +78,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
28961 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
28962 return 0;
28963 }
28964 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
28965 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
28966 if (!rdev->cp.ready)
28967 /* FIXME: cp is not running assume everythings is done right
28968 * away
28969 @@ -373,7 +373,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
28970 return r;
28971 }
28972 radeon_fence_write(rdev, 0);
28973 - atomic_set(&rdev->fence_drv.seq, 0);
28974 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
28975 INIT_LIST_HEAD(&rdev->fence_drv.created);
28976 INIT_LIST_HEAD(&rdev->fence_drv.emited);
28977 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
28978 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
28979 index 48b7cea..342236f 100644
28980 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
28981 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
28982 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
28983 request = compat_alloc_user_space(sizeof(*request));
28984 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
28985 || __put_user(req32.param, &request->param)
28986 - || __put_user((void __user *)(unsigned long)req32.value,
28987 + || __put_user((unsigned long)req32.value,
28988 &request->value))
28989 return -EFAULT;
28990
28991 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
28992 index 465746b..cb2b055 100644
28993 --- a/drivers/gpu/drm/radeon/radeon_irq.c
28994 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
28995 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
28996 unsigned int ret;
28997 RING_LOCALS;
28998
28999 - atomic_inc(&dev_priv->swi_emitted);
29000 - ret = atomic_read(&dev_priv->swi_emitted);
29001 + atomic_inc_unchecked(&dev_priv->swi_emitted);
29002 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
29003
29004 BEGIN_RING(4);
29005 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
29006 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
29007 drm_radeon_private_t *dev_priv =
29008 (drm_radeon_private_t *) dev->dev_private;
29009
29010 - atomic_set(&dev_priv->swi_emitted, 0);
29011 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
29012 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
29013
29014 dev->max_vblank_count = 0x001fffff;
29015 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
29016 index 92e7ea7..147ffad 100644
29017 --- a/drivers/gpu/drm/radeon/radeon_state.c
29018 +++ b/drivers/gpu/drm/radeon/radeon_state.c
29019 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
29020 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
29021 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
29022
29023 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29024 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29025 sarea_priv->nbox * sizeof(depth_boxes[0])))
29026 return -EFAULT;
29027
29028 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
29029 {
29030 drm_radeon_private_t *dev_priv = dev->dev_private;
29031 drm_radeon_getparam_t *param = data;
29032 - int value;
29033 + int value = 0;
29034
29035 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
29036
29037 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
29038 index 0b5468b..9c4b308 100644
29039 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
29040 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
29041 @@ -672,8 +672,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
29042 }
29043 if (unlikely(ttm_vm_ops == NULL)) {
29044 ttm_vm_ops = vma->vm_ops;
29045 - radeon_ttm_vm_ops = *ttm_vm_ops;
29046 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
29047 + pax_open_kernel();
29048 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
29049 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
29050 + pax_close_kernel();
29051 }
29052 vma->vm_ops = &radeon_ttm_vm_ops;
29053 return 0;
29054 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
29055 index a9049ed..501f284 100644
29056 --- a/drivers/gpu/drm/radeon/rs690.c
29057 +++ b/drivers/gpu/drm/radeon/rs690.c
29058 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
29059 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
29060 rdev->pm.sideport_bandwidth.full)
29061 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
29062 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
29063 + read_delay_latency.full = dfixed_const(800 * 1000);
29064 read_delay_latency.full = dfixed_div(read_delay_latency,
29065 rdev->pm.igp_sideport_mclk);
29066 + a.full = dfixed_const(370);
29067 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
29068 } else {
29069 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
29070 rdev->pm.k8_bandwidth.full)
29071 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
29072 index 727e93d..1565650 100644
29073 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
29074 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
29075 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
29076 static int ttm_pool_mm_shrink(struct shrinker *shrink,
29077 struct shrink_control *sc)
29078 {
29079 - static atomic_t start_pool = ATOMIC_INIT(0);
29080 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
29081 unsigned i;
29082 - unsigned pool_offset = atomic_add_return(1, &start_pool);
29083 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
29084 struct ttm_page_pool *pool;
29085 int shrink_pages = sc->nr_to_scan;
29086
29087 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
29088 index 9cf87d9..2000b7d 100644
29089 --- a/drivers/gpu/drm/via/via_drv.h
29090 +++ b/drivers/gpu/drm/via/via_drv.h
29091 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
29092 typedef uint32_t maskarray_t[5];
29093
29094 typedef struct drm_via_irq {
29095 - atomic_t irq_received;
29096 + atomic_unchecked_t irq_received;
29097 uint32_t pending_mask;
29098 uint32_t enable_mask;
29099 wait_queue_head_t irq_queue;
29100 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
29101 struct timeval last_vblank;
29102 int last_vblank_valid;
29103 unsigned usec_per_vblank;
29104 - atomic_t vbl_received;
29105 + atomic_unchecked_t vbl_received;
29106 drm_via_state_t hc_state;
29107 char pci_buf[VIA_PCI_BUF_SIZE];
29108 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
29109 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
29110 index d391f48..10c8ca3 100644
29111 --- a/drivers/gpu/drm/via/via_irq.c
29112 +++ b/drivers/gpu/drm/via/via_irq.c
29113 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
29114 if (crtc != 0)
29115 return 0;
29116
29117 - return atomic_read(&dev_priv->vbl_received);
29118 + return atomic_read_unchecked(&dev_priv->vbl_received);
29119 }
29120
29121 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29122 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29123
29124 status = VIA_READ(VIA_REG_INTERRUPT);
29125 if (status & VIA_IRQ_VBLANK_PENDING) {
29126 - atomic_inc(&dev_priv->vbl_received);
29127 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
29128 + atomic_inc_unchecked(&dev_priv->vbl_received);
29129 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
29130 do_gettimeofday(&cur_vblank);
29131 if (dev_priv->last_vblank_valid) {
29132 dev_priv->usec_per_vblank =
29133 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29134 dev_priv->last_vblank = cur_vblank;
29135 dev_priv->last_vblank_valid = 1;
29136 }
29137 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
29138 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
29139 DRM_DEBUG("US per vblank is: %u\n",
29140 dev_priv->usec_per_vblank);
29141 }
29142 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29143
29144 for (i = 0; i < dev_priv->num_irqs; ++i) {
29145 if (status & cur_irq->pending_mask) {
29146 - atomic_inc(&cur_irq->irq_received);
29147 + atomic_inc_unchecked(&cur_irq->irq_received);
29148 DRM_WAKEUP(&cur_irq->irq_queue);
29149 handled = 1;
29150 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
29151 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
29152 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29153 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
29154 masks[irq][4]));
29155 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
29156 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
29157 } else {
29158 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29159 (((cur_irq_sequence =
29160 - atomic_read(&cur_irq->irq_received)) -
29161 + atomic_read_unchecked(&cur_irq->irq_received)) -
29162 *sequence) <= (1 << 23)));
29163 }
29164 *sequence = cur_irq_sequence;
29165 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
29166 }
29167
29168 for (i = 0; i < dev_priv->num_irqs; ++i) {
29169 - atomic_set(&cur_irq->irq_received, 0);
29170 + atomic_set_unchecked(&cur_irq->irq_received, 0);
29171 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
29172 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
29173 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
29174 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
29175 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
29176 case VIA_IRQ_RELATIVE:
29177 irqwait->request.sequence +=
29178 - atomic_read(&cur_irq->irq_received);
29179 + atomic_read_unchecked(&cur_irq->irq_received);
29180 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
29181 case VIA_IRQ_ABSOLUTE:
29182 break;
29183 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29184 index 10fc01f..b4e9822 100644
29185 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29186 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29187 @@ -240,7 +240,7 @@ struct vmw_private {
29188 * Fencing and IRQs.
29189 */
29190
29191 - atomic_t fence_seq;
29192 + atomic_unchecked_t fence_seq;
29193 wait_queue_head_t fence_queue;
29194 wait_queue_head_t fifo_queue;
29195 atomic_t fence_queue_waiters;
29196 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
29197 index 41b95ed..69ea504 100644
29198 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
29199 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
29200 @@ -610,7 +610,7 @@ int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
29201 struct drm_vmw_fence_rep fence_rep;
29202 struct drm_vmw_fence_rep __user *user_fence_rep;
29203 int ret;
29204 - void *user_cmd;
29205 + void __user *user_cmd;
29206 void *cmd;
29207 uint32_t sequence;
29208 struct vmw_sw_context *sw_context = &dev_priv->ctx;
29209 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
29210 index 61eacc1..ee38ce8 100644
29211 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
29212 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
29213 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
29214 while (!vmw_lag_lt(queue, us)) {
29215 spin_lock(&queue->lock);
29216 if (list_empty(&queue->head))
29217 - sequence = atomic_read(&dev_priv->fence_seq);
29218 + sequence = atomic_read_unchecked(&dev_priv->fence_seq);
29219 else {
29220 fence = list_first_entry(&queue->head,
29221 struct vmw_fence, head);
29222 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29223 index 635c0ff..2641bbb 100644
29224 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29225 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29226 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
29227 (unsigned int) min,
29228 (unsigned int) fifo->capabilities);
29229
29230 - atomic_set(&dev_priv->fence_seq, dev_priv->last_read_sequence);
29231 + atomic_set_unchecked(&dev_priv->fence_seq, dev_priv->last_read_sequence);
29232 iowrite32(dev_priv->last_read_sequence, fifo_mem + SVGA_FIFO_FENCE);
29233 vmw_fence_queue_init(&fifo->fence_queue);
29234 return vmw_fifo_send_fence(dev_priv, &dummy);
29235 @@ -356,7 +356,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
29236 if (reserveable)
29237 iowrite32(bytes, fifo_mem +
29238 SVGA_FIFO_RESERVED);
29239 - return fifo_mem + (next_cmd >> 2);
29240 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
29241 } else {
29242 need_bounce = true;
29243 }
29244 @@ -476,7 +476,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *sequence)
29245
29246 fm = vmw_fifo_reserve(dev_priv, bytes);
29247 if (unlikely(fm == NULL)) {
29248 - *sequence = atomic_read(&dev_priv->fence_seq);
29249 + *sequence = atomic_read_unchecked(&dev_priv->fence_seq);
29250 ret = -ENOMEM;
29251 (void)vmw_fallback_wait(dev_priv, false, true, *sequence,
29252 false, 3*HZ);
29253 @@ -484,7 +484,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *sequence)
29254 }
29255
29256 do {
29257 - *sequence = atomic_add_return(1, &dev_priv->fence_seq);
29258 + *sequence = atomic_add_return_unchecked(1, &dev_priv->fence_seq);
29259 } while (*sequence == 0);
29260
29261 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
29262 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29263 index e92298a..f68f2d6 100644
29264 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29265 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29266 @@ -100,7 +100,7 @@ bool vmw_fence_signaled(struct vmw_private *dev_priv,
29267 * emitted. Then the fence is stale and signaled.
29268 */
29269
29270 - ret = ((atomic_read(&dev_priv->fence_seq) - sequence)
29271 + ret = ((atomic_read_unchecked(&dev_priv->fence_seq) - sequence)
29272 > VMW_FENCE_WRAP);
29273
29274 return ret;
29275 @@ -131,7 +131,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
29276
29277 if (fifo_idle)
29278 down_read(&fifo_state->rwsem);
29279 - signal_seq = atomic_read(&dev_priv->fence_seq);
29280 + signal_seq = atomic_read_unchecked(&dev_priv->fence_seq);
29281 ret = 0;
29282
29283 for (;;) {
29284 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
29285 index dfe32e6..dd18a00 100644
29286 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
29287 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
29288 @@ -843,7 +843,6 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
29289 struct vmw_framebuffer *vfb = NULL;
29290 struct vmw_surface *surface = NULL;
29291 struct vmw_dma_buffer *bo = NULL;
29292 - u64 required_size;
29293 int ret;
29294
29295 /**
29296 @@ -852,8 +851,9 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
29297 * requested framebuffer.
29298 */
29299
29300 - required_size = mode_cmd->pitch * mode_cmd->height;
29301 - if (unlikely(required_size > (u64) dev_priv->vram_size)) {
29302 + if (!vmw_kms_validate_mode_vram(dev_priv,
29303 + mode_cmd->pitch,
29304 + mode_cmd->height)) {
29305 DRM_ERROR("VRAM size is too small for requested mode.\n");
29306 return NULL;
29307 }
29308 diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
29309 index c72f1c0..18376f1 100644
29310 --- a/drivers/gpu/vga/vgaarb.c
29311 +++ b/drivers/gpu/vga/vgaarb.c
29312 @@ -993,14 +993,20 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
29313 uc = &priv->cards[i];
29314 }
29315
29316 - if (!uc)
29317 - return -EINVAL;
29318 + if (!uc) {
29319 + ret_val = -EINVAL;
29320 + goto done;
29321 + }
29322
29323 - if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0)
29324 - return -EINVAL;
29325 + if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0) {
29326 + ret_val = -EINVAL;
29327 + goto done;
29328 + }
29329
29330 - if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0)
29331 - return -EINVAL;
29332 + if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0) {
29333 + ret_val = -EINVAL;
29334 + goto done;
29335 + }
29336
29337 vga_put(pdev, io_state);
29338
29339 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
29340 index e9c8f80..427d61e 100644
29341 --- a/drivers/hid/hid-core.c
29342 +++ b/drivers/hid/hid-core.c
29343 @@ -1951,7 +1951,7 @@ static bool hid_ignore(struct hid_device *hdev)
29344
29345 int hid_add_device(struct hid_device *hdev)
29346 {
29347 - static atomic_t id = ATOMIC_INIT(0);
29348 + static atomic_unchecked_t id = ATOMIC_INIT(0);
29349 int ret;
29350
29351 if (WARN_ON(hdev->status & HID_STAT_ADDED))
29352 @@ -1966,7 +1966,7 @@ int hid_add_device(struct hid_device *hdev)
29353 /* XXX hack, any other cleaner solution after the driver core
29354 * is converted to allow more than 20 bytes as the device name? */
29355 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
29356 - hdev->vendor, hdev->product, atomic_inc_return(&id));
29357 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
29358
29359 hid_debug_register(hdev, dev_name(&hdev->dev));
29360 ret = device_add(&hdev->dev);
29361 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
29362 index 7c1188b..5a64357 100644
29363 --- a/drivers/hid/usbhid/hiddev.c
29364 +++ b/drivers/hid/usbhid/hiddev.c
29365 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29366 break;
29367
29368 case HIDIOCAPPLICATION:
29369 - if (arg < 0 || arg >= hid->maxapplication)
29370 + if (arg >= hid->maxapplication)
29371 break;
29372
29373 for (i = 0; i < hid->maxcollection; i++)
29374 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
29375 index 66f6729..2d6de0a 100644
29376 --- a/drivers/hwmon/acpi_power_meter.c
29377 +++ b/drivers/hwmon/acpi_power_meter.c
29378 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
29379 return res;
29380
29381 temp /= 1000;
29382 - if (temp < 0)
29383 - return -EINVAL;
29384
29385 mutex_lock(&resource->lock);
29386 resource->trip[attr->index - 7] = temp;
29387 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
29388 index fe4104c..346febb 100644
29389 --- a/drivers/hwmon/sht15.c
29390 +++ b/drivers/hwmon/sht15.c
29391 @@ -166,7 +166,7 @@ struct sht15_data {
29392 int supply_uV;
29393 bool supply_uV_valid;
29394 struct work_struct update_supply_work;
29395 - atomic_t interrupt_handled;
29396 + atomic_unchecked_t interrupt_handled;
29397 };
29398
29399 /**
29400 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
29401 return ret;
29402
29403 gpio_direction_input(data->pdata->gpio_data);
29404 - atomic_set(&data->interrupt_handled, 0);
29405 + atomic_set_unchecked(&data->interrupt_handled, 0);
29406
29407 enable_irq(gpio_to_irq(data->pdata->gpio_data));
29408 if (gpio_get_value(data->pdata->gpio_data) == 0) {
29409 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
29410 /* Only relevant if the interrupt hasn't occurred. */
29411 - if (!atomic_read(&data->interrupt_handled))
29412 + if (!atomic_read_unchecked(&data->interrupt_handled))
29413 schedule_work(&data->read_work);
29414 }
29415 ret = wait_event_timeout(data->wait_queue,
29416 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
29417
29418 /* First disable the interrupt */
29419 disable_irq_nosync(irq);
29420 - atomic_inc(&data->interrupt_handled);
29421 + atomic_inc_unchecked(&data->interrupt_handled);
29422 /* Then schedule a reading work struct */
29423 if (data->state != SHT15_READING_NOTHING)
29424 schedule_work(&data->read_work);
29425 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
29426 * If not, then start the interrupt again - care here as could
29427 * have gone low in meantime so verify it hasn't!
29428 */
29429 - atomic_set(&data->interrupt_handled, 0);
29430 + atomic_set_unchecked(&data->interrupt_handled, 0);
29431 enable_irq(gpio_to_irq(data->pdata->gpio_data));
29432 /* If still not occurred or another handler has been scheduled */
29433 if (gpio_get_value(data->pdata->gpio_data)
29434 - || atomic_read(&data->interrupt_handled))
29435 + || atomic_read_unchecked(&data->interrupt_handled))
29436 return;
29437 }
29438
29439 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
29440 index 378fcb5..5e91fa8 100644
29441 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
29442 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
29443 @@ -43,7 +43,7 @@
29444 extern struct i2c_adapter amd756_smbus;
29445
29446 static struct i2c_adapter *s4882_adapter;
29447 -static struct i2c_algorithm *s4882_algo;
29448 +static i2c_algorithm_no_const *s4882_algo;
29449
29450 /* Wrapper access functions for multiplexed SMBus */
29451 static DEFINE_MUTEX(amd756_lock);
29452 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
29453 index 29015eb..af2d8e9 100644
29454 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
29455 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
29456 @@ -41,7 +41,7 @@
29457 extern struct i2c_adapter *nforce2_smbus;
29458
29459 static struct i2c_adapter *s4985_adapter;
29460 -static struct i2c_algorithm *s4985_algo;
29461 +static i2c_algorithm_no_const *s4985_algo;
29462
29463 /* Wrapper access functions for multiplexed SMBus */
29464 static DEFINE_MUTEX(nforce2_lock);
29465 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
29466 index d7a4833..7fae376 100644
29467 --- a/drivers/i2c/i2c-mux.c
29468 +++ b/drivers/i2c/i2c-mux.c
29469 @@ -28,7 +28,7 @@
29470 /* multiplexer per channel data */
29471 struct i2c_mux_priv {
29472 struct i2c_adapter adap;
29473 - struct i2c_algorithm algo;
29474 + i2c_algorithm_no_const algo;
29475
29476 struct i2c_adapter *parent;
29477 void *mux_dev; /* the mux chip/device */
29478 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
29479 index 57d00ca..0145194 100644
29480 --- a/drivers/ide/aec62xx.c
29481 +++ b/drivers/ide/aec62xx.c
29482 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
29483 .cable_detect = atp86x_cable_detect,
29484 };
29485
29486 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
29487 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
29488 { /* 0: AEC6210 */
29489 .name = DRV_NAME,
29490 .init_chipset = init_chipset_aec62xx,
29491 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
29492 index 2c8016a..911a27c 100644
29493 --- a/drivers/ide/alim15x3.c
29494 +++ b/drivers/ide/alim15x3.c
29495 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
29496 .dma_sff_read_status = ide_dma_sff_read_status,
29497 };
29498
29499 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
29500 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
29501 .name = DRV_NAME,
29502 .init_chipset = init_chipset_ali15x3,
29503 .init_hwif = init_hwif_ali15x3,
29504 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
29505 index 3747b25..56fc995 100644
29506 --- a/drivers/ide/amd74xx.c
29507 +++ b/drivers/ide/amd74xx.c
29508 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
29509 .udma_mask = udma, \
29510 }
29511
29512 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
29513 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
29514 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
29515 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
29516 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
29517 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
29518 index 15f0ead..cb43480 100644
29519 --- a/drivers/ide/atiixp.c
29520 +++ b/drivers/ide/atiixp.c
29521 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
29522 .cable_detect = atiixp_cable_detect,
29523 };
29524
29525 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
29526 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
29527 { /* 0: IXP200/300/400/700 */
29528 .name = DRV_NAME,
29529 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
29530 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
29531 index 5f80312..d1fc438 100644
29532 --- a/drivers/ide/cmd64x.c
29533 +++ b/drivers/ide/cmd64x.c
29534 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
29535 .dma_sff_read_status = ide_dma_sff_read_status,
29536 };
29537
29538 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
29539 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
29540 { /* 0: CMD643 */
29541 .name = DRV_NAME,
29542 .init_chipset = init_chipset_cmd64x,
29543 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
29544 index 2c1e5f7..1444762 100644
29545 --- a/drivers/ide/cs5520.c
29546 +++ b/drivers/ide/cs5520.c
29547 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
29548 .set_dma_mode = cs5520_set_dma_mode,
29549 };
29550
29551 -static const struct ide_port_info cyrix_chipset __devinitdata = {
29552 +static const struct ide_port_info cyrix_chipset __devinitconst = {
29553 .name = DRV_NAME,
29554 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
29555 .port_ops = &cs5520_port_ops,
29556 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
29557 index 4dc4eb9..49b40ad 100644
29558 --- a/drivers/ide/cs5530.c
29559 +++ b/drivers/ide/cs5530.c
29560 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
29561 .udma_filter = cs5530_udma_filter,
29562 };
29563
29564 -static const struct ide_port_info cs5530_chipset __devinitdata = {
29565 +static const struct ide_port_info cs5530_chipset __devinitconst = {
29566 .name = DRV_NAME,
29567 .init_chipset = init_chipset_cs5530,
29568 .init_hwif = init_hwif_cs5530,
29569 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
29570 index 5059faf..18d4c85 100644
29571 --- a/drivers/ide/cs5535.c
29572 +++ b/drivers/ide/cs5535.c
29573 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
29574 .cable_detect = cs5535_cable_detect,
29575 };
29576
29577 -static const struct ide_port_info cs5535_chipset __devinitdata = {
29578 +static const struct ide_port_info cs5535_chipset __devinitconst = {
29579 .name = DRV_NAME,
29580 .port_ops = &cs5535_port_ops,
29581 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
29582 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
29583 index 67cbcfa..37ea151 100644
29584 --- a/drivers/ide/cy82c693.c
29585 +++ b/drivers/ide/cy82c693.c
29586 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
29587 .set_dma_mode = cy82c693_set_dma_mode,
29588 };
29589
29590 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
29591 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
29592 .name = DRV_NAME,
29593 .init_iops = init_iops_cy82c693,
29594 .port_ops = &cy82c693_port_ops,
29595 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
29596 index 58c51cd..4aec3b8 100644
29597 --- a/drivers/ide/hpt366.c
29598 +++ b/drivers/ide/hpt366.c
29599 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
29600 }
29601 };
29602
29603 -static const struct hpt_info hpt36x __devinitdata = {
29604 +static const struct hpt_info hpt36x __devinitconst = {
29605 .chip_name = "HPT36x",
29606 .chip_type = HPT36x,
29607 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
29608 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
29609 .timings = &hpt36x_timings
29610 };
29611
29612 -static const struct hpt_info hpt370 __devinitdata = {
29613 +static const struct hpt_info hpt370 __devinitconst = {
29614 .chip_name = "HPT370",
29615 .chip_type = HPT370,
29616 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
29617 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
29618 .timings = &hpt37x_timings
29619 };
29620
29621 -static const struct hpt_info hpt370a __devinitdata = {
29622 +static const struct hpt_info hpt370a __devinitconst = {
29623 .chip_name = "HPT370A",
29624 .chip_type = HPT370A,
29625 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
29626 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
29627 .timings = &hpt37x_timings
29628 };
29629
29630 -static const struct hpt_info hpt374 __devinitdata = {
29631 +static const struct hpt_info hpt374 __devinitconst = {
29632 .chip_name = "HPT374",
29633 .chip_type = HPT374,
29634 .udma_mask = ATA_UDMA5,
29635 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
29636 .timings = &hpt37x_timings
29637 };
29638
29639 -static const struct hpt_info hpt372 __devinitdata = {
29640 +static const struct hpt_info hpt372 __devinitconst = {
29641 .chip_name = "HPT372",
29642 .chip_type = HPT372,
29643 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29644 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
29645 .timings = &hpt37x_timings
29646 };
29647
29648 -static const struct hpt_info hpt372a __devinitdata = {
29649 +static const struct hpt_info hpt372a __devinitconst = {
29650 .chip_name = "HPT372A",
29651 .chip_type = HPT372A,
29652 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29653 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
29654 .timings = &hpt37x_timings
29655 };
29656
29657 -static const struct hpt_info hpt302 __devinitdata = {
29658 +static const struct hpt_info hpt302 __devinitconst = {
29659 .chip_name = "HPT302",
29660 .chip_type = HPT302,
29661 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29662 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
29663 .timings = &hpt37x_timings
29664 };
29665
29666 -static const struct hpt_info hpt371 __devinitdata = {
29667 +static const struct hpt_info hpt371 __devinitconst = {
29668 .chip_name = "HPT371",
29669 .chip_type = HPT371,
29670 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29671 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
29672 .timings = &hpt37x_timings
29673 };
29674
29675 -static const struct hpt_info hpt372n __devinitdata = {
29676 +static const struct hpt_info hpt372n __devinitconst = {
29677 .chip_name = "HPT372N",
29678 .chip_type = HPT372N,
29679 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29680 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
29681 .timings = &hpt37x_timings
29682 };
29683
29684 -static const struct hpt_info hpt302n __devinitdata = {
29685 +static const struct hpt_info hpt302n __devinitconst = {
29686 .chip_name = "HPT302N",
29687 .chip_type = HPT302N,
29688 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29689 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
29690 .timings = &hpt37x_timings
29691 };
29692
29693 -static const struct hpt_info hpt371n __devinitdata = {
29694 +static const struct hpt_info hpt371n __devinitconst = {
29695 .chip_name = "HPT371N",
29696 .chip_type = HPT371N,
29697 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29698 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
29699 .dma_sff_read_status = ide_dma_sff_read_status,
29700 };
29701
29702 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
29703 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
29704 { /* 0: HPT36x */
29705 .name = DRV_NAME,
29706 .init_chipset = init_chipset_hpt366,
29707 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
29708 index 04b0956..f5b47dc 100644
29709 --- a/drivers/ide/ide-cd.c
29710 +++ b/drivers/ide/ide-cd.c
29711 @@ -769,7 +769,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
29712 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
29713 if ((unsigned long)buf & alignment
29714 || blk_rq_bytes(rq) & q->dma_pad_mask
29715 - || object_is_on_stack(buf))
29716 + || object_starts_on_stack(buf))
29717 drive->dma = 0;
29718 }
29719 }
29720 diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
29721 index 61fdf54..2834ea6 100644
29722 --- a/drivers/ide/ide-floppy.c
29723 +++ b/drivers/ide/ide-floppy.c
29724 @@ -379,6 +379,8 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
29725 u8 pc_buf[256], header_len, desc_cnt;
29726 int i, rc = 1, blocks, length;
29727
29728 + pax_track_stack();
29729 +
29730 ide_debug_log(IDE_DBG_FUNC, "enter");
29731
29732 drive->bios_cyl = 0;
29733 diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c
29734 index d267b7a..a22ca84 100644
29735 --- a/drivers/ide/ide-floppy_ioctl.c
29736 +++ b/drivers/ide/ide-floppy_ioctl.c
29737 @@ -292,8 +292,7 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
29738 * and CDROM_SEND_PACKET (legacy) ioctls
29739 */
29740 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
29741 - err = scsi_cmd_ioctl(bdev->bd_disk->queue, bdev->bd_disk,
29742 - mode, cmd, argp);
29743 + err = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp);
29744
29745 if (err == -ENOTTY)
29746 err = generic_ide_ioctl(drive, bdev, cmd, arg);
29747 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
29748 index a743e68..1cfd674 100644
29749 --- a/drivers/ide/ide-pci-generic.c
29750 +++ b/drivers/ide/ide-pci-generic.c
29751 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
29752 .udma_mask = ATA_UDMA6, \
29753 }
29754
29755 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
29756 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
29757 /* 0: Unknown */
29758 DECLARE_GENERIC_PCI_DEV(0),
29759
29760 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
29761 index 560e66d..d5dd180 100644
29762 --- a/drivers/ide/it8172.c
29763 +++ b/drivers/ide/it8172.c
29764 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
29765 .set_dma_mode = it8172_set_dma_mode,
29766 };
29767
29768 -static const struct ide_port_info it8172_port_info __devinitdata = {
29769 +static const struct ide_port_info it8172_port_info __devinitconst = {
29770 .name = DRV_NAME,
29771 .port_ops = &it8172_port_ops,
29772 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
29773 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
29774 index 46816ba..1847aeb 100644
29775 --- a/drivers/ide/it8213.c
29776 +++ b/drivers/ide/it8213.c
29777 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
29778 .cable_detect = it8213_cable_detect,
29779 };
29780
29781 -static const struct ide_port_info it8213_chipset __devinitdata = {
29782 +static const struct ide_port_info it8213_chipset __devinitconst = {
29783 .name = DRV_NAME,
29784 .enablebits = { {0x41, 0x80, 0x80} },
29785 .port_ops = &it8213_port_ops,
29786 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
29787 index 2e3169f..c5611db 100644
29788 --- a/drivers/ide/it821x.c
29789 +++ b/drivers/ide/it821x.c
29790 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
29791 .cable_detect = it821x_cable_detect,
29792 };
29793
29794 -static const struct ide_port_info it821x_chipset __devinitdata = {
29795 +static const struct ide_port_info it821x_chipset __devinitconst = {
29796 .name = DRV_NAME,
29797 .init_chipset = init_chipset_it821x,
29798 .init_hwif = init_hwif_it821x,
29799 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
29800 index 74c2c4a..efddd7d 100644
29801 --- a/drivers/ide/jmicron.c
29802 +++ b/drivers/ide/jmicron.c
29803 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
29804 .cable_detect = jmicron_cable_detect,
29805 };
29806
29807 -static const struct ide_port_info jmicron_chipset __devinitdata = {
29808 +static const struct ide_port_info jmicron_chipset __devinitconst = {
29809 .name = DRV_NAME,
29810 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
29811 .port_ops = &jmicron_port_ops,
29812 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
29813 index 95327a2..73f78d8 100644
29814 --- a/drivers/ide/ns87415.c
29815 +++ b/drivers/ide/ns87415.c
29816 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
29817 .dma_sff_read_status = superio_dma_sff_read_status,
29818 };
29819
29820 -static const struct ide_port_info ns87415_chipset __devinitdata = {
29821 +static const struct ide_port_info ns87415_chipset __devinitconst = {
29822 .name = DRV_NAME,
29823 .init_hwif = init_hwif_ns87415,
29824 .tp_ops = &ns87415_tp_ops,
29825 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
29826 index 1a53a4c..39edc66 100644
29827 --- a/drivers/ide/opti621.c
29828 +++ b/drivers/ide/opti621.c
29829 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
29830 .set_pio_mode = opti621_set_pio_mode,
29831 };
29832
29833 -static const struct ide_port_info opti621_chipset __devinitdata = {
29834 +static const struct ide_port_info opti621_chipset __devinitconst = {
29835 .name = DRV_NAME,
29836 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
29837 .port_ops = &opti621_port_ops,
29838 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
29839 index 9546fe2..2e5ceb6 100644
29840 --- a/drivers/ide/pdc202xx_new.c
29841 +++ b/drivers/ide/pdc202xx_new.c
29842 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
29843 .udma_mask = udma, \
29844 }
29845
29846 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
29847 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
29848 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
29849 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
29850 };
29851 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
29852 index 3a35ec6..5634510 100644
29853 --- a/drivers/ide/pdc202xx_old.c
29854 +++ b/drivers/ide/pdc202xx_old.c
29855 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
29856 .max_sectors = sectors, \
29857 }
29858
29859 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
29860 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
29861 { /* 0: PDC20246 */
29862 .name = DRV_NAME,
29863 .init_chipset = init_chipset_pdc202xx,
29864 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
29865 index b59d04c..368c2a7 100644
29866 --- a/drivers/ide/piix.c
29867 +++ b/drivers/ide/piix.c
29868 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
29869 .udma_mask = udma, \
29870 }
29871
29872 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
29873 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
29874 /* 0: MPIIX */
29875 { /*
29876 * MPIIX actually has only a single IDE channel mapped to
29877 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
29878 index a6414a8..c04173e 100644
29879 --- a/drivers/ide/rz1000.c
29880 +++ b/drivers/ide/rz1000.c
29881 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
29882 }
29883 }
29884
29885 -static const struct ide_port_info rz1000_chipset __devinitdata = {
29886 +static const struct ide_port_info rz1000_chipset __devinitconst = {
29887 .name = DRV_NAME,
29888 .host_flags = IDE_HFLAG_NO_DMA,
29889 };
29890 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
29891 index 356b9b5..d4758eb 100644
29892 --- a/drivers/ide/sc1200.c
29893 +++ b/drivers/ide/sc1200.c
29894 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
29895 .dma_sff_read_status = ide_dma_sff_read_status,
29896 };
29897
29898 -static const struct ide_port_info sc1200_chipset __devinitdata = {
29899 +static const struct ide_port_info sc1200_chipset __devinitconst = {
29900 .name = DRV_NAME,
29901 .port_ops = &sc1200_port_ops,
29902 .dma_ops = &sc1200_dma_ops,
29903 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
29904 index b7f5b0c..9701038 100644
29905 --- a/drivers/ide/scc_pata.c
29906 +++ b/drivers/ide/scc_pata.c
29907 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
29908 .dma_sff_read_status = scc_dma_sff_read_status,
29909 };
29910
29911 -static const struct ide_port_info scc_chipset __devinitdata = {
29912 +static const struct ide_port_info scc_chipset __devinitconst = {
29913 .name = "sccIDE",
29914 .init_iops = init_iops_scc,
29915 .init_dma = scc_init_dma,
29916 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
29917 index 35fb8da..24d72ef 100644
29918 --- a/drivers/ide/serverworks.c
29919 +++ b/drivers/ide/serverworks.c
29920 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
29921 .cable_detect = svwks_cable_detect,
29922 };
29923
29924 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
29925 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
29926 { /* 0: OSB4 */
29927 .name = DRV_NAME,
29928 .init_chipset = init_chipset_svwks,
29929 diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
29930 index ab3db61..afed580 100644
29931 --- a/drivers/ide/setup-pci.c
29932 +++ b/drivers/ide/setup-pci.c
29933 @@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
29934 int ret, i, n_ports = dev2 ? 4 : 2;
29935 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
29936
29937 + pax_track_stack();
29938 +
29939 for (i = 0; i < n_ports / 2; i++) {
29940 ret = ide_setup_pci_controller(pdev[i], d, !i);
29941 if (ret < 0)
29942 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
29943 index ddeda44..46f7e30 100644
29944 --- a/drivers/ide/siimage.c
29945 +++ b/drivers/ide/siimage.c
29946 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
29947 .udma_mask = ATA_UDMA6, \
29948 }
29949
29950 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
29951 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
29952 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
29953 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
29954 };
29955 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
29956 index 4a00225..09e61b4 100644
29957 --- a/drivers/ide/sis5513.c
29958 +++ b/drivers/ide/sis5513.c
29959 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
29960 .cable_detect = sis_cable_detect,
29961 };
29962
29963 -static const struct ide_port_info sis5513_chipset __devinitdata = {
29964 +static const struct ide_port_info sis5513_chipset __devinitconst = {
29965 .name = DRV_NAME,
29966 .init_chipset = init_chipset_sis5513,
29967 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
29968 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
29969 index f21dc2a..d051cd2 100644
29970 --- a/drivers/ide/sl82c105.c
29971 +++ b/drivers/ide/sl82c105.c
29972 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
29973 .dma_sff_read_status = ide_dma_sff_read_status,
29974 };
29975
29976 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
29977 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
29978 .name = DRV_NAME,
29979 .init_chipset = init_chipset_sl82c105,
29980 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
29981 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
29982 index 864ffe0..863a5e9 100644
29983 --- a/drivers/ide/slc90e66.c
29984 +++ b/drivers/ide/slc90e66.c
29985 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
29986 .cable_detect = slc90e66_cable_detect,
29987 };
29988
29989 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
29990 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
29991 .name = DRV_NAME,
29992 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
29993 .port_ops = &slc90e66_port_ops,
29994 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
29995 index e444d24..ba577de 100644
29996 --- a/drivers/ide/tc86c001.c
29997 +++ b/drivers/ide/tc86c001.c
29998 @@ -191,7 +191,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
29999 .dma_sff_read_status = ide_dma_sff_read_status,
30000 };
30001
30002 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
30003 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
30004 .name = DRV_NAME,
30005 .init_hwif = init_hwif_tc86c001,
30006 .port_ops = &tc86c001_port_ops,
30007 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
30008 index e53a1b7..d11aff7 100644
30009 --- a/drivers/ide/triflex.c
30010 +++ b/drivers/ide/triflex.c
30011 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
30012 .set_dma_mode = triflex_set_mode,
30013 };
30014
30015 -static const struct ide_port_info triflex_device __devinitdata = {
30016 +static const struct ide_port_info triflex_device __devinitconst = {
30017 .name = DRV_NAME,
30018 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
30019 .port_ops = &triflex_port_ops,
30020 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
30021 index 4b42ca0..e494a98 100644
30022 --- a/drivers/ide/trm290.c
30023 +++ b/drivers/ide/trm290.c
30024 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
30025 .dma_check = trm290_dma_check,
30026 };
30027
30028 -static const struct ide_port_info trm290_chipset __devinitdata = {
30029 +static const struct ide_port_info trm290_chipset __devinitconst = {
30030 .name = DRV_NAME,
30031 .init_hwif = init_hwif_trm290,
30032 .tp_ops = &trm290_tp_ops,
30033 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
30034 index f46f49c..eb77678 100644
30035 --- a/drivers/ide/via82cxxx.c
30036 +++ b/drivers/ide/via82cxxx.c
30037 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
30038 .cable_detect = via82cxxx_cable_detect,
30039 };
30040
30041 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
30042 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
30043 .name = DRV_NAME,
30044 .init_chipset = init_chipset_via82cxxx,
30045 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
30046 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
30047 index fc0f2bd..ac2f8a5 100644
30048 --- a/drivers/infiniband/core/cm.c
30049 +++ b/drivers/infiniband/core/cm.c
30050 @@ -113,7 +113,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
30051
30052 struct cm_counter_group {
30053 struct kobject obj;
30054 - atomic_long_t counter[CM_ATTR_COUNT];
30055 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
30056 };
30057
30058 struct cm_counter_attribute {
30059 @@ -1387,7 +1387,7 @@ static void cm_dup_req_handler(struct cm_work *work,
30060 struct ib_mad_send_buf *msg = NULL;
30061 int ret;
30062
30063 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30064 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30065 counter[CM_REQ_COUNTER]);
30066
30067 /* Quick state check to discard duplicate REQs. */
30068 @@ -1765,7 +1765,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
30069 if (!cm_id_priv)
30070 return;
30071
30072 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30073 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30074 counter[CM_REP_COUNTER]);
30075 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
30076 if (ret)
30077 @@ -1932,7 +1932,7 @@ static int cm_rtu_handler(struct cm_work *work)
30078 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
30079 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
30080 spin_unlock_irq(&cm_id_priv->lock);
30081 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30082 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30083 counter[CM_RTU_COUNTER]);
30084 goto out;
30085 }
30086 @@ -2115,7 +2115,7 @@ static int cm_dreq_handler(struct cm_work *work)
30087 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
30088 dreq_msg->local_comm_id);
30089 if (!cm_id_priv) {
30090 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30091 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30092 counter[CM_DREQ_COUNTER]);
30093 cm_issue_drep(work->port, work->mad_recv_wc);
30094 return -EINVAL;
30095 @@ -2140,7 +2140,7 @@ static int cm_dreq_handler(struct cm_work *work)
30096 case IB_CM_MRA_REP_RCVD:
30097 break;
30098 case IB_CM_TIMEWAIT:
30099 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30100 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30101 counter[CM_DREQ_COUNTER]);
30102 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30103 goto unlock;
30104 @@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
30105 cm_free_msg(msg);
30106 goto deref;
30107 case IB_CM_DREQ_RCVD:
30108 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30109 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30110 counter[CM_DREQ_COUNTER]);
30111 goto unlock;
30112 default:
30113 @@ -2521,7 +2521,7 @@ static int cm_mra_handler(struct cm_work *work)
30114 ib_modify_mad(cm_id_priv->av.port->mad_agent,
30115 cm_id_priv->msg, timeout)) {
30116 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
30117 - atomic_long_inc(&work->port->
30118 + atomic_long_inc_unchecked(&work->port->
30119 counter_group[CM_RECV_DUPLICATES].
30120 counter[CM_MRA_COUNTER]);
30121 goto out;
30122 @@ -2530,7 +2530,7 @@ static int cm_mra_handler(struct cm_work *work)
30123 break;
30124 case IB_CM_MRA_REQ_RCVD:
30125 case IB_CM_MRA_REP_RCVD:
30126 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30127 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30128 counter[CM_MRA_COUNTER]);
30129 /* fall through */
30130 default:
30131 @@ -2692,7 +2692,7 @@ static int cm_lap_handler(struct cm_work *work)
30132 case IB_CM_LAP_IDLE:
30133 break;
30134 case IB_CM_MRA_LAP_SENT:
30135 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30136 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30137 counter[CM_LAP_COUNTER]);
30138 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30139 goto unlock;
30140 @@ -2708,7 +2708,7 @@ static int cm_lap_handler(struct cm_work *work)
30141 cm_free_msg(msg);
30142 goto deref;
30143 case IB_CM_LAP_RCVD:
30144 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30145 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30146 counter[CM_LAP_COUNTER]);
30147 goto unlock;
30148 default:
30149 @@ -2992,7 +2992,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
30150 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
30151 if (cur_cm_id_priv) {
30152 spin_unlock_irq(&cm.lock);
30153 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30154 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30155 counter[CM_SIDR_REQ_COUNTER]);
30156 goto out; /* Duplicate message. */
30157 }
30158 @@ -3204,10 +3204,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
30159 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
30160 msg->retries = 1;
30161
30162 - atomic_long_add(1 + msg->retries,
30163 + atomic_long_add_unchecked(1 + msg->retries,
30164 &port->counter_group[CM_XMIT].counter[attr_index]);
30165 if (msg->retries)
30166 - atomic_long_add(msg->retries,
30167 + atomic_long_add_unchecked(msg->retries,
30168 &port->counter_group[CM_XMIT_RETRIES].
30169 counter[attr_index]);
30170
30171 @@ -3417,7 +3417,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
30172 }
30173
30174 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
30175 - atomic_long_inc(&port->counter_group[CM_RECV].
30176 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
30177 counter[attr_id - CM_ATTR_ID_OFFSET]);
30178
30179 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
30180 @@ -3615,7 +3615,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
30181 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
30182
30183 return sprintf(buf, "%ld\n",
30184 - atomic_long_read(&group->counter[cm_attr->index]));
30185 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
30186 }
30187
30188 static const struct sysfs_ops cm_counter_ops = {
30189 diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
30190 index ca4c5dc..572d1ae 100644
30191 --- a/drivers/infiniband/core/cma.c
30192 +++ b/drivers/infiniband/core/cma.c
30193 @@ -2492,6 +2492,9 @@ static int cma_resolve_ib_udp(struct rdma_id_private *id_priv,
30194
30195 req.private_data_len = sizeof(struct cma_hdr) +
30196 conn_param->private_data_len;
30197 + if (req.private_data_len < conn_param->private_data_len)
30198 + return -EINVAL;
30199 +
30200 req.private_data = kzalloc(req.private_data_len, GFP_ATOMIC);
30201 if (!req.private_data)
30202 return -ENOMEM;
30203 @@ -2541,6 +2544,9 @@ static int cma_connect_ib(struct rdma_id_private *id_priv,
30204 memset(&req, 0, sizeof req);
30205 offset = cma_user_data_offset(id_priv->id.ps);
30206 req.private_data_len = offset + conn_param->private_data_len;
30207 + if (req.private_data_len < conn_param->private_data_len)
30208 + return -EINVAL;
30209 +
30210 private_data = kzalloc(req.private_data_len, GFP_ATOMIC);
30211 if (!private_data)
30212 return -ENOMEM;
30213 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
30214 index 4507043..14ad522 100644
30215 --- a/drivers/infiniband/core/fmr_pool.c
30216 +++ b/drivers/infiniband/core/fmr_pool.c
30217 @@ -97,8 +97,8 @@ struct ib_fmr_pool {
30218
30219 struct task_struct *thread;
30220
30221 - atomic_t req_ser;
30222 - atomic_t flush_ser;
30223 + atomic_unchecked_t req_ser;
30224 + atomic_unchecked_t flush_ser;
30225
30226 wait_queue_head_t force_wait;
30227 };
30228 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
30229 struct ib_fmr_pool *pool = pool_ptr;
30230
30231 do {
30232 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
30233 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
30234 ib_fmr_batch_release(pool);
30235
30236 - atomic_inc(&pool->flush_ser);
30237 + atomic_inc_unchecked(&pool->flush_ser);
30238 wake_up_interruptible(&pool->force_wait);
30239
30240 if (pool->flush_function)
30241 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
30242 }
30243
30244 set_current_state(TASK_INTERRUPTIBLE);
30245 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
30246 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
30247 !kthread_should_stop())
30248 schedule();
30249 __set_current_state(TASK_RUNNING);
30250 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
30251 pool->dirty_watermark = params->dirty_watermark;
30252 pool->dirty_len = 0;
30253 spin_lock_init(&pool->pool_lock);
30254 - atomic_set(&pool->req_ser, 0);
30255 - atomic_set(&pool->flush_ser, 0);
30256 + atomic_set_unchecked(&pool->req_ser, 0);
30257 + atomic_set_unchecked(&pool->flush_ser, 0);
30258 init_waitqueue_head(&pool->force_wait);
30259
30260 pool->thread = kthread_run(ib_fmr_cleanup_thread,
30261 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
30262 }
30263 spin_unlock_irq(&pool->pool_lock);
30264
30265 - serial = atomic_inc_return(&pool->req_ser);
30266 + serial = atomic_inc_return_unchecked(&pool->req_ser);
30267 wake_up_process(pool->thread);
30268
30269 if (wait_event_interruptible(pool->force_wait,
30270 - atomic_read(&pool->flush_ser) - serial >= 0))
30271 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
30272 return -EINTR;
30273
30274 return 0;
30275 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
30276 } else {
30277 list_add_tail(&fmr->list, &pool->dirty_list);
30278 if (++pool->dirty_len >= pool->dirty_watermark) {
30279 - atomic_inc(&pool->req_ser);
30280 + atomic_inc_unchecked(&pool->req_ser);
30281 wake_up_process(pool->thread);
30282 }
30283 }
30284 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
30285 index 40c8353..946b0e4 100644
30286 --- a/drivers/infiniband/hw/cxgb4/mem.c
30287 +++ b/drivers/infiniband/hw/cxgb4/mem.c
30288 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
30289 int err;
30290 struct fw_ri_tpte tpt;
30291 u32 stag_idx;
30292 - static atomic_t key;
30293 + static atomic_unchecked_t key;
30294
30295 if (c4iw_fatal_error(rdev))
30296 return -EIO;
30297 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
30298 &rdev->resource.tpt_fifo_lock);
30299 if (!stag_idx)
30300 return -ENOMEM;
30301 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
30302 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
30303 }
30304 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
30305 __func__, stag_state, type, pdid, stag_idx);
30306 diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
30307 index 31ae1b1..2f5b038 100644
30308 --- a/drivers/infiniband/hw/ipath/ipath_fs.c
30309 +++ b/drivers/infiniband/hw/ipath/ipath_fs.c
30310 @@ -113,6 +113,8 @@ static ssize_t atomic_counters_read(struct file *file, char __user *buf,
30311 struct infinipath_counters counters;
30312 struct ipath_devdata *dd;
30313
30314 + pax_track_stack();
30315 +
30316 dd = file->f_path.dentry->d_inode->i_private;
30317 dd->ipath_f_read_counters(dd, &counters);
30318
30319 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
30320 index 79b3dbc..96e5fcc 100644
30321 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
30322 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
30323 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
30324 struct ib_atomic_eth *ateth;
30325 struct ipath_ack_entry *e;
30326 u64 vaddr;
30327 - atomic64_t *maddr;
30328 + atomic64_unchecked_t *maddr;
30329 u64 sdata;
30330 u32 rkey;
30331 u8 next;
30332 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
30333 IB_ACCESS_REMOTE_ATOMIC)))
30334 goto nack_acc_unlck;
30335 /* Perform atomic OP and save result. */
30336 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30337 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30338 sdata = be64_to_cpu(ateth->swap_data);
30339 e = &qp->s_ack_queue[qp->r_head_ack_queue];
30340 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
30341 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30342 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30343 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30344 be64_to_cpu(ateth->compare_data),
30345 sdata);
30346 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
30347 index 1f95bba..9530f87 100644
30348 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
30349 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
30350 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
30351 unsigned long flags;
30352 struct ib_wc wc;
30353 u64 sdata;
30354 - atomic64_t *maddr;
30355 + atomic64_unchecked_t *maddr;
30356 enum ib_wc_status send_status;
30357
30358 /*
30359 @@ -382,11 +382,11 @@ again:
30360 IB_ACCESS_REMOTE_ATOMIC)))
30361 goto acc_err;
30362 /* Perform atomic OP and save result. */
30363 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30364 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30365 sdata = wqe->wr.wr.atomic.compare_add;
30366 *(u64 *) sqp->s_sge.sge.vaddr =
30367 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
30368 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30369 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30370 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30371 sdata, wqe->wr.wr.atomic.swap);
30372 goto send_comp;
30373 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
30374 index 2d668c6..3312bb7 100644
30375 --- a/drivers/infiniband/hw/nes/nes.c
30376 +++ b/drivers/infiniband/hw/nes/nes.c
30377 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
30378 LIST_HEAD(nes_adapter_list);
30379 static LIST_HEAD(nes_dev_list);
30380
30381 -atomic_t qps_destroyed;
30382 +atomic_unchecked_t qps_destroyed;
30383
30384 static unsigned int ee_flsh_adapter;
30385 static unsigned int sysfs_nonidx_addr;
30386 @@ -275,7 +275,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
30387 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
30388 struct nes_adapter *nesadapter = nesdev->nesadapter;
30389
30390 - atomic_inc(&qps_destroyed);
30391 + atomic_inc_unchecked(&qps_destroyed);
30392
30393 /* Free the control structures */
30394
30395 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
30396 index 6fe7987..68637b5 100644
30397 --- a/drivers/infiniband/hw/nes/nes.h
30398 +++ b/drivers/infiniband/hw/nes/nes.h
30399 @@ -175,17 +175,17 @@ extern unsigned int nes_debug_level;
30400 extern unsigned int wqm_quanta;
30401 extern struct list_head nes_adapter_list;
30402
30403 -extern atomic_t cm_connects;
30404 -extern atomic_t cm_accepts;
30405 -extern atomic_t cm_disconnects;
30406 -extern atomic_t cm_closes;
30407 -extern atomic_t cm_connecteds;
30408 -extern atomic_t cm_connect_reqs;
30409 -extern atomic_t cm_rejects;
30410 -extern atomic_t mod_qp_timouts;
30411 -extern atomic_t qps_created;
30412 -extern atomic_t qps_destroyed;
30413 -extern atomic_t sw_qps_destroyed;
30414 +extern atomic_unchecked_t cm_connects;
30415 +extern atomic_unchecked_t cm_accepts;
30416 +extern atomic_unchecked_t cm_disconnects;
30417 +extern atomic_unchecked_t cm_closes;
30418 +extern atomic_unchecked_t cm_connecteds;
30419 +extern atomic_unchecked_t cm_connect_reqs;
30420 +extern atomic_unchecked_t cm_rejects;
30421 +extern atomic_unchecked_t mod_qp_timouts;
30422 +extern atomic_unchecked_t qps_created;
30423 +extern atomic_unchecked_t qps_destroyed;
30424 +extern atomic_unchecked_t sw_qps_destroyed;
30425 extern u32 mh_detected;
30426 extern u32 mh_pauses_sent;
30427 extern u32 cm_packets_sent;
30428 @@ -194,14 +194,14 @@ extern u32 cm_packets_created;
30429 extern u32 cm_packets_received;
30430 extern u32 cm_packets_dropped;
30431 extern u32 cm_packets_retrans;
30432 -extern atomic_t cm_listens_created;
30433 -extern atomic_t cm_listens_destroyed;
30434 +extern atomic_unchecked_t cm_listens_created;
30435 +extern atomic_unchecked_t cm_listens_destroyed;
30436 extern u32 cm_backlog_drops;
30437 -extern atomic_t cm_loopbacks;
30438 -extern atomic_t cm_nodes_created;
30439 -extern atomic_t cm_nodes_destroyed;
30440 -extern atomic_t cm_accel_dropped_pkts;
30441 -extern atomic_t cm_resets_recvd;
30442 +extern atomic_unchecked_t cm_loopbacks;
30443 +extern atomic_unchecked_t cm_nodes_created;
30444 +extern atomic_unchecked_t cm_nodes_destroyed;
30445 +extern atomic_unchecked_t cm_accel_dropped_pkts;
30446 +extern atomic_unchecked_t cm_resets_recvd;
30447
30448 extern u32 int_mod_timer_init;
30449 extern u32 int_mod_cq_depth_256;
30450 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
30451 index a237547..28a9819 100644
30452 --- a/drivers/infiniband/hw/nes/nes_cm.c
30453 +++ b/drivers/infiniband/hw/nes/nes_cm.c
30454 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
30455 u32 cm_packets_retrans;
30456 u32 cm_packets_created;
30457 u32 cm_packets_received;
30458 -atomic_t cm_listens_created;
30459 -atomic_t cm_listens_destroyed;
30460 +atomic_unchecked_t cm_listens_created;
30461 +atomic_unchecked_t cm_listens_destroyed;
30462 u32 cm_backlog_drops;
30463 -atomic_t cm_loopbacks;
30464 -atomic_t cm_nodes_created;
30465 -atomic_t cm_nodes_destroyed;
30466 -atomic_t cm_accel_dropped_pkts;
30467 -atomic_t cm_resets_recvd;
30468 +atomic_unchecked_t cm_loopbacks;
30469 +atomic_unchecked_t cm_nodes_created;
30470 +atomic_unchecked_t cm_nodes_destroyed;
30471 +atomic_unchecked_t cm_accel_dropped_pkts;
30472 +atomic_unchecked_t cm_resets_recvd;
30473
30474 static inline int mini_cm_accelerated(struct nes_cm_core *,
30475 struct nes_cm_node *);
30476 @@ -151,13 +151,13 @@ static struct nes_cm_ops nes_cm_api = {
30477
30478 static struct nes_cm_core *g_cm_core;
30479
30480 -atomic_t cm_connects;
30481 -atomic_t cm_accepts;
30482 -atomic_t cm_disconnects;
30483 -atomic_t cm_closes;
30484 -atomic_t cm_connecteds;
30485 -atomic_t cm_connect_reqs;
30486 -atomic_t cm_rejects;
30487 +atomic_unchecked_t cm_connects;
30488 +atomic_unchecked_t cm_accepts;
30489 +atomic_unchecked_t cm_disconnects;
30490 +atomic_unchecked_t cm_closes;
30491 +atomic_unchecked_t cm_connecteds;
30492 +atomic_unchecked_t cm_connect_reqs;
30493 +atomic_unchecked_t cm_rejects;
30494
30495
30496 /**
30497 @@ -1045,7 +1045,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
30498 kfree(listener);
30499 listener = NULL;
30500 ret = 0;
30501 - atomic_inc(&cm_listens_destroyed);
30502 + atomic_inc_unchecked(&cm_listens_destroyed);
30503 } else {
30504 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
30505 }
30506 @@ -1242,7 +1242,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
30507 cm_node->rem_mac);
30508
30509 add_hte_node(cm_core, cm_node);
30510 - atomic_inc(&cm_nodes_created);
30511 + atomic_inc_unchecked(&cm_nodes_created);
30512
30513 return cm_node;
30514 }
30515 @@ -1300,7 +1300,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
30516 }
30517
30518 atomic_dec(&cm_core->node_cnt);
30519 - atomic_inc(&cm_nodes_destroyed);
30520 + atomic_inc_unchecked(&cm_nodes_destroyed);
30521 nesqp = cm_node->nesqp;
30522 if (nesqp) {
30523 nesqp->cm_node = NULL;
30524 @@ -1367,7 +1367,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
30525
30526 static void drop_packet(struct sk_buff *skb)
30527 {
30528 - atomic_inc(&cm_accel_dropped_pkts);
30529 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30530 dev_kfree_skb_any(skb);
30531 }
30532
30533 @@ -1430,7 +1430,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
30534 {
30535
30536 int reset = 0; /* whether to send reset in case of err.. */
30537 - atomic_inc(&cm_resets_recvd);
30538 + atomic_inc_unchecked(&cm_resets_recvd);
30539 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
30540 " refcnt=%d\n", cm_node, cm_node->state,
30541 atomic_read(&cm_node->ref_count));
30542 @@ -2059,7 +2059,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
30543 rem_ref_cm_node(cm_node->cm_core, cm_node);
30544 return NULL;
30545 }
30546 - atomic_inc(&cm_loopbacks);
30547 + atomic_inc_unchecked(&cm_loopbacks);
30548 loopbackremotenode->loopbackpartner = cm_node;
30549 loopbackremotenode->tcp_cntxt.rcv_wscale =
30550 NES_CM_DEFAULT_RCV_WND_SCALE;
30551 @@ -2334,7 +2334,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
30552 add_ref_cm_node(cm_node);
30553 } else if (cm_node->state == NES_CM_STATE_TSA) {
30554 rem_ref_cm_node(cm_core, cm_node);
30555 - atomic_inc(&cm_accel_dropped_pkts);
30556 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30557 dev_kfree_skb_any(skb);
30558 break;
30559 }
30560 @@ -2640,7 +2640,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
30561
30562 if ((cm_id) && (cm_id->event_handler)) {
30563 if (issue_disconn) {
30564 - atomic_inc(&cm_disconnects);
30565 + atomic_inc_unchecked(&cm_disconnects);
30566 cm_event.event = IW_CM_EVENT_DISCONNECT;
30567 cm_event.status = disconn_status;
30568 cm_event.local_addr = cm_id->local_addr;
30569 @@ -2662,7 +2662,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
30570 }
30571
30572 if (issue_close) {
30573 - atomic_inc(&cm_closes);
30574 + atomic_inc_unchecked(&cm_closes);
30575 nes_disconnect(nesqp, 1);
30576
30577 cm_id->provider_data = nesqp;
30578 @@ -2793,7 +2793,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
30579
30580 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
30581 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
30582 - atomic_inc(&cm_accepts);
30583 + atomic_inc_unchecked(&cm_accepts);
30584
30585 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
30586 netdev_refcnt_read(nesvnic->netdev));
30587 @@ -3003,7 +3003,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
30588
30589 struct nes_cm_core *cm_core;
30590
30591 - atomic_inc(&cm_rejects);
30592 + atomic_inc_unchecked(&cm_rejects);
30593 cm_node = (struct nes_cm_node *) cm_id->provider_data;
30594 loopback = cm_node->loopbackpartner;
30595 cm_core = cm_node->cm_core;
30596 @@ -3069,7 +3069,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
30597 ntohl(cm_id->local_addr.sin_addr.s_addr),
30598 ntohs(cm_id->local_addr.sin_port));
30599
30600 - atomic_inc(&cm_connects);
30601 + atomic_inc_unchecked(&cm_connects);
30602 nesqp->active_conn = 1;
30603
30604 /* cache the cm_id in the qp */
30605 @@ -3175,7 +3175,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
30606 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
30607 return err;
30608 }
30609 - atomic_inc(&cm_listens_created);
30610 + atomic_inc_unchecked(&cm_listens_created);
30611 }
30612
30613 cm_id->add_ref(cm_id);
30614 @@ -3280,7 +3280,7 @@ static void cm_event_connected(struct nes_cm_event *event)
30615 if (nesqp->destroyed) {
30616 return;
30617 }
30618 - atomic_inc(&cm_connecteds);
30619 + atomic_inc_unchecked(&cm_connecteds);
30620 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
30621 " local port 0x%04X. jiffies = %lu.\n",
30622 nesqp->hwqp.qp_id,
30623 @@ -3495,7 +3495,7 @@ static void cm_event_reset(struct nes_cm_event *event)
30624
30625 cm_id->add_ref(cm_id);
30626 ret = cm_id->event_handler(cm_id, &cm_event);
30627 - atomic_inc(&cm_closes);
30628 + atomic_inc_unchecked(&cm_closes);
30629 cm_event.event = IW_CM_EVENT_CLOSE;
30630 cm_event.status = 0;
30631 cm_event.provider_data = cm_id->provider_data;
30632 @@ -3531,7 +3531,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
30633 return;
30634 cm_id = cm_node->cm_id;
30635
30636 - atomic_inc(&cm_connect_reqs);
30637 + atomic_inc_unchecked(&cm_connect_reqs);
30638 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30639 cm_node, cm_id, jiffies);
30640
30641 @@ -3569,7 +3569,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
30642 return;
30643 cm_id = cm_node->cm_id;
30644
30645 - atomic_inc(&cm_connect_reqs);
30646 + atomic_inc_unchecked(&cm_connect_reqs);
30647 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30648 cm_node, cm_id, jiffies);
30649
30650 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
30651 index 9d7ffeb..a95dd7d 100644
30652 --- a/drivers/infiniband/hw/nes/nes_nic.c
30653 +++ b/drivers/infiniband/hw/nes/nes_nic.c
30654 @@ -1274,31 +1274,31 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
30655 target_stat_values[++index] = mh_detected;
30656 target_stat_values[++index] = mh_pauses_sent;
30657 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
30658 - target_stat_values[++index] = atomic_read(&cm_connects);
30659 - target_stat_values[++index] = atomic_read(&cm_accepts);
30660 - target_stat_values[++index] = atomic_read(&cm_disconnects);
30661 - target_stat_values[++index] = atomic_read(&cm_connecteds);
30662 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
30663 - target_stat_values[++index] = atomic_read(&cm_rejects);
30664 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
30665 - target_stat_values[++index] = atomic_read(&qps_created);
30666 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
30667 - target_stat_values[++index] = atomic_read(&qps_destroyed);
30668 - target_stat_values[++index] = atomic_read(&cm_closes);
30669 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
30670 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
30671 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
30672 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
30673 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
30674 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
30675 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
30676 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
30677 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
30678 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
30679 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
30680 target_stat_values[++index] = cm_packets_sent;
30681 target_stat_values[++index] = cm_packets_bounced;
30682 target_stat_values[++index] = cm_packets_created;
30683 target_stat_values[++index] = cm_packets_received;
30684 target_stat_values[++index] = cm_packets_dropped;
30685 target_stat_values[++index] = cm_packets_retrans;
30686 - target_stat_values[++index] = atomic_read(&cm_listens_created);
30687 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
30688 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
30689 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
30690 target_stat_values[++index] = cm_backlog_drops;
30691 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
30692 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
30693 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
30694 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
30695 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
30696 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
30697 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
30698 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
30699 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
30700 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
30701 target_stat_values[++index] = nesadapter->free_4kpbl;
30702 target_stat_values[++index] = nesadapter->free_256pbl;
30703 target_stat_values[++index] = int_mod_timer_init;
30704 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
30705 index 9f2f7d4..6d2fee2 100644
30706 --- a/drivers/infiniband/hw/nes/nes_verbs.c
30707 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
30708 @@ -46,9 +46,9 @@
30709
30710 #include <rdma/ib_umem.h>
30711
30712 -atomic_t mod_qp_timouts;
30713 -atomic_t qps_created;
30714 -atomic_t sw_qps_destroyed;
30715 +atomic_unchecked_t mod_qp_timouts;
30716 +atomic_unchecked_t qps_created;
30717 +atomic_unchecked_t sw_qps_destroyed;
30718
30719 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
30720
30721 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
30722 if (init_attr->create_flags)
30723 return ERR_PTR(-EINVAL);
30724
30725 - atomic_inc(&qps_created);
30726 + atomic_inc_unchecked(&qps_created);
30727 switch (init_attr->qp_type) {
30728 case IB_QPT_RC:
30729 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
30730 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
30731 struct iw_cm_event cm_event;
30732 int ret;
30733
30734 - atomic_inc(&sw_qps_destroyed);
30735 + atomic_inc_unchecked(&sw_qps_destroyed);
30736 nesqp->destroyed = 1;
30737
30738 /* Blow away the connection if it exists. */
30739 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
30740 index c9624ea..e025b66 100644
30741 --- a/drivers/infiniband/hw/qib/qib.h
30742 +++ b/drivers/infiniband/hw/qib/qib.h
30743 @@ -51,6 +51,7 @@
30744 #include <linux/completion.h>
30745 #include <linux/kref.h>
30746 #include <linux/sched.h>
30747 +#include <linux/slab.h>
30748
30749 #include "qib_common.h"
30750 #include "qib_verbs.h"
30751 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
30752 index c351aa4..e6967c2 100644
30753 --- a/drivers/input/gameport/gameport.c
30754 +++ b/drivers/input/gameport/gameport.c
30755 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
30756 */
30757 static void gameport_init_port(struct gameport *gameport)
30758 {
30759 - static atomic_t gameport_no = ATOMIC_INIT(0);
30760 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
30761
30762 __module_get(THIS_MODULE);
30763
30764 mutex_init(&gameport->drv_mutex);
30765 device_initialize(&gameport->dev);
30766 dev_set_name(&gameport->dev, "gameport%lu",
30767 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
30768 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
30769 gameport->dev.bus = &gameport_bus;
30770 gameport->dev.release = gameport_release_port;
30771 if (gameport->parent)
30772 diff --git a/drivers/input/input.c b/drivers/input/input.c
30773 index da38d97..2aa0b79 100644
30774 --- a/drivers/input/input.c
30775 +++ b/drivers/input/input.c
30776 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
30777 */
30778 int input_register_device(struct input_dev *dev)
30779 {
30780 - static atomic_t input_no = ATOMIC_INIT(0);
30781 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
30782 struct input_handler *handler;
30783 const char *path;
30784 int error;
30785 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
30786 dev->setkeycode = input_default_setkeycode;
30787
30788 dev_set_name(&dev->dev, "input%ld",
30789 - (unsigned long) atomic_inc_return(&input_no) - 1);
30790 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
30791
30792 error = device_add(&dev->dev);
30793 if (error)
30794 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
30795 index b8d8611..15f8d2c 100644
30796 --- a/drivers/input/joystick/sidewinder.c
30797 +++ b/drivers/input/joystick/sidewinder.c
30798 @@ -30,6 +30,7 @@
30799 #include <linux/kernel.h>
30800 #include <linux/module.h>
30801 #include <linux/slab.h>
30802 +#include <linux/sched.h>
30803 #include <linux/init.h>
30804 #include <linux/input.h>
30805 #include <linux/gameport.h>
30806 @@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
30807 unsigned char buf[SW_LENGTH];
30808 int i;
30809
30810 + pax_track_stack();
30811 +
30812 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
30813
30814 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
30815 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
30816 index d728875..844c89b 100644
30817 --- a/drivers/input/joystick/xpad.c
30818 +++ b/drivers/input/joystick/xpad.c
30819 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
30820
30821 static int xpad_led_probe(struct usb_xpad *xpad)
30822 {
30823 - static atomic_t led_seq = ATOMIC_INIT(0);
30824 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
30825 long led_no;
30826 struct xpad_led *led;
30827 struct led_classdev *led_cdev;
30828 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
30829 if (!led)
30830 return -ENOMEM;
30831
30832 - led_no = (long)atomic_inc_return(&led_seq) - 1;
30833 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
30834
30835 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
30836 led->xpad = xpad;
30837 diff --git a/drivers/input/misc/cma3000_d0x.c b/drivers/input/misc/cma3000_d0x.c
30838 index 1633b63..09f8f20 100644
30839 --- a/drivers/input/misc/cma3000_d0x.c
30840 +++ b/drivers/input/misc/cma3000_d0x.c
30841 @@ -114,8 +114,8 @@ static void decode_mg(struct cma3000_accl_data *data, int *datax,
30842 static irqreturn_t cma3000_thread_irq(int irq, void *dev_id)
30843 {
30844 struct cma3000_accl_data *data = dev_id;
30845 - int datax, datay, dataz;
30846 - u8 ctrl, mode, range, intr_status;
30847 + int datax, datay, dataz, intr_status;
30848 + u8 ctrl, mode, range;
30849
30850 intr_status = CMA3000_READ(data, CMA3000_INTSTATUS, "interrupt status");
30851 if (intr_status < 0)
30852 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
30853 index 0110b5a..d3ad144 100644
30854 --- a/drivers/input/mousedev.c
30855 +++ b/drivers/input/mousedev.c
30856 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
30857
30858 spin_unlock_irq(&client->packet_lock);
30859
30860 - if (copy_to_user(buffer, data, count))
30861 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
30862 return -EFAULT;
30863
30864 return count;
30865 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
30866 index ba70058..571d25d 100644
30867 --- a/drivers/input/serio/serio.c
30868 +++ b/drivers/input/serio/serio.c
30869 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
30870 */
30871 static void serio_init_port(struct serio *serio)
30872 {
30873 - static atomic_t serio_no = ATOMIC_INIT(0);
30874 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
30875
30876 __module_get(THIS_MODULE);
30877
30878 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
30879 mutex_init(&serio->drv_mutex);
30880 device_initialize(&serio->dev);
30881 dev_set_name(&serio->dev, "serio%ld",
30882 - (long)atomic_inc_return(&serio_no) - 1);
30883 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
30884 serio->dev.bus = &serio_bus;
30885 serio->dev.release = serio_release_port;
30886 serio->dev.groups = serio_device_attr_groups;
30887 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
30888 index e44933d..9ba484a 100644
30889 --- a/drivers/isdn/capi/capi.c
30890 +++ b/drivers/isdn/capi/capi.c
30891 @@ -83,8 +83,8 @@ struct capiminor {
30892
30893 struct capi20_appl *ap;
30894 u32 ncci;
30895 - atomic_t datahandle;
30896 - atomic_t msgid;
30897 + atomic_unchecked_t datahandle;
30898 + atomic_unchecked_t msgid;
30899
30900 struct tty_port port;
30901 int ttyinstop;
30902 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
30903 capimsg_setu16(s, 2, mp->ap->applid);
30904 capimsg_setu8 (s, 4, CAPI_DATA_B3);
30905 capimsg_setu8 (s, 5, CAPI_RESP);
30906 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
30907 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
30908 capimsg_setu32(s, 8, mp->ncci);
30909 capimsg_setu16(s, 12, datahandle);
30910 }
30911 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
30912 mp->outbytes -= len;
30913 spin_unlock_bh(&mp->outlock);
30914
30915 - datahandle = atomic_inc_return(&mp->datahandle);
30916 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
30917 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
30918 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
30919 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
30920 capimsg_setu16(skb->data, 2, mp->ap->applid);
30921 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
30922 capimsg_setu8 (skb->data, 5, CAPI_REQ);
30923 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
30924 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
30925 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
30926 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
30927 capimsg_setu16(skb->data, 16, len); /* Data length */
30928 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
30929 index db621db..825ea1a 100644
30930 --- a/drivers/isdn/gigaset/common.c
30931 +++ b/drivers/isdn/gigaset/common.c
30932 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
30933 cs->commands_pending = 0;
30934 cs->cur_at_seq = 0;
30935 cs->gotfwver = -1;
30936 - cs->open_count = 0;
30937 + local_set(&cs->open_count, 0);
30938 cs->dev = NULL;
30939 cs->tty = NULL;
30940 cs->tty_dev = NULL;
30941 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
30942 index 212efaf..f187c6b 100644
30943 --- a/drivers/isdn/gigaset/gigaset.h
30944 +++ b/drivers/isdn/gigaset/gigaset.h
30945 @@ -35,6 +35,7 @@
30946 #include <linux/tty_driver.h>
30947 #include <linux/list.h>
30948 #include <linux/atomic.h>
30949 +#include <asm/local.h>
30950
30951 #define GIG_VERSION {0, 5, 0, 0}
30952 #define GIG_COMPAT {0, 4, 0, 0}
30953 @@ -433,7 +434,7 @@ struct cardstate {
30954 spinlock_t cmdlock;
30955 unsigned curlen, cmdbytes;
30956
30957 - unsigned open_count;
30958 + local_t open_count;
30959 struct tty_struct *tty;
30960 struct tasklet_struct if_wake_tasklet;
30961 unsigned control_state;
30962 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
30963 index e35058b..5898a8b 100644
30964 --- a/drivers/isdn/gigaset/interface.c
30965 +++ b/drivers/isdn/gigaset/interface.c
30966 @@ -162,9 +162,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
30967 }
30968 tty->driver_data = cs;
30969
30970 - ++cs->open_count;
30971 -
30972 - if (cs->open_count == 1) {
30973 + if (local_inc_return(&cs->open_count) == 1) {
30974 spin_lock_irqsave(&cs->lock, flags);
30975 cs->tty = tty;
30976 spin_unlock_irqrestore(&cs->lock, flags);
30977 @@ -192,10 +190,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
30978
30979 if (!cs->connected)
30980 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30981 - else if (!cs->open_count)
30982 + else if (!local_read(&cs->open_count))
30983 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30984 else {
30985 - if (!--cs->open_count) {
30986 + if (!local_dec_return(&cs->open_count)) {
30987 spin_lock_irqsave(&cs->lock, flags);
30988 cs->tty = NULL;
30989 spin_unlock_irqrestore(&cs->lock, flags);
30990 @@ -230,7 +228,7 @@ static int if_ioctl(struct tty_struct *tty,
30991 if (!cs->connected) {
30992 gig_dbg(DEBUG_IF, "not connected");
30993 retval = -ENODEV;
30994 - } else if (!cs->open_count)
30995 + } else if (!local_read(&cs->open_count))
30996 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30997 else {
30998 retval = 0;
30999 @@ -360,7 +358,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
31000 retval = -ENODEV;
31001 goto done;
31002 }
31003 - if (!cs->open_count) {
31004 + if (!local_read(&cs->open_count)) {
31005 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31006 retval = -ENODEV;
31007 goto done;
31008 @@ -413,7 +411,7 @@ static int if_write_room(struct tty_struct *tty)
31009 if (!cs->connected) {
31010 gig_dbg(DEBUG_IF, "not connected");
31011 retval = -ENODEV;
31012 - } else if (!cs->open_count)
31013 + } else if (!local_read(&cs->open_count))
31014 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31015 else if (cs->mstate != MS_LOCKED) {
31016 dev_warn(cs->dev, "can't write to unlocked device\n");
31017 @@ -443,7 +441,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
31018
31019 if (!cs->connected)
31020 gig_dbg(DEBUG_IF, "not connected");
31021 - else if (!cs->open_count)
31022 + else if (!local_read(&cs->open_count))
31023 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31024 else if (cs->mstate != MS_LOCKED)
31025 dev_warn(cs->dev, "can't write to unlocked device\n");
31026 @@ -471,7 +469,7 @@ static void if_throttle(struct tty_struct *tty)
31027
31028 if (!cs->connected)
31029 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31030 - else if (!cs->open_count)
31031 + else if (!local_read(&cs->open_count))
31032 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31033 else
31034 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
31035 @@ -495,7 +493,7 @@ static void if_unthrottle(struct tty_struct *tty)
31036
31037 if (!cs->connected)
31038 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31039 - else if (!cs->open_count)
31040 + else if (!local_read(&cs->open_count))
31041 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31042 else
31043 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
31044 @@ -526,7 +524,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
31045 goto out;
31046 }
31047
31048 - if (!cs->open_count) {
31049 + if (!local_read(&cs->open_count)) {
31050 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31051 goto out;
31052 }
31053 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
31054 index 2a57da59..e7a12ed 100644
31055 --- a/drivers/isdn/hardware/avm/b1.c
31056 +++ b/drivers/isdn/hardware/avm/b1.c
31057 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
31058 }
31059 if (left) {
31060 if (t4file->user) {
31061 - if (copy_from_user(buf, dp, left))
31062 + if (left > sizeof buf || copy_from_user(buf, dp, left))
31063 return -EFAULT;
31064 } else {
31065 memcpy(buf, dp, left);
31066 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
31067 }
31068 if (left) {
31069 if (config->user) {
31070 - if (copy_from_user(buf, dp, left))
31071 + if (left > sizeof buf || copy_from_user(buf, dp, left))
31072 return -EFAULT;
31073 } else {
31074 memcpy(buf, dp, left);
31075 diff --git a/drivers/isdn/hardware/eicon/capidtmf.c b/drivers/isdn/hardware/eicon/capidtmf.c
31076 index f130724..c373c68 100644
31077 --- a/drivers/isdn/hardware/eicon/capidtmf.c
31078 +++ b/drivers/isdn/hardware/eicon/capidtmf.c
31079 @@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_state *p_state, byte *buffer, word leng
31080 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
31081 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
31082
31083 + pax_track_stack();
31084
31085 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
31086 {
31087 diff --git a/drivers/isdn/hardware/eicon/capifunc.c b/drivers/isdn/hardware/eicon/capifunc.c
31088 index 4d425c6..a9be6c4 100644
31089 --- a/drivers/isdn/hardware/eicon/capifunc.c
31090 +++ b/drivers/isdn/hardware/eicon/capifunc.c
31091 @@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
31092 IDI_SYNC_REQ req;
31093 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31094
31095 + pax_track_stack();
31096 +
31097 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31098
31099 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31100 diff --git a/drivers/isdn/hardware/eicon/diddfunc.c b/drivers/isdn/hardware/eicon/diddfunc.c
31101 index 3029234..ef0d9e2 100644
31102 --- a/drivers/isdn/hardware/eicon/diddfunc.c
31103 +++ b/drivers/isdn/hardware/eicon/diddfunc.c
31104 @@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
31105 IDI_SYNC_REQ req;
31106 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31107
31108 + pax_track_stack();
31109 +
31110 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31111
31112 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31113 diff --git a/drivers/isdn/hardware/eicon/divasfunc.c b/drivers/isdn/hardware/eicon/divasfunc.c
31114 index 0bbee78..a0d0a01 100644
31115 --- a/drivers/isdn/hardware/eicon/divasfunc.c
31116 +++ b/drivers/isdn/hardware/eicon/divasfunc.c
31117 @@ -160,6 +160,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
31118 IDI_SYNC_REQ req;
31119 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31120
31121 + pax_track_stack();
31122 +
31123 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31124
31125 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31126 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
31127 index 85784a7..a19ca98 100644
31128 --- a/drivers/isdn/hardware/eicon/divasync.h
31129 +++ b/drivers/isdn/hardware/eicon/divasync.h
31130 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
31131 } diva_didd_add_adapter_t;
31132 typedef struct _diva_didd_remove_adapter {
31133 IDI_CALL p_request;
31134 -} diva_didd_remove_adapter_t;
31135 +} __no_const diva_didd_remove_adapter_t;
31136 typedef struct _diva_didd_read_adapter_array {
31137 void * buffer;
31138 dword length;
31139 diff --git a/drivers/isdn/hardware/eicon/idifunc.c b/drivers/isdn/hardware/eicon/idifunc.c
31140 index db87d51..7d09acf 100644
31141 --- a/drivers/isdn/hardware/eicon/idifunc.c
31142 +++ b/drivers/isdn/hardware/eicon/idifunc.c
31143 @@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
31144 IDI_SYNC_REQ req;
31145 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31146
31147 + pax_track_stack();
31148 +
31149 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31150
31151 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31152 diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
31153 index a339598..b6a8bfc 100644
31154 --- a/drivers/isdn/hardware/eicon/message.c
31155 +++ b/drivers/isdn/hardware/eicon/message.c
31156 @@ -4886,6 +4886,8 @@ static void sig_ind(PLCI *plci)
31157 dword d;
31158 word w;
31159
31160 + pax_track_stack();
31161 +
31162 a = plci->adapter;
31163 Id = ((word)plci->Id<<8)|a->Id;
31164 PUT_WORD(&SS_Ind[4],0x0000);
31165 @@ -7480,6 +7482,8 @@ static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
31166 word j, n, w;
31167 dword d;
31168
31169 + pax_track_stack();
31170 +
31171
31172 for(i=0;i<8;i++) bp_parms[i].length = 0;
31173 for(i=0;i<2;i++) global_config[i].length = 0;
31174 @@ -7954,6 +7958,8 @@ static word add_b23(PLCI *plci, API_PARSE *bp)
31175 const byte llc3[] = {4,3,2,2,6,6,0};
31176 const byte header[] = {0,2,3,3,0,0,0};
31177
31178 + pax_track_stack();
31179 +
31180 for(i=0;i<8;i++) bp_parms[i].length = 0;
31181 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
31182 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
31183 @@ -14741,6 +14747,8 @@ static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
31184 word appl_number_group_type[MAX_APPL];
31185 PLCI *auxplci;
31186
31187 + pax_track_stack();
31188 +
31189 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
31190
31191 if(!a->group_optimization_enabled)
31192 diff --git a/drivers/isdn/hardware/eicon/mntfunc.c b/drivers/isdn/hardware/eicon/mntfunc.c
31193 index a564b75..f3cf8b5 100644
31194 --- a/drivers/isdn/hardware/eicon/mntfunc.c
31195 +++ b/drivers/isdn/hardware/eicon/mntfunc.c
31196 @@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
31197 IDI_SYNC_REQ req;
31198 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31199
31200 + pax_track_stack();
31201 +
31202 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31203
31204 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31205 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
31206 index a3bd163..8956575 100644
31207 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
31208 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
31209 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
31210 typedef struct _diva_os_idi_adapter_interface {
31211 diva_init_card_proc_t cleanup_adapter_proc;
31212 diva_cmd_card_proc_t cmd_proc;
31213 -} diva_os_idi_adapter_interface_t;
31214 +} __no_const diva_os_idi_adapter_interface_t;
31215
31216 typedef struct _diva_os_xdi_adapter {
31217 struct list_head link;
31218 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
31219 index 6ed82ad..b05ac05 100644
31220 --- a/drivers/isdn/i4l/isdn_common.c
31221 +++ b/drivers/isdn/i4l/isdn_common.c
31222 @@ -1286,6 +1286,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
31223 } iocpar;
31224 void __user *argp = (void __user *)arg;
31225
31226 + pax_track_stack();
31227 +
31228 #define name iocpar.name
31229 #define bname iocpar.bname
31230 #define iocts iocpar.iocts
31231 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
31232 index 1f355bb..43f1fea 100644
31233 --- a/drivers/isdn/icn/icn.c
31234 +++ b/drivers/isdn/icn/icn.c
31235 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
31236 if (count > len)
31237 count = len;
31238 if (user) {
31239 - if (copy_from_user(msg, buf, count))
31240 + if (count > sizeof msg || copy_from_user(msg, buf, count))
31241 return -EFAULT;
31242 } else
31243 memcpy(msg, buf, count);
31244 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
31245 index 2535933..09a8e86 100644
31246 --- a/drivers/lguest/core.c
31247 +++ b/drivers/lguest/core.c
31248 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
31249 * it's worked so far. The end address needs +1 because __get_vm_area
31250 * allocates an extra guard page, so we need space for that.
31251 */
31252 +
31253 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31254 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31255 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
31256 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31257 +#else
31258 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31259 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
31260 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31261 +#endif
31262 +
31263 if (!switcher_vma) {
31264 err = -ENOMEM;
31265 printk("lguest: could not map switcher pages high\n");
31266 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
31267 * Now the Switcher is mapped at the right address, we can't fail!
31268 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
31269 */
31270 - memcpy(switcher_vma->addr, start_switcher_text,
31271 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
31272 end_switcher_text - start_switcher_text);
31273
31274 printk(KERN_INFO "lguest: mapped switcher at %p\n",
31275 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
31276 index 65af42f..530c87a 100644
31277 --- a/drivers/lguest/x86/core.c
31278 +++ b/drivers/lguest/x86/core.c
31279 @@ -59,7 +59,7 @@ static struct {
31280 /* Offset from where switcher.S was compiled to where we've copied it */
31281 static unsigned long switcher_offset(void)
31282 {
31283 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
31284 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
31285 }
31286
31287 /* This cpu's struct lguest_pages. */
31288 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
31289 * These copies are pretty cheap, so we do them unconditionally: */
31290 /* Save the current Host top-level page directory.
31291 */
31292 +
31293 +#ifdef CONFIG_PAX_PER_CPU_PGD
31294 + pages->state.host_cr3 = read_cr3();
31295 +#else
31296 pages->state.host_cr3 = __pa(current->mm->pgd);
31297 +#endif
31298 +
31299 /*
31300 * Set up the Guest's page tables to see this CPU's pages (and no
31301 * other CPU's pages).
31302 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
31303 * compiled-in switcher code and the high-mapped copy we just made.
31304 */
31305 for (i = 0; i < IDT_ENTRIES; i++)
31306 - default_idt_entries[i] += switcher_offset();
31307 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
31308
31309 /*
31310 * Set up the Switcher's per-cpu areas.
31311 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
31312 * it will be undisturbed when we switch. To change %cs and jump we
31313 * need this structure to feed to Intel's "lcall" instruction.
31314 */
31315 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
31316 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
31317 lguest_entry.segment = LGUEST_CS;
31318
31319 /*
31320 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
31321 index 40634b0..4f5855e 100644
31322 --- a/drivers/lguest/x86/switcher_32.S
31323 +++ b/drivers/lguest/x86/switcher_32.S
31324 @@ -87,6 +87,7 @@
31325 #include <asm/page.h>
31326 #include <asm/segment.h>
31327 #include <asm/lguest.h>
31328 +#include <asm/processor-flags.h>
31329
31330 // We mark the start of the code to copy
31331 // It's placed in .text tho it's never run here
31332 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
31333 // Changes type when we load it: damn Intel!
31334 // For after we switch over our page tables
31335 // That entry will be read-only: we'd crash.
31336 +
31337 +#ifdef CONFIG_PAX_KERNEXEC
31338 + mov %cr0, %edx
31339 + xor $X86_CR0_WP, %edx
31340 + mov %edx, %cr0
31341 +#endif
31342 +
31343 movl $(GDT_ENTRY_TSS*8), %edx
31344 ltr %dx
31345
31346 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
31347 // Let's clear it again for our return.
31348 // The GDT descriptor of the Host
31349 // Points to the table after two "size" bytes
31350 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
31351 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
31352 // Clear "used" from type field (byte 5, bit 2)
31353 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
31354 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
31355 +
31356 +#ifdef CONFIG_PAX_KERNEXEC
31357 + mov %cr0, %eax
31358 + xor $X86_CR0_WP, %eax
31359 + mov %eax, %cr0
31360 +#endif
31361
31362 // Once our page table's switched, the Guest is live!
31363 // The Host fades as we run this final step.
31364 @@ -295,13 +309,12 @@ deliver_to_host:
31365 // I consulted gcc, and it gave
31366 // These instructions, which I gladly credit:
31367 leal (%edx,%ebx,8), %eax
31368 - movzwl (%eax),%edx
31369 - movl 4(%eax), %eax
31370 - xorw %ax, %ax
31371 - orl %eax, %edx
31372 + movl 4(%eax), %edx
31373 + movw (%eax), %dx
31374 // Now the address of the handler's in %edx
31375 // We call it now: its "iret" drops us home.
31376 - jmp *%edx
31377 + ljmp $__KERNEL_CS, $1f
31378 +1: jmp *%edx
31379
31380 // Every interrupt can come to us here
31381 // But we must truly tell each apart.
31382 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
31383 index 4daf9e5..b8d1d0f 100644
31384 --- a/drivers/macintosh/macio_asic.c
31385 +++ b/drivers/macintosh/macio_asic.c
31386 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
31387 * MacIO is matched against any Apple ID, it's probe() function
31388 * will then decide wether it applies or not
31389 */
31390 -static const struct pci_device_id __devinitdata pci_ids [] = { {
31391 +static const struct pci_device_id __devinitconst pci_ids [] = { {
31392 .vendor = PCI_VENDOR_ID_APPLE,
31393 .device = PCI_ANY_ID,
31394 .subvendor = PCI_ANY_ID,
31395 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
31396 index 2e9a3ca..c2fb229 100644
31397 --- a/drivers/md/dm-ioctl.c
31398 +++ b/drivers/md/dm-ioctl.c
31399 @@ -1578,7 +1578,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
31400 cmd == DM_LIST_VERSIONS_CMD)
31401 return 0;
31402
31403 - if ((cmd == DM_DEV_CREATE_CMD)) {
31404 + if (cmd == DM_DEV_CREATE_CMD) {
31405 if (!*param->name) {
31406 DMWARN("name not supplied when creating device");
31407 return -EINVAL;
31408 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
31409 index 9bfd057..01180bc 100644
31410 --- a/drivers/md/dm-raid1.c
31411 +++ b/drivers/md/dm-raid1.c
31412 @@ -40,7 +40,7 @@ enum dm_raid1_error {
31413
31414 struct mirror {
31415 struct mirror_set *ms;
31416 - atomic_t error_count;
31417 + atomic_unchecked_t error_count;
31418 unsigned long error_type;
31419 struct dm_dev *dev;
31420 sector_t offset;
31421 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
31422 struct mirror *m;
31423
31424 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
31425 - if (!atomic_read(&m->error_count))
31426 + if (!atomic_read_unchecked(&m->error_count))
31427 return m;
31428
31429 return NULL;
31430 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
31431 * simple way to tell if a device has encountered
31432 * errors.
31433 */
31434 - atomic_inc(&m->error_count);
31435 + atomic_inc_unchecked(&m->error_count);
31436
31437 if (test_and_set_bit(error_type, &m->error_type))
31438 return;
31439 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
31440 struct mirror *m = get_default_mirror(ms);
31441
31442 do {
31443 - if (likely(!atomic_read(&m->error_count)))
31444 + if (likely(!atomic_read_unchecked(&m->error_count)))
31445 return m;
31446
31447 if (m-- == ms->mirror)
31448 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
31449 {
31450 struct mirror *default_mirror = get_default_mirror(m->ms);
31451
31452 - return !atomic_read(&default_mirror->error_count);
31453 + return !atomic_read_unchecked(&default_mirror->error_count);
31454 }
31455
31456 static int mirror_available(struct mirror_set *ms, struct bio *bio)
31457 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
31458 */
31459 if (likely(region_in_sync(ms, region, 1)))
31460 m = choose_mirror(ms, bio->bi_sector);
31461 - else if (m && atomic_read(&m->error_count))
31462 + else if (m && atomic_read_unchecked(&m->error_count))
31463 m = NULL;
31464
31465 if (likely(m))
31466 @@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
31467 }
31468
31469 ms->mirror[mirror].ms = ms;
31470 - atomic_set(&(ms->mirror[mirror].error_count), 0);
31471 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
31472 ms->mirror[mirror].error_type = 0;
31473 ms->mirror[mirror].offset = offset;
31474
31475 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
31476 */
31477 static char device_status_char(struct mirror *m)
31478 {
31479 - if (!atomic_read(&(m->error_count)))
31480 + if (!atomic_read_unchecked(&(m->error_count)))
31481 return 'A';
31482
31483 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
31484 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
31485 index 3d80cf0..b77cc47 100644
31486 --- a/drivers/md/dm-stripe.c
31487 +++ b/drivers/md/dm-stripe.c
31488 @@ -20,7 +20,7 @@ struct stripe {
31489 struct dm_dev *dev;
31490 sector_t physical_start;
31491
31492 - atomic_t error_count;
31493 + atomic_unchecked_t error_count;
31494 };
31495
31496 struct stripe_c {
31497 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
31498 kfree(sc);
31499 return r;
31500 }
31501 - atomic_set(&(sc->stripe[i].error_count), 0);
31502 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
31503 }
31504
31505 ti->private = sc;
31506 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
31507 DMEMIT("%d ", sc->stripes);
31508 for (i = 0; i < sc->stripes; i++) {
31509 DMEMIT("%s ", sc->stripe[i].dev->name);
31510 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
31511 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
31512 'D' : 'A';
31513 }
31514 buffer[i] = '\0';
31515 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
31516 */
31517 for (i = 0; i < sc->stripes; i++)
31518 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
31519 - atomic_inc(&(sc->stripe[i].error_count));
31520 - if (atomic_read(&(sc->stripe[i].error_count)) <
31521 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
31522 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
31523 DM_IO_ERROR_THRESHOLD)
31524 schedule_work(&sc->trigger_event);
31525 }
31526 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
31527 index bc04518..7a83b81 100644
31528 --- a/drivers/md/dm-table.c
31529 +++ b/drivers/md/dm-table.c
31530 @@ -389,7 +389,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
31531 if (!dev_size)
31532 return 0;
31533
31534 - if ((start >= dev_size) || (start + len > dev_size)) {
31535 + if ((start >= dev_size) || (len > dev_size - start)) {
31536 DMWARN("%s: %s too small for target: "
31537 "start=%llu, len=%llu, dev_size=%llu",
31538 dm_device_name(ti->table->md), bdevname(bdev, b),
31539 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
31540 index 52b39f3..83a8b6b 100644
31541 --- a/drivers/md/dm.c
31542 +++ b/drivers/md/dm.c
31543 @@ -165,9 +165,9 @@ struct mapped_device {
31544 /*
31545 * Event handling.
31546 */
31547 - atomic_t event_nr;
31548 + atomic_unchecked_t event_nr;
31549 wait_queue_head_t eventq;
31550 - atomic_t uevent_seq;
31551 + atomic_unchecked_t uevent_seq;
31552 struct list_head uevent_list;
31553 spinlock_t uevent_lock; /* Protect access to uevent_list */
31554
31555 @@ -1843,8 +1843,8 @@ static struct mapped_device *alloc_dev(int minor)
31556 rwlock_init(&md->map_lock);
31557 atomic_set(&md->holders, 1);
31558 atomic_set(&md->open_count, 0);
31559 - atomic_set(&md->event_nr, 0);
31560 - atomic_set(&md->uevent_seq, 0);
31561 + atomic_set_unchecked(&md->event_nr, 0);
31562 + atomic_set_unchecked(&md->uevent_seq, 0);
31563 INIT_LIST_HEAD(&md->uevent_list);
31564 spin_lock_init(&md->uevent_lock);
31565
31566 @@ -1978,7 +1978,7 @@ static void event_callback(void *context)
31567
31568 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
31569
31570 - atomic_inc(&md->event_nr);
31571 + atomic_inc_unchecked(&md->event_nr);
31572 wake_up(&md->eventq);
31573 }
31574
31575 @@ -2614,18 +2614,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
31576
31577 uint32_t dm_next_uevent_seq(struct mapped_device *md)
31578 {
31579 - return atomic_add_return(1, &md->uevent_seq);
31580 + return atomic_add_return_unchecked(1, &md->uevent_seq);
31581 }
31582
31583 uint32_t dm_get_event_nr(struct mapped_device *md)
31584 {
31585 - return atomic_read(&md->event_nr);
31586 + return atomic_read_unchecked(&md->event_nr);
31587 }
31588
31589 int dm_wait_event(struct mapped_device *md, int event_nr)
31590 {
31591 return wait_event_interruptible(md->eventq,
31592 - (event_nr != atomic_read(&md->event_nr)));
31593 + (event_nr != atomic_read_unchecked(&md->event_nr)));
31594 }
31595
31596 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
31597 diff --git a/drivers/md/md.c b/drivers/md/md.c
31598 index 5c95ccb..217fa57 100644
31599 --- a/drivers/md/md.c
31600 +++ b/drivers/md/md.c
31601 @@ -280,10 +280,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
31602 * start build, activate spare
31603 */
31604 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
31605 -static atomic_t md_event_count;
31606 +static atomic_unchecked_t md_event_count;
31607 void md_new_event(mddev_t *mddev)
31608 {
31609 - atomic_inc(&md_event_count);
31610 + atomic_inc_unchecked(&md_event_count);
31611 wake_up(&md_event_waiters);
31612 }
31613 EXPORT_SYMBOL_GPL(md_new_event);
31614 @@ -293,7 +293,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
31615 */
31616 static void md_new_event_inintr(mddev_t *mddev)
31617 {
31618 - atomic_inc(&md_event_count);
31619 + atomic_inc_unchecked(&md_event_count);
31620 wake_up(&md_event_waiters);
31621 }
31622
31623 @@ -1531,7 +1531,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
31624
31625 rdev->preferred_minor = 0xffff;
31626 rdev->data_offset = le64_to_cpu(sb->data_offset);
31627 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31628 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31629
31630 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
31631 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
31632 @@ -1748,7 +1748,7 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
31633 else
31634 sb->resync_offset = cpu_to_le64(0);
31635
31636 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
31637 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
31638
31639 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
31640 sb->size = cpu_to_le64(mddev->dev_sectors);
31641 @@ -2643,7 +2643,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
31642 static ssize_t
31643 errors_show(mdk_rdev_t *rdev, char *page)
31644 {
31645 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
31646 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
31647 }
31648
31649 static ssize_t
31650 @@ -2652,7 +2652,7 @@ errors_store(mdk_rdev_t *rdev, const char *buf, size_t len)
31651 char *e;
31652 unsigned long n = simple_strtoul(buf, &e, 10);
31653 if (*buf && (*e == 0 || *e == '\n')) {
31654 - atomic_set(&rdev->corrected_errors, n);
31655 + atomic_set_unchecked(&rdev->corrected_errors, n);
31656 return len;
31657 }
31658 return -EINVAL;
31659 @@ -3042,8 +3042,8 @@ int md_rdev_init(mdk_rdev_t *rdev)
31660 rdev->sb_loaded = 0;
31661 rdev->bb_page = NULL;
31662 atomic_set(&rdev->nr_pending, 0);
31663 - atomic_set(&rdev->read_errors, 0);
31664 - atomic_set(&rdev->corrected_errors, 0);
31665 + atomic_set_unchecked(&rdev->read_errors, 0);
31666 + atomic_set_unchecked(&rdev->corrected_errors, 0);
31667
31668 INIT_LIST_HEAD(&rdev->same_set);
31669 init_waitqueue_head(&rdev->blocked_wait);
31670 @@ -6667,7 +6667,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
31671
31672 spin_unlock(&pers_lock);
31673 seq_printf(seq, "\n");
31674 - seq->poll_event = atomic_read(&md_event_count);
31675 + seq->poll_event = atomic_read_unchecked(&md_event_count);
31676 return 0;
31677 }
31678 if (v == (void*)2) {
31679 @@ -6756,7 +6756,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
31680 chunk_kb ? "KB" : "B");
31681 if (bitmap->file) {
31682 seq_printf(seq, ", file: ");
31683 - seq_path(seq, &bitmap->file->f_path, " \t\n");
31684 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
31685 }
31686
31687 seq_printf(seq, "\n");
31688 @@ -6787,7 +6787,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
31689 return error;
31690
31691 seq = file->private_data;
31692 - seq->poll_event = atomic_read(&md_event_count);
31693 + seq->poll_event = atomic_read_unchecked(&md_event_count);
31694 return error;
31695 }
31696
31697 @@ -6801,7 +6801,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
31698 /* always allow read */
31699 mask = POLLIN | POLLRDNORM;
31700
31701 - if (seq->poll_event != atomic_read(&md_event_count))
31702 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
31703 mask |= POLLERR | POLLPRI;
31704 return mask;
31705 }
31706 @@ -6845,7 +6845,7 @@ static int is_mddev_idle(mddev_t *mddev, int init)
31707 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
31708 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
31709 (int)part_stat_read(&disk->part0, sectors[1]) -
31710 - atomic_read(&disk->sync_io);
31711 + atomic_read_unchecked(&disk->sync_io);
31712 /* sync IO will cause sync_io to increase before the disk_stats
31713 * as sync_io is counted when a request starts, and
31714 * disk_stats is counted when it completes.
31715 diff --git a/drivers/md/md.h b/drivers/md/md.h
31716 index 0a309dc..7e01d7f 100644
31717 --- a/drivers/md/md.h
31718 +++ b/drivers/md/md.h
31719 @@ -124,13 +124,13 @@ struct mdk_rdev_s
31720 * only maintained for arrays that
31721 * support hot removal
31722 */
31723 - atomic_t read_errors; /* number of consecutive read errors that
31724 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
31725 * we have tried to ignore.
31726 */
31727 struct timespec last_read_error; /* monotonic time since our
31728 * last read error
31729 */
31730 - atomic_t corrected_errors; /* number of corrected read errors,
31731 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
31732 * for reporting to userspace and storing
31733 * in superblock.
31734 */
31735 @@ -415,7 +415,7 @@ static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
31736
31737 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
31738 {
31739 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31740 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31741 }
31742
31743 struct mdk_personality
31744 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
31745 index 606fc04..f1ff8dc 100644
31746 --- a/drivers/md/raid1.c
31747 +++ b/drivers/md/raid1.c
31748 @@ -1550,7 +1550,7 @@ static int fix_sync_read_error(r1bio_t *r1_bio)
31749 if (r1_sync_page_io(rdev, sect, s,
31750 bio->bi_io_vec[idx].bv_page,
31751 READ) != 0)
31752 - atomic_add(s, &rdev->corrected_errors);
31753 + atomic_add_unchecked(s, &rdev->corrected_errors);
31754 }
31755 sectors -= s;
31756 sect += s;
31757 @@ -1763,7 +1763,7 @@ static void fix_read_error(conf_t *conf, int read_disk,
31758 test_bit(In_sync, &rdev->flags)) {
31759 if (r1_sync_page_io(rdev, sect, s,
31760 conf->tmppage, READ)) {
31761 - atomic_add(s, &rdev->corrected_errors);
31762 + atomic_add_unchecked(s, &rdev->corrected_errors);
31763 printk(KERN_INFO
31764 "md/raid1:%s: read error corrected "
31765 "(%d sectors at %llu on %s)\n",
31766 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
31767 index 1d44228..98db57d 100644
31768 --- a/drivers/md/raid10.c
31769 +++ b/drivers/md/raid10.c
31770 @@ -1423,7 +1423,7 @@ static void end_sync_read(struct bio *bio, int error)
31771 /* The write handler will notice the lack of
31772 * R10BIO_Uptodate and record any errors etc
31773 */
31774 - atomic_add(r10_bio->sectors,
31775 + atomic_add_unchecked(r10_bio->sectors,
31776 &conf->mirrors[d].rdev->corrected_errors);
31777
31778 /* for reconstruct, we always reschedule after a read.
31779 @@ -1723,7 +1723,7 @@ static void check_decay_read_errors(mddev_t *mddev, mdk_rdev_t *rdev)
31780 {
31781 struct timespec cur_time_mon;
31782 unsigned long hours_since_last;
31783 - unsigned int read_errors = atomic_read(&rdev->read_errors);
31784 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
31785
31786 ktime_get_ts(&cur_time_mon);
31787
31788 @@ -1745,9 +1745,9 @@ static void check_decay_read_errors(mddev_t *mddev, mdk_rdev_t *rdev)
31789 * overflowing the shift of read_errors by hours_since_last.
31790 */
31791 if (hours_since_last >= 8 * sizeof(read_errors))
31792 - atomic_set(&rdev->read_errors, 0);
31793 + atomic_set_unchecked(&rdev->read_errors, 0);
31794 else
31795 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
31796 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
31797 }
31798
31799 static int r10_sync_page_io(mdk_rdev_t *rdev, sector_t sector,
31800 @@ -1797,8 +1797,8 @@ static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio)
31801 return;
31802
31803 check_decay_read_errors(mddev, rdev);
31804 - atomic_inc(&rdev->read_errors);
31805 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
31806 + atomic_inc_unchecked(&rdev->read_errors);
31807 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
31808 char b[BDEVNAME_SIZE];
31809 bdevname(rdev->bdev, b);
31810
31811 @@ -1806,7 +1806,7 @@ static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio)
31812 "md/raid10:%s: %s: Raid device exceeded "
31813 "read_error threshold [cur %d:max %d]\n",
31814 mdname(mddev), b,
31815 - atomic_read(&rdev->read_errors), max_read_errors);
31816 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
31817 printk(KERN_NOTICE
31818 "md/raid10:%s: %s: Failing raid device\n",
31819 mdname(mddev), b);
31820 @@ -1951,7 +1951,7 @@ static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio)
31821 (unsigned long long)(
31822 sect + rdev->data_offset),
31823 bdevname(rdev->bdev, b));
31824 - atomic_add(s, &rdev->corrected_errors);
31825 + atomic_add_unchecked(s, &rdev->corrected_errors);
31826 }
31827
31828 rdev_dec_pending(rdev, mddev);
31829 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
31830 index b6200c3..02e8702 100644
31831 --- a/drivers/md/raid5.c
31832 +++ b/drivers/md/raid5.c
31833 @@ -1616,19 +1616,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
31834 (unsigned long long)(sh->sector
31835 + rdev->data_offset),
31836 bdevname(rdev->bdev, b));
31837 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
31838 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
31839 clear_bit(R5_ReadError, &sh->dev[i].flags);
31840 clear_bit(R5_ReWrite, &sh->dev[i].flags);
31841 }
31842 - if (atomic_read(&conf->disks[i].rdev->read_errors))
31843 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
31844 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
31845 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
31846 } else {
31847 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
31848 int retry = 0;
31849 rdev = conf->disks[i].rdev;
31850
31851 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
31852 - atomic_inc(&rdev->read_errors);
31853 + atomic_inc_unchecked(&rdev->read_errors);
31854 if (conf->mddev->degraded >= conf->max_degraded)
31855 printk_ratelimited(
31856 KERN_WARNING
31857 @@ -1648,7 +1648,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
31858 (unsigned long long)(sh->sector
31859 + rdev->data_offset),
31860 bdn);
31861 - else if (atomic_read(&rdev->read_errors)
31862 + else if (atomic_read_unchecked(&rdev->read_errors)
31863 > conf->max_nr_stripes)
31864 printk(KERN_WARNING
31865 "md/raid:%s: Too many read errors, failing device %s.\n",
31866 @@ -1978,6 +1978,7 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous)
31867 sector_t r_sector;
31868 struct stripe_head sh2;
31869
31870 + pax_track_stack();
31871
31872 chunk_offset = sector_div(new_sector, sectors_per_chunk);
31873 stripe = new_sector;
31874 diff --git a/drivers/media/common/saa7146_hlp.c b/drivers/media/common/saa7146_hlp.c
31875 index 1d1d8d2..6c6837a 100644
31876 --- a/drivers/media/common/saa7146_hlp.c
31877 +++ b/drivers/media/common/saa7146_hlp.c
31878 @@ -353,6 +353,8 @@ static void calculate_clipping_registers_rect(struct saa7146_dev *dev, struct sa
31879
31880 int x[32], y[32], w[32], h[32];
31881
31882 + pax_track_stack();
31883 +
31884 /* clear out memory */
31885 memset(&line_list[0], 0x00, sizeof(u32)*32);
31886 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
31887 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
31888 index 573d540..16f78f3 100644
31889 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
31890 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
31891 @@ -1675,7 +1675,7 @@ static struct ddb_info ddb_v6 = {
31892 .subvendor = _subvend, .subdevice = _subdev, \
31893 .driver_data = (unsigned long)&_driverdata }
31894
31895 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
31896 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
31897 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
31898 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
31899 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
31900 diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
31901 index 7ea517b..252fe54 100644
31902 --- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
31903 +++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
31904 @@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, u8 * eb
31905 u8 buf[HOST_LINK_BUF_SIZE];
31906 int i;
31907
31908 + pax_track_stack();
31909 +
31910 dprintk("%s\n", __func__);
31911
31912 /* check if we have space for a link buf in the rx_buffer */
31913 @@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
31914 unsigned long timeout;
31915 int written;
31916
31917 + pax_track_stack();
31918 +
31919 dprintk("%s\n", __func__);
31920
31921 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
31922 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
31923 index a7d876f..8c21b61 100644
31924 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
31925 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
31926 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
31927 union {
31928 dmx_ts_cb ts;
31929 dmx_section_cb sec;
31930 - } cb;
31931 + } __no_const cb;
31932
31933 struct dvb_demux *demux;
31934 void *priv;
31935 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
31936 index f732877..d38c35a 100644
31937 --- a/drivers/media/dvb/dvb-core/dvbdev.c
31938 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
31939 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
31940 const struct dvb_device *template, void *priv, int type)
31941 {
31942 struct dvb_device *dvbdev;
31943 - struct file_operations *dvbdevfops;
31944 + file_operations_no_const *dvbdevfops;
31945 struct device *clsdev;
31946 int minor;
31947 int id;
31948 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
31949 index acb5fb2..2413f1d 100644
31950 --- a/drivers/media/dvb/dvb-usb/cxusb.c
31951 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
31952 @@ -1059,7 +1059,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
31953 struct dib0700_adapter_state {
31954 int (*set_param_save) (struct dvb_frontend *,
31955 struct dvb_frontend_parameters *);
31956 -};
31957 +} __no_const;
31958
31959 static int dib7070_set_param_override(struct dvb_frontend *fe,
31960 struct dvb_frontend_parameters *fep)
31961 diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
31962 index a224e94..503b76a 100644
31963 --- a/drivers/media/dvb/dvb-usb/dib0700_core.c
31964 +++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
31965 @@ -478,6 +478,8 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
31966 if (!buf)
31967 return -ENOMEM;
31968
31969 + pax_track_stack();
31970 +
31971 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
31972 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",
31973 hx.addr, hx.len, hx.chk);
31974 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
31975 index 058b231..183d2b3 100644
31976 --- a/drivers/media/dvb/dvb-usb/dw2102.c
31977 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
31978 @@ -95,7 +95,7 @@ struct su3000_state {
31979
31980 struct s6x0_state {
31981 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
31982 -};
31983 +} __no_const;
31984
31985 /* debug */
31986 static int dvb_usb_dw2102_debug;
31987 diff --git a/drivers/media/dvb/dvb-usb/lmedm04.c b/drivers/media/dvb/dvb-usb/lmedm04.c
31988 index 37b1469..28a6f6f 100644
31989 --- a/drivers/media/dvb/dvb-usb/lmedm04.c
31990 +++ b/drivers/media/dvb/dvb-usb/lmedm04.c
31991 @@ -742,6 +742,7 @@ static int lme2510_download_firmware(struct usb_device *dev,
31992 usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
31993 0x06, 0x80, 0x0200, 0x00, data, 0x0109, 1000);
31994
31995 + pax_track_stack();
31996
31997 data[0] = 0x8a;
31998 len_in = 1;
31999 @@ -764,6 +765,8 @@ static void lme_coldreset(struct usb_device *dev)
32000 int ret = 0, len_in;
32001 u8 data[512] = {0};
32002
32003 + pax_track_stack();
32004 +
32005 data[0] = 0x0a;
32006 len_in = 1;
32007 info("FRM Firmware Cold Reset");
32008 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
32009 index ba91735..4261d84 100644
32010 --- a/drivers/media/dvb/frontends/dib3000.h
32011 +++ b/drivers/media/dvb/frontends/dib3000.h
32012 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
32013 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
32014 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
32015 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
32016 -};
32017 +} __no_const;
32018
32019 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
32020 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
32021 diff --git a/drivers/media/dvb/frontends/ds3000.c b/drivers/media/dvb/frontends/ds3000.c
32022 index 90bf573..e8463da 100644
32023 --- a/drivers/media/dvb/frontends/ds3000.c
32024 +++ b/drivers/media/dvb/frontends/ds3000.c
32025 @@ -1210,7 +1210,7 @@ static int ds3000_set_frontend(struct dvb_frontend *fe,
32026
32027 for (i = 0; i < 30 ; i++) {
32028 ds3000_read_status(fe, &status);
32029 - if (status && FE_HAS_LOCK)
32030 + if (status & FE_HAS_LOCK)
32031 break;
32032
32033 msleep(10);
32034 diff --git a/drivers/media/dvb/frontends/mb86a16.c b/drivers/media/dvb/frontends/mb86a16.c
32035 index c283112..7f367a7 100644
32036 --- a/drivers/media/dvb/frontends/mb86a16.c
32037 +++ b/drivers/media/dvb/frontends/mb86a16.c
32038 @@ -1060,6 +1060,8 @@ static int mb86a16_set_fe(struct mb86a16_state *state)
32039 int ret = -1;
32040 int sync;
32041
32042 + pax_track_stack();
32043 +
32044 dprintk(verbose, MB86A16_INFO, 1, "freq=%d Mhz, symbrt=%d Ksps", state->frequency, state->srate);
32045
32046 fcp = 3000;
32047 diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
32048 index c709ce6..b3fe620 100644
32049 --- a/drivers/media/dvb/frontends/or51211.c
32050 +++ b/drivers/media/dvb/frontends/or51211.c
32051 @@ -113,6 +113,8 @@ static int or51211_load_firmware (struct dvb_frontend* fe,
32052 u8 tudata[585];
32053 int i;
32054
32055 + pax_track_stack();
32056 +
32057 dprintk("Firmware is %zd bytes\n",fw->size);
32058
32059 /* Get eprom data */
32060 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
32061 index 0564192..75b16f5 100644
32062 --- a/drivers/media/dvb/ngene/ngene-cards.c
32063 +++ b/drivers/media/dvb/ngene/ngene-cards.c
32064 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
32065
32066 /****************************************************************************/
32067
32068 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
32069 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
32070 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
32071 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
32072 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
32073 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
32074 index 16a089f..ab1667d 100644
32075 --- a/drivers/media/radio/radio-cadet.c
32076 +++ b/drivers/media/radio/radio-cadet.c
32077 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
32078 unsigned char readbuf[RDS_BUFFER];
32079 int i = 0;
32080
32081 + if (count > RDS_BUFFER)
32082 + return -EFAULT;
32083 mutex_lock(&dev->lock);
32084 if (dev->rdsstat == 0) {
32085 dev->rdsstat = 1;
32086 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
32087 index 9cde353..8c6a1c3 100644
32088 --- a/drivers/media/video/au0828/au0828.h
32089 +++ b/drivers/media/video/au0828/au0828.h
32090 @@ -191,7 +191,7 @@ struct au0828_dev {
32091
32092 /* I2C */
32093 struct i2c_adapter i2c_adap;
32094 - struct i2c_algorithm i2c_algo;
32095 + i2c_algorithm_no_const i2c_algo;
32096 struct i2c_client i2c_client;
32097 u32 i2c_rc;
32098
32099 diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
32100 index 9e2f870..22e3a08 100644
32101 --- a/drivers/media/video/cx18/cx18-driver.c
32102 +++ b/drivers/media/video/cx18/cx18-driver.c
32103 @@ -327,6 +327,8 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
32104 struct i2c_client c;
32105 u8 eedata[256];
32106
32107 + pax_track_stack();
32108 +
32109 memset(&c, 0, sizeof(c));
32110 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
32111 c.adapter = &cx->i2c_adap[0];
32112 diff --git a/drivers/media/video/cx23885/cx23885-input.c b/drivers/media/video/cx23885/cx23885-input.c
32113 index ce765e3..f9e1b04 100644
32114 --- a/drivers/media/video/cx23885/cx23885-input.c
32115 +++ b/drivers/media/video/cx23885/cx23885-input.c
32116 @@ -53,6 +53,8 @@ static void cx23885_input_process_measurements(struct cx23885_dev *dev,
32117 bool handle = false;
32118 struct ir_raw_event ir_core_event[64];
32119
32120 + pax_track_stack();
32121 +
32122 do {
32123 num = 0;
32124 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event,
32125 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
32126 index 68d1240..46b32eb 100644
32127 --- a/drivers/media/video/cx88/cx88-alsa.c
32128 +++ b/drivers/media/video/cx88/cx88-alsa.c
32129 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
32130 * Only boards with eeprom and byte 1 at eeprom=1 have it
32131 */
32132
32133 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
32134 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
32135 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
32136 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
32137 {0, }
32138 diff --git a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
32139 index 9515f3a..c9ecb85 100644
32140 --- a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
32141 +++ b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
32142 @@ -120,6 +120,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw *hdw)
32143 u8 *eeprom;
32144 struct tveeprom tvdata;
32145
32146 + pax_track_stack();
32147 +
32148 memset(&tvdata,0,sizeof(tvdata));
32149
32150 eeprom = pvr2_eeprom_fetch(hdw);
32151 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
32152 index 305e6aa..0143317 100644
32153 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
32154 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
32155 @@ -196,7 +196,7 @@ struct pvr2_hdw {
32156
32157 /* I2C stuff */
32158 struct i2c_adapter i2c_adap;
32159 - struct i2c_algorithm i2c_algo;
32160 + i2c_algorithm_no_const i2c_algo;
32161 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
32162 int i2c_cx25840_hack_state;
32163 int i2c_linked;
32164 diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
32165 index f9f29cc..5a2e330 100644
32166 --- a/drivers/media/video/saa7134/saa6752hs.c
32167 +++ b/drivers/media/video/saa7134/saa6752hs.c
32168 @@ -682,6 +682,8 @@ static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes)
32169 unsigned char localPAT[256];
32170 unsigned char localPMT[256];
32171
32172 + pax_track_stack();
32173 +
32174 /* Set video format - must be done first as it resets other settings */
32175 set_reg8(client, 0x41, h->video_format);
32176
32177 diff --git a/drivers/media/video/saa7164/saa7164-cmd.c b/drivers/media/video/saa7164/saa7164-cmd.c
32178 index 62fac7f..f29e0b9 100644
32179 --- a/drivers/media/video/saa7164/saa7164-cmd.c
32180 +++ b/drivers/media/video/saa7164/saa7164-cmd.c
32181 @@ -88,6 +88,8 @@ int saa7164_irq_dequeue(struct saa7164_dev *dev)
32182 u8 tmp[512];
32183 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32184
32185 + pax_track_stack();
32186 +
32187 /* While any outstand message on the bus exists... */
32188 do {
32189
32190 @@ -141,6 +143,8 @@ int saa7164_cmd_dequeue(struct saa7164_dev *dev)
32191 u8 tmp[512];
32192 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32193
32194 + pax_track_stack();
32195 +
32196 while (loop) {
32197
32198 struct tmComResInfo tRsp = { 0, 0, 0, 0, 0, 0 };
32199 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
32200 index 84cd1b6..f741e07 100644
32201 --- a/drivers/media/video/timblogiw.c
32202 +++ b/drivers/media/video/timblogiw.c
32203 @@ -744,7 +744,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
32204
32205 /* Platform device functions */
32206
32207 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
32208 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
32209 .vidioc_querycap = timblogiw_querycap,
32210 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
32211 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
32212 @@ -766,7 +766,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
32213 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
32214 };
32215
32216 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
32217 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
32218 .owner = THIS_MODULE,
32219 .open = timblogiw_open,
32220 .release = timblogiw_close,
32221 diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
32222 index f344411..6ae9974 100644
32223 --- a/drivers/media/video/usbvision/usbvision-core.c
32224 +++ b/drivers/media/video/usbvision/usbvision-core.c
32225 @@ -707,6 +707,8 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
32226 unsigned char rv, gv, bv;
32227 static unsigned char *Y, *U, *V;
32228
32229 + pax_track_stack();
32230 +
32231 frame = usbvision->cur_frame;
32232 image_size = frame->frmwidth * frame->frmheight;
32233 if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
32234 diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
32235 index f300dea..04834ba 100644
32236 --- a/drivers/media/video/videobuf-dma-sg.c
32237 +++ b/drivers/media/video/videobuf-dma-sg.c
32238 @@ -607,6 +607,8 @@ void *videobuf_sg_alloc(size_t size)
32239 {
32240 struct videobuf_queue q;
32241
32242 + pax_track_stack();
32243 +
32244 /* Required to make generic handler to call __videobuf_alloc */
32245 q.int_ops = &sg_ops;
32246
32247 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
32248 index 7956a10..f39232f 100644
32249 --- a/drivers/message/fusion/mptbase.c
32250 +++ b/drivers/message/fusion/mptbase.c
32251 @@ -6681,8 +6681,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
32252 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
32253 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
32254
32255 +#ifdef CONFIG_GRKERNSEC_HIDESYM
32256 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
32257 +#else
32258 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
32259 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
32260 +#endif
32261 +
32262 /*
32263 * Rounding UP to nearest 4-kB boundary here...
32264 */
32265 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
32266 index 7596aec..f7ae9aa 100644
32267 --- a/drivers/message/fusion/mptsas.c
32268 +++ b/drivers/message/fusion/mptsas.c
32269 @@ -439,6 +439,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
32270 return 0;
32271 }
32272
32273 +static inline void
32274 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
32275 +{
32276 + if (phy_info->port_details) {
32277 + phy_info->port_details->rphy = rphy;
32278 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
32279 + ioc->name, rphy));
32280 + }
32281 +
32282 + if (rphy) {
32283 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
32284 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
32285 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
32286 + ioc->name, rphy, rphy->dev.release));
32287 + }
32288 +}
32289 +
32290 /* no mutex */
32291 static void
32292 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
32293 @@ -477,23 +494,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
32294 return NULL;
32295 }
32296
32297 -static inline void
32298 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
32299 -{
32300 - if (phy_info->port_details) {
32301 - phy_info->port_details->rphy = rphy;
32302 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
32303 - ioc->name, rphy));
32304 - }
32305 -
32306 - if (rphy) {
32307 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
32308 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
32309 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
32310 - ioc->name, rphy, rphy->dev.release));
32311 - }
32312 -}
32313 -
32314 static inline struct sas_port *
32315 mptsas_get_port(struct mptsas_phyinfo *phy_info)
32316 {
32317 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
32318 index ce61a57..3da8862 100644
32319 --- a/drivers/message/fusion/mptscsih.c
32320 +++ b/drivers/message/fusion/mptscsih.c
32321 @@ -1268,15 +1268,16 @@ mptscsih_info(struct Scsi_Host *SChost)
32322
32323 h = shost_priv(SChost);
32324
32325 - if (h) {
32326 - if (h->info_kbuf == NULL)
32327 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
32328 - return h->info_kbuf;
32329 - h->info_kbuf[0] = '\0';
32330 + if (!h)
32331 + return NULL;
32332
32333 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
32334 - h->info_kbuf[size-1] = '\0';
32335 - }
32336 + if (h->info_kbuf == NULL)
32337 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
32338 + return h->info_kbuf;
32339 + h->info_kbuf[0] = '\0';
32340 +
32341 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
32342 + h->info_kbuf[size-1] = '\0';
32343
32344 return h->info_kbuf;
32345 }
32346 diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
32347 index 098de2b..fbb922c 100644
32348 --- a/drivers/message/i2o/i2o_config.c
32349 +++ b/drivers/message/i2o/i2o_config.c
32350 @@ -781,6 +781,8 @@ static int i2o_cfg_passthru(unsigned long arg)
32351 struct i2o_message *msg;
32352 unsigned int iop;
32353
32354 + pax_track_stack();
32355 +
32356 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
32357 return -EFAULT;
32358
32359 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
32360 index 07dbeaf..5533142 100644
32361 --- a/drivers/message/i2o/i2o_proc.c
32362 +++ b/drivers/message/i2o/i2o_proc.c
32363 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
32364 "Array Controller Device"
32365 };
32366
32367 -static char *chtostr(u8 * chars, int n)
32368 -{
32369 - char tmp[256];
32370 - tmp[0] = 0;
32371 - return strncat(tmp, (char *)chars, n);
32372 -}
32373 -
32374 static int i2o_report_query_status(struct seq_file *seq, int block_status,
32375 char *group)
32376 {
32377 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
32378
32379 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
32380 seq_printf(seq, "%-#8x", ddm_table.module_id);
32381 - seq_printf(seq, "%-29s",
32382 - chtostr(ddm_table.module_name_version, 28));
32383 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
32384 seq_printf(seq, "%9d ", ddm_table.data_size);
32385 seq_printf(seq, "%8d", ddm_table.code_size);
32386
32387 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
32388
32389 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
32390 seq_printf(seq, "%-#8x", dst->module_id);
32391 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
32392 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
32393 + seq_printf(seq, "%-.28s", dst->module_name_version);
32394 + seq_printf(seq, "%-.8s", dst->date);
32395 seq_printf(seq, "%8d ", dst->module_size);
32396 seq_printf(seq, "%8d ", dst->mpb_size);
32397 seq_printf(seq, "0x%04x", dst->module_flags);
32398 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
32399 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
32400 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
32401 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
32402 - seq_printf(seq, "Vendor info : %s\n",
32403 - chtostr((u8 *) (work32 + 2), 16));
32404 - seq_printf(seq, "Product info : %s\n",
32405 - chtostr((u8 *) (work32 + 6), 16));
32406 - seq_printf(seq, "Description : %s\n",
32407 - chtostr((u8 *) (work32 + 10), 16));
32408 - seq_printf(seq, "Product rev. : %s\n",
32409 - chtostr((u8 *) (work32 + 14), 8));
32410 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
32411 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
32412 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
32413 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
32414
32415 seq_printf(seq, "Serial number : ");
32416 print_serial_number(seq, (u8 *) (work32 + 16),
32417 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
32418 }
32419
32420 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
32421 - seq_printf(seq, "Module name : %s\n",
32422 - chtostr(result.module_name, 24));
32423 - seq_printf(seq, "Module revision : %s\n",
32424 - chtostr(result.module_rev, 8));
32425 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
32426 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
32427
32428 seq_printf(seq, "Serial number : ");
32429 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
32430 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
32431 return 0;
32432 }
32433
32434 - seq_printf(seq, "Device name : %s\n",
32435 - chtostr(result.device_name, 64));
32436 - seq_printf(seq, "Service name : %s\n",
32437 - chtostr(result.service_name, 64));
32438 - seq_printf(seq, "Physical name : %s\n",
32439 - chtostr(result.physical_location, 64));
32440 - seq_printf(seq, "Instance number : %s\n",
32441 - chtostr(result.instance_number, 4));
32442 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
32443 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
32444 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
32445 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
32446
32447 return 0;
32448 }
32449 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
32450 index a8c08f3..155fe3d 100644
32451 --- a/drivers/message/i2o/iop.c
32452 +++ b/drivers/message/i2o/iop.c
32453 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
32454
32455 spin_lock_irqsave(&c->context_list_lock, flags);
32456
32457 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
32458 - atomic_inc(&c->context_list_counter);
32459 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
32460 + atomic_inc_unchecked(&c->context_list_counter);
32461
32462 - entry->context = atomic_read(&c->context_list_counter);
32463 + entry->context = atomic_read_unchecked(&c->context_list_counter);
32464
32465 list_add(&entry->list, &c->context_list);
32466
32467 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
32468
32469 #if BITS_PER_LONG == 64
32470 spin_lock_init(&c->context_list_lock);
32471 - atomic_set(&c->context_list_counter, 0);
32472 + atomic_set_unchecked(&c->context_list_counter, 0);
32473 INIT_LIST_HEAD(&c->context_list);
32474 #endif
32475
32476 diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
32477 index a20e1c4..4f57255 100644
32478 --- a/drivers/mfd/ab3100-core.c
32479 +++ b/drivers/mfd/ab3100-core.c
32480 @@ -809,7 +809,7 @@ struct ab_family_id {
32481 char *name;
32482 };
32483
32484 -static const struct ab_family_id ids[] __devinitdata = {
32485 +static const struct ab_family_id ids[] __devinitconst = {
32486 /* AB3100 */
32487 {
32488 .id = 0xc0,
32489 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
32490 index f12720d..3c251fd 100644
32491 --- a/drivers/mfd/abx500-core.c
32492 +++ b/drivers/mfd/abx500-core.c
32493 @@ -14,7 +14,7 @@ static LIST_HEAD(abx500_list);
32494
32495 struct abx500_device_entry {
32496 struct list_head list;
32497 - struct abx500_ops ops;
32498 + abx500_ops_no_const ops;
32499 struct device *dev;
32500 };
32501
32502 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
32503 index 5c2a06a..8fa077c 100644
32504 --- a/drivers/mfd/janz-cmodio.c
32505 +++ b/drivers/mfd/janz-cmodio.c
32506 @@ -13,6 +13,7 @@
32507
32508 #include <linux/kernel.h>
32509 #include <linux/module.h>
32510 +#include <linux/slab.h>
32511 #include <linux/init.h>
32512 #include <linux/pci.h>
32513 #include <linux/interrupt.h>
32514 diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c
32515 index 5fe5de1..af64f53 100644
32516 --- a/drivers/mfd/wm8350-i2c.c
32517 +++ b/drivers/mfd/wm8350-i2c.c
32518 @@ -44,6 +44,8 @@ static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg,
32519 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
32520 int ret;
32521
32522 + pax_track_stack();
32523 +
32524 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
32525 return -EINVAL;
32526
32527 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
32528 index 8b51cd6..f628f8d 100644
32529 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
32530 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
32531 @@ -437,7 +437,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
32532 * the lid is closed. This leads to interrupts as soon as a little move
32533 * is done.
32534 */
32535 - atomic_inc(&lis3_dev.count);
32536 + atomic_inc_unchecked(&lis3_dev.count);
32537
32538 wake_up_interruptible(&lis3_dev.misc_wait);
32539 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
32540 @@ -520,7 +520,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
32541 if (lis3_dev.pm_dev)
32542 pm_runtime_get_sync(lis3_dev.pm_dev);
32543
32544 - atomic_set(&lis3_dev.count, 0);
32545 + atomic_set_unchecked(&lis3_dev.count, 0);
32546 return 0;
32547 }
32548
32549 @@ -547,7 +547,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
32550 add_wait_queue(&lis3_dev.misc_wait, &wait);
32551 while (true) {
32552 set_current_state(TASK_INTERRUPTIBLE);
32553 - data = atomic_xchg(&lis3_dev.count, 0);
32554 + data = atomic_xchg_unchecked(&lis3_dev.count, 0);
32555 if (data)
32556 break;
32557
32558 @@ -585,7 +585,7 @@ out:
32559 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
32560 {
32561 poll_wait(file, &lis3_dev.misc_wait, wait);
32562 - if (atomic_read(&lis3_dev.count))
32563 + if (atomic_read_unchecked(&lis3_dev.count))
32564 return POLLIN | POLLRDNORM;
32565 return 0;
32566 }
32567 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
32568 index a193958..4d7ecd2 100644
32569 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
32570 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
32571 @@ -265,7 +265,7 @@ struct lis3lv02d {
32572 struct input_polled_dev *idev; /* input device */
32573 struct platform_device *pdev; /* platform device */
32574 struct regulator_bulk_data regulators[2];
32575 - atomic_t count; /* interrupt count after last read */
32576 + atomic_unchecked_t count; /* interrupt count after last read */
32577 union axis_conversion ac; /* hw -> logical axis */
32578 int mapped_btns[3];
32579
32580 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
32581 index 2f30bad..c4c13d0 100644
32582 --- a/drivers/misc/sgi-gru/gruhandles.c
32583 +++ b/drivers/misc/sgi-gru/gruhandles.c
32584 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
32585 unsigned long nsec;
32586
32587 nsec = CLKS2NSEC(clks);
32588 - atomic_long_inc(&mcs_op_statistics[op].count);
32589 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
32590 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
32591 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
32592 if (mcs_op_statistics[op].max < nsec)
32593 mcs_op_statistics[op].max = nsec;
32594 }
32595 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
32596 index 7768b87..f8aac38 100644
32597 --- a/drivers/misc/sgi-gru/gruprocfs.c
32598 +++ b/drivers/misc/sgi-gru/gruprocfs.c
32599 @@ -32,9 +32,9 @@
32600
32601 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
32602
32603 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
32604 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
32605 {
32606 - unsigned long val = atomic_long_read(v);
32607 + unsigned long val = atomic_long_read_unchecked(v);
32608
32609 seq_printf(s, "%16lu %s\n", val, id);
32610 }
32611 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
32612
32613 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
32614 for (op = 0; op < mcsop_last; op++) {
32615 - count = atomic_long_read(&mcs_op_statistics[op].count);
32616 - total = atomic_long_read(&mcs_op_statistics[op].total);
32617 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
32618 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
32619 max = mcs_op_statistics[op].max;
32620 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
32621 count ? total / count : 0, max);
32622 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
32623 index 5c3ce24..4915ccb 100644
32624 --- a/drivers/misc/sgi-gru/grutables.h
32625 +++ b/drivers/misc/sgi-gru/grutables.h
32626 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
32627 * GRU statistics.
32628 */
32629 struct gru_stats_s {
32630 - atomic_long_t vdata_alloc;
32631 - atomic_long_t vdata_free;
32632 - atomic_long_t gts_alloc;
32633 - atomic_long_t gts_free;
32634 - atomic_long_t gms_alloc;
32635 - atomic_long_t gms_free;
32636 - atomic_long_t gts_double_allocate;
32637 - atomic_long_t assign_context;
32638 - atomic_long_t assign_context_failed;
32639 - atomic_long_t free_context;
32640 - atomic_long_t load_user_context;
32641 - atomic_long_t load_kernel_context;
32642 - atomic_long_t lock_kernel_context;
32643 - atomic_long_t unlock_kernel_context;
32644 - atomic_long_t steal_user_context;
32645 - atomic_long_t steal_kernel_context;
32646 - atomic_long_t steal_context_failed;
32647 - atomic_long_t nopfn;
32648 - atomic_long_t asid_new;
32649 - atomic_long_t asid_next;
32650 - atomic_long_t asid_wrap;
32651 - atomic_long_t asid_reuse;
32652 - atomic_long_t intr;
32653 - atomic_long_t intr_cbr;
32654 - atomic_long_t intr_tfh;
32655 - atomic_long_t intr_spurious;
32656 - atomic_long_t intr_mm_lock_failed;
32657 - atomic_long_t call_os;
32658 - atomic_long_t call_os_wait_queue;
32659 - atomic_long_t user_flush_tlb;
32660 - atomic_long_t user_unload_context;
32661 - atomic_long_t user_exception;
32662 - atomic_long_t set_context_option;
32663 - atomic_long_t check_context_retarget_intr;
32664 - atomic_long_t check_context_unload;
32665 - atomic_long_t tlb_dropin;
32666 - atomic_long_t tlb_preload_page;
32667 - atomic_long_t tlb_dropin_fail_no_asid;
32668 - atomic_long_t tlb_dropin_fail_upm;
32669 - atomic_long_t tlb_dropin_fail_invalid;
32670 - atomic_long_t tlb_dropin_fail_range_active;
32671 - atomic_long_t tlb_dropin_fail_idle;
32672 - atomic_long_t tlb_dropin_fail_fmm;
32673 - atomic_long_t tlb_dropin_fail_no_exception;
32674 - atomic_long_t tfh_stale_on_fault;
32675 - atomic_long_t mmu_invalidate_range;
32676 - atomic_long_t mmu_invalidate_page;
32677 - atomic_long_t flush_tlb;
32678 - atomic_long_t flush_tlb_gru;
32679 - atomic_long_t flush_tlb_gru_tgh;
32680 - atomic_long_t flush_tlb_gru_zero_asid;
32681 + atomic_long_unchecked_t vdata_alloc;
32682 + atomic_long_unchecked_t vdata_free;
32683 + atomic_long_unchecked_t gts_alloc;
32684 + atomic_long_unchecked_t gts_free;
32685 + atomic_long_unchecked_t gms_alloc;
32686 + atomic_long_unchecked_t gms_free;
32687 + atomic_long_unchecked_t gts_double_allocate;
32688 + atomic_long_unchecked_t assign_context;
32689 + atomic_long_unchecked_t assign_context_failed;
32690 + atomic_long_unchecked_t free_context;
32691 + atomic_long_unchecked_t load_user_context;
32692 + atomic_long_unchecked_t load_kernel_context;
32693 + atomic_long_unchecked_t lock_kernel_context;
32694 + atomic_long_unchecked_t unlock_kernel_context;
32695 + atomic_long_unchecked_t steal_user_context;
32696 + atomic_long_unchecked_t steal_kernel_context;
32697 + atomic_long_unchecked_t steal_context_failed;
32698 + atomic_long_unchecked_t nopfn;
32699 + atomic_long_unchecked_t asid_new;
32700 + atomic_long_unchecked_t asid_next;
32701 + atomic_long_unchecked_t asid_wrap;
32702 + atomic_long_unchecked_t asid_reuse;
32703 + atomic_long_unchecked_t intr;
32704 + atomic_long_unchecked_t intr_cbr;
32705 + atomic_long_unchecked_t intr_tfh;
32706 + atomic_long_unchecked_t intr_spurious;
32707 + atomic_long_unchecked_t intr_mm_lock_failed;
32708 + atomic_long_unchecked_t call_os;
32709 + atomic_long_unchecked_t call_os_wait_queue;
32710 + atomic_long_unchecked_t user_flush_tlb;
32711 + atomic_long_unchecked_t user_unload_context;
32712 + atomic_long_unchecked_t user_exception;
32713 + atomic_long_unchecked_t set_context_option;
32714 + atomic_long_unchecked_t check_context_retarget_intr;
32715 + atomic_long_unchecked_t check_context_unload;
32716 + atomic_long_unchecked_t tlb_dropin;
32717 + atomic_long_unchecked_t tlb_preload_page;
32718 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
32719 + atomic_long_unchecked_t tlb_dropin_fail_upm;
32720 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
32721 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
32722 + atomic_long_unchecked_t tlb_dropin_fail_idle;
32723 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
32724 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
32725 + atomic_long_unchecked_t tfh_stale_on_fault;
32726 + atomic_long_unchecked_t mmu_invalidate_range;
32727 + atomic_long_unchecked_t mmu_invalidate_page;
32728 + atomic_long_unchecked_t flush_tlb;
32729 + atomic_long_unchecked_t flush_tlb_gru;
32730 + atomic_long_unchecked_t flush_tlb_gru_tgh;
32731 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
32732
32733 - atomic_long_t copy_gpa;
32734 - atomic_long_t read_gpa;
32735 + atomic_long_unchecked_t copy_gpa;
32736 + atomic_long_unchecked_t read_gpa;
32737
32738 - atomic_long_t mesq_receive;
32739 - atomic_long_t mesq_receive_none;
32740 - atomic_long_t mesq_send;
32741 - atomic_long_t mesq_send_failed;
32742 - atomic_long_t mesq_noop;
32743 - atomic_long_t mesq_send_unexpected_error;
32744 - atomic_long_t mesq_send_lb_overflow;
32745 - atomic_long_t mesq_send_qlimit_reached;
32746 - atomic_long_t mesq_send_amo_nacked;
32747 - atomic_long_t mesq_send_put_nacked;
32748 - atomic_long_t mesq_page_overflow;
32749 - atomic_long_t mesq_qf_locked;
32750 - atomic_long_t mesq_qf_noop_not_full;
32751 - atomic_long_t mesq_qf_switch_head_failed;
32752 - atomic_long_t mesq_qf_unexpected_error;
32753 - atomic_long_t mesq_noop_unexpected_error;
32754 - atomic_long_t mesq_noop_lb_overflow;
32755 - atomic_long_t mesq_noop_qlimit_reached;
32756 - atomic_long_t mesq_noop_amo_nacked;
32757 - atomic_long_t mesq_noop_put_nacked;
32758 - atomic_long_t mesq_noop_page_overflow;
32759 + atomic_long_unchecked_t mesq_receive;
32760 + atomic_long_unchecked_t mesq_receive_none;
32761 + atomic_long_unchecked_t mesq_send;
32762 + atomic_long_unchecked_t mesq_send_failed;
32763 + atomic_long_unchecked_t mesq_noop;
32764 + atomic_long_unchecked_t mesq_send_unexpected_error;
32765 + atomic_long_unchecked_t mesq_send_lb_overflow;
32766 + atomic_long_unchecked_t mesq_send_qlimit_reached;
32767 + atomic_long_unchecked_t mesq_send_amo_nacked;
32768 + atomic_long_unchecked_t mesq_send_put_nacked;
32769 + atomic_long_unchecked_t mesq_page_overflow;
32770 + atomic_long_unchecked_t mesq_qf_locked;
32771 + atomic_long_unchecked_t mesq_qf_noop_not_full;
32772 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
32773 + atomic_long_unchecked_t mesq_qf_unexpected_error;
32774 + atomic_long_unchecked_t mesq_noop_unexpected_error;
32775 + atomic_long_unchecked_t mesq_noop_lb_overflow;
32776 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
32777 + atomic_long_unchecked_t mesq_noop_amo_nacked;
32778 + atomic_long_unchecked_t mesq_noop_put_nacked;
32779 + atomic_long_unchecked_t mesq_noop_page_overflow;
32780
32781 };
32782
32783 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
32784 tghop_invalidate, mcsop_last};
32785
32786 struct mcs_op_statistic {
32787 - atomic_long_t count;
32788 - atomic_long_t total;
32789 + atomic_long_unchecked_t count;
32790 + atomic_long_unchecked_t total;
32791 unsigned long max;
32792 };
32793
32794 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
32795
32796 #define STAT(id) do { \
32797 if (gru_options & OPT_STATS) \
32798 - atomic_long_inc(&gru_stats.id); \
32799 + atomic_long_inc_unchecked(&gru_stats.id); \
32800 } while (0)
32801
32802 #ifdef CONFIG_SGI_GRU_DEBUG
32803 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
32804 index 851b2f2..a4ec097 100644
32805 --- a/drivers/misc/sgi-xp/xp.h
32806 +++ b/drivers/misc/sgi-xp/xp.h
32807 @@ -289,7 +289,7 @@ struct xpc_interface {
32808 xpc_notify_func, void *);
32809 void (*received) (short, int, void *);
32810 enum xp_retval (*partid_to_nasids) (short, void *);
32811 -};
32812 +} __no_const;
32813
32814 extern struct xpc_interface xpc_interface;
32815
32816 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
32817 index b94d5f7..7f494c5 100644
32818 --- a/drivers/misc/sgi-xp/xpc.h
32819 +++ b/drivers/misc/sgi-xp/xpc.h
32820 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
32821 void (*received_payload) (struct xpc_channel *, void *);
32822 void (*notify_senders_of_disconnect) (struct xpc_channel *);
32823 };
32824 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
32825
32826 /* struct xpc_partition act_state values (for XPC HB) */
32827
32828 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
32829 /* found in xpc_main.c */
32830 extern struct device *xpc_part;
32831 extern struct device *xpc_chan;
32832 -extern struct xpc_arch_operations xpc_arch_ops;
32833 +extern xpc_arch_operations_no_const xpc_arch_ops;
32834 extern int xpc_disengage_timelimit;
32835 extern int xpc_disengage_timedout;
32836 extern int xpc_activate_IRQ_rcvd;
32837 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
32838 index 8d082b4..aa749ae 100644
32839 --- a/drivers/misc/sgi-xp/xpc_main.c
32840 +++ b/drivers/misc/sgi-xp/xpc_main.c
32841 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
32842 .notifier_call = xpc_system_die,
32843 };
32844
32845 -struct xpc_arch_operations xpc_arch_ops;
32846 +xpc_arch_operations_no_const xpc_arch_ops;
32847
32848 /*
32849 * Timer function to enforce the timelimit on the partition disengage.
32850 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
32851 index 26c5286..292d261 100644
32852 --- a/drivers/mmc/host/sdhci-pci.c
32853 +++ b/drivers/mmc/host/sdhci-pci.c
32854 @@ -542,7 +542,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
32855 .probe = via_probe,
32856 };
32857
32858 -static const struct pci_device_id pci_ids[] __devinitdata = {
32859 +static const struct pci_device_id pci_ids[] __devinitconst = {
32860 {
32861 .vendor = PCI_VENDOR_ID_RICOH,
32862 .device = PCI_DEVICE_ID_RICOH_R5C822,
32863 diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
32864 index e1e122f..d99a6ea 100644
32865 --- a/drivers/mtd/chips/cfi_cmdset_0001.c
32866 +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
32867 @@ -757,6 +757,8 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
32868 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
32869 unsigned long timeo = jiffies + HZ;
32870
32871 + pax_track_stack();
32872 +
32873 /* Prevent setting state FL_SYNCING for chip in suspended state. */
32874 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
32875 goto sleep;
32876 @@ -1653,6 +1655,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
32877 unsigned long initial_adr;
32878 int initial_len = len;
32879
32880 + pax_track_stack();
32881 +
32882 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
32883 adr += chip->start;
32884 initial_adr = adr;
32885 @@ -1871,6 +1875,8 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
32886 int retries = 3;
32887 int ret;
32888
32889 + pax_track_stack();
32890 +
32891 adr += chip->start;
32892
32893 retry:
32894 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
32895 index 179814a..abe9d60 100644
32896 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
32897 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
32898 @@ -255,6 +255,8 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
32899 unsigned long cmd_addr;
32900 struct cfi_private *cfi = map->fldrv_priv;
32901
32902 + pax_track_stack();
32903 +
32904 adr += chip->start;
32905
32906 /* Ensure cmd read/writes are aligned. */
32907 @@ -429,6 +431,8 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
32908 DECLARE_WAITQUEUE(wait, current);
32909 int wbufsize, z;
32910
32911 + pax_track_stack();
32912 +
32913 /* M58LW064A requires bus alignment for buffer wriets -- saw */
32914 if (adr & (map_bankwidth(map)-1))
32915 return -EINVAL;
32916 @@ -743,6 +747,8 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
32917 DECLARE_WAITQUEUE(wait, current);
32918 int ret = 0;
32919
32920 + pax_track_stack();
32921 +
32922 adr += chip->start;
32923
32924 /* Let's determine this according to the interleave only once */
32925 @@ -1048,6 +1054,8 @@ static inline int do_lock_oneblock(struct map_info *map, struct flchip *chip, un
32926 unsigned long timeo = jiffies + HZ;
32927 DECLARE_WAITQUEUE(wait, current);
32928
32929 + pax_track_stack();
32930 +
32931 adr += chip->start;
32932
32933 /* Let's determine this according to the interleave only once */
32934 @@ -1197,6 +1205,8 @@ static inline int do_unlock_oneblock(struct map_info *map, struct flchip *chip,
32935 unsigned long timeo = jiffies + HZ;
32936 DECLARE_WAITQUEUE(wait, current);
32937
32938 + pax_track_stack();
32939 +
32940 adr += chip->start;
32941
32942 /* Let's determine this according to the interleave only once */
32943 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
32944 index f7fbf60..9866457 100644
32945 --- a/drivers/mtd/devices/doc2000.c
32946 +++ b/drivers/mtd/devices/doc2000.c
32947 @@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
32948
32949 /* The ECC will not be calculated correctly if less than 512 is written */
32950 /* DBB-
32951 - if (len != 0x200 && eccbuf)
32952 + if (len != 0x200)
32953 printk(KERN_WARNING
32954 "ECC needs a full sector write (adr: %lx size %lx)\n",
32955 (long) to, (long) len);
32956 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
32957 index 241192f..d0c35a3 100644
32958 --- a/drivers/mtd/devices/doc2001.c
32959 +++ b/drivers/mtd/devices/doc2001.c
32960 @@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
32961 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
32962
32963 /* Don't allow read past end of device */
32964 - if (from >= this->totlen)
32965 + if (from >= this->totlen || !len)
32966 return -EINVAL;
32967
32968 /* Don't allow a single read to cross a 512-byte block boundary */
32969 diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
32970 index 037b399..225a71d 100644
32971 --- a/drivers/mtd/ftl.c
32972 +++ b/drivers/mtd/ftl.c
32973 @@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit,
32974 loff_t offset;
32975 uint16_t srcunitswap = cpu_to_le16(srcunit);
32976
32977 + pax_track_stack();
32978 +
32979 eun = &part->EUNInfo[srcunit];
32980 xfer = &part->XferInfo[xferunit];
32981 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
32982 diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
32983 index d7592e6..31c505c 100644
32984 --- a/drivers/mtd/inftlcore.c
32985 +++ b/drivers/mtd/inftlcore.c
32986 @@ -259,6 +259,8 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
32987 struct inftl_oob oob;
32988 size_t retlen;
32989
32990 + pax_track_stack();
32991 +
32992 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
32993 "pending=%d)\n", inftl, thisVUC, pendingblock);
32994
32995 diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
32996 index 104052e..6232be5 100644
32997 --- a/drivers/mtd/inftlmount.c
32998 +++ b/drivers/mtd/inftlmount.c
32999 @@ -53,6 +53,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
33000 struct INFTLPartition *ip;
33001 size_t retlen;
33002
33003 + pax_track_stack();
33004 +
33005 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
33006
33007 /*
33008 diff --git a/drivers/mtd/lpddr/qinfo_probe.c b/drivers/mtd/lpddr/qinfo_probe.c
33009 index dbfe17b..c7b0918 100644
33010 --- a/drivers/mtd/lpddr/qinfo_probe.c
33011 +++ b/drivers/mtd/lpddr/qinfo_probe.c
33012 @@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map_info *map, struct lpddr_private *lpddr)
33013 {
33014 map_word pfow_val[4];
33015
33016 + pax_track_stack();
33017 +
33018 /* Check identification string */
33019 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
33020 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
33021 diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
33022 index 49e20a4..60fbfa5 100644
33023 --- a/drivers/mtd/mtdchar.c
33024 +++ b/drivers/mtd/mtdchar.c
33025 @@ -554,6 +554,8 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
33026 u_long size;
33027 struct mtd_info_user info;
33028
33029 + pax_track_stack();
33030 +
33031 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
33032
33033 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
33034 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
33035 index d527621..2491fab 100644
33036 --- a/drivers/mtd/nand/denali.c
33037 +++ b/drivers/mtd/nand/denali.c
33038 @@ -26,6 +26,7 @@
33039 #include <linux/pci.h>
33040 #include <linux/mtd/mtd.h>
33041 #include <linux/module.h>
33042 +#include <linux/slab.h>
33043
33044 #include "denali.h"
33045
33046 diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
33047 index b155666..611b801 100644
33048 --- a/drivers/mtd/nftlcore.c
33049 +++ b/drivers/mtd/nftlcore.c
33050 @@ -264,6 +264,8 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
33051 int inplace = 1;
33052 size_t retlen;
33053
33054 + pax_track_stack();
33055 +
33056 memset(BlockMap, 0xff, sizeof(BlockMap));
33057 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
33058
33059 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
33060 index e3cd1ff..0ea79a3 100644
33061 --- a/drivers/mtd/nftlmount.c
33062 +++ b/drivers/mtd/nftlmount.c
33063 @@ -24,6 +24,7 @@
33064 #include <asm/errno.h>
33065 #include <linux/delay.h>
33066 #include <linux/slab.h>
33067 +#include <linux/sched.h>
33068 #include <linux/mtd/mtd.h>
33069 #include <linux/mtd/nand.h>
33070 #include <linux/mtd/nftl.h>
33071 @@ -45,6 +46,8 @@ static int find_boot_record(struct NFTLrecord *nftl)
33072 struct mtd_info *mtd = nftl->mbd.mtd;
33073 unsigned int i;
33074
33075 + pax_track_stack();
33076 +
33077 /* Assume logical EraseSize == physical erasesize for starting the scan.
33078 We'll sort it out later if we find a MediaHeader which says otherwise */
33079 /* Actually, we won't. The new DiskOnChip driver has already scanned
33080 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
33081 index 6c3fb5a..c542a81 100644
33082 --- a/drivers/mtd/ubi/build.c
33083 +++ b/drivers/mtd/ubi/build.c
33084 @@ -1311,7 +1311,7 @@ module_exit(ubi_exit);
33085 static int __init bytes_str_to_int(const char *str)
33086 {
33087 char *endp;
33088 - unsigned long result;
33089 + unsigned long result, scale = 1;
33090
33091 result = simple_strtoul(str, &endp, 0);
33092 if (str == endp || result >= INT_MAX) {
33093 @@ -1322,11 +1322,11 @@ static int __init bytes_str_to_int(const char *str)
33094
33095 switch (*endp) {
33096 case 'G':
33097 - result *= 1024;
33098 + scale *= 1024;
33099 case 'M':
33100 - result *= 1024;
33101 + scale *= 1024;
33102 case 'K':
33103 - result *= 1024;
33104 + scale *= 1024;
33105 if (endp[1] == 'i' && endp[2] == 'B')
33106 endp += 2;
33107 case '\0':
33108 @@ -1337,7 +1337,13 @@ static int __init bytes_str_to_int(const char *str)
33109 return -EINVAL;
33110 }
33111
33112 - return result;
33113 + if ((intoverflow_t)result*scale >= INT_MAX) {
33114 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
33115 + str);
33116 + return -EINVAL;
33117 + }
33118 +
33119 + return result*scale;
33120 }
33121
33122 /**
33123 diff --git a/drivers/net/atlx/atl2.c b/drivers/net/atlx/atl2.c
33124 index d4f7dda..d627d46 100644
33125 --- a/drivers/net/atlx/atl2.c
33126 +++ b/drivers/net/atlx/atl2.c
33127 @@ -2857,7 +2857,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
33128 */
33129
33130 #define ATL2_PARAM(X, desc) \
33131 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
33132 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
33133 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
33134 MODULE_PARM_DESC(X, desc);
33135 #else
33136 diff --git a/drivers/net/bna/bfa_ioc_ct.c b/drivers/net/bna/bfa_ioc_ct.c
33137 index 87aecdf..ec23470 100644
33138 --- a/drivers/net/bna/bfa_ioc_ct.c
33139 +++ b/drivers/net/bna/bfa_ioc_ct.c
33140 @@ -48,7 +48,21 @@ static void bfa_ioc_ct_sync_ack(struct bfa_ioc *ioc);
33141 static bool bfa_ioc_ct_sync_complete(struct bfa_ioc *ioc);
33142 static enum bfa_status bfa_ioc_ct_pll_init(void __iomem *rb, bool fcmode);
33143
33144 -static struct bfa_ioc_hwif nw_hwif_ct;
33145 +static struct bfa_ioc_hwif nw_hwif_ct = {
33146 + .ioc_pll_init = bfa_ioc_ct_pll_init,
33147 + .ioc_firmware_lock = bfa_ioc_ct_firmware_lock,
33148 + .ioc_firmware_unlock = bfa_ioc_ct_firmware_unlock,
33149 + .ioc_reg_init = bfa_ioc_ct_reg_init,
33150 + .ioc_map_port = bfa_ioc_ct_map_port,
33151 + .ioc_isr_mode_set = bfa_ioc_ct_isr_mode_set,
33152 + .ioc_notify_fail = bfa_ioc_ct_notify_fail,
33153 + .ioc_ownership_reset = bfa_ioc_ct_ownership_reset,
33154 + .ioc_sync_start = bfa_ioc_ct_sync_start,
33155 + .ioc_sync_join = bfa_ioc_ct_sync_join,
33156 + .ioc_sync_leave = bfa_ioc_ct_sync_leave,
33157 + .ioc_sync_ack = bfa_ioc_ct_sync_ack,
33158 + .ioc_sync_complete = bfa_ioc_ct_sync_complete
33159 +};
33160
33161 /**
33162 * Called from bfa_ioc_attach() to map asic specific calls.
33163 @@ -56,20 +70,6 @@ static struct bfa_ioc_hwif nw_hwif_ct;
33164 void
33165 bfa_nw_ioc_set_ct_hwif(struct bfa_ioc *ioc)
33166 {
33167 - nw_hwif_ct.ioc_pll_init = bfa_ioc_ct_pll_init;
33168 - nw_hwif_ct.ioc_firmware_lock = bfa_ioc_ct_firmware_lock;
33169 - nw_hwif_ct.ioc_firmware_unlock = bfa_ioc_ct_firmware_unlock;
33170 - nw_hwif_ct.ioc_reg_init = bfa_ioc_ct_reg_init;
33171 - nw_hwif_ct.ioc_map_port = bfa_ioc_ct_map_port;
33172 - nw_hwif_ct.ioc_isr_mode_set = bfa_ioc_ct_isr_mode_set;
33173 - nw_hwif_ct.ioc_notify_fail = bfa_ioc_ct_notify_fail;
33174 - nw_hwif_ct.ioc_ownership_reset = bfa_ioc_ct_ownership_reset;
33175 - nw_hwif_ct.ioc_sync_start = bfa_ioc_ct_sync_start;
33176 - nw_hwif_ct.ioc_sync_join = bfa_ioc_ct_sync_join;
33177 - nw_hwif_ct.ioc_sync_leave = bfa_ioc_ct_sync_leave;
33178 - nw_hwif_ct.ioc_sync_ack = bfa_ioc_ct_sync_ack;
33179 - nw_hwif_ct.ioc_sync_complete = bfa_ioc_ct_sync_complete;
33180 -
33181 ioc->ioc_hwif = &nw_hwif_ct;
33182 }
33183
33184 diff --git a/drivers/net/bna/bnad.c b/drivers/net/bna/bnad.c
33185 index 8e35b25..c39f205 100644
33186 --- a/drivers/net/bna/bnad.c
33187 +++ b/drivers/net/bna/bnad.c
33188 @@ -1673,7 +1673,14 @@ bnad_setup_tx(struct bnad *bnad, uint tx_id)
33189 struct bna_intr_info *intr_info =
33190 &res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info;
33191 struct bna_tx_config *tx_config = &bnad->tx_config[tx_id];
33192 - struct bna_tx_event_cbfn tx_cbfn;
33193 + static struct bna_tx_event_cbfn tx_cbfn = {
33194 + /* Initialize the tx event handlers */
33195 + .tcb_setup_cbfn = bnad_cb_tcb_setup,
33196 + .tcb_destroy_cbfn = bnad_cb_tcb_destroy,
33197 + .tx_stall_cbfn = bnad_cb_tx_stall,
33198 + .tx_resume_cbfn = bnad_cb_tx_resume,
33199 + .tx_cleanup_cbfn = bnad_cb_tx_cleanup
33200 + };
33201 struct bna_tx *tx;
33202 unsigned long flags;
33203
33204 @@ -1682,13 +1689,6 @@ bnad_setup_tx(struct bnad *bnad, uint tx_id)
33205 tx_config->txq_depth = bnad->txq_depth;
33206 tx_config->tx_type = BNA_TX_T_REGULAR;
33207
33208 - /* Initialize the tx event handlers */
33209 - tx_cbfn.tcb_setup_cbfn = bnad_cb_tcb_setup;
33210 - tx_cbfn.tcb_destroy_cbfn = bnad_cb_tcb_destroy;
33211 - tx_cbfn.tx_stall_cbfn = bnad_cb_tx_stall;
33212 - tx_cbfn.tx_resume_cbfn = bnad_cb_tx_resume;
33213 - tx_cbfn.tx_cleanup_cbfn = bnad_cb_tx_cleanup;
33214 -
33215 /* Get BNA's resource requirement for one tx object */
33216 spin_lock_irqsave(&bnad->bna_lock, flags);
33217 bna_tx_res_req(bnad->num_txq_per_tx,
33218 @@ -1819,21 +1819,21 @@ bnad_setup_rx(struct bnad *bnad, uint rx_id)
33219 struct bna_intr_info *intr_info =
33220 &res_info[BNA_RX_RES_T_INTR].res_u.intr_info;
33221 struct bna_rx_config *rx_config = &bnad->rx_config[rx_id];
33222 - struct bna_rx_event_cbfn rx_cbfn;
33223 + static struct bna_rx_event_cbfn rx_cbfn = {
33224 + /* Initialize the Rx event handlers */
33225 + .rcb_setup_cbfn = bnad_cb_rcb_setup,
33226 + .rcb_destroy_cbfn = bnad_cb_rcb_destroy,
33227 + .ccb_setup_cbfn = bnad_cb_ccb_setup,
33228 + .ccb_destroy_cbfn = bnad_cb_ccb_destroy,
33229 + .rx_cleanup_cbfn = bnad_cb_rx_cleanup,
33230 + .rx_post_cbfn = bnad_cb_rx_post
33231 + };
33232 struct bna_rx *rx;
33233 unsigned long flags;
33234
33235 /* Initialize the Rx object configuration */
33236 bnad_init_rx_config(bnad, rx_config);
33237
33238 - /* Initialize the Rx event handlers */
33239 - rx_cbfn.rcb_setup_cbfn = bnad_cb_rcb_setup;
33240 - rx_cbfn.rcb_destroy_cbfn = bnad_cb_rcb_destroy;
33241 - rx_cbfn.ccb_setup_cbfn = bnad_cb_ccb_setup;
33242 - rx_cbfn.ccb_destroy_cbfn = bnad_cb_ccb_destroy;
33243 - rx_cbfn.rx_cleanup_cbfn = bnad_cb_rx_cleanup;
33244 - rx_cbfn.rx_post_cbfn = bnad_cb_rx_post;
33245 -
33246 /* Get BNA's resource requirement for one Rx object */
33247 spin_lock_irqsave(&bnad->bna_lock, flags);
33248 bna_rx_res_req(rx_config, res_info);
33249 diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
33250 index 4b2b570..31033f4 100644
33251 --- a/drivers/net/bnx2.c
33252 +++ b/drivers/net/bnx2.c
33253 @@ -5877,6 +5877,8 @@ bnx2_test_nvram(struct bnx2 *bp)
33254 int rc = 0;
33255 u32 magic, csum;
33256
33257 + pax_track_stack();
33258 +
33259 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
33260 goto test_nvram_done;
33261
33262 diff --git a/drivers/net/bnx2x/bnx2x_ethtool.c b/drivers/net/bnx2x/bnx2x_ethtool.c
33263 index cf3e479..5dc0ecc 100644
33264 --- a/drivers/net/bnx2x/bnx2x_ethtool.c
33265 +++ b/drivers/net/bnx2x/bnx2x_ethtool.c
33266 @@ -1943,6 +1943,8 @@ static int bnx2x_test_nvram(struct bnx2x *bp)
33267 int i, rc;
33268 u32 magic, crc;
33269
33270 + pax_track_stack();
33271 +
33272 if (BP_NOMCP(bp))
33273 return 0;
33274
33275 diff --git a/drivers/net/bnx2x/bnx2x_sp.h b/drivers/net/bnx2x/bnx2x_sp.h
33276 index 9a517c2..a50cfcb 100644
33277 --- a/drivers/net/bnx2x/bnx2x_sp.h
33278 +++ b/drivers/net/bnx2x/bnx2x_sp.h
33279 @@ -449,7 +449,7 @@ struct bnx2x_rx_mode_obj {
33280
33281 int (*wait_comp)(struct bnx2x *bp,
33282 struct bnx2x_rx_mode_ramrod_params *p);
33283 -};
33284 +} __no_const;
33285
33286 /********************** Set multicast group ***********************************/
33287
33288 diff --git a/drivers/net/cxgb3/l2t.h b/drivers/net/cxgb3/l2t.h
33289 index c5f5479..2e8c260 100644
33290 --- a/drivers/net/cxgb3/l2t.h
33291 +++ b/drivers/net/cxgb3/l2t.h
33292 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
33293 */
33294 struct l2t_skb_cb {
33295 arp_failure_handler_func arp_failure_handler;
33296 -};
33297 +} __no_const;
33298
33299 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
33300
33301 diff --git a/drivers/net/cxgb4/cxgb4_main.c b/drivers/net/cxgb4/cxgb4_main.c
33302 index b4efa29..c5f2703 100644
33303 --- a/drivers/net/cxgb4/cxgb4_main.c
33304 +++ b/drivers/net/cxgb4/cxgb4_main.c
33305 @@ -3396,6 +3396,8 @@ static int __devinit enable_msix(struct adapter *adap)
33306 unsigned int nchan = adap->params.nports;
33307 struct msix_entry entries[MAX_INGQ + 1];
33308
33309 + pax_track_stack();
33310 +
33311 for (i = 0; i < ARRAY_SIZE(entries); ++i)
33312 entries[i].entry = i;
33313
33314 diff --git a/drivers/net/cxgb4/t4_hw.c b/drivers/net/cxgb4/t4_hw.c
33315 index d1ec111..12735bc 100644
33316 --- a/drivers/net/cxgb4/t4_hw.c
33317 +++ b/drivers/net/cxgb4/t4_hw.c
33318 @@ -362,6 +362,8 @@ static int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
33319 u8 vpd[VPD_LEN], csum;
33320 unsigned int vpdr_len, kw_offset, id_len;
33321
33322 + pax_track_stack();
33323 +
33324 ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(vpd), vpd);
33325 if (ret < 0)
33326 return ret;
33327 diff --git a/drivers/net/e1000e/82571.c b/drivers/net/e1000e/82571.c
33328 index 536b3a5..e6f8dcc 100644
33329 --- a/drivers/net/e1000e/82571.c
33330 +++ b/drivers/net/e1000e/82571.c
33331 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
33332 {
33333 struct e1000_hw *hw = &adapter->hw;
33334 struct e1000_mac_info *mac = &hw->mac;
33335 - struct e1000_mac_operations *func = &mac->ops;
33336 + e1000_mac_operations_no_const *func = &mac->ops;
33337 u32 swsm = 0;
33338 u32 swsm2 = 0;
33339 bool force_clear_smbi = false;
33340 diff --git a/drivers/net/e1000e/es2lan.c b/drivers/net/e1000e/es2lan.c
33341 index e4f4225..24da2ea 100644
33342 --- a/drivers/net/e1000e/es2lan.c
33343 +++ b/drivers/net/e1000e/es2lan.c
33344 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
33345 {
33346 struct e1000_hw *hw = &adapter->hw;
33347 struct e1000_mac_info *mac = &hw->mac;
33348 - struct e1000_mac_operations *func = &mac->ops;
33349 + e1000_mac_operations_no_const *func = &mac->ops;
33350
33351 /* Set media type */
33352 switch (adapter->pdev->device) {
33353 diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
33354 index 2967039..ca8c40c 100644
33355 --- a/drivers/net/e1000e/hw.h
33356 +++ b/drivers/net/e1000e/hw.h
33357 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
33358 void (*write_vfta)(struct e1000_hw *, u32, u32);
33359 s32 (*read_mac_addr)(struct e1000_hw *);
33360 };
33361 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
33362
33363 /*
33364 * When to use various PHY register access functions:
33365 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
33366 void (*power_up)(struct e1000_hw *);
33367 void (*power_down)(struct e1000_hw *);
33368 };
33369 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
33370
33371 /* Function pointers for the NVM. */
33372 struct e1000_nvm_operations {
33373 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
33374 s32 (*validate)(struct e1000_hw *);
33375 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
33376 };
33377 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
33378
33379 struct e1000_mac_info {
33380 - struct e1000_mac_operations ops;
33381 + e1000_mac_operations_no_const ops;
33382 u8 addr[ETH_ALEN];
33383 u8 perm_addr[ETH_ALEN];
33384
33385 @@ -872,7 +875,7 @@ struct e1000_mac_info {
33386 };
33387
33388 struct e1000_phy_info {
33389 - struct e1000_phy_operations ops;
33390 + e1000_phy_operations_no_const ops;
33391
33392 enum e1000_phy_type type;
33393
33394 @@ -906,7 +909,7 @@ struct e1000_phy_info {
33395 };
33396
33397 struct e1000_nvm_info {
33398 - struct e1000_nvm_operations ops;
33399 + e1000_nvm_operations_no_const ops;
33400
33401 enum e1000_nvm_type type;
33402 enum e1000_nvm_override override;
33403 diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
33404 index fa8677c..196356f 100644
33405 --- a/drivers/net/fealnx.c
33406 +++ b/drivers/net/fealnx.c
33407 @@ -150,7 +150,7 @@ struct chip_info {
33408 int flags;
33409 };
33410
33411 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
33412 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
33413 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
33414 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
33415 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
33416 diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
33417 index 2a5a34d..be871cc 100644
33418 --- a/drivers/net/hamradio/6pack.c
33419 +++ b/drivers/net/hamradio/6pack.c
33420 @@ -463,6 +463,8 @@ static void sixpack_receive_buf(struct tty_struct *tty,
33421 unsigned char buf[512];
33422 int count1;
33423
33424 + pax_track_stack();
33425 +
33426 if (!count)
33427 return;
33428
33429 diff --git a/drivers/net/igb/e1000_hw.h b/drivers/net/igb/e1000_hw.h
33430 index 4519a13..f97fcd0 100644
33431 --- a/drivers/net/igb/e1000_hw.h
33432 +++ b/drivers/net/igb/e1000_hw.h
33433 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
33434 s32 (*read_mac_addr)(struct e1000_hw *);
33435 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
33436 };
33437 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
33438
33439 struct e1000_phy_operations {
33440 s32 (*acquire)(struct e1000_hw *);
33441 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
33442 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
33443 s32 (*write_reg)(struct e1000_hw *, u32, u16);
33444 };
33445 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
33446
33447 struct e1000_nvm_operations {
33448 s32 (*acquire)(struct e1000_hw *);
33449 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
33450 s32 (*update)(struct e1000_hw *);
33451 s32 (*validate)(struct e1000_hw *);
33452 };
33453 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
33454
33455 struct e1000_info {
33456 s32 (*get_invariants)(struct e1000_hw *);
33457 @@ -350,7 +353,7 @@ struct e1000_info {
33458 extern const struct e1000_info e1000_82575_info;
33459
33460 struct e1000_mac_info {
33461 - struct e1000_mac_operations ops;
33462 + e1000_mac_operations_no_const ops;
33463
33464 u8 addr[6];
33465 u8 perm_addr[6];
33466 @@ -388,7 +391,7 @@ struct e1000_mac_info {
33467 };
33468
33469 struct e1000_phy_info {
33470 - struct e1000_phy_operations ops;
33471 + e1000_phy_operations_no_const ops;
33472
33473 enum e1000_phy_type type;
33474
33475 @@ -423,7 +426,7 @@ struct e1000_phy_info {
33476 };
33477
33478 struct e1000_nvm_info {
33479 - struct e1000_nvm_operations ops;
33480 + e1000_nvm_operations_no_const ops;
33481 enum e1000_nvm_type type;
33482 enum e1000_nvm_override override;
33483
33484 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
33485 s32 (*check_for_ack)(struct e1000_hw *, u16);
33486 s32 (*check_for_rst)(struct e1000_hw *, u16);
33487 };
33488 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
33489
33490 struct e1000_mbx_stats {
33491 u32 msgs_tx;
33492 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
33493 };
33494
33495 struct e1000_mbx_info {
33496 - struct e1000_mbx_operations ops;
33497 + e1000_mbx_operations_no_const ops;
33498 struct e1000_mbx_stats stats;
33499 u32 timeout;
33500 u32 usec_delay;
33501 diff --git a/drivers/net/igbvf/vf.h b/drivers/net/igbvf/vf.h
33502 index d7ed58f..64cde36 100644
33503 --- a/drivers/net/igbvf/vf.h
33504 +++ b/drivers/net/igbvf/vf.h
33505 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
33506 s32 (*read_mac_addr)(struct e1000_hw *);
33507 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
33508 };
33509 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
33510
33511 struct e1000_mac_info {
33512 - struct e1000_mac_operations ops;
33513 + e1000_mac_operations_no_const ops;
33514 u8 addr[6];
33515 u8 perm_addr[6];
33516
33517 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
33518 s32 (*check_for_ack)(struct e1000_hw *);
33519 s32 (*check_for_rst)(struct e1000_hw *);
33520 };
33521 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
33522
33523 struct e1000_mbx_stats {
33524 u32 msgs_tx;
33525 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
33526 };
33527
33528 struct e1000_mbx_info {
33529 - struct e1000_mbx_operations ops;
33530 + e1000_mbx_operations_no_const ops;
33531 struct e1000_mbx_stats stats;
33532 u32 timeout;
33533 u32 usec_delay;
33534 diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
33535 index 6a130eb..1aeb9e4 100644
33536 --- a/drivers/net/ixgb/ixgb_main.c
33537 +++ b/drivers/net/ixgb/ixgb_main.c
33538 @@ -1070,6 +1070,8 @@ ixgb_set_multi(struct net_device *netdev)
33539 u32 rctl;
33540 int i;
33541
33542 + pax_track_stack();
33543 +
33544 /* Check for Promiscuous and All Multicast modes */
33545
33546 rctl = IXGB_READ_REG(hw, RCTL);
33547 diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
33548 index dd7fbeb..44b9bbf 100644
33549 --- a/drivers/net/ixgb/ixgb_param.c
33550 +++ b/drivers/net/ixgb/ixgb_param.c
33551 @@ -261,6 +261,9 @@ void __devinit
33552 ixgb_check_options(struct ixgb_adapter *adapter)
33553 {
33554 int bd = adapter->bd_number;
33555 +
33556 + pax_track_stack();
33557 +
33558 if (bd >= IXGB_MAX_NIC) {
33559 pr_notice("Warning: no configuration for board #%i\n", bd);
33560 pr_notice("Using defaults for all values\n");
33561 diff --git a/drivers/net/ixgbe/ixgbe_type.h b/drivers/net/ixgbe/ixgbe_type.h
33562 index e0d970e..1cfdea5 100644
33563 --- a/drivers/net/ixgbe/ixgbe_type.h
33564 +++ b/drivers/net/ixgbe/ixgbe_type.h
33565 @@ -2642,6 +2642,7 @@ struct ixgbe_eeprom_operations {
33566 s32 (*update_checksum)(struct ixgbe_hw *);
33567 u16 (*calc_checksum)(struct ixgbe_hw *);
33568 };
33569 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
33570
33571 struct ixgbe_mac_operations {
33572 s32 (*init_hw)(struct ixgbe_hw *);
33573 @@ -2703,6 +2704,7 @@ struct ixgbe_mac_operations {
33574 /* Manageability interface */
33575 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
33576 };
33577 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
33578
33579 struct ixgbe_phy_operations {
33580 s32 (*identify)(struct ixgbe_hw *);
33581 @@ -2722,9 +2724,10 @@ struct ixgbe_phy_operations {
33582 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
33583 s32 (*check_overtemp)(struct ixgbe_hw *);
33584 };
33585 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
33586
33587 struct ixgbe_eeprom_info {
33588 - struct ixgbe_eeprom_operations ops;
33589 + ixgbe_eeprom_operations_no_const ops;
33590 enum ixgbe_eeprom_type type;
33591 u32 semaphore_delay;
33592 u16 word_size;
33593 @@ -2734,7 +2737,7 @@ struct ixgbe_eeprom_info {
33594
33595 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
33596 struct ixgbe_mac_info {
33597 - struct ixgbe_mac_operations ops;
33598 + ixgbe_mac_operations_no_const ops;
33599 enum ixgbe_mac_type type;
33600 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
33601 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
33602 @@ -2762,7 +2765,7 @@ struct ixgbe_mac_info {
33603 };
33604
33605 struct ixgbe_phy_info {
33606 - struct ixgbe_phy_operations ops;
33607 + ixgbe_phy_operations_no_const ops;
33608 struct mdio_if_info mdio;
33609 enum ixgbe_phy_type type;
33610 u32 id;
33611 @@ -2790,6 +2793,7 @@ struct ixgbe_mbx_operations {
33612 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
33613 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
33614 };
33615 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
33616
33617 struct ixgbe_mbx_stats {
33618 u32 msgs_tx;
33619 @@ -2801,7 +2805,7 @@ struct ixgbe_mbx_stats {
33620 };
33621
33622 struct ixgbe_mbx_info {
33623 - struct ixgbe_mbx_operations ops;
33624 + ixgbe_mbx_operations_no_const ops;
33625 struct ixgbe_mbx_stats stats;
33626 u32 timeout;
33627 u32 usec_delay;
33628 diff --git a/drivers/net/ixgbevf/vf.h b/drivers/net/ixgbevf/vf.h
33629 index 10306b4..28df758 100644
33630 --- a/drivers/net/ixgbevf/vf.h
33631 +++ b/drivers/net/ixgbevf/vf.h
33632 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
33633 s32 (*clear_vfta)(struct ixgbe_hw *);
33634 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
33635 };
33636 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
33637
33638 enum ixgbe_mac_type {
33639 ixgbe_mac_unknown = 0,
33640 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
33641 };
33642
33643 struct ixgbe_mac_info {
33644 - struct ixgbe_mac_operations ops;
33645 + ixgbe_mac_operations_no_const ops;
33646 u8 addr[6];
33647 u8 perm_addr[6];
33648
33649 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
33650 s32 (*check_for_ack)(struct ixgbe_hw *);
33651 s32 (*check_for_rst)(struct ixgbe_hw *);
33652 };
33653 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
33654
33655 struct ixgbe_mbx_stats {
33656 u32 msgs_tx;
33657 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
33658 };
33659
33660 struct ixgbe_mbx_info {
33661 - struct ixgbe_mbx_operations ops;
33662 + ixgbe_mbx_operations_no_const ops;
33663 struct ixgbe_mbx_stats stats;
33664 u32 timeout;
33665 u32 udelay;
33666 diff --git a/drivers/net/ksz884x.c b/drivers/net/ksz884x.c
33667 index 27418d3..adf15bb 100644
33668 --- a/drivers/net/ksz884x.c
33669 +++ b/drivers/net/ksz884x.c
33670 @@ -6533,6 +6533,8 @@ static void netdev_get_ethtool_stats(struct net_device *dev,
33671 int rc;
33672 u64 counter[TOTAL_PORT_COUNTER_NUM];
33673
33674 + pax_track_stack();
33675 +
33676 mutex_lock(&hw_priv->lock);
33677 n = SWITCH_PORT_NUM;
33678 for (i = 0, p = port->first_port; i < port->mib_port_cnt; i++, p++) {
33679 diff --git a/drivers/net/mlx4/main.c b/drivers/net/mlx4/main.c
33680 index f0ee35d..3831c8a 100644
33681 --- a/drivers/net/mlx4/main.c
33682 +++ b/drivers/net/mlx4/main.c
33683 @@ -40,6 +40,7 @@
33684 #include <linux/dma-mapping.h>
33685 #include <linux/slab.h>
33686 #include <linux/io-mapping.h>
33687 +#include <linux/sched.h>
33688
33689 #include <linux/mlx4/device.h>
33690 #include <linux/mlx4/doorbell.h>
33691 @@ -762,6 +763,8 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
33692 u64 icm_size;
33693 int err;
33694
33695 + pax_track_stack();
33696 +
33697 err = mlx4_QUERY_FW(dev);
33698 if (err) {
33699 if (err == -EACCES)
33700 diff --git a/drivers/net/niu.c b/drivers/net/niu.c
33701 index ed47585..5e5be8f 100644
33702 --- a/drivers/net/niu.c
33703 +++ b/drivers/net/niu.c
33704 @@ -9061,6 +9061,8 @@ static void __devinit niu_try_msix(struct niu *np, u8 *ldg_num_map)
33705 int i, num_irqs, err;
33706 u8 first_ldg;
33707
33708 + pax_track_stack();
33709 +
33710 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
33711 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
33712 ldg_num_map[i] = first_ldg + i;
33713 diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
33714 index 80b6f36..5cd8938 100644
33715 --- a/drivers/net/pcnet32.c
33716 +++ b/drivers/net/pcnet32.c
33717 @@ -270,7 +270,7 @@ struct pcnet32_private {
33718 struct sk_buff **rx_skbuff;
33719 dma_addr_t *tx_dma_addr;
33720 dma_addr_t *rx_dma_addr;
33721 - struct pcnet32_access a;
33722 + struct pcnet32_access *a;
33723 spinlock_t lock; /* Guard lock */
33724 unsigned int cur_rx, cur_tx; /* The next free ring entry */
33725 unsigned int rx_ring_size; /* current rx ring size */
33726 @@ -460,9 +460,9 @@ static void pcnet32_netif_start(struct net_device *dev)
33727 u16 val;
33728
33729 netif_wake_queue(dev);
33730 - val = lp->a.read_csr(ioaddr, CSR3);
33731 + val = lp->a->read_csr(ioaddr, CSR3);
33732 val &= 0x00ff;
33733 - lp->a.write_csr(ioaddr, CSR3, val);
33734 + lp->a->write_csr(ioaddr, CSR3, val);
33735 napi_enable(&lp->napi);
33736 }
33737
33738 @@ -730,7 +730,7 @@ static u32 pcnet32_get_link(struct net_device *dev)
33739 r = mii_link_ok(&lp->mii_if);
33740 } else if (lp->chip_version >= PCNET32_79C970A) {
33741 ulong ioaddr = dev->base_addr; /* card base I/O address */
33742 - r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
33743 + r = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
33744 } else { /* can not detect link on really old chips */
33745 r = 1;
33746 }
33747 @@ -792,7 +792,7 @@ static int pcnet32_set_ringparam(struct net_device *dev,
33748 pcnet32_netif_stop(dev);
33749
33750 spin_lock_irqsave(&lp->lock, flags);
33751 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
33752 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
33753
33754 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
33755
33756 @@ -868,7 +868,7 @@ static void pcnet32_ethtool_test(struct net_device *dev,
33757 static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
33758 {
33759 struct pcnet32_private *lp = netdev_priv(dev);
33760 - struct pcnet32_access *a = &lp->a; /* access to registers */
33761 + struct pcnet32_access *a = lp->a; /* access to registers */
33762 ulong ioaddr = dev->base_addr; /* card base I/O address */
33763 struct sk_buff *skb; /* sk buff */
33764 int x, i; /* counters */
33765 @@ -888,21 +888,21 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
33766 pcnet32_netif_stop(dev);
33767
33768 spin_lock_irqsave(&lp->lock, flags);
33769 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
33770 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
33771
33772 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
33773
33774 /* Reset the PCNET32 */
33775 - lp->a.reset(ioaddr);
33776 - lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
33777 + lp->a->reset(ioaddr);
33778 + lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
33779
33780 /* switch pcnet32 to 32bit mode */
33781 - lp->a.write_bcr(ioaddr, 20, 2);
33782 + lp->a->write_bcr(ioaddr, 20, 2);
33783
33784 /* purge & init rings but don't actually restart */
33785 pcnet32_restart(dev, 0x0000);
33786
33787 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
33788 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
33789
33790 /* Initialize Transmit buffers. */
33791 size = data_len + 15;
33792 @@ -947,10 +947,10 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
33793
33794 /* set int loopback in CSR15 */
33795 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
33796 - lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
33797 + lp->a->write_csr(ioaddr, CSR15, x | 0x0044);
33798
33799 teststatus = cpu_to_le16(0x8000);
33800 - lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
33801 + lp->a->write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
33802
33803 /* Check status of descriptors */
33804 for (x = 0; x < numbuffs; x++) {
33805 @@ -969,7 +969,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
33806 }
33807 }
33808
33809 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
33810 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
33811 wmb();
33812 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
33813 netdev_printk(KERN_DEBUG, dev, "RX loopback packets:\n");
33814 @@ -1015,7 +1015,7 @@ clean_up:
33815 pcnet32_restart(dev, CSR0_NORMAL);
33816 } else {
33817 pcnet32_purge_rx_ring(dev);
33818 - lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
33819 + lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
33820 }
33821 spin_unlock_irqrestore(&lp->lock, flags);
33822
33823 @@ -1026,7 +1026,7 @@ static int pcnet32_set_phys_id(struct net_device *dev,
33824 enum ethtool_phys_id_state state)
33825 {
33826 struct pcnet32_private *lp = netdev_priv(dev);
33827 - struct pcnet32_access *a = &lp->a;
33828 + struct pcnet32_access *a = lp->a;
33829 ulong ioaddr = dev->base_addr;
33830 unsigned long flags;
33831 int i;
33832 @@ -1067,7 +1067,7 @@ static int pcnet32_suspend(struct net_device *dev, unsigned long *flags,
33833 {
33834 int csr5;
33835 struct pcnet32_private *lp = netdev_priv(dev);
33836 - struct pcnet32_access *a = &lp->a;
33837 + struct pcnet32_access *a = lp->a;
33838 ulong ioaddr = dev->base_addr;
33839 int ticks;
33840
33841 @@ -1324,8 +1324,8 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
33842 spin_lock_irqsave(&lp->lock, flags);
33843 if (pcnet32_tx(dev)) {
33844 /* reset the chip to clear the error condition, then restart */
33845 - lp->a.reset(ioaddr);
33846 - lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
33847 + lp->a->reset(ioaddr);
33848 + lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
33849 pcnet32_restart(dev, CSR0_START);
33850 netif_wake_queue(dev);
33851 }
33852 @@ -1337,12 +1337,12 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
33853 __napi_complete(napi);
33854
33855 /* clear interrupt masks */
33856 - val = lp->a.read_csr(ioaddr, CSR3);
33857 + val = lp->a->read_csr(ioaddr, CSR3);
33858 val &= 0x00ff;
33859 - lp->a.write_csr(ioaddr, CSR3, val);
33860 + lp->a->write_csr(ioaddr, CSR3, val);
33861
33862 /* Set interrupt enable. */
33863 - lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
33864 + lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN);
33865
33866 spin_unlock_irqrestore(&lp->lock, flags);
33867 }
33868 @@ -1365,7 +1365,7 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
33869 int i, csr0;
33870 u16 *buff = ptr;
33871 struct pcnet32_private *lp = netdev_priv(dev);
33872 - struct pcnet32_access *a = &lp->a;
33873 + struct pcnet32_access *a = lp->a;
33874 ulong ioaddr = dev->base_addr;
33875 unsigned long flags;
33876
33877 @@ -1401,9 +1401,9 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
33878 for (j = 0; j < PCNET32_MAX_PHYS; j++) {
33879 if (lp->phymask & (1 << j)) {
33880 for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
33881 - lp->a.write_bcr(ioaddr, 33,
33882 + lp->a->write_bcr(ioaddr, 33,
33883 (j << 5) | i);
33884 - *buff++ = lp->a.read_bcr(ioaddr, 34);
33885 + *buff++ = lp->a->read_bcr(ioaddr, 34);
33886 }
33887 }
33888 }
33889 @@ -1785,7 +1785,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
33890 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
33891 lp->options |= PCNET32_PORT_FD;
33892
33893 - lp->a = *a;
33894 + lp->a = a;
33895
33896 /* prior to register_netdev, dev->name is not yet correct */
33897 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
33898 @@ -1844,7 +1844,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
33899 if (lp->mii) {
33900 /* lp->phycount and lp->phymask are set to 0 by memset above */
33901
33902 - lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
33903 + lp->mii_if.phy_id = ((lp->a->read_bcr(ioaddr, 33)) >> 5) & 0x1f;
33904 /* scan for PHYs */
33905 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
33906 unsigned short id1, id2;
33907 @@ -1864,7 +1864,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
33908 pr_info("Found PHY %04x:%04x at address %d\n",
33909 id1, id2, i);
33910 }
33911 - lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
33912 + lp->a->write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
33913 if (lp->phycount > 1)
33914 lp->options |= PCNET32_PORT_MII;
33915 }
33916 @@ -2020,10 +2020,10 @@ static int pcnet32_open(struct net_device *dev)
33917 }
33918
33919 /* Reset the PCNET32 */
33920 - lp->a.reset(ioaddr);
33921 + lp->a->reset(ioaddr);
33922
33923 /* switch pcnet32 to 32bit mode */
33924 - lp->a.write_bcr(ioaddr, 20, 2);
33925 + lp->a->write_bcr(ioaddr, 20, 2);
33926
33927 netif_printk(lp, ifup, KERN_DEBUG, dev,
33928 "%s() irq %d tx/rx rings %#x/%#x init %#x\n",
33929 @@ -2032,14 +2032,14 @@ static int pcnet32_open(struct net_device *dev)
33930 (u32) (lp->init_dma_addr));
33931
33932 /* set/reset autoselect bit */
33933 - val = lp->a.read_bcr(ioaddr, 2) & ~2;
33934 + val = lp->a->read_bcr(ioaddr, 2) & ~2;
33935 if (lp->options & PCNET32_PORT_ASEL)
33936 val |= 2;
33937 - lp->a.write_bcr(ioaddr, 2, val);
33938 + lp->a->write_bcr(ioaddr, 2, val);
33939
33940 /* handle full duplex setting */
33941 if (lp->mii_if.full_duplex) {
33942 - val = lp->a.read_bcr(ioaddr, 9) & ~3;
33943 + val = lp->a->read_bcr(ioaddr, 9) & ~3;
33944 if (lp->options & PCNET32_PORT_FD) {
33945 val |= 1;
33946 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
33947 @@ -2049,14 +2049,14 @@ static int pcnet32_open(struct net_device *dev)
33948 if (lp->chip_version == 0x2627)
33949 val |= 3;
33950 }
33951 - lp->a.write_bcr(ioaddr, 9, val);
33952 + lp->a->write_bcr(ioaddr, 9, val);
33953 }
33954
33955 /* set/reset GPSI bit in test register */
33956 - val = lp->a.read_csr(ioaddr, 124) & ~0x10;
33957 + val = lp->a->read_csr(ioaddr, 124) & ~0x10;
33958 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
33959 val |= 0x10;
33960 - lp->a.write_csr(ioaddr, 124, val);
33961 + lp->a->write_csr(ioaddr, 124, val);
33962
33963 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
33964 if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT &&
33965 @@ -2075,24 +2075,24 @@ static int pcnet32_open(struct net_device *dev)
33966 * duplex, and/or enable auto negotiation, and clear DANAS
33967 */
33968 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
33969 - lp->a.write_bcr(ioaddr, 32,
33970 - lp->a.read_bcr(ioaddr, 32) | 0x0080);
33971 + lp->a->write_bcr(ioaddr, 32,
33972 + lp->a->read_bcr(ioaddr, 32) | 0x0080);
33973 /* disable Auto Negotiation, set 10Mpbs, HD */
33974 - val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
33975 + val = lp->a->read_bcr(ioaddr, 32) & ~0xb8;
33976 if (lp->options & PCNET32_PORT_FD)
33977 val |= 0x10;
33978 if (lp->options & PCNET32_PORT_100)
33979 val |= 0x08;
33980 - lp->a.write_bcr(ioaddr, 32, val);
33981 + lp->a->write_bcr(ioaddr, 32, val);
33982 } else {
33983 if (lp->options & PCNET32_PORT_ASEL) {
33984 - lp->a.write_bcr(ioaddr, 32,
33985 - lp->a.read_bcr(ioaddr,
33986 + lp->a->write_bcr(ioaddr, 32,
33987 + lp->a->read_bcr(ioaddr,
33988 32) | 0x0080);
33989 /* enable auto negotiate, setup, disable fd */
33990 - val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
33991 + val = lp->a->read_bcr(ioaddr, 32) & ~0x98;
33992 val |= 0x20;
33993 - lp->a.write_bcr(ioaddr, 32, val);
33994 + lp->a->write_bcr(ioaddr, 32, val);
33995 }
33996 }
33997 } else {
33998 @@ -2105,10 +2105,10 @@ static int pcnet32_open(struct net_device *dev)
33999 * There is really no good other way to handle multiple PHYs
34000 * other than turning off all automatics
34001 */
34002 - val = lp->a.read_bcr(ioaddr, 2);
34003 - lp->a.write_bcr(ioaddr, 2, val & ~2);
34004 - val = lp->a.read_bcr(ioaddr, 32);
34005 - lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
34006 + val = lp->a->read_bcr(ioaddr, 2);
34007 + lp->a->write_bcr(ioaddr, 2, val & ~2);
34008 + val = lp->a->read_bcr(ioaddr, 32);
34009 + lp->a->write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
34010
34011 if (!(lp->options & PCNET32_PORT_ASEL)) {
34012 /* setup ecmd */
34013 @@ -2118,7 +2118,7 @@ static int pcnet32_open(struct net_device *dev)
34014 ethtool_cmd_speed_set(&ecmd,
34015 (lp->options & PCNET32_PORT_100) ?
34016 SPEED_100 : SPEED_10);
34017 - bcr9 = lp->a.read_bcr(ioaddr, 9);
34018 + bcr9 = lp->a->read_bcr(ioaddr, 9);
34019
34020 if (lp->options & PCNET32_PORT_FD) {
34021 ecmd.duplex = DUPLEX_FULL;
34022 @@ -2127,7 +2127,7 @@ static int pcnet32_open(struct net_device *dev)
34023 ecmd.duplex = DUPLEX_HALF;
34024 bcr9 |= ~(1 << 0);
34025 }
34026 - lp->a.write_bcr(ioaddr, 9, bcr9);
34027 + lp->a->write_bcr(ioaddr, 9, bcr9);
34028 }
34029
34030 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
34031 @@ -2158,9 +2158,9 @@ static int pcnet32_open(struct net_device *dev)
34032
34033 #ifdef DO_DXSUFLO
34034 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
34035 - val = lp->a.read_csr(ioaddr, CSR3);
34036 + val = lp->a->read_csr(ioaddr, CSR3);
34037 val |= 0x40;
34038 - lp->a.write_csr(ioaddr, CSR3, val);
34039 + lp->a->write_csr(ioaddr, CSR3, val);
34040 }
34041 #endif
34042
34043 @@ -2176,11 +2176,11 @@ static int pcnet32_open(struct net_device *dev)
34044 napi_enable(&lp->napi);
34045
34046 /* Re-initialize the PCNET32, and start it when done. */
34047 - lp->a.write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
34048 - lp->a.write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
34049 + lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
34050 + lp->a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
34051
34052 - lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
34053 - lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
34054 + lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
34055 + lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
34056
34057 netif_start_queue(dev);
34058
34059 @@ -2192,19 +2192,19 @@ static int pcnet32_open(struct net_device *dev)
34060
34061 i = 0;
34062 while (i++ < 100)
34063 - if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
34064 + if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
34065 break;
34066 /*
34067 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
34068 * reports that doing so triggers a bug in the '974.
34069 */
34070 - lp->a.write_csr(ioaddr, CSR0, CSR0_NORMAL);
34071 + lp->a->write_csr(ioaddr, CSR0, CSR0_NORMAL);
34072
34073 netif_printk(lp, ifup, KERN_DEBUG, dev,
34074 "pcnet32 open after %d ticks, init block %#x csr0 %4.4x\n",
34075 i,
34076 (u32) (lp->init_dma_addr),
34077 - lp->a.read_csr(ioaddr, CSR0));
34078 + lp->a->read_csr(ioaddr, CSR0));
34079
34080 spin_unlock_irqrestore(&lp->lock, flags);
34081
34082 @@ -2218,7 +2218,7 @@ err_free_ring:
34083 * Switch back to 16bit mode to avoid problems with dumb
34084 * DOS packet driver after a warm reboot
34085 */
34086 - lp->a.write_bcr(ioaddr, 20, 4);
34087 + lp->a->write_bcr(ioaddr, 20, 4);
34088
34089 err_free_irq:
34090 spin_unlock_irqrestore(&lp->lock, flags);
34091 @@ -2323,7 +2323,7 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
34092
34093 /* wait for stop */
34094 for (i = 0; i < 100; i++)
34095 - if (lp->a.read_csr(ioaddr, CSR0) & CSR0_STOP)
34096 + if (lp->a->read_csr(ioaddr, CSR0) & CSR0_STOP)
34097 break;
34098
34099 if (i >= 100)
34100 @@ -2335,13 +2335,13 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
34101 return;
34102
34103 /* ReInit Ring */
34104 - lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
34105 + lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
34106 i = 0;
34107 while (i++ < 1000)
34108 - if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
34109 + if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
34110 break;
34111
34112 - lp->a.write_csr(ioaddr, CSR0, csr0_bits);
34113 + lp->a->write_csr(ioaddr, CSR0, csr0_bits);
34114 }
34115
34116 static void pcnet32_tx_timeout(struct net_device *dev)
34117 @@ -2353,8 +2353,8 @@ static void pcnet32_tx_timeout(struct net_device *dev)
34118 /* Transmitter timeout, serious problems. */
34119 if (pcnet32_debug & NETIF_MSG_DRV)
34120 pr_err("%s: transmit timed out, status %4.4x, resetting\n",
34121 - dev->name, lp->a.read_csr(ioaddr, CSR0));
34122 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
34123 + dev->name, lp->a->read_csr(ioaddr, CSR0));
34124 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
34125 dev->stats.tx_errors++;
34126 if (netif_msg_tx_err(lp)) {
34127 int i;
34128 @@ -2397,7 +2397,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
34129
34130 netif_printk(lp, tx_queued, KERN_DEBUG, dev,
34131 "%s() called, csr0 %4.4x\n",
34132 - __func__, lp->a.read_csr(ioaddr, CSR0));
34133 + __func__, lp->a->read_csr(ioaddr, CSR0));
34134
34135 /* Default status -- will not enable Successful-TxDone
34136 * interrupt when that option is available to us.
34137 @@ -2427,7 +2427,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
34138 dev->stats.tx_bytes += skb->len;
34139
34140 /* Trigger an immediate send poll. */
34141 - lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
34142 + lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
34143
34144 if (lp->tx_ring[(entry + 1) & lp->tx_mod_mask].base != 0) {
34145 lp->tx_full = 1;
34146 @@ -2452,16 +2452,16 @@ pcnet32_interrupt(int irq, void *dev_id)
34147
34148 spin_lock(&lp->lock);
34149
34150 - csr0 = lp->a.read_csr(ioaddr, CSR0);
34151 + csr0 = lp->a->read_csr(ioaddr, CSR0);
34152 while ((csr0 & 0x8f00) && --boguscnt >= 0) {
34153 if (csr0 == 0xffff)
34154 break; /* PCMCIA remove happened */
34155 /* Acknowledge all of the current interrupt sources ASAP. */
34156 - lp->a.write_csr(ioaddr, CSR0, csr0 & ~0x004f);
34157 + lp->a->write_csr(ioaddr, CSR0, csr0 & ~0x004f);
34158
34159 netif_printk(lp, intr, KERN_DEBUG, dev,
34160 "interrupt csr0=%#2.2x new csr=%#2.2x\n",
34161 - csr0, lp->a.read_csr(ioaddr, CSR0));
34162 + csr0, lp->a->read_csr(ioaddr, CSR0));
34163
34164 /* Log misc errors. */
34165 if (csr0 & 0x4000)
34166 @@ -2488,19 +2488,19 @@ pcnet32_interrupt(int irq, void *dev_id)
34167 if (napi_schedule_prep(&lp->napi)) {
34168 u16 val;
34169 /* set interrupt masks */
34170 - val = lp->a.read_csr(ioaddr, CSR3);
34171 + val = lp->a->read_csr(ioaddr, CSR3);
34172 val |= 0x5f00;
34173 - lp->a.write_csr(ioaddr, CSR3, val);
34174 + lp->a->write_csr(ioaddr, CSR3, val);
34175
34176 __napi_schedule(&lp->napi);
34177 break;
34178 }
34179 - csr0 = lp->a.read_csr(ioaddr, CSR0);
34180 + csr0 = lp->a->read_csr(ioaddr, CSR0);
34181 }
34182
34183 netif_printk(lp, intr, KERN_DEBUG, dev,
34184 "exiting interrupt, csr0=%#4.4x\n",
34185 - lp->a.read_csr(ioaddr, CSR0));
34186 + lp->a->read_csr(ioaddr, CSR0));
34187
34188 spin_unlock(&lp->lock);
34189
34190 @@ -2520,20 +2520,20 @@ static int pcnet32_close(struct net_device *dev)
34191
34192 spin_lock_irqsave(&lp->lock, flags);
34193
34194 - dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
34195 + dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
34196
34197 netif_printk(lp, ifdown, KERN_DEBUG, dev,
34198 "Shutting down ethercard, status was %2.2x\n",
34199 - lp->a.read_csr(ioaddr, CSR0));
34200 + lp->a->read_csr(ioaddr, CSR0));
34201
34202 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
34203 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
34204 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
34205
34206 /*
34207 * Switch back to 16bit mode to avoid problems with dumb
34208 * DOS packet driver after a warm reboot
34209 */
34210 - lp->a.write_bcr(ioaddr, 20, 4);
34211 + lp->a->write_bcr(ioaddr, 20, 4);
34212
34213 spin_unlock_irqrestore(&lp->lock, flags);
34214
34215 @@ -2556,7 +2556,7 @@ static struct net_device_stats *pcnet32_get_stats(struct net_device *dev)
34216 unsigned long flags;
34217
34218 spin_lock_irqsave(&lp->lock, flags);
34219 - dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
34220 + dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
34221 spin_unlock_irqrestore(&lp->lock, flags);
34222
34223 return &dev->stats;
34224 @@ -2577,10 +2577,10 @@ static void pcnet32_load_multicast(struct net_device *dev)
34225 if (dev->flags & IFF_ALLMULTI) {
34226 ib->filter[0] = cpu_to_le32(~0U);
34227 ib->filter[1] = cpu_to_le32(~0U);
34228 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
34229 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
34230 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
34231 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
34232 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
34233 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
34234 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
34235 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
34236 return;
34237 }
34238 /* clear the multicast filter */
34239 @@ -2594,7 +2594,7 @@ static void pcnet32_load_multicast(struct net_device *dev)
34240 mcast_table[crc >> 4] |= cpu_to_le16(1 << (crc & 0xf));
34241 }
34242 for (i = 0; i < 4; i++)
34243 - lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
34244 + lp->a->write_csr(ioaddr, PCNET32_MC_FILTER + i,
34245 le16_to_cpu(mcast_table[i]));
34246 }
34247
34248 @@ -2609,28 +2609,28 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
34249
34250 spin_lock_irqsave(&lp->lock, flags);
34251 suspended = pcnet32_suspend(dev, &flags, 0);
34252 - csr15 = lp->a.read_csr(ioaddr, CSR15);
34253 + csr15 = lp->a->read_csr(ioaddr, CSR15);
34254 if (dev->flags & IFF_PROMISC) {
34255 /* Log any net taps. */
34256 netif_info(lp, hw, dev, "Promiscuous mode enabled\n");
34257 lp->init_block->mode =
34258 cpu_to_le16(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
34259 7);
34260 - lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
34261 + lp->a->write_csr(ioaddr, CSR15, csr15 | 0x8000);
34262 } else {
34263 lp->init_block->mode =
34264 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7);
34265 - lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
34266 + lp->a->write_csr(ioaddr, CSR15, csr15 & 0x7fff);
34267 pcnet32_load_multicast(dev);
34268 }
34269
34270 if (suspended) {
34271 int csr5;
34272 /* clear SUSPEND (SPND) - CSR5 bit 0 */
34273 - csr5 = lp->a.read_csr(ioaddr, CSR5);
34274 - lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
34275 + csr5 = lp->a->read_csr(ioaddr, CSR5);
34276 + lp->a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
34277 } else {
34278 - lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
34279 + lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
34280 pcnet32_restart(dev, CSR0_NORMAL);
34281 netif_wake_queue(dev);
34282 }
34283 @@ -2648,8 +2648,8 @@ static int mdio_read(struct net_device *dev, int phy_id, int reg_num)
34284 if (!lp->mii)
34285 return 0;
34286
34287 - lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
34288 - val_out = lp->a.read_bcr(ioaddr, 34);
34289 + lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
34290 + val_out = lp->a->read_bcr(ioaddr, 34);
34291
34292 return val_out;
34293 }
34294 @@ -2663,8 +2663,8 @@ static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val)
34295 if (!lp->mii)
34296 return;
34297
34298 - lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
34299 - lp->a.write_bcr(ioaddr, 34, val);
34300 + lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
34301 + lp->a->write_bcr(ioaddr, 34, val);
34302 }
34303
34304 static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34305 @@ -2741,7 +2741,7 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
34306 curr_link = mii_link_ok(&lp->mii_if);
34307 } else {
34308 ulong ioaddr = dev->base_addr; /* card base I/O address */
34309 - curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
34310 + curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
34311 }
34312 if (!curr_link) {
34313 if (prev_link || verbose) {
34314 @@ -2764,13 +2764,13 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
34315 (ecmd.duplex == DUPLEX_FULL)
34316 ? "full" : "half");
34317 }
34318 - bcr9 = lp->a.read_bcr(dev->base_addr, 9);
34319 + bcr9 = lp->a->read_bcr(dev->base_addr, 9);
34320 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
34321 if (lp->mii_if.full_duplex)
34322 bcr9 |= (1 << 0);
34323 else
34324 bcr9 &= ~(1 << 0);
34325 - lp->a.write_bcr(dev->base_addr, 9, bcr9);
34326 + lp->a->write_bcr(dev->base_addr, 9, bcr9);
34327 }
34328 } else {
34329 netif_info(lp, link, dev, "link up\n");
34330 diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
34331 index edfa15d..002bfa9 100644
34332 --- a/drivers/net/ppp_generic.c
34333 +++ b/drivers/net/ppp_generic.c
34334 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34335 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
34336 struct ppp_stats stats;
34337 struct ppp_comp_stats cstats;
34338 - char *vers;
34339
34340 switch (cmd) {
34341 case SIOCGPPPSTATS:
34342 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34343 break;
34344
34345 case SIOCGPPPVER:
34346 - vers = PPP_VERSION;
34347 - if (copy_to_user(addr, vers, strlen(vers) + 1))
34348 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
34349 break;
34350 err = 0;
34351 break;
34352 diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
34353 index 6d657ca..d1be94b 100644
34354 --- a/drivers/net/r8169.c
34355 +++ b/drivers/net/r8169.c
34356 @@ -663,12 +663,12 @@ struct rtl8169_private {
34357 struct mdio_ops {
34358 void (*write)(void __iomem *, int, int);
34359 int (*read)(void __iomem *, int);
34360 - } mdio_ops;
34361 + } __no_const mdio_ops;
34362
34363 struct pll_power_ops {
34364 void (*down)(struct rtl8169_private *);
34365 void (*up)(struct rtl8169_private *);
34366 - } pll_power_ops;
34367 + } __no_const pll_power_ops;
34368
34369 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
34370 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
34371 diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
34372 index 3c0f131..17f8b02 100644
34373 --- a/drivers/net/sis190.c
34374 +++ b/drivers/net/sis190.c
34375 @@ -1624,7 +1624,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
34376 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
34377 struct net_device *dev)
34378 {
34379 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
34380 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
34381 struct sis190_private *tp = netdev_priv(dev);
34382 struct pci_dev *isa_bridge;
34383 u8 reg, tmp8;
34384 diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
34385 index 4793df8..44c9849 100644
34386 --- a/drivers/net/sundance.c
34387 +++ b/drivers/net/sundance.c
34388 @@ -218,7 +218,7 @@ enum {
34389 struct pci_id_info {
34390 const char *name;
34391 };
34392 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34393 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34394 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34395 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34396 {"D-Link DFE-580TX 4 port Server Adapter"},
34397 diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
34398 index 2ea456d..3ad9523 100644
34399 --- a/drivers/net/tg3.h
34400 +++ b/drivers/net/tg3.h
34401 @@ -134,6 +134,7 @@
34402 #define CHIPREV_ID_5750_A0 0x4000
34403 #define CHIPREV_ID_5750_A1 0x4001
34404 #define CHIPREV_ID_5750_A3 0x4003
34405 +#define CHIPREV_ID_5750_C1 0x4201
34406 #define CHIPREV_ID_5750_C2 0x4202
34407 #define CHIPREV_ID_5752_A0_HW 0x5000
34408 #define CHIPREV_ID_5752_A0 0x6000
34409 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
34410 index 515f122..41dd273 100644
34411 --- a/drivers/net/tokenring/abyss.c
34412 +++ b/drivers/net/tokenring/abyss.c
34413 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
34414
34415 static int __init abyss_init (void)
34416 {
34417 - abyss_netdev_ops = tms380tr_netdev_ops;
34418 + pax_open_kernel();
34419 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34420
34421 - abyss_netdev_ops.ndo_open = abyss_open;
34422 - abyss_netdev_ops.ndo_stop = abyss_close;
34423 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
34424 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
34425 + pax_close_kernel();
34426
34427 return pci_register_driver(&abyss_driver);
34428 }
34429 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
34430 index 6153cfd..cf69c1c 100644
34431 --- a/drivers/net/tokenring/madgemc.c
34432 +++ b/drivers/net/tokenring/madgemc.c
34433 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
34434
34435 static int __init madgemc_init (void)
34436 {
34437 - madgemc_netdev_ops = tms380tr_netdev_ops;
34438 - madgemc_netdev_ops.ndo_open = madgemc_open;
34439 - madgemc_netdev_ops.ndo_stop = madgemc_close;
34440 + pax_open_kernel();
34441 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34442 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
34443 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
34444 + pax_close_kernel();
34445
34446 return mca_register_driver (&madgemc_driver);
34447 }
34448 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
34449 index 8d362e6..f91cc52 100644
34450 --- a/drivers/net/tokenring/proteon.c
34451 +++ b/drivers/net/tokenring/proteon.c
34452 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
34453 struct platform_device *pdev;
34454 int i, num = 0, err = 0;
34455
34456 - proteon_netdev_ops = tms380tr_netdev_ops;
34457 - proteon_netdev_ops.ndo_open = proteon_open;
34458 - proteon_netdev_ops.ndo_stop = tms380tr_close;
34459 + pax_open_kernel();
34460 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34461 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
34462 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
34463 + pax_close_kernel();
34464
34465 err = platform_driver_register(&proteon_driver);
34466 if (err)
34467 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
34468 index 46db5c5..37c1536 100644
34469 --- a/drivers/net/tokenring/skisa.c
34470 +++ b/drivers/net/tokenring/skisa.c
34471 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
34472 struct platform_device *pdev;
34473 int i, num = 0, err = 0;
34474
34475 - sk_isa_netdev_ops = tms380tr_netdev_ops;
34476 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
34477 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34478 + pax_open_kernel();
34479 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34480 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
34481 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34482 + pax_close_kernel();
34483
34484 err = platform_driver_register(&sk_isa_driver);
34485 if (err)
34486 diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
34487 index ce90efc..2676f89 100644
34488 --- a/drivers/net/tulip/de2104x.c
34489 +++ b/drivers/net/tulip/de2104x.c
34490 @@ -1795,6 +1795,8 @@ static void __devinit de21041_get_srom_info (struct de_private *de)
34491 struct de_srom_info_leaf *il;
34492 void *bufp;
34493
34494 + pax_track_stack();
34495 +
34496 /* download entire eeprom */
34497 for (i = 0; i < DE_EEPROM_WORDS; i++)
34498 ((__le16 *)ee_data)[i] =
34499 diff --git a/drivers/net/tulip/de4x5.c b/drivers/net/tulip/de4x5.c
34500 index 959b410..c97fac2 100644
34501 --- a/drivers/net/tulip/de4x5.c
34502 +++ b/drivers/net/tulip/de4x5.c
34503 @@ -5397,7 +5397,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34504 for (i=0; i<ETH_ALEN; i++) {
34505 tmp.addr[i] = dev->dev_addr[i];
34506 }
34507 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34508 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34509 break;
34510
34511 case DE4X5_SET_HWADDR: /* Set the hardware address */
34512 @@ -5437,7 +5437,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34513 spin_lock_irqsave(&lp->lock, flags);
34514 memcpy(&statbuf, &lp->pktStats, ioc->len);
34515 spin_unlock_irqrestore(&lp->lock, flags);
34516 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34517 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34518 return -EFAULT;
34519 break;
34520 }
34521 diff --git a/drivers/net/tulip/eeprom.c b/drivers/net/tulip/eeprom.c
34522 index fa5eee9..e074432 100644
34523 --- a/drivers/net/tulip/eeprom.c
34524 +++ b/drivers/net/tulip/eeprom.c
34525 @@ -81,7 +81,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34526 {NULL}};
34527
34528
34529 -static const char *block_name[] __devinitdata = {
34530 +static const char *block_name[] __devinitconst = {
34531 "21140 non-MII",
34532 "21140 MII PHY",
34533 "21142 Serial PHY",
34534 diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
34535 index 862eadf..3eee1e6 100644
34536 --- a/drivers/net/tulip/winbond-840.c
34537 +++ b/drivers/net/tulip/winbond-840.c
34538 @@ -236,7 +236,7 @@ struct pci_id_info {
34539 int drv_flags; /* Driver use, intended as capability flags. */
34540 };
34541
34542 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34543 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34544 { /* Sometime a Level-One switch card. */
34545 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34546 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34547 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
34548 index 304fe78..db112fa 100644
34549 --- a/drivers/net/usb/hso.c
34550 +++ b/drivers/net/usb/hso.c
34551 @@ -71,7 +71,7 @@
34552 #include <asm/byteorder.h>
34553 #include <linux/serial_core.h>
34554 #include <linux/serial.h>
34555 -
34556 +#include <asm/local.h>
34557
34558 #define MOD_AUTHOR "Option Wireless"
34559 #define MOD_DESCRIPTION "USB High Speed Option driver"
34560 @@ -257,7 +257,7 @@ struct hso_serial {
34561
34562 /* from usb_serial_port */
34563 struct tty_struct *tty;
34564 - int open_count;
34565 + local_t open_count;
34566 spinlock_t serial_lock;
34567
34568 int (*write_data) (struct hso_serial *serial);
34569 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
34570 struct urb *urb;
34571
34572 urb = serial->rx_urb[0];
34573 - if (serial->open_count > 0) {
34574 + if (local_read(&serial->open_count) > 0) {
34575 count = put_rxbuf_data(urb, serial);
34576 if (count == -1)
34577 return;
34578 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
34579 DUMP1(urb->transfer_buffer, urb->actual_length);
34580
34581 /* Anyone listening? */
34582 - if (serial->open_count == 0)
34583 + if (local_read(&serial->open_count) == 0)
34584 return;
34585
34586 if (status == 0) {
34587 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
34588 spin_unlock_irq(&serial->serial_lock);
34589
34590 /* check for port already opened, if not set the termios */
34591 - serial->open_count++;
34592 - if (serial->open_count == 1) {
34593 + if (local_inc_return(&serial->open_count) == 1) {
34594 serial->rx_state = RX_IDLE;
34595 /* Force default termio settings */
34596 _hso_serial_set_termios(tty, NULL);
34597 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
34598 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
34599 if (result) {
34600 hso_stop_serial_device(serial->parent);
34601 - serial->open_count--;
34602 + local_dec(&serial->open_count);
34603 kref_put(&serial->parent->ref, hso_serial_ref_free);
34604 }
34605 } else {
34606 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
34607
34608 /* reset the rts and dtr */
34609 /* do the actual close */
34610 - serial->open_count--;
34611 + local_dec(&serial->open_count);
34612
34613 - if (serial->open_count <= 0) {
34614 - serial->open_count = 0;
34615 + if (local_read(&serial->open_count) <= 0) {
34616 + local_set(&serial->open_count, 0);
34617 spin_lock_irq(&serial->serial_lock);
34618 if (serial->tty == tty) {
34619 serial->tty->driver_data = NULL;
34620 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
34621
34622 /* the actual setup */
34623 spin_lock_irqsave(&serial->serial_lock, flags);
34624 - if (serial->open_count)
34625 + if (local_read(&serial->open_count))
34626 _hso_serial_set_termios(tty, old);
34627 else
34628 tty->termios = old;
34629 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
34630 D1("Pending read interrupt on port %d\n", i);
34631 spin_lock(&serial->serial_lock);
34632 if (serial->rx_state == RX_IDLE &&
34633 - serial->open_count > 0) {
34634 + local_read(&serial->open_count) > 0) {
34635 /* Setup and send a ctrl req read on
34636 * port i */
34637 if (!serial->rx_urb_filled[0]) {
34638 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
34639 /* Start all serial ports */
34640 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
34641 if (serial_table[i] && (serial_table[i]->interface == iface)) {
34642 - if (dev2ser(serial_table[i])->open_count) {
34643 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
34644 result =
34645 hso_start_serial_device(serial_table[i], GFP_NOIO);
34646 hso_kick_transmit(dev2ser(serial_table[i]));
34647 diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
34648 index 27400ed..c796e05 100644
34649 --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
34650 +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
34651 @@ -601,8 +601,7 @@ vmxnet3_set_rss_indir(struct net_device *netdev,
34652 * Return with error code if any of the queue indices
34653 * is out of range
34654 */
34655 - if (p->ring_index[i] < 0 ||
34656 - p->ring_index[i] >= adapter->num_rx_queues)
34657 + if (p->ring_index[i] >= adapter->num_rx_queues)
34658 return -EINVAL;
34659 }
34660
34661 diff --git a/drivers/net/vxge/vxge-config.h b/drivers/net/vxge/vxge-config.h
34662 index dd36258..e47fd31 100644
34663 --- a/drivers/net/vxge/vxge-config.h
34664 +++ b/drivers/net/vxge/vxge-config.h
34665 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34666 void (*link_down)(struct __vxge_hw_device *devh);
34667 void (*crit_err)(struct __vxge_hw_device *devh,
34668 enum vxge_hw_event type, u64 ext_data);
34669 -};
34670 +} __no_const;
34671
34672 /*
34673 * struct __vxge_hw_blockpool_entry - Block private data structure
34674 diff --git a/drivers/net/vxge/vxge-main.c b/drivers/net/vxge/vxge-main.c
34675 index 178348a2..18bb433 100644
34676 --- a/drivers/net/vxge/vxge-main.c
34677 +++ b/drivers/net/vxge/vxge-main.c
34678 @@ -100,6 +100,8 @@ static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
34679 struct sk_buff *completed[NR_SKB_COMPLETED];
34680 int more;
34681
34682 + pax_track_stack();
34683 +
34684 do {
34685 more = 0;
34686 skb_ptr = completed;
34687 @@ -1915,6 +1917,8 @@ static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
34688 u8 mtable[256] = {0}; /* CPU to vpath mapping */
34689 int index;
34690
34691 + pax_track_stack();
34692 +
34693 /*
34694 * Filling
34695 * - itable with bucket numbers
34696 diff --git a/drivers/net/vxge/vxge-traffic.h b/drivers/net/vxge/vxge-traffic.h
34697 index 4a518a3..936b334 100644
34698 --- a/drivers/net/vxge/vxge-traffic.h
34699 +++ b/drivers/net/vxge/vxge-traffic.h
34700 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34701 struct vxge_hw_mempool_dma *dma_object,
34702 u32 index,
34703 u32 is_last);
34704 -};
34705 +} __no_const;
34706
34707 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34708 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34709 diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c
34710 index 56aeb01..547f71f 100644
34711 --- a/drivers/net/wan/hdlc_x25.c
34712 +++ b/drivers/net/wan/hdlc_x25.c
34713 @@ -134,16 +134,16 @@ static netdev_tx_t x25_xmit(struct sk_buff *skb, struct net_device *dev)
34714
34715 static int x25_open(struct net_device *dev)
34716 {
34717 - struct lapb_register_struct cb;
34718 + static struct lapb_register_struct cb = {
34719 + .connect_confirmation = x25_connected,
34720 + .connect_indication = x25_connected,
34721 + .disconnect_confirmation = x25_disconnected,
34722 + .disconnect_indication = x25_disconnected,
34723 + .data_indication = x25_data_indication,
34724 + .data_transmit = x25_data_transmit
34725 + };
34726 int result;
34727
34728 - cb.connect_confirmation = x25_connected;
34729 - cb.connect_indication = x25_connected;
34730 - cb.disconnect_confirmation = x25_disconnected;
34731 - cb.disconnect_indication = x25_disconnected;
34732 - cb.data_indication = x25_data_indication;
34733 - cb.data_transmit = x25_data_transmit;
34734 -
34735 result = lapb_register(dev, &cb);
34736 if (result != LAPB_OK)
34737 return result;
34738 diff --git a/drivers/net/wimax/i2400m/usb-fw.c b/drivers/net/wimax/i2400m/usb-fw.c
34739 index 1fda46c..f2858f2 100644
34740 --- a/drivers/net/wimax/i2400m/usb-fw.c
34741 +++ b/drivers/net/wimax/i2400m/usb-fw.c
34742 @@ -287,6 +287,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(struct i2400m *i2400m,
34743 int do_autopm = 1;
34744 DECLARE_COMPLETION_ONSTACK(notif_completion);
34745
34746 + pax_track_stack();
34747 +
34748 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
34749 i2400m, ack, ack_size);
34750 BUG_ON(_ack == i2400m->bm_ack_buf);
34751 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
34752 index e1b3e3c..e413f18 100644
34753 --- a/drivers/net/wireless/airo.c
34754 +++ b/drivers/net/wireless/airo.c
34755 @@ -3003,6 +3003,8 @@ static void airo_process_scan_results (struct airo_info *ai) {
34756 BSSListElement * loop_net;
34757 BSSListElement * tmp_net;
34758
34759 + pax_track_stack();
34760 +
34761 /* Blow away current list of scan results */
34762 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
34763 list_move_tail (&loop_net->list, &ai->network_free_list);
34764 @@ -3794,6 +3796,8 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
34765 WepKeyRid wkr;
34766 int rc;
34767
34768 + pax_track_stack();
34769 +
34770 memset( &mySsid, 0, sizeof( mySsid ) );
34771 kfree (ai->flash);
34772 ai->flash = NULL;
34773 @@ -4753,6 +4757,8 @@ static int proc_stats_rid_open( struct inode *inode,
34774 __le32 *vals = stats.vals;
34775 int len;
34776
34777 + pax_track_stack();
34778 +
34779 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
34780 return -ENOMEM;
34781 data = file->private_data;
34782 @@ -5476,6 +5482,8 @@ static int proc_BSSList_open( struct inode *inode, struct file *file ) {
34783 /* If doLoseSync is not 1, we won't do a Lose Sync */
34784 int doLoseSync = -1;
34785
34786 + pax_track_stack();
34787 +
34788 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
34789 return -ENOMEM;
34790 data = file->private_data;
34791 @@ -7181,6 +7189,8 @@ static int airo_get_aplist(struct net_device *dev,
34792 int i;
34793 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
34794
34795 + pax_track_stack();
34796 +
34797 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
34798 if (!qual)
34799 return -ENOMEM;
34800 @@ -7741,6 +7751,8 @@ static void airo_read_wireless_stats(struct airo_info *local)
34801 CapabilityRid cap_rid;
34802 __le32 *vals = stats_rid.vals;
34803
34804 + pax_track_stack();
34805 +
34806 /* Get stats out of the card */
34807 clear_bit(JOB_WSTATS, &local->jobs);
34808 if (local->power.event) {
34809 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
34810 index 17c4b56..00d836f 100644
34811 --- a/drivers/net/wireless/ath/ath.h
34812 +++ b/drivers/net/wireless/ath/ath.h
34813 @@ -121,6 +121,7 @@ struct ath_ops {
34814 void (*write_flush) (void *);
34815 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
34816 };
34817 +typedef struct ath_ops __no_const ath_ops_no_const;
34818
34819 struct ath_common;
34820 struct ath_bus_ops;
34821 diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
34822 index ccca724..7afbadc 100644
34823 --- a/drivers/net/wireless/ath/ath5k/debug.c
34824 +++ b/drivers/net/wireless/ath/ath5k/debug.c
34825 @@ -203,6 +203,8 @@ static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
34826 unsigned int v;
34827 u64 tsf;
34828
34829 + pax_track_stack();
34830 +
34831 v = ath5k_hw_reg_read(ah, AR5K_BEACON);
34832 len += snprintf(buf + len, sizeof(buf) - len,
34833 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
34834 @@ -321,6 +323,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
34835 unsigned int len = 0;
34836 unsigned int i;
34837
34838 + pax_track_stack();
34839 +
34840 len += snprintf(buf + len, sizeof(buf) - len,
34841 "DEBUG LEVEL: 0x%08x\n\n", ah->debug.level);
34842
34843 @@ -492,6 +496,8 @@ static ssize_t read_file_misc(struct file *file, char __user *user_buf,
34844 unsigned int len = 0;
34845 u32 filt = ath5k_hw_get_rx_filter(ah);
34846
34847 + pax_track_stack();
34848 +
34849 len += snprintf(buf + len, sizeof(buf) - len, "bssid-mask: %pM\n",
34850 ah->bssidmask);
34851 len += snprintf(buf + len, sizeof(buf) - len, "filter-flags: 0x%x ",
34852 @@ -548,6 +554,8 @@ static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
34853 unsigned int len = 0;
34854 int i;
34855
34856 + pax_track_stack();
34857 +
34858 len += snprintf(buf + len, sizeof(buf) - len,
34859 "RX\n---------------------\n");
34860 len += snprintf(buf + len, sizeof(buf) - len, "CRC\t%u\t(%u%%)\n",
34861 @@ -665,6 +673,8 @@ static ssize_t read_file_ani(struct file *file, char __user *user_buf,
34862 char buf[700];
34863 unsigned int len = 0;
34864
34865 + pax_track_stack();
34866 +
34867 len += snprintf(buf + len, sizeof(buf) - len,
34868 "HW has PHY error counters:\t%s\n",
34869 ah->ah_capabilities.cap_has_phyerr_counters ?
34870 @@ -829,6 +839,8 @@ static ssize_t read_file_queue(struct file *file, char __user *user_buf,
34871 struct ath5k_buf *bf, *bf0;
34872 int i, n;
34873
34874 + pax_track_stack();
34875 +
34876 len += snprintf(buf + len, sizeof(buf) - len,
34877 "available txbuffers: %d\n", ah->txbuf_len);
34878
34879 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
34880 index 7c2aaad..ad14dee 100644
34881 --- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
34882 +++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
34883 @@ -758,6 +758,8 @@ static void ar9003_hw_tx_iq_cal_post_proc(struct ath_hw *ah)
34884 int i, im, j;
34885 int nmeasurement;
34886
34887 + pax_track_stack();
34888 +
34889 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
34890 if (ah->txchainmask & (1 << i))
34891 num_chains++;
34892 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
34893 index f80d1d6..08b773d 100644
34894 --- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
34895 +++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
34896 @@ -406,6 +406,8 @@ static bool create_pa_curve(u32 *data_L, u32 *data_U, u32 *pa_table, u16 *gain)
34897 int theta_low_bin = 0;
34898 int i;
34899
34900 + pax_track_stack();
34901 +
34902 /* disregard any bin that contains <= 16 samples */
34903 thresh_accum_cnt = 16;
34904 scale_factor = 5;
34905 diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
34906 index d1eb896..8b67cd4 100644
34907 --- a/drivers/net/wireless/ath/ath9k/debug.c
34908 +++ b/drivers/net/wireless/ath/ath9k/debug.c
34909 @@ -387,6 +387,8 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
34910 char buf[512];
34911 unsigned int len = 0;
34912
34913 + pax_track_stack();
34914 +
34915 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
34916 len += snprintf(buf + len, sizeof(buf) - len,
34917 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
34918 @@ -477,6 +479,8 @@ static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
34919 u8 addr[ETH_ALEN];
34920 u32 tmp;
34921
34922 + pax_track_stack();
34923 +
34924 len += snprintf(buf + len, sizeof(buf) - len,
34925 "%s (chan=%d center-freq: %d MHz channel-type: %d (%s))\n",
34926 wiphy_name(sc->hw->wiphy),
34927 diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
34928 index d3ff33c..309398e 100644
34929 --- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
34930 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
34931 @@ -31,6 +31,8 @@ static ssize_t read_file_tgt_int_stats(struct file *file, char __user *user_buf,
34932 unsigned int len = 0;
34933 int ret = 0;
34934
34935 + pax_track_stack();
34936 +
34937 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
34938
34939 ath9k_htc_ps_wakeup(priv);
34940 @@ -89,6 +91,8 @@ static ssize_t read_file_tgt_tx_stats(struct file *file, char __user *user_buf,
34941 unsigned int len = 0;
34942 int ret = 0;
34943
34944 + pax_track_stack();
34945 +
34946 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
34947
34948 ath9k_htc_ps_wakeup(priv);
34949 @@ -159,6 +163,8 @@ static ssize_t read_file_tgt_rx_stats(struct file *file, char __user *user_buf,
34950 unsigned int len = 0;
34951 int ret = 0;
34952
34953 + pax_track_stack();
34954 +
34955 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
34956
34957 ath9k_htc_ps_wakeup(priv);
34958 @@ -203,6 +209,8 @@ static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
34959 char buf[512];
34960 unsigned int len = 0;
34961
34962 + pax_track_stack();
34963 +
34964 len += snprintf(buf + len, sizeof(buf) - len,
34965 "%20s : %10u\n", "Buffers queued",
34966 priv->debug.tx_stats.buf_queued);
34967 @@ -376,6 +384,8 @@ static ssize_t read_file_slot(struct file *file, char __user *user_buf,
34968 char buf[512];
34969 unsigned int len = 0;
34970
34971 + pax_track_stack();
34972 +
34973 spin_lock_bh(&priv->tx.tx_lock);
34974
34975 len += snprintf(buf + len, sizeof(buf) - len, "TX slot bitmap : ");
34976 @@ -411,6 +421,8 @@ static ssize_t read_file_queue(struct file *file, char __user *user_buf,
34977 char buf[512];
34978 unsigned int len = 0;
34979
34980 + pax_track_stack();
34981 +
34982 len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
34983 "Mgmt endpoint", skb_queue_len(&priv->tx.mgmt_ep_queue));
34984
34985 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
34986 index c798890..c19a8fb 100644
34987 --- a/drivers/net/wireless/ath/ath9k/hw.h
34988 +++ b/drivers/net/wireless/ath/ath9k/hw.h
34989 @@ -588,7 +588,7 @@ struct ath_hw_private_ops {
34990
34991 /* ANI */
34992 void (*ani_cache_ini_regs)(struct ath_hw *ah);
34993 -};
34994 +} __no_const;
34995
34996 /**
34997 * struct ath_hw_ops - callbacks used by hardware code and driver code
34998 @@ -639,7 +639,7 @@ struct ath_hw_ops {
34999 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35000 struct ath_hw_antcomb_conf *antconf);
35001
35002 -};
35003 +} __no_const;
35004
35005 struct ath_nf_limits {
35006 s16 max;
35007 @@ -652,7 +652,7 @@ struct ath_nf_limits {
35008 #define AH_UNPLUGGED 0x2 /* The card has been physically removed. */
35009
35010 struct ath_hw {
35011 - struct ath_ops reg_ops;
35012 + ath_ops_no_const reg_ops;
35013
35014 struct ieee80211_hw *hw;
35015 struct ath_common common;
35016 diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c
35017 index ef9ad79..f5f8d80 100644
35018 --- a/drivers/net/wireless/ipw2x00/ipw2100.c
35019 +++ b/drivers/net/wireless/ipw2x00/ipw2100.c
35020 @@ -2102,6 +2102,8 @@ static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
35021 int err;
35022 DECLARE_SSID_BUF(ssid);
35023
35024 + pax_track_stack();
35025 +
35026 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
35027
35028 if (ssid_len)
35029 @@ -5451,6 +5453,8 @@ static int ipw2100_set_key(struct ipw2100_priv *priv,
35030 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
35031 int err;
35032
35033 + pax_track_stack();
35034 +
35035 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
35036 idx, keylen, len);
35037
35038 diff --git a/drivers/net/wireless/ipw2x00/libipw_rx.c b/drivers/net/wireless/ipw2x00/libipw_rx.c
35039 index 32a9966..de69787 100644
35040 --- a/drivers/net/wireless/ipw2x00/libipw_rx.c
35041 +++ b/drivers/net/wireless/ipw2x00/libipw_rx.c
35042 @@ -1565,6 +1565,8 @@ static void libipw_process_probe_response(struct libipw_device
35043 unsigned long flags;
35044 DECLARE_SSID_BUF(ssid);
35045
35046 + pax_track_stack();
35047 +
35048 LIBIPW_DEBUG_SCAN("'%s' (%pM"
35049 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
35050 print_ssid(ssid, info_element->data, info_element->len),
35051 diff --git a/drivers/net/wireless/iwlegacy/iwl3945-base.c b/drivers/net/wireless/iwlegacy/iwl3945-base.c
35052 index 66ee1562..b90412b 100644
35053 --- a/drivers/net/wireless/iwlegacy/iwl3945-base.c
35054 +++ b/drivers/net/wireless/iwlegacy/iwl3945-base.c
35055 @@ -3687,7 +3687,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
35056 */
35057 if (iwl3945_mod_params.disable_hw_scan) {
35058 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
35059 - iwl3945_hw_ops.hw_scan = NULL;
35060 + pax_open_kernel();
35061 + *(void **)&iwl3945_hw_ops.hw_scan = NULL;
35062 + pax_close_kernel();
35063 }
35064
35065 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
35066 diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
35067 index 3789ff4..22ab151 100644
35068 --- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
35069 +++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
35070 @@ -920,6 +920,8 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
35071 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
35072 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
35073
35074 + pax_track_stack();
35075 +
35076 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
35077
35078 /* Treat uninitialized rate scaling data same as non-existing. */
35079 @@ -2931,6 +2933,8 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
35080 container_of(lq_sta, struct iwl_station_priv, lq_sta);
35081 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
35082
35083 + pax_track_stack();
35084 +
35085 /* Override starting rate (index 0) if needed for debug purposes */
35086 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
35087
35088 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
35089 index f9a407e..a6f2bb7 100644
35090 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
35091 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
35092 @@ -68,8 +68,8 @@ do { \
35093 } while (0)
35094
35095 #else
35096 -#define IWL_DEBUG(__priv, level, fmt, args...)
35097 -#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
35098 +#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
35099 +#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
35100 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
35101 const void *p, u32 len)
35102 {}
35103 diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
35104 index ec1485b..900c3bd 100644
35105 --- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
35106 +++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
35107 @@ -561,6 +561,8 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
35108 int pos = 0;
35109 const size_t bufsz = sizeof(buf);
35110
35111 + pax_track_stack();
35112 +
35113 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
35114 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
35115 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
35116 @@ -693,6 +695,8 @@ static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
35117 char buf[256 * NUM_IWL_RXON_CTX];
35118 const size_t bufsz = sizeof(buf);
35119
35120 + pax_track_stack();
35121 +
35122 for_each_context(priv, ctx) {
35123 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
35124 ctx->ctxid);
35125 diff --git a/drivers/net/wireless/iwmc3200wifi/debugfs.c b/drivers/net/wireless/iwmc3200wifi/debugfs.c
35126 index 0a0cc96..fd49ad8 100644
35127 --- a/drivers/net/wireless/iwmc3200wifi/debugfs.c
35128 +++ b/drivers/net/wireless/iwmc3200wifi/debugfs.c
35129 @@ -327,6 +327,8 @@ static ssize_t iwm_debugfs_fw_err_read(struct file *filp,
35130 int buf_len = 512;
35131 size_t len = 0;
35132
35133 + pax_track_stack();
35134 +
35135 if (*ppos != 0)
35136 return 0;
35137 if (count < sizeof(buf))
35138 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35139 index 031cd89..bdc8435 100644
35140 --- a/drivers/net/wireless/mac80211_hwsim.c
35141 +++ b/drivers/net/wireless/mac80211_hwsim.c
35142 @@ -1670,9 +1670,11 @@ static int __init init_mac80211_hwsim(void)
35143 return -EINVAL;
35144
35145 if (fake_hw_scan) {
35146 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35147 - mac80211_hwsim_ops.sw_scan_start = NULL;
35148 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35149 + pax_open_kernel();
35150 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35151 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35152 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35153 + pax_close_kernel();
35154 }
35155
35156 spin_lock_init(&hwsim_radio_lock);
35157 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35158 index 2215c3c..64e6a47 100644
35159 --- a/drivers/net/wireless/mwifiex/main.h
35160 +++ b/drivers/net/wireless/mwifiex/main.h
35161 @@ -560,7 +560,7 @@ struct mwifiex_if_ops {
35162
35163 void (*update_mp_end_port) (struct mwifiex_adapter *, u16);
35164 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35165 -};
35166 +} __no_const;
35167
35168 struct mwifiex_adapter {
35169 struct mwifiex_private *priv[MWIFIEX_MAX_BSS_NUM];
35170 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35171 index 29f9389..f6d2ce0 100644
35172 --- a/drivers/net/wireless/rndis_wlan.c
35173 +++ b/drivers/net/wireless/rndis_wlan.c
35174 @@ -1277,7 +1277,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35175
35176 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35177
35178 - if (rts_threshold < 0 || rts_threshold > 2347)
35179 + if (rts_threshold > 2347)
35180 rts_threshold = 2347;
35181
35182 tmp = cpu_to_le32(rts_threshold);
35183 diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
35184 index 3b11642..d6bb049 100644
35185 --- a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
35186 +++ b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
35187 @@ -837,6 +837,8 @@ bool _rtl92c_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw,
35188 u8 rfpath;
35189 u8 num_total_rfpath = rtlphy->num_total_rfpath;
35190
35191 + pax_track_stack();
35192 +
35193 precommoncmdcnt = 0;
35194 _rtl92c_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
35195 MAX_PRECMD_CNT,
35196 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35197 index a77f1bb..c608b2b 100644
35198 --- a/drivers/net/wireless/wl1251/wl1251.h
35199 +++ b/drivers/net/wireless/wl1251/wl1251.h
35200 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35201 void (*reset)(struct wl1251 *wl);
35202 void (*enable_irq)(struct wl1251 *wl);
35203 void (*disable_irq)(struct wl1251 *wl);
35204 -};
35205 +} __no_const;
35206
35207 struct wl1251 {
35208 struct ieee80211_hw *hw;
35209 diff --git a/drivers/net/wireless/wl12xx/spi.c b/drivers/net/wireless/wl12xx/spi.c
35210 index e0b3736..4b466e6 100644
35211 --- a/drivers/net/wireless/wl12xx/spi.c
35212 +++ b/drivers/net/wireless/wl12xx/spi.c
35213 @@ -281,6 +281,8 @@ static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
35214 u32 chunk_len;
35215 int i;
35216
35217 + pax_track_stack();
35218 +
35219 WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
35220
35221 spi_message_init(&m);
35222 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35223 index f34b5b2..b5abb9f 100644
35224 --- a/drivers/oprofile/buffer_sync.c
35225 +++ b/drivers/oprofile/buffer_sync.c
35226 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35227 if (cookie == NO_COOKIE)
35228 offset = pc;
35229 if (cookie == INVALID_COOKIE) {
35230 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35231 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35232 offset = pc;
35233 }
35234 if (cookie != last_cookie) {
35235 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35236 /* add userspace sample */
35237
35238 if (!mm) {
35239 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35240 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35241 return 0;
35242 }
35243
35244 cookie = lookup_dcookie(mm, s->eip, &offset);
35245
35246 if (cookie == INVALID_COOKIE) {
35247 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35248 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35249 return 0;
35250 }
35251
35252 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35253 /* ignore backtraces if failed to add a sample */
35254 if (state == sb_bt_start) {
35255 state = sb_bt_ignore;
35256 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35257 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35258 }
35259 }
35260 release_mm(mm);
35261 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35262 index dd87e86..bc0148c 100644
35263 --- a/drivers/oprofile/event_buffer.c
35264 +++ b/drivers/oprofile/event_buffer.c
35265 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35266 }
35267
35268 if (buffer_pos == buffer_size) {
35269 - atomic_inc(&oprofile_stats.event_lost_overflow);
35270 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35271 return;
35272 }
35273
35274 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35275 index f8c752e..28bf4fc 100644
35276 --- a/drivers/oprofile/oprof.c
35277 +++ b/drivers/oprofile/oprof.c
35278 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35279 if (oprofile_ops.switch_events())
35280 return;
35281
35282 - atomic_inc(&oprofile_stats.multiplex_counter);
35283 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35284 start_switch_worker();
35285 }
35286
35287 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35288 index 917d28e..d62d981 100644
35289 --- a/drivers/oprofile/oprofile_stats.c
35290 +++ b/drivers/oprofile/oprofile_stats.c
35291 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35292 cpu_buf->sample_invalid_eip = 0;
35293 }
35294
35295 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35296 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35297 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35298 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35299 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35300 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35301 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35302 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35303 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35304 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35305 }
35306
35307
35308 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35309 index 38b6fc0..b5cbfce 100644
35310 --- a/drivers/oprofile/oprofile_stats.h
35311 +++ b/drivers/oprofile/oprofile_stats.h
35312 @@ -13,11 +13,11 @@
35313 #include <linux/atomic.h>
35314
35315 struct oprofile_stat_struct {
35316 - atomic_t sample_lost_no_mm;
35317 - atomic_t sample_lost_no_mapping;
35318 - atomic_t bt_lost_no_mapping;
35319 - atomic_t event_lost_overflow;
35320 - atomic_t multiplex_counter;
35321 + atomic_unchecked_t sample_lost_no_mm;
35322 + atomic_unchecked_t sample_lost_no_mapping;
35323 + atomic_unchecked_t bt_lost_no_mapping;
35324 + atomic_unchecked_t event_lost_overflow;
35325 + atomic_unchecked_t multiplex_counter;
35326 };
35327
35328 extern struct oprofile_stat_struct oprofile_stats;
35329 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35330 index 1c0b799..c11b2d2 100644
35331 --- a/drivers/oprofile/oprofilefs.c
35332 +++ b/drivers/oprofile/oprofilefs.c
35333 @@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
35334
35335
35336 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35337 - char const *name, atomic_t *val)
35338 + char const *name, atomic_unchecked_t *val)
35339 {
35340 return __oprofilefs_create_file(sb, root, name,
35341 &atomic_ro_fops, 0444, val);
35342 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35343 index 3f56bc0..707d642 100644
35344 --- a/drivers/parport/procfs.c
35345 +++ b/drivers/parport/procfs.c
35346 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35347
35348 *ppos += len;
35349
35350 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35351 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35352 }
35353
35354 #ifdef CONFIG_PARPORT_1284
35355 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35356
35357 *ppos += len;
35358
35359 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35360 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35361 }
35362 #endif /* IEEE1284.3 support. */
35363
35364 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35365 index 9fff878..ad0ad53 100644
35366 --- a/drivers/pci/hotplug/cpci_hotplug.h
35367 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35368 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35369 int (*hardware_test) (struct slot* slot, u32 value);
35370 u8 (*get_power) (struct slot* slot);
35371 int (*set_power) (struct slot* slot, int value);
35372 -};
35373 +} __no_const;
35374
35375 struct cpci_hp_controller {
35376 unsigned int irq;
35377 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35378 index 76ba8a1..20ca857 100644
35379 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35380 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35381 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35382
35383 void compaq_nvram_init (void __iomem *rom_start)
35384 {
35385 +
35386 +#ifndef CONFIG_PAX_KERNEXEC
35387 if (rom_start) {
35388 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35389 }
35390 +#endif
35391 +
35392 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35393
35394 /* initialize our int15 lock */
35395 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35396 index cbfbab1..6a9fced 100644
35397 --- a/drivers/pci/pcie/aspm.c
35398 +++ b/drivers/pci/pcie/aspm.c
35399 @@ -27,9 +27,9 @@
35400 #define MODULE_PARAM_PREFIX "pcie_aspm."
35401
35402 /* Note: those are not register definitions */
35403 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35404 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35405 -#define ASPM_STATE_L1 (4) /* L1 state */
35406 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35407 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35408 +#define ASPM_STATE_L1 (4U) /* L1 state */
35409 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35410 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35411
35412 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35413 index 6ab6bd3..72bdc69 100644
35414 --- a/drivers/pci/probe.c
35415 +++ b/drivers/pci/probe.c
35416 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35417 u32 l, sz, mask;
35418 u16 orig_cmd;
35419
35420 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35421 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35422
35423 if (!dev->mmio_always_on) {
35424 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35425 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35426 index 27911b5..5b6db88 100644
35427 --- a/drivers/pci/proc.c
35428 +++ b/drivers/pci/proc.c
35429 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35430 static int __init pci_proc_init(void)
35431 {
35432 struct pci_dev *dev = NULL;
35433 +
35434 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
35435 +#ifdef CONFIG_GRKERNSEC_PROC_USER
35436 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35437 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35438 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35439 +#endif
35440 +#else
35441 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35442 +#endif
35443 proc_create("devices", 0, proc_bus_pci_dir,
35444 &proc_bus_pci_dev_operations);
35445 proc_initialized = 1;
35446 diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
35447 index 90832a9..419089a 100644
35448 --- a/drivers/pci/xen-pcifront.c
35449 +++ b/drivers/pci/xen-pcifront.c
35450 @@ -187,6 +187,8 @@ static int pcifront_bus_read(struct pci_bus *bus, unsigned int devfn,
35451 struct pcifront_sd *sd = bus->sysdata;
35452 struct pcifront_device *pdev = pcifront_get_pdev(sd);
35453
35454 + pax_track_stack();
35455 +
35456 if (verbose_request)
35457 dev_info(&pdev->xdev->dev,
35458 "read dev=%04x:%02x:%02x.%01x - offset %x size %d\n",
35459 @@ -226,6 +228,8 @@ static int pcifront_bus_write(struct pci_bus *bus, unsigned int devfn,
35460 struct pcifront_sd *sd = bus->sysdata;
35461 struct pcifront_device *pdev = pcifront_get_pdev(sd);
35462
35463 + pax_track_stack();
35464 +
35465 if (verbose_request)
35466 dev_info(&pdev->xdev->dev,
35467 "write dev=%04x:%02x:%02x.%01x - "
35468 @@ -258,6 +262,8 @@ static int pci_frontend_enable_msix(struct pci_dev *dev,
35469 struct pcifront_device *pdev = pcifront_get_pdev(sd);
35470 struct msi_desc *entry;
35471
35472 + pax_track_stack();
35473 +
35474 if (nvec > SH_INFO_MAX_VEC) {
35475 dev_err(&dev->dev, "too much vector for pci frontend: %x."
35476 " Increase SH_INFO_MAX_VEC.\n", nvec);
35477 @@ -309,6 +315,8 @@ static void pci_frontend_disable_msix(struct pci_dev *dev)
35478 struct pcifront_sd *sd = dev->bus->sysdata;
35479 struct pcifront_device *pdev = pcifront_get_pdev(sd);
35480
35481 + pax_track_stack();
35482 +
35483 err = do_pci_op(pdev, &op);
35484
35485 /* What should do for error ? */
35486 @@ -328,6 +336,8 @@ static int pci_frontend_enable_msi(struct pci_dev *dev, int vector[])
35487 struct pcifront_sd *sd = dev->bus->sysdata;
35488 struct pcifront_device *pdev = pcifront_get_pdev(sd);
35489
35490 + pax_track_stack();
35491 +
35492 err = do_pci_op(pdev, &op);
35493 if (likely(!err)) {
35494 vector[0] = op.value;
35495 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35496 index 7bd829f..a3237ad 100644
35497 --- a/drivers/platform/x86/thinkpad_acpi.c
35498 +++ b/drivers/platform/x86/thinkpad_acpi.c
35499 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35500 return 0;
35501 }
35502
35503 -void static hotkey_mask_warn_incomplete_mask(void)
35504 +static void hotkey_mask_warn_incomplete_mask(void)
35505 {
35506 /* log only what the user can fix... */
35507 const u32 wantedmask = hotkey_driver_mask &
35508 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35509 }
35510 }
35511
35512 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35513 - struct tp_nvram_state *newn,
35514 - const u32 event_mask)
35515 -{
35516 -
35517 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35518 do { \
35519 if ((event_mask & (1 << __scancode)) && \
35520 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35521 tpacpi_hotkey_send_key(__scancode); \
35522 } while (0)
35523
35524 - void issue_volchange(const unsigned int oldvol,
35525 - const unsigned int newvol)
35526 - {
35527 - unsigned int i = oldvol;
35528 +static void issue_volchange(const unsigned int oldvol,
35529 + const unsigned int newvol,
35530 + const u32 event_mask)
35531 +{
35532 + unsigned int i = oldvol;
35533
35534 - while (i > newvol) {
35535 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35536 - i--;
35537 - }
35538 - while (i < newvol) {
35539 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35540 - i++;
35541 - }
35542 + while (i > newvol) {
35543 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35544 + i--;
35545 }
35546 + while (i < newvol) {
35547 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35548 + i++;
35549 + }
35550 +}
35551
35552 - void issue_brightnesschange(const unsigned int oldbrt,
35553 - const unsigned int newbrt)
35554 - {
35555 - unsigned int i = oldbrt;
35556 +static void issue_brightnesschange(const unsigned int oldbrt,
35557 + const unsigned int newbrt,
35558 + const u32 event_mask)
35559 +{
35560 + unsigned int i = oldbrt;
35561
35562 - while (i > newbrt) {
35563 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35564 - i--;
35565 - }
35566 - while (i < newbrt) {
35567 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35568 - i++;
35569 - }
35570 + while (i > newbrt) {
35571 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35572 + i--;
35573 + }
35574 + while (i < newbrt) {
35575 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35576 + i++;
35577 }
35578 +}
35579
35580 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35581 + struct tp_nvram_state *newn,
35582 + const u32 event_mask)
35583 +{
35584 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35585 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35586 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35587 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35588 oldn->volume_level != newn->volume_level) {
35589 /* recently muted, or repeated mute keypress, or
35590 * multiple presses ending in mute */
35591 - issue_volchange(oldn->volume_level, newn->volume_level);
35592 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35593 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35594 }
35595 } else {
35596 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35597 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35598 }
35599 if (oldn->volume_level != newn->volume_level) {
35600 - issue_volchange(oldn->volume_level, newn->volume_level);
35601 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35602 } else if (oldn->volume_toggle != newn->volume_toggle) {
35603 /* repeated vol up/down keypress at end of scale ? */
35604 if (newn->volume_level == 0)
35605 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35606 /* handle brightness */
35607 if (oldn->brightness_level != newn->brightness_level) {
35608 issue_brightnesschange(oldn->brightness_level,
35609 - newn->brightness_level);
35610 + newn->brightness_level,
35611 + event_mask);
35612 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35613 /* repeated key presses that didn't change state */
35614 if (newn->brightness_level == 0)
35615 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35616 && !tp_features.bright_unkfw)
35617 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35618 }
35619 +}
35620
35621 #undef TPACPI_COMPARE_KEY
35622 #undef TPACPI_MAY_SEND_KEY
35623 -}
35624
35625 /*
35626 * Polling driver
35627 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35628 index b859d16..5cc6b1a 100644
35629 --- a/drivers/pnp/pnpbios/bioscalls.c
35630 +++ b/drivers/pnp/pnpbios/bioscalls.c
35631 @@ -59,7 +59,7 @@ do { \
35632 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35633 } while(0)
35634
35635 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35636 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35637 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35638
35639 /*
35640 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35641
35642 cpu = get_cpu();
35643 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35644 +
35645 + pax_open_kernel();
35646 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35647 + pax_close_kernel();
35648
35649 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35650 spin_lock_irqsave(&pnp_bios_lock, flags);
35651 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35652 :"memory");
35653 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35654
35655 + pax_open_kernel();
35656 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35657 + pax_close_kernel();
35658 +
35659 put_cpu();
35660
35661 /* If we get here and this is set then the PnP BIOS faulted on us. */
35662 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35663 return status;
35664 }
35665
35666 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
35667 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35668 {
35669 int i;
35670
35671 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35672 pnp_bios_callpoint.offset = header->fields.pm16offset;
35673 pnp_bios_callpoint.segment = PNP_CS16;
35674
35675 + pax_open_kernel();
35676 +
35677 for_each_possible_cpu(i) {
35678 struct desc_struct *gdt = get_cpu_gdt_table(i);
35679 if (!gdt)
35680 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35681 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
35682 (unsigned long)__va(header->fields.pm16dseg));
35683 }
35684 +
35685 + pax_close_kernel();
35686 }
35687 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
35688 index b0ecacb..7c9da2e 100644
35689 --- a/drivers/pnp/resource.c
35690 +++ b/drivers/pnp/resource.c
35691 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
35692 return 1;
35693
35694 /* check if the resource is valid */
35695 - if (*irq < 0 || *irq > 15)
35696 + if (*irq > 15)
35697 return 0;
35698
35699 /* check if the resource is reserved */
35700 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
35701 return 1;
35702
35703 /* check if the resource is valid */
35704 - if (*dma < 0 || *dma == 4 || *dma > 7)
35705 + if (*dma == 4 || *dma > 7)
35706 return 0;
35707
35708 /* check if the resource is reserved */
35709 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
35710 index bb16f5b..c751eef 100644
35711 --- a/drivers/power/bq27x00_battery.c
35712 +++ b/drivers/power/bq27x00_battery.c
35713 @@ -67,7 +67,7 @@
35714 struct bq27x00_device_info;
35715 struct bq27x00_access_methods {
35716 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
35717 -};
35718 +} __no_const;
35719
35720 enum bq27x00_chip { BQ27000, BQ27500 };
35721
35722 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
35723 index 33f5d9a..d957d3f 100644
35724 --- a/drivers/regulator/max8660.c
35725 +++ b/drivers/regulator/max8660.c
35726 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
35727 max8660->shadow_regs[MAX8660_OVER1] = 5;
35728 } else {
35729 /* Otherwise devices can be toggled via software */
35730 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
35731 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
35732 + pax_open_kernel();
35733 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
35734 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
35735 + pax_close_kernel();
35736 }
35737
35738 /*
35739 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
35740 index 3285d41..ab7c22a 100644
35741 --- a/drivers/regulator/mc13892-regulator.c
35742 +++ b/drivers/regulator/mc13892-regulator.c
35743 @@ -564,10 +564,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
35744 }
35745 mc13xxx_unlock(mc13892);
35746
35747 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
35748 + pax_open_kernel();
35749 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
35750 = mc13892_vcam_set_mode;
35751 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
35752 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
35753 = mc13892_vcam_get_mode;
35754 + pax_close_kernel();
35755 for (i = 0; i < pdata->num_regulators; i++) {
35756 init_data = &pdata->regulators[i];
35757 priv->regulators[i] = regulator_register(
35758 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
35759 index cace6d3..f623fda 100644
35760 --- a/drivers/rtc/rtc-dev.c
35761 +++ b/drivers/rtc/rtc-dev.c
35762 @@ -14,6 +14,7 @@
35763 #include <linux/module.h>
35764 #include <linux/rtc.h>
35765 #include <linux/sched.h>
35766 +#include <linux/grsecurity.h>
35767 #include "rtc-core.h"
35768
35769 static dev_t rtc_devt;
35770 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
35771 if (copy_from_user(&tm, uarg, sizeof(tm)))
35772 return -EFAULT;
35773
35774 + gr_log_timechange();
35775 +
35776 return rtc_set_time(rtc, &tm);
35777
35778 case RTC_PIE_ON:
35779 diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
35780 index f66c33b..7ae5823 100644
35781 --- a/drivers/scsi/BusLogic.c
35782 +++ b/drivers/scsi/BusLogic.c
35783 @@ -962,6 +962,8 @@ static int __init BusLogic_InitializeFlashPointProbeInfo(struct BusLogic_HostAda
35784 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
35785 *PrototypeHostAdapter)
35786 {
35787 + pax_track_stack();
35788 +
35789 /*
35790 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
35791 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
35792 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
35793 index ffb5878..e6d785c 100644
35794 --- a/drivers/scsi/aacraid/aacraid.h
35795 +++ b/drivers/scsi/aacraid/aacraid.h
35796 @@ -492,7 +492,7 @@ struct adapter_ops
35797 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
35798 /* Administrative operations */
35799 int (*adapter_comm)(struct aac_dev * dev, int comm);
35800 -};
35801 +} __no_const;
35802
35803 /*
35804 * Define which interrupt handler needs to be installed
35805 diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
35806 index 8a0b330..b4286de 100644
35807 --- a/drivers/scsi/aacraid/commctrl.c
35808 +++ b/drivers/scsi/aacraid/commctrl.c
35809 @@ -482,6 +482,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
35810 u32 actual_fibsize64, actual_fibsize = 0;
35811 int i;
35812
35813 + pax_track_stack();
35814
35815 if (dev->in_reset) {
35816 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
35817 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
35818 index c7b6fed..4db0569 100644
35819 --- a/drivers/scsi/aacraid/linit.c
35820 +++ b/drivers/scsi/aacraid/linit.c
35821 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
35822 #elif defined(__devinitconst)
35823 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
35824 #else
35825 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
35826 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
35827 #endif
35828 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
35829 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
35830 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
35831 index d5ff142..49c0ebb 100644
35832 --- a/drivers/scsi/aic94xx/aic94xx_init.c
35833 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
35834 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
35835 .lldd_control_phy = asd_control_phy,
35836 };
35837
35838 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
35839 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
35840 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
35841 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
35842 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
35843 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
35844 index a796de9..1ef20e1 100644
35845 --- a/drivers/scsi/bfa/bfa.h
35846 +++ b/drivers/scsi/bfa/bfa.h
35847 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
35848 u32 *end);
35849 int cpe_vec_q0;
35850 int rme_vec_q0;
35851 -};
35852 +} __no_const;
35853 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
35854
35855 struct bfa_faa_cbfn_s {
35856 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
35857 index e07bd47..dbd260a 100644
35858 --- a/drivers/scsi/bfa/bfa_fcpim.c
35859 +++ b/drivers/scsi/bfa/bfa_fcpim.c
35860 @@ -4179,7 +4179,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
35861 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
35862 {
35863 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
35864 - struct bfa_itn_s *itn;
35865 + bfa_itn_s_no_const *itn;
35866
35867 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
35868 itn->isr = isr;
35869 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
35870 index 1080bcb..a3b39e3 100644
35871 --- a/drivers/scsi/bfa/bfa_fcpim.h
35872 +++ b/drivers/scsi/bfa/bfa_fcpim.h
35873 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
35874 struct bfa_itn_s {
35875 bfa_isr_func_t isr;
35876 };
35877 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
35878
35879 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
35880 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
35881 @@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
35882 struct list_head iotag_tio_free_q; /* free IO resources */
35883 struct list_head iotag_unused_q; /* unused IO resources*/
35884 struct bfa_iotag_s *iotag_arr;
35885 - struct bfa_itn_s *itn_arr;
35886 + bfa_itn_s_no_const *itn_arr;
35887 int num_ioim_reqs;
35888 int num_fwtio_reqs;
35889 int num_itns;
35890 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
35891 index d4f951f..197c350 100644
35892 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
35893 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
35894 @@ -1700,6 +1700,8 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
35895 u16 len, count;
35896 u16 templen;
35897
35898 + pax_track_stack();
35899 +
35900 /*
35901 * get hba attributes
35902 */
35903 @@ -1977,6 +1979,8 @@ bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
35904 u8 count = 0;
35905 u16 templen;
35906
35907 + pax_track_stack();
35908 +
35909 /*
35910 * get port attributes
35911 */
35912 diff --git a/drivers/scsi/bfa/bfa_fcs_rport.c b/drivers/scsi/bfa/bfa_fcs_rport.c
35913 index 52628d5..f89d033 100644
35914 --- a/drivers/scsi/bfa/bfa_fcs_rport.c
35915 +++ b/drivers/scsi/bfa/bfa_fcs_rport.c
35916 @@ -1871,6 +1871,8 @@ bfa_fcs_rport_process_rpsc(struct bfa_fcs_rport_s *rport,
35917 struct fc_rpsc_speed_info_s speeds;
35918 struct bfa_port_attr_s pport_attr;
35919
35920 + pax_track_stack();
35921 +
35922 bfa_trc(port->fcs, rx_fchs->s_id);
35923 bfa_trc(port->fcs, rx_fchs->d_id);
35924
35925 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
35926 index 546d46b..642fa5b 100644
35927 --- a/drivers/scsi/bfa/bfa_ioc.h
35928 +++ b/drivers/scsi/bfa/bfa_ioc.h
35929 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
35930 bfa_ioc_disable_cbfn_t disable_cbfn;
35931 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
35932 bfa_ioc_reset_cbfn_t reset_cbfn;
35933 -};
35934 +} __no_const;
35935
35936 /*
35937 * IOC event notification mechanism.
35938 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
35939 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
35940 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
35941 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
35942 -};
35943 +} __no_const;
35944
35945 /*
35946 * Queue element to wait for room in request queue. FIFO order is
35947 diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
35948 index 66fb725..0fe05ab 100644
35949 --- a/drivers/scsi/bfa/bfad.c
35950 +++ b/drivers/scsi/bfa/bfad.c
35951 @@ -1019,6 +1019,8 @@ bfad_start_ops(struct bfad_s *bfad) {
35952 struct bfad_vport_s *vport, *vport_new;
35953 struct bfa_fcs_driver_info_s driver_info;
35954
35955 + pax_track_stack();
35956 +
35957 /* Limit min/max. xfer size to [64k-32MB] */
35958 if (max_xfer_size < BFAD_MIN_SECTORS >> 1)
35959 max_xfer_size = BFAD_MIN_SECTORS >> 1;
35960 diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
35961 index b4f6c9a..0eb1938 100644
35962 --- a/drivers/scsi/dpt_i2o.c
35963 +++ b/drivers/scsi/dpt_i2o.c
35964 @@ -1811,6 +1811,8 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
35965 dma_addr_t addr;
35966 ulong flags = 0;
35967
35968 + pax_track_stack();
35969 +
35970 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
35971 // get user msg size in u32s
35972 if(get_user(size, &user_msg[0])){
35973 @@ -2317,6 +2319,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
35974 s32 rcode;
35975 dma_addr_t addr;
35976
35977 + pax_track_stack();
35978 +
35979 memset(msg, 0 , sizeof(msg));
35980 len = scsi_bufflen(cmd);
35981 direction = 0x00000000;
35982 diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
35983 index 94de889..ca4f0cf 100644
35984 --- a/drivers/scsi/eata.c
35985 +++ b/drivers/scsi/eata.c
35986 @@ -1087,6 +1087,8 @@ static int port_detect(unsigned long port_base, unsigned int j,
35987 struct hostdata *ha;
35988 char name[16];
35989
35990 + pax_track_stack();
35991 +
35992 sprintf(name, "%s%d", driver_name, j);
35993
35994 if (!request_region(port_base, REGION_SIZE, driver_name)) {
35995 diff --git a/drivers/scsi/fcoe/fcoe_ctlr.c b/drivers/scsi/fcoe/fcoe_ctlr.c
35996 index c74c4b8..c41ca3f 100644
35997 --- a/drivers/scsi/fcoe/fcoe_ctlr.c
35998 +++ b/drivers/scsi/fcoe/fcoe_ctlr.c
35999 @@ -2503,6 +2503,8 @@ static int fcoe_ctlr_vn_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
36000 } buf;
36001 int rc;
36002
36003 + pax_track_stack();
36004 +
36005 fiph = (struct fip_header *)skb->data;
36006 sub = fiph->fip_subcode;
36007
36008 diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
36009 index 3242bca..45a83e7 100644
36010 --- a/drivers/scsi/gdth.c
36011 +++ b/drivers/scsi/gdth.c
36012 @@ -4107,6 +4107,8 @@ static int ioc_lockdrv(void __user *arg)
36013 unsigned long flags;
36014 gdth_ha_str *ha;
36015
36016 + pax_track_stack();
36017 +
36018 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
36019 return -EFAULT;
36020 ha = gdth_find_ha(ldrv.ionode);
36021 @@ -4139,6 +4141,8 @@ static int ioc_resetdrv(void __user *arg, char *cmnd)
36022 gdth_ha_str *ha;
36023 int rval;
36024
36025 + pax_track_stack();
36026 +
36027 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
36028 res.number >= MAX_HDRIVES)
36029 return -EFAULT;
36030 @@ -4174,6 +4178,8 @@ static int ioc_general(void __user *arg, char *cmnd)
36031 gdth_ha_str *ha;
36032 int rval;
36033
36034 + pax_track_stack();
36035 +
36036 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
36037 return -EFAULT;
36038 ha = gdth_find_ha(gen.ionode);
36039 @@ -4642,6 +4648,9 @@ static void gdth_flush(gdth_ha_str *ha)
36040 int i;
36041 gdth_cmd_str gdtcmd;
36042 char cmnd[MAX_COMMAND_SIZE];
36043 +
36044 + pax_track_stack();
36045 +
36046 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
36047
36048 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
36049 diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
36050 index 6527543..81e4fe2 100644
36051 --- a/drivers/scsi/gdth_proc.c
36052 +++ b/drivers/scsi/gdth_proc.c
36053 @@ -47,6 +47,9 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
36054 u64 paddr;
36055
36056 char cmnd[MAX_COMMAND_SIZE];
36057 +
36058 + pax_track_stack();
36059 +
36060 memset(cmnd, 0xff, 12);
36061 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
36062
36063 @@ -175,6 +178,8 @@ static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
36064 gdth_hget_str *phg;
36065 char cmnd[MAX_COMMAND_SIZE];
36066
36067 + pax_track_stack();
36068 +
36069 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
36070 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
36071 if (!gdtcmd || !estr)
36072 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36073 index 351dc0b..951dc32 100644
36074 --- a/drivers/scsi/hosts.c
36075 +++ b/drivers/scsi/hosts.c
36076 @@ -42,7 +42,7 @@
36077 #include "scsi_logging.h"
36078
36079
36080 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36081 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36082
36083
36084 static void scsi_host_cls_release(struct device *dev)
36085 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36086 * subtract one because we increment first then return, but we need to
36087 * know what the next host number was before increment
36088 */
36089 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36090 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36091 shost->dma_channel = 0xff;
36092
36093 /* These three are default values which can be overridden */
36094 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36095 index 418ce83..7ee1225 100644
36096 --- a/drivers/scsi/hpsa.c
36097 +++ b/drivers/scsi/hpsa.c
36098 @@ -499,7 +499,7 @@ static inline u32 next_command(struct ctlr_info *h)
36099 u32 a;
36100
36101 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36102 - return h->access.command_completed(h);
36103 + return h->access->command_completed(h);
36104
36105 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36106 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36107 @@ -2956,7 +2956,7 @@ static void start_io(struct ctlr_info *h)
36108 while (!list_empty(&h->reqQ)) {
36109 c = list_entry(h->reqQ.next, struct CommandList, list);
36110 /* can't do anything if fifo is full */
36111 - if ((h->access.fifo_full(h))) {
36112 + if ((h->access->fifo_full(h))) {
36113 dev_warn(&h->pdev->dev, "fifo full\n");
36114 break;
36115 }
36116 @@ -2966,7 +2966,7 @@ static void start_io(struct ctlr_info *h)
36117 h->Qdepth--;
36118
36119 /* Tell the controller execute command */
36120 - h->access.submit_command(h, c);
36121 + h->access->submit_command(h, c);
36122
36123 /* Put job onto the completed Q */
36124 addQ(&h->cmpQ, c);
36125 @@ -2975,17 +2975,17 @@ static void start_io(struct ctlr_info *h)
36126
36127 static inline unsigned long get_next_completion(struct ctlr_info *h)
36128 {
36129 - return h->access.command_completed(h);
36130 + return h->access->command_completed(h);
36131 }
36132
36133 static inline bool interrupt_pending(struct ctlr_info *h)
36134 {
36135 - return h->access.intr_pending(h);
36136 + return h->access->intr_pending(h);
36137 }
36138
36139 static inline long interrupt_not_for_us(struct ctlr_info *h)
36140 {
36141 - return (h->access.intr_pending(h) == 0) ||
36142 + return (h->access->intr_pending(h) == 0) ||
36143 (h->interrupts_enabled == 0);
36144 }
36145
36146 @@ -3882,7 +3882,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36147 if (prod_index < 0)
36148 return -ENODEV;
36149 h->product_name = products[prod_index].product_name;
36150 - h->access = *(products[prod_index].access);
36151 + h->access = products[prod_index].access;
36152
36153 if (hpsa_board_disabled(h->pdev)) {
36154 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36155 @@ -4163,7 +4163,7 @@ reinit_after_soft_reset:
36156 }
36157
36158 /* make sure the board interrupts are off */
36159 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36160 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36161
36162 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36163 goto clean2;
36164 @@ -4197,7 +4197,7 @@ reinit_after_soft_reset:
36165 * fake ones to scoop up any residual completions.
36166 */
36167 spin_lock_irqsave(&h->lock, flags);
36168 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36169 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36170 spin_unlock_irqrestore(&h->lock, flags);
36171 free_irq(h->intr[h->intr_mode], h);
36172 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36173 @@ -4216,9 +4216,9 @@ reinit_after_soft_reset:
36174 dev_info(&h->pdev->dev, "Board READY.\n");
36175 dev_info(&h->pdev->dev,
36176 "Waiting for stale completions to drain.\n");
36177 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36178 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36179 msleep(10000);
36180 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36181 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36182
36183 rc = controller_reset_failed(h->cfgtable);
36184 if (rc)
36185 @@ -4239,7 +4239,7 @@ reinit_after_soft_reset:
36186 }
36187
36188 /* Turn the interrupts on so we can service requests */
36189 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36190 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36191
36192 hpsa_hba_inquiry(h);
36193 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36194 @@ -4292,7 +4292,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36195 * To write all data in the battery backed cache to disks
36196 */
36197 hpsa_flush_cache(h);
36198 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36199 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36200 free_irq(h->intr[h->intr_mode], h);
36201 #ifdef CONFIG_PCI_MSI
36202 if (h->msix_vector)
36203 @@ -4455,7 +4455,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36204 return;
36205 }
36206 /* Change the access methods to the performant access methods */
36207 - h->access = SA5_performant_access;
36208 + h->access = &SA5_performant_access;
36209 h->transMethod = CFGTBL_Trans_Performant;
36210 }
36211
36212 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36213 index 7f53cea..a8c7188 100644
36214 --- a/drivers/scsi/hpsa.h
36215 +++ b/drivers/scsi/hpsa.h
36216 @@ -73,7 +73,7 @@ struct ctlr_info {
36217 unsigned int msix_vector;
36218 unsigned int msi_vector;
36219 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36220 - struct access_method access;
36221 + struct access_method *access;
36222
36223 /* queue and queue Info */
36224 struct list_head reqQ;
36225 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36226 index f2df059..a3a9930 100644
36227 --- a/drivers/scsi/ips.h
36228 +++ b/drivers/scsi/ips.h
36229 @@ -1027,7 +1027,7 @@ typedef struct {
36230 int (*intr)(struct ips_ha *);
36231 void (*enableint)(struct ips_ha *);
36232 uint32_t (*statupd)(struct ips_ha *);
36233 -} ips_hw_func_t;
36234 +} __no_const ips_hw_func_t;
36235
36236 typedef struct ips_ha {
36237 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36238 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36239 index d261e98..1e00f35 100644
36240 --- a/drivers/scsi/libfc/fc_exch.c
36241 +++ b/drivers/scsi/libfc/fc_exch.c
36242 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36243 * all together if not used XXX
36244 */
36245 struct {
36246 - atomic_t no_free_exch;
36247 - atomic_t no_free_exch_xid;
36248 - atomic_t xid_not_found;
36249 - atomic_t xid_busy;
36250 - atomic_t seq_not_found;
36251 - atomic_t non_bls_resp;
36252 + atomic_unchecked_t no_free_exch;
36253 + atomic_unchecked_t no_free_exch_xid;
36254 + atomic_unchecked_t xid_not_found;
36255 + atomic_unchecked_t xid_busy;
36256 + atomic_unchecked_t seq_not_found;
36257 + atomic_unchecked_t non_bls_resp;
36258 } stats;
36259 };
36260
36261 @@ -718,7 +718,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36262 /* allocate memory for exchange */
36263 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36264 if (!ep) {
36265 - atomic_inc(&mp->stats.no_free_exch);
36266 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36267 goto out;
36268 }
36269 memset(ep, 0, sizeof(*ep));
36270 @@ -779,7 +779,7 @@ out:
36271 return ep;
36272 err:
36273 spin_unlock_bh(&pool->lock);
36274 - atomic_inc(&mp->stats.no_free_exch_xid);
36275 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36276 mempool_free(ep, mp->ep_pool);
36277 return NULL;
36278 }
36279 @@ -922,7 +922,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36280 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36281 ep = fc_exch_find(mp, xid);
36282 if (!ep) {
36283 - atomic_inc(&mp->stats.xid_not_found);
36284 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36285 reject = FC_RJT_OX_ID;
36286 goto out;
36287 }
36288 @@ -952,7 +952,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36289 ep = fc_exch_find(mp, xid);
36290 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36291 if (ep) {
36292 - atomic_inc(&mp->stats.xid_busy);
36293 + atomic_inc_unchecked(&mp->stats.xid_busy);
36294 reject = FC_RJT_RX_ID;
36295 goto rel;
36296 }
36297 @@ -963,7 +963,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36298 }
36299 xid = ep->xid; /* get our XID */
36300 } else if (!ep) {
36301 - atomic_inc(&mp->stats.xid_not_found);
36302 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36303 reject = FC_RJT_RX_ID; /* XID not found */
36304 goto out;
36305 }
36306 @@ -980,7 +980,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36307 } else {
36308 sp = &ep->seq;
36309 if (sp->id != fh->fh_seq_id) {
36310 - atomic_inc(&mp->stats.seq_not_found);
36311 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36312 if (f_ctl & FC_FC_END_SEQ) {
36313 /*
36314 * Update sequence_id based on incoming last
36315 @@ -1430,22 +1430,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36316
36317 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36318 if (!ep) {
36319 - atomic_inc(&mp->stats.xid_not_found);
36320 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36321 goto out;
36322 }
36323 if (ep->esb_stat & ESB_ST_COMPLETE) {
36324 - atomic_inc(&mp->stats.xid_not_found);
36325 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36326 goto rel;
36327 }
36328 if (ep->rxid == FC_XID_UNKNOWN)
36329 ep->rxid = ntohs(fh->fh_rx_id);
36330 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36331 - atomic_inc(&mp->stats.xid_not_found);
36332 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36333 goto rel;
36334 }
36335 if (ep->did != ntoh24(fh->fh_s_id) &&
36336 ep->did != FC_FID_FLOGI) {
36337 - atomic_inc(&mp->stats.xid_not_found);
36338 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36339 goto rel;
36340 }
36341 sof = fr_sof(fp);
36342 @@ -1454,7 +1454,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36343 sp->ssb_stat |= SSB_ST_RESP;
36344 sp->id = fh->fh_seq_id;
36345 } else if (sp->id != fh->fh_seq_id) {
36346 - atomic_inc(&mp->stats.seq_not_found);
36347 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36348 goto rel;
36349 }
36350
36351 @@ -1518,9 +1518,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36352 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36353
36354 if (!sp)
36355 - atomic_inc(&mp->stats.xid_not_found);
36356 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36357 else
36358 - atomic_inc(&mp->stats.non_bls_resp);
36359 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36360
36361 fc_frame_free(fp);
36362 }
36363 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36364 index db9238f..4378ed2 100644
36365 --- a/drivers/scsi/libsas/sas_ata.c
36366 +++ b/drivers/scsi/libsas/sas_ata.c
36367 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
36368 .postreset = ata_std_postreset,
36369 .error_handler = ata_std_error_handler,
36370 .post_internal_cmd = sas_ata_post_internal,
36371 - .qc_defer = ata_std_qc_defer,
36372 + .qc_defer = ata_std_qc_defer,
36373 .qc_prep = ata_noop_qc_prep,
36374 .qc_issue = sas_ata_qc_issue,
36375 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36376 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36377 index c088a36..01c73b0 100644
36378 --- a/drivers/scsi/lpfc/lpfc.h
36379 +++ b/drivers/scsi/lpfc/lpfc.h
36380 @@ -425,7 +425,7 @@ struct lpfc_vport {
36381 struct dentry *debug_nodelist;
36382 struct dentry *vport_debugfs_root;
36383 struct lpfc_debugfs_trc *disc_trc;
36384 - atomic_t disc_trc_cnt;
36385 + atomic_unchecked_t disc_trc_cnt;
36386 #endif
36387 uint8_t stat_data_enabled;
36388 uint8_t stat_data_blocked;
36389 @@ -835,8 +835,8 @@ struct lpfc_hba {
36390 struct timer_list fabric_block_timer;
36391 unsigned long bit_flags;
36392 #define FABRIC_COMANDS_BLOCKED 0
36393 - atomic_t num_rsrc_err;
36394 - atomic_t num_cmd_success;
36395 + atomic_unchecked_t num_rsrc_err;
36396 + atomic_unchecked_t num_cmd_success;
36397 unsigned long last_rsrc_error_time;
36398 unsigned long last_ramp_down_time;
36399 unsigned long last_ramp_up_time;
36400 @@ -850,7 +850,7 @@ struct lpfc_hba {
36401 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
36402 struct dentry *debug_slow_ring_trc;
36403 struct lpfc_debugfs_trc *slow_ring_trc;
36404 - atomic_t slow_ring_trc_cnt;
36405 + atomic_unchecked_t slow_ring_trc_cnt;
36406 /* iDiag debugfs sub-directory */
36407 struct dentry *idiag_root;
36408 struct dentry *idiag_pci_cfg;
36409 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36410 index a0424dd..2499b6b 100644
36411 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36412 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36413 @@ -105,7 +105,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36414
36415 #include <linux/debugfs.h>
36416
36417 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36418 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36419 static unsigned long lpfc_debugfs_start_time = 0L;
36420
36421 /* iDiag */
36422 @@ -146,7 +146,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36423 lpfc_debugfs_enable = 0;
36424
36425 len = 0;
36426 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36427 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36428 (lpfc_debugfs_max_disc_trc - 1);
36429 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36430 dtp = vport->disc_trc + i;
36431 @@ -212,7 +212,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36432 lpfc_debugfs_enable = 0;
36433
36434 len = 0;
36435 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36436 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36437 (lpfc_debugfs_max_slow_ring_trc - 1);
36438 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36439 dtp = phba->slow_ring_trc + i;
36440 @@ -635,14 +635,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36441 !vport || !vport->disc_trc)
36442 return;
36443
36444 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36445 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36446 (lpfc_debugfs_max_disc_trc - 1);
36447 dtp = vport->disc_trc + index;
36448 dtp->fmt = fmt;
36449 dtp->data1 = data1;
36450 dtp->data2 = data2;
36451 dtp->data3 = data3;
36452 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36453 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36454 dtp->jif = jiffies;
36455 #endif
36456 return;
36457 @@ -673,14 +673,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36458 !phba || !phba->slow_ring_trc)
36459 return;
36460
36461 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36462 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36463 (lpfc_debugfs_max_slow_ring_trc - 1);
36464 dtp = phba->slow_ring_trc + index;
36465 dtp->fmt = fmt;
36466 dtp->data1 = data1;
36467 dtp->data2 = data2;
36468 dtp->data3 = data3;
36469 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36470 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36471 dtp->jif = jiffies;
36472 #endif
36473 return;
36474 @@ -3828,7 +3828,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36475 "slow_ring buffer\n");
36476 goto debug_failed;
36477 }
36478 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36479 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36480 memset(phba->slow_ring_trc, 0,
36481 (sizeof(struct lpfc_debugfs_trc) *
36482 lpfc_debugfs_max_slow_ring_trc));
36483 @@ -3874,7 +3874,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36484 "buffer\n");
36485 goto debug_failed;
36486 }
36487 - atomic_set(&vport->disc_trc_cnt, 0);
36488 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36489
36490 snprintf(name, sizeof(name), "discovery_trace");
36491 vport->debug_disc_trc =
36492 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36493 index a3c8200..31e562e 100644
36494 --- a/drivers/scsi/lpfc/lpfc_init.c
36495 +++ b/drivers/scsi/lpfc/lpfc_init.c
36496 @@ -9969,8 +9969,10 @@ lpfc_init(void)
36497 printk(LPFC_COPYRIGHT "\n");
36498
36499 if (lpfc_enable_npiv) {
36500 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36501 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36502 + pax_open_kernel();
36503 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36504 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36505 + pax_close_kernel();
36506 }
36507 lpfc_transport_template =
36508 fc_attach_transport(&lpfc_transport_functions);
36509 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36510 index eadd241..26c8e0f 100644
36511 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36512 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36513 @@ -297,7 +297,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36514 uint32_t evt_posted;
36515
36516 spin_lock_irqsave(&phba->hbalock, flags);
36517 - atomic_inc(&phba->num_rsrc_err);
36518 + atomic_inc_unchecked(&phba->num_rsrc_err);
36519 phba->last_rsrc_error_time = jiffies;
36520
36521 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36522 @@ -338,7 +338,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36523 unsigned long flags;
36524 struct lpfc_hba *phba = vport->phba;
36525 uint32_t evt_posted;
36526 - atomic_inc(&phba->num_cmd_success);
36527 + atomic_inc_unchecked(&phba->num_cmd_success);
36528
36529 if (vport->cfg_lun_queue_depth <= queue_depth)
36530 return;
36531 @@ -382,8 +382,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36532 unsigned long num_rsrc_err, num_cmd_success;
36533 int i;
36534
36535 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36536 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36537 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36538 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36539
36540 vports = lpfc_create_vport_work_array(phba);
36541 if (vports != NULL)
36542 @@ -403,8 +403,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36543 }
36544 }
36545 lpfc_destroy_vport_work_array(phba, vports);
36546 - atomic_set(&phba->num_rsrc_err, 0);
36547 - atomic_set(&phba->num_cmd_success, 0);
36548 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36549 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36550 }
36551
36552 /**
36553 @@ -438,8 +438,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36554 }
36555 }
36556 lpfc_destroy_vport_work_array(phba, vports);
36557 - atomic_set(&phba->num_rsrc_err, 0);
36558 - atomic_set(&phba->num_cmd_success, 0);
36559 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36560 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36561 }
36562
36563 /**
36564 diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
36565 index 2e6619e..fa64494 100644
36566 --- a/drivers/scsi/megaraid/megaraid_mbox.c
36567 +++ b/drivers/scsi/megaraid/megaraid_mbox.c
36568 @@ -3503,6 +3503,8 @@ megaraid_cmm_register(adapter_t *adapter)
36569 int rval;
36570 int i;
36571
36572 + pax_track_stack();
36573 +
36574 // Allocate memory for the base list of scb for management module.
36575 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
36576
36577 diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
36578 index 86afb13f..c912398 100644
36579 --- a/drivers/scsi/osd/osd_initiator.c
36580 +++ b/drivers/scsi/osd/osd_initiator.c
36581 @@ -97,6 +97,8 @@ static int _osd_get_print_system_info(struct osd_dev *od,
36582 int nelem = ARRAY_SIZE(get_attrs), a = 0;
36583 int ret;
36584
36585 + pax_track_stack();
36586 +
36587 or = osd_start_request(od, GFP_KERNEL);
36588 if (!or)
36589 return -ENOMEM;
36590 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36591 index d079f9a..d26072c 100644
36592 --- a/drivers/scsi/pmcraid.c
36593 +++ b/drivers/scsi/pmcraid.c
36594 @@ -201,8 +201,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36595 res->scsi_dev = scsi_dev;
36596 scsi_dev->hostdata = res;
36597 res->change_detected = 0;
36598 - atomic_set(&res->read_failures, 0);
36599 - atomic_set(&res->write_failures, 0);
36600 + atomic_set_unchecked(&res->read_failures, 0);
36601 + atomic_set_unchecked(&res->write_failures, 0);
36602 rc = 0;
36603 }
36604 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36605 @@ -2677,9 +2677,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36606
36607 /* If this was a SCSI read/write command keep count of errors */
36608 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36609 - atomic_inc(&res->read_failures);
36610 + atomic_inc_unchecked(&res->read_failures);
36611 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36612 - atomic_inc(&res->write_failures);
36613 + atomic_inc_unchecked(&res->write_failures);
36614
36615 if (!RES_IS_GSCSI(res->cfg_entry) &&
36616 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36617 @@ -3535,7 +3535,7 @@ static int pmcraid_queuecommand_lck(
36618 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36619 * hrrq_id assigned here in queuecommand
36620 */
36621 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36622 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36623 pinstance->num_hrrq;
36624 cmd->cmd_done = pmcraid_io_done;
36625
36626 @@ -3860,7 +3860,7 @@ static long pmcraid_ioctl_passthrough(
36627 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36628 * hrrq_id assigned here in queuecommand
36629 */
36630 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36631 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36632 pinstance->num_hrrq;
36633
36634 if (request_size) {
36635 @@ -4498,7 +4498,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36636
36637 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36638 /* add resources only after host is added into system */
36639 - if (!atomic_read(&pinstance->expose_resources))
36640 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36641 return;
36642
36643 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36644 @@ -5332,8 +5332,8 @@ static int __devinit pmcraid_init_instance(
36645 init_waitqueue_head(&pinstance->reset_wait_q);
36646
36647 atomic_set(&pinstance->outstanding_cmds, 0);
36648 - atomic_set(&pinstance->last_message_id, 0);
36649 - atomic_set(&pinstance->expose_resources, 0);
36650 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36651 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36652
36653 INIT_LIST_HEAD(&pinstance->free_res_q);
36654 INIT_LIST_HEAD(&pinstance->used_res_q);
36655 @@ -6048,7 +6048,7 @@ static int __devinit pmcraid_probe(
36656 /* Schedule worker thread to handle CCN and take care of adding and
36657 * removing devices to OS
36658 */
36659 - atomic_set(&pinstance->expose_resources, 1);
36660 + atomic_set_unchecked(&pinstance->expose_resources, 1);
36661 schedule_work(&pinstance->worker_q);
36662 return rc;
36663
36664 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36665 index f920baf..4417389 100644
36666 --- a/drivers/scsi/pmcraid.h
36667 +++ b/drivers/scsi/pmcraid.h
36668 @@ -749,7 +749,7 @@ struct pmcraid_instance {
36669 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36670
36671 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36672 - atomic_t last_message_id;
36673 + atomic_unchecked_t last_message_id;
36674
36675 /* configuration table */
36676 struct pmcraid_config_table *cfg_table;
36677 @@ -778,7 +778,7 @@ struct pmcraid_instance {
36678 atomic_t outstanding_cmds;
36679
36680 /* should add/delete resources to mid-layer now ?*/
36681 - atomic_t expose_resources;
36682 + atomic_unchecked_t expose_resources;
36683
36684
36685
36686 @@ -814,8 +814,8 @@ struct pmcraid_resource_entry {
36687 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36688 };
36689 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36690 - atomic_t read_failures; /* count of failed READ commands */
36691 - atomic_t write_failures; /* count of failed WRITE commands */
36692 + atomic_unchecked_t read_failures; /* count of failed READ commands */
36693 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36694
36695 /* To indicate add/delete/modify during CCN */
36696 u8 change_detected;
36697 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36698 index a03eaf4..a6b3fd9 100644
36699 --- a/drivers/scsi/qla2xxx/qla_def.h
36700 +++ b/drivers/scsi/qla2xxx/qla_def.h
36701 @@ -2244,7 +2244,7 @@ struct isp_operations {
36702 int (*get_flash_version) (struct scsi_qla_host *, void *);
36703 int (*start_scsi) (srb_t *);
36704 int (*abort_isp) (struct scsi_qla_host *);
36705 -};
36706 +} __no_const;
36707
36708 /* MSI-X Support *************************************************************/
36709
36710 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36711 index 473c5c8..4e2f24a 100644
36712 --- a/drivers/scsi/qla4xxx/ql4_def.h
36713 +++ b/drivers/scsi/qla4xxx/ql4_def.h
36714 @@ -256,7 +256,7 @@ struct ddb_entry {
36715 atomic_t retry_relogin_timer; /* Min Time between relogins
36716 * (4000 only) */
36717 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
36718 - atomic_t relogin_retry_count; /* Num of times relogin has been
36719 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36720 * retried */
36721
36722 uint16_t port;
36723 diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c
36724 index 42ed5db..0262f9e 100644
36725 --- a/drivers/scsi/qla4xxx/ql4_init.c
36726 +++ b/drivers/scsi/qla4xxx/ql4_init.c
36727 @@ -680,7 +680,7 @@ static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
36728 ddb_entry->fw_ddb_index = fw_ddb_index;
36729 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36730 atomic_set(&ddb_entry->relogin_timer, 0);
36731 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36732 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36733 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
36734 list_add_tail(&ddb_entry->list, &ha->ddb_list);
36735 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
36736 @@ -1433,7 +1433,7 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, uint32_t fw_ddb_index,
36737 if ((ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) &&
36738 (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)) {
36739 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
36740 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36741 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36742 atomic_set(&ddb_entry->relogin_timer, 0);
36743 clear_bit(DF_RELOGIN, &ddb_entry->flags);
36744 iscsi_unblock_session(ddb_entry->sess);
36745 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36746 index f2364ec..44c42b1 100644
36747 --- a/drivers/scsi/qla4xxx/ql4_os.c
36748 +++ b/drivers/scsi/qla4xxx/ql4_os.c
36749 @@ -811,13 +811,13 @@ static void qla4xxx_timer(struct scsi_qla_host *ha)
36750 ddb_entry->fw_ddb_device_state ==
36751 DDB_DS_SESSION_FAILED) {
36752 /* Reset retry relogin timer */
36753 - atomic_inc(&ddb_entry->relogin_retry_count);
36754 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36755 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
36756 " timed out-retrying"
36757 " relogin (%d)\n",
36758 ha->host_no,
36759 ddb_entry->fw_ddb_index,
36760 - atomic_read(&ddb_entry->
36761 + atomic_read_unchecked(&ddb_entry->
36762 relogin_retry_count))
36763 );
36764 start_dpc++;
36765 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36766 index 2aeb2e9..46e3925 100644
36767 --- a/drivers/scsi/scsi.c
36768 +++ b/drivers/scsi/scsi.c
36769 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36770 unsigned long timeout;
36771 int rtn = 0;
36772
36773 - atomic_inc(&cmd->device->iorequest_cnt);
36774 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36775
36776 /* check if the device is still usable */
36777 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36778 diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
36779 index 6888b2c..45befa1 100644
36780 --- a/drivers/scsi/scsi_debug.c
36781 +++ b/drivers/scsi/scsi_debug.c
36782 @@ -1493,6 +1493,8 @@ static int resp_mode_select(struct scsi_cmnd * scp, int mselect6,
36783 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
36784 unsigned char *cmd = (unsigned char *)scp->cmnd;
36785
36786 + pax_track_stack();
36787 +
36788 if ((errsts = check_readiness(scp, 1, devip)))
36789 return errsts;
36790 memset(arr, 0, sizeof(arr));
36791 @@ -1590,6 +1592,8 @@ static int resp_log_sense(struct scsi_cmnd * scp,
36792 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
36793 unsigned char *cmd = (unsigned char *)scp->cmnd;
36794
36795 + pax_track_stack();
36796 +
36797 if ((errsts = check_readiness(scp, 1, devip)))
36798 return errsts;
36799 memset(arr, 0, sizeof(arr));
36800 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36801 index 6d219e4..eb3ded3 100644
36802 --- a/drivers/scsi/scsi_lib.c
36803 +++ b/drivers/scsi/scsi_lib.c
36804 @@ -1415,7 +1415,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36805 shost = sdev->host;
36806 scsi_init_cmd_errh(cmd);
36807 cmd->result = DID_NO_CONNECT << 16;
36808 - atomic_inc(&cmd->device->iorequest_cnt);
36809 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36810
36811 /*
36812 * SCSI request completion path will do scsi_device_unbusy(),
36813 @@ -1441,9 +1441,9 @@ static void scsi_softirq_done(struct request *rq)
36814
36815 INIT_LIST_HEAD(&cmd->eh_entry);
36816
36817 - atomic_inc(&cmd->device->iodone_cnt);
36818 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
36819 if (cmd->result)
36820 - atomic_inc(&cmd->device->ioerr_cnt);
36821 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36822
36823 disposition = scsi_decide_disposition(cmd);
36824 if (disposition != SUCCESS &&
36825 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36826 index e0bd3f7..816b8a6 100644
36827 --- a/drivers/scsi/scsi_sysfs.c
36828 +++ b/drivers/scsi/scsi_sysfs.c
36829 @@ -622,7 +622,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36830 char *buf) \
36831 { \
36832 struct scsi_device *sdev = to_scsi_device(dev); \
36833 - unsigned long long count = atomic_read(&sdev->field); \
36834 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
36835 return snprintf(buf, 20, "0x%llx\n", count); \
36836 } \
36837 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36838 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36839 index 84a1fdf..693b0d6 100644
36840 --- a/drivers/scsi/scsi_tgt_lib.c
36841 +++ b/drivers/scsi/scsi_tgt_lib.c
36842 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36843 int err;
36844
36845 dprintk("%lx %u\n", uaddr, len);
36846 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36847 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36848 if (err) {
36849 /*
36850 * TODO: need to fixup sg_tablesize, max_segment_size,
36851 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36852 index 1b21491..1b7f60e 100644
36853 --- a/drivers/scsi/scsi_transport_fc.c
36854 +++ b/drivers/scsi/scsi_transport_fc.c
36855 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36856 * Netlink Infrastructure
36857 */
36858
36859 -static atomic_t fc_event_seq;
36860 +static atomic_unchecked_t fc_event_seq;
36861
36862 /**
36863 * fc_get_event_number - Obtain the next sequential FC event number
36864 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
36865 u32
36866 fc_get_event_number(void)
36867 {
36868 - return atomic_add_return(1, &fc_event_seq);
36869 + return atomic_add_return_unchecked(1, &fc_event_seq);
36870 }
36871 EXPORT_SYMBOL(fc_get_event_number);
36872
36873 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
36874 {
36875 int error;
36876
36877 - atomic_set(&fc_event_seq, 0);
36878 + atomic_set_unchecked(&fc_event_seq, 0);
36879
36880 error = transport_class_register(&fc_host_class);
36881 if (error)
36882 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
36883 char *cp;
36884
36885 *val = simple_strtoul(buf, &cp, 0);
36886 - if ((*cp && (*cp != '\n')) || (*val < 0))
36887 + if (*cp && (*cp != '\n'))
36888 return -EINVAL;
36889 /*
36890 * Check for overflow; dev_loss_tmo is u32
36891 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
36892 index 3fd16d7..ba0871f 100644
36893 --- a/drivers/scsi/scsi_transport_iscsi.c
36894 +++ b/drivers/scsi/scsi_transport_iscsi.c
36895 @@ -83,7 +83,7 @@ struct iscsi_internal {
36896 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
36897 };
36898
36899 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
36900 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
36901 static struct workqueue_struct *iscsi_eh_timer_workq;
36902
36903 /*
36904 @@ -761,7 +761,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
36905 int err;
36906
36907 ihost = shost->shost_data;
36908 - session->sid = atomic_add_return(1, &iscsi_session_nr);
36909 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
36910
36911 if (id == ISCSI_MAX_TARGET) {
36912 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
36913 @@ -2200,7 +2200,7 @@ static __init int iscsi_transport_init(void)
36914 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
36915 ISCSI_TRANSPORT_VERSION);
36916
36917 - atomic_set(&iscsi_session_nr, 0);
36918 + atomic_set_unchecked(&iscsi_session_nr, 0);
36919
36920 err = class_register(&iscsi_transport_class);
36921 if (err)
36922 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
36923 index 21a045e..ec89e03 100644
36924 --- a/drivers/scsi/scsi_transport_srp.c
36925 +++ b/drivers/scsi/scsi_transport_srp.c
36926 @@ -33,7 +33,7 @@
36927 #include "scsi_transport_srp_internal.h"
36928
36929 struct srp_host_attrs {
36930 - atomic_t next_port_id;
36931 + atomic_unchecked_t next_port_id;
36932 };
36933 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
36934
36935 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
36936 struct Scsi_Host *shost = dev_to_shost(dev);
36937 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
36938
36939 - atomic_set(&srp_host->next_port_id, 0);
36940 + atomic_set_unchecked(&srp_host->next_port_id, 0);
36941 return 0;
36942 }
36943
36944 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
36945 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
36946 rport->roles = ids->roles;
36947
36948 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
36949 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
36950 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
36951
36952 transport_setup_device(&rport->dev);
36953 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
36954 index 953773c..c7f29de 100644
36955 --- a/drivers/scsi/sd.c
36956 +++ b/drivers/scsi/sd.c
36957 @@ -1073,6 +1073,10 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode,
36958 SCSI_LOG_IOCTL(1, printk("sd_ioctl: disk=%s, cmd=0x%x\n",
36959 disk->disk_name, cmd));
36960
36961 + error = scsi_verify_blk_ioctl(bdev, cmd);
36962 + if (error < 0)
36963 + return error;
36964 +
36965 /*
36966 * If we are in the middle of error recovery, don't let anyone
36967 * else try and use this device. Also, if error recovery fails, it
36968 @@ -1095,7 +1099,7 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode,
36969 error = scsi_ioctl(sdp, cmd, p);
36970 break;
36971 default:
36972 - error = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, p);
36973 + error = scsi_cmd_blk_ioctl(bdev, mode, cmd, p);
36974 if (error != -ENOTTY)
36975 break;
36976 error = scsi_ioctl(sdp, cmd, p);
36977 @@ -1265,6 +1269,11 @@ static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode,
36978 unsigned int cmd, unsigned long arg)
36979 {
36980 struct scsi_device *sdev = scsi_disk(bdev->bd_disk)->device;
36981 + int ret;
36982 +
36983 + ret = scsi_verify_blk_ioctl(bdev, cmd);
36984 + if (ret < 0)
36985 + return ret;
36986
36987 /*
36988 * If we are in the middle of error recovery, don't let anyone
36989 @@ -1276,8 +1285,6 @@ static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode,
36990 return -ENODEV;
36991
36992 if (sdev->host->hostt->compat_ioctl) {
36993 - int ret;
36994 -
36995 ret = sdev->host->hostt->compat_ioctl(sdev, cmd, (void __user *)arg);
36996
36997 return ret;
36998 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
36999 index 909ed9e..1ae290a 100644
37000 --- a/drivers/scsi/sg.c
37001 +++ b/drivers/scsi/sg.c
37002 @@ -1075,7 +1075,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37003 sdp->disk->disk_name,
37004 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37005 NULL,
37006 - (char *)arg);
37007 + (char __user *)arg);
37008 case BLKTRACESTART:
37009 return blk_trace_startstop(sdp->device->request_queue, 1);
37010 case BLKTRACESTOP:
37011 @@ -2310,7 +2310,7 @@ struct sg_proc_leaf {
37012 const struct file_operations * fops;
37013 };
37014
37015 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37016 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37017 {"allow_dio", &adio_fops},
37018 {"debug", &debug_fops},
37019 {"def_reserved_size", &dressz_fops},
37020 @@ -2325,7 +2325,7 @@ sg_proc_init(void)
37021 {
37022 int k, mask;
37023 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
37024 - struct sg_proc_leaf * leaf;
37025 + const struct sg_proc_leaf * leaf;
37026
37027 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
37028 if (!sg_proc_sgp)
37029 diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
37030 index b4543f5..e1b34b8 100644
37031 --- a/drivers/scsi/sym53c8xx_2/sym_glue.c
37032 +++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
37033 @@ -1756,6 +1756,8 @@ static int __devinit sym2_probe(struct pci_dev *pdev,
37034 int do_iounmap = 0;
37035 int do_disable_device = 1;
37036
37037 + pax_track_stack();
37038 +
37039 memset(&sym_dev, 0, sizeof(sym_dev));
37040 memset(&nvram, 0, sizeof(nvram));
37041 sym_dev.pdev = pdev;
37042 diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
37043 index a18996d..fe993cb 100644
37044 --- a/drivers/scsi/vmw_pvscsi.c
37045 +++ b/drivers/scsi/vmw_pvscsi.c
37046 @@ -447,6 +447,8 @@ static void pvscsi_setup_all_rings(const struct pvscsi_adapter *adapter)
37047 dma_addr_t base;
37048 unsigned i;
37049
37050 + pax_track_stack();
37051 +
37052 cmd.ringsStatePPN = adapter->ringStatePA >> PAGE_SHIFT;
37053 cmd.reqRingNumPages = adapter->req_pages;
37054 cmd.cmpRingNumPages = adapter->cmp_pages;
37055 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
37056 index c5f37f0..898d202 100644
37057 --- a/drivers/spi/spi-dw-pci.c
37058 +++ b/drivers/spi/spi-dw-pci.c
37059 @@ -148,7 +148,7 @@ static int spi_resume(struct pci_dev *pdev)
37060 #define spi_resume NULL
37061 #endif
37062
37063 -static const struct pci_device_id pci_ids[] __devinitdata = {
37064 +static const struct pci_device_id pci_ids[] __devinitconst = {
37065 /* Intel MID platform SPI controller 0 */
37066 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
37067 {},
37068 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37069 index 4d1b9f5..8408fe3 100644
37070 --- a/drivers/spi/spi.c
37071 +++ b/drivers/spi/spi.c
37072 @@ -1023,7 +1023,7 @@ int spi_bus_unlock(struct spi_master *master)
37073 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37074
37075 /* portable code must never pass more than 32 bytes */
37076 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37077 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37078
37079 static u8 *buf;
37080
37081 diff --git a/drivers/staging/ath6kl/os/linux/ar6000_drv.c b/drivers/staging/ath6kl/os/linux/ar6000_drv.c
37082 index 32ee39a..3004c3d 100644
37083 --- a/drivers/staging/ath6kl/os/linux/ar6000_drv.c
37084 +++ b/drivers/staging/ath6kl/os/linux/ar6000_drv.c
37085 @@ -362,7 +362,7 @@ static struct ar_cookie s_ar_cookie_mem[MAX_COOKIE_NUM];
37086 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_HOST_INTEREST_ITEM_ADDRESS(item) : 0))
37087
37088
37089 -static struct net_device_ops ar6000_netdev_ops = {
37090 +static net_device_ops_no_const ar6000_netdev_ops = {
37091 .ndo_init = NULL,
37092 .ndo_open = ar6000_open,
37093 .ndo_stop = ar6000_close,
37094 diff --git a/drivers/staging/ath6kl/os/linux/include/ar6k_pal.h b/drivers/staging/ath6kl/os/linux/include/ar6k_pal.h
37095 index 39e0873..0925710 100644
37096 --- a/drivers/staging/ath6kl/os/linux/include/ar6k_pal.h
37097 +++ b/drivers/staging/ath6kl/os/linux/include/ar6k_pal.h
37098 @@ -30,7 +30,7 @@ typedef bool (*ar6k_pal_recv_pkt_t)(void *pHciPalInfo, void *skb);
37099 typedef struct ar6k_pal_config_s
37100 {
37101 ar6k_pal_recv_pkt_t fpar6k_pal_recv_pkt;
37102 -}ar6k_pal_config_t;
37103 +} __no_const ar6k_pal_config_t;
37104
37105 void register_pal_cb(ar6k_pal_config_t *palConfig_p);
37106 #endif /* _AR6K_PAL_H_ */
37107 diff --git a/drivers/staging/brcm80211/brcmfmac/dhd_linux.c b/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
37108 index 05dada9..96171c6 100644
37109 --- a/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
37110 +++ b/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
37111 @@ -451,14 +451,14 @@ static void brcmf_op_if(struct brcmf_if *ifp)
37112 free_netdev(ifp->net);
37113 }
37114 /* Allocate etherdev, including space for private structure */
37115 - ifp->net = alloc_etherdev(sizeof(drvr_priv));
37116 + ifp->net = alloc_etherdev(sizeof(*drvr_priv));
37117 if (!ifp->net) {
37118 BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
37119 ret = -ENOMEM;
37120 }
37121 if (ret == 0) {
37122 strcpy(ifp->net->name, ifp->name);
37123 - memcpy(netdev_priv(ifp->net), &drvr_priv, sizeof(drvr_priv));
37124 + memcpy(netdev_priv(ifp->net), &drvr_priv, sizeof(*drvr_priv));
37125 err = brcmf_net_attach(&drvr_priv->pub, ifp->idx);
37126 if (err != 0) {
37127 BRCMF_ERROR(("%s: brcmf_net_attach failed, "
37128 @@ -1279,7 +1279,7 @@ struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen)
37129 BRCMF_TRACE(("%s: Enter\n", __func__));
37130
37131 /* Allocate etherdev, including space for private structure */
37132 - net = alloc_etherdev(sizeof(drvr_priv));
37133 + net = alloc_etherdev(sizeof(*drvr_priv));
37134 if (!net) {
37135 BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
37136 goto fail;
37137 @@ -1295,7 +1295,7 @@ struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen)
37138 /*
37139 * Save the brcmf_info into the priv
37140 */
37141 - memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
37142 + memcpy(netdev_priv(net), &drvr_priv, sizeof(*drvr_priv));
37143
37144 /* Set network interface name if it was provided as module parameter */
37145 if (iface_name[0]) {
37146 @@ -1352,7 +1352,7 @@ struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen)
37147 /*
37148 * Save the brcmf_info into the priv
37149 */
37150 - memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
37151 + memcpy(netdev_priv(net), &drvr_priv, sizeof(*drvr_priv));
37152
37153 #if defined(CONFIG_PM_SLEEP)
37154 atomic_set(&brcmf_mmc_suspend, false);
37155 diff --git a/drivers/staging/brcm80211/brcmfmac/sdio_host.h b/drivers/staging/brcm80211/brcmfmac/sdio_host.h
37156 index d345472..cedb19e 100644
37157 --- a/drivers/staging/brcm80211/brcmfmac/sdio_host.h
37158 +++ b/drivers/staging/brcm80211/brcmfmac/sdio_host.h
37159 @@ -263,7 +263,7 @@ struct brcmf_sdioh_driver {
37160 u16 func, uint bustype, u32 regsva, void *param);
37161 /* detach from device */
37162 void (*detach) (void *ch);
37163 -};
37164 +} __no_const;
37165
37166 struct sdioh_info;
37167
37168 diff --git a/drivers/staging/brcm80211/brcmsmac/phy/phy_int.h b/drivers/staging/brcm80211/brcmsmac/phy/phy_int.h
37169 index a01b01c..b3f721c 100644
37170 --- a/drivers/staging/brcm80211/brcmsmac/phy/phy_int.h
37171 +++ b/drivers/staging/brcm80211/brcmsmac/phy/phy_int.h
37172 @@ -591,7 +591,7 @@ struct phy_func_ptr {
37173 initfn_t carrsuppr;
37174 rxsigpwrfn_t rxsigpwr;
37175 detachfn_t detach;
37176 -};
37177 +} __no_const;
37178
37179 struct brcms_phy {
37180 struct brcms_phy_pub pubpi_ro;
37181 diff --git a/drivers/staging/et131x/et1310_tx.c b/drivers/staging/et131x/et1310_tx.c
37182 index 8fb3051..a8b6c67 100644
37183 --- a/drivers/staging/et131x/et1310_tx.c
37184 +++ b/drivers/staging/et131x/et1310_tx.c
37185 @@ -635,11 +635,11 @@ inline void et131x_free_send_packet(struct et131x_adapter *etdev,
37186 struct net_device_stats *stats = &etdev->net_stats;
37187
37188 if (tcb->flags & fMP_DEST_BROAD)
37189 - atomic_inc(&etdev->stats.brdcstxmt);
37190 + atomic_inc_unchecked(&etdev->stats.brdcstxmt);
37191 else if (tcb->flags & fMP_DEST_MULTI)
37192 - atomic_inc(&etdev->stats.multixmt);
37193 + atomic_inc_unchecked(&etdev->stats.multixmt);
37194 else
37195 - atomic_inc(&etdev->stats.unixmt);
37196 + atomic_inc_unchecked(&etdev->stats.unixmt);
37197
37198 if (tcb->skb) {
37199 stats->tx_bytes += tcb->skb->len;
37200 diff --git a/drivers/staging/et131x/et131x_adapter.h b/drivers/staging/et131x/et131x_adapter.h
37201 index 408c50b..fd65e9f 100644
37202 --- a/drivers/staging/et131x/et131x_adapter.h
37203 +++ b/drivers/staging/et131x/et131x_adapter.h
37204 @@ -106,11 +106,11 @@ struct ce_stats {
37205 * operations
37206 */
37207 u32 unircv; /* # multicast packets received */
37208 - atomic_t unixmt; /* # multicast packets for Tx */
37209 + atomic_unchecked_t unixmt; /* # multicast packets for Tx */
37210 u32 multircv; /* # multicast packets received */
37211 - atomic_t multixmt; /* # multicast packets for Tx */
37212 + atomic_unchecked_t multixmt; /* # multicast packets for Tx */
37213 u32 brdcstrcv; /* # broadcast packets received */
37214 - atomic_t brdcstxmt; /* # broadcast packets for Tx */
37215 + atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
37216 u32 norcvbuf; /* # Rx packets discarded */
37217 u32 noxmtbuf; /* # Tx packets discarded */
37218
37219 diff --git a/drivers/staging/hv/channel.c b/drivers/staging/hv/channel.c
37220 index 455f47a..86205ff 100644
37221 --- a/drivers/staging/hv/channel.c
37222 +++ b/drivers/staging/hv/channel.c
37223 @@ -447,8 +447,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
37224 int ret = 0;
37225 int t;
37226
37227 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
37228 - atomic_inc(&vmbus_connection.next_gpadl_handle);
37229 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
37230 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
37231
37232 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
37233 if (ret)
37234 diff --git a/drivers/staging/hv/hv.c b/drivers/staging/hv/hv.c
37235 index 824f816..a800af7 100644
37236 --- a/drivers/staging/hv/hv.c
37237 +++ b/drivers/staging/hv/hv.c
37238 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
37239 u64 output_address = (output) ? virt_to_phys(output) : 0;
37240 u32 output_address_hi = output_address >> 32;
37241 u32 output_address_lo = output_address & 0xFFFFFFFF;
37242 - volatile void *hypercall_page = hv_context.hypercall_page;
37243 + volatile void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
37244
37245 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
37246 "=a"(hv_status_lo) : "d" (control_hi),
37247 diff --git a/drivers/staging/hv/hv_mouse.c b/drivers/staging/hv/hv_mouse.c
37248 index d957fc2..43cedd9 100644
37249 --- a/drivers/staging/hv/hv_mouse.c
37250 +++ b/drivers/staging/hv/hv_mouse.c
37251 @@ -878,8 +878,10 @@ static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
37252 if (hid_dev) {
37253 DPRINT_INFO(INPUTVSC_DRV, "hid_device created");
37254
37255 - hid_dev->ll_driver->open = mousevsc_hid_open;
37256 - hid_dev->ll_driver->close = mousevsc_hid_close;
37257 + pax_open_kernel();
37258 + *(void **)&hid_dev->ll_driver->open = mousevsc_hid_open;
37259 + *(void **)&hid_dev->ll_driver->close = mousevsc_hid_close;
37260 + pax_close_kernel();
37261
37262 hid_dev->bus = BUS_VIRTUAL;
37263 hid_dev->vendor = input_device_ctx->device_info.vendor;
37264 diff --git a/drivers/staging/hv/hyperv_vmbus.h b/drivers/staging/hv/hyperv_vmbus.h
37265 index 349ad80..3f75719 100644
37266 --- a/drivers/staging/hv/hyperv_vmbus.h
37267 +++ b/drivers/staging/hv/hyperv_vmbus.h
37268 @@ -559,7 +559,7 @@ enum vmbus_connect_state {
37269 struct vmbus_connection {
37270 enum vmbus_connect_state conn_state;
37271
37272 - atomic_t next_gpadl_handle;
37273 + atomic_unchecked_t next_gpadl_handle;
37274
37275 /*
37276 * Represents channel interrupts. Each bit position represents a
37277 diff --git a/drivers/staging/hv/rndis_filter.c b/drivers/staging/hv/rndis_filter.c
37278 index dbb5201..d6047c6 100644
37279 --- a/drivers/staging/hv/rndis_filter.c
37280 +++ b/drivers/staging/hv/rndis_filter.c
37281 @@ -43,7 +43,7 @@ struct rndis_device {
37282
37283 enum rndis_device_state state;
37284 u32 link_stat;
37285 - atomic_t new_req_id;
37286 + atomic_unchecked_t new_req_id;
37287
37288 spinlock_t request_lock;
37289 struct list_head req_list;
37290 @@ -117,7 +117,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
37291 * template
37292 */
37293 set = &rndis_msg->msg.set_req;
37294 - set->req_id = atomic_inc_return(&dev->new_req_id);
37295 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37296
37297 /* Add to the request list */
37298 spin_lock_irqsave(&dev->request_lock, flags);
37299 @@ -622,7 +622,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
37300
37301 /* Setup the rndis set */
37302 halt = &request->request_msg.msg.halt_req;
37303 - halt->req_id = atomic_inc_return(&dev->new_req_id);
37304 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37305
37306 /* Ignore return since this msg is optional. */
37307 rndis_filter_send_request(dev, request);
37308 diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c
37309 index 1c949f5..7a8b104 100644
37310 --- a/drivers/staging/hv/vmbus_drv.c
37311 +++ b/drivers/staging/hv/vmbus_drv.c
37312 @@ -660,11 +660,11 @@ int vmbus_child_device_register(struct hv_device *child_device_obj)
37313 {
37314 int ret = 0;
37315
37316 - static atomic_t device_num = ATOMIC_INIT(0);
37317 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
37318
37319 /* Set the device name. Otherwise, device_register() will fail. */
37320 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
37321 - atomic_inc_return(&device_num));
37322 + atomic_inc_return_unchecked(&device_num));
37323
37324 /* The new device belongs to this bus */
37325 child_device_obj->device.bus = &hv_bus; /* device->dev.bus; */
37326 diff --git a/drivers/staging/iio/ring_generic.h b/drivers/staging/iio/ring_generic.h
37327 index 3f26f71..fb5c787 100644
37328 --- a/drivers/staging/iio/ring_generic.h
37329 +++ b/drivers/staging/iio/ring_generic.h
37330 @@ -62,7 +62,7 @@ struct iio_ring_access_funcs {
37331
37332 int (*is_enabled)(struct iio_ring_buffer *ring);
37333 int (*enable)(struct iio_ring_buffer *ring);
37334 -};
37335 +} __no_const;
37336
37337 struct iio_ring_setup_ops {
37338 int (*preenable)(struct iio_dev *);
37339 diff --git a/drivers/staging/mei/interface.c b/drivers/staging/mei/interface.c
37340 index cfec92d..a65dacf 100644
37341 --- a/drivers/staging/mei/interface.c
37342 +++ b/drivers/staging/mei/interface.c
37343 @@ -332,7 +332,7 @@ int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl)
37344 mei_hdr->reserved = 0;
37345
37346 mei_flow_control = (struct hbm_flow_control *) &dev->wr_msg_buf[1];
37347 - memset(mei_flow_control, 0, sizeof(mei_flow_control));
37348 + memset(mei_flow_control, 0, sizeof(*mei_flow_control));
37349 mei_flow_control->host_addr = cl->host_client_id;
37350 mei_flow_control->me_addr = cl->me_client_id;
37351 mei_flow_control->cmd.cmd = MEI_FLOW_CONTROL_CMD;
37352 @@ -396,7 +396,7 @@ int mei_disconnect(struct mei_device *dev, struct mei_cl *cl)
37353
37354 mei_cli_disconnect =
37355 (struct hbm_client_disconnect_request *) &dev->wr_msg_buf[1];
37356 - memset(mei_cli_disconnect, 0, sizeof(mei_cli_disconnect));
37357 + memset(mei_cli_disconnect, 0, sizeof(*mei_cli_disconnect));
37358 mei_cli_disconnect->host_addr = cl->host_client_id;
37359 mei_cli_disconnect->me_addr = cl->me_client_id;
37360 mei_cli_disconnect->cmd.cmd = CLIENT_DISCONNECT_REQ_CMD;
37361 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37362 index 8b307b4..a97ac91 100644
37363 --- a/drivers/staging/octeon/ethernet-rx.c
37364 +++ b/drivers/staging/octeon/ethernet-rx.c
37365 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37366 /* Increment RX stats for virtual ports */
37367 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37368 #ifdef CONFIG_64BIT
37369 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37370 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37371 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37372 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37373 #else
37374 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37375 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37376 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37377 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37378 #endif
37379 }
37380 netif_receive_skb(skb);
37381 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37382 dev->name);
37383 */
37384 #ifdef CONFIG_64BIT
37385 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37386 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37387 #else
37388 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37389 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37390 #endif
37391 dev_kfree_skb_irq(skb);
37392 }
37393 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37394 index a8f780e..aef1098 100644
37395 --- a/drivers/staging/octeon/ethernet.c
37396 +++ b/drivers/staging/octeon/ethernet.c
37397 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37398 * since the RX tasklet also increments it.
37399 */
37400 #ifdef CONFIG_64BIT
37401 - atomic64_add(rx_status.dropped_packets,
37402 - (atomic64_t *)&priv->stats.rx_dropped);
37403 + atomic64_add_unchecked(rx_status.dropped_packets,
37404 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37405 #else
37406 - atomic_add(rx_status.dropped_packets,
37407 - (atomic_t *)&priv->stats.rx_dropped);
37408 + atomic_add_unchecked(rx_status.dropped_packets,
37409 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37410 #endif
37411 }
37412
37413 diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
37414 index f3c6060..56bf826 100644
37415 --- a/drivers/staging/pohmelfs/inode.c
37416 +++ b/drivers/staging/pohmelfs/inode.c
37417 @@ -1861,7 +1861,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
37418 mutex_init(&psb->mcache_lock);
37419 psb->mcache_root = RB_ROOT;
37420 psb->mcache_timeout = msecs_to_jiffies(5000);
37421 - atomic_long_set(&psb->mcache_gen, 0);
37422 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
37423
37424 psb->trans_max_pages = 100;
37425
37426 @@ -1876,7 +1876,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
37427 INIT_LIST_HEAD(&psb->crypto_ready_list);
37428 INIT_LIST_HEAD(&psb->crypto_active_list);
37429
37430 - atomic_set(&psb->trans_gen, 1);
37431 + atomic_set_unchecked(&psb->trans_gen, 1);
37432 atomic_long_set(&psb->total_inodes, 0);
37433
37434 mutex_init(&psb->state_lock);
37435 diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
37436 index e22665c..a2a9390 100644
37437 --- a/drivers/staging/pohmelfs/mcache.c
37438 +++ b/drivers/staging/pohmelfs/mcache.c
37439 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
37440 m->data = data;
37441 m->start = start;
37442 m->size = size;
37443 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
37444 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
37445
37446 mutex_lock(&psb->mcache_lock);
37447 err = pohmelfs_mcache_insert(psb, m);
37448 diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
37449 index 985b6b7..7699e05 100644
37450 --- a/drivers/staging/pohmelfs/netfs.h
37451 +++ b/drivers/staging/pohmelfs/netfs.h
37452 @@ -571,14 +571,14 @@ struct pohmelfs_config;
37453 struct pohmelfs_sb {
37454 struct rb_root mcache_root;
37455 struct mutex mcache_lock;
37456 - atomic_long_t mcache_gen;
37457 + atomic_long_unchecked_t mcache_gen;
37458 unsigned long mcache_timeout;
37459
37460 unsigned int idx;
37461
37462 unsigned int trans_retries;
37463
37464 - atomic_t trans_gen;
37465 + atomic_unchecked_t trans_gen;
37466
37467 unsigned int crypto_attached_size;
37468 unsigned int crypto_align_size;
37469 diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
37470 index 36a2535..0591bf4 100644
37471 --- a/drivers/staging/pohmelfs/trans.c
37472 +++ b/drivers/staging/pohmelfs/trans.c
37473 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
37474 int err;
37475 struct netfs_cmd *cmd = t->iovec.iov_base;
37476
37477 - t->gen = atomic_inc_return(&psb->trans_gen);
37478 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
37479
37480 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
37481 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
37482 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37483 index b70cb2b..4db41a7 100644
37484 --- a/drivers/staging/rtl8712/rtl871x_io.h
37485 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37486 @@ -83,7 +83,7 @@ struct _io_ops {
37487 u8 *pmem);
37488 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37489 u8 *pmem);
37490 -};
37491 +} __no_const;
37492
37493 struct io_req {
37494 struct list_head list;
37495 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37496 index c7b5e8b..783d6cb 100644
37497 --- a/drivers/staging/sbe-2t3e3/netdev.c
37498 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37499 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37500 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37501
37502 if (rlen)
37503 - if (copy_to_user(data, &resp, rlen))
37504 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37505 return -EFAULT;
37506
37507 return 0;
37508 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37509 index be21617..0954e45 100644
37510 --- a/drivers/staging/usbip/usbip_common.h
37511 +++ b/drivers/staging/usbip/usbip_common.h
37512 @@ -289,7 +289,7 @@ struct usbip_device {
37513 void (*shutdown)(struct usbip_device *);
37514 void (*reset)(struct usbip_device *);
37515 void (*unusable)(struct usbip_device *);
37516 - } eh_ops;
37517 + } __no_const eh_ops;
37518 };
37519
37520 #if 0
37521 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37522 index 71a586e..4d8a91a 100644
37523 --- a/drivers/staging/usbip/vhci.h
37524 +++ b/drivers/staging/usbip/vhci.h
37525 @@ -85,7 +85,7 @@ struct vhci_hcd {
37526 unsigned resuming:1;
37527 unsigned long re_timeout;
37528
37529 - atomic_t seqnum;
37530 + atomic_unchecked_t seqnum;
37531
37532 /*
37533 * NOTE:
37534 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37535 index 2ee97e2..0420b86 100644
37536 --- a/drivers/staging/usbip/vhci_hcd.c
37537 +++ b/drivers/staging/usbip/vhci_hcd.c
37538 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
37539 return;
37540 }
37541
37542 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37543 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37544 if (priv->seqnum == 0xffff)
37545 dev_info(&urb->dev->dev, "seqnum max\n");
37546
37547 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37548 return -ENOMEM;
37549 }
37550
37551 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37552 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37553 if (unlink->seqnum == 0xffff)
37554 pr_info("seqnum max\n");
37555
37556 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
37557 vdev->rhport = rhport;
37558 }
37559
37560 - atomic_set(&vhci->seqnum, 0);
37561 + atomic_set_unchecked(&vhci->seqnum, 0);
37562 spin_lock_init(&vhci->lock);
37563
37564 hcd->power_budget = 0; /* no limit */
37565 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37566 index 3872b8c..fe6d2f4 100644
37567 --- a/drivers/staging/usbip/vhci_rx.c
37568 +++ b/drivers/staging/usbip/vhci_rx.c
37569 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37570 if (!urb) {
37571 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37572 pr_info("max seqnum %d\n",
37573 - atomic_read(&the_controller->seqnum));
37574 + atomic_read_unchecked(&the_controller->seqnum));
37575 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37576 return;
37577 }
37578 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37579 index 7735027..30eed13 100644
37580 --- a/drivers/staging/vt6655/hostap.c
37581 +++ b/drivers/staging/vt6655/hostap.c
37582 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37583 *
37584 */
37585
37586 +static net_device_ops_no_const apdev_netdev_ops;
37587 +
37588 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37589 {
37590 PSDevice apdev_priv;
37591 struct net_device *dev = pDevice->dev;
37592 int ret;
37593 - const struct net_device_ops apdev_netdev_ops = {
37594 - .ndo_start_xmit = pDevice->tx_80211,
37595 - };
37596
37597 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37598
37599 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37600 *apdev_priv = *pDevice;
37601 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37602
37603 + /* only half broken now */
37604 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37605 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37606
37607 pDevice->apdev->type = ARPHRD_IEEE80211;
37608 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37609 index 51b5adf..098e320 100644
37610 --- a/drivers/staging/vt6656/hostap.c
37611 +++ b/drivers/staging/vt6656/hostap.c
37612 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37613 *
37614 */
37615
37616 +static net_device_ops_no_const apdev_netdev_ops;
37617 +
37618 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37619 {
37620 PSDevice apdev_priv;
37621 struct net_device *dev = pDevice->dev;
37622 int ret;
37623 - const struct net_device_ops apdev_netdev_ops = {
37624 - .ndo_start_xmit = pDevice->tx_80211,
37625 - };
37626
37627 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37628
37629 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37630 *apdev_priv = *pDevice;
37631 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37632
37633 + /* only half broken now */
37634 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37635 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37636
37637 pDevice->apdev->type = ARPHRD_IEEE80211;
37638 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37639 index 7843dfd..3db105f 100644
37640 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37641 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37642 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37643
37644 struct usbctlx_completor {
37645 int (*complete) (struct usbctlx_completor *);
37646 -};
37647 +} __no_const;
37648
37649 static int
37650 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37651 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37652 index 1ca66ea..76f1343 100644
37653 --- a/drivers/staging/zcache/tmem.c
37654 +++ b/drivers/staging/zcache/tmem.c
37655 @@ -39,7 +39,7 @@
37656 * A tmem host implementation must use this function to register callbacks
37657 * for memory allocation.
37658 */
37659 -static struct tmem_hostops tmem_hostops;
37660 +static tmem_hostops_no_const tmem_hostops;
37661
37662 static void tmem_objnode_tree_init(void);
37663
37664 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37665 * A tmem host implementation must use this function to register
37666 * callbacks for a page-accessible memory (PAM) implementation
37667 */
37668 -static struct tmem_pamops tmem_pamops;
37669 +static tmem_pamops_no_const tmem_pamops;
37670
37671 void tmem_register_pamops(struct tmem_pamops *m)
37672 {
37673 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37674 index ed147c4..94fc3c6 100644
37675 --- a/drivers/staging/zcache/tmem.h
37676 +++ b/drivers/staging/zcache/tmem.h
37677 @@ -180,6 +180,7 @@ struct tmem_pamops {
37678 void (*new_obj)(struct tmem_obj *);
37679 int (*replace_in_obj)(void *, struct tmem_obj *);
37680 };
37681 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37682 extern void tmem_register_pamops(struct tmem_pamops *m);
37683
37684 /* memory allocation methods provided by the host implementation */
37685 @@ -189,6 +190,7 @@ struct tmem_hostops {
37686 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37687 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37688 };
37689 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37690 extern void tmem_register_hostops(struct tmem_hostops *m);
37691
37692 /* core tmem accessor functions */
37693 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
37694 index c4ac6f6..4f90f53 100644
37695 --- a/drivers/target/iscsi/iscsi_target.c
37696 +++ b/drivers/target/iscsi/iscsi_target.c
37697 @@ -1370,7 +1370,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
37698 * outstanding_r2ts reaches zero, go ahead and send the delayed
37699 * TASK_ABORTED status.
37700 */
37701 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
37702 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
37703 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
37704 if (--cmd->outstanding_r2ts < 1) {
37705 iscsit_stop_dataout_timer(cmd);
37706 diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
37707 index 8badcb4..94c9ac6 100644
37708 --- a/drivers/target/target_core_alua.c
37709 +++ b/drivers/target/target_core_alua.c
37710 @@ -723,6 +723,8 @@ static int core_alua_update_tpg_primary_metadata(
37711 char path[ALUA_METADATA_PATH_LEN];
37712 int len;
37713
37714 + pax_track_stack();
37715 +
37716 memset(path, 0, ALUA_METADATA_PATH_LEN);
37717
37718 len = snprintf(md_buf, tg_pt_gp->tg_pt_gp_md_buf_len,
37719 @@ -986,6 +988,8 @@ static int core_alua_update_tpg_secondary_metadata(
37720 char path[ALUA_METADATA_PATH_LEN], wwn[ALUA_SECONDARY_METADATA_WWN_LEN];
37721 int len;
37722
37723 + pax_track_stack();
37724 +
37725 memset(path, 0, ALUA_METADATA_PATH_LEN);
37726 memset(wwn, 0, ALUA_SECONDARY_METADATA_WWN_LEN);
37727
37728 diff --git a/drivers/target/target_core_cdb.c b/drivers/target/target_core_cdb.c
37729 index 5f91397..dcc2d25 100644
37730 --- a/drivers/target/target_core_cdb.c
37731 +++ b/drivers/target/target_core_cdb.c
37732 @@ -933,6 +933,8 @@ target_emulate_modesense(struct se_cmd *cmd, int ten)
37733 int length = 0;
37734 unsigned char buf[SE_MODE_PAGE_BUF];
37735
37736 + pax_track_stack();
37737 +
37738 memset(buf, 0, SE_MODE_PAGE_BUF);
37739
37740 switch (cdb[2] & 0x3f) {
37741 diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
37742 index b2575d8..b6b28fd 100644
37743 --- a/drivers/target/target_core_configfs.c
37744 +++ b/drivers/target/target_core_configfs.c
37745 @@ -1267,6 +1267,8 @@ static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts(
37746 ssize_t len = 0;
37747 int reg_count = 0, prf_isid;
37748
37749 + pax_track_stack();
37750 +
37751 if (!su_dev->se_dev_ptr)
37752 return -ENODEV;
37753
37754 diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
37755 index 7fd3a16..bc2fb3e 100644
37756 --- a/drivers/target/target_core_pr.c
37757 +++ b/drivers/target/target_core_pr.c
37758 @@ -918,6 +918,8 @@ static int __core_scsi3_check_aptpl_registration(
37759 unsigned char t_port[PR_APTPL_MAX_TPORT_LEN];
37760 u16 tpgt;
37761
37762 + pax_track_stack();
37763 +
37764 memset(i_port, 0, PR_APTPL_MAX_IPORT_LEN);
37765 memset(t_port, 0, PR_APTPL_MAX_TPORT_LEN);
37766 /*
37767 @@ -1867,6 +1869,8 @@ static int __core_scsi3_update_aptpl_buf(
37768 ssize_t len = 0;
37769 int reg_count = 0;
37770
37771 + pax_track_stack();
37772 +
37773 memset(buf, 0, pr_aptpl_buf_len);
37774 /*
37775 * Called to clear metadata once APTPL has been deactivated.
37776 @@ -1989,6 +1993,8 @@ static int __core_scsi3_write_aptpl_to_file(
37777 char path[512];
37778 int ret;
37779
37780 + pax_track_stack();
37781 +
37782 memset(iov, 0, sizeof(struct iovec));
37783 memset(path, 0, 512);
37784
37785 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37786 index 5c1b8c5..0cb7d0e 100644
37787 --- a/drivers/target/target_core_tmr.c
37788 +++ b/drivers/target/target_core_tmr.c
37789 @@ -255,7 +255,7 @@ static void core_tmr_drain_task_list(
37790 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37791 cmd->t_task_list_num,
37792 atomic_read(&cmd->t_task_cdbs_left),
37793 - atomic_read(&cmd->t_task_cdbs_sent),
37794 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37795 atomic_read(&cmd->t_transport_active),
37796 atomic_read(&cmd->t_transport_stop),
37797 atomic_read(&cmd->t_transport_sent));
37798 @@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
37799 pr_debug("LUN_RESET: got t_transport_active = 1 for"
37800 " task: %p, t_fe_count: %d dev: %p\n", task,
37801 fe_count, dev);
37802 - atomic_set(&cmd->t_transport_aborted, 1);
37803 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37804 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37805
37806 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37807 @@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
37808 }
37809 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
37810 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
37811 - atomic_set(&cmd->t_transport_aborted, 1);
37812 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37813 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37814
37815 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37816 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37817 index e2added..ccb5251 100644
37818 --- a/drivers/target/target_core_transport.c
37819 +++ b/drivers/target/target_core_transport.c
37820 @@ -1445,7 +1445,7 @@ struct se_device *transport_add_device_to_core_hba(
37821
37822 dev->queue_depth = dev_limits->queue_depth;
37823 atomic_set(&dev->depth_left, dev->queue_depth);
37824 - atomic_set(&dev->dev_ordered_id, 0);
37825 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37826
37827 se_dev_set_default_attribs(dev, dev_limits);
37828
37829 @@ -1633,7 +1633,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37830 * Used to determine when ORDERED commands should go from
37831 * Dormant to Active status.
37832 */
37833 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37834 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37835 smp_mb__after_atomic_inc();
37836 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37837 cmd->se_ordered_id, cmd->sam_task_attr,
37838 @@ -1960,7 +1960,7 @@ static void transport_generic_request_failure(
37839 " t_transport_active: %d t_transport_stop: %d"
37840 " t_transport_sent: %d\n", cmd->t_task_list_num,
37841 atomic_read(&cmd->t_task_cdbs_left),
37842 - atomic_read(&cmd->t_task_cdbs_sent),
37843 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37844 atomic_read(&cmd->t_task_cdbs_ex_left),
37845 atomic_read(&cmd->t_transport_active),
37846 atomic_read(&cmd->t_transport_stop),
37847 @@ -2460,9 +2460,9 @@ check_depth:
37848 spin_lock_irqsave(&cmd->t_state_lock, flags);
37849 atomic_set(&task->task_active, 1);
37850 atomic_set(&task->task_sent, 1);
37851 - atomic_inc(&cmd->t_task_cdbs_sent);
37852 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37853
37854 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
37855 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37856 cmd->t_task_list_num)
37857 atomic_set(&cmd->transport_sent, 1);
37858
37859 @@ -4682,7 +4682,7 @@ static void transport_generic_wait_for_tasks(
37860 atomic_set(&cmd->transport_lun_stop, 0);
37861 }
37862 if (!atomic_read(&cmd->t_transport_active) ||
37863 - atomic_read(&cmd->t_transport_aborted))
37864 + atomic_read_unchecked(&cmd->t_transport_aborted))
37865 goto remove;
37866
37867 atomic_set(&cmd->t_transport_stop, 1);
37868 @@ -4917,7 +4917,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
37869 {
37870 int ret = 0;
37871
37872 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
37873 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
37874 if (!send_status ||
37875 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
37876 return 1;
37877 @@ -4954,7 +4954,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
37878 */
37879 if (cmd->data_direction == DMA_TO_DEVICE) {
37880 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
37881 - atomic_inc(&cmd->t_transport_aborted);
37882 + atomic_inc_unchecked(&cmd->t_transport_aborted);
37883 smp_mb__after_atomic_inc();
37884 cmd->scsi_status = SAM_STAT_TASK_ABORTED;
37885 transport_new_cmd_failure(cmd);
37886 @@ -5068,7 +5068,7 @@ static void transport_processing_shutdown(struct se_device *dev)
37887 cmd->se_tfo->get_task_tag(cmd),
37888 cmd->t_task_list_num,
37889 atomic_read(&cmd->t_task_cdbs_left),
37890 - atomic_read(&cmd->t_task_cdbs_sent),
37891 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37892 atomic_read(&cmd->t_transport_active),
37893 atomic_read(&cmd->t_transport_stop),
37894 atomic_read(&cmd->t_transport_sent));
37895 diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
37896 index d5f923b..9c78228 100644
37897 --- a/drivers/telephony/ixj.c
37898 +++ b/drivers/telephony/ixj.c
37899 @@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
37900 bool mContinue;
37901 char *pIn, *pOut;
37902
37903 + pax_track_stack();
37904 +
37905 if (!SCI_Prepare(j))
37906 return 0;
37907
37908 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37909 index 4c8b665..1d931eb 100644
37910 --- a/drivers/tty/hvc/hvcs.c
37911 +++ b/drivers/tty/hvc/hvcs.c
37912 @@ -83,6 +83,7 @@
37913 #include <asm/hvcserver.h>
37914 #include <asm/uaccess.h>
37915 #include <asm/vio.h>
37916 +#include <asm/local.h>
37917
37918 /*
37919 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37920 @@ -270,7 +271,7 @@ struct hvcs_struct {
37921 unsigned int index;
37922
37923 struct tty_struct *tty;
37924 - int open_count;
37925 + local_t open_count;
37926
37927 /*
37928 * Used to tell the driver kernel_thread what operations need to take
37929 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37930
37931 spin_lock_irqsave(&hvcsd->lock, flags);
37932
37933 - if (hvcsd->open_count > 0) {
37934 + if (local_read(&hvcsd->open_count) > 0) {
37935 spin_unlock_irqrestore(&hvcsd->lock, flags);
37936 printk(KERN_INFO "HVCS: vterm state unchanged. "
37937 "The hvcs device node is still in use.\n");
37938 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37939 if ((retval = hvcs_partner_connect(hvcsd)))
37940 goto error_release;
37941
37942 - hvcsd->open_count = 1;
37943 + local_set(&hvcsd->open_count, 1);
37944 hvcsd->tty = tty;
37945 tty->driver_data = hvcsd;
37946
37947 @@ -1179,7 +1180,7 @@ fast_open:
37948
37949 spin_lock_irqsave(&hvcsd->lock, flags);
37950 kref_get(&hvcsd->kref);
37951 - hvcsd->open_count++;
37952 + local_inc(&hvcsd->open_count);
37953 hvcsd->todo_mask |= HVCS_SCHED_READ;
37954 spin_unlock_irqrestore(&hvcsd->lock, flags);
37955
37956 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37957 hvcsd = tty->driver_data;
37958
37959 spin_lock_irqsave(&hvcsd->lock, flags);
37960 - if (--hvcsd->open_count == 0) {
37961 + if (local_dec_and_test(&hvcsd->open_count)) {
37962
37963 vio_disable_interrupts(hvcsd->vdev);
37964
37965 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37966 free_irq(irq, hvcsd);
37967 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37968 return;
37969 - } else if (hvcsd->open_count < 0) {
37970 + } else if (local_read(&hvcsd->open_count) < 0) {
37971 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37972 " is missmanaged.\n",
37973 - hvcsd->vdev->unit_address, hvcsd->open_count);
37974 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37975 }
37976
37977 spin_unlock_irqrestore(&hvcsd->lock, flags);
37978 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37979
37980 spin_lock_irqsave(&hvcsd->lock, flags);
37981 /* Preserve this so that we know how many kref refs to put */
37982 - temp_open_count = hvcsd->open_count;
37983 + temp_open_count = local_read(&hvcsd->open_count);
37984
37985 /*
37986 * Don't kref put inside the spinlock because the destruction
37987 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37988 hvcsd->tty->driver_data = NULL;
37989 hvcsd->tty = NULL;
37990
37991 - hvcsd->open_count = 0;
37992 + local_set(&hvcsd->open_count, 0);
37993
37994 /* This will drop any buffered data on the floor which is OK in a hangup
37995 * scenario. */
37996 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
37997 * the middle of a write operation? This is a crummy place to do this
37998 * but we want to keep it all in the spinlock.
37999 */
38000 - if (hvcsd->open_count <= 0) {
38001 + if (local_read(&hvcsd->open_count) <= 0) {
38002 spin_unlock_irqrestore(&hvcsd->lock, flags);
38003 return -ENODEV;
38004 }
38005 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38006 {
38007 struct hvcs_struct *hvcsd = tty->driver_data;
38008
38009 - if (!hvcsd || hvcsd->open_count <= 0)
38010 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
38011 return 0;
38012
38013 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38014 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38015 index ef92869..f4ebd88 100644
38016 --- a/drivers/tty/ipwireless/tty.c
38017 +++ b/drivers/tty/ipwireless/tty.c
38018 @@ -29,6 +29,7 @@
38019 #include <linux/tty_driver.h>
38020 #include <linux/tty_flip.h>
38021 #include <linux/uaccess.h>
38022 +#include <asm/local.h>
38023
38024 #include "tty.h"
38025 #include "network.h"
38026 @@ -51,7 +52,7 @@ struct ipw_tty {
38027 int tty_type;
38028 struct ipw_network *network;
38029 struct tty_struct *linux_tty;
38030 - int open_count;
38031 + local_t open_count;
38032 unsigned int control_lines;
38033 struct mutex ipw_tty_mutex;
38034 int tx_bytes_queued;
38035 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38036 mutex_unlock(&tty->ipw_tty_mutex);
38037 return -ENODEV;
38038 }
38039 - if (tty->open_count == 0)
38040 + if (local_read(&tty->open_count) == 0)
38041 tty->tx_bytes_queued = 0;
38042
38043 - tty->open_count++;
38044 + local_inc(&tty->open_count);
38045
38046 tty->linux_tty = linux_tty;
38047 linux_tty->driver_data = tty;
38048 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38049
38050 static void do_ipw_close(struct ipw_tty *tty)
38051 {
38052 - tty->open_count--;
38053 -
38054 - if (tty->open_count == 0) {
38055 + if (local_dec_return(&tty->open_count) == 0) {
38056 struct tty_struct *linux_tty = tty->linux_tty;
38057
38058 if (linux_tty != NULL) {
38059 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38060 return;
38061
38062 mutex_lock(&tty->ipw_tty_mutex);
38063 - if (tty->open_count == 0) {
38064 + if (local_read(&tty->open_count) == 0) {
38065 mutex_unlock(&tty->ipw_tty_mutex);
38066 return;
38067 }
38068 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38069 return;
38070 }
38071
38072 - if (!tty->open_count) {
38073 + if (!local_read(&tty->open_count)) {
38074 mutex_unlock(&tty->ipw_tty_mutex);
38075 return;
38076 }
38077 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38078 return -ENODEV;
38079
38080 mutex_lock(&tty->ipw_tty_mutex);
38081 - if (!tty->open_count) {
38082 + if (!local_read(&tty->open_count)) {
38083 mutex_unlock(&tty->ipw_tty_mutex);
38084 return -EINVAL;
38085 }
38086 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38087 if (!tty)
38088 return -ENODEV;
38089
38090 - if (!tty->open_count)
38091 + if (!local_read(&tty->open_count))
38092 return -EINVAL;
38093
38094 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38095 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38096 if (!tty)
38097 return 0;
38098
38099 - if (!tty->open_count)
38100 + if (!local_read(&tty->open_count))
38101 return 0;
38102
38103 return tty->tx_bytes_queued;
38104 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38105 if (!tty)
38106 return -ENODEV;
38107
38108 - if (!tty->open_count)
38109 + if (!local_read(&tty->open_count))
38110 return -EINVAL;
38111
38112 return get_control_lines(tty);
38113 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38114 if (!tty)
38115 return -ENODEV;
38116
38117 - if (!tty->open_count)
38118 + if (!local_read(&tty->open_count))
38119 return -EINVAL;
38120
38121 return set_control_lines(tty, set, clear);
38122 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38123 if (!tty)
38124 return -ENODEV;
38125
38126 - if (!tty->open_count)
38127 + if (!local_read(&tty->open_count))
38128 return -EINVAL;
38129
38130 /* FIXME: Exactly how is the tty object locked here .. */
38131 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38132 against a parallel ioctl etc */
38133 mutex_lock(&ttyj->ipw_tty_mutex);
38134 }
38135 - while (ttyj->open_count)
38136 + while (local_read(&ttyj->open_count))
38137 do_ipw_close(ttyj);
38138 ipwireless_disassociate_network_ttys(network,
38139 ttyj->channel_idx);
38140 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38141 index 8a50e4e..7d9ca3d 100644
38142 --- a/drivers/tty/n_gsm.c
38143 +++ b/drivers/tty/n_gsm.c
38144 @@ -1625,7 +1625,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38145 kref_init(&dlci->ref);
38146 mutex_init(&dlci->mutex);
38147 dlci->fifo = &dlci->_fifo;
38148 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38149 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38150 kfree(dlci);
38151 return NULL;
38152 }
38153 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38154 index 39d6ab6..eb97f41 100644
38155 --- a/drivers/tty/n_tty.c
38156 +++ b/drivers/tty/n_tty.c
38157 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38158 {
38159 *ops = tty_ldisc_N_TTY;
38160 ops->owner = NULL;
38161 - ops->refcount = ops->flags = 0;
38162 + atomic_set(&ops->refcount, 0);
38163 + ops->flags = 0;
38164 }
38165 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38166 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38167 index e18604b..a7d5a11 100644
38168 --- a/drivers/tty/pty.c
38169 +++ b/drivers/tty/pty.c
38170 @@ -773,8 +773,10 @@ static void __init unix98_pty_init(void)
38171 register_sysctl_table(pty_root_table);
38172
38173 /* Now create the /dev/ptmx special device */
38174 + pax_open_kernel();
38175 tty_default_fops(&ptmx_fops);
38176 - ptmx_fops.open = ptmx_open;
38177 + *(void **)&ptmx_fops.open = ptmx_open;
38178 + pax_close_kernel();
38179
38180 cdev_init(&ptmx_cdev, &ptmx_fops);
38181 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38182 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38183 index 6a1241c..d04ab0d 100644
38184 --- a/drivers/tty/rocket.c
38185 +++ b/drivers/tty/rocket.c
38186 @@ -1277,6 +1277,8 @@ static int get_ports(struct r_port *info, struct rocket_ports __user *retports)
38187 struct rocket_ports tmp;
38188 int board;
38189
38190 + pax_track_stack();
38191 +
38192 if (!retports)
38193 return -EFAULT;
38194 memset(&tmp, 0, sizeof (tmp));
38195 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38196 index 87e7e6c..89744e0 100644
38197 --- a/drivers/tty/serial/kgdboc.c
38198 +++ b/drivers/tty/serial/kgdboc.c
38199 @@ -23,8 +23,9 @@
38200 #define MAX_CONFIG_LEN 40
38201
38202 static struct kgdb_io kgdboc_io_ops;
38203 +static struct kgdb_io kgdboc_io_ops_console;
38204
38205 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38206 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38207 static int configured = -1;
38208
38209 static char config[MAX_CONFIG_LEN];
38210 @@ -147,6 +148,8 @@ static void cleanup_kgdboc(void)
38211 kgdboc_unregister_kbd();
38212 if (configured == 1)
38213 kgdb_unregister_io_module(&kgdboc_io_ops);
38214 + else if (configured == 2)
38215 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38216 }
38217
38218 static int configure_kgdboc(void)
38219 @@ -156,13 +159,13 @@ static int configure_kgdboc(void)
38220 int err;
38221 char *cptr = config;
38222 struct console *cons;
38223 + int is_console = 0;
38224
38225 err = kgdboc_option_setup(config);
38226 if (err || !strlen(config) || isspace(config[0]))
38227 goto noconfig;
38228
38229 err = -ENODEV;
38230 - kgdboc_io_ops.is_console = 0;
38231 kgdb_tty_driver = NULL;
38232
38233 kgdboc_use_kms = 0;
38234 @@ -183,7 +186,7 @@ static int configure_kgdboc(void)
38235 int idx;
38236 if (cons->device && cons->device(cons, &idx) == p &&
38237 idx == tty_line) {
38238 - kgdboc_io_ops.is_console = 1;
38239 + is_console = 1;
38240 break;
38241 }
38242 cons = cons->next;
38243 @@ -193,12 +196,16 @@ static int configure_kgdboc(void)
38244 kgdb_tty_line = tty_line;
38245
38246 do_register:
38247 - err = kgdb_register_io_module(&kgdboc_io_ops);
38248 + if (is_console) {
38249 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38250 + configured = 2;
38251 + } else {
38252 + err = kgdb_register_io_module(&kgdboc_io_ops);
38253 + configured = 1;
38254 + }
38255 if (err)
38256 goto noconfig;
38257
38258 - configured = 1;
38259 -
38260 return 0;
38261
38262 noconfig:
38263 @@ -212,7 +219,7 @@ noconfig:
38264 static int __init init_kgdboc(void)
38265 {
38266 /* Already configured? */
38267 - if (configured == 1)
38268 + if (configured >= 1)
38269 return 0;
38270
38271 return configure_kgdboc();
38272 @@ -261,7 +268,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38273 if (config[len - 1] == '\n')
38274 config[len - 1] = '\0';
38275
38276 - if (configured == 1)
38277 + if (configured >= 1)
38278 cleanup_kgdboc();
38279
38280 /* Go and configure with the new params. */
38281 @@ -301,6 +308,15 @@ static struct kgdb_io kgdboc_io_ops = {
38282 .post_exception = kgdboc_post_exp_handler,
38283 };
38284
38285 +static struct kgdb_io kgdboc_io_ops_console = {
38286 + .name = "kgdboc",
38287 + .read_char = kgdboc_get_char,
38288 + .write_char = kgdboc_put_char,
38289 + .pre_exception = kgdboc_pre_exp_handler,
38290 + .post_exception = kgdboc_post_exp_handler,
38291 + .is_console = 1
38292 +};
38293 +
38294 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38295 /* This is only available if kgdboc is a built in for early debugging */
38296 static int __init kgdboc_early_init(char *opt)
38297 diff --git a/drivers/tty/serial/mfd.c b/drivers/tty/serial/mfd.c
38298 index cab52f4..29fc6aa 100644
38299 --- a/drivers/tty/serial/mfd.c
38300 +++ b/drivers/tty/serial/mfd.c
38301 @@ -1423,7 +1423,7 @@ static void serial_hsu_remove(struct pci_dev *pdev)
38302 }
38303
38304 /* First 3 are UART ports, and the 4th is the DMA */
38305 -static const struct pci_device_id pci_ids[] __devinitdata = {
38306 +static const struct pci_device_id pci_ids[] __devinitconst = {
38307 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081B) },
38308 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081C) },
38309 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081D) },
38310 diff --git a/drivers/tty/serial/mrst_max3110.c b/drivers/tty/serial/mrst_max3110.c
38311 index 23bc743..d425c07 100644
38312 --- a/drivers/tty/serial/mrst_max3110.c
38313 +++ b/drivers/tty/serial/mrst_max3110.c
38314 @@ -393,6 +393,8 @@ static void max3110_con_receive(struct uart_max3110 *max)
38315 int loop = 1, num, total = 0;
38316 u8 recv_buf[512], *pbuf;
38317
38318 + pax_track_stack();
38319 +
38320 pbuf = recv_buf;
38321 do {
38322 num = max3110_read_multi(max, pbuf);
38323 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38324 index 1a890e2..1d8139c 100644
38325 --- a/drivers/tty/tty_io.c
38326 +++ b/drivers/tty/tty_io.c
38327 @@ -3238,7 +3238,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38328
38329 void tty_default_fops(struct file_operations *fops)
38330 {
38331 - *fops = tty_fops;
38332 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38333 }
38334
38335 /*
38336 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38337 index a76c808..ecbc743 100644
38338 --- a/drivers/tty/tty_ldisc.c
38339 +++ b/drivers/tty/tty_ldisc.c
38340 @@ -75,7 +75,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38341 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38342 struct tty_ldisc_ops *ldo = ld->ops;
38343
38344 - ldo->refcount--;
38345 + atomic_dec(&ldo->refcount);
38346 module_put(ldo->owner);
38347 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38348
38349 @@ -110,7 +110,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38350 spin_lock_irqsave(&tty_ldisc_lock, flags);
38351 tty_ldiscs[disc] = new_ldisc;
38352 new_ldisc->num = disc;
38353 - new_ldisc->refcount = 0;
38354 + atomic_set(&new_ldisc->refcount, 0);
38355 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38356
38357 return ret;
38358 @@ -138,7 +138,7 @@ int tty_unregister_ldisc(int disc)
38359 return -EINVAL;
38360
38361 spin_lock_irqsave(&tty_ldisc_lock, flags);
38362 - if (tty_ldiscs[disc]->refcount)
38363 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38364 ret = -EBUSY;
38365 else
38366 tty_ldiscs[disc] = NULL;
38367 @@ -159,7 +159,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38368 if (ldops) {
38369 ret = ERR_PTR(-EAGAIN);
38370 if (try_module_get(ldops->owner)) {
38371 - ldops->refcount++;
38372 + atomic_inc(&ldops->refcount);
38373 ret = ldops;
38374 }
38375 }
38376 @@ -172,7 +172,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38377 unsigned long flags;
38378
38379 spin_lock_irqsave(&tty_ldisc_lock, flags);
38380 - ldops->refcount--;
38381 + atomic_dec(&ldops->refcount);
38382 module_put(ldops->owner);
38383 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38384 }
38385 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38386 index 3761ccf..2c613b3 100644
38387 --- a/drivers/tty/vt/keyboard.c
38388 +++ b/drivers/tty/vt/keyboard.c
38389 @@ -656,6 +656,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38390 kbd->kbdmode == VC_OFF) &&
38391 value != KVAL(K_SAK))
38392 return; /* SAK is allowed even in raw mode */
38393 +
38394 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38395 + {
38396 + void *func = fn_handler[value];
38397 + if (func == fn_show_state || func == fn_show_ptregs ||
38398 + func == fn_show_mem)
38399 + return;
38400 + }
38401 +#endif
38402 +
38403 fn_handler[value](vc);
38404 }
38405
38406 diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
38407 index b3915b7..e716839 100644
38408 --- a/drivers/tty/vt/vt.c
38409 +++ b/drivers/tty/vt/vt.c
38410 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier);
38411
38412 static void notify_write(struct vc_data *vc, unsigned int unicode)
38413 {
38414 - struct vt_notifier_param param = { .vc = vc, unicode = unicode };
38415 + struct vt_notifier_param param = { .vc = vc, .c = unicode };
38416 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
38417 }
38418
38419 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
38420 index 5e096f4..0da1363 100644
38421 --- a/drivers/tty/vt/vt_ioctl.c
38422 +++ b/drivers/tty/vt/vt_ioctl.c
38423 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38424 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38425 return -EFAULT;
38426
38427 - if (!capable(CAP_SYS_TTY_CONFIG))
38428 - perm = 0;
38429 -
38430 switch (cmd) {
38431 case KDGKBENT:
38432 key_map = key_maps[s];
38433 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38434 val = (i ? K_HOLE : K_NOSUCHMAP);
38435 return put_user(val, &user_kbe->kb_value);
38436 case KDSKBENT:
38437 + if (!capable(CAP_SYS_TTY_CONFIG))
38438 + perm = 0;
38439 +
38440 if (!perm)
38441 return -EPERM;
38442 if (!i && v == K_NOSUCHMAP) {
38443 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38444 int i, j, k;
38445 int ret;
38446
38447 - if (!capable(CAP_SYS_TTY_CONFIG))
38448 - perm = 0;
38449 -
38450 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38451 if (!kbs) {
38452 ret = -ENOMEM;
38453 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38454 kfree(kbs);
38455 return ((p && *p) ? -EOVERFLOW : 0);
38456 case KDSKBSENT:
38457 + if (!capable(CAP_SYS_TTY_CONFIG))
38458 + perm = 0;
38459 +
38460 if (!perm) {
38461 ret = -EPERM;
38462 goto reterr;
38463 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38464 index d2efe82..9440ab6 100644
38465 --- a/drivers/uio/uio.c
38466 +++ b/drivers/uio/uio.c
38467 @@ -25,6 +25,7 @@
38468 #include <linux/kobject.h>
38469 #include <linux/cdev.h>
38470 #include <linux/uio_driver.h>
38471 +#include <asm/local.h>
38472
38473 #define UIO_MAX_DEVICES (1U << MINORBITS)
38474
38475 @@ -32,10 +33,10 @@ struct uio_device {
38476 struct module *owner;
38477 struct device *dev;
38478 int minor;
38479 - atomic_t event;
38480 + atomic_unchecked_t event;
38481 struct fasync_struct *async_queue;
38482 wait_queue_head_t wait;
38483 - int vma_count;
38484 + local_t vma_count;
38485 struct uio_info *info;
38486 struct kobject *map_dir;
38487 struct kobject *portio_dir;
38488 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38489 struct device_attribute *attr, char *buf)
38490 {
38491 struct uio_device *idev = dev_get_drvdata(dev);
38492 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38493 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38494 }
38495
38496 static struct device_attribute uio_class_attributes[] = {
38497 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38498 {
38499 struct uio_device *idev = info->uio_dev;
38500
38501 - atomic_inc(&idev->event);
38502 + atomic_inc_unchecked(&idev->event);
38503 wake_up_interruptible(&idev->wait);
38504 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38505 }
38506 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38507 }
38508
38509 listener->dev = idev;
38510 - listener->event_count = atomic_read(&idev->event);
38511 + listener->event_count = atomic_read_unchecked(&idev->event);
38512 filep->private_data = listener;
38513
38514 if (idev->info->open) {
38515 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38516 return -EIO;
38517
38518 poll_wait(filep, &idev->wait, wait);
38519 - if (listener->event_count != atomic_read(&idev->event))
38520 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38521 return POLLIN | POLLRDNORM;
38522 return 0;
38523 }
38524 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38525 do {
38526 set_current_state(TASK_INTERRUPTIBLE);
38527
38528 - event_count = atomic_read(&idev->event);
38529 + event_count = atomic_read_unchecked(&idev->event);
38530 if (event_count != listener->event_count) {
38531 if (copy_to_user(buf, &event_count, count))
38532 retval = -EFAULT;
38533 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38534 static void uio_vma_open(struct vm_area_struct *vma)
38535 {
38536 struct uio_device *idev = vma->vm_private_data;
38537 - idev->vma_count++;
38538 + local_inc(&idev->vma_count);
38539 }
38540
38541 static void uio_vma_close(struct vm_area_struct *vma)
38542 {
38543 struct uio_device *idev = vma->vm_private_data;
38544 - idev->vma_count--;
38545 + local_dec(&idev->vma_count);
38546 }
38547
38548 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38549 @@ -823,7 +824,7 @@ int __uio_register_device(struct module *owner,
38550 idev->owner = owner;
38551 idev->info = info;
38552 init_waitqueue_head(&idev->wait);
38553 - atomic_set(&idev->event, 0);
38554 + atomic_set_unchecked(&idev->event, 0);
38555
38556 ret = uio_get_minor(idev);
38557 if (ret)
38558 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38559 index a845f8b..4f54072 100644
38560 --- a/drivers/usb/atm/cxacru.c
38561 +++ b/drivers/usb/atm/cxacru.c
38562 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38563 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38564 if (ret < 2)
38565 return -EINVAL;
38566 - if (index < 0 || index > 0x7f)
38567 + if (index > 0x7f)
38568 return -EINVAL;
38569 pos += tmp;
38570
38571 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38572 index d3448ca..d2864ca 100644
38573 --- a/drivers/usb/atm/usbatm.c
38574 +++ b/drivers/usb/atm/usbatm.c
38575 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38576 if (printk_ratelimit())
38577 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38578 __func__, vpi, vci);
38579 - atomic_inc(&vcc->stats->rx_err);
38580 + atomic_inc_unchecked(&vcc->stats->rx_err);
38581 return;
38582 }
38583
38584 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38585 if (length > ATM_MAX_AAL5_PDU) {
38586 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38587 __func__, length, vcc);
38588 - atomic_inc(&vcc->stats->rx_err);
38589 + atomic_inc_unchecked(&vcc->stats->rx_err);
38590 goto out;
38591 }
38592
38593 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38594 if (sarb->len < pdu_length) {
38595 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38596 __func__, pdu_length, sarb->len, vcc);
38597 - atomic_inc(&vcc->stats->rx_err);
38598 + atomic_inc_unchecked(&vcc->stats->rx_err);
38599 goto out;
38600 }
38601
38602 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38603 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38604 __func__, vcc);
38605 - atomic_inc(&vcc->stats->rx_err);
38606 + atomic_inc_unchecked(&vcc->stats->rx_err);
38607 goto out;
38608 }
38609
38610 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38611 if (printk_ratelimit())
38612 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38613 __func__, length);
38614 - atomic_inc(&vcc->stats->rx_drop);
38615 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38616 goto out;
38617 }
38618
38619 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38620
38621 vcc->push(vcc, skb);
38622
38623 - atomic_inc(&vcc->stats->rx);
38624 + atomic_inc_unchecked(&vcc->stats->rx);
38625 out:
38626 skb_trim(sarb, 0);
38627 }
38628 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38629 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38630
38631 usbatm_pop(vcc, skb);
38632 - atomic_inc(&vcc->stats->tx);
38633 + atomic_inc_unchecked(&vcc->stats->tx);
38634
38635 skb = skb_dequeue(&instance->sndqueue);
38636 }
38637 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38638 if (!left--)
38639 return sprintf(page,
38640 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38641 - atomic_read(&atm_dev->stats.aal5.tx),
38642 - atomic_read(&atm_dev->stats.aal5.tx_err),
38643 - atomic_read(&atm_dev->stats.aal5.rx),
38644 - atomic_read(&atm_dev->stats.aal5.rx_err),
38645 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38646 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38647 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38648 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38649 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38650 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38651
38652 if (!left--) {
38653 if (instance->disconnected)
38654 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38655 index 0149c09..f108812 100644
38656 --- a/drivers/usb/core/devices.c
38657 +++ b/drivers/usb/core/devices.c
38658 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38659 * time it gets called.
38660 */
38661 static struct device_connect_event {
38662 - atomic_t count;
38663 + atomic_unchecked_t count;
38664 wait_queue_head_t wait;
38665 } device_event = {
38666 .count = ATOMIC_INIT(1),
38667 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38668
38669 void usbfs_conn_disc_event(void)
38670 {
38671 - atomic_add(2, &device_event.count);
38672 + atomic_add_unchecked(2, &device_event.count);
38673 wake_up(&device_event.wait);
38674 }
38675
38676 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38677
38678 poll_wait(file, &device_event.wait, wait);
38679
38680 - event_count = atomic_read(&device_event.count);
38681 + event_count = atomic_read_unchecked(&device_event.count);
38682 if (file->f_version != event_count) {
38683 file->f_version = event_count;
38684 return POLLIN | POLLRDNORM;
38685 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
38686 index 0b5ec23..0da3d76 100644
38687 --- a/drivers/usb/core/message.c
38688 +++ b/drivers/usb/core/message.c
38689 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
38690 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
38691 if (buf) {
38692 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
38693 - if (len > 0) {
38694 - smallbuf = kmalloc(++len, GFP_NOIO);
38695 + if (len++ > 0) {
38696 + smallbuf = kmalloc(len, GFP_NOIO);
38697 if (!smallbuf)
38698 return buf;
38699 memcpy(smallbuf, buf, len);
38700 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38701 index 1fc8f12..20647c1 100644
38702 --- a/drivers/usb/early/ehci-dbgp.c
38703 +++ b/drivers/usb/early/ehci-dbgp.c
38704 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38705
38706 #ifdef CONFIG_KGDB
38707 static struct kgdb_io kgdbdbgp_io_ops;
38708 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38709 +static struct kgdb_io kgdbdbgp_io_ops_console;
38710 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38711 #else
38712 #define dbgp_kgdb_mode (0)
38713 #endif
38714 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38715 .write_char = kgdbdbgp_write_char,
38716 };
38717
38718 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38719 + .name = "kgdbdbgp",
38720 + .read_char = kgdbdbgp_read_char,
38721 + .write_char = kgdbdbgp_write_char,
38722 + .is_console = 1
38723 +};
38724 +
38725 static int kgdbdbgp_wait_time;
38726
38727 static int __init kgdbdbgp_parse_config(char *str)
38728 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38729 ptr++;
38730 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38731 }
38732 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38733 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38734 + if (early_dbgp_console.index != -1)
38735 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38736 + else
38737 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38738
38739 return 0;
38740 }
38741 diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
38742 index d718033..6075579 100644
38743 --- a/drivers/usb/host/xhci-mem.c
38744 +++ b/drivers/usb/host/xhci-mem.c
38745 @@ -1685,6 +1685,8 @@ static int xhci_check_trb_in_td_math(struct xhci_hcd *xhci, gfp_t mem_flags)
38746 unsigned int num_tests;
38747 int i, ret;
38748
38749 + pax_track_stack();
38750 +
38751 num_tests = ARRAY_SIZE(simple_test_vector);
38752 for (i = 0; i < num_tests; i++) {
38753 ret = xhci_test_trb_in_td(xhci,
38754 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38755 index d6bea3e..60b250e 100644
38756 --- a/drivers/usb/wusbcore/wa-hc.h
38757 +++ b/drivers/usb/wusbcore/wa-hc.h
38758 @@ -192,7 +192,7 @@ struct wahc {
38759 struct list_head xfer_delayed_list;
38760 spinlock_t xfer_list_lock;
38761 struct work_struct xfer_work;
38762 - atomic_t xfer_id_count;
38763 + atomic_unchecked_t xfer_id_count;
38764 };
38765
38766
38767 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38768 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38769 spin_lock_init(&wa->xfer_list_lock);
38770 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38771 - atomic_set(&wa->xfer_id_count, 1);
38772 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38773 }
38774
38775 /**
38776 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38777 index 4193345..49ae93d 100644
38778 --- a/drivers/usb/wusbcore/wa-xfer.c
38779 +++ b/drivers/usb/wusbcore/wa-xfer.c
38780 @@ -295,7 +295,7 @@ out:
38781 */
38782 static void wa_xfer_id_init(struct wa_xfer *xfer)
38783 {
38784 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38785 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38786 }
38787
38788 /*
38789 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38790 index c14c42b..f955cc2 100644
38791 --- a/drivers/vhost/vhost.c
38792 +++ b/drivers/vhost/vhost.c
38793 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38794 return 0;
38795 }
38796
38797 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38798 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38799 {
38800 struct file *eventfp, *filep = NULL,
38801 *pollstart = NULL, *pollstop = NULL;
38802 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38803 index b0b2ac3..89a4399 100644
38804 --- a/drivers/video/aty/aty128fb.c
38805 +++ b/drivers/video/aty/aty128fb.c
38806 @@ -148,7 +148,7 @@ enum {
38807 };
38808
38809 /* Must match above enum */
38810 -static const char *r128_family[] __devinitdata = {
38811 +static const char *r128_family[] __devinitconst = {
38812 "AGP",
38813 "PCI",
38814 "PRO AGP",
38815 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38816 index 5c3960d..15cf8fc 100644
38817 --- a/drivers/video/fbcmap.c
38818 +++ b/drivers/video/fbcmap.c
38819 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38820 rc = -ENODEV;
38821 goto out;
38822 }
38823 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38824 - !info->fbops->fb_setcmap)) {
38825 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38826 rc = -EINVAL;
38827 goto out1;
38828 }
38829 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38830 index ad93629..ca6a218 100644
38831 --- a/drivers/video/fbmem.c
38832 +++ b/drivers/video/fbmem.c
38833 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38834 image->dx += image->width + 8;
38835 }
38836 } else if (rotate == FB_ROTATE_UD) {
38837 - for (x = 0; x < num && image->dx >= 0; x++) {
38838 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38839 info->fbops->fb_imageblit(info, image);
38840 image->dx -= image->width + 8;
38841 }
38842 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38843 image->dy += image->height + 8;
38844 }
38845 } else if (rotate == FB_ROTATE_CCW) {
38846 - for (x = 0; x < num && image->dy >= 0; x++) {
38847 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38848 info->fbops->fb_imageblit(info, image);
38849 image->dy -= image->height + 8;
38850 }
38851 @@ -939,6 +939,8 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
38852 int flags = info->flags;
38853 int ret = 0;
38854
38855 + pax_track_stack();
38856 +
38857 if (var->activate & FB_ACTIVATE_INV_MODE) {
38858 struct fb_videomode mode1, mode2;
38859
38860 @@ -1064,6 +1066,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38861 void __user *argp = (void __user *)arg;
38862 long ret = 0;
38863
38864 + pax_track_stack();
38865 +
38866 switch (cmd) {
38867 case FBIOGET_VSCREENINFO:
38868 if (!lock_fb_info(info))
38869 @@ -1143,7 +1147,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38870 return -EFAULT;
38871 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38872 return -EINVAL;
38873 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38874 + if (con2fb.framebuffer >= FB_MAX)
38875 return -EINVAL;
38876 if (!registered_fb[con2fb.framebuffer])
38877 request_module("fb%d", con2fb.framebuffer);
38878 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38879 index 5a5d092..265c5ed 100644
38880 --- a/drivers/video/geode/gx1fb_core.c
38881 +++ b/drivers/video/geode/gx1fb_core.c
38882 @@ -29,7 +29,7 @@ static int crt_option = 1;
38883 static char panel_option[32] = "";
38884
38885 /* Modes relevant to the GX1 (taken from modedb.c) */
38886 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
38887 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
38888 /* 640x480-60 VESA */
38889 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38890 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38891 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38892 index 896e53d..4d87d0b 100644
38893 --- a/drivers/video/gxt4500.c
38894 +++ b/drivers/video/gxt4500.c
38895 @@ -156,7 +156,7 @@ struct gxt4500_par {
38896 static char *mode_option;
38897
38898 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38899 -static const struct fb_videomode defaultmode __devinitdata = {
38900 +static const struct fb_videomode defaultmode __devinitconst = {
38901 .refresh = 60,
38902 .xres = 1280,
38903 .yres = 1024,
38904 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38905 return 0;
38906 }
38907
38908 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38909 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38910 .id = "IBM GXT4500P",
38911 .type = FB_TYPE_PACKED_PIXELS,
38912 .visual = FB_VISUAL_PSEUDOCOLOR,
38913 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38914 index 7672d2e..b56437f 100644
38915 --- a/drivers/video/i810/i810_accel.c
38916 +++ b/drivers/video/i810/i810_accel.c
38917 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38918 }
38919 }
38920 printk("ringbuffer lockup!!!\n");
38921 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38922 i810_report_error(mmio);
38923 par->dev_flags |= LOCKUP;
38924 info->pixmap.scan_align = 1;
38925 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38926 index 318f6fb..9a389c1 100644
38927 --- a/drivers/video/i810/i810_main.c
38928 +++ b/drivers/video/i810/i810_main.c
38929 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38930 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38931
38932 /* PCI */
38933 -static const char *i810_pci_list[] __devinitdata = {
38934 +static const char *i810_pci_list[] __devinitconst = {
38935 "Intel(R) 810 Framebuffer Device" ,
38936 "Intel(R) 810-DC100 Framebuffer Device" ,
38937 "Intel(R) 810E Framebuffer Device" ,
38938 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38939 index de36693..3c63fc2 100644
38940 --- a/drivers/video/jz4740_fb.c
38941 +++ b/drivers/video/jz4740_fb.c
38942 @@ -136,7 +136,7 @@ struct jzfb {
38943 uint32_t pseudo_palette[16];
38944 };
38945
38946 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38947 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38948 .id = "JZ4740 FB",
38949 .type = FB_TYPE_PACKED_PIXELS,
38950 .visual = FB_VISUAL_TRUECOLOR,
38951 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38952 index 3c14e43..eafa544 100644
38953 --- a/drivers/video/logo/logo_linux_clut224.ppm
38954 +++ b/drivers/video/logo/logo_linux_clut224.ppm
38955 @@ -1,1604 +1,1123 @@
38956 P3
38957 -# Standard 224-color Linux logo
38958 80 80
38959 255
38960 - 0 0 0 0 0 0 0 0 0 0 0 0
38961 - 0 0 0 0 0 0 0 0 0 0 0 0
38962 - 0 0 0 0 0 0 0 0 0 0 0 0
38963 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 6 6 6 10 10 10 10 10 10
38970 - 10 10 10 6 6 6 6 6 6 6 6 6
38971 - 0 0 0 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 0 0 0
38977 - 0 0 0 0 0 0 0 0 0 0 0 0
38978 - 0 0 0 0 0 0 0 0 0 0 0 0
38979 - 0 0 0 0 0 0 0 0 0 0 0 0
38980 - 0 0 0 0 0 0 0 0 0 0 0 0
38981 - 0 0 0 0 0 0 0 0 0 0 0 0
38982 - 0 0 0 0 0 0 0 0 0 0 0 0
38983 - 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
38989 - 22 22 22 26 26 26 30 30 30 34 34 34
38990 - 30 30 30 30 30 30 26 26 26 18 18 18
38991 - 14 14 14 10 10 10 6 6 6 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 0 0 0
38997 - 0 0 0 0 0 0 0 0 0 0 0 0
38998 - 0 0 0 0 0 0 0 0 0 0 0 0
38999 - 0 0 0 0 0 0 0 0 0 0 0 0
39000 - 0 0 0 0 0 0 0 0 0 0 0 0
39001 - 0 0 0 0 0 1 0 0 1 0 0 0
39002 - 0 0 0 0 0 0 0 0 0 0 0 0
39003 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 14 14 14 26 26 26 42 42 42
39009 - 54 54 54 66 66 66 78 78 78 78 78 78
39010 - 78 78 78 74 74 74 66 66 66 54 54 54
39011 - 42 42 42 26 26 26 18 18 18 10 10 10
39012 - 6 6 6 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 0 0 0
39017 - 0 0 0 0 0 0 0 0 0 0 0 0
39018 - 0 0 0 0 0 0 0 0 0 0 0 0
39019 - 0 0 0 0 0 0 0 0 0 0 0 0
39020 - 0 0 0 0 0 0 0 0 0 0 0 0
39021 - 0 0 1 0 0 0 0 0 0 0 0 0
39022 - 0 0 0 0 0 0 0 0 0 0 0 0
39023 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39028 - 22 22 22 42 42 42 66 66 66 86 86 86
39029 - 66 66 66 38 38 38 38 38 38 22 22 22
39030 - 26 26 26 34 34 34 54 54 54 66 66 66
39031 - 86 86 86 70 70 70 46 46 46 26 26 26
39032 - 14 14 14 6 6 6 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 0 0 0
39037 - 0 0 0 0 0 0 0 0 0 0 0 0
39038 - 0 0 0 0 0 0 0 0 0 0 0 0
39039 - 0 0 0 0 0 0 0 0 0 0 0 0
39040 - 0 0 0 0 0 0 0 0 0 0 0 0
39041 - 0 0 1 0 0 1 0 0 1 0 0 0
39042 - 0 0 0 0 0 0 0 0 0 0 0 0
39043 - 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
39048 - 50 50 50 82 82 82 58 58 58 6 6 6
39049 - 2 2 6 2 2 6 2 2 6 2 2 6
39050 - 2 2 6 2 2 6 2 2 6 2 2 6
39051 - 6 6 6 54 54 54 86 86 86 66 66 66
39052 - 38 38 38 18 18 18 6 6 6 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 0 0 0
39057 - 0 0 0 0 0 0 0 0 0 0 0 0
39058 - 0 0 0 0 0 0 0 0 0 0 0 0
39059 - 0 0 0 0 0 0 0 0 0 0 0 0
39060 - 0 0 0 0 0 0 0 0 0 0 0 0
39061 - 0 0 0 0 0 0 0 0 0 0 0 0
39062 - 0 0 0 0 0 0 0 0 0 0 0 0
39063 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 22 22 22 50 50 50
39068 - 78 78 78 34 34 34 2 2 6 2 2 6
39069 - 2 2 6 2 2 6 2 2 6 2 2 6
39070 - 2 2 6 2 2 6 2 2 6 2 2 6
39071 - 2 2 6 2 2 6 6 6 6 70 70 70
39072 - 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0
39077 - 0 0 0 0 0 0 0 0 0 0 0 0
39078 - 0 0 0 0 0 0 0 0 0 0 0 0
39079 - 0 0 0 0 0 0 0 0 0 0 0 0
39080 - 0 0 0 0 0 0 0 0 0 0 0 0
39081 - 0 0 1 0 0 1 0 0 1 0 0 0
39082 - 0 0 0 0 0 0 0 0 0 0 0 0
39083 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 18 18 18 42 42 42 82 82 82
39088 - 26 26 26 2 2 6 2 2 6 2 2 6
39089 - 2 2 6 2 2 6 2 2 6 2 2 6
39090 - 2 2 6 2 2 6 2 2 6 14 14 14
39091 - 46 46 46 34 34 34 6 6 6 2 2 6
39092 - 42 42 42 78 78 78 42 42 42 18 18 18
39093 - 6 6 6 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 0 0 0
39097 - 0 0 0 0 0 0 0 0 0 0 0 0
39098 - 0 0 0 0 0 0 0 0 0 0 0 0
39099 - 0 0 0 0 0 0 0 0 0 0 0 0
39100 - 0 0 0 0 0 0 0 0 0 0 0 0
39101 - 0 0 1 0 0 0 0 0 1 0 0 0
39102 - 0 0 0 0 0 0 0 0 0 0 0 0
39103 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 10 10 10 30 30 30 66 66 66 58 58 58
39108 - 2 2 6 2 2 6 2 2 6 2 2 6
39109 - 2 2 6 2 2 6 2 2 6 2 2 6
39110 - 2 2 6 2 2 6 2 2 6 26 26 26
39111 - 86 86 86 101 101 101 46 46 46 10 10 10
39112 - 2 2 6 58 58 58 70 70 70 34 34 34
39113 - 10 10 10 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 0 0 0
39117 - 0 0 0 0 0 0 0 0 0 0 0 0
39118 - 0 0 0 0 0 0 0 0 0 0 0 0
39119 - 0 0 0 0 0 0 0 0 0 0 0 0
39120 - 0 0 0 0 0 0 0 0 0 0 0 0
39121 - 0 0 1 0 0 1 0 0 1 0 0 0
39122 - 0 0 0 0 0 0 0 0 0 0 0 0
39123 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 14 14 14 42 42 42 86 86 86 10 10 10
39128 - 2 2 6 2 2 6 2 2 6 2 2 6
39129 - 2 2 6 2 2 6 2 2 6 2 2 6
39130 - 2 2 6 2 2 6 2 2 6 30 30 30
39131 - 94 94 94 94 94 94 58 58 58 26 26 26
39132 - 2 2 6 6 6 6 78 78 78 54 54 54
39133 - 22 22 22 6 6 6 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 0 0 0
39137 - 0 0 0 0 0 0 0 0 0 0 0 0
39138 - 0 0 0 0 0 0 0 0 0 0 0 0
39139 - 0 0 0 0 0 0 0 0 0 0 0 0
39140 - 0 0 0 0 0 0 0 0 0 0 0 0
39141 - 0 0 0 0 0 0 0 0 0 0 0 0
39142 - 0 0 0 0 0 0 0 0 0 0 0 0
39143 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
39147 - 22 22 22 62 62 62 62 62 62 2 2 6
39148 - 2 2 6 2 2 6 2 2 6 2 2 6
39149 - 2 2 6 2 2 6 2 2 6 2 2 6
39150 - 2 2 6 2 2 6 2 2 6 26 26 26
39151 - 54 54 54 38 38 38 18 18 18 10 10 10
39152 - 2 2 6 2 2 6 34 34 34 82 82 82
39153 - 38 38 38 14 14 14 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 0 0 0
39157 - 0 0 0 0 0 0 0 0 0 0 0 0
39158 - 0 0 0 0 0 0 0 0 0 0 0 0
39159 - 0 0 0 0 0 0 0 0 0 0 0 0
39160 - 0 0 0 0 0 0 0 0 0 0 0 0
39161 - 0 0 0 0 0 1 0 0 1 0 0 0
39162 - 0 0 0 0 0 0 0 0 0 0 0 0
39163 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
39167 - 30 30 30 78 78 78 30 30 30 2 2 6
39168 - 2 2 6 2 2 6 2 2 6 2 2 6
39169 - 2 2 6 2 2 6 2 2 6 2 2 6
39170 - 2 2 6 2 2 6 2 2 6 10 10 10
39171 - 10 10 10 2 2 6 2 2 6 2 2 6
39172 - 2 2 6 2 2 6 2 2 6 78 78 78
39173 - 50 50 50 18 18 18 6 6 6 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 0 0 0
39177 - 0 0 0 0 0 0 0 0 0 0 0 0
39178 - 0 0 0 0 0 0 0 0 0 0 0 0
39179 - 0 0 0 0 0 0 0 0 0 0 0 0
39180 - 0 0 0 0 0 0 0 0 0 0 0 0
39181 - 0 0 1 0 0 0 0 0 0 0 0 0
39182 - 0 0 0 0 0 0 0 0 0 0 0 0
39183 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
39187 - 38 38 38 86 86 86 14 14 14 2 2 6
39188 - 2 2 6 2 2 6 2 2 6 2 2 6
39189 - 2 2 6 2 2 6 2 2 6 2 2 6
39190 - 2 2 6 2 2 6 2 2 6 2 2 6
39191 - 2 2 6 2 2 6 2 2 6 2 2 6
39192 - 2 2 6 2 2 6 2 2 6 54 54 54
39193 - 66 66 66 26 26 26 6 6 6 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 0 0 0
39197 - 0 0 0 0 0 0 0 0 0 0 0 0
39198 - 0 0 0 0 0 0 0 0 0 0 0 0
39199 - 0 0 0 0 0 0 0 0 0 0 0 0
39200 - 0 0 0 0 0 0 0 0 0 0 0 0
39201 - 0 0 0 0 0 1 0 0 1 0 0 0
39202 - 0 0 0 0 0 0 0 0 0 0 0 0
39203 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
39207 - 42 42 42 82 82 82 2 2 6 2 2 6
39208 - 2 2 6 6 6 6 10 10 10 2 2 6
39209 - 2 2 6 2 2 6 2 2 6 2 2 6
39210 - 2 2 6 2 2 6 2 2 6 6 6 6
39211 - 14 14 14 10 10 10 2 2 6 2 2 6
39212 - 2 2 6 2 2 6 2 2 6 18 18 18
39213 - 82 82 82 34 34 34 10 10 10 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 0 0 0
39217 - 0 0 0 0 0 0 0 0 0 0 0 0
39218 - 0 0 0 0 0 0 0 0 0 0 0 0
39219 - 0 0 0 0 0 0 0 0 0 0 0 0
39220 - 0 0 0 0 0 0 0 0 0 0 0 0
39221 - 0 0 1 0 0 0 0 0 0 0 0 0
39222 - 0 0 0 0 0 0 0 0 0 0 0 0
39223 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
39227 - 46 46 46 86 86 86 2 2 6 2 2 6
39228 - 6 6 6 6 6 6 22 22 22 34 34 34
39229 - 6 6 6 2 2 6 2 2 6 2 2 6
39230 - 2 2 6 2 2 6 18 18 18 34 34 34
39231 - 10 10 10 50 50 50 22 22 22 2 2 6
39232 - 2 2 6 2 2 6 2 2 6 10 10 10
39233 - 86 86 86 42 42 42 14 14 14 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 0 0 0
39237 - 0 0 0 0 0 0 0 0 0 0 0 0
39238 - 0 0 0 0 0 0 0 0 0 0 0 0
39239 - 0 0 0 0 0 0 0 0 0 0 0 0
39240 - 0 0 0 0 0 0 0 0 0 0 0 0
39241 - 0 0 1 0 0 1 0 0 1 0 0 0
39242 - 0 0 0 0 0 0 0 0 0 0 0 0
39243 - 0 0 0 0 0 0 0 0 0 0 0 0
39244 - 0 0 0 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 14 14 14
39247 - 46 46 46 86 86 86 2 2 6 2 2 6
39248 - 38 38 38 116 116 116 94 94 94 22 22 22
39249 - 22 22 22 2 2 6 2 2 6 2 2 6
39250 - 14 14 14 86 86 86 138 138 138 162 162 162
39251 -154 154 154 38 38 38 26 26 26 6 6 6
39252 - 2 2 6 2 2 6 2 2 6 2 2 6
39253 - 86 86 86 46 46 46 14 14 14 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 0 0 0
39257 - 0 0 0 0 0 0 0 0 0 0 0 0
39258 - 0 0 0 0 0 0 0 0 0 0 0 0
39259 - 0 0 0 0 0 0 0 0 0 0 0 0
39260 - 0 0 0 0 0 0 0 0 0 0 0 0
39261 - 0 0 0 0 0 0 0 0 0 0 0 0
39262 - 0 0 0 0 0 0 0 0 0 0 0 0
39263 - 0 0 0 0 0 0 0 0 0 0 0 0
39264 - 0 0 0 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 14 14 14
39267 - 46 46 46 86 86 86 2 2 6 14 14 14
39268 -134 134 134 198 198 198 195 195 195 116 116 116
39269 - 10 10 10 2 2 6 2 2 6 6 6 6
39270 -101 98 89 187 187 187 210 210 210 218 218 218
39271 -214 214 214 134 134 134 14 14 14 6 6 6
39272 - 2 2 6 2 2 6 2 2 6 2 2 6
39273 - 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0
39277 - 0 0 0 0 0 0 0 0 0 0 0 0
39278 - 0 0 0 0 0 0 0 0 0 0 0 0
39279 - 0 0 0 0 0 0 0 0 0 0 0 0
39280 - 0 0 0 0 0 0 0 0 1 0 0 0
39281 - 0 0 1 0 0 1 0 0 1 0 0 0
39282 - 0 0 0 0 0 0 0 0 0 0 0 0
39283 - 0 0 0 0 0 0 0 0 0 0 0 0
39284 - 0 0 0 0 0 0 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 14 14 14
39287 - 46 46 46 86 86 86 2 2 6 54 54 54
39288 -218 218 218 195 195 195 226 226 226 246 246 246
39289 - 58 58 58 2 2 6 2 2 6 30 30 30
39290 -210 210 210 253 253 253 174 174 174 123 123 123
39291 -221 221 221 234 234 234 74 74 74 2 2 6
39292 - 2 2 6 2 2 6 2 2 6 2 2 6
39293 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
39297 - 0 0 0 0 0 0 0 0 0 0 0 0
39298 - 0 0 0 0 0 0 0 0 0 0 0 0
39299 - 0 0 0 0 0 0 0 0 0 0 0 0
39300 - 0 0 0 0 0 0 0 0 0 0 0 0
39301 - 0 0 0 0 0 0 0 0 0 0 0 0
39302 - 0 0 0 0 0 0 0 0 0 0 0 0
39303 - 0 0 0 0 0 0 0 0 0 0 0 0
39304 - 0 0 0 0 0 0 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 14 14 14
39307 - 46 46 46 82 82 82 2 2 6 106 106 106
39308 -170 170 170 26 26 26 86 86 86 226 226 226
39309 -123 123 123 10 10 10 14 14 14 46 46 46
39310 -231 231 231 190 190 190 6 6 6 70 70 70
39311 - 90 90 90 238 238 238 158 158 158 2 2 6
39312 - 2 2 6 2 2 6 2 2 6 2 2 6
39313 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0
39317 - 0 0 0 0 0 0 0 0 0 0 0 0
39318 - 0 0 0 0 0 0 0 0 0 0 0 0
39319 - 0 0 0 0 0 0 0 0 0 0 0 0
39320 - 0 0 0 0 0 0 0 0 1 0 0 0
39321 - 0 0 1 0 0 1 0 0 1 0 0 0
39322 - 0 0 0 0 0 0 0 0 0 0 0 0
39323 - 0 0 0 0 0 0 0 0 0 0 0 0
39324 - 0 0 0 0 0 0 0 0 0 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 14 14 14
39327 - 42 42 42 86 86 86 6 6 6 116 116 116
39328 -106 106 106 6 6 6 70 70 70 149 149 149
39329 -128 128 128 18 18 18 38 38 38 54 54 54
39330 -221 221 221 106 106 106 2 2 6 14 14 14
39331 - 46 46 46 190 190 190 198 198 198 2 2 6
39332 - 2 2 6 2 2 6 2 2 6 2 2 6
39333 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0 0 0
39337 - 0 0 0 0 0 0 0 0 0 0 0 0
39338 - 0 0 0 0 0 0 0 0 0 0 0 0
39339 - 0 0 0 0 0 0 0 0 0 0 0 0
39340 - 0 0 0 0 0 0 0 0 1 0 0 0
39341 - 0 0 1 0 0 0 0 0 1 0 0 0
39342 - 0 0 0 0 0 0 0 0 0 0 0 0
39343 - 0 0 0 0 0 0 0 0 0 0 0 0
39344 - 0 0 0 0 0 0 0 0 0 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 14 14 14
39347 - 42 42 42 94 94 94 14 14 14 101 101 101
39348 -128 128 128 2 2 6 18 18 18 116 116 116
39349 -118 98 46 121 92 8 121 92 8 98 78 10
39350 -162 162 162 106 106 106 2 2 6 2 2 6
39351 - 2 2 6 195 195 195 195 195 195 6 6 6
39352 - 2 2 6 2 2 6 2 2 6 2 2 6
39353 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
39357 - 0 0 0 0 0 0 0 0 0 0 0 0
39358 - 0 0 0 0 0 0 0 0 0 0 0 0
39359 - 0 0 0 0 0 0 0 0 0 0 0 0
39360 - 0 0 0 0 0 0 0 0 1 0 0 1
39361 - 0 0 1 0 0 0 0 0 1 0 0 0
39362 - 0 0 0 0 0 0 0 0 0 0 0 0
39363 - 0 0 0 0 0 0 0 0 0 0 0 0
39364 - 0 0 0 0 0 0 0 0 0 0 0 0
39365 - 0 0 0 0 0 0 0 0 0 0 0 0
39366 - 0 0 0 0 0 0 0 0 0 10 10 10
39367 - 38 38 38 90 90 90 14 14 14 58 58 58
39368 -210 210 210 26 26 26 54 38 6 154 114 10
39369 -226 170 11 236 186 11 225 175 15 184 144 12
39370 -215 174 15 175 146 61 37 26 9 2 2 6
39371 - 70 70 70 246 246 246 138 138 138 2 2 6
39372 - 2 2 6 2 2 6 2 2 6 2 2 6
39373 - 70 70 70 66 66 66 26 26 26 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
39377 - 0 0 0 0 0 0 0 0 0 0 0 0
39378 - 0 0 0 0 0 0 0 0 0 0 0 0
39379 - 0 0 0 0 0 0 0 0 0 0 0 0
39380 - 0 0 0 0 0 0 0 0 0 0 0 0
39381 - 0 0 0 0 0 0 0 0 0 0 0 0
39382 - 0 0 0 0 0 0 0 0 0 0 0 0
39383 - 0 0 0 0 0 0 0 0 0 0 0 0
39384 - 0 0 0 0 0 0 0 0 0 0 0 0
39385 - 0 0 0 0 0 0 0 0 0 0 0 0
39386 - 0 0 0 0 0 0 0 0 0 10 10 10
39387 - 38 38 38 86 86 86 14 14 14 10 10 10
39388 -195 195 195 188 164 115 192 133 9 225 175 15
39389 -239 182 13 234 190 10 232 195 16 232 200 30
39390 -245 207 45 241 208 19 232 195 16 184 144 12
39391 -218 194 134 211 206 186 42 42 42 2 2 6
39392 - 2 2 6 2 2 6 2 2 6 2 2 6
39393 - 50 50 50 74 74 74 30 30 30 6 6 6
39394 - 0 0 0 0 0 0 0 0 0 0 0 0
39395 - 0 0 0 0 0 0 0 0 0 0 0 0
39396 - 0 0 0 0 0 0 0 0 0 0 0 0
39397 - 0 0 0 0 0 0 0 0 0 0 0 0
39398 - 0 0 0 0 0 0 0 0 0 0 0 0
39399 - 0 0 0 0 0 0 0 0 0 0 0 0
39400 - 0 0 0 0 0 0 0 0 0 0 0 0
39401 - 0 0 0 0 0 0 0 0 0 0 0 0
39402 - 0 0 0 0 0 0 0 0 0 0 0 0
39403 - 0 0 0 0 0 0 0 0 0 0 0 0
39404 - 0 0 0 0 0 0 0 0 0 0 0 0
39405 - 0 0 0 0 0 0 0 0 0 0 0 0
39406 - 0 0 0 0 0 0 0 0 0 10 10 10
39407 - 34 34 34 86 86 86 14 14 14 2 2 6
39408 -121 87 25 192 133 9 219 162 10 239 182 13
39409 -236 186 11 232 195 16 241 208 19 244 214 54
39410 -246 218 60 246 218 38 246 215 20 241 208 19
39411 -241 208 19 226 184 13 121 87 25 2 2 6
39412 - 2 2 6 2 2 6 2 2 6 2 2 6
39413 - 50 50 50 82 82 82 34 34 34 10 10 10
39414 - 0 0 0 0 0 0 0 0 0 0 0 0
39415 - 0 0 0 0 0 0 0 0 0 0 0 0
39416 - 0 0 0 0 0 0 0 0 0 0 0 0
39417 - 0 0 0 0 0 0 0 0 0 0 0 0
39418 - 0 0 0 0 0 0 0 0 0 0 0 0
39419 - 0 0 0 0 0 0 0 0 0 0 0 0
39420 - 0 0 0 0 0 0 0 0 0 0 0 0
39421 - 0 0 0 0 0 0 0 0 0 0 0 0
39422 - 0 0 0 0 0 0 0 0 0 0 0 0
39423 - 0 0 0 0 0 0 0 0 0 0 0 0
39424 - 0 0 0 0 0 0 0 0 0 0 0 0
39425 - 0 0 0 0 0 0 0 0 0 0 0 0
39426 - 0 0 0 0 0 0 0 0 0 10 10 10
39427 - 34 34 34 82 82 82 30 30 30 61 42 6
39428 -180 123 7 206 145 10 230 174 11 239 182 13
39429 -234 190 10 238 202 15 241 208 19 246 218 74
39430 -246 218 38 246 215 20 246 215 20 246 215 20
39431 -226 184 13 215 174 15 184 144 12 6 6 6
39432 - 2 2 6 2 2 6 2 2 6 2 2 6
39433 - 26 26 26 94 94 94 42 42 42 14 14 14
39434 - 0 0 0 0 0 0 0 0 0 0 0 0
39435 - 0 0 0 0 0 0 0 0 0 0 0 0
39436 - 0 0 0 0 0 0 0 0 0 0 0 0
39437 - 0 0 0 0 0 0 0 0 0 0 0 0
39438 - 0 0 0 0 0 0 0 0 0 0 0 0
39439 - 0 0 0 0 0 0 0 0 0 0 0 0
39440 - 0 0 0 0 0 0 0 0 0 0 0 0
39441 - 0 0 0 0 0 0 0 0 0 0 0 0
39442 - 0 0 0 0 0 0 0 0 0 0 0 0
39443 - 0 0 0 0 0 0 0 0 0 0 0 0
39444 - 0 0 0 0 0 0 0 0 0 0 0 0
39445 - 0 0 0 0 0 0 0 0 0 0 0 0
39446 - 0 0 0 0 0 0 0 0 0 10 10 10
39447 - 30 30 30 78 78 78 50 50 50 104 69 6
39448 -192 133 9 216 158 10 236 178 12 236 186 11
39449 -232 195 16 241 208 19 244 214 54 245 215 43
39450 -246 215 20 246 215 20 241 208 19 198 155 10
39451 -200 144 11 216 158 10 156 118 10 2 2 6
39452 - 2 2 6 2 2 6 2 2 6 2 2 6
39453 - 6 6 6 90 90 90 54 54 54 18 18 18
39454 - 6 6 6 0 0 0 0 0 0 0 0 0
39455 - 0 0 0 0 0 0 0 0 0 0 0 0
39456 - 0 0 0 0 0 0 0 0 0 0 0 0
39457 - 0 0 0 0 0 0 0 0 0 0 0 0
39458 - 0 0 0 0 0 0 0 0 0 0 0 0
39459 - 0 0 0 0 0 0 0 0 0 0 0 0
39460 - 0 0 0 0 0 0 0 0 0 0 0 0
39461 - 0 0 0 0 0 0 0 0 0 0 0 0
39462 - 0 0 0 0 0 0 0 0 0 0 0 0
39463 - 0 0 0 0 0 0 0 0 0 0 0 0
39464 - 0 0 0 0 0 0 0 0 0 0 0 0
39465 - 0 0 0 0 0 0 0 0 0 0 0 0
39466 - 0 0 0 0 0 0 0 0 0 10 10 10
39467 - 30 30 30 78 78 78 46 46 46 22 22 22
39468 -137 92 6 210 162 10 239 182 13 238 190 10
39469 -238 202 15 241 208 19 246 215 20 246 215 20
39470 -241 208 19 203 166 17 185 133 11 210 150 10
39471 -216 158 10 210 150 10 102 78 10 2 2 6
39472 - 6 6 6 54 54 54 14 14 14 2 2 6
39473 - 2 2 6 62 62 62 74 74 74 30 30 30
39474 - 10 10 10 0 0 0 0 0 0 0 0 0
39475 - 0 0 0 0 0 0 0 0 0 0 0 0
39476 - 0 0 0 0 0 0 0 0 0 0 0 0
39477 - 0 0 0 0 0 0 0 0 0 0 0 0
39478 - 0 0 0 0 0 0 0 0 0 0 0 0
39479 - 0 0 0 0 0 0 0 0 0 0 0 0
39480 - 0 0 0 0 0 0 0 0 0 0 0 0
39481 - 0 0 0 0 0 0 0 0 0 0 0 0
39482 - 0 0 0 0 0 0 0 0 0 0 0 0
39483 - 0 0 0 0 0 0 0 0 0 0 0 0
39484 - 0 0 0 0 0 0 0 0 0 0 0 0
39485 - 0 0 0 0 0 0 0 0 0 0 0 0
39486 - 0 0 0 0 0 0 0 0 0 10 10 10
39487 - 34 34 34 78 78 78 50 50 50 6 6 6
39488 - 94 70 30 139 102 15 190 146 13 226 184 13
39489 -232 200 30 232 195 16 215 174 15 190 146 13
39490 -168 122 10 192 133 9 210 150 10 213 154 11
39491 -202 150 34 182 157 106 101 98 89 2 2 6
39492 - 2 2 6 78 78 78 116 116 116 58 58 58
39493 - 2 2 6 22 22 22 90 90 90 46 46 46
39494 - 18 18 18 6 6 6 0 0 0 0 0 0
39495 - 0 0 0 0 0 0 0 0 0 0 0 0
39496 - 0 0 0 0 0 0 0 0 0 0 0 0
39497 - 0 0 0 0 0 0 0 0 0 0 0 0
39498 - 0 0 0 0 0 0 0 0 0 0 0 0
39499 - 0 0 0 0 0 0 0 0 0 0 0 0
39500 - 0 0 0 0 0 0 0 0 0 0 0 0
39501 - 0 0 0 0 0 0 0 0 0 0 0 0
39502 - 0 0 0 0 0 0 0 0 0 0 0 0
39503 - 0 0 0 0 0 0 0 0 0 0 0 0
39504 - 0 0 0 0 0 0 0 0 0 0 0 0
39505 - 0 0 0 0 0 0 0 0 0 0 0 0
39506 - 0 0 0 0 0 0 0 0 0 10 10 10
39507 - 38 38 38 86 86 86 50 50 50 6 6 6
39508 -128 128 128 174 154 114 156 107 11 168 122 10
39509 -198 155 10 184 144 12 197 138 11 200 144 11
39510 -206 145 10 206 145 10 197 138 11 188 164 115
39511 -195 195 195 198 198 198 174 174 174 14 14 14
39512 - 2 2 6 22 22 22 116 116 116 116 116 116
39513 - 22 22 22 2 2 6 74 74 74 70 70 70
39514 - 30 30 30 10 10 10 0 0 0 0 0 0
39515 - 0 0 0 0 0 0 0 0 0 0 0 0
39516 - 0 0 0 0 0 0 0 0 0 0 0 0
39517 - 0 0 0 0 0 0 0 0 0 0 0 0
39518 - 0 0 0 0 0 0 0 0 0 0 0 0
39519 - 0 0 0 0 0 0 0 0 0 0 0 0
39520 - 0 0 0 0 0 0 0 0 0 0 0 0
39521 - 0 0 0 0 0 0 0 0 0 0 0 0
39522 - 0 0 0 0 0 0 0 0 0 0 0 0
39523 - 0 0 0 0 0 0 0 0 0 0 0 0
39524 - 0 0 0 0 0 0 0 0 0 0 0 0
39525 - 0 0 0 0 0 0 0 0 0 0 0 0
39526 - 0 0 0 0 0 0 6 6 6 18 18 18
39527 - 50 50 50 101 101 101 26 26 26 10 10 10
39528 -138 138 138 190 190 190 174 154 114 156 107 11
39529 -197 138 11 200 144 11 197 138 11 192 133 9
39530 -180 123 7 190 142 34 190 178 144 187 187 187
39531 -202 202 202 221 221 221 214 214 214 66 66 66
39532 - 2 2 6 2 2 6 50 50 50 62 62 62
39533 - 6 6 6 2 2 6 10 10 10 90 90 90
39534 - 50 50 50 18 18 18 6 6 6 0 0 0
39535 - 0 0 0 0 0 0 0 0 0 0 0 0
39536 - 0 0 0 0 0 0 0 0 0 0 0 0
39537 - 0 0 0 0 0 0 0 0 0 0 0 0
39538 - 0 0 0 0 0 0 0 0 0 0 0 0
39539 - 0 0 0 0 0 0 0 0 0 0 0 0
39540 - 0 0 0 0 0 0 0 0 0 0 0 0
39541 - 0 0 0 0 0 0 0 0 0 0 0 0
39542 - 0 0 0 0 0 0 0 0 0 0 0 0
39543 - 0 0 0 0 0 0 0 0 0 0 0 0
39544 - 0 0 0 0 0 0 0 0 0 0 0 0
39545 - 0 0 0 0 0 0 0 0 0 0 0 0
39546 - 0 0 0 0 0 0 10 10 10 34 34 34
39547 - 74 74 74 74 74 74 2 2 6 6 6 6
39548 -144 144 144 198 198 198 190 190 190 178 166 146
39549 -154 121 60 156 107 11 156 107 11 168 124 44
39550 -174 154 114 187 187 187 190 190 190 210 210 210
39551 -246 246 246 253 253 253 253 253 253 182 182 182
39552 - 6 6 6 2 2 6 2 2 6 2 2 6
39553 - 2 2 6 2 2 6 2 2 6 62 62 62
39554 - 74 74 74 34 34 34 14 14 14 0 0 0
39555 - 0 0 0 0 0 0 0 0 0 0 0 0
39556 - 0 0 0 0 0 0 0 0 0 0 0 0
39557 - 0 0 0 0 0 0 0 0 0 0 0 0
39558 - 0 0 0 0 0 0 0 0 0 0 0 0
39559 - 0 0 0 0 0 0 0 0 0 0 0 0
39560 - 0 0 0 0 0 0 0 0 0 0 0 0
39561 - 0 0 0 0 0 0 0 0 0 0 0 0
39562 - 0 0 0 0 0 0 0 0 0 0 0 0
39563 - 0 0 0 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 0 0 0
39565 - 0 0 0 0 0 0 0 0 0 0 0 0
39566 - 0 0 0 10 10 10 22 22 22 54 54 54
39567 - 94 94 94 18 18 18 2 2 6 46 46 46
39568 -234 234 234 221 221 221 190 190 190 190 190 190
39569 -190 190 190 187 187 187 187 187 187 190 190 190
39570 -190 190 190 195 195 195 214 214 214 242 242 242
39571 -253 253 253 253 253 253 253 253 253 253 253 253
39572 - 82 82 82 2 2 6 2 2 6 2 2 6
39573 - 2 2 6 2 2 6 2 2 6 14 14 14
39574 - 86 86 86 54 54 54 22 22 22 6 6 6
39575 - 0 0 0 0 0 0 0 0 0 0 0 0
39576 - 0 0 0 0 0 0 0 0 0 0 0 0
39577 - 0 0 0 0 0 0 0 0 0 0 0 0
39578 - 0 0 0 0 0 0 0 0 0 0 0 0
39579 - 0 0 0 0 0 0 0 0 0 0 0 0
39580 - 0 0 0 0 0 0 0 0 0 0 0 0
39581 - 0 0 0 0 0 0 0 0 0 0 0 0
39582 - 0 0 0 0 0 0 0 0 0 0 0 0
39583 - 0 0 0 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 0 0 0 0
39585 - 0 0 0 0 0 0 0 0 0 0 0 0
39586 - 6 6 6 18 18 18 46 46 46 90 90 90
39587 - 46 46 46 18 18 18 6 6 6 182 182 182
39588 -253 253 253 246 246 246 206 206 206 190 190 190
39589 -190 190 190 190 190 190 190 190 190 190 190 190
39590 -206 206 206 231 231 231 250 250 250 253 253 253
39591 -253 253 253 253 253 253 253 253 253 253 253 253
39592 -202 202 202 14 14 14 2 2 6 2 2 6
39593 - 2 2 6 2 2 6 2 2 6 2 2 6
39594 - 42 42 42 86 86 86 42 42 42 18 18 18
39595 - 6 6 6 0 0 0 0 0 0 0 0 0
39596 - 0 0 0 0 0 0 0 0 0 0 0 0
39597 - 0 0 0 0 0 0 0 0 0 0 0 0
39598 - 0 0 0 0 0 0 0 0 0 0 0 0
39599 - 0 0 0 0 0 0 0 0 0 0 0 0
39600 - 0 0 0 0 0 0 0 0 0 0 0 0
39601 - 0 0 0 0 0 0 0 0 0 0 0 0
39602 - 0 0 0 0 0 0 0 0 0 0 0 0
39603 - 0 0 0 0 0 0 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 0 0 0 0
39605 - 0 0 0 0 0 0 0 0 0 6 6 6
39606 - 14 14 14 38 38 38 74 74 74 66 66 66
39607 - 2 2 6 6 6 6 90 90 90 250 250 250
39608 -253 253 253 253 253 253 238 238 238 198 198 198
39609 -190 190 190 190 190 190 195 195 195 221 221 221
39610 -246 246 246 253 253 253 253 253 253 253 253 253
39611 -253 253 253 253 253 253 253 253 253 253 253 253
39612 -253 253 253 82 82 82 2 2 6 2 2 6
39613 - 2 2 6 2 2 6 2 2 6 2 2 6
39614 - 2 2 6 78 78 78 70 70 70 34 34 34
39615 - 14 14 14 6 6 6 0 0 0 0 0 0
39616 - 0 0 0 0 0 0 0 0 0 0 0 0
39617 - 0 0 0 0 0 0 0 0 0 0 0 0
39618 - 0 0 0 0 0 0 0 0 0 0 0 0
39619 - 0 0 0 0 0 0 0 0 0 0 0 0
39620 - 0 0 0 0 0 0 0 0 0 0 0 0
39621 - 0 0 0 0 0 0 0 0 0 0 0 0
39622 - 0 0 0 0 0 0 0 0 0 0 0 0
39623 - 0 0 0 0 0 0 0 0 0 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 0 0 0
39625 - 0 0 0 0 0 0 0 0 0 14 14 14
39626 - 34 34 34 66 66 66 78 78 78 6 6 6
39627 - 2 2 6 18 18 18 218 218 218 253 253 253
39628 -253 253 253 253 253 253 253 253 253 246 246 246
39629 -226 226 226 231 231 231 246 246 246 253 253 253
39630 -253 253 253 253 253 253 253 253 253 253 253 253
39631 -253 253 253 253 253 253 253 253 253 253 253 253
39632 -253 253 253 178 178 178 2 2 6 2 2 6
39633 - 2 2 6 2 2 6 2 2 6 2 2 6
39634 - 2 2 6 18 18 18 90 90 90 62 62 62
39635 - 30 30 30 10 10 10 0 0 0 0 0 0
39636 - 0 0 0 0 0 0 0 0 0 0 0 0
39637 - 0 0 0 0 0 0 0 0 0 0 0 0
39638 - 0 0 0 0 0 0 0 0 0 0 0 0
39639 - 0 0 0 0 0 0 0 0 0 0 0 0
39640 - 0 0 0 0 0 0 0 0 0 0 0 0
39641 - 0 0 0 0 0 0 0 0 0 0 0 0
39642 - 0 0 0 0 0 0 0 0 0 0 0 0
39643 - 0 0 0 0 0 0 0 0 0 0 0 0
39644 - 0 0 0 0 0 0 0 0 0 0 0 0
39645 - 0 0 0 0 0 0 10 10 10 26 26 26
39646 - 58 58 58 90 90 90 18 18 18 2 2 6
39647 - 2 2 6 110 110 110 253 253 253 253 253 253
39648 -253 253 253 253 253 253 253 253 253 253 253 253
39649 -250 250 250 253 253 253 253 253 253 253 253 253
39650 -253 253 253 253 253 253 253 253 253 253 253 253
39651 -253 253 253 253 253 253 253 253 253 253 253 253
39652 -253 253 253 231 231 231 18 18 18 2 2 6
39653 - 2 2 6 2 2 6 2 2 6 2 2 6
39654 - 2 2 6 2 2 6 18 18 18 94 94 94
39655 - 54 54 54 26 26 26 10 10 10 0 0 0
39656 - 0 0 0 0 0 0 0 0 0 0 0 0
39657 - 0 0 0 0 0 0 0 0 0 0 0 0
39658 - 0 0 0 0 0 0 0 0 0 0 0 0
39659 - 0 0 0 0 0 0 0 0 0 0 0 0
39660 - 0 0 0 0 0 0 0 0 0 0 0 0
39661 - 0 0 0 0 0 0 0 0 0 0 0 0
39662 - 0 0 0 0 0 0 0 0 0 0 0 0
39663 - 0 0 0 0 0 0 0 0 0 0 0 0
39664 - 0 0 0 0 0 0 0 0 0 0 0 0
39665 - 0 0 0 6 6 6 22 22 22 50 50 50
39666 - 90 90 90 26 26 26 2 2 6 2 2 6
39667 - 14 14 14 195 195 195 250 250 250 253 253 253
39668 -253 253 253 253 253 253 253 253 253 253 253 253
39669 -253 253 253 253 253 253 253 253 253 253 253 253
39670 -253 253 253 253 253 253 253 253 253 253 253 253
39671 -253 253 253 253 253 253 253 253 253 253 253 253
39672 -250 250 250 242 242 242 54 54 54 2 2 6
39673 - 2 2 6 2 2 6 2 2 6 2 2 6
39674 - 2 2 6 2 2 6 2 2 6 38 38 38
39675 - 86 86 86 50 50 50 22 22 22 6 6 6
39676 - 0 0 0 0 0 0 0 0 0 0 0 0
39677 - 0 0 0 0 0 0 0 0 0 0 0 0
39678 - 0 0 0 0 0 0 0 0 0 0 0 0
39679 - 0 0 0 0 0 0 0 0 0 0 0 0
39680 - 0 0 0 0 0 0 0 0 0 0 0 0
39681 - 0 0 0 0 0 0 0 0 0 0 0 0
39682 - 0 0 0 0 0 0 0 0 0 0 0 0
39683 - 0 0 0 0 0 0 0 0 0 0 0 0
39684 - 0 0 0 0 0 0 0 0 0 0 0 0
39685 - 6 6 6 14 14 14 38 38 38 82 82 82
39686 - 34 34 34 2 2 6 2 2 6 2 2 6
39687 - 42 42 42 195 195 195 246 246 246 253 253 253
39688 -253 253 253 253 253 253 253 253 253 250 250 250
39689 -242 242 242 242 242 242 250 250 250 253 253 253
39690 -253 253 253 253 253 253 253 253 253 253 253 253
39691 -253 253 253 250 250 250 246 246 246 238 238 238
39692 -226 226 226 231 231 231 101 101 101 6 6 6
39693 - 2 2 6 2 2 6 2 2 6 2 2 6
39694 - 2 2 6 2 2 6 2 2 6 2 2 6
39695 - 38 38 38 82 82 82 42 42 42 14 14 14
39696 - 6 6 6 0 0 0 0 0 0 0 0 0
39697 - 0 0 0 0 0 0 0 0 0 0 0 0
39698 - 0 0 0 0 0 0 0 0 0 0 0 0
39699 - 0 0 0 0 0 0 0 0 0 0 0 0
39700 - 0 0 0 0 0 0 0 0 0 0 0 0
39701 - 0 0 0 0 0 0 0 0 0 0 0 0
39702 - 0 0 0 0 0 0 0 0 0 0 0 0
39703 - 0 0 0 0 0 0 0 0 0 0 0 0
39704 - 0 0 0 0 0 0 0 0 0 0 0 0
39705 - 10 10 10 26 26 26 62 62 62 66 66 66
39706 - 2 2 6 2 2 6 2 2 6 6 6 6
39707 - 70 70 70 170 170 170 206 206 206 234 234 234
39708 -246 246 246 250 250 250 250 250 250 238 238 238
39709 -226 226 226 231 231 231 238 238 238 250 250 250
39710 -250 250 250 250 250 250 246 246 246 231 231 231
39711 -214 214 214 206 206 206 202 202 202 202 202 202
39712 -198 198 198 202 202 202 182 182 182 18 18 18
39713 - 2 2 6 2 2 6 2 2 6 2 2 6
39714 - 2 2 6 2 2 6 2 2 6 2 2 6
39715 - 2 2 6 62 62 62 66 66 66 30 30 30
39716 - 10 10 10 0 0 0 0 0 0 0 0 0
39717 - 0 0 0 0 0 0 0 0 0 0 0 0
39718 - 0 0 0 0 0 0 0 0 0 0 0 0
39719 - 0 0 0 0 0 0 0 0 0 0 0 0
39720 - 0 0 0 0 0 0 0 0 0 0 0 0
39721 - 0 0 0 0 0 0 0 0 0 0 0 0
39722 - 0 0 0 0 0 0 0 0 0 0 0 0
39723 - 0 0 0 0 0 0 0 0 0 0 0 0
39724 - 0 0 0 0 0 0 0 0 0 0 0 0
39725 - 14 14 14 42 42 42 82 82 82 18 18 18
39726 - 2 2 6 2 2 6 2 2 6 10 10 10
39727 - 94 94 94 182 182 182 218 218 218 242 242 242
39728 -250 250 250 253 253 253 253 253 253 250 250 250
39729 -234 234 234 253 253 253 253 253 253 253 253 253
39730 -253 253 253 253 253 253 253 253 253 246 246 246
39731 -238 238 238 226 226 226 210 210 210 202 202 202
39732 -195 195 195 195 195 195 210 210 210 158 158 158
39733 - 6 6 6 14 14 14 50 50 50 14 14 14
39734 - 2 2 6 2 2 6 2 2 6 2 2 6
39735 - 2 2 6 6 6 6 86 86 86 46 46 46
39736 - 18 18 18 6 6 6 0 0 0 0 0 0
39737 - 0 0 0 0 0 0 0 0 0 0 0 0
39738 - 0 0 0 0 0 0 0 0 0 0 0 0
39739 - 0 0 0 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 6 6 6
39745 - 22 22 22 54 54 54 70 70 70 2 2 6
39746 - 2 2 6 10 10 10 2 2 6 22 22 22
39747 -166 166 166 231 231 231 250 250 250 253 253 253
39748 -253 253 253 253 253 253 253 253 253 250 250 250
39749 -242 242 242 253 253 253 253 253 253 253 253 253
39750 -253 253 253 253 253 253 253 253 253 253 253 253
39751 -253 253 253 253 253 253 253 253 253 246 246 246
39752 -231 231 231 206 206 206 198 198 198 226 226 226
39753 - 94 94 94 2 2 6 6 6 6 38 38 38
39754 - 30 30 30 2 2 6 2 2 6 2 2 6
39755 - 2 2 6 2 2 6 62 62 62 66 66 66
39756 - 26 26 26 10 10 10 0 0 0 0 0 0
39757 - 0 0 0 0 0 0 0 0 0 0 0 0
39758 - 0 0 0 0 0 0 0 0 0 0 0 0
39759 - 0 0 0 0 0 0 0 0 0 0 0 0
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 0 0 0 0 0 0 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 10 10 10
39765 - 30 30 30 74 74 74 50 50 50 2 2 6
39766 - 26 26 26 26 26 26 2 2 6 106 106 106
39767 -238 238 238 253 253 253 253 253 253 253 253 253
39768 -253 253 253 253 253 253 253 253 253 253 253 253
39769 -253 253 253 253 253 253 253 253 253 253 253 253
39770 -253 253 253 253 253 253 253 253 253 253 253 253
39771 -253 253 253 253 253 253 253 253 253 253 253 253
39772 -253 253 253 246 246 246 218 218 218 202 202 202
39773 -210 210 210 14 14 14 2 2 6 2 2 6
39774 - 30 30 30 22 22 22 2 2 6 2 2 6
39775 - 2 2 6 2 2 6 18 18 18 86 86 86
39776 - 42 42 42 14 14 14 0 0 0 0 0 0
39777 - 0 0 0 0 0 0 0 0 0 0 0 0
39778 - 0 0 0 0 0 0 0 0 0 0 0 0
39779 - 0 0 0 0 0 0 0 0 0 0 0 0
39780 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 0 0 0 0 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 0 0 0 14 14 14
39785 - 42 42 42 90 90 90 22 22 22 2 2 6
39786 - 42 42 42 2 2 6 18 18 18 218 218 218
39787 -253 253 253 253 253 253 253 253 253 253 253 253
39788 -253 253 253 253 253 253 253 253 253 253 253 253
39789 -253 253 253 253 253 253 253 253 253 253 253 253
39790 -253 253 253 253 253 253 253 253 253 253 253 253
39791 -253 253 253 253 253 253 253 253 253 253 253 253
39792 -253 253 253 253 253 253 250 250 250 221 221 221
39793 -218 218 218 101 101 101 2 2 6 14 14 14
39794 - 18 18 18 38 38 38 10 10 10 2 2 6
39795 - 2 2 6 2 2 6 2 2 6 78 78 78
39796 - 58 58 58 22 22 22 6 6 6 0 0 0
39797 - 0 0 0 0 0 0 0 0 0 0 0 0
39798 - 0 0 0 0 0 0 0 0 0 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 0 0 0 0 0 0 0 0 0 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 6 6 6 18 18 18
39805 - 54 54 54 82 82 82 2 2 6 26 26 26
39806 - 22 22 22 2 2 6 123 123 123 253 253 253
39807 -253 253 253 253 253 253 253 253 253 253 253 253
39808 -253 253 253 253 253 253 253 253 253 253 253 253
39809 -253 253 253 253 253 253 253 253 253 253 253 253
39810 -253 253 253 253 253 253 253 253 253 253 253 253
39811 -253 253 253 253 253 253 253 253 253 253 253 253
39812 -253 253 253 253 253 253 253 253 253 250 250 250
39813 -238 238 238 198 198 198 6 6 6 38 38 38
39814 - 58 58 58 26 26 26 38 38 38 2 2 6
39815 - 2 2 6 2 2 6 2 2 6 46 46 46
39816 - 78 78 78 30 30 30 10 10 10 0 0 0
39817 - 0 0 0 0 0 0 0 0 0 0 0 0
39818 - 0 0 0 0 0 0 0 0 0 0 0 0
39819 - 0 0 0 0 0 0 0 0 0 0 0 0
39820 - 0 0 0 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 0 0 0 0 0 0 0 0 0 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 0 0 0 10 10 10 30 30 30
39825 - 74 74 74 58 58 58 2 2 6 42 42 42
39826 - 2 2 6 22 22 22 231 231 231 253 253 253
39827 -253 253 253 253 253 253 253 253 253 253 253 253
39828 -253 253 253 253 253 253 253 253 253 250 250 250
39829 -253 253 253 253 253 253 253 253 253 253 253 253
39830 -253 253 253 253 253 253 253 253 253 253 253 253
39831 -253 253 253 253 253 253 253 253 253 253 253 253
39832 -253 253 253 253 253 253 253 253 253 253 253 253
39833 -253 253 253 246 246 246 46 46 46 38 38 38
39834 - 42 42 42 14 14 14 38 38 38 14 14 14
39835 - 2 2 6 2 2 6 2 2 6 6 6 6
39836 - 86 86 86 46 46 46 14 14 14 0 0 0
39837 - 0 0 0 0 0 0 0 0 0 0 0 0
39838 - 0 0 0 0 0 0 0 0 0 0 0 0
39839 - 0 0 0 0 0 0 0 0 0 0 0 0
39840 - 0 0 0 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 0 0 0 0 0 0 0 0 0
39842 - 0 0 0 0 0 0 0 0 0 0 0 0
39843 - 0 0 0 0 0 0 0 0 0 0 0 0
39844 - 0 0 0 6 6 6 14 14 14 42 42 42
39845 - 90 90 90 18 18 18 18 18 18 26 26 26
39846 - 2 2 6 116 116 116 253 253 253 253 253 253
39847 -253 253 253 253 253 253 253 253 253 253 253 253
39848 -253 253 253 253 253 253 250 250 250 238 238 238
39849 -253 253 253 253 253 253 253 253 253 253 253 253
39850 -253 253 253 253 253 253 253 253 253 253 253 253
39851 -253 253 253 253 253 253 253 253 253 253 253 253
39852 -253 253 253 253 253 253 253 253 253 253 253 253
39853 -253 253 253 253 253 253 94 94 94 6 6 6
39854 - 2 2 6 2 2 6 10 10 10 34 34 34
39855 - 2 2 6 2 2 6 2 2 6 2 2 6
39856 - 74 74 74 58 58 58 22 22 22 6 6 6
39857 - 0 0 0 0 0 0 0 0 0 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 0 0 0
39859 - 0 0 0 0 0 0 0 0 0 0 0 0
39860 - 0 0 0 0 0 0 0 0 0 0 0 0
39861 - 0 0 0 0 0 0 0 0 0 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 10 10 10 26 26 26 66 66 66
39865 - 82 82 82 2 2 6 38 38 38 6 6 6
39866 - 14 14 14 210 210 210 253 253 253 253 253 253
39867 -253 253 253 253 253 253 253 253 253 253 253 253
39868 -253 253 253 253 253 253 246 246 246 242 242 242
39869 -253 253 253 253 253 253 253 253 253 253 253 253
39870 -253 253 253 253 253 253 253 253 253 253 253 253
39871 -253 253 253 253 253 253 253 253 253 253 253 253
39872 -253 253 253 253 253 253 253 253 253 253 253 253
39873 -253 253 253 253 253 253 144 144 144 2 2 6
39874 - 2 2 6 2 2 6 2 2 6 46 46 46
39875 - 2 2 6 2 2 6 2 2 6 2 2 6
39876 - 42 42 42 74 74 74 30 30 30 10 10 10
39877 - 0 0 0 0 0 0 0 0 0 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 0 0 0
39879 - 0 0 0 0 0 0 0 0 0 0 0 0
39880 - 0 0 0 0 0 0 0 0 0 0 0 0
39881 - 0 0 0 0 0 0 0 0 0 0 0 0
39882 - 0 0 0 0 0 0 0 0 0 0 0 0
39883 - 0 0 0 0 0 0 0 0 0 0 0 0
39884 - 6 6 6 14 14 14 42 42 42 90 90 90
39885 - 26 26 26 6 6 6 42 42 42 2 2 6
39886 - 74 74 74 250 250 250 253 253 253 253 253 253
39887 -253 253 253 253 253 253 253 253 253 253 253 253
39888 -253 253 253 253 253 253 242 242 242 242 242 242
39889 -253 253 253 253 253 253 253 253 253 253 253 253
39890 -253 253 253 253 253 253 253 253 253 253 253 253
39891 -253 253 253 253 253 253 253 253 253 253 253 253
39892 -253 253 253 253 253 253 253 253 253 253 253 253
39893 -253 253 253 253 253 253 182 182 182 2 2 6
39894 - 2 2 6 2 2 6 2 2 6 46 46 46
39895 - 2 2 6 2 2 6 2 2 6 2 2 6
39896 - 10 10 10 86 86 86 38 38 38 10 10 10
39897 - 0 0 0 0 0 0 0 0 0 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 0 0 0
39899 - 0 0 0 0 0 0 0 0 0 0 0 0
39900 - 0 0 0 0 0 0 0 0 0 0 0 0
39901 - 0 0 0 0 0 0 0 0 0 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 0 0 0 0 0 0
39904 - 10 10 10 26 26 26 66 66 66 82 82 82
39905 - 2 2 6 22 22 22 18 18 18 2 2 6
39906 -149 149 149 253 253 253 253 253 253 253 253 253
39907 -253 253 253 253 253 253 253 253 253 253 253 253
39908 -253 253 253 253 253 253 234 234 234 242 242 242
39909 -253 253 253 253 253 253 253 253 253 253 253 253
39910 -253 253 253 253 253 253 253 253 253 253 253 253
39911 -253 253 253 253 253 253 253 253 253 253 253 253
39912 -253 253 253 253 253 253 253 253 253 253 253 253
39913 -253 253 253 253 253 253 206 206 206 2 2 6
39914 - 2 2 6 2 2 6 2 2 6 38 38 38
39915 - 2 2 6 2 2 6 2 2 6 2 2 6
39916 - 6 6 6 86 86 86 46 46 46 14 14 14
39917 - 0 0 0 0 0 0 0 0 0 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 0 0 0
39919 - 0 0 0 0 0 0 0 0 0 0 0 0
39920 - 0 0 0 0 0 0 0 0 0 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 0 0 0
39922 - 0 0 0 0 0 0 0 0 0 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 6 6 6
39924 - 18 18 18 46 46 46 86 86 86 18 18 18
39925 - 2 2 6 34 34 34 10 10 10 6 6 6
39926 -210 210 210 253 253 253 253 253 253 253 253 253
39927 -253 253 253 253 253 253 253 253 253 253 253 253
39928 -253 253 253 253 253 253 234 234 234 242 242 242
39929 -253 253 253 253 253 253 253 253 253 253 253 253
39930 -253 253 253 253 253 253 253 253 253 253 253 253
39931 -253 253 253 253 253 253 253 253 253 253 253 253
39932 -253 253 253 253 253 253 253 253 253 253 253 253
39933 -253 253 253 253 253 253 221 221 221 6 6 6
39934 - 2 2 6 2 2 6 6 6 6 30 30 30
39935 - 2 2 6 2 2 6 2 2 6 2 2 6
39936 - 2 2 6 82 82 82 54 54 54 18 18 18
39937 - 6 6 6 0 0 0 0 0 0 0 0 0
39938 - 0 0 0 0 0 0 0 0 0 0 0 0
39939 - 0 0 0 0 0 0 0 0 0 0 0 0
39940 - 0 0 0 0 0 0 0 0 0 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 0 0 0
39942 - 0 0 0 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 10 10 10
39944 - 26 26 26 66 66 66 62 62 62 2 2 6
39945 - 2 2 6 38 38 38 10 10 10 26 26 26
39946 -238 238 238 253 253 253 253 253 253 253 253 253
39947 -253 253 253 253 253 253 253 253 253 253 253 253
39948 -253 253 253 253 253 253 231 231 231 238 238 238
39949 -253 253 253 253 253 253 253 253 253 253 253 253
39950 -253 253 253 253 253 253 253 253 253 253 253 253
39951 -253 253 253 253 253 253 253 253 253 253 253 253
39952 -253 253 253 253 253 253 253 253 253 253 253 253
39953 -253 253 253 253 253 253 231 231 231 6 6 6
39954 - 2 2 6 2 2 6 10 10 10 30 30 30
39955 - 2 2 6 2 2 6 2 2 6 2 2 6
39956 - 2 2 6 66 66 66 58 58 58 22 22 22
39957 - 6 6 6 0 0 0 0 0 0 0 0 0
39958 - 0 0 0 0 0 0 0 0 0 0 0 0
39959 - 0 0 0 0 0 0 0 0 0 0 0 0
39960 - 0 0 0 0 0 0 0 0 0 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 0 0 0
39962 - 0 0 0 0 0 0 0 0 0 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 10 10 10
39964 - 38 38 38 78 78 78 6 6 6 2 2 6
39965 - 2 2 6 46 46 46 14 14 14 42 42 42
39966 -246 246 246 253 253 253 253 253 253 253 253 253
39967 -253 253 253 253 253 253 253 253 253 253 253 253
39968 -253 253 253 253 253 253 231 231 231 242 242 242
39969 -253 253 253 253 253 253 253 253 253 253 253 253
39970 -253 253 253 253 253 253 253 253 253 253 253 253
39971 -253 253 253 253 253 253 253 253 253 253 253 253
39972 -253 253 253 253 253 253 253 253 253 253 253 253
39973 -253 253 253 253 253 253 234 234 234 10 10 10
39974 - 2 2 6 2 2 6 22 22 22 14 14 14
39975 - 2 2 6 2 2 6 2 2 6 2 2 6
39976 - 2 2 6 66 66 66 62 62 62 22 22 22
39977 - 6 6 6 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 0 0 0
39979 - 0 0 0 0 0 0 0 0 0 0 0 0
39980 - 0 0 0 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 6 6 6 18 18 18
39984 - 50 50 50 74 74 74 2 2 6 2 2 6
39985 - 14 14 14 70 70 70 34 34 34 62 62 62
39986 -250 250 250 253 253 253 253 253 253 253 253 253
39987 -253 253 253 253 253 253 253 253 253 253 253 253
39988 -253 253 253 253 253 253 231 231 231 246 246 246
39989 -253 253 253 253 253 253 253 253 253 253 253 253
39990 -253 253 253 253 253 253 253 253 253 253 253 253
39991 -253 253 253 253 253 253 253 253 253 253 253 253
39992 -253 253 253 253 253 253 253 253 253 253 253 253
39993 -253 253 253 253 253 253 234 234 234 14 14 14
39994 - 2 2 6 2 2 6 30 30 30 2 2 6
39995 - 2 2 6 2 2 6 2 2 6 2 2 6
39996 - 2 2 6 66 66 66 62 62 62 22 22 22
39997 - 6 6 6 0 0 0 0 0 0 0 0 0
39998 - 0 0 0 0 0 0 0 0 0 0 0 0
39999 - 0 0 0 0 0 0 0 0 0 0 0 0
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 0 0 0 6 6 6 18 18 18
40004 - 54 54 54 62 62 62 2 2 6 2 2 6
40005 - 2 2 6 30 30 30 46 46 46 70 70 70
40006 -250 250 250 253 253 253 253 253 253 253 253 253
40007 -253 253 253 253 253 253 253 253 253 253 253 253
40008 -253 253 253 253 253 253 231 231 231 246 246 246
40009 -253 253 253 253 253 253 253 253 253 253 253 253
40010 -253 253 253 253 253 253 253 253 253 253 253 253
40011 -253 253 253 253 253 253 253 253 253 253 253 253
40012 -253 253 253 253 253 253 253 253 253 253 253 253
40013 -253 253 253 253 253 253 226 226 226 10 10 10
40014 - 2 2 6 6 6 6 30 30 30 2 2 6
40015 - 2 2 6 2 2 6 2 2 6 2 2 6
40016 - 2 2 6 66 66 66 58 58 58 22 22 22
40017 - 6 6 6 0 0 0 0 0 0 0 0 0
40018 - 0 0 0 0 0 0 0 0 0 0 0 0
40019 - 0 0 0 0 0 0 0 0 0 0 0 0
40020 - 0 0 0 0 0 0 0 0 0 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 0 0 0 0 0 0 6 6 6 22 22 22
40024 - 58 58 58 62 62 62 2 2 6 2 2 6
40025 - 2 2 6 2 2 6 30 30 30 78 78 78
40026 -250 250 250 253 253 253 253 253 253 253 253 253
40027 -253 253 253 253 253 253 253 253 253 253 253 253
40028 -253 253 253 253 253 253 231 231 231 246 246 246
40029 -253 253 253 253 253 253 253 253 253 253 253 253
40030 -253 253 253 253 253 253 253 253 253 253 253 253
40031 -253 253 253 253 253 253 253 253 253 253 253 253
40032 -253 253 253 253 253 253 253 253 253 253 253 253
40033 -253 253 253 253 253 253 206 206 206 2 2 6
40034 - 22 22 22 34 34 34 18 14 6 22 22 22
40035 - 26 26 26 18 18 18 6 6 6 2 2 6
40036 - 2 2 6 82 82 82 54 54 54 18 18 18
40037 - 6 6 6 0 0 0 0 0 0 0 0 0
40038 - 0 0 0 0 0 0 0 0 0 0 0 0
40039 - 0 0 0 0 0 0 0 0 0 0 0 0
40040 - 0 0 0 0 0 0 0 0 0 0 0 0
40041 - 0 0 0 0 0 0 0 0 0 0 0 0
40042 - 0 0 0 0 0 0 0 0 0 0 0 0
40043 - 0 0 0 0 0 0 6 6 6 26 26 26
40044 - 62 62 62 106 106 106 74 54 14 185 133 11
40045 -210 162 10 121 92 8 6 6 6 62 62 62
40046 -238 238 238 253 253 253 253 253 253 253 253 253
40047 -253 253 253 253 253 253 253 253 253 253 253 253
40048 -253 253 253 253 253 253 231 231 231 246 246 246
40049 -253 253 253 253 253 253 253 253 253 253 253 253
40050 -253 253 253 253 253 253 253 253 253 253 253 253
40051 -253 253 253 253 253 253 253 253 253 253 253 253
40052 -253 253 253 253 253 253 253 253 253 253 253 253
40053 -253 253 253 253 253 253 158 158 158 18 18 18
40054 - 14 14 14 2 2 6 2 2 6 2 2 6
40055 - 6 6 6 18 18 18 66 66 66 38 38 38
40056 - 6 6 6 94 94 94 50 50 50 18 18 18
40057 - 6 6 6 0 0 0 0 0 0 0 0 0
40058 - 0 0 0 0 0 0 0 0 0 0 0 0
40059 - 0 0 0 0 0 0 0 0 0 0 0 0
40060 - 0 0 0 0 0 0 0 0 0 0 0 0
40061 - 0 0 0 0 0 0 0 0 0 0 0 0
40062 - 0 0 0 0 0 0 0 0 0 6 6 6
40063 - 10 10 10 10 10 10 18 18 18 38 38 38
40064 - 78 78 78 142 134 106 216 158 10 242 186 14
40065 -246 190 14 246 190 14 156 118 10 10 10 10
40066 - 90 90 90 238 238 238 253 253 253 253 253 253
40067 -253 253 253 253 253 253 253 253 253 253 253 253
40068 -253 253 253 253 253 253 231 231 231 250 250 250
40069 -253 253 253 253 253 253 253 253 253 253 253 253
40070 -253 253 253 253 253 253 253 253 253 253 253 253
40071 -253 253 253 253 253 253 253 253 253 253 253 253
40072 -253 253 253 253 253 253 253 253 253 246 230 190
40073 -238 204 91 238 204 91 181 142 44 37 26 9
40074 - 2 2 6 2 2 6 2 2 6 2 2 6
40075 - 2 2 6 2 2 6 38 38 38 46 46 46
40076 - 26 26 26 106 106 106 54 54 54 18 18 18
40077 - 6 6 6 0 0 0 0 0 0 0 0 0
40078 - 0 0 0 0 0 0 0 0 0 0 0 0
40079 - 0 0 0 0 0 0 0 0 0 0 0 0
40080 - 0 0 0 0 0 0 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 0 0 0 0
40082 - 0 0 0 6 6 6 14 14 14 22 22 22
40083 - 30 30 30 38 38 38 50 50 50 70 70 70
40084 -106 106 106 190 142 34 226 170 11 242 186 14
40085 -246 190 14 246 190 14 246 190 14 154 114 10
40086 - 6 6 6 74 74 74 226 226 226 253 253 253
40087 -253 253 253 253 253 253 253 253 253 253 253 253
40088 -253 253 253 253 253 253 231 231 231 250 250 250
40089 -253 253 253 253 253 253 253 253 253 253 253 253
40090 -253 253 253 253 253 253 253 253 253 253 253 253
40091 -253 253 253 253 253 253 253 253 253 253 253 253
40092 -253 253 253 253 253 253 253 253 253 228 184 62
40093 -241 196 14 241 208 19 232 195 16 38 30 10
40094 - 2 2 6 2 2 6 2 2 6 2 2 6
40095 - 2 2 6 6 6 6 30 30 30 26 26 26
40096 -203 166 17 154 142 90 66 66 66 26 26 26
40097 - 6 6 6 0 0 0 0 0 0 0 0 0
40098 - 0 0 0 0 0 0 0 0 0 0 0 0
40099 - 0 0 0 0 0 0 0 0 0 0 0 0
40100 - 0 0 0 0 0 0 0 0 0 0 0 0
40101 - 0 0 0 0 0 0 0 0 0 0 0 0
40102 - 6 6 6 18 18 18 38 38 38 58 58 58
40103 - 78 78 78 86 86 86 101 101 101 123 123 123
40104 -175 146 61 210 150 10 234 174 13 246 186 14
40105 -246 190 14 246 190 14 246 190 14 238 190 10
40106 -102 78 10 2 2 6 46 46 46 198 198 198
40107 -253 253 253 253 253 253 253 253 253 253 253 253
40108 -253 253 253 253 253 253 234 234 234 242 242 242
40109 -253 253 253 253 253 253 253 253 253 253 253 253
40110 -253 253 253 253 253 253 253 253 253 253 253 253
40111 -253 253 253 253 253 253 253 253 253 253 253 253
40112 -253 253 253 253 253 253 253 253 253 224 178 62
40113 -242 186 14 241 196 14 210 166 10 22 18 6
40114 - 2 2 6 2 2 6 2 2 6 2 2 6
40115 - 2 2 6 2 2 6 6 6 6 121 92 8
40116 -238 202 15 232 195 16 82 82 82 34 34 34
40117 - 10 10 10 0 0 0 0 0 0 0 0 0
40118 - 0 0 0 0 0 0 0 0 0 0 0 0
40119 - 0 0 0 0 0 0 0 0 0 0 0 0
40120 - 0 0 0 0 0 0 0 0 0 0 0 0
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 14 14 14 38 38 38 70 70 70 154 122 46
40123 -190 142 34 200 144 11 197 138 11 197 138 11
40124 -213 154 11 226 170 11 242 186 14 246 190 14
40125 -246 190 14 246 190 14 246 190 14 246 190 14
40126 -225 175 15 46 32 6 2 2 6 22 22 22
40127 -158 158 158 250 250 250 253 253 253 253 253 253
40128 -253 253 253 253 253 253 253 253 253 253 253 253
40129 -253 253 253 253 253 253 253 253 253 253 253 253
40130 -253 253 253 253 253 253 253 253 253 253 253 253
40131 -253 253 253 253 253 253 253 253 253 253 253 253
40132 -253 253 253 250 250 250 242 242 242 224 178 62
40133 -239 182 13 236 186 11 213 154 11 46 32 6
40134 - 2 2 6 2 2 6 2 2 6 2 2 6
40135 - 2 2 6 2 2 6 61 42 6 225 175 15
40136 -238 190 10 236 186 11 112 100 78 42 42 42
40137 - 14 14 14 0 0 0 0 0 0 0 0 0
40138 - 0 0 0 0 0 0 0 0 0 0 0 0
40139 - 0 0 0 0 0 0 0 0 0 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 6 6 6
40142 - 22 22 22 54 54 54 154 122 46 213 154 11
40143 -226 170 11 230 174 11 226 170 11 226 170 11
40144 -236 178 12 242 186 14 246 190 14 246 190 14
40145 -246 190 14 246 190 14 246 190 14 246 190 14
40146 -241 196 14 184 144 12 10 10 10 2 2 6
40147 - 6 6 6 116 116 116 242 242 242 253 253 253
40148 -253 253 253 253 253 253 253 253 253 253 253 253
40149 -253 253 253 253 253 253 253 253 253 253 253 253
40150 -253 253 253 253 253 253 253 253 253 253 253 253
40151 -253 253 253 253 253 253 253 253 253 253 253 253
40152 -253 253 253 231 231 231 198 198 198 214 170 54
40153 -236 178 12 236 178 12 210 150 10 137 92 6
40154 - 18 14 6 2 2 6 2 2 6 2 2 6
40155 - 6 6 6 70 47 6 200 144 11 236 178 12
40156 -239 182 13 239 182 13 124 112 88 58 58 58
40157 - 22 22 22 6 6 6 0 0 0 0 0 0
40158 - 0 0 0 0 0 0 0 0 0 0 0 0
40159 - 0 0 0 0 0 0 0 0 0 0 0 0
40160 - 0 0 0 0 0 0 0 0 0 0 0 0
40161 - 0 0 0 0 0 0 0 0 0 10 10 10
40162 - 30 30 30 70 70 70 180 133 36 226 170 11
40163 -239 182 13 242 186 14 242 186 14 246 186 14
40164 -246 190 14 246 190 14 246 190 14 246 190 14
40165 -246 190 14 246 190 14 246 190 14 246 190 14
40166 -246 190 14 232 195 16 98 70 6 2 2 6
40167 - 2 2 6 2 2 6 66 66 66 221 221 221
40168 -253 253 253 253 253 253 253 253 253 253 253 253
40169 -253 253 253 253 253 253 253 253 253 253 253 253
40170 -253 253 253 253 253 253 253 253 253 253 253 253
40171 -253 253 253 253 253 253 253 253 253 253 253 253
40172 -253 253 253 206 206 206 198 198 198 214 166 58
40173 -230 174 11 230 174 11 216 158 10 192 133 9
40174 -163 110 8 116 81 8 102 78 10 116 81 8
40175 -167 114 7 197 138 11 226 170 11 239 182 13
40176 -242 186 14 242 186 14 162 146 94 78 78 78
40177 - 34 34 34 14 14 14 6 6 6 0 0 0
40178 - 0 0 0 0 0 0 0 0 0 0 0 0
40179 - 0 0 0 0 0 0 0 0 0 0 0 0
40180 - 0 0 0 0 0 0 0 0 0 0 0 0
40181 - 0 0 0 0 0 0 0 0 0 6 6 6
40182 - 30 30 30 78 78 78 190 142 34 226 170 11
40183 -239 182 13 246 190 14 246 190 14 246 190 14
40184 -246 190 14 246 190 14 246 190 14 246 190 14
40185 -246 190 14 246 190 14 246 190 14 246 190 14
40186 -246 190 14 241 196 14 203 166 17 22 18 6
40187 - 2 2 6 2 2 6 2 2 6 38 38 38
40188 -218 218 218 253 253 253 253 253 253 253 253 253
40189 -253 253 253 253 253 253 253 253 253 253 253 253
40190 -253 253 253 253 253 253 253 253 253 253 253 253
40191 -253 253 253 253 253 253 253 253 253 253 253 253
40192 -250 250 250 206 206 206 198 198 198 202 162 69
40193 -226 170 11 236 178 12 224 166 10 210 150 10
40194 -200 144 11 197 138 11 192 133 9 197 138 11
40195 -210 150 10 226 170 11 242 186 14 246 190 14
40196 -246 190 14 246 186 14 225 175 15 124 112 88
40197 - 62 62 62 30 30 30 14 14 14 6 6 6
40198 - 0 0 0 0 0 0 0 0 0 0 0 0
40199 - 0 0 0 0 0 0 0 0 0 0 0 0
40200 - 0 0 0 0 0 0 0 0 0 0 0 0
40201 - 0 0 0 0 0 0 0 0 0 10 10 10
40202 - 30 30 30 78 78 78 174 135 50 224 166 10
40203 -239 182 13 246 190 14 246 190 14 246 190 14
40204 -246 190 14 246 190 14 246 190 14 246 190 14
40205 -246 190 14 246 190 14 246 190 14 246 190 14
40206 -246 190 14 246 190 14 241 196 14 139 102 15
40207 - 2 2 6 2 2 6 2 2 6 2 2 6
40208 - 78 78 78 250 250 250 253 253 253 253 253 253
40209 -253 253 253 253 253 253 253 253 253 253 253 253
40210 -253 253 253 253 253 253 253 253 253 253 253 253
40211 -253 253 253 253 253 253 253 253 253 253 253 253
40212 -250 250 250 214 214 214 198 198 198 190 150 46
40213 -219 162 10 236 178 12 234 174 13 224 166 10
40214 -216 158 10 213 154 11 213 154 11 216 158 10
40215 -226 170 11 239 182 13 246 190 14 246 190 14
40216 -246 190 14 246 190 14 242 186 14 206 162 42
40217 -101 101 101 58 58 58 30 30 30 14 14 14
40218 - 6 6 6 0 0 0 0 0 0 0 0 0
40219 - 0 0 0 0 0 0 0 0 0 0 0 0
40220 - 0 0 0 0 0 0 0 0 0 0 0 0
40221 - 0 0 0 0 0 0 0 0 0 10 10 10
40222 - 30 30 30 74 74 74 174 135 50 216 158 10
40223 -236 178 12 246 190 14 246 190 14 246 190 14
40224 -246 190 14 246 190 14 246 190 14 246 190 14
40225 -246 190 14 246 190 14 246 190 14 246 190 14
40226 -246 190 14 246 190 14 241 196 14 226 184 13
40227 - 61 42 6 2 2 6 2 2 6 2 2 6
40228 - 22 22 22 238 238 238 253 253 253 253 253 253
40229 -253 253 253 253 253 253 253 253 253 253 253 253
40230 -253 253 253 253 253 253 253 253 253 253 253 253
40231 -253 253 253 253 253 253 253 253 253 253 253 253
40232 -253 253 253 226 226 226 187 187 187 180 133 36
40233 -216 158 10 236 178 12 239 182 13 236 178 12
40234 -230 174 11 226 170 11 226 170 11 230 174 11
40235 -236 178 12 242 186 14 246 190 14 246 190 14
40236 -246 190 14 246 190 14 246 186 14 239 182 13
40237 -206 162 42 106 106 106 66 66 66 34 34 34
40238 - 14 14 14 6 6 6 0 0 0 0 0 0
40239 - 0 0 0 0 0 0 0 0 0 0 0 0
40240 - 0 0 0 0 0 0 0 0 0 0 0 0
40241 - 0 0 0 0 0 0 0 0 0 6 6 6
40242 - 26 26 26 70 70 70 163 133 67 213 154 11
40243 -236 178 12 246 190 14 246 190 14 246 190 14
40244 -246 190 14 246 190 14 246 190 14 246 190 14
40245 -246 190 14 246 190 14 246 190 14 246 190 14
40246 -246 190 14 246 190 14 246 190 14 241 196 14
40247 -190 146 13 18 14 6 2 2 6 2 2 6
40248 - 46 46 46 246 246 246 253 253 253 253 253 253
40249 -253 253 253 253 253 253 253 253 253 253 253 253
40250 -253 253 253 253 253 253 253 253 253 253 253 253
40251 -253 253 253 253 253 253 253 253 253 253 253 253
40252 -253 253 253 221 221 221 86 86 86 156 107 11
40253 -216 158 10 236 178 12 242 186 14 246 186 14
40254 -242 186 14 239 182 13 239 182 13 242 186 14
40255 -242 186 14 246 186 14 246 190 14 246 190 14
40256 -246 190 14 246 190 14 246 190 14 246 190 14
40257 -242 186 14 225 175 15 142 122 72 66 66 66
40258 - 30 30 30 10 10 10 0 0 0 0 0 0
40259 - 0 0 0 0 0 0 0 0 0 0 0 0
40260 - 0 0 0 0 0 0 0 0 0 0 0 0
40261 - 0 0 0 0 0 0 0 0 0 6 6 6
40262 - 26 26 26 70 70 70 163 133 67 210 150 10
40263 -236 178 12 246 190 14 246 190 14 246 190 14
40264 -246 190 14 246 190 14 246 190 14 246 190 14
40265 -246 190 14 246 190 14 246 190 14 246 190 14
40266 -246 190 14 246 190 14 246 190 14 246 190 14
40267 -232 195 16 121 92 8 34 34 34 106 106 106
40268 -221 221 221 253 253 253 253 253 253 253 253 253
40269 -253 253 253 253 253 253 253 253 253 253 253 253
40270 -253 253 253 253 253 253 253 253 253 253 253 253
40271 -253 253 253 253 253 253 253 253 253 253 253 253
40272 -242 242 242 82 82 82 18 14 6 163 110 8
40273 -216 158 10 236 178 12 242 186 14 246 190 14
40274 -246 190 14 246 190 14 246 190 14 246 190 14
40275 -246 190 14 246 190 14 246 190 14 246 190 14
40276 -246 190 14 246 190 14 246 190 14 246 190 14
40277 -246 190 14 246 190 14 242 186 14 163 133 67
40278 - 46 46 46 18 18 18 6 6 6 0 0 0
40279 - 0 0 0 0 0 0 0 0 0 0 0 0
40280 - 0 0 0 0 0 0 0 0 0 0 0 0
40281 - 0 0 0 0 0 0 0 0 0 10 10 10
40282 - 30 30 30 78 78 78 163 133 67 210 150 10
40283 -236 178 12 246 186 14 246 190 14 246 190 14
40284 -246 190 14 246 190 14 246 190 14 246 190 14
40285 -246 190 14 246 190 14 246 190 14 246 190 14
40286 -246 190 14 246 190 14 246 190 14 246 190 14
40287 -241 196 14 215 174 15 190 178 144 253 253 253
40288 -253 253 253 253 253 253 253 253 253 253 253 253
40289 -253 253 253 253 253 253 253 253 253 253 253 253
40290 -253 253 253 253 253 253 253 253 253 253 253 253
40291 -253 253 253 253 253 253 253 253 253 218 218 218
40292 - 58 58 58 2 2 6 22 18 6 167 114 7
40293 -216 158 10 236 178 12 246 186 14 246 190 14
40294 -246 190 14 246 190 14 246 190 14 246 190 14
40295 -246 190 14 246 190 14 246 190 14 246 190 14
40296 -246 190 14 246 190 14 246 190 14 246 190 14
40297 -246 190 14 246 186 14 242 186 14 190 150 46
40298 - 54 54 54 22 22 22 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 14 14 14
40302 - 38 38 38 86 86 86 180 133 36 213 154 11
40303 -236 178 12 246 186 14 246 190 14 246 190 14
40304 -246 190 14 246 190 14 246 190 14 246 190 14
40305 -246 190 14 246 190 14 246 190 14 246 190 14
40306 -246 190 14 246 190 14 246 190 14 246 190 14
40307 -246 190 14 232 195 16 190 146 13 214 214 214
40308 -253 253 253 253 253 253 253 253 253 253 253 253
40309 -253 253 253 253 253 253 253 253 253 253 253 253
40310 -253 253 253 253 253 253 253 253 253 253 253 253
40311 -253 253 253 250 250 250 170 170 170 26 26 26
40312 - 2 2 6 2 2 6 37 26 9 163 110 8
40313 -219 162 10 239 182 13 246 186 14 246 190 14
40314 -246 190 14 246 190 14 246 190 14 246 190 14
40315 -246 190 14 246 190 14 246 190 14 246 190 14
40316 -246 190 14 246 190 14 246 190 14 246 190 14
40317 -246 186 14 236 178 12 224 166 10 142 122 72
40318 - 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
40322 - 50 50 50 109 106 95 192 133 9 224 166 10
40323 -242 186 14 246 190 14 246 190 14 246 190 14
40324 -246 190 14 246 190 14 246 190 14 246 190 14
40325 -246 190 14 246 190 14 246 190 14 246 190 14
40326 -246 190 14 246 190 14 246 190 14 246 190 14
40327 -242 186 14 226 184 13 210 162 10 142 110 46
40328 -226 226 226 253 253 253 253 253 253 253 253 253
40329 -253 253 253 253 253 253 253 253 253 253 253 253
40330 -253 253 253 253 253 253 253 253 253 253 253 253
40331 -198 198 198 66 66 66 2 2 6 2 2 6
40332 - 2 2 6 2 2 6 50 34 6 156 107 11
40333 -219 162 10 239 182 13 246 186 14 246 190 14
40334 -246 190 14 246 190 14 246 190 14 246 190 14
40335 -246 190 14 246 190 14 246 190 14 246 190 14
40336 -246 190 14 246 190 14 246 190 14 242 186 14
40337 -234 174 13 213 154 11 154 122 46 66 66 66
40338 - 30 30 30 10 10 10 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 6 6 6 22 22 22
40342 - 58 58 58 154 121 60 206 145 10 234 174 13
40343 -242 186 14 246 186 14 246 190 14 246 190 14
40344 -246 190 14 246 190 14 246 190 14 246 190 14
40345 -246 190 14 246 190 14 246 190 14 246 190 14
40346 -246 190 14 246 190 14 246 190 14 246 190 14
40347 -246 186 14 236 178 12 210 162 10 163 110 8
40348 - 61 42 6 138 138 138 218 218 218 250 250 250
40349 -253 253 253 253 253 253 253 253 253 250 250 250
40350 -242 242 242 210 210 210 144 144 144 66 66 66
40351 - 6 6 6 2 2 6 2 2 6 2 2 6
40352 - 2 2 6 2 2 6 61 42 6 163 110 8
40353 -216 158 10 236 178 12 246 190 14 246 190 14
40354 -246 190 14 246 190 14 246 190 14 246 190 14
40355 -246 190 14 246 190 14 246 190 14 246 190 14
40356 -246 190 14 239 182 13 230 174 11 216 158 10
40357 -190 142 34 124 112 88 70 70 70 38 38 38
40358 - 18 18 18 6 6 6 0 0 0 0 0 0
40359 - 0 0 0 0 0 0 0 0 0 0 0 0
40360 - 0 0 0 0 0 0 0 0 0 0 0 0
40361 - 0 0 0 0 0 0 6 6 6 22 22 22
40362 - 62 62 62 168 124 44 206 145 10 224 166 10
40363 -236 178 12 239 182 13 242 186 14 242 186 14
40364 -246 186 14 246 190 14 246 190 14 246 190 14
40365 -246 190 14 246 190 14 246 190 14 246 190 14
40366 -246 190 14 246 190 14 246 190 14 246 190 14
40367 -246 190 14 236 178 12 216 158 10 175 118 6
40368 - 80 54 7 2 2 6 6 6 6 30 30 30
40369 - 54 54 54 62 62 62 50 50 50 38 38 38
40370 - 14 14 14 2 2 6 2 2 6 2 2 6
40371 - 2 2 6 2 2 6 2 2 6 2 2 6
40372 - 2 2 6 6 6 6 80 54 7 167 114 7
40373 -213 154 11 236 178 12 246 190 14 246 190 14
40374 -246 190 14 246 190 14 246 190 14 246 190 14
40375 -246 190 14 242 186 14 239 182 13 239 182 13
40376 -230 174 11 210 150 10 174 135 50 124 112 88
40377 - 82 82 82 54 54 54 34 34 34 18 18 18
40378 - 6 6 6 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 0 0 0
40380 - 0 0 0 0 0 0 0 0 0 0 0 0
40381 - 0 0 0 0 0 0 6 6 6 18 18 18
40382 - 50 50 50 158 118 36 192 133 9 200 144 11
40383 -216 158 10 219 162 10 224 166 10 226 170 11
40384 -230 174 11 236 178 12 239 182 13 239 182 13
40385 -242 186 14 246 186 14 246 190 14 246 190 14
40386 -246 190 14 246 190 14 246 190 14 246 190 14
40387 -246 186 14 230 174 11 210 150 10 163 110 8
40388 -104 69 6 10 10 10 2 2 6 2 2 6
40389 - 2 2 6 2 2 6 2 2 6 2 2 6
40390 - 2 2 6 2 2 6 2 2 6 2 2 6
40391 - 2 2 6 2 2 6 2 2 6 2 2 6
40392 - 2 2 6 6 6 6 91 60 6 167 114 7
40393 -206 145 10 230 174 11 242 186 14 246 190 14
40394 -246 190 14 246 190 14 246 186 14 242 186 14
40395 -239 182 13 230 174 11 224 166 10 213 154 11
40396 -180 133 36 124 112 88 86 86 86 58 58 58
40397 - 38 38 38 22 22 22 10 10 10 6 6 6
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 0 0 0
40400 - 0 0 0 0 0 0 0 0 0 0 0 0
40401 - 0 0 0 0 0 0 0 0 0 14 14 14
40402 - 34 34 34 70 70 70 138 110 50 158 118 36
40403 -167 114 7 180 123 7 192 133 9 197 138 11
40404 -200 144 11 206 145 10 213 154 11 219 162 10
40405 -224 166 10 230 174 11 239 182 13 242 186 14
40406 -246 186 14 246 186 14 246 186 14 246 186 14
40407 -239 182 13 216 158 10 185 133 11 152 99 6
40408 -104 69 6 18 14 6 2 2 6 2 2 6
40409 - 2 2 6 2 2 6 2 2 6 2 2 6
40410 - 2 2 6 2 2 6 2 2 6 2 2 6
40411 - 2 2 6 2 2 6 2 2 6 2 2 6
40412 - 2 2 6 6 6 6 80 54 7 152 99 6
40413 -192 133 9 219 162 10 236 178 12 239 182 13
40414 -246 186 14 242 186 14 239 182 13 236 178 12
40415 -224 166 10 206 145 10 192 133 9 154 121 60
40416 - 94 94 94 62 62 62 42 42 42 22 22 22
40417 - 14 14 14 6 6 6 0 0 0 0 0 0
40418 - 0 0 0 0 0 0 0 0 0 0 0 0
40419 - 0 0 0 0 0 0 0 0 0 0 0 0
40420 - 0 0 0 0 0 0 0 0 0 0 0 0
40421 - 0 0 0 0 0 0 0 0 0 6 6 6
40422 - 18 18 18 34 34 34 58 58 58 78 78 78
40423 -101 98 89 124 112 88 142 110 46 156 107 11
40424 -163 110 8 167 114 7 175 118 6 180 123 7
40425 -185 133 11 197 138 11 210 150 10 219 162 10
40426 -226 170 11 236 178 12 236 178 12 234 174 13
40427 -219 162 10 197 138 11 163 110 8 130 83 6
40428 - 91 60 6 10 10 10 2 2 6 2 2 6
40429 - 18 18 18 38 38 38 38 38 38 38 38 38
40430 - 38 38 38 38 38 38 38 38 38 38 38 38
40431 - 38 38 38 38 38 38 26 26 26 2 2 6
40432 - 2 2 6 6 6 6 70 47 6 137 92 6
40433 -175 118 6 200 144 11 219 162 10 230 174 11
40434 -234 174 13 230 174 11 219 162 10 210 150 10
40435 -192 133 9 163 110 8 124 112 88 82 82 82
40436 - 50 50 50 30 30 30 14 14 14 6 6 6
40437 - 0 0 0 0 0 0 0 0 0 0 0 0
40438 - 0 0 0 0 0 0 0 0 0 0 0 0
40439 - 0 0 0 0 0 0 0 0 0 0 0 0
40440 - 0 0 0 0 0 0 0 0 0 0 0 0
40441 - 0 0 0 0 0 0 0 0 0 0 0 0
40442 - 6 6 6 14 14 14 22 22 22 34 34 34
40443 - 42 42 42 58 58 58 74 74 74 86 86 86
40444 -101 98 89 122 102 70 130 98 46 121 87 25
40445 -137 92 6 152 99 6 163 110 8 180 123 7
40446 -185 133 11 197 138 11 206 145 10 200 144 11
40447 -180 123 7 156 107 11 130 83 6 104 69 6
40448 - 50 34 6 54 54 54 110 110 110 101 98 89
40449 - 86 86 86 82 82 82 78 78 78 78 78 78
40450 - 78 78 78 78 78 78 78 78 78 78 78 78
40451 - 78 78 78 82 82 82 86 86 86 94 94 94
40452 -106 106 106 101 101 101 86 66 34 124 80 6
40453 -156 107 11 180 123 7 192 133 9 200 144 11
40454 -206 145 10 200 144 11 192 133 9 175 118 6
40455 -139 102 15 109 106 95 70 70 70 42 42 42
40456 - 22 22 22 10 10 10 0 0 0 0 0 0
40457 - 0 0 0 0 0 0 0 0 0 0 0 0
40458 - 0 0 0 0 0 0 0 0 0 0 0 0
40459 - 0 0 0 0 0 0 0 0 0 0 0 0
40460 - 0 0 0 0 0 0 0 0 0 0 0 0
40461 - 0 0 0 0 0 0 0 0 0 0 0 0
40462 - 0 0 0 0 0 0 6 6 6 10 10 10
40463 - 14 14 14 22 22 22 30 30 30 38 38 38
40464 - 50 50 50 62 62 62 74 74 74 90 90 90
40465 -101 98 89 112 100 78 121 87 25 124 80 6
40466 -137 92 6 152 99 6 152 99 6 152 99 6
40467 -138 86 6 124 80 6 98 70 6 86 66 30
40468 -101 98 89 82 82 82 58 58 58 46 46 46
40469 - 38 38 38 34 34 34 34 34 34 34 34 34
40470 - 34 34 34 34 34 34 34 34 34 34 34 34
40471 - 34 34 34 34 34 34 38 38 38 42 42 42
40472 - 54 54 54 82 82 82 94 86 76 91 60 6
40473 -134 86 6 156 107 11 167 114 7 175 118 6
40474 -175 118 6 167 114 7 152 99 6 121 87 25
40475 -101 98 89 62 62 62 34 34 34 18 18 18
40476 - 6 6 6 0 0 0 0 0 0 0 0 0
40477 - 0 0 0 0 0 0 0 0 0 0 0 0
40478 - 0 0 0 0 0 0 0 0 0 0 0 0
40479 - 0 0 0 0 0 0 0 0 0 0 0 0
40480 - 0 0 0 0 0 0 0 0 0 0 0 0
40481 - 0 0 0 0 0 0 0 0 0 0 0 0
40482 - 0 0 0 0 0 0 0 0 0 0 0 0
40483 - 0 0 0 6 6 6 6 6 6 10 10 10
40484 - 18 18 18 22 22 22 30 30 30 42 42 42
40485 - 50 50 50 66 66 66 86 86 86 101 98 89
40486 -106 86 58 98 70 6 104 69 6 104 69 6
40487 -104 69 6 91 60 6 82 62 34 90 90 90
40488 - 62 62 62 38 38 38 22 22 22 14 14 14
40489 - 10 10 10 10 10 10 10 10 10 10 10 10
40490 - 10 10 10 10 10 10 6 6 6 10 10 10
40491 - 10 10 10 10 10 10 10 10 10 14 14 14
40492 - 22 22 22 42 42 42 70 70 70 89 81 66
40493 - 80 54 7 104 69 6 124 80 6 137 92 6
40494 -134 86 6 116 81 8 100 82 52 86 86 86
40495 - 58 58 58 30 30 30 14 14 14 6 6 6
40496 - 0 0 0 0 0 0 0 0 0 0 0 0
40497 - 0 0 0 0 0 0 0 0 0 0 0 0
40498 - 0 0 0 0 0 0 0 0 0 0 0 0
40499 - 0 0 0 0 0 0 0 0 0 0 0 0
40500 - 0 0 0 0 0 0 0 0 0 0 0 0
40501 - 0 0 0 0 0 0 0 0 0 0 0 0
40502 - 0 0 0 0 0 0 0 0 0 0 0 0
40503 - 0 0 0 0 0 0 0 0 0 0 0 0
40504 - 0 0 0 6 6 6 10 10 10 14 14 14
40505 - 18 18 18 26 26 26 38 38 38 54 54 54
40506 - 70 70 70 86 86 86 94 86 76 89 81 66
40507 - 89 81 66 86 86 86 74 74 74 50 50 50
40508 - 30 30 30 14 14 14 6 6 6 0 0 0
40509 - 0 0 0 0 0 0 0 0 0 0 0 0
40510 - 0 0 0 0 0 0 0 0 0 0 0 0
40511 - 0 0 0 0 0 0 0 0 0 0 0 0
40512 - 6 6 6 18 18 18 34 34 34 58 58 58
40513 - 82 82 82 89 81 66 89 81 66 89 81 66
40514 - 94 86 66 94 86 76 74 74 74 50 50 50
40515 - 26 26 26 14 14 14 6 6 6 0 0 0
40516 - 0 0 0 0 0 0 0 0 0 0 0 0
40517 - 0 0 0 0 0 0 0 0 0 0 0 0
40518 - 0 0 0 0 0 0 0 0 0 0 0 0
40519 - 0 0 0 0 0 0 0 0 0 0 0 0
40520 - 0 0 0 0 0 0 0 0 0 0 0 0
40521 - 0 0 0 0 0 0 0 0 0 0 0 0
40522 - 0 0 0 0 0 0 0 0 0 0 0 0
40523 - 0 0 0 0 0 0 0 0 0 0 0 0
40524 - 0 0 0 0 0 0 0 0 0 0 0 0
40525 - 6 6 6 6 6 6 14 14 14 18 18 18
40526 - 30 30 30 38 38 38 46 46 46 54 54 54
40527 - 50 50 50 42 42 42 30 30 30 18 18 18
40528 - 10 10 10 0 0 0 0 0 0 0 0 0
40529 - 0 0 0 0 0 0 0 0 0 0 0 0
40530 - 0 0 0 0 0 0 0 0 0 0 0 0
40531 - 0 0 0 0 0 0 0 0 0 0 0 0
40532 - 0 0 0 6 6 6 14 14 14 26 26 26
40533 - 38 38 38 50 50 50 58 58 58 58 58 58
40534 - 54 54 54 42 42 42 30 30 30 18 18 18
40535 - 10 10 10 0 0 0 0 0 0 0 0 0
40536 - 0 0 0 0 0 0 0 0 0 0 0 0
40537 - 0 0 0 0 0 0 0 0 0 0 0 0
40538 - 0 0 0 0 0 0 0 0 0 0 0 0
40539 - 0 0 0 0 0 0 0 0 0 0 0 0
40540 - 0 0 0 0 0 0 0 0 0 0 0 0
40541 - 0 0 0 0 0 0 0 0 0 0 0 0
40542 - 0 0 0 0 0 0 0 0 0 0 0 0
40543 - 0 0 0 0 0 0 0 0 0 0 0 0
40544 - 0 0 0 0 0 0 0 0 0 0 0 0
40545 - 0 0 0 0 0 0 0 0 0 6 6 6
40546 - 6 6 6 10 10 10 14 14 14 18 18 18
40547 - 18 18 18 14 14 14 10 10 10 6 6 6
40548 - 0 0 0 0 0 0 0 0 0 0 0 0
40549 - 0 0 0 0 0 0 0 0 0 0 0 0
40550 - 0 0 0 0 0 0 0 0 0 0 0 0
40551 - 0 0 0 0 0 0 0 0 0 0 0 0
40552 - 0 0 0 0 0 0 0 0 0 6 6 6
40553 - 14 14 14 18 18 18 22 22 22 22 22 22
40554 - 18 18 18 14 14 14 10 10 10 6 6 6
40555 - 0 0 0 0 0 0 0 0 0 0 0 0
40556 - 0 0 0 0 0 0 0 0 0 0 0 0
40557 - 0 0 0 0 0 0 0 0 0 0 0 0
40558 - 0 0 0 0 0 0 0 0 0 0 0 0
40559 - 0 0 0 0 0 0 0 0 0 0 0 0
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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40566 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
40576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40601 +4 4 4 4 4 4
40602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40615 +4 4 4 4 4 4
40616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40629 +4 4 4 4 4 4
40630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40643 +4 4 4 4 4 4
40644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40648 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40649 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40653 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40654 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40655 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40657 +4 4 4 4 4 4
40658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40662 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40663 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40664 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40667 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40668 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40669 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40670 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40671 +4 4 4 4 4 4
40672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40676 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40677 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40678 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40681 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40682 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40683 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40684 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40685 +4 4 4 4 4 4
40686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40689 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40690 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40691 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40692 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40694 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40695 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40696 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40697 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40698 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40699 +4 4 4 4 4 4
40700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40703 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40704 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40705 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40706 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40707 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40708 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40709 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40710 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40711 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40712 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40713 +4 4 4 4 4 4
40714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40717 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40718 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40719 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40720 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40721 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40722 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40723 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40724 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40725 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40726 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40727 +4 4 4 4 4 4
40728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40730 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40731 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40732 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40733 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40734 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40735 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40736 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40737 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40738 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40739 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40740 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40741 +4 4 4 4 4 4
40742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40744 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40745 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40746 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40747 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40748 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40749 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40750 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40751 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40752 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40753 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40754 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40755 +4 4 4 4 4 4
40756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40758 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40759 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40760 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40761 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40762 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40763 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40764 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40765 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40766 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40767 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40768 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40769 +4 4 4 4 4 4
40770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40772 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40773 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40774 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40775 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40776 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40777 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40778 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40779 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40780 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40781 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40782 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40783 +4 4 4 4 4 4
40784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40785 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40786 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40787 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40788 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40789 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40790 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40791 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40792 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40793 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40794 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40795 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40796 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40797 +4 4 4 4 4 4
40798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40799 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40800 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40801 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40802 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40803 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40804 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40805 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40806 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40807 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40808 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40809 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40810 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40811 +0 0 0 4 4 4
40812 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40813 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40814 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40815 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40816 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40817 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40818 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40819 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40820 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40821 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40822 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40823 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40824 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40825 +2 0 0 0 0 0
40826 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40827 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40828 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40829 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40830 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40831 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40832 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40833 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40834 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40835 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40836 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40837 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40838 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40839 +37 38 37 0 0 0
40840 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40841 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40842 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40843 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40844 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40845 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40846 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40847 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40848 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40849 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40850 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40851 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40852 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40853 +85 115 134 4 0 0
40854 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40855 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40856 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40857 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40858 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40859 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40860 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40861 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40862 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40863 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40864 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40865 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40866 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40867 +60 73 81 4 0 0
40868 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40869 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40870 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40871 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40872 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40873 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40874 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40875 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40876 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40877 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40878 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40879 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40880 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40881 +16 19 21 4 0 0
40882 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40883 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40884 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40885 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40886 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40887 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40888 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40889 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40890 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40891 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40892 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40893 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40894 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40895 +4 0 0 4 3 3
40896 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40897 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40898 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40900 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40901 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40902 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40903 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40904 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40905 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40906 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40907 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40908 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40909 +3 2 2 4 4 4
40910 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40911 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40912 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40913 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40914 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40915 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40916 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40917 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40918 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40919 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40920 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40921 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40922 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40923 +4 4 4 4 4 4
40924 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40925 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40926 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40927 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40928 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40929 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40930 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40931 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40932 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40933 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40934 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40935 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40936 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40937 +4 4 4 4 4 4
40938 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40939 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40940 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40941 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40942 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40943 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40944 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40945 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40946 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40947 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40948 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40949 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40950 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40951 +5 5 5 5 5 5
40952 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40953 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40954 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40955 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40956 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40957 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40958 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40959 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40960 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40961 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40962 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40963 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40964 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40965 +5 5 5 4 4 4
40966 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40967 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40968 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40969 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40970 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40971 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40972 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40973 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40974 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40975 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40976 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40977 +4 0 0 4 0 0 5 5 5 5 5 5 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 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40981 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40982 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40983 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40984 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40985 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40986 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40987 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40988 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40989 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40990 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40991 +3 3 3 5 5 5 6 6 6 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 41 54 63 137 136 137 153 152 153 137 136 137
40995 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40996 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40997 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40998 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40999 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41000 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41001 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41002 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41003 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41004 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41009 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41010 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41011 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41012 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41013 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41014 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41015 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41016 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41017 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41018 +6 6 6 4 0 0 4 0 0 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 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41023 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41024 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41025 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41026 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41027 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41028 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41029 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41030 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41031 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41032 +4 0 0 4 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 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41037 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41038 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41039 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41040 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41041 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41042 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41043 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41044 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41045 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41046 +6 6 6 4 0 0 6 6 6 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 41 54 63 163 162 163 166 165 166 154 154 154
41051 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41052 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41053 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41054 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41055 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41056 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41057 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41058 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41059 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41060 +4 0 0 3 2 2 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 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41065 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41066 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41067 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41068 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41069 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41070 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41071 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41072 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41073 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41074 +4 0 0 4 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 167 166 167 174 174 174 163 162 163
41079 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41080 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41081 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41082 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41083 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41084 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41085 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41086 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41087 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41088 +4 0 0 4 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 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41093 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41094 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41095 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41096 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41097 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41098 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41099 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41100 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41101 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41102 +4 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 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41107 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41108 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41109 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41110 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41111 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41112 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41113 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41114 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41115 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
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 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41121 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41122 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41123 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41124 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41125 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41126 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41127 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41128 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41129 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41130 +0 0 0 3 3 3 5 5 5 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 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41135 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41136 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41137 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41138 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41139 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41140 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41141 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41142 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41143 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41144 +0 0 0 3 3 3 5 5 5 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 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41149 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41150 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41151 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41152 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41153 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41154 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41155 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41156 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41157 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41158 +0 0 0 3 3 3 5 5 5 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 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41163 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41164 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41165 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41166 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41167 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41168 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41169 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41170 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41171 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41172 +0 0 0 3 3 3 5 5 5 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 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41177 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41178 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41179 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41180 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41181 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41182 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41183 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41184 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41185 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41186 +0 0 0 3 3 3 5 5 5 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 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41191 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41192 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41193 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41194 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41195 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41196 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41197 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41198 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41199 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41200 +0 0 0 3 3 3 5 5 5 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 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41205 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41206 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41207 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41208 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41209 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41210 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41211 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41212 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41213 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41214 +0 0 0 3 3 3 5 5 5 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 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41219 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41220 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41221 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41222 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41223 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41224 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41225 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41226 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41227 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41228 +0 0 0 3 3 3 5 5 5 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 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41233 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41234 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41235 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41236 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41237 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41238 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41239 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41240 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41241 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41242 +0 0 0 3 3 3 5 5 5 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 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41247 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41248 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41249 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41250 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41251 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41252 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41253 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41254 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41255 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41256 +0 0 0 3 3 3 5 5 5 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 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41261 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41262 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41263 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41264 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41265 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41266 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41267 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41268 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41269 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41270 +0 0 0 3 3 3 5 5 5 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 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41275 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41276 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41277 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41278 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41279 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41280 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41281 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41282 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41283 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41284 +0 0 0 3 3 3 5 5 5 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 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41289 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41290 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41291 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41292 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41293 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41294 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41295 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41296 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41297 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41298 +0 0 0 3 3 3 5 5 5 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 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41303 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41304 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41305 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41306 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41307 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41308 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41309 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41310 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41311 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41312 +0 0 0 3 3 3 5 5 5 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 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41317 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41318 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41319 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41320 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41321 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41322 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41323 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41324 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41325 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41326 +0 0 0 3 3 3 5 5 5 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 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41331 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41332 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41333 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41334 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41335 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41336 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41337 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41338 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41339 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41340 +0 0 0 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 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41345 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41346 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41347 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41348 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41349 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41350 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41352 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41353 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41354 +4 3 3 5 5 5 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 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41359 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41360 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41361 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41362 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41363 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41364 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41365 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41366 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41367 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41368 +5 5 5 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 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41373 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41374 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41375 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41376 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41377 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41378 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41379 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41380 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41381 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41387 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41388 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41389 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41390 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41391 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41392 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41393 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41394 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41395 +13 16 17 4 0 0 4 0 0 4 3 3 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 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41401 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41402 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41403 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41404 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41405 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41406 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41407 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41408 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41409 +4 0 0 4 0 0 5 5 5 5 5 5 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 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41415 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41416 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41417 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41418 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41419 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41420 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41421 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41422 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41423 +4 3 3 5 5 5 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 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41429 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41430 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41431 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41432 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41433 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41434 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41435 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41436 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41443 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41444 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41445 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41446 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41447 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41448 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41449 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41450 +4 0 0 4 0 0 4 0 0 6 6 6 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 5 5 5 4 3 3 5 5 5 6 6 6
41457 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41458 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41459 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41460 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41461 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41462 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41463 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41464 +4 0 0 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 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41471 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41472 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41473 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41474 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41475 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41476 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41477 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41483 +4 4 4 4 4 4
41484 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41485 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41486 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41487 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41488 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41489 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41490 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41491 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41497 +4 4 4 4 4 4
41498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41499 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41500 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41501 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41502 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41503 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41504 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41505 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41511 +4 4 4 4 4 4
41512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41513 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41514 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41515 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41516 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41517 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41518 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41519 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41525 +4 4 4 4 4 4
41526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41527 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41528 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41529 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41530 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41531 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41532 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41533 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41538 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41539 +4 4 4 4 4 4
41540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41542 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41543 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41544 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41545 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41546 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41547 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41552 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41553 +4 4 4 4 4 4
41554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41557 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41558 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41559 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41560 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41566 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41567 +4 4 4 4 4 4
41568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41571 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41572 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41573 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41574 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41581 +4 4 4 4 4 4
41582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41585 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41586 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41587 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41588 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41595 +4 4 4 4 4 4
41596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41599 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41600 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41601 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41602 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41609 +4 4 4 4 4 4
41610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41614 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41615 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41616 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41623 +4 4 4 4 4 4
41624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41628 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41629 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41630 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41637 +4 4 4 4 4 4
41638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41642 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41643 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41644 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41651 +4 4 4 4 4 4
41652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41656 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41657 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41665 +4 4 4 4 4 4
41666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41670 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41671 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41679 +4 4 4 4 4 4
41680 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41681 index 087fc99..f85ed76 100644
41682 --- a/drivers/video/udlfb.c
41683 +++ b/drivers/video/udlfb.c
41684 @@ -585,11 +585,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41685 dlfb_urb_completion(urb);
41686
41687 error:
41688 - atomic_add(bytes_sent, &dev->bytes_sent);
41689 - atomic_add(bytes_identical, &dev->bytes_identical);
41690 - atomic_add(width*height*2, &dev->bytes_rendered);
41691 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41692 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41693 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41694 end_cycles = get_cycles();
41695 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41696 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41697 >> 10)), /* Kcycles */
41698 &dev->cpu_kcycles_used);
41699
41700 @@ -710,11 +710,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41701 dlfb_urb_completion(urb);
41702
41703 error:
41704 - atomic_add(bytes_sent, &dev->bytes_sent);
41705 - atomic_add(bytes_identical, &dev->bytes_identical);
41706 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41707 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41708 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41709 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41710 end_cycles = get_cycles();
41711 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41712 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41713 >> 10)), /* Kcycles */
41714 &dev->cpu_kcycles_used);
41715 }
41716 @@ -1306,7 +1306,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41717 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41718 struct dlfb_data *dev = fb_info->par;
41719 return snprintf(buf, PAGE_SIZE, "%u\n",
41720 - atomic_read(&dev->bytes_rendered));
41721 + atomic_read_unchecked(&dev->bytes_rendered));
41722 }
41723
41724 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41725 @@ -1314,7 +1314,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41726 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41727 struct dlfb_data *dev = fb_info->par;
41728 return snprintf(buf, PAGE_SIZE, "%u\n",
41729 - atomic_read(&dev->bytes_identical));
41730 + atomic_read_unchecked(&dev->bytes_identical));
41731 }
41732
41733 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41734 @@ -1322,7 +1322,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41735 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41736 struct dlfb_data *dev = fb_info->par;
41737 return snprintf(buf, PAGE_SIZE, "%u\n",
41738 - atomic_read(&dev->bytes_sent));
41739 + atomic_read_unchecked(&dev->bytes_sent));
41740 }
41741
41742 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41743 @@ -1330,7 +1330,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41744 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41745 struct dlfb_data *dev = fb_info->par;
41746 return snprintf(buf, PAGE_SIZE, "%u\n",
41747 - atomic_read(&dev->cpu_kcycles_used));
41748 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41749 }
41750
41751 static ssize_t edid_show(
41752 @@ -1387,10 +1387,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41753 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41754 struct dlfb_data *dev = fb_info->par;
41755
41756 - atomic_set(&dev->bytes_rendered, 0);
41757 - atomic_set(&dev->bytes_identical, 0);
41758 - atomic_set(&dev->bytes_sent, 0);
41759 - atomic_set(&dev->cpu_kcycles_used, 0);
41760 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41761 + atomic_set_unchecked(&dev->bytes_identical, 0);
41762 + atomic_set_unchecked(&dev->bytes_sent, 0);
41763 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41764
41765 return count;
41766 }
41767 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41768 index 7f8472c..9842e87 100644
41769 --- a/drivers/video/uvesafb.c
41770 +++ b/drivers/video/uvesafb.c
41771 @@ -19,6 +19,7 @@
41772 #include <linux/io.h>
41773 #include <linux/mutex.h>
41774 #include <linux/slab.h>
41775 +#include <linux/moduleloader.h>
41776 #include <video/edid.h>
41777 #include <video/uvesafb.h>
41778 #ifdef CONFIG_X86
41779 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
41780 NULL,
41781 };
41782
41783 - return call_usermodehelper(v86d_path, argv, envp, 1);
41784 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
41785 }
41786
41787 /*
41788 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41789 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41790 par->pmi_setpal = par->ypan = 0;
41791 } else {
41792 +
41793 +#ifdef CONFIG_PAX_KERNEXEC
41794 +#ifdef CONFIG_MODULES
41795 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41796 +#endif
41797 + if (!par->pmi_code) {
41798 + par->pmi_setpal = par->ypan = 0;
41799 + return 0;
41800 + }
41801 +#endif
41802 +
41803 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41804 + task->t.regs.edi);
41805 +
41806 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41807 + pax_open_kernel();
41808 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41809 + pax_close_kernel();
41810 +
41811 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41812 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41813 +#else
41814 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41815 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41816 +#endif
41817 +
41818 printk(KERN_INFO "uvesafb: protected mode interface info at "
41819 "%04x:%04x\n",
41820 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41821 @@ -1821,6 +1844,11 @@ out:
41822 if (par->vbe_modes)
41823 kfree(par->vbe_modes);
41824
41825 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41826 + if (par->pmi_code)
41827 + module_free_exec(NULL, par->pmi_code);
41828 +#endif
41829 +
41830 framebuffer_release(info);
41831 return err;
41832 }
41833 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
41834 kfree(par->vbe_state_orig);
41835 if (par->vbe_state_saved)
41836 kfree(par->vbe_state_saved);
41837 +
41838 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41839 + if (par->pmi_code)
41840 + module_free_exec(NULL, par->pmi_code);
41841 +#endif
41842 +
41843 }
41844
41845 framebuffer_release(info);
41846 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41847 index 501b340..86bd4cf 100644
41848 --- a/drivers/video/vesafb.c
41849 +++ b/drivers/video/vesafb.c
41850 @@ -9,6 +9,7 @@
41851 */
41852
41853 #include <linux/module.h>
41854 +#include <linux/moduleloader.h>
41855 #include <linux/kernel.h>
41856 #include <linux/errno.h>
41857 #include <linux/string.h>
41858 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41859 static int vram_total __initdata; /* Set total amount of memory */
41860 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41861 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41862 -static void (*pmi_start)(void) __read_mostly;
41863 -static void (*pmi_pal) (void) __read_mostly;
41864 +static void (*pmi_start)(void) __read_only;
41865 +static void (*pmi_pal) (void) __read_only;
41866 static int depth __read_mostly;
41867 static int vga_compat __read_mostly;
41868 /* --------------------------------------------------------------------- */
41869 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41870 unsigned int size_vmode;
41871 unsigned int size_remap;
41872 unsigned int size_total;
41873 + void *pmi_code = NULL;
41874
41875 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41876 return -ENODEV;
41877 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41878 size_remap = size_total;
41879 vesafb_fix.smem_len = size_remap;
41880
41881 -#ifndef __i386__
41882 - screen_info.vesapm_seg = 0;
41883 -#endif
41884 -
41885 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41886 printk(KERN_WARNING
41887 "vesafb: cannot reserve video memory at 0x%lx\n",
41888 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41889 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41890 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41891
41892 +#ifdef __i386__
41893 +
41894 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41895 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
41896 + if (!pmi_code)
41897 +#elif !defined(CONFIG_PAX_KERNEXEC)
41898 + if (0)
41899 +#endif
41900 +
41901 +#endif
41902 + screen_info.vesapm_seg = 0;
41903 +
41904 if (screen_info.vesapm_seg) {
41905 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41906 - screen_info.vesapm_seg,screen_info.vesapm_off);
41907 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41908 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41909 }
41910
41911 if (screen_info.vesapm_seg < 0xc000)
41912 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41913
41914 if (ypan || pmi_setpal) {
41915 unsigned short *pmi_base;
41916 +
41917 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41918 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41919 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41920 +
41921 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41922 + pax_open_kernel();
41923 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41924 +#else
41925 + pmi_code = pmi_base;
41926 +#endif
41927 +
41928 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41929 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41930 +
41931 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41932 + pmi_start = ktva_ktla(pmi_start);
41933 + pmi_pal = ktva_ktla(pmi_pal);
41934 + pax_close_kernel();
41935 +#endif
41936 +
41937 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41938 if (pmi_base[3]) {
41939 printk(KERN_INFO "vesafb: pmi: ports = ");
41940 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41941 info->node, info->fix.id);
41942 return 0;
41943 err:
41944 +
41945 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41946 + module_free_exec(NULL, pmi_code);
41947 +#endif
41948 +
41949 if (info->screen_base)
41950 iounmap(info->screen_base);
41951 framebuffer_release(info);
41952 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41953 index 88714ae..16c2e11 100644
41954 --- a/drivers/video/via/via_clock.h
41955 +++ b/drivers/video/via/via_clock.h
41956 @@ -56,7 +56,7 @@ struct via_clock {
41957
41958 void (*set_engine_pll_state)(u8 state);
41959 void (*set_engine_pll)(struct via_pll_config config);
41960 -};
41961 +} __no_const;
41962
41963
41964 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41965 diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
41966 index e058ace..2424d93 100644
41967 --- a/drivers/virtio/virtio_balloon.c
41968 +++ b/drivers/virtio/virtio_balloon.c
41969 @@ -174,6 +174,8 @@ static void update_balloon_stats(struct virtio_balloon *vb)
41970 struct sysinfo i;
41971 int idx = 0;
41972
41973 + pax_track_stack();
41974 +
41975 all_vm_events(events);
41976 si_meminfo(&i);
41977
41978 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41979 index e56c934..fc22f4b 100644
41980 --- a/drivers/xen/xen-pciback/conf_space.h
41981 +++ b/drivers/xen/xen-pciback/conf_space.h
41982 @@ -44,15 +44,15 @@ struct config_field {
41983 struct {
41984 conf_dword_write write;
41985 conf_dword_read read;
41986 - } dw;
41987 + } __no_const dw;
41988 struct {
41989 conf_word_write write;
41990 conf_word_read read;
41991 - } w;
41992 + } __no_const w;
41993 struct {
41994 conf_byte_write write;
41995 conf_byte_read read;
41996 - } b;
41997 + } __no_const b;
41998 } u;
41999 struct list_head list;
42000 };
42001 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42002 index e3c03db..93b0172 100644
42003 --- a/fs/9p/vfs_inode.c
42004 +++ b/fs/9p/vfs_inode.c
42005 @@ -1288,7 +1288,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42006 void
42007 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42008 {
42009 - char *s = nd_get_link(nd);
42010 + const char *s = nd_get_link(nd);
42011
42012 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
42013 IS_ERR(s) ? "<error>" : s);
42014 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42015 index 79e2ca7..5828ad1 100644
42016 --- a/fs/Kconfig.binfmt
42017 +++ b/fs/Kconfig.binfmt
42018 @@ -86,7 +86,7 @@ config HAVE_AOUT
42019
42020 config BINFMT_AOUT
42021 tristate "Kernel support for a.out and ECOFF binaries"
42022 - depends on HAVE_AOUT
42023 + depends on HAVE_AOUT && BROKEN
42024 ---help---
42025 A.out (Assembler.OUTput) is a set of formats for libraries and
42026 executables used in the earliest versions of UNIX. Linux used
42027 diff --git a/fs/aio.c b/fs/aio.c
42028 index e29ec48..f083e5e 100644
42029 --- a/fs/aio.c
42030 +++ b/fs/aio.c
42031 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42032 size += sizeof(struct io_event) * nr_events;
42033 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42034
42035 - if (nr_pages < 0)
42036 + if (nr_pages <= 0)
42037 return -EINVAL;
42038
42039 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42040 @@ -1088,6 +1088,8 @@ static int read_events(struct kioctx *ctx,
42041 struct aio_timeout to;
42042 int retry = 0;
42043
42044 + pax_track_stack();
42045 +
42046 /* needed to zero any padding within an entry (there shouldn't be
42047 * any, but C is fun!
42048 */
42049 @@ -1381,22 +1383,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42050 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42051 {
42052 ssize_t ret;
42053 + struct iovec iovstack;
42054
42055 #ifdef CONFIG_COMPAT
42056 if (compat)
42057 ret = compat_rw_copy_check_uvector(type,
42058 (struct compat_iovec __user *)kiocb->ki_buf,
42059 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42060 + kiocb->ki_nbytes, 1, &iovstack,
42061 &kiocb->ki_iovec);
42062 else
42063 #endif
42064 ret = rw_copy_check_uvector(type,
42065 (struct iovec __user *)kiocb->ki_buf,
42066 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42067 + kiocb->ki_nbytes, 1, &iovstack,
42068 &kiocb->ki_iovec);
42069 if (ret < 0)
42070 goto out;
42071
42072 + if (kiocb->ki_iovec == &iovstack) {
42073 + kiocb->ki_inline_vec = iovstack;
42074 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42075 + }
42076 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42077 kiocb->ki_cur_seg = 0;
42078 /* ki_nbytes/left now reflect bytes instead of segs */
42079 diff --git a/fs/attr.c b/fs/attr.c
42080 index 538e279..046cc6d 100644
42081 --- a/fs/attr.c
42082 +++ b/fs/attr.c
42083 @@ -98,6 +98,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42084 unsigned long limit;
42085
42086 limit = rlimit(RLIMIT_FSIZE);
42087 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42088 if (limit != RLIM_INFINITY && offset > limit)
42089 goto out_sig;
42090 if (offset > inode->i_sb->s_maxbytes)
42091 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42092 index e1fbdee..cd5ea56 100644
42093 --- a/fs/autofs4/waitq.c
42094 +++ b/fs/autofs4/waitq.c
42095 @@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
42096 {
42097 unsigned long sigpipe, flags;
42098 mm_segment_t fs;
42099 - const char *data = (const char *)addr;
42100 + const char __user *data = (const char __force_user *)addr;
42101 ssize_t wr = 0;
42102
42103 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
42104 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42105 index 720d885..012e7f0 100644
42106 --- a/fs/befs/linuxvfs.c
42107 +++ b/fs/befs/linuxvfs.c
42108 @@ -503,7 +503,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42109 {
42110 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42111 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42112 - char *link = nd_get_link(nd);
42113 + const char *link = nd_get_link(nd);
42114 if (!IS_ERR(link))
42115 kfree(link);
42116 }
42117 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42118 index a6395bd..a5b24c4 100644
42119 --- a/fs/binfmt_aout.c
42120 +++ b/fs/binfmt_aout.c
42121 @@ -16,6 +16,7 @@
42122 #include <linux/string.h>
42123 #include <linux/fs.h>
42124 #include <linux/file.h>
42125 +#include <linux/security.h>
42126 #include <linux/stat.h>
42127 #include <linux/fcntl.h>
42128 #include <linux/ptrace.h>
42129 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42130 #endif
42131 # define START_STACK(u) ((void __user *)u.start_stack)
42132
42133 + memset(&dump, 0, sizeof(dump));
42134 +
42135 fs = get_fs();
42136 set_fs(KERNEL_DS);
42137 has_dumped = 1;
42138 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42139
42140 /* If the size of the dump file exceeds the rlimit, then see what would happen
42141 if we wrote the stack, but not the data area. */
42142 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42143 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42144 dump.u_dsize = 0;
42145
42146 /* Make sure we have enough room to write the stack and data areas. */
42147 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42148 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42149 dump.u_ssize = 0;
42150
42151 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42152 rlim = rlimit(RLIMIT_DATA);
42153 if (rlim >= RLIM_INFINITY)
42154 rlim = ~0;
42155 +
42156 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42157 if (ex.a_data + ex.a_bss > rlim)
42158 return -ENOMEM;
42159
42160 @@ -262,6 +269,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42161 install_exec_creds(bprm);
42162 current->flags &= ~PF_FORKNOEXEC;
42163
42164 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42165 + current->mm->pax_flags = 0UL;
42166 +#endif
42167 +
42168 +#ifdef CONFIG_PAX_PAGEEXEC
42169 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42170 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42171 +
42172 +#ifdef CONFIG_PAX_EMUTRAMP
42173 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42174 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42175 +#endif
42176 +
42177 +#ifdef CONFIG_PAX_MPROTECT
42178 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42179 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42180 +#endif
42181 +
42182 + }
42183 +#endif
42184 +
42185 if (N_MAGIC(ex) == OMAGIC) {
42186 unsigned long text_addr, map_size;
42187 loff_t pos;
42188 @@ -334,7 +362,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42189
42190 down_write(&current->mm->mmap_sem);
42191 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42192 - PROT_READ | PROT_WRITE | PROT_EXEC,
42193 + PROT_READ | PROT_WRITE,
42194 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42195 fd_offset + ex.a_text);
42196 up_write(&current->mm->mmap_sem);
42197 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42198 index 21ac5ee..f54fdd0 100644
42199 --- a/fs/binfmt_elf.c
42200 +++ b/fs/binfmt_elf.c
42201 @@ -32,6 +32,7 @@
42202 #include <linux/elf.h>
42203 #include <linux/utsname.h>
42204 #include <linux/coredump.h>
42205 +#include <linux/xattr.h>
42206 #include <asm/uaccess.h>
42207 #include <asm/param.h>
42208 #include <asm/page.h>
42209 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42210 #define elf_core_dump NULL
42211 #endif
42212
42213 +#ifdef CONFIG_PAX_MPROTECT
42214 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42215 +#endif
42216 +
42217 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42218 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42219 #else
42220 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
42221 .load_binary = load_elf_binary,
42222 .load_shlib = load_elf_library,
42223 .core_dump = elf_core_dump,
42224 +
42225 +#ifdef CONFIG_PAX_MPROTECT
42226 + .handle_mprotect= elf_handle_mprotect,
42227 +#endif
42228 +
42229 .min_coredump = ELF_EXEC_PAGESIZE,
42230 };
42231
42232 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
42233
42234 static int set_brk(unsigned long start, unsigned long end)
42235 {
42236 + unsigned long e = end;
42237 +
42238 start = ELF_PAGEALIGN(start);
42239 end = ELF_PAGEALIGN(end);
42240 if (end > start) {
42241 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
42242 if (BAD_ADDR(addr))
42243 return addr;
42244 }
42245 - current->mm->start_brk = current->mm->brk = end;
42246 + current->mm->start_brk = current->mm->brk = e;
42247 return 0;
42248 }
42249
42250 @@ -148,12 +160,15 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42251 elf_addr_t __user *u_rand_bytes;
42252 const char *k_platform = ELF_PLATFORM;
42253 const char *k_base_platform = ELF_BASE_PLATFORM;
42254 - unsigned char k_rand_bytes[16];
42255 + u32 k_rand_bytes[4];
42256 int items;
42257 elf_addr_t *elf_info;
42258 int ei_index = 0;
42259 const struct cred *cred = current_cred();
42260 struct vm_area_struct *vma;
42261 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42262 +
42263 + pax_track_stack();
42264
42265 /*
42266 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42267 @@ -195,8 +210,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42268 * Generate 16 random bytes for userspace PRNG seeding.
42269 */
42270 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42271 - u_rand_bytes = (elf_addr_t __user *)
42272 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42273 + srandom32(k_rand_bytes[0] ^ random32());
42274 + srandom32(k_rand_bytes[1] ^ random32());
42275 + srandom32(k_rand_bytes[2] ^ random32());
42276 + srandom32(k_rand_bytes[3] ^ random32());
42277 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42278 + u_rand_bytes = (elf_addr_t __user *) p;
42279 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42280 return -EFAULT;
42281
42282 @@ -308,9 +327,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42283 return -EFAULT;
42284 current->mm->env_end = p;
42285
42286 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42287 +
42288 /* Put the elf_info on the stack in the right place. */
42289 sp = (elf_addr_t __user *)envp + 1;
42290 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42291 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42292 return -EFAULT;
42293 return 0;
42294 }
42295 @@ -381,10 +402,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42296 {
42297 struct elf_phdr *elf_phdata;
42298 struct elf_phdr *eppnt;
42299 - unsigned long load_addr = 0;
42300 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42301 int load_addr_set = 0;
42302 unsigned long last_bss = 0, elf_bss = 0;
42303 - unsigned long error = ~0UL;
42304 + unsigned long error = -EINVAL;
42305 unsigned long total_size;
42306 int retval, i, size;
42307
42308 @@ -430,6 +451,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42309 goto out_close;
42310 }
42311
42312 +#ifdef CONFIG_PAX_SEGMEXEC
42313 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42314 + pax_task_size = SEGMEXEC_TASK_SIZE;
42315 +#endif
42316 +
42317 eppnt = elf_phdata;
42318 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42319 if (eppnt->p_type == PT_LOAD) {
42320 @@ -473,8 +499,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42321 k = load_addr + eppnt->p_vaddr;
42322 if (BAD_ADDR(k) ||
42323 eppnt->p_filesz > eppnt->p_memsz ||
42324 - eppnt->p_memsz > TASK_SIZE ||
42325 - TASK_SIZE - eppnt->p_memsz < k) {
42326 + eppnt->p_memsz > pax_task_size ||
42327 + pax_task_size - eppnt->p_memsz < k) {
42328 error = -ENOMEM;
42329 goto out_close;
42330 }
42331 @@ -528,6 +554,348 @@ out:
42332 return error;
42333 }
42334
42335 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42336 +{
42337 + unsigned long pax_flags = 0UL;
42338 +
42339 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42340 +
42341 +#ifdef CONFIG_PAX_PAGEEXEC
42342 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42343 + pax_flags |= MF_PAX_PAGEEXEC;
42344 +#endif
42345 +
42346 +#ifdef CONFIG_PAX_SEGMEXEC
42347 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42348 + pax_flags |= MF_PAX_SEGMEXEC;
42349 +#endif
42350 +
42351 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42352 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42353 + if ((__supported_pte_mask & _PAGE_NX))
42354 + pax_flags &= ~MF_PAX_SEGMEXEC;
42355 + else
42356 + pax_flags &= ~MF_PAX_PAGEEXEC;
42357 + }
42358 +#endif
42359 +
42360 +#ifdef CONFIG_PAX_EMUTRAMP
42361 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42362 + pax_flags |= MF_PAX_EMUTRAMP;
42363 +#endif
42364 +
42365 +#ifdef CONFIG_PAX_MPROTECT
42366 + if (elf_phdata->p_flags & PF_MPROTECT)
42367 + pax_flags |= MF_PAX_MPROTECT;
42368 +#endif
42369 +
42370 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42371 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42372 + pax_flags |= MF_PAX_RANDMMAP;
42373 +#endif
42374 +
42375 +#endif
42376 +
42377 + return pax_flags;
42378 +}
42379 +
42380 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42381 +{
42382 + unsigned long pax_flags = 0UL;
42383 +
42384 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42385 +
42386 +#ifdef CONFIG_PAX_PAGEEXEC
42387 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42388 + pax_flags |= MF_PAX_PAGEEXEC;
42389 +#endif
42390 +
42391 +#ifdef CONFIG_PAX_SEGMEXEC
42392 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42393 + pax_flags |= MF_PAX_SEGMEXEC;
42394 +#endif
42395 +
42396 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42397 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42398 + if ((__supported_pte_mask & _PAGE_NX))
42399 + pax_flags &= ~MF_PAX_SEGMEXEC;
42400 + else
42401 + pax_flags &= ~MF_PAX_PAGEEXEC;
42402 + }
42403 +#endif
42404 +
42405 +#ifdef CONFIG_PAX_EMUTRAMP
42406 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42407 + pax_flags |= MF_PAX_EMUTRAMP;
42408 +#endif
42409 +
42410 +#ifdef CONFIG_PAX_MPROTECT
42411 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42412 + pax_flags |= MF_PAX_MPROTECT;
42413 +#endif
42414 +
42415 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42416 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42417 + pax_flags |= MF_PAX_RANDMMAP;
42418 +#endif
42419 +
42420 +#endif
42421 +
42422 + return pax_flags;
42423 +}
42424 +
42425 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42426 +{
42427 + unsigned long pax_flags = 0UL;
42428 +
42429 +#ifdef CONFIG_PAX_EI_PAX
42430 +
42431 +#ifdef CONFIG_PAX_PAGEEXEC
42432 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42433 + pax_flags |= MF_PAX_PAGEEXEC;
42434 +#endif
42435 +
42436 +#ifdef CONFIG_PAX_SEGMEXEC
42437 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42438 + pax_flags |= MF_PAX_SEGMEXEC;
42439 +#endif
42440 +
42441 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42442 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42443 + if ((__supported_pte_mask & _PAGE_NX))
42444 + pax_flags &= ~MF_PAX_SEGMEXEC;
42445 + else
42446 + pax_flags &= ~MF_PAX_PAGEEXEC;
42447 + }
42448 +#endif
42449 +
42450 +#ifdef CONFIG_PAX_EMUTRAMP
42451 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42452 + pax_flags |= MF_PAX_EMUTRAMP;
42453 +#endif
42454 +
42455 +#ifdef CONFIG_PAX_MPROTECT
42456 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42457 + pax_flags |= MF_PAX_MPROTECT;
42458 +#endif
42459 +
42460 +#ifdef CONFIG_PAX_ASLR
42461 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42462 + pax_flags |= MF_PAX_RANDMMAP;
42463 +#endif
42464 +
42465 +#else
42466 +
42467 +#ifdef CONFIG_PAX_PAGEEXEC
42468 + pax_flags |= MF_PAX_PAGEEXEC;
42469 +#endif
42470 +
42471 +#ifdef CONFIG_PAX_MPROTECT
42472 + pax_flags |= MF_PAX_MPROTECT;
42473 +#endif
42474 +
42475 +#ifdef CONFIG_PAX_RANDMMAP
42476 + pax_flags |= MF_PAX_RANDMMAP;
42477 +#endif
42478 +
42479 +#ifdef CONFIG_PAX_SEGMEXEC
42480 + if (!(__supported_pte_mask & _PAGE_NX)) {
42481 + pax_flags &= ~MF_PAX_PAGEEXEC;
42482 + pax_flags |= MF_PAX_SEGMEXEC;
42483 + }
42484 +#endif
42485 +
42486 +#endif
42487 +
42488 + return pax_flags;
42489 +}
42490 +
42491 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42492 +{
42493 +
42494 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42495 + unsigned long i;
42496 +
42497 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42498 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42499 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42500 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42501 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42502 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42503 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42504 + return ~0UL;
42505 +
42506 +#ifdef CONFIG_PAX_SOFTMODE
42507 + if (pax_softmode)
42508 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42509 + else
42510 +#endif
42511 +
42512 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42513 + break;
42514 + }
42515 +#endif
42516 +
42517 + return ~0UL;
42518 +}
42519 +
42520 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42521 +{
42522 + unsigned long pax_flags = 0UL;
42523 +
42524 +#ifdef CONFIG_PAX_PAGEEXEC
42525 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42526 + pax_flags |= MF_PAX_PAGEEXEC;
42527 +#endif
42528 +
42529 +#ifdef CONFIG_PAX_SEGMEXEC
42530 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42531 + pax_flags |= MF_PAX_SEGMEXEC;
42532 +#endif
42533 +
42534 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42535 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42536 + if ((__supported_pte_mask & _PAGE_NX))
42537 + pax_flags &= ~MF_PAX_SEGMEXEC;
42538 + else
42539 + pax_flags &= ~MF_PAX_PAGEEXEC;
42540 + }
42541 +#endif
42542 +
42543 +#ifdef CONFIG_PAX_EMUTRAMP
42544 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42545 + pax_flags |= MF_PAX_EMUTRAMP;
42546 +#endif
42547 +
42548 +#ifdef CONFIG_PAX_MPROTECT
42549 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42550 + pax_flags |= MF_PAX_MPROTECT;
42551 +#endif
42552 +
42553 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42554 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42555 + pax_flags |= MF_PAX_RANDMMAP;
42556 +#endif
42557 +
42558 + return pax_flags;
42559 +}
42560 +
42561 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42562 +{
42563 + unsigned long pax_flags = 0UL;
42564 +
42565 +#ifdef CONFIG_PAX_PAGEEXEC
42566 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42567 + pax_flags |= MF_PAX_PAGEEXEC;
42568 +#endif
42569 +
42570 +#ifdef CONFIG_PAX_SEGMEXEC
42571 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42572 + pax_flags |= MF_PAX_SEGMEXEC;
42573 +#endif
42574 +
42575 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42576 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42577 + if ((__supported_pte_mask & _PAGE_NX))
42578 + pax_flags &= ~MF_PAX_SEGMEXEC;
42579 + else
42580 + pax_flags &= ~MF_PAX_PAGEEXEC;
42581 + }
42582 +#endif
42583 +
42584 +#ifdef CONFIG_PAX_EMUTRAMP
42585 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42586 + pax_flags |= MF_PAX_EMUTRAMP;
42587 +#endif
42588 +
42589 +#ifdef CONFIG_PAX_MPROTECT
42590 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42591 + pax_flags |= MF_PAX_MPROTECT;
42592 +#endif
42593 +
42594 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42595 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42596 + pax_flags |= MF_PAX_RANDMMAP;
42597 +#endif
42598 +
42599 + return pax_flags;
42600 +}
42601 +
42602 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42603 +{
42604 +
42605 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42606 + ssize_t xattr_size, i;
42607 + unsigned char xattr_value[5];
42608 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42609 +
42610 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42611 + if (xattr_size <= 0)
42612 + return ~0UL;
42613 +
42614 + for (i = 0; i < xattr_size; i++)
42615 + switch (xattr_value[i]) {
42616 + default:
42617 + return ~0UL;
42618 +
42619 +#define parse_flag(option1, option2, flag) \
42620 + case option1: \
42621 + pax_flags_hardmode |= MF_PAX_##flag; \
42622 + break; \
42623 + case option2: \
42624 + pax_flags_softmode |= MF_PAX_##flag; \
42625 + break;
42626 +
42627 + parse_flag('p', 'P', PAGEEXEC);
42628 + parse_flag('e', 'E', EMUTRAMP);
42629 + parse_flag('m', 'M', MPROTECT);
42630 + parse_flag('r', 'R', RANDMMAP);
42631 + parse_flag('s', 'S', SEGMEXEC);
42632 +
42633 +#undef parse_flag
42634 + }
42635 +
42636 + if (pax_flags_hardmode & pax_flags_softmode)
42637 + return ~0UL;
42638 +
42639 +#ifdef CONFIG_PAX_SOFTMODE
42640 + if (pax_softmode)
42641 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42642 + else
42643 +#endif
42644 +
42645 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42646 +#else
42647 + return ~0UL;
42648 +#endif
42649 +}
42650 +
42651 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42652 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42653 +{
42654 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42655 +
42656 + pax_flags = pax_parse_ei_pax(elf_ex);
42657 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42658 + xattr_pax_flags = pax_parse_xattr_pax(file);
42659 +
42660 + if (pt_pax_flags == ~0UL)
42661 + pt_pax_flags = xattr_pax_flags;
42662 + else if (xattr_pax_flags == ~0UL)
42663 + xattr_pax_flags = pt_pax_flags;
42664 + if (pt_pax_flags != xattr_pax_flags)
42665 + return -EINVAL;
42666 + if (pt_pax_flags != ~0UL)
42667 + pax_flags = pt_pax_flags;
42668 +
42669 + if (0 > pax_check_flags(&pax_flags))
42670 + return -EINVAL;
42671 +
42672 + current->mm->pax_flags = pax_flags;
42673 + return 0;
42674 +}
42675 +#endif
42676 +
42677 /*
42678 * These are the functions used to load ELF style executables and shared
42679 * libraries. There is no binary dependent code anywhere else.
42680 @@ -544,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42681 {
42682 unsigned int random_variable = 0;
42683
42684 +#ifdef CONFIG_PAX_RANDUSTACK
42685 + if (randomize_va_space)
42686 + return stack_top - current->mm->delta_stack;
42687 +#endif
42688 +
42689 if ((current->flags & PF_RANDOMIZE) &&
42690 !(current->personality & ADDR_NO_RANDOMIZE)) {
42691 random_variable = get_random_int() & STACK_RND_MASK;
42692 @@ -562,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42693 unsigned long load_addr = 0, load_bias = 0;
42694 int load_addr_set = 0;
42695 char * elf_interpreter = NULL;
42696 - unsigned long error;
42697 + unsigned long error = 0;
42698 struct elf_phdr *elf_ppnt, *elf_phdata;
42699 unsigned long elf_bss, elf_brk;
42700 int retval, i;
42701 @@ -572,11 +945,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42702 unsigned long start_code, end_code, start_data, end_data;
42703 unsigned long reloc_func_desc __maybe_unused = 0;
42704 int executable_stack = EXSTACK_DEFAULT;
42705 - unsigned long def_flags = 0;
42706 struct {
42707 struct elfhdr elf_ex;
42708 struct elfhdr interp_elf_ex;
42709 } *loc;
42710 + unsigned long pax_task_size = TASK_SIZE;
42711
42712 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42713 if (!loc) {
42714 @@ -713,11 +1086,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42715
42716 /* OK, This is the point of no return */
42717 current->flags &= ~PF_FORKNOEXEC;
42718 - current->mm->def_flags = def_flags;
42719 +
42720 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42721 + current->mm->pax_flags = 0UL;
42722 +#endif
42723 +
42724 +#ifdef CONFIG_PAX_DLRESOLVE
42725 + current->mm->call_dl_resolve = 0UL;
42726 +#endif
42727 +
42728 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42729 + current->mm->call_syscall = 0UL;
42730 +#endif
42731 +
42732 +#ifdef CONFIG_PAX_ASLR
42733 + current->mm->delta_mmap = 0UL;
42734 + current->mm->delta_stack = 0UL;
42735 +#endif
42736 +
42737 + current->mm->def_flags = 0;
42738 +
42739 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42740 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42741 + send_sig(SIGKILL, current, 0);
42742 + goto out_free_dentry;
42743 + }
42744 +#endif
42745 +
42746 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42747 + pax_set_initial_flags(bprm);
42748 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42749 + if (pax_set_initial_flags_func)
42750 + (pax_set_initial_flags_func)(bprm);
42751 +#endif
42752 +
42753 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42754 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42755 + current->mm->context.user_cs_limit = PAGE_SIZE;
42756 + current->mm->def_flags |= VM_PAGEEXEC;
42757 + }
42758 +#endif
42759 +
42760 +#ifdef CONFIG_PAX_SEGMEXEC
42761 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42762 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42763 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42764 + pax_task_size = SEGMEXEC_TASK_SIZE;
42765 + current->mm->def_flags |= VM_NOHUGEPAGE;
42766 + }
42767 +#endif
42768 +
42769 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42770 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42771 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42772 + put_cpu();
42773 + }
42774 +#endif
42775
42776 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42777 may depend on the personality. */
42778 SET_PERSONALITY(loc->elf_ex);
42779 +
42780 +#ifdef CONFIG_PAX_ASLR
42781 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42782 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42783 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42784 + }
42785 +#endif
42786 +
42787 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42788 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42789 + executable_stack = EXSTACK_DISABLE_X;
42790 + current->personality &= ~READ_IMPLIES_EXEC;
42791 + } else
42792 +#endif
42793 +
42794 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42795 current->personality |= READ_IMPLIES_EXEC;
42796
42797 @@ -808,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42798 #else
42799 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42800 #endif
42801 +
42802 +#ifdef CONFIG_PAX_RANDMMAP
42803 + /* PaX: randomize base address at the default exe base if requested */
42804 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42805 +#ifdef CONFIG_SPARC64
42806 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42807 +#else
42808 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42809 +#endif
42810 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42811 + elf_flags |= MAP_FIXED;
42812 + }
42813 +#endif
42814 +
42815 }
42816
42817 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42818 @@ -840,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42819 * allowed task size. Note that p_filesz must always be
42820 * <= p_memsz so it is only necessary to check p_memsz.
42821 */
42822 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42823 - elf_ppnt->p_memsz > TASK_SIZE ||
42824 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42825 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42826 + elf_ppnt->p_memsz > pax_task_size ||
42827 + pax_task_size - elf_ppnt->p_memsz < k) {
42828 /* set_brk can never work. Avoid overflows. */
42829 send_sig(SIGKILL, current, 0);
42830 retval = -EINVAL;
42831 @@ -870,6 +1327,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42832 start_data += load_bias;
42833 end_data += load_bias;
42834
42835 +#ifdef CONFIG_PAX_RANDMMAP
42836 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
42837 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
42838 +#endif
42839 +
42840 /* Calling set_brk effectively mmaps the pages that we need
42841 * for the bss and break sections. We must do this before
42842 * mapping in the interpreter, to make sure it doesn't wind
42843 @@ -881,9 +1343,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42844 goto out_free_dentry;
42845 }
42846 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42847 - send_sig(SIGSEGV, current, 0);
42848 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42849 - goto out_free_dentry;
42850 + /*
42851 + * This bss-zeroing can fail if the ELF
42852 + * file specifies odd protections. So
42853 + * we don't check the return value
42854 + */
42855 }
42856
42857 if (elf_interpreter) {
42858 @@ -1098,7 +1562,7 @@ out:
42859 * Decide what to dump of a segment, part, all or none.
42860 */
42861 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42862 - unsigned long mm_flags)
42863 + unsigned long mm_flags, long signr)
42864 {
42865 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42866
42867 @@ -1132,7 +1596,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42868 if (vma->vm_file == NULL)
42869 return 0;
42870
42871 - if (FILTER(MAPPED_PRIVATE))
42872 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42873 goto whole;
42874
42875 /*
42876 @@ -1354,9 +1818,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42877 {
42878 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42879 int i = 0;
42880 - do
42881 + do {
42882 i += 2;
42883 - while (auxv[i - 2] != AT_NULL);
42884 + } while (auxv[i - 2] != AT_NULL);
42885 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42886 }
42887
42888 @@ -1862,14 +2326,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42889 }
42890
42891 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42892 - unsigned long mm_flags)
42893 + struct coredump_params *cprm)
42894 {
42895 struct vm_area_struct *vma;
42896 size_t size = 0;
42897
42898 for (vma = first_vma(current, gate_vma); vma != NULL;
42899 vma = next_vma(vma, gate_vma))
42900 - size += vma_dump_size(vma, mm_flags);
42901 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42902 return size;
42903 }
42904
42905 @@ -1963,7 +2427,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42906
42907 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42908
42909 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42910 + offset += elf_core_vma_data_size(gate_vma, cprm);
42911 offset += elf_core_extra_data_size();
42912 e_shoff = offset;
42913
42914 @@ -1977,10 +2441,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42915 offset = dataoff;
42916
42917 size += sizeof(*elf);
42918 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42919 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42920 goto end_coredump;
42921
42922 size += sizeof(*phdr4note);
42923 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42924 if (size > cprm->limit
42925 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42926 goto end_coredump;
42927 @@ -1994,7 +2460,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42928 phdr.p_offset = offset;
42929 phdr.p_vaddr = vma->vm_start;
42930 phdr.p_paddr = 0;
42931 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42932 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42933 phdr.p_memsz = vma->vm_end - vma->vm_start;
42934 offset += phdr.p_filesz;
42935 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42936 @@ -2005,6 +2471,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42937 phdr.p_align = ELF_EXEC_PAGESIZE;
42938
42939 size += sizeof(phdr);
42940 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42941 if (size > cprm->limit
42942 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42943 goto end_coredump;
42944 @@ -2029,7 +2496,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42945 unsigned long addr;
42946 unsigned long end;
42947
42948 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42949 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42950
42951 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42952 struct page *page;
42953 @@ -2038,6 +2505,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42954 page = get_dump_page(addr);
42955 if (page) {
42956 void *kaddr = kmap(page);
42957 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42958 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42959 !dump_write(cprm->file, kaddr,
42960 PAGE_SIZE);
42961 @@ -2055,6 +2523,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42962
42963 if (e_phnum == PN_XNUM) {
42964 size += sizeof(*shdr4extnum);
42965 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42966 if (size > cprm->limit
42967 || !dump_write(cprm->file, shdr4extnum,
42968 sizeof(*shdr4extnum)))
42969 @@ -2075,6 +2544,97 @@ out:
42970
42971 #endif /* CONFIG_ELF_CORE */
42972
42973 +#ifdef CONFIG_PAX_MPROTECT
42974 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
42975 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42976 + * we'll remove VM_MAYWRITE for good on RELRO segments.
42977 + *
42978 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42979 + * basis because we want to allow the common case and not the special ones.
42980 + */
42981 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42982 +{
42983 + struct elfhdr elf_h;
42984 + struct elf_phdr elf_p;
42985 + unsigned long i;
42986 + unsigned long oldflags;
42987 + bool is_textrel_rw, is_textrel_rx, is_relro;
42988 +
42989 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42990 + return;
42991 +
42992 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42993 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42994 +
42995 +#ifdef CONFIG_PAX_ELFRELOCS
42996 + /* possible TEXTREL */
42997 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42998 + 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);
42999 +#else
43000 + is_textrel_rw = false;
43001 + is_textrel_rx = false;
43002 +#endif
43003 +
43004 + /* possible RELRO */
43005 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43006 +
43007 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43008 + return;
43009 +
43010 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43011 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43012 +
43013 +#ifdef CONFIG_PAX_ETEXECRELOCS
43014 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43015 +#else
43016 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43017 +#endif
43018 +
43019 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43020 + !elf_check_arch(&elf_h) ||
43021 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43022 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43023 + return;
43024 +
43025 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43026 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43027 + return;
43028 + switch (elf_p.p_type) {
43029 + case PT_DYNAMIC:
43030 + if (!is_textrel_rw && !is_textrel_rx)
43031 + continue;
43032 + i = 0UL;
43033 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43034 + elf_dyn dyn;
43035 +
43036 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43037 + return;
43038 + if (dyn.d_tag == DT_NULL)
43039 + return;
43040 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43041 + gr_log_textrel(vma);
43042 + if (is_textrel_rw)
43043 + vma->vm_flags |= VM_MAYWRITE;
43044 + else
43045 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43046 + vma->vm_flags &= ~VM_MAYWRITE;
43047 + return;
43048 + }
43049 + i++;
43050 + }
43051 + return;
43052 +
43053 + case PT_GNU_RELRO:
43054 + if (!is_relro)
43055 + continue;
43056 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43057 + vma->vm_flags &= ~VM_MAYWRITE;
43058 + return;
43059 + }
43060 + }
43061 +}
43062 +#endif
43063 +
43064 static int __init init_elf_binfmt(void)
43065 {
43066 return register_binfmt(&elf_format);
43067 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43068 index 1bffbe0..c8c283e 100644
43069 --- a/fs/binfmt_flat.c
43070 +++ b/fs/binfmt_flat.c
43071 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43072 realdatastart = (unsigned long) -ENOMEM;
43073 printk("Unable to allocate RAM for process data, errno %d\n",
43074 (int)-realdatastart);
43075 + down_write(&current->mm->mmap_sem);
43076 do_munmap(current->mm, textpos, text_len);
43077 + up_write(&current->mm->mmap_sem);
43078 ret = realdatastart;
43079 goto err;
43080 }
43081 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43082 }
43083 if (IS_ERR_VALUE(result)) {
43084 printk("Unable to read data+bss, errno %d\n", (int)-result);
43085 + down_write(&current->mm->mmap_sem);
43086 do_munmap(current->mm, textpos, text_len);
43087 do_munmap(current->mm, realdatastart, len);
43088 + up_write(&current->mm->mmap_sem);
43089 ret = result;
43090 goto err;
43091 }
43092 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43093 }
43094 if (IS_ERR_VALUE(result)) {
43095 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43096 + down_write(&current->mm->mmap_sem);
43097 do_munmap(current->mm, textpos, text_len + data_len + extra +
43098 MAX_SHARED_LIBS * sizeof(unsigned long));
43099 + up_write(&current->mm->mmap_sem);
43100 ret = result;
43101 goto err;
43102 }
43103 diff --git a/fs/bio.c b/fs/bio.c
43104 index 9bfade8..782f3b9 100644
43105 --- a/fs/bio.c
43106 +++ b/fs/bio.c
43107 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43108 const int read = bio_data_dir(bio) == READ;
43109 struct bio_map_data *bmd = bio->bi_private;
43110 int i;
43111 - char *p = bmd->sgvecs[0].iov_base;
43112 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43113
43114 __bio_for_each_segment(bvec, bio, i, 0) {
43115 char *addr = page_address(bvec->bv_page);
43116 diff --git a/fs/block_dev.c b/fs/block_dev.c
43117 index 1c44b8d..e2507b4 100644
43118 --- a/fs/block_dev.c
43119 +++ b/fs/block_dev.c
43120 @@ -681,7 +681,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43121 else if (bdev->bd_contains == bdev)
43122 return true; /* is a whole device which isn't held */
43123
43124 - else if (whole->bd_holder == bd_may_claim)
43125 + else if (whole->bd_holder == (void *)bd_may_claim)
43126 return true; /* is a partition of a device that is being partitioned */
43127 else if (whole->bd_holder != NULL)
43128 return false; /* is a partition of a held device */
43129 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43130 index 011cab3..9ace713 100644
43131 --- a/fs/btrfs/ctree.c
43132 +++ b/fs/btrfs/ctree.c
43133 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43134 free_extent_buffer(buf);
43135 add_root_to_dirty_list(root);
43136 } else {
43137 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43138 - parent_start = parent->start;
43139 - else
43140 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43141 + if (parent)
43142 + parent_start = parent->start;
43143 + else
43144 + parent_start = 0;
43145 + } else
43146 parent_start = 0;
43147
43148 WARN_ON(trans->transid != btrfs_header_generation(parent));
43149 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43150 index b2d004a..6bb543d 100644
43151 --- a/fs/btrfs/inode.c
43152 +++ b/fs/btrfs/inode.c
43153 @@ -6922,7 +6922,7 @@ fail:
43154 return -ENOMEM;
43155 }
43156
43157 -static int btrfs_getattr(struct vfsmount *mnt,
43158 +int btrfs_getattr(struct vfsmount *mnt,
43159 struct dentry *dentry, struct kstat *stat)
43160 {
43161 struct inode *inode = dentry->d_inode;
43162 @@ -6934,6 +6934,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43163 return 0;
43164 }
43165
43166 +EXPORT_SYMBOL(btrfs_getattr);
43167 +
43168 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43169 +{
43170 + return BTRFS_I(inode)->root->anon_dev;
43171 +}
43172 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43173 +
43174 /*
43175 * If a file is moved, it will inherit the cow and compression flags of the new
43176 * directory.
43177 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43178 index dae5dfe..6aa01b1 100644
43179 --- a/fs/btrfs/ioctl.c
43180 +++ b/fs/btrfs/ioctl.c
43181 @@ -2704,9 +2704,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43182 for (i = 0; i < num_types; i++) {
43183 struct btrfs_space_info *tmp;
43184
43185 + /* Don't copy in more than we allocated */
43186 if (!slot_count)
43187 break;
43188
43189 + slot_count--;
43190 +
43191 info = NULL;
43192 rcu_read_lock();
43193 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43194 @@ -2728,15 +2731,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43195 memcpy(dest, &space, sizeof(space));
43196 dest++;
43197 space_args.total_spaces++;
43198 - slot_count--;
43199 }
43200 - if (!slot_count)
43201 - break;
43202 }
43203 up_read(&info->groups_sem);
43204 }
43205
43206 - user_dest = (struct btrfs_ioctl_space_info *)
43207 + user_dest = (struct btrfs_ioctl_space_info __user *)
43208 (arg + sizeof(struct btrfs_ioctl_space_args));
43209
43210 if (copy_to_user(user_dest, dest_orig, alloc_size))
43211 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43212 index 59bb176..be9977d 100644
43213 --- a/fs/btrfs/relocation.c
43214 +++ b/fs/btrfs/relocation.c
43215 @@ -1242,7 +1242,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43216 }
43217 spin_unlock(&rc->reloc_root_tree.lock);
43218
43219 - BUG_ON((struct btrfs_root *)node->data != root);
43220 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43221
43222 if (!del) {
43223 spin_lock(&rc->reloc_root_tree.lock);
43224 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43225 index 622f469..e8d2d55 100644
43226 --- a/fs/cachefiles/bind.c
43227 +++ b/fs/cachefiles/bind.c
43228 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43229 args);
43230
43231 /* start by checking things over */
43232 - ASSERT(cache->fstop_percent >= 0 &&
43233 - cache->fstop_percent < cache->fcull_percent &&
43234 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43235 cache->fcull_percent < cache->frun_percent &&
43236 cache->frun_percent < 100);
43237
43238 - ASSERT(cache->bstop_percent >= 0 &&
43239 - cache->bstop_percent < cache->bcull_percent &&
43240 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43241 cache->bcull_percent < cache->brun_percent &&
43242 cache->brun_percent < 100);
43243
43244 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43245 index 0a1467b..6a53245 100644
43246 --- a/fs/cachefiles/daemon.c
43247 +++ b/fs/cachefiles/daemon.c
43248 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43249 if (n > buflen)
43250 return -EMSGSIZE;
43251
43252 - if (copy_to_user(_buffer, buffer, n) != 0)
43253 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43254 return -EFAULT;
43255
43256 return n;
43257 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43258 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43259 return -EIO;
43260
43261 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43262 + if (datalen > PAGE_SIZE - 1)
43263 return -EOPNOTSUPP;
43264
43265 /* drag the command string into the kernel so we can parse it */
43266 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43267 if (args[0] != '%' || args[1] != '\0')
43268 return -EINVAL;
43269
43270 - if (fstop < 0 || fstop >= cache->fcull_percent)
43271 + if (fstop >= cache->fcull_percent)
43272 return cachefiles_daemon_range_error(cache, args);
43273
43274 cache->fstop_percent = fstop;
43275 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43276 if (args[0] != '%' || args[1] != '\0')
43277 return -EINVAL;
43278
43279 - if (bstop < 0 || bstop >= cache->bcull_percent)
43280 + if (bstop >= cache->bcull_percent)
43281 return cachefiles_daemon_range_error(cache, args);
43282
43283 cache->bstop_percent = bstop;
43284 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43285 index bd6bc1b..b627b53 100644
43286 --- a/fs/cachefiles/internal.h
43287 +++ b/fs/cachefiles/internal.h
43288 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43289 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43290 struct rb_root active_nodes; /* active nodes (can't be culled) */
43291 rwlock_t active_lock; /* lock for active_nodes */
43292 - atomic_t gravecounter; /* graveyard uniquifier */
43293 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43294 unsigned frun_percent; /* when to stop culling (% files) */
43295 unsigned fcull_percent; /* when to start culling (% files) */
43296 unsigned fstop_percent; /* when to stop allocating (% files) */
43297 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43298 * proc.c
43299 */
43300 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43301 -extern atomic_t cachefiles_lookup_histogram[HZ];
43302 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43303 -extern atomic_t cachefiles_create_histogram[HZ];
43304 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43305 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43306 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43307
43308 extern int __init cachefiles_proc_init(void);
43309 extern void cachefiles_proc_cleanup(void);
43310 static inline
43311 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43312 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43313 {
43314 unsigned long jif = jiffies - start_jif;
43315 if (jif >= HZ)
43316 jif = HZ - 1;
43317 - atomic_inc(&histogram[jif]);
43318 + atomic_inc_unchecked(&histogram[jif]);
43319 }
43320
43321 #else
43322 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43323 index a0358c2..d6137f2 100644
43324 --- a/fs/cachefiles/namei.c
43325 +++ b/fs/cachefiles/namei.c
43326 @@ -318,7 +318,7 @@ try_again:
43327 /* first step is to make up a grave dentry in the graveyard */
43328 sprintf(nbuffer, "%08x%08x",
43329 (uint32_t) get_seconds(),
43330 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43331 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43332
43333 /* do the multiway lock magic */
43334 trap = lock_rename(cache->graveyard, dir);
43335 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43336 index eccd339..4c1d995 100644
43337 --- a/fs/cachefiles/proc.c
43338 +++ b/fs/cachefiles/proc.c
43339 @@ -14,9 +14,9 @@
43340 #include <linux/seq_file.h>
43341 #include "internal.h"
43342
43343 -atomic_t cachefiles_lookup_histogram[HZ];
43344 -atomic_t cachefiles_mkdir_histogram[HZ];
43345 -atomic_t cachefiles_create_histogram[HZ];
43346 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43347 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43348 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43349
43350 /*
43351 * display the latency histogram
43352 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43353 return 0;
43354 default:
43355 index = (unsigned long) v - 3;
43356 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43357 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43358 - z = atomic_read(&cachefiles_create_histogram[index]);
43359 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43360 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43361 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43362 if (x == 0 && y == 0 && z == 0)
43363 return 0;
43364
43365 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43366 index 0e3c092..818480e 100644
43367 --- a/fs/cachefiles/rdwr.c
43368 +++ b/fs/cachefiles/rdwr.c
43369 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43370 old_fs = get_fs();
43371 set_fs(KERNEL_DS);
43372 ret = file->f_op->write(
43373 - file, (const void __user *) data, len, &pos);
43374 + file, (const void __force_user *) data, len, &pos);
43375 set_fs(old_fs);
43376 kunmap(page);
43377 if (ret != len)
43378 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43379 index 382abc9..bd89646 100644
43380 --- a/fs/ceph/dir.c
43381 +++ b/fs/ceph/dir.c
43382 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43383 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43384 struct ceph_mds_client *mdsc = fsc->mdsc;
43385 unsigned frag = fpos_frag(filp->f_pos);
43386 - int off = fpos_off(filp->f_pos);
43387 + unsigned int off = fpos_off(filp->f_pos);
43388 int err;
43389 u32 ftype;
43390 struct ceph_mds_reply_info_parsed *rinfo;
43391 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43392 index 6d40656..bc1f825 100644
43393 --- a/fs/cifs/cifs_debug.c
43394 +++ b/fs/cifs/cifs_debug.c
43395 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43396
43397 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43398 #ifdef CONFIG_CIFS_STATS2
43399 - atomic_set(&totBufAllocCount, 0);
43400 - atomic_set(&totSmBufAllocCount, 0);
43401 + atomic_set_unchecked(&totBufAllocCount, 0);
43402 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43403 #endif /* CONFIG_CIFS_STATS2 */
43404 spin_lock(&cifs_tcp_ses_lock);
43405 list_for_each(tmp1, &cifs_tcp_ses_list) {
43406 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43407 tcon = list_entry(tmp3,
43408 struct cifs_tcon,
43409 tcon_list);
43410 - atomic_set(&tcon->num_smbs_sent, 0);
43411 - atomic_set(&tcon->num_writes, 0);
43412 - atomic_set(&tcon->num_reads, 0);
43413 - atomic_set(&tcon->num_oplock_brks, 0);
43414 - atomic_set(&tcon->num_opens, 0);
43415 - atomic_set(&tcon->num_posixopens, 0);
43416 - atomic_set(&tcon->num_posixmkdirs, 0);
43417 - atomic_set(&tcon->num_closes, 0);
43418 - atomic_set(&tcon->num_deletes, 0);
43419 - atomic_set(&tcon->num_mkdirs, 0);
43420 - atomic_set(&tcon->num_rmdirs, 0);
43421 - atomic_set(&tcon->num_renames, 0);
43422 - atomic_set(&tcon->num_t2renames, 0);
43423 - atomic_set(&tcon->num_ffirst, 0);
43424 - atomic_set(&tcon->num_fnext, 0);
43425 - atomic_set(&tcon->num_fclose, 0);
43426 - atomic_set(&tcon->num_hardlinks, 0);
43427 - atomic_set(&tcon->num_symlinks, 0);
43428 - atomic_set(&tcon->num_locks, 0);
43429 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43430 + atomic_set_unchecked(&tcon->num_writes, 0);
43431 + atomic_set_unchecked(&tcon->num_reads, 0);
43432 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43433 + atomic_set_unchecked(&tcon->num_opens, 0);
43434 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43435 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43436 + atomic_set_unchecked(&tcon->num_closes, 0);
43437 + atomic_set_unchecked(&tcon->num_deletes, 0);
43438 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43439 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43440 + atomic_set_unchecked(&tcon->num_renames, 0);
43441 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43442 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43443 + atomic_set_unchecked(&tcon->num_fnext, 0);
43444 + atomic_set_unchecked(&tcon->num_fclose, 0);
43445 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43446 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43447 + atomic_set_unchecked(&tcon->num_locks, 0);
43448 }
43449 }
43450 }
43451 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43452 smBufAllocCount.counter, cifs_min_small);
43453 #ifdef CONFIG_CIFS_STATS2
43454 seq_printf(m, "Total Large %d Small %d Allocations\n",
43455 - atomic_read(&totBufAllocCount),
43456 - atomic_read(&totSmBufAllocCount));
43457 + atomic_read_unchecked(&totBufAllocCount),
43458 + atomic_read_unchecked(&totSmBufAllocCount));
43459 #endif /* CONFIG_CIFS_STATS2 */
43460
43461 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43462 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43463 if (tcon->need_reconnect)
43464 seq_puts(m, "\tDISCONNECTED ");
43465 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43466 - atomic_read(&tcon->num_smbs_sent),
43467 - atomic_read(&tcon->num_oplock_brks));
43468 + atomic_read_unchecked(&tcon->num_smbs_sent),
43469 + atomic_read_unchecked(&tcon->num_oplock_brks));
43470 seq_printf(m, "\nReads: %d Bytes: %lld",
43471 - atomic_read(&tcon->num_reads),
43472 + atomic_read_unchecked(&tcon->num_reads),
43473 (long long)(tcon->bytes_read));
43474 seq_printf(m, "\nWrites: %d Bytes: %lld",
43475 - atomic_read(&tcon->num_writes),
43476 + atomic_read_unchecked(&tcon->num_writes),
43477 (long long)(tcon->bytes_written));
43478 seq_printf(m, "\nFlushes: %d",
43479 - atomic_read(&tcon->num_flushes));
43480 + atomic_read_unchecked(&tcon->num_flushes));
43481 seq_printf(m, "\nLocks: %d HardLinks: %d "
43482 "Symlinks: %d",
43483 - atomic_read(&tcon->num_locks),
43484 - atomic_read(&tcon->num_hardlinks),
43485 - atomic_read(&tcon->num_symlinks));
43486 + atomic_read_unchecked(&tcon->num_locks),
43487 + atomic_read_unchecked(&tcon->num_hardlinks),
43488 + atomic_read_unchecked(&tcon->num_symlinks));
43489 seq_printf(m, "\nOpens: %d Closes: %d "
43490 "Deletes: %d",
43491 - atomic_read(&tcon->num_opens),
43492 - atomic_read(&tcon->num_closes),
43493 - atomic_read(&tcon->num_deletes));
43494 + atomic_read_unchecked(&tcon->num_opens),
43495 + atomic_read_unchecked(&tcon->num_closes),
43496 + atomic_read_unchecked(&tcon->num_deletes));
43497 seq_printf(m, "\nPosix Opens: %d "
43498 "Posix Mkdirs: %d",
43499 - atomic_read(&tcon->num_posixopens),
43500 - atomic_read(&tcon->num_posixmkdirs));
43501 + atomic_read_unchecked(&tcon->num_posixopens),
43502 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43503 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43504 - atomic_read(&tcon->num_mkdirs),
43505 - atomic_read(&tcon->num_rmdirs));
43506 + atomic_read_unchecked(&tcon->num_mkdirs),
43507 + atomic_read_unchecked(&tcon->num_rmdirs));
43508 seq_printf(m, "\nRenames: %d T2 Renames %d",
43509 - atomic_read(&tcon->num_renames),
43510 - atomic_read(&tcon->num_t2renames));
43511 + atomic_read_unchecked(&tcon->num_renames),
43512 + atomic_read_unchecked(&tcon->num_t2renames));
43513 seq_printf(m, "\nFindFirst: %d FNext %d "
43514 "FClose %d",
43515 - atomic_read(&tcon->num_ffirst),
43516 - atomic_read(&tcon->num_fnext),
43517 - atomic_read(&tcon->num_fclose));
43518 + atomic_read_unchecked(&tcon->num_ffirst),
43519 + atomic_read_unchecked(&tcon->num_fnext),
43520 + atomic_read_unchecked(&tcon->num_fclose));
43521 }
43522 }
43523 }
43524 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43525 index 54b8f1e..f6a4c00 100644
43526 --- a/fs/cifs/cifsfs.c
43527 +++ b/fs/cifs/cifsfs.c
43528 @@ -981,7 +981,7 @@ cifs_init_request_bufs(void)
43529 cifs_req_cachep = kmem_cache_create("cifs_request",
43530 CIFSMaxBufSize +
43531 MAX_CIFS_HDR_SIZE, 0,
43532 - SLAB_HWCACHE_ALIGN, NULL);
43533 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43534 if (cifs_req_cachep == NULL)
43535 return -ENOMEM;
43536
43537 @@ -1008,7 +1008,7 @@ cifs_init_request_bufs(void)
43538 efficient to alloc 1 per page off the slab compared to 17K (5page)
43539 alloc of large cifs buffers even when page debugging is on */
43540 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43541 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43542 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43543 NULL);
43544 if (cifs_sm_req_cachep == NULL) {
43545 mempool_destroy(cifs_req_poolp);
43546 @@ -1093,8 +1093,8 @@ init_cifs(void)
43547 atomic_set(&bufAllocCount, 0);
43548 atomic_set(&smBufAllocCount, 0);
43549 #ifdef CONFIG_CIFS_STATS2
43550 - atomic_set(&totBufAllocCount, 0);
43551 - atomic_set(&totSmBufAllocCount, 0);
43552 + atomic_set_unchecked(&totBufAllocCount, 0);
43553 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43554 #endif /* CONFIG_CIFS_STATS2 */
43555
43556 atomic_set(&midCount, 0);
43557 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43558 index 95dad9d..fe7af1a 100644
43559 --- a/fs/cifs/cifsglob.h
43560 +++ b/fs/cifs/cifsglob.h
43561 @@ -381,28 +381,28 @@ struct cifs_tcon {
43562 __u16 Flags; /* optional support bits */
43563 enum statusEnum tidStatus;
43564 #ifdef CONFIG_CIFS_STATS
43565 - atomic_t num_smbs_sent;
43566 - atomic_t num_writes;
43567 - atomic_t num_reads;
43568 - atomic_t num_flushes;
43569 - atomic_t num_oplock_brks;
43570 - atomic_t num_opens;
43571 - atomic_t num_closes;
43572 - atomic_t num_deletes;
43573 - atomic_t num_mkdirs;
43574 - atomic_t num_posixopens;
43575 - atomic_t num_posixmkdirs;
43576 - atomic_t num_rmdirs;
43577 - atomic_t num_renames;
43578 - atomic_t num_t2renames;
43579 - atomic_t num_ffirst;
43580 - atomic_t num_fnext;
43581 - atomic_t num_fclose;
43582 - atomic_t num_hardlinks;
43583 - atomic_t num_symlinks;
43584 - atomic_t num_locks;
43585 - atomic_t num_acl_get;
43586 - atomic_t num_acl_set;
43587 + atomic_unchecked_t num_smbs_sent;
43588 + atomic_unchecked_t num_writes;
43589 + atomic_unchecked_t num_reads;
43590 + atomic_unchecked_t num_flushes;
43591 + atomic_unchecked_t num_oplock_brks;
43592 + atomic_unchecked_t num_opens;
43593 + atomic_unchecked_t num_closes;
43594 + atomic_unchecked_t num_deletes;
43595 + atomic_unchecked_t num_mkdirs;
43596 + atomic_unchecked_t num_posixopens;
43597 + atomic_unchecked_t num_posixmkdirs;
43598 + atomic_unchecked_t num_rmdirs;
43599 + atomic_unchecked_t num_renames;
43600 + atomic_unchecked_t num_t2renames;
43601 + atomic_unchecked_t num_ffirst;
43602 + atomic_unchecked_t num_fnext;
43603 + atomic_unchecked_t num_fclose;
43604 + atomic_unchecked_t num_hardlinks;
43605 + atomic_unchecked_t num_symlinks;
43606 + atomic_unchecked_t num_locks;
43607 + atomic_unchecked_t num_acl_get;
43608 + atomic_unchecked_t num_acl_set;
43609 #ifdef CONFIG_CIFS_STATS2
43610 unsigned long long time_writes;
43611 unsigned long long time_reads;
43612 @@ -613,7 +613,7 @@ convert_delimiter(char *path, char delim)
43613 }
43614
43615 #ifdef CONFIG_CIFS_STATS
43616 -#define cifs_stats_inc atomic_inc
43617 +#define cifs_stats_inc atomic_inc_unchecked
43618
43619 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43620 unsigned int bytes)
43621 @@ -953,8 +953,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43622 /* Various Debug counters */
43623 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43624 #ifdef CONFIG_CIFS_STATS2
43625 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43626 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43627 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43628 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43629 #endif
43630 GLOBAL_EXTERN atomic_t smBufAllocCount;
43631 GLOBAL_EXTERN atomic_t midCount;
43632 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43633 index db3f18c..1f5955e 100644
43634 --- a/fs/cifs/link.c
43635 +++ b/fs/cifs/link.c
43636 @@ -593,7 +593,7 @@ symlink_exit:
43637
43638 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43639 {
43640 - char *p = nd_get_link(nd);
43641 + const char *p = nd_get_link(nd);
43642 if (!IS_ERR(p))
43643 kfree(p);
43644 }
43645 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43646 index 7c16933..c8212b5 100644
43647 --- a/fs/cifs/misc.c
43648 +++ b/fs/cifs/misc.c
43649 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43650 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43651 atomic_inc(&bufAllocCount);
43652 #ifdef CONFIG_CIFS_STATS2
43653 - atomic_inc(&totBufAllocCount);
43654 + atomic_inc_unchecked(&totBufAllocCount);
43655 #endif /* CONFIG_CIFS_STATS2 */
43656 }
43657
43658 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43659 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43660 atomic_inc(&smBufAllocCount);
43661 #ifdef CONFIG_CIFS_STATS2
43662 - atomic_inc(&totSmBufAllocCount);
43663 + atomic_inc_unchecked(&totSmBufAllocCount);
43664 #endif /* CONFIG_CIFS_STATS2 */
43665
43666 }
43667 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43668 index 6901578..d402eb5 100644
43669 --- a/fs/coda/cache.c
43670 +++ b/fs/coda/cache.c
43671 @@ -24,7 +24,7 @@
43672 #include "coda_linux.h"
43673 #include "coda_cache.h"
43674
43675 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43676 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43677
43678 /* replace or extend an acl cache hit */
43679 void coda_cache_enter(struct inode *inode, int mask)
43680 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43681 struct coda_inode_info *cii = ITOC(inode);
43682
43683 spin_lock(&cii->c_lock);
43684 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43685 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43686 if (cii->c_uid != current_fsuid()) {
43687 cii->c_uid = current_fsuid();
43688 cii->c_cached_perm = mask;
43689 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43690 {
43691 struct coda_inode_info *cii = ITOC(inode);
43692 spin_lock(&cii->c_lock);
43693 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43694 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43695 spin_unlock(&cii->c_lock);
43696 }
43697
43698 /* remove all acl caches */
43699 void coda_cache_clear_all(struct super_block *sb)
43700 {
43701 - atomic_inc(&permission_epoch);
43702 + atomic_inc_unchecked(&permission_epoch);
43703 }
43704
43705
43706 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43707 spin_lock(&cii->c_lock);
43708 hit = (mask & cii->c_cached_perm) == mask &&
43709 cii->c_uid == current_fsuid() &&
43710 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43711 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43712 spin_unlock(&cii->c_lock);
43713
43714 return hit;
43715 diff --git a/fs/compat.c b/fs/compat.c
43716 index 58b1da4..afcd9b8 100644
43717 --- a/fs/compat.c
43718 +++ b/fs/compat.c
43719 @@ -133,8 +133,8 @@ asmlinkage long compat_sys_utimes(const char __user *filename, struct compat_tim
43720 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
43721 {
43722 compat_ino_t ino = stat->ino;
43723 - typeof(ubuf->st_uid) uid = 0;
43724 - typeof(ubuf->st_gid) gid = 0;
43725 + typeof(((struct compat_stat *)0)->st_uid) uid = 0;
43726 + typeof(((struct compat_stat *)0)->st_gid) gid = 0;
43727 int err;
43728
43729 SET_UID(uid, stat->uid);
43730 @@ -508,7 +508,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43731
43732 set_fs(KERNEL_DS);
43733 /* The __user pointer cast is valid because of the set_fs() */
43734 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43735 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43736 set_fs(oldfs);
43737 /* truncating is ok because it's a user address */
43738 if (!ret)
43739 @@ -566,7 +566,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43740 goto out;
43741
43742 ret = -EINVAL;
43743 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43744 + if (nr_segs > UIO_MAXIOV)
43745 goto out;
43746 if (nr_segs > fast_segs) {
43747 ret = -ENOMEM;
43748 @@ -848,6 +848,7 @@ struct compat_old_linux_dirent {
43749
43750 struct compat_readdir_callback {
43751 struct compat_old_linux_dirent __user *dirent;
43752 + struct file * file;
43753 int result;
43754 };
43755
43756 @@ -865,6 +866,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43757 buf->result = -EOVERFLOW;
43758 return -EOVERFLOW;
43759 }
43760 +
43761 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43762 + return 0;
43763 +
43764 buf->result++;
43765 dirent = buf->dirent;
43766 if (!access_ok(VERIFY_WRITE, dirent,
43767 @@ -897,6 +902,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43768
43769 buf.result = 0;
43770 buf.dirent = dirent;
43771 + buf.file = file;
43772
43773 error = vfs_readdir(file, compat_fillonedir, &buf);
43774 if (buf.result)
43775 @@ -917,6 +923,7 @@ struct compat_linux_dirent {
43776 struct compat_getdents_callback {
43777 struct compat_linux_dirent __user *current_dir;
43778 struct compat_linux_dirent __user *previous;
43779 + struct file * file;
43780 int count;
43781 int error;
43782 };
43783 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43784 buf->error = -EOVERFLOW;
43785 return -EOVERFLOW;
43786 }
43787 +
43788 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43789 + return 0;
43790 +
43791 dirent = buf->previous;
43792 if (dirent) {
43793 if (__put_user(offset, &dirent->d_off))
43794 @@ -985,6 +996,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43795 buf.previous = NULL;
43796 buf.count = count;
43797 buf.error = 0;
43798 + buf.file = file;
43799
43800 error = vfs_readdir(file, compat_filldir, &buf);
43801 if (error >= 0)
43802 @@ -1006,6 +1018,7 @@ out:
43803 struct compat_getdents_callback64 {
43804 struct linux_dirent64 __user *current_dir;
43805 struct linux_dirent64 __user *previous;
43806 + struct file * file;
43807 int count;
43808 int error;
43809 };
43810 @@ -1022,6 +1035,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43811 buf->error = -EINVAL; /* only used if we fail.. */
43812 if (reclen > buf->count)
43813 return -EINVAL;
43814 +
43815 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43816 + return 0;
43817 +
43818 dirent = buf->previous;
43819
43820 if (dirent) {
43821 @@ -1073,13 +1090,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43822 buf.previous = NULL;
43823 buf.count = count;
43824 buf.error = 0;
43825 + buf.file = file;
43826
43827 error = vfs_readdir(file, compat_filldir64, &buf);
43828 if (error >= 0)
43829 error = buf.error;
43830 lastdirent = buf.previous;
43831 if (lastdirent) {
43832 - typeof(lastdirent->d_off) d_off = file->f_pos;
43833 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43834 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43835 error = -EFAULT;
43836 else
43837 @@ -1446,6 +1464,8 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp,
43838 struct fdtable *fdt;
43839 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
43840
43841 + pax_track_stack();
43842 +
43843 if (n < 0)
43844 goto out_nofds;
43845
43846 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43847 index 112e45a..b59845b 100644
43848 --- a/fs/compat_binfmt_elf.c
43849 +++ b/fs/compat_binfmt_elf.c
43850 @@ -30,11 +30,13 @@
43851 #undef elf_phdr
43852 #undef elf_shdr
43853 #undef elf_note
43854 +#undef elf_dyn
43855 #undef elf_addr_t
43856 #define elfhdr elf32_hdr
43857 #define elf_phdr elf32_phdr
43858 #define elf_shdr elf32_shdr
43859 #define elf_note elf32_note
43860 +#define elf_dyn Elf32_Dyn
43861 #define elf_addr_t Elf32_Addr
43862
43863 /*
43864 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43865 index 51352de..93292ff 100644
43866 --- a/fs/compat_ioctl.c
43867 +++ b/fs/compat_ioctl.c
43868 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43869
43870 err = get_user(palp, &up->palette);
43871 err |= get_user(length, &up->length);
43872 + if (err)
43873 + return -EFAULT;
43874
43875 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43876 err = put_user(compat_ptr(palp), &up_native->palette);
43877 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43878 return -EFAULT;
43879 if (__get_user(udata, &ss32->iomem_base))
43880 return -EFAULT;
43881 - ss.iomem_base = compat_ptr(udata);
43882 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43883 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43884 __get_user(ss.port_high, &ss32->port_high))
43885 return -EFAULT;
43886 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
43887 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43888 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43889 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43890 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43891 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43892 return -EFAULT;
43893
43894 return ioctl_preallocate(file, p);
43895 @@ -1644,8 +1646,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43896 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43897 {
43898 unsigned int a, b;
43899 - a = *(unsigned int *)p;
43900 - b = *(unsigned int *)q;
43901 + a = *(const unsigned int *)p;
43902 + b = *(const unsigned int *)q;
43903 if (a > b)
43904 return 1;
43905 if (a < b)
43906 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43907 index 9a37a9b..35792b6 100644
43908 --- a/fs/configfs/dir.c
43909 +++ b/fs/configfs/dir.c
43910 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43911 }
43912 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43913 struct configfs_dirent *next;
43914 - const char * name;
43915 + const unsigned char * name;
43916 + char d_name[sizeof(next->s_dentry->d_iname)];
43917 int len;
43918 struct inode *inode = NULL;
43919
43920 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43921 continue;
43922
43923 name = configfs_get_name(next);
43924 - len = strlen(name);
43925 + if (next->s_dentry && name == next->s_dentry->d_iname) {
43926 + len = next->s_dentry->d_name.len;
43927 + memcpy(d_name, name, len);
43928 + name = d_name;
43929 + } else
43930 + len = strlen(name);
43931
43932 /*
43933 * We'll have a dentry and an inode for
43934 diff --git a/fs/dcache.c b/fs/dcache.c
43935 index 8b732a2..6db6c27 100644
43936 --- a/fs/dcache.c
43937 +++ b/fs/dcache.c
43938 @@ -3015,7 +3015,7 @@ void __init vfs_caches_init(unsigned long mempages)
43939 mempages -= reserve;
43940
43941 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43942 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43943 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43944
43945 dcache_init();
43946 inode_init();
43947 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43948 index 528da01..bd8c23d 100644
43949 --- a/fs/ecryptfs/inode.c
43950 +++ b/fs/ecryptfs/inode.c
43951 @@ -691,7 +691,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43952 old_fs = get_fs();
43953 set_fs(get_ds());
43954 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43955 - (char __user *)lower_buf,
43956 + (char __force_user *)lower_buf,
43957 lower_bufsiz);
43958 set_fs(old_fs);
43959 if (rc < 0)
43960 @@ -737,7 +737,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43961 }
43962 old_fs = get_fs();
43963 set_fs(get_ds());
43964 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43965 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43966 set_fs(old_fs);
43967 if (rc < 0) {
43968 kfree(buf);
43969 @@ -752,7 +752,7 @@ out:
43970 static void
43971 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43972 {
43973 - char *buf = nd_get_link(nd);
43974 + const char *buf = nd_get_link(nd);
43975 if (!IS_ERR(buf)) {
43976 /* Free the char* */
43977 kfree(buf);
43978 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43979 index 940a82e..63af89e 100644
43980 --- a/fs/ecryptfs/miscdev.c
43981 +++ b/fs/ecryptfs/miscdev.c
43982 @@ -328,7 +328,7 @@ check_list:
43983 goto out_unlock_msg_ctx;
43984 i = 5;
43985 if (msg_ctx->msg) {
43986 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
43987 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43988 goto out_unlock_msg_ctx;
43989 i += packet_length_size;
43990 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43991 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43992 index 3745f7c..89cc7a3 100644
43993 --- a/fs/ecryptfs/read_write.c
43994 +++ b/fs/ecryptfs/read_write.c
43995 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43996 return -EIO;
43997 fs_save = get_fs();
43998 set_fs(get_ds());
43999 - rc = vfs_write(lower_file, data, size, &offset);
44000 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44001 set_fs(fs_save);
44002 mark_inode_dirty_sync(ecryptfs_inode);
44003 return rc;
44004 @@ -235,7 +235,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44005 return -EIO;
44006 fs_save = get_fs();
44007 set_fs(get_ds());
44008 - rc = vfs_read(lower_file, data, size, &offset);
44009 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44010 set_fs(fs_save);
44011 return rc;
44012 }
44013 diff --git a/fs/exec.c b/fs/exec.c
44014 index 25dcbe5..09c172c 100644
44015 --- a/fs/exec.c
44016 +++ b/fs/exec.c
44017 @@ -55,12 +55,28 @@
44018 #include <linux/pipe_fs_i.h>
44019 #include <linux/oom.h>
44020 #include <linux/compat.h>
44021 +#include <linux/random.h>
44022 +#include <linux/seq_file.h>
44023 +
44024 +#ifdef CONFIG_PAX_REFCOUNT
44025 +#include <linux/kallsyms.h>
44026 +#include <linux/kdebug.h>
44027 +#endif
44028
44029 #include <asm/uaccess.h>
44030 #include <asm/mmu_context.h>
44031 #include <asm/tlb.h>
44032 #include "internal.h"
44033
44034 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
44035 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
44036 +#endif
44037 +
44038 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44039 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44040 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44041 +#endif
44042 +
44043 int core_uses_pid;
44044 char core_pattern[CORENAME_MAX_SIZE] = "core";
44045 unsigned int core_pipe_limit;
44046 @@ -70,7 +86,7 @@ struct core_name {
44047 char *corename;
44048 int used, size;
44049 };
44050 -static atomic_t call_count = ATOMIC_INIT(1);
44051 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44052
44053 /* The maximal length of core_pattern is also specified in sysctl.c */
44054
44055 @@ -188,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44056 int write)
44057 {
44058 struct page *page;
44059 - int ret;
44060
44061 -#ifdef CONFIG_STACK_GROWSUP
44062 - if (write) {
44063 - ret = expand_downwards(bprm->vma, pos);
44064 - if (ret < 0)
44065 - return NULL;
44066 - }
44067 -#endif
44068 - ret = get_user_pages(current, bprm->mm, pos,
44069 - 1, write, 1, &page, NULL);
44070 - if (ret <= 0)
44071 + if (0 > expand_downwards(bprm->vma, pos))
44072 + return NULL;
44073 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44074 return NULL;
44075
44076 if (write) {
44077 @@ -274,6 +282,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44078 vma->vm_end = STACK_TOP_MAX;
44079 vma->vm_start = vma->vm_end - PAGE_SIZE;
44080 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44081 +
44082 +#ifdef CONFIG_PAX_SEGMEXEC
44083 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44084 +#endif
44085 +
44086 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44087 INIT_LIST_HEAD(&vma->anon_vma_chain);
44088
44089 @@ -288,6 +301,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44090 mm->stack_vm = mm->total_vm = 1;
44091 up_write(&mm->mmap_sem);
44092 bprm->p = vma->vm_end - sizeof(void *);
44093 +
44094 +#ifdef CONFIG_PAX_RANDUSTACK
44095 + if (randomize_va_space)
44096 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
44097 +#endif
44098 +
44099 return 0;
44100 err:
44101 up_write(&mm->mmap_sem);
44102 @@ -396,19 +415,7 @@ err:
44103 return err;
44104 }
44105
44106 -struct user_arg_ptr {
44107 -#ifdef CONFIG_COMPAT
44108 - bool is_compat;
44109 -#endif
44110 - union {
44111 - const char __user *const __user *native;
44112 -#ifdef CONFIG_COMPAT
44113 - compat_uptr_t __user *compat;
44114 -#endif
44115 - } ptr;
44116 -};
44117 -
44118 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44119 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44120 {
44121 const char __user *native;
44122
44123 @@ -417,14 +424,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44124 compat_uptr_t compat;
44125
44126 if (get_user(compat, argv.ptr.compat + nr))
44127 - return ERR_PTR(-EFAULT);
44128 + return (const char __force_user *)ERR_PTR(-EFAULT);
44129
44130 return compat_ptr(compat);
44131 }
44132 #endif
44133
44134 if (get_user(native, argv.ptr.native + nr))
44135 - return ERR_PTR(-EFAULT);
44136 + return (const char __force_user *)ERR_PTR(-EFAULT);
44137
44138 return native;
44139 }
44140 @@ -443,7 +450,7 @@ static int count(struct user_arg_ptr argv, int max)
44141 if (!p)
44142 break;
44143
44144 - if (IS_ERR(p))
44145 + if (IS_ERR((const char __force_kernel *)p))
44146 return -EFAULT;
44147
44148 if (i++ >= max)
44149 @@ -477,7 +484,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44150
44151 ret = -EFAULT;
44152 str = get_user_arg_ptr(argv, argc);
44153 - if (IS_ERR(str))
44154 + if (IS_ERR((const char __force_kernel *)str))
44155 goto out;
44156
44157 len = strnlen_user(str, MAX_ARG_STRLEN);
44158 @@ -559,7 +566,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44159 int r;
44160 mm_segment_t oldfs = get_fs();
44161 struct user_arg_ptr argv = {
44162 - .ptr.native = (const char __user *const __user *)__argv,
44163 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44164 };
44165
44166 set_fs(KERNEL_DS);
44167 @@ -594,7 +601,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44168 unsigned long new_end = old_end - shift;
44169 struct mmu_gather tlb;
44170
44171 - BUG_ON(new_start > new_end);
44172 + if (new_start >= new_end || new_start < mmap_min_addr)
44173 + return -ENOMEM;
44174
44175 /*
44176 * ensure there are no vmas between where we want to go
44177 @@ -603,6 +611,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44178 if (vma != find_vma(mm, new_start))
44179 return -EFAULT;
44180
44181 +#ifdef CONFIG_PAX_SEGMEXEC
44182 + BUG_ON(pax_find_mirror_vma(vma));
44183 +#endif
44184 +
44185 /*
44186 * cover the whole range: [new_start, old_end)
44187 */
44188 @@ -683,10 +695,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44189 stack_top = arch_align_stack(stack_top);
44190 stack_top = PAGE_ALIGN(stack_top);
44191
44192 - if (unlikely(stack_top < mmap_min_addr) ||
44193 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44194 - return -ENOMEM;
44195 -
44196 stack_shift = vma->vm_end - stack_top;
44197
44198 bprm->p -= stack_shift;
44199 @@ -698,8 +706,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44200 bprm->exec -= stack_shift;
44201
44202 down_write(&mm->mmap_sem);
44203 +
44204 + /* Move stack pages down in memory. */
44205 + if (stack_shift) {
44206 + ret = shift_arg_pages(vma, stack_shift);
44207 + if (ret)
44208 + goto out_unlock;
44209 + }
44210 +
44211 vm_flags = VM_STACK_FLAGS;
44212
44213 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44214 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44215 + vm_flags &= ~VM_EXEC;
44216 +
44217 +#ifdef CONFIG_PAX_MPROTECT
44218 + if (mm->pax_flags & MF_PAX_MPROTECT)
44219 + vm_flags &= ~VM_MAYEXEC;
44220 +#endif
44221 +
44222 + }
44223 +#endif
44224 +
44225 /*
44226 * Adjust stack execute permissions; explicitly enable for
44227 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44228 @@ -718,13 +746,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44229 goto out_unlock;
44230 BUG_ON(prev != vma);
44231
44232 - /* Move stack pages down in memory. */
44233 - if (stack_shift) {
44234 - ret = shift_arg_pages(vma, stack_shift);
44235 - if (ret)
44236 - goto out_unlock;
44237 - }
44238 -
44239 /* mprotect_fixup is overkill to remove the temporary stack flags */
44240 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44241
44242 @@ -805,7 +826,7 @@ int kernel_read(struct file *file, loff_t offset,
44243 old_fs = get_fs();
44244 set_fs(get_ds());
44245 /* The cast to a user pointer is valid due to the set_fs() */
44246 - result = vfs_read(file, (void __user *)addr, count, &pos);
44247 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44248 set_fs(old_fs);
44249 return result;
44250 }
44251 @@ -1251,7 +1272,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
44252 }
44253 rcu_read_unlock();
44254
44255 - if (p->fs->users > n_fs) {
44256 + if (atomic_read(&p->fs->users) > n_fs) {
44257 bprm->unsafe |= LSM_UNSAFE_SHARE;
44258 } else {
44259 res = -EAGAIN;
44260 @@ -1454,6 +1475,11 @@ static int do_execve_common(const char *filename,
44261 struct user_arg_ptr envp,
44262 struct pt_regs *regs)
44263 {
44264 +#ifdef CONFIG_GRKERNSEC
44265 + struct file *old_exec_file;
44266 + struct acl_subject_label *old_acl;
44267 + struct rlimit old_rlim[RLIM_NLIMITS];
44268 +#endif
44269 struct linux_binprm *bprm;
44270 struct file *file;
44271 struct files_struct *displaced;
44272 @@ -1461,6 +1487,8 @@ static int do_execve_common(const char *filename,
44273 int retval;
44274 const struct cred *cred = current_cred();
44275
44276 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44277 +
44278 /*
44279 * We move the actual failure in case of RLIMIT_NPROC excess from
44280 * set*uid() to execve() because too many poorly written programs
44281 @@ -1507,6 +1535,16 @@ static int do_execve_common(const char *filename,
44282 bprm->filename = filename;
44283 bprm->interp = filename;
44284
44285 + if (gr_process_user_ban()) {
44286 + retval = -EPERM;
44287 + goto out_file;
44288 + }
44289 +
44290 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44291 + retval = -EACCES;
44292 + goto out_file;
44293 + }
44294 +
44295 retval = bprm_mm_init(bprm);
44296 if (retval)
44297 goto out_file;
44298 @@ -1536,9 +1574,40 @@ static int do_execve_common(const char *filename,
44299 if (retval < 0)
44300 goto out;
44301
44302 + if (!gr_tpe_allow(file)) {
44303 + retval = -EACCES;
44304 + goto out;
44305 + }
44306 +
44307 + if (gr_check_crash_exec(file)) {
44308 + retval = -EACCES;
44309 + goto out;
44310 + }
44311 +
44312 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44313 +
44314 + gr_handle_exec_args(bprm, argv);
44315 +
44316 +#ifdef CONFIG_GRKERNSEC
44317 + old_acl = current->acl;
44318 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44319 + old_exec_file = current->exec_file;
44320 + get_file(file);
44321 + current->exec_file = file;
44322 +#endif
44323 +
44324 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44325 + bprm->unsafe & LSM_UNSAFE_SHARE);
44326 + if (retval < 0)
44327 + goto out_fail;
44328 +
44329 retval = search_binary_handler(bprm,regs);
44330 if (retval < 0)
44331 - goto out;
44332 + goto out_fail;
44333 +#ifdef CONFIG_GRKERNSEC
44334 + if (old_exec_file)
44335 + fput(old_exec_file);
44336 +#endif
44337
44338 /* execve succeeded */
44339 current->fs->in_exec = 0;
44340 @@ -1549,6 +1618,14 @@ static int do_execve_common(const char *filename,
44341 put_files_struct(displaced);
44342 return retval;
44343
44344 +out_fail:
44345 +#ifdef CONFIG_GRKERNSEC
44346 + current->acl = old_acl;
44347 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44348 + fput(current->exec_file);
44349 + current->exec_file = old_exec_file;
44350 +#endif
44351 +
44352 out:
44353 if (bprm->mm) {
44354 acct_arg_size(bprm, 0);
44355 @@ -1622,7 +1699,7 @@ static int expand_corename(struct core_name *cn)
44356 {
44357 char *old_corename = cn->corename;
44358
44359 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44360 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44361 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44362
44363 if (!cn->corename) {
44364 @@ -1719,7 +1796,7 @@ static int format_corename(struct core_name *cn, long signr)
44365 int pid_in_pattern = 0;
44366 int err = 0;
44367
44368 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44369 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44370 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44371 cn->used = 0;
44372
44373 @@ -1816,6 +1893,218 @@ out:
44374 return ispipe;
44375 }
44376
44377 +int pax_check_flags(unsigned long *flags)
44378 +{
44379 + int retval = 0;
44380 +
44381 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44382 + if (*flags & MF_PAX_SEGMEXEC)
44383 + {
44384 + *flags &= ~MF_PAX_SEGMEXEC;
44385 + retval = -EINVAL;
44386 + }
44387 +#endif
44388 +
44389 + if ((*flags & MF_PAX_PAGEEXEC)
44390 +
44391 +#ifdef CONFIG_PAX_PAGEEXEC
44392 + && (*flags & MF_PAX_SEGMEXEC)
44393 +#endif
44394 +
44395 + )
44396 + {
44397 + *flags &= ~MF_PAX_PAGEEXEC;
44398 + retval = -EINVAL;
44399 + }
44400 +
44401 + if ((*flags & MF_PAX_MPROTECT)
44402 +
44403 +#ifdef CONFIG_PAX_MPROTECT
44404 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44405 +#endif
44406 +
44407 + )
44408 + {
44409 + *flags &= ~MF_PAX_MPROTECT;
44410 + retval = -EINVAL;
44411 + }
44412 +
44413 + if ((*flags & MF_PAX_EMUTRAMP)
44414 +
44415 +#ifdef CONFIG_PAX_EMUTRAMP
44416 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44417 +#endif
44418 +
44419 + )
44420 + {
44421 + *flags &= ~MF_PAX_EMUTRAMP;
44422 + retval = -EINVAL;
44423 + }
44424 +
44425 + return retval;
44426 +}
44427 +
44428 +EXPORT_SYMBOL(pax_check_flags);
44429 +
44430 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44431 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44432 +{
44433 + struct task_struct *tsk = current;
44434 + struct mm_struct *mm = current->mm;
44435 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44436 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44437 + char *path_exec = NULL;
44438 + char *path_fault = NULL;
44439 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44440 +
44441 + if (buffer_exec && buffer_fault) {
44442 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44443 +
44444 + down_read(&mm->mmap_sem);
44445 + vma = mm->mmap;
44446 + while (vma && (!vma_exec || !vma_fault)) {
44447 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44448 + vma_exec = vma;
44449 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44450 + vma_fault = vma;
44451 + vma = vma->vm_next;
44452 + }
44453 + if (vma_exec) {
44454 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44455 + if (IS_ERR(path_exec))
44456 + path_exec = "<path too long>";
44457 + else {
44458 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44459 + if (path_exec) {
44460 + *path_exec = 0;
44461 + path_exec = buffer_exec;
44462 + } else
44463 + path_exec = "<path too long>";
44464 + }
44465 + }
44466 + if (vma_fault) {
44467 + start = vma_fault->vm_start;
44468 + end = vma_fault->vm_end;
44469 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44470 + if (vma_fault->vm_file) {
44471 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44472 + if (IS_ERR(path_fault))
44473 + path_fault = "<path too long>";
44474 + else {
44475 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44476 + if (path_fault) {
44477 + *path_fault = 0;
44478 + path_fault = buffer_fault;
44479 + } else
44480 + path_fault = "<path too long>";
44481 + }
44482 + } else
44483 + path_fault = "<anonymous mapping>";
44484 + }
44485 + up_read(&mm->mmap_sem);
44486 + }
44487 + if (tsk->signal->curr_ip)
44488 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44489 + else
44490 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44491 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44492 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44493 + task_uid(tsk), task_euid(tsk), pc, sp);
44494 + free_page((unsigned long)buffer_exec);
44495 + free_page((unsigned long)buffer_fault);
44496 + pax_report_insns(regs, pc, sp);
44497 + do_coredump(SIGKILL, SIGKILL, regs);
44498 +}
44499 +#endif
44500 +
44501 +#ifdef CONFIG_PAX_REFCOUNT
44502 +void pax_report_refcount_overflow(struct pt_regs *regs)
44503 +{
44504 + if (current->signal->curr_ip)
44505 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44506 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44507 + else
44508 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44509 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44510 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44511 + show_regs(regs);
44512 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44513 +}
44514 +#endif
44515 +
44516 +#ifdef CONFIG_PAX_USERCOPY
44517 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44518 +int object_is_on_stack(const void *obj, unsigned long len)
44519 +{
44520 + const void * const stack = task_stack_page(current);
44521 + const void * const stackend = stack + THREAD_SIZE;
44522 +
44523 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44524 + const void *frame = NULL;
44525 + const void *oldframe;
44526 +#endif
44527 +
44528 + if (obj + len < obj)
44529 + return -1;
44530 +
44531 + if (obj + len <= stack || stackend <= obj)
44532 + return 0;
44533 +
44534 + if (obj < stack || stackend < obj + len)
44535 + return -1;
44536 +
44537 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44538 + oldframe = __builtin_frame_address(1);
44539 + if (oldframe)
44540 + frame = __builtin_frame_address(2);
44541 + /*
44542 + low ----------------------------------------------> high
44543 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44544 + ^----------------^
44545 + allow copies only within here
44546 + */
44547 + while (stack <= frame && frame < stackend) {
44548 + /* if obj + len extends past the last frame, this
44549 + check won't pass and the next frame will be 0,
44550 + causing us to bail out and correctly report
44551 + the copy as invalid
44552 + */
44553 + if (obj + len <= frame)
44554 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44555 + oldframe = frame;
44556 + frame = *(const void * const *)frame;
44557 + }
44558 + return -1;
44559 +#else
44560 + return 1;
44561 +#endif
44562 +}
44563 +
44564 +NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44565 +{
44566 + if (current->signal->curr_ip)
44567 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44568 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44569 + else
44570 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44571 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44572 + dump_stack();
44573 + gr_handle_kernel_exploit();
44574 + do_group_exit(SIGKILL);
44575 +}
44576 +#endif
44577 +
44578 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44579 +void pax_track_stack(void)
44580 +{
44581 + unsigned long sp = (unsigned long)&sp;
44582 + if (sp < current_thread_info()->lowest_stack &&
44583 + sp > (unsigned long)task_stack_page(current))
44584 + current_thread_info()->lowest_stack = sp;
44585 +}
44586 +EXPORT_SYMBOL(pax_track_stack);
44587 +#endif
44588 +
44589 static int zap_process(struct task_struct *start, int exit_code)
44590 {
44591 struct task_struct *t;
44592 @@ -2027,17 +2316,17 @@ static void wait_for_dump_helpers(struct file *file)
44593 pipe = file->f_path.dentry->d_inode->i_pipe;
44594
44595 pipe_lock(pipe);
44596 - pipe->readers++;
44597 - pipe->writers--;
44598 + atomic_inc(&pipe->readers);
44599 + atomic_dec(&pipe->writers);
44600
44601 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44602 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44603 wake_up_interruptible_sync(&pipe->wait);
44604 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44605 pipe_wait(pipe);
44606 }
44607
44608 - pipe->readers--;
44609 - pipe->writers++;
44610 + atomic_dec(&pipe->readers);
44611 + atomic_inc(&pipe->writers);
44612 pipe_unlock(pipe);
44613
44614 }
44615 @@ -2098,7 +2387,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44616 int retval = 0;
44617 int flag = 0;
44618 int ispipe;
44619 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44620 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44621 struct coredump_params cprm = {
44622 .signr = signr,
44623 .regs = regs,
44624 @@ -2113,6 +2402,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44625
44626 audit_core_dumps(signr);
44627
44628 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44629 + gr_handle_brute_attach(current, cprm.mm_flags);
44630 +
44631 binfmt = mm->binfmt;
44632 if (!binfmt || !binfmt->core_dump)
44633 goto fail;
44634 @@ -2180,7 +2472,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44635 }
44636 cprm.limit = RLIM_INFINITY;
44637
44638 - dump_count = atomic_inc_return(&core_dump_count);
44639 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44640 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44641 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44642 task_tgid_vnr(current), current->comm);
44643 @@ -2207,6 +2499,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44644 } else {
44645 struct inode *inode;
44646
44647 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44648 +
44649 if (cprm.limit < binfmt->min_coredump)
44650 goto fail_unlock;
44651
44652 @@ -2250,7 +2544,7 @@ close_fail:
44653 filp_close(cprm.file, NULL);
44654 fail_dropcount:
44655 if (ispipe)
44656 - atomic_dec(&core_dump_count);
44657 + atomic_dec_unchecked(&core_dump_count);
44658 fail_unlock:
44659 kfree(cn.corename);
44660 fail_corename:
44661 @@ -2269,7 +2563,7 @@ fail:
44662 */
44663 int dump_write(struct file *file, const void *addr, int nr)
44664 {
44665 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44666 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44667 }
44668 EXPORT_SYMBOL(dump_write);
44669
44670 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44671 index 8f44cef..cb07120 100644
44672 --- a/fs/ext2/balloc.c
44673 +++ b/fs/ext2/balloc.c
44674 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44675
44676 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44677 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44678 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44679 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44680 sbi->s_resuid != current_fsuid() &&
44681 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44682 return 0;
44683 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44684 index 6386d76..0a266b1 100644
44685 --- a/fs/ext3/balloc.c
44686 +++ b/fs/ext3/balloc.c
44687 @@ -1446,7 +1446,7 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
44688
44689 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44690 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44691 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44692 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44693 sbi->s_resuid != current_fsuid() &&
44694 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44695 return 0;
44696 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44697 index f8224ad..fbef97c 100644
44698 --- a/fs/ext4/balloc.c
44699 +++ b/fs/ext4/balloc.c
44700 @@ -394,8 +394,8 @@ static int ext4_has_free_blocks(struct ext4_sb_info *sbi,
44701 /* Hm, nope. Are (enough) root reserved blocks available? */
44702 if (sbi->s_resuid == current_fsuid() ||
44703 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44704 - capable(CAP_SYS_RESOURCE) ||
44705 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44706 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44707 + capable_nolog(CAP_SYS_RESOURCE)) {
44708
44709 if (free_blocks >= (nblocks + dirty_blocks))
44710 return 1;
44711 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44712 index 5c38120..2291d18 100644
44713 --- a/fs/ext4/ext4.h
44714 +++ b/fs/ext4/ext4.h
44715 @@ -1180,19 +1180,19 @@ struct ext4_sb_info {
44716 unsigned long s_mb_last_start;
44717
44718 /* stats for buddy allocator */
44719 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44720 - atomic_t s_bal_success; /* we found long enough chunks */
44721 - atomic_t s_bal_allocated; /* in blocks */
44722 - atomic_t s_bal_ex_scanned; /* total extents scanned */
44723 - atomic_t s_bal_goals; /* goal hits */
44724 - atomic_t s_bal_breaks; /* too long searches */
44725 - atomic_t s_bal_2orders; /* 2^order hits */
44726 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44727 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44728 + atomic_unchecked_t s_bal_allocated; /* in blocks */
44729 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44730 + atomic_unchecked_t s_bal_goals; /* goal hits */
44731 + atomic_unchecked_t s_bal_breaks; /* too long searches */
44732 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44733 spinlock_t s_bal_lock;
44734 unsigned long s_mb_buddies_generated;
44735 unsigned long long s_mb_generation_time;
44736 - atomic_t s_mb_lost_chunks;
44737 - atomic_t s_mb_preallocated;
44738 - atomic_t s_mb_discarded;
44739 + atomic_unchecked_t s_mb_lost_chunks;
44740 + atomic_unchecked_t s_mb_preallocated;
44741 + atomic_unchecked_t s_mb_discarded;
44742 atomic_t s_lock_busy;
44743
44744 /* locality groups */
44745 diff --git a/fs/ext4/file.c b/fs/ext4/file.c
44746 index e4095e9..1c006c5 100644
44747 --- a/fs/ext4/file.c
44748 +++ b/fs/ext4/file.c
44749 @@ -181,8 +181,8 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
44750 path.dentry = mnt->mnt_root;
44751 cp = d_path(&path, buf, sizeof(buf));
44752 if (!IS_ERR(cp)) {
44753 - memcpy(sbi->s_es->s_last_mounted, cp,
44754 - sizeof(sbi->s_es->s_last_mounted));
44755 + strlcpy(sbi->s_es->s_last_mounted, cp,
44756 + sizeof(sbi->s_es->s_last_mounted));
44757 ext4_mark_super_dirty(sb);
44758 }
44759 }
44760 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
44761 index f18bfe3..43759b1 100644
44762 --- a/fs/ext4/ioctl.c
44763 +++ b/fs/ext4/ioctl.c
44764 @@ -348,7 +348,7 @@ mext_out:
44765 if (!blk_queue_discard(q))
44766 return -EOPNOTSUPP;
44767
44768 - if (copy_from_user(&range, (struct fstrim_range *)arg,
44769 + if (copy_from_user(&range, (struct fstrim_range __user *)arg,
44770 sizeof(range)))
44771 return -EFAULT;
44772
44773 @@ -358,7 +358,7 @@ mext_out:
44774 if (ret < 0)
44775 return ret;
44776
44777 - if (copy_to_user((struct fstrim_range *)arg, &range,
44778 + if (copy_to_user((struct fstrim_range __user *)arg, &range,
44779 sizeof(range)))
44780 return -EFAULT;
44781
44782 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44783 index 17a5a57..b6be3c5 100644
44784 --- a/fs/ext4/mballoc.c
44785 +++ b/fs/ext4/mballoc.c
44786 @@ -1795,7 +1795,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44787 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44788
44789 if (EXT4_SB(sb)->s_mb_stats)
44790 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44791 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44792
44793 break;
44794 }
44795 @@ -2089,7 +2089,7 @@ repeat:
44796 ac->ac_status = AC_STATUS_CONTINUE;
44797 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44798 cr = 3;
44799 - atomic_inc(&sbi->s_mb_lost_chunks);
44800 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44801 goto repeat;
44802 }
44803 }
44804 @@ -2132,6 +2132,8 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
44805 ext4_grpblk_t counters[16];
44806 } sg;
44807
44808 + pax_track_stack();
44809 +
44810 group--;
44811 if (group == 0)
44812 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
44813 @@ -2573,25 +2575,25 @@ int ext4_mb_release(struct super_block *sb)
44814 if (sbi->s_mb_stats) {
44815 ext4_msg(sb, KERN_INFO,
44816 "mballoc: %u blocks %u reqs (%u success)",
44817 - atomic_read(&sbi->s_bal_allocated),
44818 - atomic_read(&sbi->s_bal_reqs),
44819 - atomic_read(&sbi->s_bal_success));
44820 + atomic_read_unchecked(&sbi->s_bal_allocated),
44821 + atomic_read_unchecked(&sbi->s_bal_reqs),
44822 + atomic_read_unchecked(&sbi->s_bal_success));
44823 ext4_msg(sb, KERN_INFO,
44824 "mballoc: %u extents scanned, %u goal hits, "
44825 "%u 2^N hits, %u breaks, %u lost",
44826 - atomic_read(&sbi->s_bal_ex_scanned),
44827 - atomic_read(&sbi->s_bal_goals),
44828 - atomic_read(&sbi->s_bal_2orders),
44829 - atomic_read(&sbi->s_bal_breaks),
44830 - atomic_read(&sbi->s_mb_lost_chunks));
44831 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44832 + atomic_read_unchecked(&sbi->s_bal_goals),
44833 + atomic_read_unchecked(&sbi->s_bal_2orders),
44834 + atomic_read_unchecked(&sbi->s_bal_breaks),
44835 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44836 ext4_msg(sb, KERN_INFO,
44837 "mballoc: %lu generated and it took %Lu",
44838 sbi->s_mb_buddies_generated,
44839 sbi->s_mb_generation_time);
44840 ext4_msg(sb, KERN_INFO,
44841 "mballoc: %u preallocated, %u discarded",
44842 - atomic_read(&sbi->s_mb_preallocated),
44843 - atomic_read(&sbi->s_mb_discarded));
44844 + atomic_read_unchecked(&sbi->s_mb_preallocated),
44845 + atomic_read_unchecked(&sbi->s_mb_discarded));
44846 }
44847
44848 free_percpu(sbi->s_locality_groups);
44849 @@ -3070,16 +3072,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44850 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44851
44852 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44853 - atomic_inc(&sbi->s_bal_reqs);
44854 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44855 + atomic_inc_unchecked(&sbi->s_bal_reqs);
44856 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44857 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44858 - atomic_inc(&sbi->s_bal_success);
44859 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44860 + atomic_inc_unchecked(&sbi->s_bal_success);
44861 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44862 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44863 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44864 - atomic_inc(&sbi->s_bal_goals);
44865 + atomic_inc_unchecked(&sbi->s_bal_goals);
44866 if (ac->ac_found > sbi->s_mb_max_to_scan)
44867 - atomic_inc(&sbi->s_bal_breaks);
44868 + atomic_inc_unchecked(&sbi->s_bal_breaks);
44869 }
44870
44871 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44872 @@ -3477,7 +3479,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44873 trace_ext4_mb_new_inode_pa(ac, pa);
44874
44875 ext4_mb_use_inode_pa(ac, pa);
44876 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44877 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44878
44879 ei = EXT4_I(ac->ac_inode);
44880 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44881 @@ -3537,7 +3539,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44882 trace_ext4_mb_new_group_pa(ac, pa);
44883
44884 ext4_mb_use_group_pa(ac, pa);
44885 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44886 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44887
44888 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44889 lg = ac->ac_lg;
44890 @@ -3625,7 +3627,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44891 * from the bitmap and continue.
44892 */
44893 }
44894 - atomic_add(free, &sbi->s_mb_discarded);
44895 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
44896
44897 return err;
44898 }
44899 @@ -3643,7 +3645,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44900 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44901 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44902 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44903 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44904 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44905 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44906
44907 return 0;
44908 diff --git a/fs/fcntl.c b/fs/fcntl.c
44909 index 22764c7..86372c9 100644
44910 --- a/fs/fcntl.c
44911 +++ b/fs/fcntl.c
44912 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44913 if (err)
44914 return err;
44915
44916 + if (gr_handle_chroot_fowner(pid, type))
44917 + return -ENOENT;
44918 + if (gr_check_protected_task_fowner(pid, type))
44919 + return -EACCES;
44920 +
44921 f_modown(filp, pid, type, force);
44922 return 0;
44923 }
44924 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44925
44926 static int f_setown_ex(struct file *filp, unsigned long arg)
44927 {
44928 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44929 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44930 struct f_owner_ex owner;
44931 struct pid *pid;
44932 int type;
44933 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44934
44935 static int f_getown_ex(struct file *filp, unsigned long arg)
44936 {
44937 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44938 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44939 struct f_owner_ex owner;
44940 int ret = 0;
44941
44942 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44943 switch (cmd) {
44944 case F_DUPFD:
44945 case F_DUPFD_CLOEXEC:
44946 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44947 if (arg >= rlimit(RLIMIT_NOFILE))
44948 break;
44949 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44950 diff --git a/fs/fifo.c b/fs/fifo.c
44951 index b1a524d..4ee270e 100644
44952 --- a/fs/fifo.c
44953 +++ b/fs/fifo.c
44954 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44955 */
44956 filp->f_op = &read_pipefifo_fops;
44957 pipe->r_counter++;
44958 - if (pipe->readers++ == 0)
44959 + if (atomic_inc_return(&pipe->readers) == 1)
44960 wake_up_partner(inode);
44961
44962 - if (!pipe->writers) {
44963 + if (!atomic_read(&pipe->writers)) {
44964 if ((filp->f_flags & O_NONBLOCK)) {
44965 /* suppress POLLHUP until we have
44966 * seen a writer */
44967 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44968 * errno=ENXIO when there is no process reading the FIFO.
44969 */
44970 ret = -ENXIO;
44971 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44972 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44973 goto err;
44974
44975 filp->f_op = &write_pipefifo_fops;
44976 pipe->w_counter++;
44977 - if (!pipe->writers++)
44978 + if (atomic_inc_return(&pipe->writers) == 1)
44979 wake_up_partner(inode);
44980
44981 - if (!pipe->readers) {
44982 + if (!atomic_read(&pipe->readers)) {
44983 wait_for_partner(inode, &pipe->r_counter);
44984 if (signal_pending(current))
44985 goto err_wr;
44986 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44987 */
44988 filp->f_op = &rdwr_pipefifo_fops;
44989
44990 - pipe->readers++;
44991 - pipe->writers++;
44992 + atomic_inc(&pipe->readers);
44993 + atomic_inc(&pipe->writers);
44994 pipe->r_counter++;
44995 pipe->w_counter++;
44996 - if (pipe->readers == 1 || pipe->writers == 1)
44997 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44998 wake_up_partner(inode);
44999 break;
45000
45001 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45002 return 0;
45003
45004 err_rd:
45005 - if (!--pipe->readers)
45006 + if (atomic_dec_and_test(&pipe->readers))
45007 wake_up_interruptible(&pipe->wait);
45008 ret = -ERESTARTSYS;
45009 goto err;
45010
45011 err_wr:
45012 - if (!--pipe->writers)
45013 + if (atomic_dec_and_test(&pipe->writers))
45014 wake_up_interruptible(&pipe->wait);
45015 ret = -ERESTARTSYS;
45016 goto err;
45017
45018 err:
45019 - if (!pipe->readers && !pipe->writers)
45020 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45021 free_pipe_info(inode);
45022
45023 err_nocleanup:
45024 diff --git a/fs/file.c b/fs/file.c
45025 index 4c6992d..104cdea 100644
45026 --- a/fs/file.c
45027 +++ b/fs/file.c
45028 @@ -15,6 +15,7 @@
45029 #include <linux/slab.h>
45030 #include <linux/vmalloc.h>
45031 #include <linux/file.h>
45032 +#include <linux/security.h>
45033 #include <linux/fdtable.h>
45034 #include <linux/bitops.h>
45035 #include <linux/interrupt.h>
45036 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
45037 * N.B. For clone tasks sharing a files structure, this test
45038 * will limit the total number of files that can be opened.
45039 */
45040 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45041 if (nr >= rlimit(RLIMIT_NOFILE))
45042 return -EMFILE;
45043
45044 diff --git a/fs/filesystems.c b/fs/filesystems.c
45045 index 0845f84..7b4ebef 100644
45046 --- a/fs/filesystems.c
45047 +++ b/fs/filesystems.c
45048 @@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(const char *name)
45049 int len = dot ? dot - name : strlen(name);
45050
45051 fs = __get_fs_type(name, len);
45052 +
45053 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45054 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45055 +#else
45056 if (!fs && (request_module("%.*s", len, name) == 0))
45057 +#endif
45058 fs = __get_fs_type(name, len);
45059
45060 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45061 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45062 index 78b519c..212c0d0 100644
45063 --- a/fs/fs_struct.c
45064 +++ b/fs/fs_struct.c
45065 @@ -4,6 +4,7 @@
45066 #include <linux/path.h>
45067 #include <linux/slab.h>
45068 #include <linux/fs_struct.h>
45069 +#include <linux/grsecurity.h>
45070 #include "internal.h"
45071
45072 static inline void path_get_longterm(struct path *path)
45073 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45074 old_root = fs->root;
45075 fs->root = *path;
45076 path_get_longterm(path);
45077 + gr_set_chroot_entries(current, path);
45078 write_seqcount_end(&fs->seq);
45079 spin_unlock(&fs->lock);
45080 if (old_root.dentry)
45081 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45082 && fs->root.mnt == old_root->mnt) {
45083 path_get_longterm(new_root);
45084 fs->root = *new_root;
45085 + gr_set_chroot_entries(p, new_root);
45086 count++;
45087 }
45088 if (fs->pwd.dentry == old_root->dentry
45089 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
45090 spin_lock(&fs->lock);
45091 write_seqcount_begin(&fs->seq);
45092 tsk->fs = NULL;
45093 - kill = !--fs->users;
45094 + gr_clear_chroot_entries(tsk);
45095 + kill = !atomic_dec_return(&fs->users);
45096 write_seqcount_end(&fs->seq);
45097 spin_unlock(&fs->lock);
45098 task_unlock(tsk);
45099 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45100 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45101 /* We don't need to lock fs - think why ;-) */
45102 if (fs) {
45103 - fs->users = 1;
45104 + atomic_set(&fs->users, 1);
45105 fs->in_exec = 0;
45106 spin_lock_init(&fs->lock);
45107 seqcount_init(&fs->seq);
45108 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45109 spin_lock(&old->lock);
45110 fs->root = old->root;
45111 path_get_longterm(&fs->root);
45112 + /* instead of calling gr_set_chroot_entries here,
45113 + we call it from every caller of this function
45114 + */
45115 fs->pwd = old->pwd;
45116 path_get_longterm(&fs->pwd);
45117 spin_unlock(&old->lock);
45118 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
45119
45120 task_lock(current);
45121 spin_lock(&fs->lock);
45122 - kill = !--fs->users;
45123 + kill = !atomic_dec_return(&fs->users);
45124 current->fs = new_fs;
45125 + gr_set_chroot_entries(current, &new_fs->root);
45126 spin_unlock(&fs->lock);
45127 task_unlock(current);
45128
45129 @@ -170,7 +178,7 @@ EXPORT_SYMBOL(current_umask);
45130
45131 /* to be mentioned only in INIT_TASK */
45132 struct fs_struct init_fs = {
45133 - .users = 1,
45134 + .users = ATOMIC_INIT(1),
45135 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45136 .seq = SEQCNT_ZERO,
45137 .umask = 0022,
45138 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
45139 task_lock(current);
45140
45141 spin_lock(&init_fs.lock);
45142 - init_fs.users++;
45143 + atomic_inc(&init_fs.users);
45144 spin_unlock(&init_fs.lock);
45145
45146 spin_lock(&fs->lock);
45147 current->fs = &init_fs;
45148 - kill = !--fs->users;
45149 + gr_set_chroot_entries(current, &current->fs->root);
45150 + kill = !atomic_dec_return(&fs->users);
45151 spin_unlock(&fs->lock);
45152
45153 task_unlock(current);
45154 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45155 index 9905350..02eaec4 100644
45156 --- a/fs/fscache/cookie.c
45157 +++ b/fs/fscache/cookie.c
45158 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45159 parent ? (char *) parent->def->name : "<no-parent>",
45160 def->name, netfs_data);
45161
45162 - fscache_stat(&fscache_n_acquires);
45163 + fscache_stat_unchecked(&fscache_n_acquires);
45164
45165 /* if there's no parent cookie, then we don't create one here either */
45166 if (!parent) {
45167 - fscache_stat(&fscache_n_acquires_null);
45168 + fscache_stat_unchecked(&fscache_n_acquires_null);
45169 _leave(" [no parent]");
45170 return NULL;
45171 }
45172 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45173 /* allocate and initialise a cookie */
45174 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45175 if (!cookie) {
45176 - fscache_stat(&fscache_n_acquires_oom);
45177 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45178 _leave(" [ENOMEM]");
45179 return NULL;
45180 }
45181 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45182
45183 switch (cookie->def->type) {
45184 case FSCACHE_COOKIE_TYPE_INDEX:
45185 - fscache_stat(&fscache_n_cookie_index);
45186 + fscache_stat_unchecked(&fscache_n_cookie_index);
45187 break;
45188 case FSCACHE_COOKIE_TYPE_DATAFILE:
45189 - fscache_stat(&fscache_n_cookie_data);
45190 + fscache_stat_unchecked(&fscache_n_cookie_data);
45191 break;
45192 default:
45193 - fscache_stat(&fscache_n_cookie_special);
45194 + fscache_stat_unchecked(&fscache_n_cookie_special);
45195 break;
45196 }
45197
45198 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45199 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45200 atomic_dec(&parent->n_children);
45201 __fscache_cookie_put(cookie);
45202 - fscache_stat(&fscache_n_acquires_nobufs);
45203 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45204 _leave(" = NULL");
45205 return NULL;
45206 }
45207 }
45208
45209 - fscache_stat(&fscache_n_acquires_ok);
45210 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45211 _leave(" = %p", cookie);
45212 return cookie;
45213 }
45214 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45215 cache = fscache_select_cache_for_object(cookie->parent);
45216 if (!cache) {
45217 up_read(&fscache_addremove_sem);
45218 - fscache_stat(&fscache_n_acquires_no_cache);
45219 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45220 _leave(" = -ENOMEDIUM [no cache]");
45221 return -ENOMEDIUM;
45222 }
45223 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45224 object = cache->ops->alloc_object(cache, cookie);
45225 fscache_stat_d(&fscache_n_cop_alloc_object);
45226 if (IS_ERR(object)) {
45227 - fscache_stat(&fscache_n_object_no_alloc);
45228 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45229 ret = PTR_ERR(object);
45230 goto error;
45231 }
45232
45233 - fscache_stat(&fscache_n_object_alloc);
45234 + fscache_stat_unchecked(&fscache_n_object_alloc);
45235
45236 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45237
45238 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45239 struct fscache_object *object;
45240 struct hlist_node *_p;
45241
45242 - fscache_stat(&fscache_n_updates);
45243 + fscache_stat_unchecked(&fscache_n_updates);
45244
45245 if (!cookie) {
45246 - fscache_stat(&fscache_n_updates_null);
45247 + fscache_stat_unchecked(&fscache_n_updates_null);
45248 _leave(" [no cookie]");
45249 return;
45250 }
45251 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45252 struct fscache_object *object;
45253 unsigned long event;
45254
45255 - fscache_stat(&fscache_n_relinquishes);
45256 + fscache_stat_unchecked(&fscache_n_relinquishes);
45257 if (retire)
45258 - fscache_stat(&fscache_n_relinquishes_retire);
45259 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45260
45261 if (!cookie) {
45262 - fscache_stat(&fscache_n_relinquishes_null);
45263 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45264 _leave(" [no cookie]");
45265 return;
45266 }
45267 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45268
45269 /* wait for the cookie to finish being instantiated (or to fail) */
45270 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45271 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45272 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45273 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45274 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45275 }
45276 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45277 index f6aad48..88dcf26 100644
45278 --- a/fs/fscache/internal.h
45279 +++ b/fs/fscache/internal.h
45280 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45281 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45282 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45283
45284 -extern atomic_t fscache_n_op_pend;
45285 -extern atomic_t fscache_n_op_run;
45286 -extern atomic_t fscache_n_op_enqueue;
45287 -extern atomic_t fscache_n_op_deferred_release;
45288 -extern atomic_t fscache_n_op_release;
45289 -extern atomic_t fscache_n_op_gc;
45290 -extern atomic_t fscache_n_op_cancelled;
45291 -extern atomic_t fscache_n_op_rejected;
45292 +extern atomic_unchecked_t fscache_n_op_pend;
45293 +extern atomic_unchecked_t fscache_n_op_run;
45294 +extern atomic_unchecked_t fscache_n_op_enqueue;
45295 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45296 +extern atomic_unchecked_t fscache_n_op_release;
45297 +extern atomic_unchecked_t fscache_n_op_gc;
45298 +extern atomic_unchecked_t fscache_n_op_cancelled;
45299 +extern atomic_unchecked_t fscache_n_op_rejected;
45300
45301 -extern atomic_t fscache_n_attr_changed;
45302 -extern atomic_t fscache_n_attr_changed_ok;
45303 -extern atomic_t fscache_n_attr_changed_nobufs;
45304 -extern atomic_t fscache_n_attr_changed_nomem;
45305 -extern atomic_t fscache_n_attr_changed_calls;
45306 +extern atomic_unchecked_t fscache_n_attr_changed;
45307 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45308 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45309 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45310 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45311
45312 -extern atomic_t fscache_n_allocs;
45313 -extern atomic_t fscache_n_allocs_ok;
45314 -extern atomic_t fscache_n_allocs_wait;
45315 -extern atomic_t fscache_n_allocs_nobufs;
45316 -extern atomic_t fscache_n_allocs_intr;
45317 -extern atomic_t fscache_n_allocs_object_dead;
45318 -extern atomic_t fscache_n_alloc_ops;
45319 -extern atomic_t fscache_n_alloc_op_waits;
45320 +extern atomic_unchecked_t fscache_n_allocs;
45321 +extern atomic_unchecked_t fscache_n_allocs_ok;
45322 +extern atomic_unchecked_t fscache_n_allocs_wait;
45323 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45324 +extern atomic_unchecked_t fscache_n_allocs_intr;
45325 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45326 +extern atomic_unchecked_t fscache_n_alloc_ops;
45327 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45328
45329 -extern atomic_t fscache_n_retrievals;
45330 -extern atomic_t fscache_n_retrievals_ok;
45331 -extern atomic_t fscache_n_retrievals_wait;
45332 -extern atomic_t fscache_n_retrievals_nodata;
45333 -extern atomic_t fscache_n_retrievals_nobufs;
45334 -extern atomic_t fscache_n_retrievals_intr;
45335 -extern atomic_t fscache_n_retrievals_nomem;
45336 -extern atomic_t fscache_n_retrievals_object_dead;
45337 -extern atomic_t fscache_n_retrieval_ops;
45338 -extern atomic_t fscache_n_retrieval_op_waits;
45339 +extern atomic_unchecked_t fscache_n_retrievals;
45340 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45341 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45342 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45343 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45344 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45345 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45346 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45347 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45348 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45349
45350 -extern atomic_t fscache_n_stores;
45351 -extern atomic_t fscache_n_stores_ok;
45352 -extern atomic_t fscache_n_stores_again;
45353 -extern atomic_t fscache_n_stores_nobufs;
45354 -extern atomic_t fscache_n_stores_oom;
45355 -extern atomic_t fscache_n_store_ops;
45356 -extern atomic_t fscache_n_store_calls;
45357 -extern atomic_t fscache_n_store_pages;
45358 -extern atomic_t fscache_n_store_radix_deletes;
45359 -extern atomic_t fscache_n_store_pages_over_limit;
45360 +extern atomic_unchecked_t fscache_n_stores;
45361 +extern atomic_unchecked_t fscache_n_stores_ok;
45362 +extern atomic_unchecked_t fscache_n_stores_again;
45363 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45364 +extern atomic_unchecked_t fscache_n_stores_oom;
45365 +extern atomic_unchecked_t fscache_n_store_ops;
45366 +extern atomic_unchecked_t fscache_n_store_calls;
45367 +extern atomic_unchecked_t fscache_n_store_pages;
45368 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45369 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45370
45371 -extern atomic_t fscache_n_store_vmscan_not_storing;
45372 -extern atomic_t fscache_n_store_vmscan_gone;
45373 -extern atomic_t fscache_n_store_vmscan_busy;
45374 -extern atomic_t fscache_n_store_vmscan_cancelled;
45375 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45376 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45377 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45378 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45379
45380 -extern atomic_t fscache_n_marks;
45381 -extern atomic_t fscache_n_uncaches;
45382 +extern atomic_unchecked_t fscache_n_marks;
45383 +extern atomic_unchecked_t fscache_n_uncaches;
45384
45385 -extern atomic_t fscache_n_acquires;
45386 -extern atomic_t fscache_n_acquires_null;
45387 -extern atomic_t fscache_n_acquires_no_cache;
45388 -extern atomic_t fscache_n_acquires_ok;
45389 -extern atomic_t fscache_n_acquires_nobufs;
45390 -extern atomic_t fscache_n_acquires_oom;
45391 +extern atomic_unchecked_t fscache_n_acquires;
45392 +extern atomic_unchecked_t fscache_n_acquires_null;
45393 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45394 +extern atomic_unchecked_t fscache_n_acquires_ok;
45395 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45396 +extern atomic_unchecked_t fscache_n_acquires_oom;
45397
45398 -extern atomic_t fscache_n_updates;
45399 -extern atomic_t fscache_n_updates_null;
45400 -extern atomic_t fscache_n_updates_run;
45401 +extern atomic_unchecked_t fscache_n_updates;
45402 +extern atomic_unchecked_t fscache_n_updates_null;
45403 +extern atomic_unchecked_t fscache_n_updates_run;
45404
45405 -extern atomic_t fscache_n_relinquishes;
45406 -extern atomic_t fscache_n_relinquishes_null;
45407 -extern atomic_t fscache_n_relinquishes_waitcrt;
45408 -extern atomic_t fscache_n_relinquishes_retire;
45409 +extern atomic_unchecked_t fscache_n_relinquishes;
45410 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45411 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45412 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45413
45414 -extern atomic_t fscache_n_cookie_index;
45415 -extern atomic_t fscache_n_cookie_data;
45416 -extern atomic_t fscache_n_cookie_special;
45417 +extern atomic_unchecked_t fscache_n_cookie_index;
45418 +extern atomic_unchecked_t fscache_n_cookie_data;
45419 +extern atomic_unchecked_t fscache_n_cookie_special;
45420
45421 -extern atomic_t fscache_n_object_alloc;
45422 -extern atomic_t fscache_n_object_no_alloc;
45423 -extern atomic_t fscache_n_object_lookups;
45424 -extern atomic_t fscache_n_object_lookups_negative;
45425 -extern atomic_t fscache_n_object_lookups_positive;
45426 -extern atomic_t fscache_n_object_lookups_timed_out;
45427 -extern atomic_t fscache_n_object_created;
45428 -extern atomic_t fscache_n_object_avail;
45429 -extern atomic_t fscache_n_object_dead;
45430 +extern atomic_unchecked_t fscache_n_object_alloc;
45431 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45432 +extern atomic_unchecked_t fscache_n_object_lookups;
45433 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45434 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45435 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45436 +extern atomic_unchecked_t fscache_n_object_created;
45437 +extern atomic_unchecked_t fscache_n_object_avail;
45438 +extern atomic_unchecked_t fscache_n_object_dead;
45439
45440 -extern atomic_t fscache_n_checkaux_none;
45441 -extern atomic_t fscache_n_checkaux_okay;
45442 -extern atomic_t fscache_n_checkaux_update;
45443 -extern atomic_t fscache_n_checkaux_obsolete;
45444 +extern atomic_unchecked_t fscache_n_checkaux_none;
45445 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45446 +extern atomic_unchecked_t fscache_n_checkaux_update;
45447 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45448
45449 extern atomic_t fscache_n_cop_alloc_object;
45450 extern atomic_t fscache_n_cop_lookup_object;
45451 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45452 atomic_inc(stat);
45453 }
45454
45455 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45456 +{
45457 + atomic_inc_unchecked(stat);
45458 +}
45459 +
45460 static inline void fscache_stat_d(atomic_t *stat)
45461 {
45462 atomic_dec(stat);
45463 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45464
45465 #define __fscache_stat(stat) (NULL)
45466 #define fscache_stat(stat) do {} while (0)
45467 +#define fscache_stat_unchecked(stat) do {} while (0)
45468 #define fscache_stat_d(stat) do {} while (0)
45469 #endif
45470
45471 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45472 index b6b897c..0ffff9c 100644
45473 --- a/fs/fscache/object.c
45474 +++ b/fs/fscache/object.c
45475 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45476 /* update the object metadata on disk */
45477 case FSCACHE_OBJECT_UPDATING:
45478 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45479 - fscache_stat(&fscache_n_updates_run);
45480 + fscache_stat_unchecked(&fscache_n_updates_run);
45481 fscache_stat(&fscache_n_cop_update_object);
45482 object->cache->ops->update_object(object);
45483 fscache_stat_d(&fscache_n_cop_update_object);
45484 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45485 spin_lock(&object->lock);
45486 object->state = FSCACHE_OBJECT_DEAD;
45487 spin_unlock(&object->lock);
45488 - fscache_stat(&fscache_n_object_dead);
45489 + fscache_stat_unchecked(&fscache_n_object_dead);
45490 goto terminal_transit;
45491
45492 /* handle the parent cache of this object being withdrawn from
45493 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45494 spin_lock(&object->lock);
45495 object->state = FSCACHE_OBJECT_DEAD;
45496 spin_unlock(&object->lock);
45497 - fscache_stat(&fscache_n_object_dead);
45498 + fscache_stat_unchecked(&fscache_n_object_dead);
45499 goto terminal_transit;
45500
45501 /* complain about the object being woken up once it is
45502 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45503 parent->cookie->def->name, cookie->def->name,
45504 object->cache->tag->name);
45505
45506 - fscache_stat(&fscache_n_object_lookups);
45507 + fscache_stat_unchecked(&fscache_n_object_lookups);
45508 fscache_stat(&fscache_n_cop_lookup_object);
45509 ret = object->cache->ops->lookup_object(object);
45510 fscache_stat_d(&fscache_n_cop_lookup_object);
45511 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45512 if (ret == -ETIMEDOUT) {
45513 /* probably stuck behind another object, so move this one to
45514 * the back of the queue */
45515 - fscache_stat(&fscache_n_object_lookups_timed_out);
45516 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45517 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45518 }
45519
45520 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45521
45522 spin_lock(&object->lock);
45523 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45524 - fscache_stat(&fscache_n_object_lookups_negative);
45525 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45526
45527 /* transit here to allow write requests to begin stacking up
45528 * and read requests to begin returning ENODATA */
45529 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45530 * result, in which case there may be data available */
45531 spin_lock(&object->lock);
45532 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45533 - fscache_stat(&fscache_n_object_lookups_positive);
45534 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45535
45536 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45537
45538 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45539 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45540 } else {
45541 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45542 - fscache_stat(&fscache_n_object_created);
45543 + fscache_stat_unchecked(&fscache_n_object_created);
45544
45545 object->state = FSCACHE_OBJECT_AVAILABLE;
45546 spin_unlock(&object->lock);
45547 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45548 fscache_enqueue_dependents(object);
45549
45550 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45551 - fscache_stat(&fscache_n_object_avail);
45552 + fscache_stat_unchecked(&fscache_n_object_avail);
45553
45554 _leave("");
45555 }
45556 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45557 enum fscache_checkaux result;
45558
45559 if (!object->cookie->def->check_aux) {
45560 - fscache_stat(&fscache_n_checkaux_none);
45561 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45562 return FSCACHE_CHECKAUX_OKAY;
45563 }
45564
45565 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45566 switch (result) {
45567 /* entry okay as is */
45568 case FSCACHE_CHECKAUX_OKAY:
45569 - fscache_stat(&fscache_n_checkaux_okay);
45570 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45571 break;
45572
45573 /* entry requires update */
45574 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45575 - fscache_stat(&fscache_n_checkaux_update);
45576 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45577 break;
45578
45579 /* entry requires deletion */
45580 case FSCACHE_CHECKAUX_OBSOLETE:
45581 - fscache_stat(&fscache_n_checkaux_obsolete);
45582 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45583 break;
45584
45585 default:
45586 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45587 index 30afdfa..2256596 100644
45588 --- a/fs/fscache/operation.c
45589 +++ b/fs/fscache/operation.c
45590 @@ -17,7 +17,7 @@
45591 #include <linux/slab.h>
45592 #include "internal.h"
45593
45594 -atomic_t fscache_op_debug_id;
45595 +atomic_unchecked_t fscache_op_debug_id;
45596 EXPORT_SYMBOL(fscache_op_debug_id);
45597
45598 /**
45599 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45600 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45601 ASSERTCMP(atomic_read(&op->usage), >, 0);
45602
45603 - fscache_stat(&fscache_n_op_enqueue);
45604 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45605 switch (op->flags & FSCACHE_OP_TYPE) {
45606 case FSCACHE_OP_ASYNC:
45607 _debug("queue async");
45608 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45609 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45610 if (op->processor)
45611 fscache_enqueue_operation(op);
45612 - fscache_stat(&fscache_n_op_run);
45613 + fscache_stat_unchecked(&fscache_n_op_run);
45614 }
45615
45616 /*
45617 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45618 if (object->n_ops > 1) {
45619 atomic_inc(&op->usage);
45620 list_add_tail(&op->pend_link, &object->pending_ops);
45621 - fscache_stat(&fscache_n_op_pend);
45622 + fscache_stat_unchecked(&fscache_n_op_pend);
45623 } else if (!list_empty(&object->pending_ops)) {
45624 atomic_inc(&op->usage);
45625 list_add_tail(&op->pend_link, &object->pending_ops);
45626 - fscache_stat(&fscache_n_op_pend);
45627 + fscache_stat_unchecked(&fscache_n_op_pend);
45628 fscache_start_operations(object);
45629 } else {
45630 ASSERTCMP(object->n_in_progress, ==, 0);
45631 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45632 object->n_exclusive++; /* reads and writes must wait */
45633 atomic_inc(&op->usage);
45634 list_add_tail(&op->pend_link, &object->pending_ops);
45635 - fscache_stat(&fscache_n_op_pend);
45636 + fscache_stat_unchecked(&fscache_n_op_pend);
45637 ret = 0;
45638 } else {
45639 /* not allowed to submit ops in any other state */
45640 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45641 if (object->n_exclusive > 0) {
45642 atomic_inc(&op->usage);
45643 list_add_tail(&op->pend_link, &object->pending_ops);
45644 - fscache_stat(&fscache_n_op_pend);
45645 + fscache_stat_unchecked(&fscache_n_op_pend);
45646 } else if (!list_empty(&object->pending_ops)) {
45647 atomic_inc(&op->usage);
45648 list_add_tail(&op->pend_link, &object->pending_ops);
45649 - fscache_stat(&fscache_n_op_pend);
45650 + fscache_stat_unchecked(&fscache_n_op_pend);
45651 fscache_start_operations(object);
45652 } else {
45653 ASSERTCMP(object->n_exclusive, ==, 0);
45654 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45655 object->n_ops++;
45656 atomic_inc(&op->usage);
45657 list_add_tail(&op->pend_link, &object->pending_ops);
45658 - fscache_stat(&fscache_n_op_pend);
45659 + fscache_stat_unchecked(&fscache_n_op_pend);
45660 ret = 0;
45661 } else if (object->state == FSCACHE_OBJECT_DYING ||
45662 object->state == FSCACHE_OBJECT_LC_DYING ||
45663 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45664 - fscache_stat(&fscache_n_op_rejected);
45665 + fscache_stat_unchecked(&fscache_n_op_rejected);
45666 ret = -ENOBUFS;
45667 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45668 fscache_report_unexpected_submission(object, op, ostate);
45669 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45670
45671 ret = -EBUSY;
45672 if (!list_empty(&op->pend_link)) {
45673 - fscache_stat(&fscache_n_op_cancelled);
45674 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45675 list_del_init(&op->pend_link);
45676 object->n_ops--;
45677 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45678 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45679 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45680 BUG();
45681
45682 - fscache_stat(&fscache_n_op_release);
45683 + fscache_stat_unchecked(&fscache_n_op_release);
45684
45685 if (op->release) {
45686 op->release(op);
45687 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45688 * lock, and defer it otherwise */
45689 if (!spin_trylock(&object->lock)) {
45690 _debug("defer put");
45691 - fscache_stat(&fscache_n_op_deferred_release);
45692 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
45693
45694 cache = object->cache;
45695 spin_lock(&cache->op_gc_list_lock);
45696 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45697
45698 _debug("GC DEFERRED REL OBJ%x OP%x",
45699 object->debug_id, op->debug_id);
45700 - fscache_stat(&fscache_n_op_gc);
45701 + fscache_stat_unchecked(&fscache_n_op_gc);
45702
45703 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45704
45705 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45706 index 3f7a59b..cf196cc 100644
45707 --- a/fs/fscache/page.c
45708 +++ b/fs/fscache/page.c
45709 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45710 val = radix_tree_lookup(&cookie->stores, page->index);
45711 if (!val) {
45712 rcu_read_unlock();
45713 - fscache_stat(&fscache_n_store_vmscan_not_storing);
45714 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45715 __fscache_uncache_page(cookie, page);
45716 return true;
45717 }
45718 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45719 spin_unlock(&cookie->stores_lock);
45720
45721 if (xpage) {
45722 - fscache_stat(&fscache_n_store_vmscan_cancelled);
45723 - fscache_stat(&fscache_n_store_radix_deletes);
45724 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45725 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45726 ASSERTCMP(xpage, ==, page);
45727 } else {
45728 - fscache_stat(&fscache_n_store_vmscan_gone);
45729 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45730 }
45731
45732 wake_up_bit(&cookie->flags, 0);
45733 @@ -107,7 +107,7 @@ page_busy:
45734 /* we might want to wait here, but that could deadlock the allocator as
45735 * the work threads writing to the cache may all end up sleeping
45736 * on memory allocation */
45737 - fscache_stat(&fscache_n_store_vmscan_busy);
45738 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45739 return false;
45740 }
45741 EXPORT_SYMBOL(__fscache_maybe_release_page);
45742 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45743 FSCACHE_COOKIE_STORING_TAG);
45744 if (!radix_tree_tag_get(&cookie->stores, page->index,
45745 FSCACHE_COOKIE_PENDING_TAG)) {
45746 - fscache_stat(&fscache_n_store_radix_deletes);
45747 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45748 xpage = radix_tree_delete(&cookie->stores, page->index);
45749 }
45750 spin_unlock(&cookie->stores_lock);
45751 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45752
45753 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45754
45755 - fscache_stat(&fscache_n_attr_changed_calls);
45756 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45757
45758 if (fscache_object_is_active(object)) {
45759 fscache_stat(&fscache_n_cop_attr_changed);
45760 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45761
45762 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45763
45764 - fscache_stat(&fscache_n_attr_changed);
45765 + fscache_stat_unchecked(&fscache_n_attr_changed);
45766
45767 op = kzalloc(sizeof(*op), GFP_KERNEL);
45768 if (!op) {
45769 - fscache_stat(&fscache_n_attr_changed_nomem);
45770 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45771 _leave(" = -ENOMEM");
45772 return -ENOMEM;
45773 }
45774 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45775 if (fscache_submit_exclusive_op(object, op) < 0)
45776 goto nobufs;
45777 spin_unlock(&cookie->lock);
45778 - fscache_stat(&fscache_n_attr_changed_ok);
45779 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45780 fscache_put_operation(op);
45781 _leave(" = 0");
45782 return 0;
45783 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45784 nobufs:
45785 spin_unlock(&cookie->lock);
45786 kfree(op);
45787 - fscache_stat(&fscache_n_attr_changed_nobufs);
45788 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45789 _leave(" = %d", -ENOBUFS);
45790 return -ENOBUFS;
45791 }
45792 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45793 /* allocate a retrieval operation and attempt to submit it */
45794 op = kzalloc(sizeof(*op), GFP_NOIO);
45795 if (!op) {
45796 - fscache_stat(&fscache_n_retrievals_nomem);
45797 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45798 return NULL;
45799 }
45800
45801 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45802 return 0;
45803 }
45804
45805 - fscache_stat(&fscache_n_retrievals_wait);
45806 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
45807
45808 jif = jiffies;
45809 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45810 fscache_wait_bit_interruptible,
45811 TASK_INTERRUPTIBLE) != 0) {
45812 - fscache_stat(&fscache_n_retrievals_intr);
45813 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45814 _leave(" = -ERESTARTSYS");
45815 return -ERESTARTSYS;
45816 }
45817 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45818 */
45819 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45820 struct fscache_retrieval *op,
45821 - atomic_t *stat_op_waits,
45822 - atomic_t *stat_object_dead)
45823 + atomic_unchecked_t *stat_op_waits,
45824 + atomic_unchecked_t *stat_object_dead)
45825 {
45826 int ret;
45827
45828 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45829 goto check_if_dead;
45830
45831 _debug(">>> WT");
45832 - fscache_stat(stat_op_waits);
45833 + fscache_stat_unchecked(stat_op_waits);
45834 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45835 fscache_wait_bit_interruptible,
45836 TASK_INTERRUPTIBLE) < 0) {
45837 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45838
45839 check_if_dead:
45840 if (unlikely(fscache_object_is_dead(object))) {
45841 - fscache_stat(stat_object_dead);
45842 + fscache_stat_unchecked(stat_object_dead);
45843 return -ENOBUFS;
45844 }
45845 return 0;
45846 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45847
45848 _enter("%p,%p,,,", cookie, page);
45849
45850 - fscache_stat(&fscache_n_retrievals);
45851 + fscache_stat_unchecked(&fscache_n_retrievals);
45852
45853 if (hlist_empty(&cookie->backing_objects))
45854 goto nobufs;
45855 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45856 goto nobufs_unlock;
45857 spin_unlock(&cookie->lock);
45858
45859 - fscache_stat(&fscache_n_retrieval_ops);
45860 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45861
45862 /* pin the netfs read context in case we need to do the actual netfs
45863 * read because we've encountered a cache read failure */
45864 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45865
45866 error:
45867 if (ret == -ENOMEM)
45868 - fscache_stat(&fscache_n_retrievals_nomem);
45869 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45870 else if (ret == -ERESTARTSYS)
45871 - fscache_stat(&fscache_n_retrievals_intr);
45872 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45873 else if (ret == -ENODATA)
45874 - fscache_stat(&fscache_n_retrievals_nodata);
45875 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45876 else if (ret < 0)
45877 - fscache_stat(&fscache_n_retrievals_nobufs);
45878 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45879 else
45880 - fscache_stat(&fscache_n_retrievals_ok);
45881 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45882
45883 fscache_put_retrieval(op);
45884 _leave(" = %d", ret);
45885 @@ -429,7 +429,7 @@ nobufs_unlock:
45886 spin_unlock(&cookie->lock);
45887 kfree(op);
45888 nobufs:
45889 - fscache_stat(&fscache_n_retrievals_nobufs);
45890 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45891 _leave(" = -ENOBUFS");
45892 return -ENOBUFS;
45893 }
45894 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45895
45896 _enter("%p,,%d,,,", cookie, *nr_pages);
45897
45898 - fscache_stat(&fscache_n_retrievals);
45899 + fscache_stat_unchecked(&fscache_n_retrievals);
45900
45901 if (hlist_empty(&cookie->backing_objects))
45902 goto nobufs;
45903 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45904 goto nobufs_unlock;
45905 spin_unlock(&cookie->lock);
45906
45907 - fscache_stat(&fscache_n_retrieval_ops);
45908 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45909
45910 /* pin the netfs read context in case we need to do the actual netfs
45911 * read because we've encountered a cache read failure */
45912 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45913
45914 error:
45915 if (ret == -ENOMEM)
45916 - fscache_stat(&fscache_n_retrievals_nomem);
45917 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45918 else if (ret == -ERESTARTSYS)
45919 - fscache_stat(&fscache_n_retrievals_intr);
45920 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45921 else if (ret == -ENODATA)
45922 - fscache_stat(&fscache_n_retrievals_nodata);
45923 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45924 else if (ret < 0)
45925 - fscache_stat(&fscache_n_retrievals_nobufs);
45926 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45927 else
45928 - fscache_stat(&fscache_n_retrievals_ok);
45929 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45930
45931 fscache_put_retrieval(op);
45932 _leave(" = %d", ret);
45933 @@ -545,7 +545,7 @@ nobufs_unlock:
45934 spin_unlock(&cookie->lock);
45935 kfree(op);
45936 nobufs:
45937 - fscache_stat(&fscache_n_retrievals_nobufs);
45938 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45939 _leave(" = -ENOBUFS");
45940 return -ENOBUFS;
45941 }
45942 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45943
45944 _enter("%p,%p,,,", cookie, page);
45945
45946 - fscache_stat(&fscache_n_allocs);
45947 + fscache_stat_unchecked(&fscache_n_allocs);
45948
45949 if (hlist_empty(&cookie->backing_objects))
45950 goto nobufs;
45951 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45952 goto nobufs_unlock;
45953 spin_unlock(&cookie->lock);
45954
45955 - fscache_stat(&fscache_n_alloc_ops);
45956 + fscache_stat_unchecked(&fscache_n_alloc_ops);
45957
45958 ret = fscache_wait_for_retrieval_activation(
45959 object, op,
45960 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45961
45962 error:
45963 if (ret == -ERESTARTSYS)
45964 - fscache_stat(&fscache_n_allocs_intr);
45965 + fscache_stat_unchecked(&fscache_n_allocs_intr);
45966 else if (ret < 0)
45967 - fscache_stat(&fscache_n_allocs_nobufs);
45968 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45969 else
45970 - fscache_stat(&fscache_n_allocs_ok);
45971 + fscache_stat_unchecked(&fscache_n_allocs_ok);
45972
45973 fscache_put_retrieval(op);
45974 _leave(" = %d", ret);
45975 @@ -625,7 +625,7 @@ nobufs_unlock:
45976 spin_unlock(&cookie->lock);
45977 kfree(op);
45978 nobufs:
45979 - fscache_stat(&fscache_n_allocs_nobufs);
45980 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45981 _leave(" = -ENOBUFS");
45982 return -ENOBUFS;
45983 }
45984 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45985
45986 spin_lock(&cookie->stores_lock);
45987
45988 - fscache_stat(&fscache_n_store_calls);
45989 + fscache_stat_unchecked(&fscache_n_store_calls);
45990
45991 /* find a page to store */
45992 page = NULL;
45993 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45994 page = results[0];
45995 _debug("gang %d [%lx]", n, page->index);
45996 if (page->index > op->store_limit) {
45997 - fscache_stat(&fscache_n_store_pages_over_limit);
45998 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45999 goto superseded;
46000 }
46001
46002 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46003 spin_unlock(&cookie->stores_lock);
46004 spin_unlock(&object->lock);
46005
46006 - fscache_stat(&fscache_n_store_pages);
46007 + fscache_stat_unchecked(&fscache_n_store_pages);
46008 fscache_stat(&fscache_n_cop_write_page);
46009 ret = object->cache->ops->write_page(op, page);
46010 fscache_stat_d(&fscache_n_cop_write_page);
46011 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46012 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46013 ASSERT(PageFsCache(page));
46014
46015 - fscache_stat(&fscache_n_stores);
46016 + fscache_stat_unchecked(&fscache_n_stores);
46017
46018 op = kzalloc(sizeof(*op), GFP_NOIO);
46019 if (!op)
46020 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46021 spin_unlock(&cookie->stores_lock);
46022 spin_unlock(&object->lock);
46023
46024 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46025 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46026 op->store_limit = object->store_limit;
46027
46028 if (fscache_submit_op(object, &op->op) < 0)
46029 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46030
46031 spin_unlock(&cookie->lock);
46032 radix_tree_preload_end();
46033 - fscache_stat(&fscache_n_store_ops);
46034 - fscache_stat(&fscache_n_stores_ok);
46035 + fscache_stat_unchecked(&fscache_n_store_ops);
46036 + fscache_stat_unchecked(&fscache_n_stores_ok);
46037
46038 /* the work queue now carries its own ref on the object */
46039 fscache_put_operation(&op->op);
46040 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46041 return 0;
46042
46043 already_queued:
46044 - fscache_stat(&fscache_n_stores_again);
46045 + fscache_stat_unchecked(&fscache_n_stores_again);
46046 already_pending:
46047 spin_unlock(&cookie->stores_lock);
46048 spin_unlock(&object->lock);
46049 spin_unlock(&cookie->lock);
46050 radix_tree_preload_end();
46051 kfree(op);
46052 - fscache_stat(&fscache_n_stores_ok);
46053 + fscache_stat_unchecked(&fscache_n_stores_ok);
46054 _leave(" = 0");
46055 return 0;
46056
46057 @@ -851,14 +851,14 @@ nobufs:
46058 spin_unlock(&cookie->lock);
46059 radix_tree_preload_end();
46060 kfree(op);
46061 - fscache_stat(&fscache_n_stores_nobufs);
46062 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46063 _leave(" = -ENOBUFS");
46064 return -ENOBUFS;
46065
46066 nomem_free:
46067 kfree(op);
46068 nomem:
46069 - fscache_stat(&fscache_n_stores_oom);
46070 + fscache_stat_unchecked(&fscache_n_stores_oom);
46071 _leave(" = -ENOMEM");
46072 return -ENOMEM;
46073 }
46074 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46075 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46076 ASSERTCMP(page, !=, NULL);
46077
46078 - fscache_stat(&fscache_n_uncaches);
46079 + fscache_stat_unchecked(&fscache_n_uncaches);
46080
46081 /* cache withdrawal may beat us to it */
46082 if (!PageFsCache(page))
46083 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46084 unsigned long loop;
46085
46086 #ifdef CONFIG_FSCACHE_STATS
46087 - atomic_add(pagevec->nr, &fscache_n_marks);
46088 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46089 #endif
46090
46091 for (loop = 0; loop < pagevec->nr; loop++) {
46092 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46093 index 4765190..2a067f2 100644
46094 --- a/fs/fscache/stats.c
46095 +++ b/fs/fscache/stats.c
46096 @@ -18,95 +18,95 @@
46097 /*
46098 * operation counters
46099 */
46100 -atomic_t fscache_n_op_pend;
46101 -atomic_t fscache_n_op_run;
46102 -atomic_t fscache_n_op_enqueue;
46103 -atomic_t fscache_n_op_requeue;
46104 -atomic_t fscache_n_op_deferred_release;
46105 -atomic_t fscache_n_op_release;
46106 -atomic_t fscache_n_op_gc;
46107 -atomic_t fscache_n_op_cancelled;
46108 -atomic_t fscache_n_op_rejected;
46109 +atomic_unchecked_t fscache_n_op_pend;
46110 +atomic_unchecked_t fscache_n_op_run;
46111 +atomic_unchecked_t fscache_n_op_enqueue;
46112 +atomic_unchecked_t fscache_n_op_requeue;
46113 +atomic_unchecked_t fscache_n_op_deferred_release;
46114 +atomic_unchecked_t fscache_n_op_release;
46115 +atomic_unchecked_t fscache_n_op_gc;
46116 +atomic_unchecked_t fscache_n_op_cancelled;
46117 +atomic_unchecked_t fscache_n_op_rejected;
46118
46119 -atomic_t fscache_n_attr_changed;
46120 -atomic_t fscache_n_attr_changed_ok;
46121 -atomic_t fscache_n_attr_changed_nobufs;
46122 -atomic_t fscache_n_attr_changed_nomem;
46123 -atomic_t fscache_n_attr_changed_calls;
46124 +atomic_unchecked_t fscache_n_attr_changed;
46125 +atomic_unchecked_t fscache_n_attr_changed_ok;
46126 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46127 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46128 +atomic_unchecked_t fscache_n_attr_changed_calls;
46129
46130 -atomic_t fscache_n_allocs;
46131 -atomic_t fscache_n_allocs_ok;
46132 -atomic_t fscache_n_allocs_wait;
46133 -atomic_t fscache_n_allocs_nobufs;
46134 -atomic_t fscache_n_allocs_intr;
46135 -atomic_t fscache_n_allocs_object_dead;
46136 -atomic_t fscache_n_alloc_ops;
46137 -atomic_t fscache_n_alloc_op_waits;
46138 +atomic_unchecked_t fscache_n_allocs;
46139 +atomic_unchecked_t fscache_n_allocs_ok;
46140 +atomic_unchecked_t fscache_n_allocs_wait;
46141 +atomic_unchecked_t fscache_n_allocs_nobufs;
46142 +atomic_unchecked_t fscache_n_allocs_intr;
46143 +atomic_unchecked_t fscache_n_allocs_object_dead;
46144 +atomic_unchecked_t fscache_n_alloc_ops;
46145 +atomic_unchecked_t fscache_n_alloc_op_waits;
46146
46147 -atomic_t fscache_n_retrievals;
46148 -atomic_t fscache_n_retrievals_ok;
46149 -atomic_t fscache_n_retrievals_wait;
46150 -atomic_t fscache_n_retrievals_nodata;
46151 -atomic_t fscache_n_retrievals_nobufs;
46152 -atomic_t fscache_n_retrievals_intr;
46153 -atomic_t fscache_n_retrievals_nomem;
46154 -atomic_t fscache_n_retrievals_object_dead;
46155 -atomic_t fscache_n_retrieval_ops;
46156 -atomic_t fscache_n_retrieval_op_waits;
46157 +atomic_unchecked_t fscache_n_retrievals;
46158 +atomic_unchecked_t fscache_n_retrievals_ok;
46159 +atomic_unchecked_t fscache_n_retrievals_wait;
46160 +atomic_unchecked_t fscache_n_retrievals_nodata;
46161 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46162 +atomic_unchecked_t fscache_n_retrievals_intr;
46163 +atomic_unchecked_t fscache_n_retrievals_nomem;
46164 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46165 +atomic_unchecked_t fscache_n_retrieval_ops;
46166 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46167
46168 -atomic_t fscache_n_stores;
46169 -atomic_t fscache_n_stores_ok;
46170 -atomic_t fscache_n_stores_again;
46171 -atomic_t fscache_n_stores_nobufs;
46172 -atomic_t fscache_n_stores_oom;
46173 -atomic_t fscache_n_store_ops;
46174 -atomic_t fscache_n_store_calls;
46175 -atomic_t fscache_n_store_pages;
46176 -atomic_t fscache_n_store_radix_deletes;
46177 -atomic_t fscache_n_store_pages_over_limit;
46178 +atomic_unchecked_t fscache_n_stores;
46179 +atomic_unchecked_t fscache_n_stores_ok;
46180 +atomic_unchecked_t fscache_n_stores_again;
46181 +atomic_unchecked_t fscache_n_stores_nobufs;
46182 +atomic_unchecked_t fscache_n_stores_oom;
46183 +atomic_unchecked_t fscache_n_store_ops;
46184 +atomic_unchecked_t fscache_n_store_calls;
46185 +atomic_unchecked_t fscache_n_store_pages;
46186 +atomic_unchecked_t fscache_n_store_radix_deletes;
46187 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46188
46189 -atomic_t fscache_n_store_vmscan_not_storing;
46190 -atomic_t fscache_n_store_vmscan_gone;
46191 -atomic_t fscache_n_store_vmscan_busy;
46192 -atomic_t fscache_n_store_vmscan_cancelled;
46193 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46194 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46195 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46196 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46197
46198 -atomic_t fscache_n_marks;
46199 -atomic_t fscache_n_uncaches;
46200 +atomic_unchecked_t fscache_n_marks;
46201 +atomic_unchecked_t fscache_n_uncaches;
46202
46203 -atomic_t fscache_n_acquires;
46204 -atomic_t fscache_n_acquires_null;
46205 -atomic_t fscache_n_acquires_no_cache;
46206 -atomic_t fscache_n_acquires_ok;
46207 -atomic_t fscache_n_acquires_nobufs;
46208 -atomic_t fscache_n_acquires_oom;
46209 +atomic_unchecked_t fscache_n_acquires;
46210 +atomic_unchecked_t fscache_n_acquires_null;
46211 +atomic_unchecked_t fscache_n_acquires_no_cache;
46212 +atomic_unchecked_t fscache_n_acquires_ok;
46213 +atomic_unchecked_t fscache_n_acquires_nobufs;
46214 +atomic_unchecked_t fscache_n_acquires_oom;
46215
46216 -atomic_t fscache_n_updates;
46217 -atomic_t fscache_n_updates_null;
46218 -atomic_t fscache_n_updates_run;
46219 +atomic_unchecked_t fscache_n_updates;
46220 +atomic_unchecked_t fscache_n_updates_null;
46221 +atomic_unchecked_t fscache_n_updates_run;
46222
46223 -atomic_t fscache_n_relinquishes;
46224 -atomic_t fscache_n_relinquishes_null;
46225 -atomic_t fscache_n_relinquishes_waitcrt;
46226 -atomic_t fscache_n_relinquishes_retire;
46227 +atomic_unchecked_t fscache_n_relinquishes;
46228 +atomic_unchecked_t fscache_n_relinquishes_null;
46229 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46230 +atomic_unchecked_t fscache_n_relinquishes_retire;
46231
46232 -atomic_t fscache_n_cookie_index;
46233 -atomic_t fscache_n_cookie_data;
46234 -atomic_t fscache_n_cookie_special;
46235 +atomic_unchecked_t fscache_n_cookie_index;
46236 +atomic_unchecked_t fscache_n_cookie_data;
46237 +atomic_unchecked_t fscache_n_cookie_special;
46238
46239 -atomic_t fscache_n_object_alloc;
46240 -atomic_t fscache_n_object_no_alloc;
46241 -atomic_t fscache_n_object_lookups;
46242 -atomic_t fscache_n_object_lookups_negative;
46243 -atomic_t fscache_n_object_lookups_positive;
46244 -atomic_t fscache_n_object_lookups_timed_out;
46245 -atomic_t fscache_n_object_created;
46246 -atomic_t fscache_n_object_avail;
46247 -atomic_t fscache_n_object_dead;
46248 +atomic_unchecked_t fscache_n_object_alloc;
46249 +atomic_unchecked_t fscache_n_object_no_alloc;
46250 +atomic_unchecked_t fscache_n_object_lookups;
46251 +atomic_unchecked_t fscache_n_object_lookups_negative;
46252 +atomic_unchecked_t fscache_n_object_lookups_positive;
46253 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46254 +atomic_unchecked_t fscache_n_object_created;
46255 +atomic_unchecked_t fscache_n_object_avail;
46256 +atomic_unchecked_t fscache_n_object_dead;
46257
46258 -atomic_t fscache_n_checkaux_none;
46259 -atomic_t fscache_n_checkaux_okay;
46260 -atomic_t fscache_n_checkaux_update;
46261 -atomic_t fscache_n_checkaux_obsolete;
46262 +atomic_unchecked_t fscache_n_checkaux_none;
46263 +atomic_unchecked_t fscache_n_checkaux_okay;
46264 +atomic_unchecked_t fscache_n_checkaux_update;
46265 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46266
46267 atomic_t fscache_n_cop_alloc_object;
46268 atomic_t fscache_n_cop_lookup_object;
46269 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46270 seq_puts(m, "FS-Cache statistics\n");
46271
46272 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46273 - atomic_read(&fscache_n_cookie_index),
46274 - atomic_read(&fscache_n_cookie_data),
46275 - atomic_read(&fscache_n_cookie_special));
46276 + atomic_read_unchecked(&fscache_n_cookie_index),
46277 + atomic_read_unchecked(&fscache_n_cookie_data),
46278 + atomic_read_unchecked(&fscache_n_cookie_special));
46279
46280 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46281 - atomic_read(&fscache_n_object_alloc),
46282 - atomic_read(&fscache_n_object_no_alloc),
46283 - atomic_read(&fscache_n_object_avail),
46284 - atomic_read(&fscache_n_object_dead));
46285 + atomic_read_unchecked(&fscache_n_object_alloc),
46286 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46287 + atomic_read_unchecked(&fscache_n_object_avail),
46288 + atomic_read_unchecked(&fscache_n_object_dead));
46289 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46290 - atomic_read(&fscache_n_checkaux_none),
46291 - atomic_read(&fscache_n_checkaux_okay),
46292 - atomic_read(&fscache_n_checkaux_update),
46293 - atomic_read(&fscache_n_checkaux_obsolete));
46294 + atomic_read_unchecked(&fscache_n_checkaux_none),
46295 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46296 + atomic_read_unchecked(&fscache_n_checkaux_update),
46297 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46298
46299 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46300 - atomic_read(&fscache_n_marks),
46301 - atomic_read(&fscache_n_uncaches));
46302 + atomic_read_unchecked(&fscache_n_marks),
46303 + atomic_read_unchecked(&fscache_n_uncaches));
46304
46305 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46306 " oom=%u\n",
46307 - atomic_read(&fscache_n_acquires),
46308 - atomic_read(&fscache_n_acquires_null),
46309 - atomic_read(&fscache_n_acquires_no_cache),
46310 - atomic_read(&fscache_n_acquires_ok),
46311 - atomic_read(&fscache_n_acquires_nobufs),
46312 - atomic_read(&fscache_n_acquires_oom));
46313 + atomic_read_unchecked(&fscache_n_acquires),
46314 + atomic_read_unchecked(&fscache_n_acquires_null),
46315 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46316 + atomic_read_unchecked(&fscache_n_acquires_ok),
46317 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46318 + atomic_read_unchecked(&fscache_n_acquires_oom));
46319
46320 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46321 - atomic_read(&fscache_n_object_lookups),
46322 - atomic_read(&fscache_n_object_lookups_negative),
46323 - atomic_read(&fscache_n_object_lookups_positive),
46324 - atomic_read(&fscache_n_object_created),
46325 - atomic_read(&fscache_n_object_lookups_timed_out));
46326 + atomic_read_unchecked(&fscache_n_object_lookups),
46327 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46328 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46329 + atomic_read_unchecked(&fscache_n_object_created),
46330 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46331
46332 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46333 - atomic_read(&fscache_n_updates),
46334 - atomic_read(&fscache_n_updates_null),
46335 - atomic_read(&fscache_n_updates_run));
46336 + atomic_read_unchecked(&fscache_n_updates),
46337 + atomic_read_unchecked(&fscache_n_updates_null),
46338 + atomic_read_unchecked(&fscache_n_updates_run));
46339
46340 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46341 - atomic_read(&fscache_n_relinquishes),
46342 - atomic_read(&fscache_n_relinquishes_null),
46343 - atomic_read(&fscache_n_relinquishes_waitcrt),
46344 - atomic_read(&fscache_n_relinquishes_retire));
46345 + atomic_read_unchecked(&fscache_n_relinquishes),
46346 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46347 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46348 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46349
46350 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46351 - atomic_read(&fscache_n_attr_changed),
46352 - atomic_read(&fscache_n_attr_changed_ok),
46353 - atomic_read(&fscache_n_attr_changed_nobufs),
46354 - atomic_read(&fscache_n_attr_changed_nomem),
46355 - atomic_read(&fscache_n_attr_changed_calls));
46356 + atomic_read_unchecked(&fscache_n_attr_changed),
46357 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46358 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46359 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46360 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46361
46362 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46363 - atomic_read(&fscache_n_allocs),
46364 - atomic_read(&fscache_n_allocs_ok),
46365 - atomic_read(&fscache_n_allocs_wait),
46366 - atomic_read(&fscache_n_allocs_nobufs),
46367 - atomic_read(&fscache_n_allocs_intr));
46368 + atomic_read_unchecked(&fscache_n_allocs),
46369 + atomic_read_unchecked(&fscache_n_allocs_ok),
46370 + atomic_read_unchecked(&fscache_n_allocs_wait),
46371 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46372 + atomic_read_unchecked(&fscache_n_allocs_intr));
46373 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46374 - atomic_read(&fscache_n_alloc_ops),
46375 - atomic_read(&fscache_n_alloc_op_waits),
46376 - atomic_read(&fscache_n_allocs_object_dead));
46377 + atomic_read_unchecked(&fscache_n_alloc_ops),
46378 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46379 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46380
46381 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46382 " int=%u oom=%u\n",
46383 - atomic_read(&fscache_n_retrievals),
46384 - atomic_read(&fscache_n_retrievals_ok),
46385 - atomic_read(&fscache_n_retrievals_wait),
46386 - atomic_read(&fscache_n_retrievals_nodata),
46387 - atomic_read(&fscache_n_retrievals_nobufs),
46388 - atomic_read(&fscache_n_retrievals_intr),
46389 - atomic_read(&fscache_n_retrievals_nomem));
46390 + atomic_read_unchecked(&fscache_n_retrievals),
46391 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46392 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46393 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46394 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46395 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46396 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46397 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46398 - atomic_read(&fscache_n_retrieval_ops),
46399 - atomic_read(&fscache_n_retrieval_op_waits),
46400 - atomic_read(&fscache_n_retrievals_object_dead));
46401 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46402 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46403 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46404
46405 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46406 - atomic_read(&fscache_n_stores),
46407 - atomic_read(&fscache_n_stores_ok),
46408 - atomic_read(&fscache_n_stores_again),
46409 - atomic_read(&fscache_n_stores_nobufs),
46410 - atomic_read(&fscache_n_stores_oom));
46411 + atomic_read_unchecked(&fscache_n_stores),
46412 + atomic_read_unchecked(&fscache_n_stores_ok),
46413 + atomic_read_unchecked(&fscache_n_stores_again),
46414 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46415 + atomic_read_unchecked(&fscache_n_stores_oom));
46416 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46417 - atomic_read(&fscache_n_store_ops),
46418 - atomic_read(&fscache_n_store_calls),
46419 - atomic_read(&fscache_n_store_pages),
46420 - atomic_read(&fscache_n_store_radix_deletes),
46421 - atomic_read(&fscache_n_store_pages_over_limit));
46422 + atomic_read_unchecked(&fscache_n_store_ops),
46423 + atomic_read_unchecked(&fscache_n_store_calls),
46424 + atomic_read_unchecked(&fscache_n_store_pages),
46425 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46426 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46427
46428 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46429 - atomic_read(&fscache_n_store_vmscan_not_storing),
46430 - atomic_read(&fscache_n_store_vmscan_gone),
46431 - atomic_read(&fscache_n_store_vmscan_busy),
46432 - atomic_read(&fscache_n_store_vmscan_cancelled));
46433 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46434 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46435 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46436 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46437
46438 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46439 - atomic_read(&fscache_n_op_pend),
46440 - atomic_read(&fscache_n_op_run),
46441 - atomic_read(&fscache_n_op_enqueue),
46442 - atomic_read(&fscache_n_op_cancelled),
46443 - atomic_read(&fscache_n_op_rejected));
46444 + atomic_read_unchecked(&fscache_n_op_pend),
46445 + atomic_read_unchecked(&fscache_n_op_run),
46446 + atomic_read_unchecked(&fscache_n_op_enqueue),
46447 + atomic_read_unchecked(&fscache_n_op_cancelled),
46448 + atomic_read_unchecked(&fscache_n_op_rejected));
46449 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46450 - atomic_read(&fscache_n_op_deferred_release),
46451 - atomic_read(&fscache_n_op_release),
46452 - atomic_read(&fscache_n_op_gc));
46453 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46454 + atomic_read_unchecked(&fscache_n_op_release),
46455 + atomic_read_unchecked(&fscache_n_op_gc));
46456
46457 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46458 atomic_read(&fscache_n_cop_alloc_object),
46459 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46460 index b6cca47..ec782c3 100644
46461 --- a/fs/fuse/cuse.c
46462 +++ b/fs/fuse/cuse.c
46463 @@ -586,10 +586,12 @@ static int __init cuse_init(void)
46464 INIT_LIST_HEAD(&cuse_conntbl[i]);
46465
46466 /* inherit and extend fuse_dev_operations */
46467 - cuse_channel_fops = fuse_dev_operations;
46468 - cuse_channel_fops.owner = THIS_MODULE;
46469 - cuse_channel_fops.open = cuse_channel_open;
46470 - cuse_channel_fops.release = cuse_channel_release;
46471 + pax_open_kernel();
46472 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46473 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46474 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46475 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46476 + pax_close_kernel();
46477
46478 cuse_class = class_create(THIS_MODULE, "cuse");
46479 if (IS_ERR(cuse_class))
46480 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46481 index 2aaf3ea..8e50863 100644
46482 --- a/fs/fuse/dev.c
46483 +++ b/fs/fuse/dev.c
46484 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46485 ret = 0;
46486 pipe_lock(pipe);
46487
46488 - if (!pipe->readers) {
46489 + if (!atomic_read(&pipe->readers)) {
46490 send_sig(SIGPIPE, current, 0);
46491 if (!ret)
46492 ret = -EPIPE;
46493 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46494 index 9f63e49..d8a64c0 100644
46495 --- a/fs/fuse/dir.c
46496 +++ b/fs/fuse/dir.c
46497 @@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *dentry)
46498 return link;
46499 }
46500
46501 -static void free_link(char *link)
46502 +static void free_link(const char *link)
46503 {
46504 if (!IS_ERR(link))
46505 free_page((unsigned long) link);
46506 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46507 index 900cf98..3896726 100644
46508 --- a/fs/gfs2/inode.c
46509 +++ b/fs/gfs2/inode.c
46510 @@ -1517,7 +1517,7 @@ out:
46511
46512 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46513 {
46514 - char *s = nd_get_link(nd);
46515 + const char *s = nd_get_link(nd);
46516 if (!IS_ERR(s))
46517 kfree(s);
46518 }
46519 diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
46520 index 4dfbfec..947c9c2 100644
46521 --- a/fs/hfsplus/catalog.c
46522 +++ b/fs/hfsplus/catalog.c
46523 @@ -179,6 +179,8 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid,
46524 int err;
46525 u16 type;
46526
46527 + pax_track_stack();
46528 +
46529 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
46530 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
46531 if (err)
46532 @@ -210,6 +212,8 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,
46533 int entry_size;
46534 int err;
46535
46536 + pax_track_stack();
46537 +
46538 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n",
46539 str->name, cnid, inode->i_nlink);
46540 err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
46541 @@ -353,6 +357,8 @@ int hfsplus_rename_cat(u32 cnid,
46542 int entry_size, type;
46543 int err;
46544
46545 + pax_track_stack();
46546 +
46547 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n",
46548 cnid, src_dir->i_ino, src_name->name,
46549 dst_dir->i_ino, dst_name->name);
46550 diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
46551 index 25b2443..09a3341 100644
46552 --- a/fs/hfsplus/dir.c
46553 +++ b/fs/hfsplus/dir.c
46554 @@ -131,6 +131,8 @@ static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir)
46555 struct hfsplus_readdir_data *rd;
46556 u16 type;
46557
46558 + pax_track_stack();
46559 +
46560 if (filp->f_pos >= inode->i_size)
46561 return 0;
46562
46563 diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
46564 index 4cc1e3a..ad0f70b 100644
46565 --- a/fs/hfsplus/inode.c
46566 +++ b/fs/hfsplus/inode.c
46567 @@ -501,6 +501,8 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
46568 int res = 0;
46569 u16 type;
46570
46571 + pax_track_stack();
46572 +
46573 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
46574
46575 HFSPLUS_I(inode)->linkid = 0;
46576 @@ -564,6 +566,8 @@ int hfsplus_cat_write_inode(struct inode *inode)
46577 struct hfs_find_data fd;
46578 hfsplus_cat_entry entry;
46579
46580 + pax_track_stack();
46581 +
46582 if (HFSPLUS_IS_RSRC(inode))
46583 main_inode = HFSPLUS_I(inode)->rsrc_inode;
46584
46585 diff --git a/fs/hfsplus/ioctl.c b/fs/hfsplus/ioctl.c
46586 index fbaa669..c548cd0 100644
46587 --- a/fs/hfsplus/ioctl.c
46588 +++ b/fs/hfsplus/ioctl.c
46589 @@ -122,6 +122,8 @@ int hfsplus_setxattr(struct dentry *dentry, const char *name,
46590 struct hfsplus_cat_file *file;
46591 int res;
46592
46593 + pax_track_stack();
46594 +
46595 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
46596 return -EOPNOTSUPP;
46597
46598 @@ -166,6 +168,8 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
46599 struct hfsplus_cat_file *file;
46600 ssize_t res = 0;
46601
46602 + pax_track_stack();
46603 +
46604 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
46605 return -EOPNOTSUPP;
46606
46607 diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
46608 index d24a9b6..dd9b3dd 100644
46609 --- a/fs/hfsplus/super.c
46610 +++ b/fs/hfsplus/super.c
46611 @@ -347,6 +347,8 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
46612 u64 last_fs_block, last_fs_page;
46613 int err;
46614
46615 + pax_track_stack();
46616 +
46617 err = -EINVAL;
46618 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
46619 if (!sbi)
46620 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46621 index ec88953..cb5e98e 100644
46622 --- a/fs/hugetlbfs/inode.c
46623 +++ b/fs/hugetlbfs/inode.c
46624 @@ -915,7 +915,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46625 .kill_sb = kill_litter_super,
46626 };
46627
46628 -static struct vfsmount *hugetlbfs_vfsmount;
46629 +struct vfsmount *hugetlbfs_vfsmount;
46630
46631 static int can_do_hugetlb_shm(void)
46632 {
46633 diff --git a/fs/inode.c b/fs/inode.c
46634 index ec79246..054c36a 100644
46635 --- a/fs/inode.c
46636 +++ b/fs/inode.c
46637 @@ -787,8 +787,8 @@ unsigned int get_next_ino(void)
46638
46639 #ifdef CONFIG_SMP
46640 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46641 - static atomic_t shared_last_ino;
46642 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46643 + static atomic_unchecked_t shared_last_ino;
46644 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46645
46646 res = next - LAST_INO_BATCH;
46647 }
46648 diff --git a/fs/jbd/checkpoint.c b/fs/jbd/checkpoint.c
46649 index f94fc48..3bb8d30 100644
46650 --- a/fs/jbd/checkpoint.c
46651 +++ b/fs/jbd/checkpoint.c
46652 @@ -358,6 +358,8 @@ int log_do_checkpoint(journal_t *journal)
46653 tid_t this_tid;
46654 int result;
46655
46656 + pax_track_stack();
46657 +
46658 jbd_debug(1, "Start checkpoint\n");
46659
46660 /*
46661 diff --git a/fs/jffs2/compr_rtime.c b/fs/jffs2/compr_rtime.c
46662 index 16a5047..88ff6ca 100644
46663 --- a/fs/jffs2/compr_rtime.c
46664 +++ b/fs/jffs2/compr_rtime.c
46665 @@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned char *data_in,
46666 int outpos = 0;
46667 int pos=0;
46668
46669 + pax_track_stack();
46670 +
46671 memset(positions,0,sizeof(positions));
46672
46673 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
46674 @@ -78,6 +80,8 @@ static int jffs2_rtime_decompress(unsigned char *data_in,
46675 int outpos = 0;
46676 int pos=0;
46677
46678 + pax_track_stack();
46679 +
46680 memset(positions,0,sizeof(positions));
46681
46682 while (outpos<destlen) {
46683 diff --git a/fs/jffs2/compr_rubin.c b/fs/jffs2/compr_rubin.c
46684 index 9e7cec8..4713089 100644
46685 --- a/fs/jffs2/compr_rubin.c
46686 +++ b/fs/jffs2/compr_rubin.c
46687 @@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsigned char *data_in,
46688 int ret;
46689 uint32_t mysrclen, mydstlen;
46690
46691 + pax_track_stack();
46692 +
46693 mysrclen = *sourcelen;
46694 mydstlen = *dstlen - 8;
46695
46696 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46697 index e513f19..2ab1351 100644
46698 --- a/fs/jffs2/erase.c
46699 +++ b/fs/jffs2/erase.c
46700 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46701 struct jffs2_unknown_node marker = {
46702 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46703 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46704 - .totlen = cpu_to_je32(c->cleanmarker_size)
46705 + .totlen = cpu_to_je32(c->cleanmarker_size),
46706 + .hdr_crc = cpu_to_je32(0)
46707 };
46708
46709 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46710 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46711 index 4515bea..178f2d6 100644
46712 --- a/fs/jffs2/wbuf.c
46713 +++ b/fs/jffs2/wbuf.c
46714 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46715 {
46716 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46717 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46718 - .totlen = constant_cpu_to_je32(8)
46719 + .totlen = constant_cpu_to_je32(8),
46720 + .hdr_crc = constant_cpu_to_je32(0)
46721 };
46722
46723 /*
46724 diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
46725 index 3e93cdd..c8a80e1 100644
46726 --- a/fs/jffs2/xattr.c
46727 +++ b/fs/jffs2/xattr.c
46728 @@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
46729
46730 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
46731
46732 + pax_track_stack();
46733 +
46734 /* Phase.1 : Merge same xref */
46735 for (i=0; i < XREF_TMPHASH_SIZE; i++)
46736 xref_tmphash[i] = NULL;
46737 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46738 index 06c8a67..589dbbd 100644
46739 --- a/fs/jfs/super.c
46740 +++ b/fs/jfs/super.c
46741 @@ -803,7 +803,7 @@ static int __init init_jfs_fs(void)
46742
46743 jfs_inode_cachep =
46744 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46745 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46746 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46747 init_once);
46748 if (jfs_inode_cachep == NULL)
46749 return -ENOMEM;
46750 diff --git a/fs/libfs.c b/fs/libfs.c
46751 index c18e9a1..0b04e2c 100644
46752 --- a/fs/libfs.c
46753 +++ b/fs/libfs.c
46754 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46755
46756 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46757 struct dentry *next;
46758 + char d_name[sizeof(next->d_iname)];
46759 + const unsigned char *name;
46760 +
46761 next = list_entry(p, struct dentry, d_u.d_child);
46762 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46763 if (!simple_positive(next)) {
46764 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46765
46766 spin_unlock(&next->d_lock);
46767 spin_unlock(&dentry->d_lock);
46768 - if (filldir(dirent, next->d_name.name,
46769 + name = next->d_name.name;
46770 + if (name == next->d_iname) {
46771 + memcpy(d_name, name, next->d_name.len);
46772 + name = d_name;
46773 + }
46774 + if (filldir(dirent, name,
46775 next->d_name.len, filp->f_pos,
46776 next->d_inode->i_ino,
46777 dt_type(next->d_inode)) < 0)
46778 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46779 index 8392cb8..ae8ed40 100644
46780 --- a/fs/lockd/clntproc.c
46781 +++ b/fs/lockd/clntproc.c
46782 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46783 /*
46784 * Cookie counter for NLM requests
46785 */
46786 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46787 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46788
46789 void nlmclnt_next_cookie(struct nlm_cookie *c)
46790 {
46791 - u32 cookie = atomic_inc_return(&nlm_cookie);
46792 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46793
46794 memcpy(c->data, &cookie, 4);
46795 c->len=4;
46796 @@ -621,6 +621,8 @@ nlmclnt_reclaim(struct nlm_host *host, struct file_lock *fl)
46797 struct nlm_rqst reqst, *req;
46798 int status;
46799
46800 + pax_track_stack();
46801 +
46802 req = &reqst;
46803 memset(req, 0, sizeof(*req));
46804 locks_init_lock(&req->a_args.lock.fl);
46805 diff --git a/fs/locks.c b/fs/locks.c
46806 index 703f545..150a552 100644
46807 --- a/fs/locks.c
46808 +++ b/fs/locks.c
46809 @@ -2022,16 +2022,16 @@ void locks_remove_flock(struct file *filp)
46810 return;
46811
46812 if (filp->f_op && filp->f_op->flock) {
46813 - struct file_lock fl = {
46814 + struct file_lock flock = {
46815 .fl_pid = current->tgid,
46816 .fl_file = filp,
46817 .fl_flags = FL_FLOCK,
46818 .fl_type = F_UNLCK,
46819 .fl_end = OFFSET_MAX,
46820 };
46821 - filp->f_op->flock(filp, F_SETLKW, &fl);
46822 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46823 - fl.fl_ops->fl_release_private(&fl);
46824 + filp->f_op->flock(filp, F_SETLKW, &flock);
46825 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46826 + flock.fl_ops->fl_release_private(&flock);
46827 }
46828
46829 lock_flocks();
46830 diff --git a/fs/logfs/super.c b/fs/logfs/super.c
46831 index ce03a18..ac8c14f 100644
46832 --- a/fs/logfs/super.c
46833 +++ b/fs/logfs/super.c
46834 @@ -266,6 +266,8 @@ static int logfs_recover_sb(struct super_block *sb)
46835 struct logfs_disk_super _ds1, *ds1 = &_ds1;
46836 int err, valid0, valid1;
46837
46838 + pax_track_stack();
46839 +
46840 /* read first superblock */
46841 err = wbuf_read(sb, super->s_sb_ofs[0], sizeof(*ds0), ds0);
46842 if (err)
46843 diff --git a/fs/minix/bitmap.c b/fs/minix/bitmap.c
46844 index 3f32bcb..7c82c29 100644
46845 --- a/fs/minix/bitmap.c
46846 +++ b/fs/minix/bitmap.c
46847 @@ -20,10 +20,11 @@ static const int nibblemap[] = { 4,3,3,2,3,2,2,1,3,2,2,1,2,1,1,0 };
46848
46849 static DEFINE_SPINLOCK(bitmap_lock);
46850
46851 -static unsigned long count_free(struct buffer_head *map[], unsigned numblocks, __u32 numbits)
46852 +static unsigned long count_free(struct buffer_head *map[], unsigned blocksize, __u32 numbits)
46853 {
46854 unsigned i, j, sum = 0;
46855 struct buffer_head *bh;
46856 + unsigned numblocks = minix_blocks_needed(numbits, blocksize);
46857
46858 for (i=0; i<numblocks-1; i++) {
46859 if (!(bh=map[i]))
46860 @@ -105,10 +106,12 @@ int minix_new_block(struct inode * inode)
46861 return 0;
46862 }
46863
46864 -unsigned long minix_count_free_blocks(struct minix_sb_info *sbi)
46865 +unsigned long minix_count_free_blocks(struct super_block *sb)
46866 {
46867 - return (count_free(sbi->s_zmap, sbi->s_zmap_blocks,
46868 - sbi->s_nzones - sbi->s_firstdatazone + 1)
46869 + struct minix_sb_info *sbi = minix_sb(sb);
46870 + u32 bits = sbi->s_nzones - (sbi->s_firstdatazone + 1);
46871 +
46872 + return (count_free(sbi->s_zmap, sb->s_blocksize, bits)
46873 << sbi->s_log_zone_size);
46874 }
46875
46876 @@ -273,7 +276,10 @@ struct inode *minix_new_inode(const struct inode *dir, int mode, int *error)
46877 return inode;
46878 }
46879
46880 -unsigned long minix_count_free_inodes(struct minix_sb_info *sbi)
46881 +unsigned long minix_count_free_inodes(struct super_block *sb)
46882 {
46883 - return count_free(sbi->s_imap, sbi->s_imap_blocks, sbi->s_ninodes + 1);
46884 + struct minix_sb_info *sbi = minix_sb(sb);
46885 + u32 bits = sbi->s_ninodes + 1;
46886 +
46887 + return count_free(sbi->s_imap, sb->s_blocksize, bits);
46888 }
46889 diff --git a/fs/minix/inode.c b/fs/minix/inode.c
46890 index e7d23e2..1ed1351 100644
46891 --- a/fs/minix/inode.c
46892 +++ b/fs/minix/inode.c
46893 @@ -279,6 +279,27 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
46894 else if (sbi->s_mount_state & MINIX_ERROR_FS)
46895 printk("MINIX-fs: mounting file system with errors, "
46896 "running fsck is recommended\n");
46897 +
46898 + /* Apparently minix can create filesystems that allocate more blocks for
46899 + * the bitmaps than needed. We simply ignore that, but verify it didn't
46900 + * create one with not enough blocks and bail out if so.
46901 + */
46902 + block = minix_blocks_needed(sbi->s_ninodes, s->s_blocksize);
46903 + if (sbi->s_imap_blocks < block) {
46904 + printk("MINIX-fs: file system does not have enough "
46905 + "imap blocks allocated. Refusing to mount\n");
46906 + goto out_iput;
46907 + }
46908 +
46909 + block = minix_blocks_needed(
46910 + (sbi->s_nzones - (sbi->s_firstdatazone + 1)),
46911 + s->s_blocksize);
46912 + if (sbi->s_zmap_blocks < block) {
46913 + printk("MINIX-fs: file system does not have enough "
46914 + "zmap blocks allocated. Refusing to mount.\n");
46915 + goto out_iput;
46916 + }
46917 +
46918 return 0;
46919
46920 out_iput:
46921 @@ -339,10 +360,10 @@ static int minix_statfs(struct dentry *dentry, struct kstatfs *buf)
46922 buf->f_type = sb->s_magic;
46923 buf->f_bsize = sb->s_blocksize;
46924 buf->f_blocks = (sbi->s_nzones - sbi->s_firstdatazone) << sbi->s_log_zone_size;
46925 - buf->f_bfree = minix_count_free_blocks(sbi);
46926 + buf->f_bfree = minix_count_free_blocks(sb);
46927 buf->f_bavail = buf->f_bfree;
46928 buf->f_files = sbi->s_ninodes;
46929 - buf->f_ffree = minix_count_free_inodes(sbi);
46930 + buf->f_ffree = minix_count_free_inodes(sb);
46931 buf->f_namelen = sbi->s_namelen;
46932 buf->f_fsid.val[0] = (u32)id;
46933 buf->f_fsid.val[1] = (u32)(id >> 32);
46934 diff --git a/fs/minix/minix.h b/fs/minix/minix.h
46935 index 341e212..6415fe0 100644
46936 --- a/fs/minix/minix.h
46937 +++ b/fs/minix/minix.h
46938 @@ -48,10 +48,10 @@ extern struct minix_inode * minix_V1_raw_inode(struct super_block *, ino_t, stru
46939 extern struct minix2_inode * minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **);
46940 extern struct inode * minix_new_inode(const struct inode *, int, int *);
46941 extern void minix_free_inode(struct inode * inode);
46942 -extern unsigned long minix_count_free_inodes(struct minix_sb_info *sbi);
46943 +extern unsigned long minix_count_free_inodes(struct super_block *sb);
46944 extern int minix_new_block(struct inode * inode);
46945 extern void minix_free_block(struct inode *inode, unsigned long block);
46946 -extern unsigned long minix_count_free_blocks(struct minix_sb_info *sbi);
46947 +extern unsigned long minix_count_free_blocks(struct super_block *sb);
46948 extern int minix_getattr(struct vfsmount *, struct dentry *, struct kstat *);
46949 extern int minix_prepare_chunk(struct page *page, loff_t pos, unsigned len);
46950
46951 @@ -88,6 +88,11 @@ static inline struct minix_inode_info *minix_i(struct inode *inode)
46952 return list_entry(inode, struct minix_inode_info, vfs_inode);
46953 }
46954
46955 +static inline unsigned minix_blocks_needed(unsigned bits, unsigned blocksize)
46956 +{
46957 + return DIV_ROUND_UP(bits, blocksize * 8);
46958 +}
46959 +
46960 #if defined(CONFIG_MINIX_FS_NATIVE_ENDIAN) && \
46961 defined(CONFIG_MINIX_FS_BIG_ENDIAN_16BIT_INDEXED)
46962
46963 diff --git a/fs/namei.c b/fs/namei.c
46964 index 3d15072..c1ddf9c 100644
46965 --- a/fs/namei.c
46966 +++ b/fs/namei.c
46967 @@ -281,16 +281,32 @@ int generic_permission(struct inode *inode, int mask)
46968 if (ret != -EACCES)
46969 return ret;
46970
46971 +#ifdef CONFIG_GRKERNSEC
46972 + /* we'll block if we have to log due to a denied capability use */
46973 + if (mask & MAY_NOT_BLOCK)
46974 + return -ECHILD;
46975 +#endif
46976 +
46977 if (S_ISDIR(inode->i_mode)) {
46978 /* DACs are overridable for directories */
46979 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46980 - return 0;
46981 if (!(mask & MAY_WRITE))
46982 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46983 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46984 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46985 return 0;
46986 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46987 + return 0;
46988 return -EACCES;
46989 }
46990 /*
46991 + * Searching includes executable on directories, else just read.
46992 + */
46993 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46994 + if (mask == MAY_READ)
46995 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46996 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46997 + return 0;
46998 +
46999 + /*
47000 * Read/write DACs are always overridable.
47001 * Executable DACs are overridable when there is
47002 * at least one exec bit set.
47003 @@ -299,14 +315,6 @@ int generic_permission(struct inode *inode, int mask)
47004 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
47005 return 0;
47006
47007 - /*
47008 - * Searching includes executable on directories, else just read.
47009 - */
47010 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47011 - if (mask == MAY_READ)
47012 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
47013 - return 0;
47014 -
47015 return -EACCES;
47016 }
47017
47018 @@ -653,11 +661,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47019 return error;
47020 }
47021
47022 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47023 + dentry->d_inode, dentry, nd->path.mnt)) {
47024 + error = -EACCES;
47025 + *p = ERR_PTR(error); /* no ->put_link(), please */
47026 + path_put(&nd->path);
47027 + return error;
47028 + }
47029 +
47030 nd->last_type = LAST_BIND;
47031 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47032 error = PTR_ERR(*p);
47033 if (!IS_ERR(*p)) {
47034 - char *s = nd_get_link(nd);
47035 + const char *s = nd_get_link(nd);
47036 error = 0;
47037 if (s)
47038 error = __vfs_follow_link(nd, s);
47039 @@ -1622,6 +1638,21 @@ static int path_lookupat(int dfd, const char *name,
47040 if (!err)
47041 err = complete_walk(nd);
47042
47043 + if (!(nd->flags & LOOKUP_PARENT)) {
47044 +#ifdef CONFIG_GRKERNSEC
47045 + if (flags & LOOKUP_RCU) {
47046 + if (!err)
47047 + path_put(&nd->path);
47048 + err = -ECHILD;
47049 + } else
47050 +#endif
47051 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47052 + if (!err)
47053 + path_put(&nd->path);
47054 + err = -ENOENT;
47055 + }
47056 + }
47057 +
47058 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47059 if (!nd->inode->i_op->lookup) {
47060 path_put(&nd->path);
47061 @@ -1649,6 +1680,15 @@ static int do_path_lookup(int dfd, const char *name,
47062 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47063
47064 if (likely(!retval)) {
47065 + if (*name != '/' && nd->path.dentry && nd->inode) {
47066 +#ifdef CONFIG_GRKERNSEC
47067 + if (flags & LOOKUP_RCU)
47068 + return -ECHILD;
47069 +#endif
47070 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47071 + return -ENOENT;
47072 + }
47073 +
47074 if (unlikely(!audit_dummy_context())) {
47075 if (nd->path.dentry && nd->inode)
47076 audit_inode(name, nd->path.dentry);
47077 @@ -2049,7 +2089,27 @@ static int may_open(struct path *path, int acc_mode, int flag)
47078 /*
47079 * Ensure there are no outstanding leases on the file.
47080 */
47081 - return break_lease(inode, flag);
47082 + error = break_lease(inode, flag);
47083 +
47084 + if (error)
47085 + return error;
47086 +
47087 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
47088 + error = -EPERM;
47089 + goto exit;
47090 + }
47091 +
47092 + if (gr_handle_rawio(inode)) {
47093 + error = -EPERM;
47094 + goto exit;
47095 + }
47096 +
47097 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode)) {
47098 + error = -EACCES;
47099 + goto exit;
47100 + }
47101 +exit:
47102 + return error;
47103 }
47104
47105 static int handle_truncate(struct file *filp)
47106 @@ -2110,6 +2170,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47107 error = complete_walk(nd);
47108 if (error)
47109 return ERR_PTR(error);
47110 +#ifdef CONFIG_GRKERNSEC
47111 + if (nd->flags & LOOKUP_RCU) {
47112 + error = -ECHILD;
47113 + goto exit;
47114 + }
47115 +#endif
47116 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47117 + error = -ENOENT;
47118 + goto exit;
47119 + }
47120 audit_inode(pathname, nd->path.dentry);
47121 if (open_flag & O_CREAT) {
47122 error = -EISDIR;
47123 @@ -2120,6 +2190,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47124 error = complete_walk(nd);
47125 if (error)
47126 return ERR_PTR(error);
47127 +#ifdef CONFIG_GRKERNSEC
47128 + if (nd->flags & LOOKUP_RCU) {
47129 + error = -ECHILD;
47130 + goto exit;
47131 + }
47132 +#endif
47133 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47134 + error = -ENOENT;
47135 + goto exit;
47136 + }
47137 audit_inode(pathname, dir);
47138 goto ok;
47139 }
47140 @@ -2141,6 +2221,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47141 error = complete_walk(nd);
47142 if (error)
47143 return ERR_PTR(-ECHILD);
47144 +#ifdef CONFIG_GRKERNSEC
47145 + if (nd->flags & LOOKUP_RCU) {
47146 + error = -ECHILD;
47147 + goto exit;
47148 + }
47149 +#endif
47150 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47151 + error = -ENOENT;
47152 + goto exit;
47153 + }
47154
47155 error = -ENOTDIR;
47156 if (nd->flags & LOOKUP_DIRECTORY) {
47157 @@ -2181,6 +2271,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47158 /* Negative dentry, just create the file */
47159 if (!dentry->d_inode) {
47160 int mode = op->mode;
47161 +
47162 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47163 + error = -EACCES;
47164 + goto exit_mutex_unlock;
47165 + }
47166 +
47167 if (!IS_POSIXACL(dir->d_inode))
47168 mode &= ~current_umask();
47169 /*
47170 @@ -2204,6 +2300,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47171 error = vfs_create(dir->d_inode, dentry, mode, nd);
47172 if (error)
47173 goto exit_mutex_unlock;
47174 + else
47175 + gr_handle_create(path->dentry, path->mnt);
47176 mutex_unlock(&dir->d_inode->i_mutex);
47177 dput(nd->path.dentry);
47178 nd->path.dentry = dentry;
47179 @@ -2213,6 +2311,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47180 /*
47181 * It already exists.
47182 */
47183 +
47184 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47185 + error = -ENOENT;
47186 + goto exit_mutex_unlock;
47187 + }
47188 +
47189 + /* only check if O_CREAT is specified, all other checks need to go
47190 + into may_open */
47191 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47192 + error = -EACCES;
47193 + goto exit_mutex_unlock;
47194 + }
47195 +
47196 mutex_unlock(&dir->d_inode->i_mutex);
47197 audit_inode(pathname, path->dentry);
47198
47199 @@ -2425,6 +2536,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47200 *path = nd.path;
47201 return dentry;
47202 eexist:
47203 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47204 + dput(dentry);
47205 + dentry = ERR_PTR(-ENOENT);
47206 + goto fail;
47207 + }
47208 dput(dentry);
47209 dentry = ERR_PTR(-EEXIST);
47210 fail:
47211 @@ -2447,6 +2563,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47212 }
47213 EXPORT_SYMBOL(user_path_create);
47214
47215 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47216 +{
47217 + char *tmp = getname(pathname);
47218 + struct dentry *res;
47219 + if (IS_ERR(tmp))
47220 + return ERR_CAST(tmp);
47221 + res = kern_path_create(dfd, tmp, path, is_dir);
47222 + if (IS_ERR(res))
47223 + putname(tmp);
47224 + else
47225 + *to = tmp;
47226 + return res;
47227 +}
47228 +
47229 int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
47230 {
47231 int error = may_create(dir, dentry);
47232 @@ -2514,6 +2644,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
47233 error = mnt_want_write(path.mnt);
47234 if (error)
47235 goto out_dput;
47236 +
47237 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47238 + error = -EPERM;
47239 + goto out_drop_write;
47240 + }
47241 +
47242 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47243 + error = -EACCES;
47244 + goto out_drop_write;
47245 + }
47246 +
47247 error = security_path_mknod(&path, dentry, mode, dev);
47248 if (error)
47249 goto out_drop_write;
47250 @@ -2531,6 +2672,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
47251 }
47252 out_drop_write:
47253 mnt_drop_write(path.mnt);
47254 +
47255 + if (!error)
47256 + gr_handle_create(dentry, path.mnt);
47257 out_dput:
47258 dput(dentry);
47259 mutex_unlock(&path.dentry->d_inode->i_mutex);
47260 @@ -2580,12 +2724,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
47261 error = mnt_want_write(path.mnt);
47262 if (error)
47263 goto out_dput;
47264 +
47265 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47266 + error = -EACCES;
47267 + goto out_drop_write;
47268 + }
47269 +
47270 error = security_path_mkdir(&path, dentry, mode);
47271 if (error)
47272 goto out_drop_write;
47273 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47274 out_drop_write:
47275 mnt_drop_write(path.mnt);
47276 +
47277 + if (!error)
47278 + gr_handle_create(dentry, path.mnt);
47279 out_dput:
47280 dput(dentry);
47281 mutex_unlock(&path.dentry->d_inode->i_mutex);
47282 @@ -2665,6 +2818,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47283 char * name;
47284 struct dentry *dentry;
47285 struct nameidata nd;
47286 + ino_t saved_ino = 0;
47287 + dev_t saved_dev = 0;
47288
47289 error = user_path_parent(dfd, pathname, &nd, &name);
47290 if (error)
47291 @@ -2693,6 +2848,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47292 error = -ENOENT;
47293 goto exit3;
47294 }
47295 +
47296 + saved_ino = dentry->d_inode->i_ino;
47297 + saved_dev = gr_get_dev_from_dentry(dentry);
47298 +
47299 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47300 + error = -EACCES;
47301 + goto exit3;
47302 + }
47303 +
47304 error = mnt_want_write(nd.path.mnt);
47305 if (error)
47306 goto exit3;
47307 @@ -2700,6 +2864,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47308 if (error)
47309 goto exit4;
47310 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47311 + if (!error && (saved_dev || saved_ino))
47312 + gr_handle_delete(saved_ino, saved_dev);
47313 exit4:
47314 mnt_drop_write(nd.path.mnt);
47315 exit3:
47316 @@ -2762,6 +2928,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47317 struct dentry *dentry;
47318 struct nameidata nd;
47319 struct inode *inode = NULL;
47320 + ino_t saved_ino = 0;
47321 + dev_t saved_dev = 0;
47322
47323 error = user_path_parent(dfd, pathname, &nd, &name);
47324 if (error)
47325 @@ -2784,6 +2952,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47326 if (!inode)
47327 goto slashes;
47328 ihold(inode);
47329 +
47330 + if (inode->i_nlink <= 1) {
47331 + saved_ino = inode->i_ino;
47332 + saved_dev = gr_get_dev_from_dentry(dentry);
47333 + }
47334 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47335 + error = -EACCES;
47336 + goto exit2;
47337 + }
47338 +
47339 error = mnt_want_write(nd.path.mnt);
47340 if (error)
47341 goto exit2;
47342 @@ -2791,6 +2969,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47343 if (error)
47344 goto exit3;
47345 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47346 + if (!error && (saved_ino || saved_dev))
47347 + gr_handle_delete(saved_ino, saved_dev);
47348 exit3:
47349 mnt_drop_write(nd.path.mnt);
47350 exit2:
47351 @@ -2866,10 +3046,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47352 error = mnt_want_write(path.mnt);
47353 if (error)
47354 goto out_dput;
47355 +
47356 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47357 + error = -EACCES;
47358 + goto out_drop_write;
47359 + }
47360 +
47361 error = security_path_symlink(&path, dentry, from);
47362 if (error)
47363 goto out_drop_write;
47364 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47365 + if (!error)
47366 + gr_handle_create(dentry, path.mnt);
47367 out_drop_write:
47368 mnt_drop_write(path.mnt);
47369 out_dput:
47370 @@ -2941,6 +3129,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47371 {
47372 struct dentry *new_dentry;
47373 struct path old_path, new_path;
47374 + char *to = NULL;
47375 int how = 0;
47376 int error;
47377
47378 @@ -2964,7 +3153,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47379 if (error)
47380 return error;
47381
47382 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47383 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47384 error = PTR_ERR(new_dentry);
47385 if (IS_ERR(new_dentry))
47386 goto out;
47387 @@ -2975,13 +3164,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47388 error = mnt_want_write(new_path.mnt);
47389 if (error)
47390 goto out_dput;
47391 +
47392 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47393 + old_path.dentry->d_inode,
47394 + old_path.dentry->d_inode->i_mode, to)) {
47395 + error = -EACCES;
47396 + goto out_drop_write;
47397 + }
47398 +
47399 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47400 + old_path.dentry, old_path.mnt, to)) {
47401 + error = -EACCES;
47402 + goto out_drop_write;
47403 + }
47404 +
47405 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47406 if (error)
47407 goto out_drop_write;
47408 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47409 + if (!error)
47410 + gr_handle_create(new_dentry, new_path.mnt);
47411 out_drop_write:
47412 mnt_drop_write(new_path.mnt);
47413 out_dput:
47414 + putname(to);
47415 dput(new_dentry);
47416 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47417 path_put(&new_path);
47418 @@ -3153,6 +3359,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47419 char *to;
47420 int error;
47421
47422 + pax_track_stack();
47423 +
47424 error = user_path_parent(olddfd, oldname, &oldnd, &from);
47425 if (error)
47426 goto exit;
47427 @@ -3209,6 +3417,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47428 if (new_dentry == trap)
47429 goto exit5;
47430
47431 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47432 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47433 + to);
47434 + if (error)
47435 + goto exit5;
47436 +
47437 error = mnt_want_write(oldnd.path.mnt);
47438 if (error)
47439 goto exit5;
47440 @@ -3218,6 +3432,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47441 goto exit6;
47442 error = vfs_rename(old_dir->d_inode, old_dentry,
47443 new_dir->d_inode, new_dentry);
47444 + if (!error)
47445 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47446 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47447 exit6:
47448 mnt_drop_write(oldnd.path.mnt);
47449 exit5:
47450 @@ -3243,6 +3460,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47451
47452 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47453 {
47454 + char tmpbuf[64];
47455 + const char *newlink;
47456 int len;
47457
47458 len = PTR_ERR(link);
47459 @@ -3252,7 +3471,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47460 len = strlen(link);
47461 if (len > (unsigned) buflen)
47462 len = buflen;
47463 - if (copy_to_user(buffer, link, len))
47464 +
47465 + if (len < sizeof(tmpbuf)) {
47466 + memcpy(tmpbuf, link, len);
47467 + newlink = tmpbuf;
47468 + } else
47469 + newlink = link;
47470 +
47471 + if (copy_to_user(buffer, newlink, len))
47472 len = -EFAULT;
47473 out:
47474 return len;
47475 diff --git a/fs/namespace.c b/fs/namespace.c
47476 index 5e7f2e9..cd13685 100644
47477 --- a/fs/namespace.c
47478 +++ b/fs/namespace.c
47479 @@ -1326,6 +1326,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
47480 if (!(sb->s_flags & MS_RDONLY))
47481 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47482 up_write(&sb->s_umount);
47483 +
47484 + gr_log_remount(mnt->mnt_devname, retval);
47485 +
47486 return retval;
47487 }
47488
47489 @@ -1345,6 +1348,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
47490 br_write_unlock(vfsmount_lock);
47491 up_write(&namespace_sem);
47492 release_mounts(&umount_list);
47493 +
47494 + gr_log_unmount(mnt->mnt_devname, retval);
47495 +
47496 return retval;
47497 }
47498
47499 @@ -2336,6 +2342,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47500 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47501 MS_STRICTATIME);
47502
47503 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47504 + retval = -EPERM;
47505 + goto dput_out;
47506 + }
47507 +
47508 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47509 + retval = -EPERM;
47510 + goto dput_out;
47511 + }
47512 +
47513 if (flags & MS_REMOUNT)
47514 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47515 data_page);
47516 @@ -2350,6 +2366,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47517 dev_name, data_page);
47518 dput_out:
47519 path_put(&path);
47520 +
47521 + gr_log_mount(dev_name, dir_name, retval);
47522 +
47523 return retval;
47524 }
47525
47526 @@ -2573,6 +2592,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47527 if (error)
47528 goto out2;
47529
47530 + if (gr_handle_chroot_pivot()) {
47531 + error = -EPERM;
47532 + goto out2;
47533 + }
47534 +
47535 get_fs_root(current->fs, &root);
47536 error = lock_mount(&old);
47537 if (error)
47538 diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
47539 index 9c51f62..503b252 100644
47540 --- a/fs/ncpfs/dir.c
47541 +++ b/fs/ncpfs/dir.c
47542 @@ -299,6 +299,8 @@ ncp_lookup_validate(struct dentry *dentry, struct nameidata *nd)
47543 int res, val = 0, len;
47544 __u8 __name[NCP_MAXPATHLEN + 1];
47545
47546 + pax_track_stack();
47547 +
47548 if (dentry == dentry->d_sb->s_root)
47549 return 1;
47550
47551 @@ -844,6 +846,8 @@ static struct dentry *ncp_lookup(struct inode *dir, struct dentry *dentry, struc
47552 int error, res, len;
47553 __u8 __name[NCP_MAXPATHLEN + 1];
47554
47555 + pax_track_stack();
47556 +
47557 error = -EIO;
47558 if (!ncp_conn_valid(server))
47559 goto finished;
47560 @@ -931,6 +935,8 @@ int ncp_create_new(struct inode *dir, struct dentry *dentry, int mode,
47561 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
47562 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
47563
47564 + pax_track_stack();
47565 +
47566 ncp_age_dentry(server, dentry);
47567 len = sizeof(__name);
47568 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
47569 @@ -992,6 +998,8 @@ static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
47570 int error, len;
47571 __u8 __name[NCP_MAXPATHLEN + 1];
47572
47573 + pax_track_stack();
47574 +
47575 DPRINTK("ncp_mkdir: making %s/%s\n",
47576 dentry->d_parent->d_name.name, dentry->d_name.name);
47577
47578 @@ -1140,6 +1148,8 @@ static int ncp_rename(struct inode *old_dir, struct dentry *old_dentry,
47579 int old_len, new_len;
47580 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
47581
47582 + pax_track_stack();
47583 +
47584 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
47585 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
47586 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
47587 diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
47588 index 202f370..9d4565e 100644
47589 --- a/fs/ncpfs/inode.c
47590 +++ b/fs/ncpfs/inode.c
47591 @@ -461,6 +461,8 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
47592 #endif
47593 struct ncp_entry_info finfo;
47594
47595 + pax_track_stack();
47596 +
47597 memset(&data, 0, sizeof(data));
47598 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
47599 if (!server)
47600 diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
47601 index 281ae95..dd895b9 100644
47602 --- a/fs/nfs/blocklayout/blocklayout.c
47603 +++ b/fs/nfs/blocklayout/blocklayout.c
47604 @@ -90,7 +90,7 @@ static int is_writable(struct pnfs_block_extent *be, sector_t isect)
47605 */
47606 struct parallel_io {
47607 struct kref refcnt;
47608 - struct rpc_call_ops call_ops;
47609 + rpc_call_ops_no_const call_ops;
47610 void (*pnfs_callback) (void *data);
47611 void *data;
47612 };
47613 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47614 index 679d2f5..ef1ffec 100644
47615 --- a/fs/nfs/inode.c
47616 +++ b/fs/nfs/inode.c
47617 @@ -150,7 +150,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47618 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47619 nfsi->attrtimeo_timestamp = jiffies;
47620
47621 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47622 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47623 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47624 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47625 else
47626 @@ -1002,16 +1002,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47627 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47628 }
47629
47630 -static atomic_long_t nfs_attr_generation_counter;
47631 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47632
47633 static unsigned long nfs_read_attr_generation_counter(void)
47634 {
47635 - return atomic_long_read(&nfs_attr_generation_counter);
47636 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47637 }
47638
47639 unsigned long nfs_inc_attr_generation_counter(void)
47640 {
47641 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47642 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47643 }
47644
47645 void nfs_fattr_init(struct nfs_fattr *fattr)
47646 diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
47647 index 6f8bcc7..8f823c5 100644
47648 --- a/fs/nfsd/nfs4state.c
47649 +++ b/fs/nfsd/nfs4state.c
47650 @@ -3999,6 +3999,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
47651 unsigned int strhashval;
47652 int err;
47653
47654 + pax_track_stack();
47655 +
47656 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
47657 (long long) lock->lk_offset,
47658 (long long) lock->lk_length);
47659 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
47660 index f810996..cec8977 100644
47661 --- a/fs/nfsd/nfs4xdr.c
47662 +++ b/fs/nfsd/nfs4xdr.c
47663 @@ -1875,6 +1875,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
47664 .dentry = dentry,
47665 };
47666
47667 + pax_track_stack();
47668 +
47669 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
47670 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
47671 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
47672 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47673 index acf88ae..4fd6245 100644
47674 --- a/fs/nfsd/vfs.c
47675 +++ b/fs/nfsd/vfs.c
47676 @@ -896,7 +896,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47677 } else {
47678 oldfs = get_fs();
47679 set_fs(KERNEL_DS);
47680 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47681 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47682 set_fs(oldfs);
47683 }
47684
47685 @@ -1000,7 +1000,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47686
47687 /* Write the data. */
47688 oldfs = get_fs(); set_fs(KERNEL_DS);
47689 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47690 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47691 set_fs(oldfs);
47692 if (host_err < 0)
47693 goto out_nfserr;
47694 @@ -1535,7 +1535,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47695 */
47696
47697 oldfs = get_fs(); set_fs(KERNEL_DS);
47698 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
47699 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
47700 set_fs(oldfs);
47701
47702 if (host_err < 0)
47703 diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
47704 index 3e65427..ac258be 100644
47705 --- a/fs/nilfs2/ioctl.c
47706 +++ b/fs/nilfs2/ioctl.c
47707 @@ -625,6 +625,9 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
47708 if (argv[n].v_nmembs > nsegs * nilfs->ns_blocks_per_segment)
47709 goto out_free;
47710
47711 + if (argv[n].v_nmembs >= UINT_MAX / argv[n].v_size)
47712 + goto out_free;
47713 +
47714 len = argv[n].v_size * argv[n].v_nmembs;
47715 base = (void __user *)(unsigned long)argv[n].v_base;
47716 if (len == 0) {
47717 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47718 index 9fde1c0..14e8827 100644
47719 --- a/fs/notify/fanotify/fanotify_user.c
47720 +++ b/fs/notify/fanotify/fanotify_user.c
47721 @@ -276,7 +276,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47722 goto out_close_fd;
47723
47724 ret = -EFAULT;
47725 - if (copy_to_user(buf, &fanotify_event_metadata,
47726 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47727 + copy_to_user(buf, &fanotify_event_metadata,
47728 fanotify_event_metadata.event_len))
47729 goto out_kill_access_response;
47730
47731 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
47732 index e14587d..f104d56 100644
47733 --- a/fs/notify/mark.c
47734 +++ b/fs/notify/mark.c
47735 @@ -135,9 +135,6 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark)
47736
47737 mark->flags &= ~FSNOTIFY_MARK_FLAG_ALIVE;
47738
47739 - /* 1 from caller and 1 for being on i_list/g_list */
47740 - BUG_ON(atomic_read(&mark->refcnt) < 2);
47741 -
47742 spin_lock(&group->mark_lock);
47743
47744 if (mark->flags & FSNOTIFY_MARK_FLAG_INODE) {
47745 @@ -182,6 +179,11 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark)
47746 iput(inode);
47747
47748 /*
47749 + * We don't necessarily have a ref on mark from caller so the above iput
47750 + * may have already destroyed it. Don't touch from now on.
47751 + */
47752 +
47753 + /*
47754 * it's possible that this group tried to destroy itself, but this
47755 * this mark was simultaneously being freed by inode. If that's the
47756 * case, we finish freeing the group here.
47757 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47758 index ee18815..7aa5d01 100644
47759 --- a/fs/notify/notification.c
47760 +++ b/fs/notify/notification.c
47761 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47762 * get set to 0 so it will never get 'freed'
47763 */
47764 static struct fsnotify_event *q_overflow_event;
47765 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47766 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47767
47768 /**
47769 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47770 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47771 */
47772 u32 fsnotify_get_cookie(void)
47773 {
47774 - return atomic_inc_return(&fsnotify_sync_cookie);
47775 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47776 }
47777 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47778
47779 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47780 index 99e3610..02c1068 100644
47781 --- a/fs/ntfs/dir.c
47782 +++ b/fs/ntfs/dir.c
47783 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47784 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47785 ~(s64)(ndir->itype.index.block_size - 1)));
47786 /* Bounds checks. */
47787 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47788 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47789 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47790 "inode 0x%lx or driver bug.", vdir->i_ino);
47791 goto err_out;
47792 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47793 index c587e2d..3641eaa 100644
47794 --- a/fs/ntfs/file.c
47795 +++ b/fs/ntfs/file.c
47796 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47797 #endif /* NTFS_RW */
47798 };
47799
47800 -const struct file_operations ntfs_empty_file_ops = {};
47801 +const struct file_operations ntfs_empty_file_ops __read_only;
47802
47803 -const struct inode_operations ntfs_empty_inode_ops = {};
47804 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47805 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47806 index 210c352..a174f83 100644
47807 --- a/fs/ocfs2/localalloc.c
47808 +++ b/fs/ocfs2/localalloc.c
47809 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47810 goto bail;
47811 }
47812
47813 - atomic_inc(&osb->alloc_stats.moves);
47814 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47815
47816 bail:
47817 if (handle)
47818 diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
47819 index 53aa41e..d7df9f1 100644
47820 --- a/fs/ocfs2/namei.c
47821 +++ b/fs/ocfs2/namei.c
47822 @@ -1063,6 +1063,8 @@ static int ocfs2_rename(struct inode *old_dir,
47823 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
47824 struct ocfs2_dir_lookup_result target_insert = { NULL, };
47825
47826 + pax_track_stack();
47827 +
47828 /* At some point it might be nice to break this function up a
47829 * bit. */
47830
47831 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47832 index 4092858..51c70ff 100644
47833 --- a/fs/ocfs2/ocfs2.h
47834 +++ b/fs/ocfs2/ocfs2.h
47835 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47836
47837 struct ocfs2_alloc_stats
47838 {
47839 - atomic_t moves;
47840 - atomic_t local_data;
47841 - atomic_t bitmap_data;
47842 - atomic_t bg_allocs;
47843 - atomic_t bg_extends;
47844 + atomic_unchecked_t moves;
47845 + atomic_unchecked_t local_data;
47846 + atomic_unchecked_t bitmap_data;
47847 + atomic_unchecked_t bg_allocs;
47848 + atomic_unchecked_t bg_extends;
47849 };
47850
47851 enum ocfs2_local_alloc_state
47852 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47853 index ba5d97e..c77db25 100644
47854 --- a/fs/ocfs2/suballoc.c
47855 +++ b/fs/ocfs2/suballoc.c
47856 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47857 mlog_errno(status);
47858 goto bail;
47859 }
47860 - atomic_inc(&osb->alloc_stats.bg_extends);
47861 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47862
47863 /* You should never ask for this much metadata */
47864 BUG_ON(bits_wanted >
47865 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47866 mlog_errno(status);
47867 goto bail;
47868 }
47869 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47870 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47871
47872 *suballoc_loc = res.sr_bg_blkno;
47873 *suballoc_bit_start = res.sr_bit_offset;
47874 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47875 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47876 res->sr_bits);
47877
47878 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47879 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47880
47881 BUG_ON(res->sr_bits != 1);
47882
47883 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47884 mlog_errno(status);
47885 goto bail;
47886 }
47887 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47888 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47889
47890 BUG_ON(res.sr_bits != 1);
47891
47892 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47893 cluster_start,
47894 num_clusters);
47895 if (!status)
47896 - atomic_inc(&osb->alloc_stats.local_data);
47897 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47898 } else {
47899 if (min_clusters > (osb->bitmap_cpg - 1)) {
47900 /* The only paths asking for contiguousness
47901 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47902 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47903 res.sr_bg_blkno,
47904 res.sr_bit_offset);
47905 - atomic_inc(&osb->alloc_stats.bitmap_data);
47906 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47907 *num_clusters = res.sr_bits;
47908 }
47909 }
47910 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47911 index 56f6102..1433c29 100644
47912 --- a/fs/ocfs2/super.c
47913 +++ b/fs/ocfs2/super.c
47914 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47915 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47916 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47917 "Stats",
47918 - atomic_read(&osb->alloc_stats.bitmap_data),
47919 - atomic_read(&osb->alloc_stats.local_data),
47920 - atomic_read(&osb->alloc_stats.bg_allocs),
47921 - atomic_read(&osb->alloc_stats.moves),
47922 - atomic_read(&osb->alloc_stats.bg_extends));
47923 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47924 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47925 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47926 + atomic_read_unchecked(&osb->alloc_stats.moves),
47927 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47928
47929 out += snprintf(buf + out, len - out,
47930 "%10s => State: %u Descriptor: %llu Size: %u bits "
47931 @@ -2112,11 +2112,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47932 spin_lock_init(&osb->osb_xattr_lock);
47933 ocfs2_init_steal_slots(osb);
47934
47935 - atomic_set(&osb->alloc_stats.moves, 0);
47936 - atomic_set(&osb->alloc_stats.local_data, 0);
47937 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47938 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47939 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47940 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47941 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47942 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47943 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47944 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47945
47946 /* Copy the blockcheck stats from the superblock probe */
47947 osb->osb_ecc_stats = *stats;
47948 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47949 index 5d22872..523db20 100644
47950 --- a/fs/ocfs2/symlink.c
47951 +++ b/fs/ocfs2/symlink.c
47952 @@ -142,7 +142,7 @@ bail:
47953
47954 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47955 {
47956 - char *link = nd_get_link(nd);
47957 + const char *link = nd_get_link(nd);
47958 if (!IS_ERR(link))
47959 kfree(link);
47960 }
47961 diff --git a/fs/open.c b/fs/open.c
47962 index f711921..28d5958 100644
47963 --- a/fs/open.c
47964 +++ b/fs/open.c
47965 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47966 error = locks_verify_truncate(inode, NULL, length);
47967 if (!error)
47968 error = security_path_truncate(&path);
47969 +
47970 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47971 + error = -EACCES;
47972 +
47973 if (!error)
47974 error = do_truncate(path.dentry, length, 0, NULL);
47975
47976 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47977 if (__mnt_is_readonly(path.mnt))
47978 res = -EROFS;
47979
47980 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47981 + res = -EACCES;
47982 +
47983 out_path_release:
47984 path_put(&path);
47985 out:
47986 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47987 if (error)
47988 goto dput_and_out;
47989
47990 + gr_log_chdir(path.dentry, path.mnt);
47991 +
47992 set_fs_pwd(current->fs, &path);
47993
47994 dput_and_out:
47995 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47996 goto out_putf;
47997
47998 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47999 +
48000 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48001 + error = -EPERM;
48002 +
48003 + if (!error)
48004 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48005 +
48006 if (!error)
48007 set_fs_pwd(current->fs, &file->f_path);
48008 out_putf:
48009 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48010 if (error)
48011 goto dput_and_out;
48012
48013 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48014 + goto dput_and_out;
48015 +
48016 set_fs_root(current->fs, &path);
48017 +
48018 + gr_handle_chroot_chdir(&path);
48019 +
48020 error = 0;
48021 dput_and_out:
48022 path_put(&path);
48023 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
48024 if (error)
48025 return error;
48026 mutex_lock(&inode->i_mutex);
48027 +
48028 + if (!gr_acl_handle_fchmod(path->dentry, path->mnt, mode)) {
48029 + error = -EACCES;
48030 + goto out_unlock;
48031 + }
48032 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48033 + error = -EACCES;
48034 + goto out_unlock;
48035 + }
48036 +
48037 error = security_path_chmod(path->dentry, path->mnt, mode);
48038 if (error)
48039 goto out_unlock;
48040 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48041 int error;
48042 struct iattr newattrs;
48043
48044 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48045 + return -EACCES;
48046 +
48047 newattrs.ia_valid = ATTR_CTIME;
48048 if (user != (uid_t) -1) {
48049 newattrs.ia_valid |= ATTR_UID;
48050 diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
48051 index 6296b40..417c00f 100644
48052 --- a/fs/partitions/efi.c
48053 +++ b/fs/partitions/efi.c
48054 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
48055 if (!gpt)
48056 return NULL;
48057
48058 + if (!le32_to_cpu(gpt->num_partition_entries))
48059 + return NULL;
48060 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
48061 + if (!pte)
48062 + return NULL;
48063 +
48064 count = le32_to_cpu(gpt->num_partition_entries) *
48065 le32_to_cpu(gpt->sizeof_partition_entry);
48066 - if (!count)
48067 - return NULL;
48068 - pte = kzalloc(count, GFP_KERNEL);
48069 - if (!pte)
48070 - return NULL;
48071 -
48072 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
48073 (u8 *) pte,
48074 count) < count) {
48075 diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
48076 index af9fdf0..75b15c3 100644
48077 --- a/fs/partitions/ldm.c
48078 +++ b/fs/partitions/ldm.c
48079 @@ -1322,7 +1322,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
48080 goto found;
48081 }
48082
48083 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
48084 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
48085 if (!f) {
48086 ldm_crit ("Out of memory.");
48087 return false;
48088 diff --git a/fs/pipe.c b/fs/pipe.c
48089 index 0e0be1d..f62a72d 100644
48090 --- a/fs/pipe.c
48091 +++ b/fs/pipe.c
48092 @@ -420,9 +420,9 @@ redo:
48093 }
48094 if (bufs) /* More to do? */
48095 continue;
48096 - if (!pipe->writers)
48097 + if (!atomic_read(&pipe->writers))
48098 break;
48099 - if (!pipe->waiting_writers) {
48100 + if (!atomic_read(&pipe->waiting_writers)) {
48101 /* syscall merging: Usually we must not sleep
48102 * if O_NONBLOCK is set, or if we got some data.
48103 * But if a writer sleeps in kernel space, then
48104 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48105 mutex_lock(&inode->i_mutex);
48106 pipe = inode->i_pipe;
48107
48108 - if (!pipe->readers) {
48109 + if (!atomic_read(&pipe->readers)) {
48110 send_sig(SIGPIPE, current, 0);
48111 ret = -EPIPE;
48112 goto out;
48113 @@ -530,7 +530,7 @@ redo1:
48114 for (;;) {
48115 int bufs;
48116
48117 - if (!pipe->readers) {
48118 + if (!atomic_read(&pipe->readers)) {
48119 send_sig(SIGPIPE, current, 0);
48120 if (!ret)
48121 ret = -EPIPE;
48122 @@ -616,9 +616,9 @@ redo2:
48123 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48124 do_wakeup = 0;
48125 }
48126 - pipe->waiting_writers++;
48127 + atomic_inc(&pipe->waiting_writers);
48128 pipe_wait(pipe);
48129 - pipe->waiting_writers--;
48130 + atomic_dec(&pipe->waiting_writers);
48131 }
48132 out:
48133 mutex_unlock(&inode->i_mutex);
48134 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48135 mask = 0;
48136 if (filp->f_mode & FMODE_READ) {
48137 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48138 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48139 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48140 mask |= POLLHUP;
48141 }
48142
48143 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48144 * Most Unices do not set POLLERR for FIFOs but on Linux they
48145 * behave exactly like pipes for poll().
48146 */
48147 - if (!pipe->readers)
48148 + if (!atomic_read(&pipe->readers))
48149 mask |= POLLERR;
48150 }
48151
48152 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48153
48154 mutex_lock(&inode->i_mutex);
48155 pipe = inode->i_pipe;
48156 - pipe->readers -= decr;
48157 - pipe->writers -= decw;
48158 + atomic_sub(decr, &pipe->readers);
48159 + atomic_sub(decw, &pipe->writers);
48160
48161 - if (!pipe->readers && !pipe->writers) {
48162 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48163 free_pipe_info(inode);
48164 } else {
48165 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48166 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48167
48168 if (inode->i_pipe) {
48169 ret = 0;
48170 - inode->i_pipe->readers++;
48171 + atomic_inc(&inode->i_pipe->readers);
48172 }
48173
48174 mutex_unlock(&inode->i_mutex);
48175 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48176
48177 if (inode->i_pipe) {
48178 ret = 0;
48179 - inode->i_pipe->writers++;
48180 + atomic_inc(&inode->i_pipe->writers);
48181 }
48182
48183 mutex_unlock(&inode->i_mutex);
48184 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48185 if (inode->i_pipe) {
48186 ret = 0;
48187 if (filp->f_mode & FMODE_READ)
48188 - inode->i_pipe->readers++;
48189 + atomic_inc(&inode->i_pipe->readers);
48190 if (filp->f_mode & FMODE_WRITE)
48191 - inode->i_pipe->writers++;
48192 + atomic_inc(&inode->i_pipe->writers);
48193 }
48194
48195 mutex_unlock(&inode->i_mutex);
48196 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
48197 inode->i_pipe = NULL;
48198 }
48199
48200 -static struct vfsmount *pipe_mnt __read_mostly;
48201 +struct vfsmount *pipe_mnt __read_mostly;
48202
48203 /*
48204 * pipefs_dname() is called from d_path().
48205 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
48206 goto fail_iput;
48207 inode->i_pipe = pipe;
48208
48209 - pipe->readers = pipe->writers = 1;
48210 + atomic_set(&pipe->readers, 1);
48211 + atomic_set(&pipe->writers, 1);
48212 inode->i_fop = &rdwr_pipefifo_fops;
48213
48214 /*
48215 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48216 index 15af622..0e9f4467 100644
48217 --- a/fs/proc/Kconfig
48218 +++ b/fs/proc/Kconfig
48219 @@ -30,12 +30,12 @@ config PROC_FS
48220
48221 config PROC_KCORE
48222 bool "/proc/kcore support" if !ARM
48223 - depends on PROC_FS && MMU
48224 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48225
48226 config PROC_VMCORE
48227 bool "/proc/vmcore support"
48228 - depends on PROC_FS && CRASH_DUMP
48229 - default y
48230 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48231 + default n
48232 help
48233 Exports the dump image of crashed kernel in ELF format.
48234
48235 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48236 limited in memory.
48237
48238 config PROC_PAGE_MONITOR
48239 - default y
48240 - depends on PROC_FS && MMU
48241 + default n
48242 + depends on PROC_FS && MMU && !GRKERNSEC
48243 bool "Enable /proc page monitoring" if EXPERT
48244 help
48245 Various /proc files exist to monitor process memory utilization:
48246 diff --git a/fs/proc/array.c b/fs/proc/array.c
48247 index 3a1dafd..c7fed72 100644
48248 --- a/fs/proc/array.c
48249 +++ b/fs/proc/array.c
48250 @@ -60,6 +60,7 @@
48251 #include <linux/tty.h>
48252 #include <linux/string.h>
48253 #include <linux/mman.h>
48254 +#include <linux/grsecurity.h>
48255 #include <linux/proc_fs.h>
48256 #include <linux/ioport.h>
48257 #include <linux/uaccess.h>
48258 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48259 seq_putc(m, '\n');
48260 }
48261
48262 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48263 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48264 +{
48265 + if (p->mm)
48266 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48267 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48268 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48269 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48270 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48271 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48272 + else
48273 + seq_printf(m, "PaX:\t-----\n");
48274 +}
48275 +#endif
48276 +
48277 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48278 struct pid *pid, struct task_struct *task)
48279 {
48280 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48281 task_cpus_allowed(m, task);
48282 cpuset_task_status_allowed(m, task);
48283 task_context_switch_counts(m, task);
48284 +
48285 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48286 + task_pax(m, task);
48287 +#endif
48288 +
48289 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48290 + task_grsec_rbac(m, task);
48291 +#endif
48292 +
48293 return 0;
48294 }
48295
48296 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48297 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48298 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48299 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48300 +#endif
48301 +
48302 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48303 struct pid *pid, struct task_struct *task, int whole)
48304 {
48305 @@ -378,6 +409,8 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48306 char tcomm[sizeof(task->comm)];
48307 unsigned long flags;
48308
48309 + pax_track_stack();
48310 +
48311 state = *get_task_state(task);
48312 vsize = eip = esp = 0;
48313 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
48314 @@ -449,6 +482,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48315 gtime = task->gtime;
48316 }
48317
48318 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48319 + if (PAX_RAND_FLAGS(mm)) {
48320 + eip = 0;
48321 + esp = 0;
48322 + wchan = 0;
48323 + }
48324 +#endif
48325 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48326 + wchan = 0;
48327 + eip =0;
48328 + esp =0;
48329 +#endif
48330 +
48331 /* scale priority and nice values from timeslices to -20..20 */
48332 /* to make it look like a "normal" Unix priority/nice value */
48333 priority = task_prio(task);
48334 @@ -489,9 +535,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48335 vsize,
48336 mm ? get_mm_rss(mm) : 0,
48337 rsslim,
48338 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48339 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
48340 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
48341 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
48342 +#else
48343 mm ? (permitted ? mm->start_code : 1) : 0,
48344 mm ? (permitted ? mm->end_code : 1) : 0,
48345 (permitted && mm) ? mm->start_stack : 0,
48346 +#endif
48347 esp,
48348 eip,
48349 /* The signal information here is obsolete.
48350 @@ -544,3 +596,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48351
48352 return 0;
48353 }
48354 +
48355 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48356 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48357 +{
48358 + u32 curr_ip = 0;
48359 + unsigned long flags;
48360 +
48361 + if (lock_task_sighand(task, &flags)) {
48362 + curr_ip = task->signal->curr_ip;
48363 + unlock_task_sighand(task, &flags);
48364 + }
48365 +
48366 + return sprintf(buffer, "%pI4\n", &curr_ip);
48367 +}
48368 +#endif
48369 diff --git a/fs/proc/base.c b/fs/proc/base.c
48370 index 5eb0206..fe01db4 100644
48371 --- a/fs/proc/base.c
48372 +++ b/fs/proc/base.c
48373 @@ -107,6 +107,22 @@ struct pid_entry {
48374 union proc_op op;
48375 };
48376
48377 +struct getdents_callback {
48378 + struct linux_dirent __user * current_dir;
48379 + struct linux_dirent __user * previous;
48380 + struct file * file;
48381 + int count;
48382 + int error;
48383 +};
48384 +
48385 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
48386 + loff_t offset, u64 ino, unsigned int d_type)
48387 +{
48388 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
48389 + buf->error = -EINVAL;
48390 + return 0;
48391 +}
48392 +
48393 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48394 .name = (NAME), \
48395 .len = sizeof(NAME) - 1, \
48396 @@ -209,6 +225,9 @@ static struct mm_struct *__check_mem_permission(struct task_struct *task)
48397 if (task == current)
48398 return mm;
48399
48400 + if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
48401 + return ERR_PTR(-EPERM);
48402 +
48403 /*
48404 * If current is actively ptrace'ing, and would also be
48405 * permitted to freshly attach with ptrace now, permit it.
48406 @@ -282,6 +301,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48407 if (!mm->arg_end)
48408 goto out_mm; /* Shh! No looking before we're done */
48409
48410 + if (gr_acl_handle_procpidmem(task))
48411 + goto out_mm;
48412 +
48413 len = mm->arg_end - mm->arg_start;
48414
48415 if (len > PAGE_SIZE)
48416 @@ -309,12 +331,28 @@ out:
48417 return res;
48418 }
48419
48420 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48421 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48422 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48423 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48424 +#endif
48425 +
48426 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48427 {
48428 struct mm_struct *mm = mm_for_maps(task);
48429 int res = PTR_ERR(mm);
48430 if (mm && !IS_ERR(mm)) {
48431 unsigned int nwords = 0;
48432 +
48433 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48434 + /* allow if we're currently ptracing this task */
48435 + if (PAX_RAND_FLAGS(mm) &&
48436 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48437 + mmput(mm);
48438 + return 0;
48439 + }
48440 +#endif
48441 +
48442 do {
48443 nwords += 2;
48444 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48445 @@ -328,7 +366,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48446 }
48447
48448
48449 -#ifdef CONFIG_KALLSYMS
48450 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48451 /*
48452 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48453 * Returns the resolved symbol. If that fails, simply return the address.
48454 @@ -367,7 +405,7 @@ static void unlock_trace(struct task_struct *task)
48455 mutex_unlock(&task->signal->cred_guard_mutex);
48456 }
48457
48458 -#ifdef CONFIG_STACKTRACE
48459 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48460
48461 #define MAX_STACK_TRACE_DEPTH 64
48462
48463 @@ -558,7 +596,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48464 return count;
48465 }
48466
48467 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48468 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48469 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48470 {
48471 long nr;
48472 @@ -587,7 +625,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48473 /************************************************************************/
48474
48475 /* permission checks */
48476 -static int proc_fd_access_allowed(struct inode *inode)
48477 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48478 {
48479 struct task_struct *task;
48480 int allowed = 0;
48481 @@ -597,7 +635,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48482 */
48483 task = get_proc_task(inode);
48484 if (task) {
48485 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48486 + if (log)
48487 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
48488 + else
48489 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48490 put_task_struct(task);
48491 }
48492 return allowed;
48493 @@ -978,6 +1019,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48494 if (!task)
48495 goto out_no_task;
48496
48497 + if (gr_acl_handle_procpidmem(task))
48498 + goto out;
48499 +
48500 ret = -ENOMEM;
48501 page = (char *)__get_free_page(GFP_TEMPORARY);
48502 if (!page)
48503 @@ -1613,7 +1657,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48504 path_put(&nd->path);
48505
48506 /* Are we allowed to snoop on the tasks file descriptors? */
48507 - if (!proc_fd_access_allowed(inode))
48508 + if (!proc_fd_access_allowed(inode,0))
48509 goto out;
48510
48511 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
48512 @@ -1652,8 +1696,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48513 struct path path;
48514
48515 /* Are we allowed to snoop on the tasks file descriptors? */
48516 - if (!proc_fd_access_allowed(inode))
48517 - goto out;
48518 + /* logging this is needed for learning on chromium to work properly,
48519 + but we don't want to flood the logs from 'ps' which does a readlink
48520 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48521 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48522 + */
48523 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48524 + if (!proc_fd_access_allowed(inode,0))
48525 + goto out;
48526 + } else {
48527 + if (!proc_fd_access_allowed(inode,1))
48528 + goto out;
48529 + }
48530
48531 error = PROC_I(inode)->op.proc_get_link(inode, &path);
48532 if (error)
48533 @@ -1718,7 +1772,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48534 rcu_read_lock();
48535 cred = __task_cred(task);
48536 inode->i_uid = cred->euid;
48537 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48538 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48539 +#else
48540 inode->i_gid = cred->egid;
48541 +#endif
48542 rcu_read_unlock();
48543 }
48544 security_task_to_inode(task, inode);
48545 @@ -1736,6 +1794,9 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48546 struct inode *inode = dentry->d_inode;
48547 struct task_struct *task;
48548 const struct cred *cred;
48549 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48550 + const struct cred *tmpcred = current_cred();
48551 +#endif
48552
48553 generic_fillattr(inode, stat);
48554
48555 @@ -1743,13 +1804,41 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48556 stat->uid = 0;
48557 stat->gid = 0;
48558 task = pid_task(proc_pid(inode), PIDTYPE_PID);
48559 +
48560 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
48561 + rcu_read_unlock();
48562 + return -ENOENT;
48563 + }
48564 +
48565 if (task) {
48566 + cred = __task_cred(task);
48567 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48568 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48569 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48570 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48571 +#endif
48572 + ) {
48573 +#endif
48574 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48575 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48576 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48577 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48578 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48579 +#endif
48580 task_dumpable(task)) {
48581 - cred = __task_cred(task);
48582 stat->uid = cred->euid;
48583 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48584 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48585 +#else
48586 stat->gid = cred->egid;
48587 +#endif
48588 }
48589 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48590 + } else {
48591 + rcu_read_unlock();
48592 + return -ENOENT;
48593 + }
48594 +#endif
48595 }
48596 rcu_read_unlock();
48597 return 0;
48598 @@ -1786,11 +1875,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48599
48600 if (task) {
48601 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48602 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48603 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48604 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48605 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48606 +#endif
48607 task_dumpable(task)) {
48608 rcu_read_lock();
48609 cred = __task_cred(task);
48610 inode->i_uid = cred->euid;
48611 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48612 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48613 +#else
48614 inode->i_gid = cred->egid;
48615 +#endif
48616 rcu_read_unlock();
48617 } else {
48618 inode->i_uid = 0;
48619 @@ -1908,7 +2006,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48620 int fd = proc_fd(inode);
48621
48622 if (task) {
48623 - files = get_files_struct(task);
48624 + if (!gr_acl_handle_procpidmem(task))
48625 + files = get_files_struct(task);
48626 put_task_struct(task);
48627 }
48628 if (files) {
48629 @@ -2176,11 +2275,21 @@ static const struct file_operations proc_fd_operations = {
48630 */
48631 static int proc_fd_permission(struct inode *inode, int mask)
48632 {
48633 + struct task_struct *task;
48634 int rv = generic_permission(inode, mask);
48635 - if (rv == 0)
48636 - return 0;
48637 +
48638 if (task_pid(current) == proc_pid(inode))
48639 rv = 0;
48640 +
48641 + task = get_proc_task(inode);
48642 + if (task == NULL)
48643 + return rv;
48644 +
48645 + if (gr_acl_handle_procpidmem(task))
48646 + rv = -EACCES;
48647 +
48648 + put_task_struct(task);
48649 +
48650 return rv;
48651 }
48652
48653 @@ -2290,6 +2399,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48654 if (!task)
48655 goto out_no_task;
48656
48657 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48658 + goto out;
48659 +
48660 /*
48661 * Yes, it does not scale. And it should not. Don't add
48662 * new entries into /proc/<tgid>/ without very good reasons.
48663 @@ -2334,6 +2446,9 @@ static int proc_pident_readdir(struct file *filp,
48664 if (!task)
48665 goto out_no_task;
48666
48667 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48668 + goto out;
48669 +
48670 ret = 0;
48671 i = filp->f_pos;
48672 switch (i) {
48673 @@ -2604,7 +2719,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48674 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48675 void *cookie)
48676 {
48677 - char *s = nd_get_link(nd);
48678 + const char *s = nd_get_link(nd);
48679 if (!IS_ERR(s))
48680 __putname(s);
48681 }
48682 @@ -2802,7 +2917,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48683 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48684 #endif
48685 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48686 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48687 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48688 INF("syscall", S_IRUGO, proc_pid_syscall),
48689 #endif
48690 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48691 @@ -2827,10 +2942,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48692 #ifdef CONFIG_SECURITY
48693 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48694 #endif
48695 -#ifdef CONFIG_KALLSYMS
48696 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48697 INF("wchan", S_IRUGO, proc_pid_wchan),
48698 #endif
48699 -#ifdef CONFIG_STACKTRACE
48700 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48701 ONE("stack", S_IRUGO, proc_pid_stack),
48702 #endif
48703 #ifdef CONFIG_SCHEDSTATS
48704 @@ -2864,6 +2979,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48705 #ifdef CONFIG_HARDWALL
48706 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48707 #endif
48708 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48709 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48710 +#endif
48711 };
48712
48713 static int proc_tgid_base_readdir(struct file * filp,
48714 @@ -2989,7 +3107,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48715 if (!inode)
48716 goto out;
48717
48718 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48719 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48720 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48721 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48722 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48723 +#else
48724 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48725 +#endif
48726 inode->i_op = &proc_tgid_base_inode_operations;
48727 inode->i_fop = &proc_tgid_base_operations;
48728 inode->i_flags|=S_IMMUTABLE;
48729 @@ -3031,7 +3156,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48730 if (!task)
48731 goto out;
48732
48733 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48734 + goto out_put_task;
48735 +
48736 result = proc_pid_instantiate(dir, dentry, task, NULL);
48737 +out_put_task:
48738 put_task_struct(task);
48739 out:
48740 return result;
48741 @@ -3096,6 +3225,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
48742 {
48743 unsigned int nr;
48744 struct task_struct *reaper;
48745 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48746 + const struct cred *tmpcred = current_cred();
48747 + const struct cred *itercred;
48748 +#endif
48749 + filldir_t __filldir = filldir;
48750 struct tgid_iter iter;
48751 struct pid_namespace *ns;
48752
48753 @@ -3119,8 +3253,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
48754 for (iter = next_tgid(ns, iter);
48755 iter.task;
48756 iter.tgid += 1, iter = next_tgid(ns, iter)) {
48757 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48758 + rcu_read_lock();
48759 + itercred = __task_cred(iter.task);
48760 +#endif
48761 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
48762 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48763 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
48764 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48765 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48766 +#endif
48767 + )
48768 +#endif
48769 + )
48770 + __filldir = &gr_fake_filldir;
48771 + else
48772 + __filldir = filldir;
48773 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48774 + rcu_read_unlock();
48775 +#endif
48776 filp->f_pos = iter.tgid + TGID_OFFSET;
48777 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
48778 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
48779 put_task_struct(iter.task);
48780 goto out;
48781 }
48782 @@ -3148,7 +3301,7 @@ static const struct pid_entry tid_base_stuff[] = {
48783 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48784 #endif
48785 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48786 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48787 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48788 INF("syscall", S_IRUGO, proc_pid_syscall),
48789 #endif
48790 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48791 @@ -3172,10 +3325,10 @@ static const struct pid_entry tid_base_stuff[] = {
48792 #ifdef CONFIG_SECURITY
48793 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48794 #endif
48795 -#ifdef CONFIG_KALLSYMS
48796 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48797 INF("wchan", S_IRUGO, proc_pid_wchan),
48798 #endif
48799 -#ifdef CONFIG_STACKTRACE
48800 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48801 ONE("stack", S_IRUGO, proc_pid_stack),
48802 #endif
48803 #ifdef CONFIG_SCHEDSTATS
48804 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48805 index 82676e3..5f8518a 100644
48806 --- a/fs/proc/cmdline.c
48807 +++ b/fs/proc/cmdline.c
48808 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48809
48810 static int __init proc_cmdline_init(void)
48811 {
48812 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48813 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48814 +#else
48815 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48816 +#endif
48817 return 0;
48818 }
48819 module_init(proc_cmdline_init);
48820 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48821 index b143471..bb105e5 100644
48822 --- a/fs/proc/devices.c
48823 +++ b/fs/proc/devices.c
48824 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48825
48826 static int __init proc_devices_init(void)
48827 {
48828 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48829 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48830 +#else
48831 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48832 +#endif
48833 return 0;
48834 }
48835 module_init(proc_devices_init);
48836 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48837 index 7ed72d6..d5f061a 100644
48838 --- a/fs/proc/inode.c
48839 +++ b/fs/proc/inode.c
48840 @@ -18,12 +18,18 @@
48841 #include <linux/module.h>
48842 #include <linux/sysctl.h>
48843 #include <linux/slab.h>
48844 +#include <linux/grsecurity.h>
48845
48846 #include <asm/system.h>
48847 #include <asm/uaccess.h>
48848
48849 #include "internal.h"
48850
48851 +#ifdef CONFIG_PROC_SYSCTL
48852 +extern const struct inode_operations proc_sys_inode_operations;
48853 +extern const struct inode_operations proc_sys_dir_operations;
48854 +#endif
48855 +
48856 static void proc_evict_inode(struct inode *inode)
48857 {
48858 struct proc_dir_entry *de;
48859 @@ -49,6 +55,13 @@ static void proc_evict_inode(struct inode *inode)
48860 ns_ops = PROC_I(inode)->ns_ops;
48861 if (ns_ops && ns_ops->put)
48862 ns_ops->put(PROC_I(inode)->ns);
48863 +
48864 +#ifdef CONFIG_PROC_SYSCTL
48865 + if (inode->i_op == &proc_sys_inode_operations ||
48866 + inode->i_op == &proc_sys_dir_operations)
48867 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48868 +#endif
48869 +
48870 }
48871
48872 static struct kmem_cache * proc_inode_cachep;
48873 @@ -440,7 +453,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48874 if (de->mode) {
48875 inode->i_mode = de->mode;
48876 inode->i_uid = de->uid;
48877 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48878 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48879 +#else
48880 inode->i_gid = de->gid;
48881 +#endif
48882 }
48883 if (de->size)
48884 inode->i_size = de->size;
48885 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48886 index 7838e5c..ff92cbc 100644
48887 --- a/fs/proc/internal.h
48888 +++ b/fs/proc/internal.h
48889 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48890 struct pid *pid, struct task_struct *task);
48891 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48892 struct pid *pid, struct task_struct *task);
48893 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48894 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48895 +#endif
48896 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48897
48898 extern const struct file_operations proc_maps_operations;
48899 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48900 index d245cb2..7e645bd 100644
48901 --- a/fs/proc/kcore.c
48902 +++ b/fs/proc/kcore.c
48903 @@ -321,6 +321,8 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
48904 off_t offset = 0;
48905 struct kcore_list *m;
48906
48907 + pax_track_stack();
48908 +
48909 /* setup ELF header */
48910 elf = (struct elfhdr *) bufp;
48911 bufp += sizeof(struct elfhdr);
48912 @@ -478,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48913 * the addresses in the elf_phdr on our list.
48914 */
48915 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48916 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48917 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48918 + if (tsz > buflen)
48919 tsz = buflen;
48920 -
48921 +
48922 while (buflen) {
48923 struct kcore_list *m;
48924
48925 @@ -509,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48926 kfree(elf_buf);
48927 } else {
48928 if (kern_addr_valid(start)) {
48929 - unsigned long n;
48930 + char *elf_buf;
48931 + mm_segment_t oldfs;
48932
48933 - n = copy_to_user(buffer, (char *)start, tsz);
48934 - /*
48935 - * We cannot distingush between fault on source
48936 - * and fault on destination. When this happens
48937 - * we clear too and hope it will trigger the
48938 - * EFAULT again.
48939 - */
48940 - if (n) {
48941 - if (clear_user(buffer + tsz - n,
48942 - n))
48943 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48944 + if (!elf_buf)
48945 + return -ENOMEM;
48946 + oldfs = get_fs();
48947 + set_fs(KERNEL_DS);
48948 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48949 + set_fs(oldfs);
48950 + if (copy_to_user(buffer, elf_buf, tsz)) {
48951 + kfree(elf_buf);
48952 return -EFAULT;
48953 + }
48954 }
48955 + set_fs(oldfs);
48956 + kfree(elf_buf);
48957 } else {
48958 if (clear_user(buffer, tsz))
48959 return -EFAULT;
48960 @@ -542,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48961
48962 static int open_kcore(struct inode *inode, struct file *filp)
48963 {
48964 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48965 + return -EPERM;
48966 +#endif
48967 if (!capable(CAP_SYS_RAWIO))
48968 return -EPERM;
48969 if (kcore_need_update)
48970 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48971 index 80e4645..d2689e9 100644
48972 --- a/fs/proc/meminfo.c
48973 +++ b/fs/proc/meminfo.c
48974 @@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48975 unsigned long pages[NR_LRU_LISTS];
48976 int lru;
48977
48978 + pax_track_stack();
48979 +
48980 /*
48981 * display in kilobytes.
48982 */
48983 @@ -158,7 +160,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48984 vmi.used >> 10,
48985 vmi.largest_chunk >> 10
48986 #ifdef CONFIG_MEMORY_FAILURE
48987 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48988 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48989 #endif
48990 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48991 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48992 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48993 index b1822dd..df622cb 100644
48994 --- a/fs/proc/nommu.c
48995 +++ b/fs/proc/nommu.c
48996 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48997 if (len < 1)
48998 len = 1;
48999 seq_printf(m, "%*c", len, ' ');
49000 - seq_path(m, &file->f_path, "");
49001 + seq_path(m, &file->f_path, "\n\\");
49002 }
49003
49004 seq_putc(m, '\n');
49005 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49006 index f738024..876984a 100644
49007 --- a/fs/proc/proc_net.c
49008 +++ b/fs/proc/proc_net.c
49009 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49010 struct task_struct *task;
49011 struct nsproxy *ns;
49012 struct net *net = NULL;
49013 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49014 + const struct cred *cred = current_cred();
49015 +#endif
49016 +
49017 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49018 + if (cred->fsuid)
49019 + return net;
49020 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49021 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
49022 + return net;
49023 +#endif
49024
49025 rcu_read_lock();
49026 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49027 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49028 index 1a77dbe..56ec911 100644
49029 --- a/fs/proc/proc_sysctl.c
49030 +++ b/fs/proc/proc_sysctl.c
49031 @@ -8,11 +8,13 @@
49032 #include <linux/namei.h>
49033 #include "internal.h"
49034
49035 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
49036 +
49037 static const struct dentry_operations proc_sys_dentry_operations;
49038 static const struct file_operations proc_sys_file_operations;
49039 -static const struct inode_operations proc_sys_inode_operations;
49040 +const struct inode_operations proc_sys_inode_operations;
49041 static const struct file_operations proc_sys_dir_file_operations;
49042 -static const struct inode_operations proc_sys_dir_operations;
49043 +const struct inode_operations proc_sys_dir_operations;
49044
49045 static struct inode *proc_sys_make_inode(struct super_block *sb,
49046 struct ctl_table_header *head, struct ctl_table *table)
49047 @@ -121,8 +123,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49048
49049 err = NULL;
49050 d_set_d_op(dentry, &proc_sys_dentry_operations);
49051 +
49052 + gr_handle_proc_create(dentry, inode);
49053 +
49054 d_add(dentry, inode);
49055
49056 + if (gr_handle_sysctl(p, MAY_EXEC))
49057 + err = ERR_PTR(-ENOENT);
49058 +
49059 out:
49060 sysctl_head_finish(head);
49061 return err;
49062 @@ -202,6 +210,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49063 return -ENOMEM;
49064 } else {
49065 d_set_d_op(child, &proc_sys_dentry_operations);
49066 +
49067 + gr_handle_proc_create(child, inode);
49068 +
49069 d_add(child, inode);
49070 }
49071 } else {
49072 @@ -230,6 +241,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49073 if (*pos < file->f_pos)
49074 continue;
49075
49076 + if (gr_handle_sysctl(table, 0))
49077 + continue;
49078 +
49079 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
49080 if (res)
49081 return res;
49082 @@ -355,6 +369,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49083 if (IS_ERR(head))
49084 return PTR_ERR(head);
49085
49086 + if (table && gr_handle_sysctl(table, MAY_EXEC))
49087 + return -ENOENT;
49088 +
49089 generic_fillattr(inode, stat);
49090 if (table)
49091 stat->mode = (stat->mode & S_IFMT) | table->mode;
49092 @@ -370,17 +387,18 @@ static const struct file_operations proc_sys_file_operations = {
49093 };
49094
49095 static const struct file_operations proc_sys_dir_file_operations = {
49096 + .read = generic_read_dir,
49097 .readdir = proc_sys_readdir,
49098 .llseek = generic_file_llseek,
49099 };
49100
49101 -static const struct inode_operations proc_sys_inode_operations = {
49102 +const struct inode_operations proc_sys_inode_operations = {
49103 .permission = proc_sys_permission,
49104 .setattr = proc_sys_setattr,
49105 .getattr = proc_sys_getattr,
49106 };
49107
49108 -static const struct inode_operations proc_sys_dir_operations = {
49109 +const struct inode_operations proc_sys_dir_operations = {
49110 .lookup = proc_sys_lookup,
49111 .permission = proc_sys_permission,
49112 .setattr = proc_sys_setattr,
49113 diff --git a/fs/proc/root.c b/fs/proc/root.c
49114 index 9a8a2b7..3018df6 100644
49115 --- a/fs/proc/root.c
49116 +++ b/fs/proc/root.c
49117 @@ -123,7 +123,15 @@ void __init proc_root_init(void)
49118 #ifdef CONFIG_PROC_DEVICETREE
49119 proc_device_tree_init();
49120 #endif
49121 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49122 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49123 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49124 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49125 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49126 +#endif
49127 +#else
49128 proc_mkdir("bus", NULL);
49129 +#endif
49130 proc_sys_init();
49131 }
49132
49133 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49134 index c7d4ee6..41c5564 100644
49135 --- a/fs/proc/task_mmu.c
49136 +++ b/fs/proc/task_mmu.c
49137 @@ -51,8 +51,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49138 "VmExe:\t%8lu kB\n"
49139 "VmLib:\t%8lu kB\n"
49140 "VmPTE:\t%8lu kB\n"
49141 - "VmSwap:\t%8lu kB\n",
49142 - hiwater_vm << (PAGE_SHIFT-10),
49143 + "VmSwap:\t%8lu kB\n"
49144 +
49145 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49146 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49147 +#endif
49148 +
49149 + ,hiwater_vm << (PAGE_SHIFT-10),
49150 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49151 mm->locked_vm << (PAGE_SHIFT-10),
49152 hiwater_rss << (PAGE_SHIFT-10),
49153 @@ -60,7 +65,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49154 data << (PAGE_SHIFT-10),
49155 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49156 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49157 - swap << (PAGE_SHIFT-10));
49158 + swap << (PAGE_SHIFT-10)
49159 +
49160 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49161 + , mm->context.user_cs_base, mm->context.user_cs_limit
49162 +#endif
49163 +
49164 + );
49165 }
49166
49167 unsigned long task_vsize(struct mm_struct *mm)
49168 @@ -207,6 +218,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
49169 return ret;
49170 }
49171
49172 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49173 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49174 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49175 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49176 +#endif
49177 +
49178 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49179 {
49180 struct mm_struct *mm = vma->vm_mm;
49181 @@ -225,13 +242,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49182 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49183 }
49184
49185 - /* We don't show the stack guard page in /proc/maps */
49186 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49187 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49188 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49189 +#else
49190 start = vma->vm_start;
49191 - if (stack_guard_page_start(vma, start))
49192 - start += PAGE_SIZE;
49193 end = vma->vm_end;
49194 - if (stack_guard_page_end(vma, end))
49195 - end -= PAGE_SIZE;
49196 +#endif
49197
49198 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49199 start,
49200 @@ -240,7 +257,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49201 flags & VM_WRITE ? 'w' : '-',
49202 flags & VM_EXEC ? 'x' : '-',
49203 flags & VM_MAYSHARE ? 's' : 'p',
49204 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49205 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49206 +#else
49207 pgoff,
49208 +#endif
49209 MAJOR(dev), MINOR(dev), ino, &len);
49210
49211 /*
49212 @@ -249,7 +270,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49213 */
49214 if (file) {
49215 pad_len_spaces(m, len);
49216 - seq_path(m, &file->f_path, "\n");
49217 + seq_path(m, &file->f_path, "\n\\");
49218 } else {
49219 const char *name = arch_vma_name(vma);
49220 if (!name) {
49221 @@ -257,8 +278,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49222 if (vma->vm_start <= mm->brk &&
49223 vma->vm_end >= mm->start_brk) {
49224 name = "[heap]";
49225 - } else if (vma->vm_start <= mm->start_stack &&
49226 - vma->vm_end >= mm->start_stack) {
49227 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49228 + (vma->vm_start <= mm->start_stack &&
49229 + vma->vm_end >= mm->start_stack)) {
49230 name = "[stack]";
49231 }
49232 } else {
49233 @@ -433,11 +455,16 @@ static int show_smap(struct seq_file *m, void *v)
49234 };
49235
49236 memset(&mss, 0, sizeof mss);
49237 - mss.vma = vma;
49238 - /* mmap_sem is held in m_start */
49239 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49240 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49241 -
49242 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49243 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49244 +#endif
49245 + mss.vma = vma;
49246 + /* mmap_sem is held in m_start */
49247 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49248 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49249 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49250 + }
49251 +#endif
49252 show_map_vma(m, vma);
49253
49254 seq_printf(m,
49255 @@ -455,7 +482,11 @@ static int show_smap(struct seq_file *m, void *v)
49256 "KernelPageSize: %8lu kB\n"
49257 "MMUPageSize: %8lu kB\n"
49258 "Locked: %8lu kB\n",
49259 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49260 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49261 +#else
49262 (vma->vm_end - vma->vm_start) >> 10,
49263 +#endif
49264 mss.resident >> 10,
49265 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49266 mss.shared_clean >> 10,
49267 @@ -1031,7 +1062,7 @@ static int show_numa_map(struct seq_file *m, void *v)
49268
49269 if (file) {
49270 seq_printf(m, " file=");
49271 - seq_path(m, &file->f_path, "\n\t= ");
49272 + seq_path(m, &file->f_path, "\n\t\\= ");
49273 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49274 seq_printf(m, " heap");
49275 } else if (vma->vm_start <= mm->start_stack &&
49276 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49277 index 980de54..2a4db5f 100644
49278 --- a/fs/proc/task_nommu.c
49279 +++ b/fs/proc/task_nommu.c
49280 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49281 else
49282 bytes += kobjsize(mm);
49283
49284 - if (current->fs && current->fs->users > 1)
49285 + if (current->fs && atomic_read(&current->fs->users) > 1)
49286 sbytes += kobjsize(current->fs);
49287 else
49288 bytes += kobjsize(current->fs);
49289 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
49290
49291 if (file) {
49292 pad_len_spaces(m, len);
49293 - seq_path(m, &file->f_path, "");
49294 + seq_path(m, &file->f_path, "\n\\");
49295 } else if (mm) {
49296 if (vma->vm_start <= mm->start_stack &&
49297 vma->vm_end >= mm->start_stack) {
49298 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49299 index d67908b..d13f6a6 100644
49300 --- a/fs/quota/netlink.c
49301 +++ b/fs/quota/netlink.c
49302 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49303 void quota_send_warning(short type, unsigned int id, dev_t dev,
49304 const char warntype)
49305 {
49306 - static atomic_t seq;
49307 + static atomic_unchecked_t seq;
49308 struct sk_buff *skb;
49309 void *msg_head;
49310 int ret;
49311 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49312 "VFS: Not enough memory to send quota warning.\n");
49313 return;
49314 }
49315 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49316 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49317 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49318 if (!msg_head) {
49319 printk(KERN_ERR
49320 diff --git a/fs/readdir.c b/fs/readdir.c
49321 index 356f715..c918d38 100644
49322 --- a/fs/readdir.c
49323 +++ b/fs/readdir.c
49324 @@ -17,6 +17,7 @@
49325 #include <linux/security.h>
49326 #include <linux/syscalls.h>
49327 #include <linux/unistd.h>
49328 +#include <linux/namei.h>
49329
49330 #include <asm/uaccess.h>
49331
49332 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49333
49334 struct readdir_callback {
49335 struct old_linux_dirent __user * dirent;
49336 + struct file * file;
49337 int result;
49338 };
49339
49340 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49341 buf->result = -EOVERFLOW;
49342 return -EOVERFLOW;
49343 }
49344 +
49345 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49346 + return 0;
49347 +
49348 buf->result++;
49349 dirent = buf->dirent;
49350 if (!access_ok(VERIFY_WRITE, dirent,
49351 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49352
49353 buf.result = 0;
49354 buf.dirent = dirent;
49355 + buf.file = file;
49356
49357 error = vfs_readdir(file, fillonedir, &buf);
49358 if (buf.result)
49359 @@ -142,6 +149,7 @@ struct linux_dirent {
49360 struct getdents_callback {
49361 struct linux_dirent __user * current_dir;
49362 struct linux_dirent __user * previous;
49363 + struct file * file;
49364 int count;
49365 int error;
49366 };
49367 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49368 buf->error = -EOVERFLOW;
49369 return -EOVERFLOW;
49370 }
49371 +
49372 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49373 + return 0;
49374 +
49375 dirent = buf->previous;
49376 if (dirent) {
49377 if (__put_user(offset, &dirent->d_off))
49378 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49379 buf.previous = NULL;
49380 buf.count = count;
49381 buf.error = 0;
49382 + buf.file = file;
49383
49384 error = vfs_readdir(file, filldir, &buf);
49385 if (error >= 0)
49386 @@ -229,6 +242,7 @@ out:
49387 struct getdents_callback64 {
49388 struct linux_dirent64 __user * current_dir;
49389 struct linux_dirent64 __user * previous;
49390 + struct file *file;
49391 int count;
49392 int error;
49393 };
49394 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49395 buf->error = -EINVAL; /* only used if we fail.. */
49396 if (reclen > buf->count)
49397 return -EINVAL;
49398 +
49399 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49400 + return 0;
49401 +
49402 dirent = buf->previous;
49403 if (dirent) {
49404 if (__put_user(offset, &dirent->d_off))
49405 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49406
49407 buf.current_dir = dirent;
49408 buf.previous = NULL;
49409 + buf.file = file;
49410 buf.count = count;
49411 buf.error = 0;
49412
49413 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49414 error = buf.error;
49415 lastdirent = buf.previous;
49416 if (lastdirent) {
49417 - typeof(lastdirent->d_off) d_off = file->f_pos;
49418 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49419 if (__put_user(d_off, &lastdirent->d_off))
49420 error = -EFAULT;
49421 else
49422 diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
49423 index 133e935..349ef18 100644
49424 --- a/fs/reiserfs/dir.c
49425 +++ b/fs/reiserfs/dir.c
49426 @@ -75,6 +75,8 @@ int reiserfs_readdir_dentry(struct dentry *dentry, void *dirent,
49427 struct reiserfs_dir_entry de;
49428 int ret = 0;
49429
49430 + pax_track_stack();
49431 +
49432 reiserfs_write_lock(inode->i_sb);
49433
49434 reiserfs_check_lock_depth(inode->i_sb, "readdir");
49435 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49436 index 60c0804..d814f98 100644
49437 --- a/fs/reiserfs/do_balan.c
49438 +++ b/fs/reiserfs/do_balan.c
49439 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49440 return;
49441 }
49442
49443 - atomic_inc(&(fs_generation(tb->tb_sb)));
49444 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49445 do_balance_starts(tb);
49446
49447 /* balance leaf returns 0 except if combining L R and S into
49448 diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
49449 index a159ba5..0396a76 100644
49450 --- a/fs/reiserfs/journal.c
49451 +++ b/fs/reiserfs/journal.c
49452 @@ -2289,6 +2289,8 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
49453 struct buffer_head *bh;
49454 int i, j;
49455
49456 + pax_track_stack();
49457 +
49458 bh = __getblk(dev, block, bufsize);
49459 if (buffer_uptodate(bh))
49460 return (bh);
49461 diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
49462 index ef39232..0fa91ba 100644
49463 --- a/fs/reiserfs/namei.c
49464 +++ b/fs/reiserfs/namei.c
49465 @@ -1225,6 +1225,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
49466 unsigned long savelink = 1;
49467 struct timespec ctime;
49468
49469 + pax_track_stack();
49470 +
49471 /* three balancings: (1) old name removal, (2) new name insertion
49472 and (3) maybe "save" link insertion
49473 stat data updates: (1) old directory,
49474 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49475 index 7a99811..2c9286f 100644
49476 --- a/fs/reiserfs/procfs.c
49477 +++ b/fs/reiserfs/procfs.c
49478 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49479 "SMALL_TAILS " : "NO_TAILS ",
49480 replay_only(sb) ? "REPLAY_ONLY " : "",
49481 convert_reiserfs(sb) ? "CONV " : "",
49482 - atomic_read(&r->s_generation_counter),
49483 + atomic_read_unchecked(&r->s_generation_counter),
49484 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49485 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49486 SF(s_good_search_by_key_reada), SF(s_bmaps),
49487 @@ -299,6 +299,8 @@ static int show_journal(struct seq_file *m, struct super_block *sb)
49488 struct journal_params *jp = &rs->s_v1.s_journal;
49489 char b[BDEVNAME_SIZE];
49490
49491 + pax_track_stack();
49492 +
49493 seq_printf(m, /* on-disk fields */
49494 "jp_journal_1st_block: \t%i\n"
49495 "jp_journal_dev: \t%s[%x]\n"
49496 diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
49497 index 313d39d..3a5811b 100644
49498 --- a/fs/reiserfs/stree.c
49499 +++ b/fs/reiserfs/stree.c
49500 @@ -1196,6 +1196,8 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
49501 int iter = 0;
49502 #endif
49503
49504 + pax_track_stack();
49505 +
49506 BUG_ON(!th->t_trans_id);
49507
49508 init_tb_struct(th, &s_del_balance, sb, path,
49509 @@ -1333,6 +1335,8 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
49510 int retval;
49511 int quota_cut_bytes = 0;
49512
49513 + pax_track_stack();
49514 +
49515 BUG_ON(!th->t_trans_id);
49516
49517 le_key2cpu_key(&cpu_key, key);
49518 @@ -1562,6 +1566,8 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
49519 int quota_cut_bytes;
49520 loff_t tail_pos = 0;
49521
49522 + pax_track_stack();
49523 +
49524 BUG_ON(!th->t_trans_id);
49525
49526 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
49527 @@ -1957,6 +1963,8 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
49528 int retval;
49529 int fs_gen;
49530
49531 + pax_track_stack();
49532 +
49533 BUG_ON(!th->t_trans_id);
49534
49535 fs_gen = get_generation(inode->i_sb);
49536 @@ -2045,6 +2053,8 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
49537 int fs_gen = 0;
49538 int quota_bytes = 0;
49539
49540 + pax_track_stack();
49541 +
49542 BUG_ON(!th->t_trans_id);
49543
49544 if (inode) { /* Do we count quotas for item? */
49545 diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
49546 index 5e3527b..e55e569 100644
49547 --- a/fs/reiserfs/super.c
49548 +++ b/fs/reiserfs/super.c
49549 @@ -931,6 +931,8 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
49550 {.option_name = NULL}
49551 };
49552
49553 + pax_track_stack();
49554 +
49555 *blocks = 0;
49556 if (!options || !*options)
49557 /* use default configuration: create tails, journaling on, no
49558 diff --git a/fs/select.c b/fs/select.c
49559 index d33418f..f8e06bc 100644
49560 --- a/fs/select.c
49561 +++ b/fs/select.c
49562 @@ -20,6 +20,7 @@
49563 #include <linux/module.h>
49564 #include <linux/slab.h>
49565 #include <linux/poll.h>
49566 +#include <linux/security.h>
49567 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49568 #include <linux/file.h>
49569 #include <linux/fdtable.h>
49570 @@ -403,6 +404,8 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
49571 int retval, i, timed_out = 0;
49572 unsigned long slack = 0;
49573
49574 + pax_track_stack();
49575 +
49576 rcu_read_lock();
49577 retval = max_select_fd(n, fds);
49578 rcu_read_unlock();
49579 @@ -528,6 +531,8 @@ int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
49580 /* Allocate small arguments on the stack to save memory and be faster */
49581 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
49582
49583 + pax_track_stack();
49584 +
49585 ret = -EINVAL;
49586 if (n < 0)
49587 goto out_nofds;
49588 @@ -837,6 +842,9 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49589 struct poll_list *walk = head;
49590 unsigned long todo = nfds;
49591
49592 + pax_track_stack();
49593 +
49594 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49595 if (nfds > rlimit(RLIMIT_NOFILE))
49596 return -EINVAL;
49597
49598 diff --git a/fs/seq_file.c b/fs/seq_file.c
49599 index dba43c3..a99fb63 100644
49600 --- a/fs/seq_file.c
49601 +++ b/fs/seq_file.c
49602 @@ -76,7 +76,8 @@ static int traverse(struct seq_file *m, loff_t offset)
49603 return 0;
49604 }
49605 if (!m->buf) {
49606 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49607 + m->size = PAGE_SIZE;
49608 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
49609 if (!m->buf)
49610 return -ENOMEM;
49611 }
49612 @@ -116,7 +117,8 @@ static int traverse(struct seq_file *m, loff_t offset)
49613 Eoverflow:
49614 m->op->stop(m, p);
49615 kfree(m->buf);
49616 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49617 + m->size <<= 1;
49618 + m->buf = kmalloc(m->size, GFP_KERNEL);
49619 return !m->buf ? -ENOMEM : -EAGAIN;
49620 }
49621
49622 @@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49623 m->version = file->f_version;
49624 /* grab buffer if we didn't have one */
49625 if (!m->buf) {
49626 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49627 + m->size = PAGE_SIZE;
49628 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
49629 if (!m->buf)
49630 goto Enomem;
49631 }
49632 @@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49633 goto Fill;
49634 m->op->stop(m, p);
49635 kfree(m->buf);
49636 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49637 + m->size <<= 1;
49638 + m->buf = kmalloc(m->size, GFP_KERNEL);
49639 if (!m->buf)
49640 goto Enomem;
49641 m->count = 0;
49642 @@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
49643 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49644 void *data)
49645 {
49646 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49647 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49648 int res = -ENOMEM;
49649
49650 if (op) {
49651 diff --git a/fs/splice.c b/fs/splice.c
49652 index fa2defa..9a697a5 100644
49653 --- a/fs/splice.c
49654 +++ b/fs/splice.c
49655 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49656 pipe_lock(pipe);
49657
49658 for (;;) {
49659 - if (!pipe->readers) {
49660 + if (!atomic_read(&pipe->readers)) {
49661 send_sig(SIGPIPE, current, 0);
49662 if (!ret)
49663 ret = -EPIPE;
49664 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49665 do_wakeup = 0;
49666 }
49667
49668 - pipe->waiting_writers++;
49669 + atomic_inc(&pipe->waiting_writers);
49670 pipe_wait(pipe);
49671 - pipe->waiting_writers--;
49672 + atomic_dec(&pipe->waiting_writers);
49673 }
49674
49675 pipe_unlock(pipe);
49676 @@ -320,6 +320,8 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
49677 .spd_release = spd_release_page,
49678 };
49679
49680 + pax_track_stack();
49681 +
49682 if (splice_grow_spd(pipe, &spd))
49683 return -ENOMEM;
49684
49685 @@ -560,7 +562,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49686 old_fs = get_fs();
49687 set_fs(get_ds());
49688 /* The cast to a user pointer is valid due to the set_fs() */
49689 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49690 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49691 set_fs(old_fs);
49692
49693 return res;
49694 @@ -575,7 +577,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49695 old_fs = get_fs();
49696 set_fs(get_ds());
49697 /* The cast to a user pointer is valid due to the set_fs() */
49698 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49699 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49700 set_fs(old_fs);
49701
49702 return res;
49703 @@ -603,6 +605,8 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49704 .spd_release = spd_release_page,
49705 };
49706
49707 + pax_track_stack();
49708 +
49709 if (splice_grow_spd(pipe, &spd))
49710 return -ENOMEM;
49711
49712 @@ -626,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49713 goto err;
49714
49715 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49716 - vec[i].iov_base = (void __user *) page_address(page);
49717 + vec[i].iov_base = (void __force_user *) page_address(page);
49718 vec[i].iov_len = this_len;
49719 spd.pages[i] = page;
49720 spd.nr_pages++;
49721 @@ -846,10 +850,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49722 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49723 {
49724 while (!pipe->nrbufs) {
49725 - if (!pipe->writers)
49726 + if (!atomic_read(&pipe->writers))
49727 return 0;
49728
49729 - if (!pipe->waiting_writers && sd->num_spliced)
49730 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49731 return 0;
49732
49733 if (sd->flags & SPLICE_F_NONBLOCK)
49734 @@ -1182,7 +1186,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49735 * out of the pipe right after the splice_to_pipe(). So set
49736 * PIPE_READERS appropriately.
49737 */
49738 - pipe->readers = 1;
49739 + atomic_set(&pipe->readers, 1);
49740
49741 current->splice_pipe = pipe;
49742 }
49743 @@ -1619,6 +1623,8 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,
49744 };
49745 long ret;
49746
49747 + pax_track_stack();
49748 +
49749 pipe = get_pipe_info(file);
49750 if (!pipe)
49751 return -EBADF;
49752 @@ -1734,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49753 ret = -ERESTARTSYS;
49754 break;
49755 }
49756 - if (!pipe->writers)
49757 + if (!atomic_read(&pipe->writers))
49758 break;
49759 - if (!pipe->waiting_writers) {
49760 + if (!atomic_read(&pipe->waiting_writers)) {
49761 if (flags & SPLICE_F_NONBLOCK) {
49762 ret = -EAGAIN;
49763 break;
49764 @@ -1768,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49765 pipe_lock(pipe);
49766
49767 while (pipe->nrbufs >= pipe->buffers) {
49768 - if (!pipe->readers) {
49769 + if (!atomic_read(&pipe->readers)) {
49770 send_sig(SIGPIPE, current, 0);
49771 ret = -EPIPE;
49772 break;
49773 @@ -1781,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49774 ret = -ERESTARTSYS;
49775 break;
49776 }
49777 - pipe->waiting_writers++;
49778 + atomic_inc(&pipe->waiting_writers);
49779 pipe_wait(pipe);
49780 - pipe->waiting_writers--;
49781 + atomic_dec(&pipe->waiting_writers);
49782 }
49783
49784 pipe_unlock(pipe);
49785 @@ -1819,14 +1825,14 @@ retry:
49786 pipe_double_lock(ipipe, opipe);
49787
49788 do {
49789 - if (!opipe->readers) {
49790 + if (!atomic_read(&opipe->readers)) {
49791 send_sig(SIGPIPE, current, 0);
49792 if (!ret)
49793 ret = -EPIPE;
49794 break;
49795 }
49796
49797 - if (!ipipe->nrbufs && !ipipe->writers)
49798 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49799 break;
49800
49801 /*
49802 @@ -1923,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49803 pipe_double_lock(ipipe, opipe);
49804
49805 do {
49806 - if (!opipe->readers) {
49807 + if (!atomic_read(&opipe->readers)) {
49808 send_sig(SIGPIPE, current, 0);
49809 if (!ret)
49810 ret = -EPIPE;
49811 @@ -1968,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49812 * return EAGAIN if we have the potential of some data in the
49813 * future, otherwise just return 0
49814 */
49815 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49816 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49817 ret = -EAGAIN;
49818
49819 pipe_unlock(ipipe);
49820 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49821 index 1ad8c93..6633545 100644
49822 --- a/fs/sysfs/file.c
49823 +++ b/fs/sysfs/file.c
49824 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49825
49826 struct sysfs_open_dirent {
49827 atomic_t refcnt;
49828 - atomic_t event;
49829 + atomic_unchecked_t event;
49830 wait_queue_head_t poll;
49831 struct list_head buffers; /* goes through sysfs_buffer.list */
49832 };
49833 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49834 if (!sysfs_get_active(attr_sd))
49835 return -ENODEV;
49836
49837 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49838 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49839 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49840
49841 sysfs_put_active(attr_sd);
49842 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49843 return -ENOMEM;
49844
49845 atomic_set(&new_od->refcnt, 0);
49846 - atomic_set(&new_od->event, 1);
49847 + atomic_set_unchecked(&new_od->event, 1);
49848 init_waitqueue_head(&new_od->poll);
49849 INIT_LIST_HEAD(&new_od->buffers);
49850 goto retry;
49851 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49852
49853 sysfs_put_active(attr_sd);
49854
49855 - if (buffer->event != atomic_read(&od->event))
49856 + if (buffer->event != atomic_read_unchecked(&od->event))
49857 goto trigger;
49858
49859 return DEFAULT_POLLMASK;
49860 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49861
49862 od = sd->s_attr.open;
49863 if (od) {
49864 - atomic_inc(&od->event);
49865 + atomic_inc_unchecked(&od->event);
49866 wake_up_interruptible(&od->poll);
49867 }
49868
49869 diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
49870 index e34f0d9..740ea7b 100644
49871 --- a/fs/sysfs/mount.c
49872 +++ b/fs/sysfs/mount.c
49873 @@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
49874 .s_name = "",
49875 .s_count = ATOMIC_INIT(1),
49876 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT),
49877 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49878 + .s_mode = S_IFDIR | S_IRWXU,
49879 +#else
49880 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
49881 +#endif
49882 .s_ino = 1,
49883 };
49884
49885 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49886 index a7ac78f..02158e1 100644
49887 --- a/fs/sysfs/symlink.c
49888 +++ b/fs/sysfs/symlink.c
49889 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49890
49891 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49892 {
49893 - char *page = nd_get_link(nd);
49894 + const char *page = nd_get_link(nd);
49895 if (!IS_ERR(page))
49896 free_page((unsigned long)page);
49897 }
49898 diff --git a/fs/udf/inode.c b/fs/udf/inode.c
49899 index 262050f..d2df565 100644
49900 --- a/fs/udf/inode.c
49901 +++ b/fs/udf/inode.c
49902 @@ -576,6 +576,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
49903 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
49904 int lastblock = 0;
49905
49906 + pax_track_stack();
49907 +
49908 prev_epos.offset = udf_file_entry_alloc_offset(inode);
49909 prev_epos.block = iinfo->i_location;
49910 prev_epos.bh = NULL;
49911 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49912 index 9215700..bf1f68e 100644
49913 --- a/fs/udf/misc.c
49914 +++ b/fs/udf/misc.c
49915 @@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49916
49917 u8 udf_tag_checksum(const struct tag *t)
49918 {
49919 - u8 *data = (u8 *)t;
49920 + const u8 *data = (const u8 *)t;
49921 u8 checksum = 0;
49922 int i;
49923 for (i = 0; i < sizeof(struct tag); ++i)
49924 diff --git a/fs/utimes.c b/fs/utimes.c
49925 index ba653f3..06ea4b1 100644
49926 --- a/fs/utimes.c
49927 +++ b/fs/utimes.c
49928 @@ -1,6 +1,7 @@
49929 #include <linux/compiler.h>
49930 #include <linux/file.h>
49931 #include <linux/fs.h>
49932 +#include <linux/security.h>
49933 #include <linux/linkage.h>
49934 #include <linux/mount.h>
49935 #include <linux/namei.h>
49936 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49937 goto mnt_drop_write_and_out;
49938 }
49939 }
49940 +
49941 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49942 + error = -EACCES;
49943 + goto mnt_drop_write_and_out;
49944 + }
49945 +
49946 mutex_lock(&inode->i_mutex);
49947 error = notify_change(path->dentry, &newattrs);
49948 mutex_unlock(&inode->i_mutex);
49949 diff --git a/fs/xattr.c b/fs/xattr.c
49950 index f060663..def7007 100644
49951 --- a/fs/xattr.c
49952 +++ b/fs/xattr.c
49953 @@ -254,7 +254,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49954 * Extended attribute SET operations
49955 */
49956 static long
49957 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49958 +setxattr(struct path *path, const char __user *name, const void __user *value,
49959 size_t size, int flags)
49960 {
49961 int error;
49962 @@ -278,7 +278,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49963 return PTR_ERR(kvalue);
49964 }
49965
49966 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49967 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49968 + error = -EACCES;
49969 + goto out;
49970 + }
49971 +
49972 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49973 +out:
49974 kfree(kvalue);
49975 return error;
49976 }
49977 @@ -295,7 +301,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49978 return error;
49979 error = mnt_want_write(path.mnt);
49980 if (!error) {
49981 - error = setxattr(path.dentry, name, value, size, flags);
49982 + error = setxattr(&path, name, value, size, flags);
49983 mnt_drop_write(path.mnt);
49984 }
49985 path_put(&path);
49986 @@ -314,7 +320,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49987 return error;
49988 error = mnt_want_write(path.mnt);
49989 if (!error) {
49990 - error = setxattr(path.dentry, name, value, size, flags);
49991 + error = setxattr(&path, name, value, size, flags);
49992 mnt_drop_write(path.mnt);
49993 }
49994 path_put(&path);
49995 @@ -325,17 +331,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49996 const void __user *,value, size_t, size, int, flags)
49997 {
49998 struct file *f;
49999 - struct dentry *dentry;
50000 int error = -EBADF;
50001
50002 f = fget(fd);
50003 if (!f)
50004 return error;
50005 - dentry = f->f_path.dentry;
50006 - audit_inode(NULL, dentry);
50007 + audit_inode(NULL, f->f_path.dentry);
50008 error = mnt_want_write_file(f);
50009 if (!error) {
50010 - error = setxattr(dentry, name, value, size, flags);
50011 + error = setxattr(&f->f_path, name, value, size, flags);
50012 mnt_drop_write(f->f_path.mnt);
50013 }
50014 fput(f);
50015 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50016 index 8d5a506..7f62712 100644
50017 --- a/fs/xattr_acl.c
50018 +++ b/fs/xattr_acl.c
50019 @@ -17,8 +17,8 @@
50020 struct posix_acl *
50021 posix_acl_from_xattr(const void *value, size_t size)
50022 {
50023 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50024 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50025 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50026 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50027 int count;
50028 struct posix_acl *acl;
50029 struct posix_acl_entry *acl_e;
50030 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50031 index 452a291..91a95f3b 100644
50032 --- a/fs/xfs/xfs_bmap.c
50033 +++ b/fs/xfs/xfs_bmap.c
50034 @@ -250,7 +250,7 @@ xfs_bmap_validate_ret(
50035 int nmap,
50036 int ret_nmap);
50037 #else
50038 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50039 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50040 #endif /* DEBUG */
50041
50042 STATIC int
50043 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50044 index 79d05e8..e3e5861 100644
50045 --- a/fs/xfs/xfs_dir2_sf.c
50046 +++ b/fs/xfs/xfs_dir2_sf.c
50047 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
50048 }
50049
50050 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50051 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50052 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50053 + char name[sfep->namelen];
50054 + memcpy(name, sfep->name, sfep->namelen);
50055 + if (filldir(dirent, name, sfep->namelen,
50056 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50057 + *offset = off & 0x7fffffff;
50058 + return 0;
50059 + }
50060 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50061 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50062 *offset = off & 0x7fffffff;
50063 return 0;
50064 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50065 index f7ce7de..e1a5db0 100644
50066 --- a/fs/xfs/xfs_ioctl.c
50067 +++ b/fs/xfs/xfs_ioctl.c
50068 @@ -128,7 +128,7 @@ xfs_find_handle(
50069 }
50070
50071 error = -EFAULT;
50072 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50073 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50074 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50075 goto out_put;
50076
50077 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50078 index 474920b..97169a9 100644
50079 --- a/fs/xfs/xfs_iops.c
50080 +++ b/fs/xfs/xfs_iops.c
50081 @@ -446,7 +446,7 @@ xfs_vn_put_link(
50082 struct nameidata *nd,
50083 void *p)
50084 {
50085 - char *s = nd_get_link(nd);
50086 + const char *s = nd_get_link(nd);
50087
50088 if (!IS_ERR(s))
50089 kfree(s);
50090 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50091 new file mode 100644
50092 index 0000000..4639511
50093 --- /dev/null
50094 +++ b/grsecurity/Kconfig
50095 @@ -0,0 +1,1051 @@
50096 +#
50097 +# grecurity configuration
50098 +#
50099 +
50100 +menu "Grsecurity"
50101 +
50102 +config GRKERNSEC
50103 + bool "Grsecurity"
50104 + select CRYPTO
50105 + select CRYPTO_SHA256
50106 + help
50107 + If you say Y here, you will be able to configure many features
50108 + that will enhance the security of your system. It is highly
50109 + recommended that you say Y here and read through the help
50110 + for each option so that you fully understand the features and
50111 + can evaluate their usefulness for your machine.
50112 +
50113 +choice
50114 + prompt "Security Level"
50115 + depends on GRKERNSEC
50116 + default GRKERNSEC_CUSTOM
50117 +
50118 +config GRKERNSEC_LOW
50119 + bool "Low"
50120 + select GRKERNSEC_LINK
50121 + select GRKERNSEC_FIFO
50122 + select GRKERNSEC_RANDNET
50123 + select GRKERNSEC_DMESG
50124 + select GRKERNSEC_CHROOT
50125 + select GRKERNSEC_CHROOT_CHDIR
50126 +
50127 + help
50128 + If you choose this option, several of the grsecurity options will
50129 + be enabled that will give you greater protection against a number
50130 + of attacks, while assuring that none of your software will have any
50131 + conflicts with the additional security measures. If you run a lot
50132 + of unusual software, or you are having problems with the higher
50133 + security levels, you should say Y here. With this option, the
50134 + following features are enabled:
50135 +
50136 + - Linking restrictions
50137 + - FIFO restrictions
50138 + - Restricted dmesg
50139 + - Enforced chdir("/") on chroot
50140 + - Runtime module disabling
50141 +
50142 +config GRKERNSEC_MEDIUM
50143 + bool "Medium"
50144 + select PAX
50145 + select PAX_EI_PAX
50146 + select PAX_PT_PAX_FLAGS
50147 + select PAX_HAVE_ACL_FLAGS
50148 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
50149 + select GRKERNSEC_CHROOT
50150 + select GRKERNSEC_CHROOT_SYSCTL
50151 + select GRKERNSEC_LINK
50152 + select GRKERNSEC_FIFO
50153 + select GRKERNSEC_DMESG
50154 + select GRKERNSEC_RANDNET
50155 + select GRKERNSEC_FORKFAIL
50156 + select GRKERNSEC_TIME
50157 + select GRKERNSEC_SIGNAL
50158 + select GRKERNSEC_CHROOT
50159 + select GRKERNSEC_CHROOT_UNIX
50160 + select GRKERNSEC_CHROOT_MOUNT
50161 + select GRKERNSEC_CHROOT_PIVOT
50162 + select GRKERNSEC_CHROOT_DOUBLE
50163 + select GRKERNSEC_CHROOT_CHDIR
50164 + select GRKERNSEC_CHROOT_MKNOD
50165 + select GRKERNSEC_PROC
50166 + select GRKERNSEC_PROC_USERGROUP
50167 + select PAX_RANDUSTACK
50168 + select PAX_ASLR
50169 + select PAX_RANDMMAP
50170 + select PAX_REFCOUNT if (X86 || SPARC64)
50171 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
50172 +
50173 + help
50174 + If you say Y here, several features in addition to those included
50175 + in the low additional security level will be enabled. These
50176 + features provide even more security to your system, though in rare
50177 + cases they may be incompatible with very old or poorly written
50178 + software. If you enable this option, make sure that your auth
50179 + service (identd) is running as gid 1001. With this option,
50180 + the following features (in addition to those provided in the
50181 + low additional security level) will be enabled:
50182 +
50183 + - Failed fork logging
50184 + - Time change logging
50185 + - Signal logging
50186 + - Deny mounts in chroot
50187 + - Deny double chrooting
50188 + - Deny sysctl writes in chroot
50189 + - Deny mknod in chroot
50190 + - Deny access to abstract AF_UNIX sockets out of chroot
50191 + - Deny pivot_root in chroot
50192 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
50193 + - /proc restrictions with special GID set to 10 (usually wheel)
50194 + - Address Space Layout Randomization (ASLR)
50195 + - Prevent exploitation of most refcount overflows
50196 + - Bounds checking of copying between the kernel and userland
50197 +
50198 +config GRKERNSEC_HIGH
50199 + bool "High"
50200 + select GRKERNSEC_LINK
50201 + select GRKERNSEC_FIFO
50202 + select GRKERNSEC_DMESG
50203 + select GRKERNSEC_FORKFAIL
50204 + select GRKERNSEC_TIME
50205 + select GRKERNSEC_SIGNAL
50206 + select GRKERNSEC_CHROOT
50207 + select GRKERNSEC_CHROOT_SHMAT
50208 + select GRKERNSEC_CHROOT_UNIX
50209 + select GRKERNSEC_CHROOT_MOUNT
50210 + select GRKERNSEC_CHROOT_FCHDIR
50211 + select GRKERNSEC_CHROOT_PIVOT
50212 + select GRKERNSEC_CHROOT_DOUBLE
50213 + select GRKERNSEC_CHROOT_CHDIR
50214 + select GRKERNSEC_CHROOT_MKNOD
50215 + select GRKERNSEC_CHROOT_CAPS
50216 + select GRKERNSEC_CHROOT_SYSCTL
50217 + select GRKERNSEC_CHROOT_FINDTASK
50218 + select GRKERNSEC_SYSFS_RESTRICT
50219 + select GRKERNSEC_PROC
50220 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
50221 + select GRKERNSEC_HIDESYM
50222 + select GRKERNSEC_BRUTE
50223 + select GRKERNSEC_PROC_USERGROUP
50224 + select GRKERNSEC_KMEM
50225 + select GRKERNSEC_RESLOG
50226 + select GRKERNSEC_RANDNET
50227 + select GRKERNSEC_PROC_ADD
50228 + select GRKERNSEC_CHROOT_CHMOD
50229 + select GRKERNSEC_CHROOT_NICE
50230 + select GRKERNSEC_SETXID
50231 + select GRKERNSEC_AUDIT_MOUNT
50232 + select GRKERNSEC_MODHARDEN if (MODULES)
50233 + select GRKERNSEC_HARDEN_PTRACE
50234 + select GRKERNSEC_VM86 if (X86_32)
50235 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
50236 + select PAX
50237 + select PAX_RANDUSTACK
50238 + select PAX_ASLR
50239 + select PAX_RANDMMAP
50240 + select PAX_NOEXEC
50241 + select PAX_MPROTECT
50242 + select PAX_EI_PAX
50243 + select PAX_PT_PAX_FLAGS
50244 + select PAX_HAVE_ACL_FLAGS
50245 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
50246 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
50247 + select PAX_RANDKSTACK if (X86_TSC && X86)
50248 + select PAX_SEGMEXEC if (X86_32)
50249 + select PAX_PAGEEXEC
50250 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
50251 + select PAX_EMUTRAMP if (PARISC)
50252 + select PAX_EMUSIGRT if (PARISC)
50253 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
50254 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
50255 + select PAX_REFCOUNT if (X86 || SPARC64)
50256 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
50257 + help
50258 + If you say Y here, many of the features of grsecurity will be
50259 + enabled, which will protect you against many kinds of attacks
50260 + against your system. The heightened security comes at a cost
50261 + of an increased chance of incompatibilities with rare software
50262 + on your machine. Since this security level enables PaX, you should
50263 + view <http://pax.grsecurity.net> and read about the PaX
50264 + project. While you are there, download chpax and run it on
50265 + binaries that cause problems with PaX. Also remember that
50266 + since the /proc restrictions are enabled, you must run your
50267 + identd as gid 1001. This security level enables the following
50268 + features in addition to those listed in the low and medium
50269 + security levels:
50270 +
50271 + - Additional /proc restrictions
50272 + - Chmod restrictions in chroot
50273 + - No signals, ptrace, or viewing of processes outside of chroot
50274 + - Capability restrictions in chroot
50275 + - Deny fchdir out of chroot
50276 + - Priority restrictions in chroot
50277 + - Segmentation-based implementation of PaX
50278 + - Mprotect restrictions
50279 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
50280 + - Kernel stack randomization
50281 + - Mount/unmount/remount logging
50282 + - Kernel symbol hiding
50283 + - Hardening of module auto-loading
50284 + - Ptrace restrictions
50285 + - Restricted vm86 mode
50286 + - Restricted sysfs/debugfs
50287 + - Active kernel exploit response
50288 +
50289 +config GRKERNSEC_CUSTOM
50290 + bool "Custom"
50291 + help
50292 + If you say Y here, you will be able to configure every grsecurity
50293 + option, which allows you to enable many more features that aren't
50294 + covered in the basic security levels. These additional features
50295 + include TPE, socket restrictions, and the sysctl system for
50296 + grsecurity. It is advised that you read through the help for
50297 + each option to determine its usefulness in your situation.
50298 +
50299 +endchoice
50300 +
50301 +menu "Address Space Protection"
50302 +depends on GRKERNSEC
50303 +
50304 +config GRKERNSEC_KMEM
50305 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50306 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50307 + help
50308 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50309 + be written to or read from to modify or leak the contents of the running
50310 + kernel. /dev/port will also not be allowed to be opened. If you have module
50311 + support disabled, enabling this will close up four ways that are
50312 + currently used to insert malicious code into the running kernel.
50313 + Even with all these features enabled, we still highly recommend that
50314 + you use the RBAC system, as it is still possible for an attacker to
50315 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50316 + If you are not using XFree86, you may be able to stop this additional
50317 + case by enabling the 'Disable privileged I/O' option. Though nothing
50318 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50319 + but only to video memory, which is the only writing we allow in this
50320 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50321 + not be allowed to mprotect it with PROT_WRITE later.
50322 + It is highly recommended that you say Y here if you meet all the
50323 + conditions above.
50324 +
50325 +config GRKERNSEC_VM86
50326 + bool "Restrict VM86 mode"
50327 + depends on X86_32
50328 +
50329 + help
50330 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50331 + make use of a special execution mode on 32bit x86 processors called
50332 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50333 + video cards and will still work with this option enabled. The purpose
50334 + of the option is to prevent exploitation of emulation errors in
50335 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50336 + Nearly all users should be able to enable this option.
50337 +
50338 +config GRKERNSEC_IO
50339 + bool "Disable privileged I/O"
50340 + depends on X86
50341 + select RTC_CLASS
50342 + select RTC_INTF_DEV
50343 + select RTC_DRV_CMOS
50344 +
50345 + help
50346 + If you say Y here, all ioperm and iopl calls will return an error.
50347 + Ioperm and iopl can be used to modify the running kernel.
50348 + Unfortunately, some programs need this access to operate properly,
50349 + the most notable of which are XFree86 and hwclock. hwclock can be
50350 + remedied by having RTC support in the kernel, so real-time
50351 + clock support is enabled if this option is enabled, to ensure
50352 + that hwclock operates correctly. XFree86 still will not
50353 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50354 + IF YOU USE XFree86. If you use XFree86 and you still want to
50355 + protect your kernel against modification, use the RBAC system.
50356 +
50357 +config GRKERNSEC_PROC_MEMMAP
50358 + bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
50359 + default y if (PAX_NOEXEC || PAX_ASLR)
50360 + depends on PAX_NOEXEC || PAX_ASLR
50361 + help
50362 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50363 + give no information about the addresses of its mappings if
50364 + PaX features that rely on random addresses are enabled on the task.
50365 + If you use PaX it is greatly recommended that you say Y here as it
50366 + closes up a hole that makes the full ASLR useless for suid
50367 + binaries.
50368 +
50369 +config GRKERNSEC_BRUTE
50370 + bool "Deter exploit bruteforcing"
50371 + help
50372 + If you say Y here, attempts to bruteforce exploits against forking
50373 + daemons such as apache or sshd, as well as against suid/sgid binaries
50374 + will be deterred. When a child of a forking daemon is killed by PaX
50375 + or crashes due to an illegal instruction or other suspicious signal,
50376 + the parent process will be delayed 30 seconds upon every subsequent
50377 + fork until the administrator is able to assess the situation and
50378 + restart the daemon.
50379 + In the suid/sgid case, the attempt is logged, the user has all their
50380 + processes terminated, and they are prevented from executing any further
50381 + processes for 15 minutes.
50382 + It is recommended that you also enable signal logging in the auditing
50383 + section so that logs are generated when a process triggers a suspicious
50384 + signal.
50385 + If the sysctl option is enabled, a sysctl option with name
50386 + "deter_bruteforce" is created.
50387 +
50388 +
50389 +config GRKERNSEC_MODHARDEN
50390 + bool "Harden module auto-loading"
50391 + depends on MODULES
50392 + help
50393 + If you say Y here, module auto-loading in response to use of some
50394 + feature implemented by an unloaded module will be restricted to
50395 + root users. Enabling this option helps defend against attacks
50396 + by unprivileged users who abuse the auto-loading behavior to
50397 + cause a vulnerable module to load that is then exploited.
50398 +
50399 + If this option prevents a legitimate use of auto-loading for a
50400 + non-root user, the administrator can execute modprobe manually
50401 + with the exact name of the module mentioned in the alert log.
50402 + Alternatively, the administrator can add the module to the list
50403 + of modules loaded at boot by modifying init scripts.
50404 +
50405 + Modification of init scripts will most likely be needed on
50406 + Ubuntu servers with encrypted home directory support enabled,
50407 + as the first non-root user logging in will cause the ecb(aes),
50408 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50409 +
50410 +config GRKERNSEC_HIDESYM
50411 + bool "Hide kernel symbols"
50412 + help
50413 + If you say Y here, getting information on loaded modules, and
50414 + displaying all kernel symbols through a syscall will be restricted
50415 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50416 + /proc/kallsyms will be restricted to the root user. The RBAC
50417 + system can hide that entry even from root.
50418 +
50419 + This option also prevents leaking of kernel addresses through
50420 + several /proc entries.
50421 +
50422 + Note that this option is only effective provided the following
50423 + conditions are met:
50424 + 1) The kernel using grsecurity is not precompiled by some distribution
50425 + 2) You have also enabled GRKERNSEC_DMESG
50426 + 3) You are using the RBAC system and hiding other files such as your
50427 + kernel image and System.map. Alternatively, enabling this option
50428 + causes the permissions on /boot, /lib/modules, and the kernel
50429 + source directory to change at compile time to prevent
50430 + reading by non-root users.
50431 + If the above conditions are met, this option will aid in providing a
50432 + useful protection against local kernel exploitation of overflows
50433 + and arbitrary read/write vulnerabilities.
50434 +
50435 +config GRKERNSEC_KERN_LOCKOUT
50436 + bool "Active kernel exploit response"
50437 + depends on X86 || ARM || PPC || SPARC
50438 + help
50439 + If you say Y here, when a PaX alert is triggered due to suspicious
50440 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50441 + or an OOPs occurs due to bad memory accesses, instead of just
50442 + terminating the offending process (and potentially allowing
50443 + a subsequent exploit from the same user), we will take one of two
50444 + actions:
50445 + If the user was root, we will panic the system
50446 + If the user was non-root, we will log the attempt, terminate
50447 + all processes owned by the user, then prevent them from creating
50448 + any new processes until the system is restarted
50449 + This deters repeated kernel exploitation/bruteforcing attempts
50450 + and is useful for later forensics.
50451 +
50452 +endmenu
50453 +menu "Role Based Access Control Options"
50454 +depends on GRKERNSEC
50455 +
50456 +config GRKERNSEC_RBAC_DEBUG
50457 + bool
50458 +
50459 +config GRKERNSEC_NO_RBAC
50460 + bool "Disable RBAC system"
50461 + help
50462 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50463 + preventing the RBAC system from being enabled. You should only say Y
50464 + here if you have no intention of using the RBAC system, so as to prevent
50465 + an attacker with root access from misusing the RBAC system to hide files
50466 + and processes when loadable module support and /dev/[k]mem have been
50467 + locked down.
50468 +
50469 +config GRKERNSEC_ACL_HIDEKERN
50470 + bool "Hide kernel processes"
50471 + help
50472 + If you say Y here, all kernel threads will be hidden to all
50473 + processes but those whose subject has the "view hidden processes"
50474 + flag.
50475 +
50476 +config GRKERNSEC_ACL_MAXTRIES
50477 + int "Maximum tries before password lockout"
50478 + default 3
50479 + help
50480 + This option enforces the maximum number of times a user can attempt
50481 + to authorize themselves with the grsecurity RBAC system before being
50482 + denied the ability to attempt authorization again for a specified time.
50483 + The lower the number, the harder it will be to brute-force a password.
50484 +
50485 +config GRKERNSEC_ACL_TIMEOUT
50486 + int "Time to wait after max password tries, in seconds"
50487 + default 30
50488 + help
50489 + This option specifies the time the user must wait after attempting to
50490 + authorize to the RBAC system with the maximum number of invalid
50491 + passwords. The higher the number, the harder it will be to brute-force
50492 + a password.
50493 +
50494 +endmenu
50495 +menu "Filesystem Protections"
50496 +depends on GRKERNSEC
50497 +
50498 +config GRKERNSEC_PROC
50499 + bool "Proc restrictions"
50500 + help
50501 + If you say Y here, the permissions of the /proc filesystem
50502 + will be altered to enhance system security and privacy. You MUST
50503 + choose either a user only restriction or a user and group restriction.
50504 + Depending upon the option you choose, you can either restrict users to
50505 + see only the processes they themselves run, or choose a group that can
50506 + view all processes and files normally restricted to root if you choose
50507 + the "restrict to user only" option. NOTE: If you're running identd as
50508 + a non-root user, you will have to run it as the group you specify here.
50509 +
50510 +config GRKERNSEC_PROC_USER
50511 + bool "Restrict /proc to user only"
50512 + depends on GRKERNSEC_PROC
50513 + help
50514 + If you say Y here, non-root users will only be able to view their own
50515 + processes, and restricts them from viewing network-related information,
50516 + and viewing kernel symbol and module information.
50517 +
50518 +config GRKERNSEC_PROC_USERGROUP
50519 + bool "Allow special group"
50520 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50521 + help
50522 + If you say Y here, you will be able to select a group that will be
50523 + able to view all processes and network-related information. If you've
50524 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50525 + remain hidden. This option is useful if you want to run identd as
50526 + a non-root user.
50527 +
50528 +config GRKERNSEC_PROC_GID
50529 + int "GID for special group"
50530 + depends on GRKERNSEC_PROC_USERGROUP
50531 + default 1001
50532 +
50533 +config GRKERNSEC_PROC_ADD
50534 + bool "Additional restrictions"
50535 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50536 + help
50537 + If you say Y here, additional restrictions will be placed on
50538 + /proc that keep normal users from viewing device information and
50539 + slabinfo information that could be useful for exploits.
50540 +
50541 +config GRKERNSEC_LINK
50542 + bool "Linking restrictions"
50543 + help
50544 + If you say Y here, /tmp race exploits will be prevented, since users
50545 + will no longer be able to follow symlinks owned by other users in
50546 + world-writable +t directories (e.g. /tmp), unless the owner of the
50547 + symlink is the owner of the directory. users will also not be
50548 + able to hardlink to files they do not own. If the sysctl option is
50549 + enabled, a sysctl option with name "linking_restrictions" is created.
50550 +
50551 +config GRKERNSEC_FIFO
50552 + bool "FIFO restrictions"
50553 + help
50554 + If you say Y here, users will not be able to write to FIFOs they don't
50555 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50556 + the FIFO is the same owner of the directory it's held in. If the sysctl
50557 + option is enabled, a sysctl option with name "fifo_restrictions" is
50558 + created.
50559 +
50560 +config GRKERNSEC_SYSFS_RESTRICT
50561 + bool "Sysfs/debugfs restriction"
50562 + depends on SYSFS
50563 + help
50564 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50565 + any filesystem normally mounted under it (e.g. debugfs) will only
50566 + be accessible by root. These filesystems generally provide access
50567 + to hardware and debug information that isn't appropriate for unprivileged
50568 + users of the system. Sysfs and debugfs have also become a large source
50569 + of new vulnerabilities, ranging from infoleaks to local compromise.
50570 + There has been very little oversight with an eye toward security involved
50571 + in adding new exporters of information to these filesystems, so their
50572 + use is discouraged.
50573 + This option is equivalent to a chmod 0700 of the mount paths.
50574 +
50575 +config GRKERNSEC_ROFS
50576 + bool "Runtime read-only mount protection"
50577 + help
50578 + If you say Y here, a sysctl option with name "romount_protect" will
50579 + be created. By setting this option to 1 at runtime, filesystems
50580 + will be protected in the following ways:
50581 + * No new writable mounts will be allowed
50582 + * Existing read-only mounts won't be able to be remounted read/write
50583 + * Write operations will be denied on all block devices
50584 + This option acts independently of grsec_lock: once it is set to 1,
50585 + it cannot be turned off. Therefore, please be mindful of the resulting
50586 + behavior if this option is enabled in an init script on a read-only
50587 + filesystem. This feature is mainly intended for secure embedded systems.
50588 +
50589 +config GRKERNSEC_CHROOT
50590 + bool "Chroot jail restrictions"
50591 + help
50592 + If you say Y here, you will be able to choose several options that will
50593 + make breaking out of a chrooted jail much more difficult. If you
50594 + encounter no software incompatibilities with the following options, it
50595 + is recommended that you enable each one.
50596 +
50597 +config GRKERNSEC_CHROOT_MOUNT
50598 + bool "Deny mounts"
50599 + depends on GRKERNSEC_CHROOT
50600 + help
50601 + If you say Y here, processes inside a chroot will not be able to
50602 + mount or remount filesystems. If the sysctl option is enabled, a
50603 + sysctl option with name "chroot_deny_mount" is created.
50604 +
50605 +config GRKERNSEC_CHROOT_DOUBLE
50606 + bool "Deny double-chroots"
50607 + depends on GRKERNSEC_CHROOT
50608 + help
50609 + If you say Y here, processes inside a chroot will not be able to chroot
50610 + again outside the chroot. This is a widely used method of breaking
50611 + out of a chroot jail and should not be allowed. If the sysctl
50612 + option is enabled, a sysctl option with name
50613 + "chroot_deny_chroot" is created.
50614 +
50615 +config GRKERNSEC_CHROOT_PIVOT
50616 + bool "Deny pivot_root in chroot"
50617 + depends on GRKERNSEC_CHROOT
50618 + help
50619 + If you say Y here, processes inside a chroot will not be able to use
50620 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50621 + works similar to chroot in that it changes the root filesystem. This
50622 + function could be misused in a chrooted process to attempt to break out
50623 + of the chroot, and therefore should not be allowed. If the sysctl
50624 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50625 + created.
50626 +
50627 +config GRKERNSEC_CHROOT_CHDIR
50628 + bool "Enforce chdir(\"/\") on all chroots"
50629 + depends on GRKERNSEC_CHROOT
50630 + help
50631 + If you say Y here, the current working directory of all newly-chrooted
50632 + applications will be set to the the root directory of the chroot.
50633 + The man page on chroot(2) states:
50634 + Note that this call does not change the current working
50635 + directory, so that `.' can be outside the tree rooted at
50636 + `/'. In particular, the super-user can escape from a
50637 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50638 +
50639 + It is recommended that you say Y here, since it's not known to break
50640 + any software. If the sysctl option is enabled, a sysctl option with
50641 + name "chroot_enforce_chdir" is created.
50642 +
50643 +config GRKERNSEC_CHROOT_CHMOD
50644 + bool "Deny (f)chmod +s"
50645 + depends on GRKERNSEC_CHROOT
50646 + help
50647 + If you say Y here, processes inside a chroot will not be able to chmod
50648 + or fchmod files to make them have suid or sgid bits. This protects
50649 + against another published method of breaking a chroot. If the sysctl
50650 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50651 + created.
50652 +
50653 +config GRKERNSEC_CHROOT_FCHDIR
50654 + bool "Deny fchdir out of chroot"
50655 + depends on GRKERNSEC_CHROOT
50656 + help
50657 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50658 + to a file descriptor of the chrooting process that points to a directory
50659 + outside the filesystem will be stopped. If the sysctl option
50660 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50661 +
50662 +config GRKERNSEC_CHROOT_MKNOD
50663 + bool "Deny mknod"
50664 + depends on GRKERNSEC_CHROOT
50665 + help
50666 + If you say Y here, processes inside a chroot will not be allowed to
50667 + mknod. The problem with using mknod inside a chroot is that it
50668 + would allow an attacker to create a device entry that is the same
50669 + as one on the physical root of your system, which could range from
50670 + anything from the console device to a device for your harddrive (which
50671 + they could then use to wipe the drive or steal data). It is recommended
50672 + that you say Y here, unless you run into software incompatibilities.
50673 + If the sysctl option is enabled, a sysctl option with name
50674 + "chroot_deny_mknod" is created.
50675 +
50676 +config GRKERNSEC_CHROOT_SHMAT
50677 + bool "Deny shmat() out of chroot"
50678 + depends on GRKERNSEC_CHROOT
50679 + help
50680 + If you say Y here, processes inside a chroot will not be able to attach
50681 + to shared memory segments that were created outside of the chroot jail.
50682 + It is recommended that you say Y here. If the sysctl option is enabled,
50683 + a sysctl option with name "chroot_deny_shmat" is created.
50684 +
50685 +config GRKERNSEC_CHROOT_UNIX
50686 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50687 + depends on GRKERNSEC_CHROOT
50688 + help
50689 + If you say Y here, processes inside a chroot will not be able to
50690 + connect to abstract (meaning not belonging to a filesystem) Unix
50691 + domain sockets that were bound outside of a chroot. It is recommended
50692 + that you say Y here. If the sysctl option is enabled, a sysctl option
50693 + with name "chroot_deny_unix" is created.
50694 +
50695 +config GRKERNSEC_CHROOT_FINDTASK
50696 + bool "Protect outside processes"
50697 + depends on GRKERNSEC_CHROOT
50698 + help
50699 + If you say Y here, processes inside a chroot will not be able to
50700 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50701 + getsid, or view any process outside of the chroot. If the sysctl
50702 + option is enabled, a sysctl option with name "chroot_findtask" is
50703 + created.
50704 +
50705 +config GRKERNSEC_CHROOT_NICE
50706 + bool "Restrict priority changes"
50707 + depends on GRKERNSEC_CHROOT
50708 + help
50709 + If you say Y here, processes inside a chroot will not be able to raise
50710 + the priority of processes in the chroot, or alter the priority of
50711 + processes outside the chroot. This provides more security than simply
50712 + removing CAP_SYS_NICE from the process' capability set. If the
50713 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50714 + is created.
50715 +
50716 +config GRKERNSEC_CHROOT_SYSCTL
50717 + bool "Deny sysctl writes"
50718 + depends on GRKERNSEC_CHROOT
50719 + help
50720 + If you say Y here, an attacker in a chroot will not be able to
50721 + write to sysctl entries, either by sysctl(2) or through a /proc
50722 + interface. It is strongly recommended that you say Y here. If the
50723 + sysctl option is enabled, a sysctl option with name
50724 + "chroot_deny_sysctl" is created.
50725 +
50726 +config GRKERNSEC_CHROOT_CAPS
50727 + bool "Capability restrictions"
50728 + depends on GRKERNSEC_CHROOT
50729 + help
50730 + If you say Y here, the capabilities on all processes within a
50731 + chroot jail will be lowered to stop module insertion, raw i/o,
50732 + system and net admin tasks, rebooting the system, modifying immutable
50733 + files, modifying IPC owned by another, and changing the system time.
50734 + This is left an option because it can break some apps. Disable this
50735 + if your chrooted apps are having problems performing those kinds of
50736 + tasks. If the sysctl option is enabled, a sysctl option with
50737 + name "chroot_caps" is created.
50738 +
50739 +endmenu
50740 +menu "Kernel Auditing"
50741 +depends on GRKERNSEC
50742 +
50743 +config GRKERNSEC_AUDIT_GROUP
50744 + bool "Single group for auditing"
50745 + help
50746 + If you say Y here, the exec, chdir, and (un)mount logging features
50747 + will only operate on a group you specify. This option is recommended
50748 + if you only want to watch certain users instead of having a large
50749 + amount of logs from the entire system. If the sysctl option is enabled,
50750 + a sysctl option with name "audit_group" is created.
50751 +
50752 +config GRKERNSEC_AUDIT_GID
50753 + int "GID for auditing"
50754 + depends on GRKERNSEC_AUDIT_GROUP
50755 + default 1007
50756 +
50757 +config GRKERNSEC_EXECLOG
50758 + bool "Exec logging"
50759 + help
50760 + If you say Y here, all execve() calls will be logged (since the
50761 + other exec*() calls are frontends to execve(), all execution
50762 + will be logged). Useful for shell-servers that like to keep track
50763 + of their users. If the sysctl option is enabled, a sysctl option with
50764 + name "exec_logging" is created.
50765 + WARNING: This option when enabled will produce a LOT of logs, especially
50766 + on an active system.
50767 +
50768 +config GRKERNSEC_RESLOG
50769 + bool "Resource logging"
50770 + help
50771 + If you say Y here, all attempts to overstep resource limits will
50772 + be logged with the resource name, the requested size, and the current
50773 + limit. It is highly recommended that you say Y here. If the sysctl
50774 + option is enabled, a sysctl option with name "resource_logging" is
50775 + created. If the RBAC system is enabled, the sysctl value is ignored.
50776 +
50777 +config GRKERNSEC_CHROOT_EXECLOG
50778 + bool "Log execs within chroot"
50779 + help
50780 + If you say Y here, all executions inside a chroot jail will be logged
50781 + to syslog. This can cause a large amount of logs if certain
50782 + applications (eg. djb's daemontools) are installed on the system, and
50783 + is therefore left as an option. If the sysctl option is enabled, a
50784 + sysctl option with name "chroot_execlog" is created.
50785 +
50786 +config GRKERNSEC_AUDIT_PTRACE
50787 + bool "Ptrace logging"
50788 + help
50789 + If you say Y here, all attempts to attach to a process via ptrace
50790 + will be logged. If the sysctl option is enabled, a sysctl option
50791 + with name "audit_ptrace" is created.
50792 +
50793 +config GRKERNSEC_AUDIT_CHDIR
50794 + bool "Chdir logging"
50795 + help
50796 + If you say Y here, all chdir() calls will be logged. If the sysctl
50797 + option is enabled, a sysctl option with name "audit_chdir" is created.
50798 +
50799 +config GRKERNSEC_AUDIT_MOUNT
50800 + bool "(Un)Mount logging"
50801 + help
50802 + If you say Y here, all mounts and unmounts will be logged. If the
50803 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50804 + created.
50805 +
50806 +config GRKERNSEC_SIGNAL
50807 + bool "Signal logging"
50808 + help
50809 + If you say Y here, certain important signals will be logged, such as
50810 + SIGSEGV, which will as a result inform you of when a error in a program
50811 + occurred, which in some cases could mean a possible exploit attempt.
50812 + If the sysctl option is enabled, a sysctl option with name
50813 + "signal_logging" is created.
50814 +
50815 +config GRKERNSEC_FORKFAIL
50816 + bool "Fork failure logging"
50817 + help
50818 + If you say Y here, all failed fork() attempts will be logged.
50819 + This could suggest a fork bomb, or someone attempting to overstep
50820 + their process limit. If the sysctl option is enabled, a sysctl option
50821 + with name "forkfail_logging" is created.
50822 +
50823 +config GRKERNSEC_TIME
50824 + bool "Time change logging"
50825 + help
50826 + If you say Y here, any changes of the system clock will be logged.
50827 + If the sysctl option is enabled, a sysctl option with name
50828 + "timechange_logging" is created.
50829 +
50830 +config GRKERNSEC_PROC_IPADDR
50831 + bool "/proc/<pid>/ipaddr support"
50832 + help
50833 + If you say Y here, a new entry will be added to each /proc/<pid>
50834 + directory that contains the IP address of the person using the task.
50835 + The IP is carried across local TCP and AF_UNIX stream sockets.
50836 + This information can be useful for IDS/IPSes to perform remote response
50837 + to a local attack. The entry is readable by only the owner of the
50838 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50839 + the RBAC system), and thus does not create privacy concerns.
50840 +
50841 +config GRKERNSEC_RWXMAP_LOG
50842 + bool 'Denied RWX mmap/mprotect logging'
50843 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50844 + help
50845 + If you say Y here, calls to mmap() and mprotect() with explicit
50846 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50847 + denied by the PAX_MPROTECT feature. If the sysctl option is
50848 + enabled, a sysctl option with name "rwxmap_logging" is created.
50849 +
50850 +config GRKERNSEC_AUDIT_TEXTREL
50851 + bool 'ELF text relocations logging (READ HELP)'
50852 + depends on PAX_MPROTECT
50853 + help
50854 + If you say Y here, text relocations will be logged with the filename
50855 + of the offending library or binary. The purpose of the feature is
50856 + to help Linux distribution developers get rid of libraries and
50857 + binaries that need text relocations which hinder the future progress
50858 + of PaX. Only Linux distribution developers should say Y here, and
50859 + never on a production machine, as this option creates an information
50860 + leak that could aid an attacker in defeating the randomization of
50861 + a single memory region. If the sysctl option is enabled, a sysctl
50862 + option with name "audit_textrel" is created.
50863 +
50864 +endmenu
50865 +
50866 +menu "Executable Protections"
50867 +depends on GRKERNSEC
50868 +
50869 +config GRKERNSEC_DMESG
50870 + bool "Dmesg(8) restriction"
50871 + help
50872 + If you say Y here, non-root users will not be able to use dmesg(8)
50873 + to view up to the last 4kb of messages in the kernel's log buffer.
50874 + The kernel's log buffer often contains kernel addresses and other
50875 + identifying information useful to an attacker in fingerprinting a
50876 + system for a targeted exploit.
50877 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50878 + created.
50879 +
50880 +config GRKERNSEC_HARDEN_PTRACE
50881 + bool "Deter ptrace-based process snooping"
50882 + help
50883 + If you say Y here, TTY sniffers and other malicious monitoring
50884 + programs implemented through ptrace will be defeated. If you
50885 + have been using the RBAC system, this option has already been
50886 + enabled for several years for all users, with the ability to make
50887 + fine-grained exceptions.
50888 +
50889 + This option only affects the ability of non-root users to ptrace
50890 + processes that are not a descendent of the ptracing process.
50891 + This means that strace ./binary and gdb ./binary will still work,
50892 + but attaching to arbitrary processes will not. If the sysctl
50893 + option is enabled, a sysctl option with name "harden_ptrace" is
50894 + created.
50895 +
50896 +config GRKERNSEC_SETXID
50897 + bool "Enforce consistent multithreaded privileges"
50898 + help
50899 + If you say Y here, a change from a root uid to a non-root uid
50900 + in a multithreaded application will cause the resulting uids,
50901 + gids, supplementary groups, and capabilities in that thread
50902 + to be propagated to the other threads of the process. In most
50903 + cases this is unnecessary, as glibc will emulate this behavior
50904 + on behalf of the application. Other libcs do not act in the
50905 + same way, allowing the other threads of the process to continue
50906 + running with root privileges. If the sysctl option is enabled,
50907 + a sysctl option with name "consistent_setxid" is created.
50908 +
50909 +config GRKERNSEC_TPE
50910 + bool "Trusted Path Execution (TPE)"
50911 + help
50912 + If you say Y here, you will be able to choose a gid to add to the
50913 + supplementary groups of users you want to mark as "untrusted."
50914 + These users will not be able to execute any files that are not in
50915 + root-owned directories writable only by root. If the sysctl option
50916 + is enabled, a sysctl option with name "tpe" is created.
50917 +
50918 +config GRKERNSEC_TPE_ALL
50919 + bool "Partially restrict all non-root users"
50920 + depends on GRKERNSEC_TPE
50921 + help
50922 + If you say Y here, all non-root users will be covered under
50923 + a weaker TPE restriction. This is separate from, and in addition to,
50924 + the main TPE options that you have selected elsewhere. Thus, if a
50925 + "trusted" GID is chosen, this restriction applies to even that GID.
50926 + Under this restriction, all non-root users will only be allowed to
50927 + execute files in directories they own that are not group or
50928 + world-writable, or in directories owned by root and writable only by
50929 + root. If the sysctl option is enabled, a sysctl option with name
50930 + "tpe_restrict_all" is created.
50931 +
50932 +config GRKERNSEC_TPE_INVERT
50933 + bool "Invert GID option"
50934 + depends on GRKERNSEC_TPE
50935 + help
50936 + If you say Y here, the group you specify in the TPE configuration will
50937 + decide what group TPE restrictions will be *disabled* for. This
50938 + option is useful if you want TPE restrictions to be applied to most
50939 + users on the system. If the sysctl option is enabled, a sysctl option
50940 + with name "tpe_invert" is created. Unlike other sysctl options, this
50941 + entry will default to on for backward-compatibility.
50942 +
50943 +config GRKERNSEC_TPE_GID
50944 + int "GID for untrusted users"
50945 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50946 + default 1005
50947 + help
50948 + Setting this GID determines what group TPE restrictions will be
50949 + *enabled* for. If the sysctl option is enabled, a sysctl option
50950 + with name "tpe_gid" is created.
50951 +
50952 +config GRKERNSEC_TPE_GID
50953 + int "GID for trusted users"
50954 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50955 + default 1005
50956 + help
50957 + Setting this GID determines what group TPE restrictions will be
50958 + *disabled* for. If the sysctl option is enabled, a sysctl option
50959 + with name "tpe_gid" is created.
50960 +
50961 +endmenu
50962 +menu "Network Protections"
50963 +depends on GRKERNSEC
50964 +
50965 +config GRKERNSEC_RANDNET
50966 + bool "Larger entropy pools"
50967 + help
50968 + If you say Y here, the entropy pools used for many features of Linux
50969 + and grsecurity will be doubled in size. Since several grsecurity
50970 + features use additional randomness, it is recommended that you say Y
50971 + here. Saying Y here has a similar effect as modifying
50972 + /proc/sys/kernel/random/poolsize.
50973 +
50974 +config GRKERNSEC_BLACKHOLE
50975 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50976 + depends on NET
50977 + help
50978 + If you say Y here, neither TCP resets nor ICMP
50979 + destination-unreachable packets will be sent in response to packets
50980 + sent to ports for which no associated listening process exists.
50981 + This feature supports both IPV4 and IPV6 and exempts the
50982 + loopback interface from blackholing. Enabling this feature
50983 + makes a host more resilient to DoS attacks and reduces network
50984 + visibility against scanners.
50985 +
50986 + The blackhole feature as-implemented is equivalent to the FreeBSD
50987 + blackhole feature, as it prevents RST responses to all packets, not
50988 + just SYNs. Under most application behavior this causes no
50989 + problems, but applications (like haproxy) may not close certain
50990 + connections in a way that cleanly terminates them on the remote
50991 + end, leaving the remote host in LAST_ACK state. Because of this
50992 + side-effect and to prevent intentional LAST_ACK DoSes, this
50993 + feature also adds automatic mitigation against such attacks.
50994 + The mitigation drastically reduces the amount of time a socket
50995 + can spend in LAST_ACK state. If you're using haproxy and not
50996 + all servers it connects to have this option enabled, consider
50997 + disabling this feature on the haproxy host.
50998 +
50999 + If the sysctl option is enabled, two sysctl options with names
51000 + "ip_blackhole" and "lastack_retries" will be created.
51001 + While "ip_blackhole" takes the standard zero/non-zero on/off
51002 + toggle, "lastack_retries" uses the same kinds of values as
51003 + "tcp_retries1" and "tcp_retries2". The default value of 4
51004 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51005 + state.
51006 +
51007 +config GRKERNSEC_SOCKET
51008 + bool "Socket restrictions"
51009 + depends on NET
51010 + help
51011 + If you say Y here, you will be able to choose from several options.
51012 + If you assign a GID on your system and add it to the supplementary
51013 + groups of users you want to restrict socket access to, this patch
51014 + will perform up to three things, based on the option(s) you choose.
51015 +
51016 +config GRKERNSEC_SOCKET_ALL
51017 + bool "Deny any sockets to group"
51018 + depends on GRKERNSEC_SOCKET
51019 + help
51020 + If you say Y here, you will be able to choose a GID of whose users will
51021 + be unable to connect to other hosts from your machine or run server
51022 + applications from your machine. If the sysctl option is enabled, a
51023 + sysctl option with name "socket_all" is created.
51024 +
51025 +config GRKERNSEC_SOCKET_ALL_GID
51026 + int "GID to deny all sockets for"
51027 + depends on GRKERNSEC_SOCKET_ALL
51028 + default 1004
51029 + help
51030 + Here you can choose the GID to disable socket access for. Remember to
51031 + add the users you want socket access disabled for to the GID
51032 + specified here. If the sysctl option is enabled, a sysctl option
51033 + with name "socket_all_gid" is created.
51034 +
51035 +config GRKERNSEC_SOCKET_CLIENT
51036 + bool "Deny client sockets to group"
51037 + depends on GRKERNSEC_SOCKET
51038 + help
51039 + If you say Y here, you will be able to choose a GID of whose users will
51040 + be unable to connect to other hosts from your machine, but will be
51041 + able to run servers. If this option is enabled, all users in the group
51042 + you specify will have to use passive mode when initiating ftp transfers
51043 + from the shell on your machine. If the sysctl option is enabled, a
51044 + sysctl option with name "socket_client" is created.
51045 +
51046 +config GRKERNSEC_SOCKET_CLIENT_GID
51047 + int "GID to deny client sockets for"
51048 + depends on GRKERNSEC_SOCKET_CLIENT
51049 + default 1003
51050 + help
51051 + Here you can choose the GID to disable client socket access for.
51052 + Remember to add the users you want client socket access disabled for to
51053 + the GID specified here. If the sysctl option is enabled, a sysctl
51054 + option with name "socket_client_gid" is created.
51055 +
51056 +config GRKERNSEC_SOCKET_SERVER
51057 + bool "Deny server sockets to group"
51058 + depends on GRKERNSEC_SOCKET
51059 + help
51060 + If you say Y here, you will be able to choose a GID of whose users will
51061 + be unable to run server applications from your machine. If the sysctl
51062 + option is enabled, a sysctl option with name "socket_server" is created.
51063 +
51064 +config GRKERNSEC_SOCKET_SERVER_GID
51065 + int "GID to deny server sockets for"
51066 + depends on GRKERNSEC_SOCKET_SERVER
51067 + default 1002
51068 + help
51069 + Here you can choose the GID to disable server socket access for.
51070 + Remember to add the users you want server socket access disabled for to
51071 + the GID specified here. If the sysctl option is enabled, a sysctl
51072 + option with name "socket_server_gid" is created.
51073 +
51074 +endmenu
51075 +menu "Sysctl support"
51076 +depends on GRKERNSEC && SYSCTL
51077 +
51078 +config GRKERNSEC_SYSCTL
51079 + bool "Sysctl support"
51080 + help
51081 + If you say Y here, you will be able to change the options that
51082 + grsecurity runs with at bootup, without having to recompile your
51083 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51084 + to enable (1) or disable (0) various features. All the sysctl entries
51085 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51086 + All features enabled in the kernel configuration are disabled at boot
51087 + if you do not say Y to the "Turn on features by default" option.
51088 + All options should be set at startup, and the grsec_lock entry should
51089 + be set to a non-zero value after all the options are set.
51090 + *THIS IS EXTREMELY IMPORTANT*
51091 +
51092 +config GRKERNSEC_SYSCTL_DISTRO
51093 + bool "Extra sysctl support for distro makers (READ HELP)"
51094 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51095 + help
51096 + If you say Y here, additional sysctl options will be created
51097 + for features that affect processes running as root. Therefore,
51098 + it is critical when using this option that the grsec_lock entry be
51099 + enabled after boot. Only distros with prebuilt kernel packages
51100 + with this option enabled that can ensure grsec_lock is enabled
51101 + after boot should use this option.
51102 + *Failure to set grsec_lock after boot makes all grsec features
51103 + this option covers useless*
51104 +
51105 + Currently this option creates the following sysctl entries:
51106 + "Disable Privileged I/O": "disable_priv_io"
51107 +
51108 +config GRKERNSEC_SYSCTL_ON
51109 + bool "Turn on features by default"
51110 + depends on GRKERNSEC_SYSCTL
51111 + help
51112 + If you say Y here, instead of having all features enabled in the
51113 + kernel configuration disabled at boot time, the features will be
51114 + enabled at boot time. It is recommended you say Y here unless
51115 + there is some reason you would want all sysctl-tunable features to
51116 + be disabled by default. As mentioned elsewhere, it is important
51117 + to enable the grsec_lock entry once you have finished modifying
51118 + the sysctl entries.
51119 +
51120 +endmenu
51121 +menu "Logging Options"
51122 +depends on GRKERNSEC
51123 +
51124 +config GRKERNSEC_FLOODTIME
51125 + int "Seconds in between log messages (minimum)"
51126 + default 10
51127 + help
51128 + This option allows you to enforce the number of seconds between
51129 + grsecurity log messages. The default should be suitable for most
51130 + people, however, if you choose to change it, choose a value small enough
51131 + to allow informative logs to be produced, but large enough to
51132 + prevent flooding.
51133 +
51134 +config GRKERNSEC_FLOODBURST
51135 + int "Number of messages in a burst (maximum)"
51136 + default 6
51137 + help
51138 + This option allows you to choose the maximum number of messages allowed
51139 + within the flood time interval you chose in a separate option. The
51140 + default should be suitable for most people, however if you find that
51141 + many of your logs are being interpreted as flooding, you may want to
51142 + raise this value.
51143 +
51144 +endmenu
51145 +
51146 +endmenu
51147 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51148 new file mode 100644
51149 index 0000000..be9ae3a
51150 --- /dev/null
51151 +++ b/grsecurity/Makefile
51152 @@ -0,0 +1,36 @@
51153 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51154 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51155 +# into an RBAC system
51156 +#
51157 +# All code in this directory and various hooks inserted throughout the kernel
51158 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51159 +# under the GPL v2 or higher
51160 +
51161 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51162 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51163 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51164 +
51165 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51166 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51167 + gracl_learn.o grsec_log.o
51168 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51169 +
51170 +ifdef CONFIG_NET
51171 +obj-y += grsec_sock.o
51172 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51173 +endif
51174 +
51175 +ifndef CONFIG_GRKERNSEC
51176 +obj-y += grsec_disabled.o
51177 +endif
51178 +
51179 +ifdef CONFIG_GRKERNSEC_HIDESYM
51180 +extra-y := grsec_hidesym.o
51181 +$(obj)/grsec_hidesym.o:
51182 + @-chmod -f 500 /boot
51183 + @-chmod -f 500 /lib/modules
51184 + @-chmod -f 500 /lib64/modules
51185 + @-chmod -f 500 /lib32/modules
51186 + @-chmod -f 700 .
51187 + @echo ' grsec: protected kernel image paths'
51188 +endif
51189 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51190 new file mode 100644
51191 index 0000000..09258e0
51192 --- /dev/null
51193 +++ b/grsecurity/gracl.c
51194 @@ -0,0 +1,4156 @@
51195 +#include <linux/kernel.h>
51196 +#include <linux/module.h>
51197 +#include <linux/sched.h>
51198 +#include <linux/mm.h>
51199 +#include <linux/file.h>
51200 +#include <linux/fs.h>
51201 +#include <linux/namei.h>
51202 +#include <linux/mount.h>
51203 +#include <linux/tty.h>
51204 +#include <linux/proc_fs.h>
51205 +#include <linux/lglock.h>
51206 +#include <linux/slab.h>
51207 +#include <linux/vmalloc.h>
51208 +#include <linux/types.h>
51209 +#include <linux/sysctl.h>
51210 +#include <linux/netdevice.h>
51211 +#include <linux/ptrace.h>
51212 +#include <linux/gracl.h>
51213 +#include <linux/gralloc.h>
51214 +#include <linux/grsecurity.h>
51215 +#include <linux/grinternal.h>
51216 +#include <linux/pid_namespace.h>
51217 +#include <linux/fdtable.h>
51218 +#include <linux/percpu.h>
51219 +
51220 +#include <asm/uaccess.h>
51221 +#include <asm/errno.h>
51222 +#include <asm/mman.h>
51223 +
51224 +static struct acl_role_db acl_role_set;
51225 +static struct name_db name_set;
51226 +static struct inodev_db inodev_set;
51227 +
51228 +/* for keeping track of userspace pointers used for subjects, so we
51229 + can share references in the kernel as well
51230 +*/
51231 +
51232 +static struct path real_root;
51233 +
51234 +static struct acl_subj_map_db subj_map_set;
51235 +
51236 +static struct acl_role_label *default_role;
51237 +
51238 +static struct acl_role_label *role_list;
51239 +
51240 +static u16 acl_sp_role_value;
51241 +
51242 +extern char *gr_shared_page[4];
51243 +static DEFINE_MUTEX(gr_dev_mutex);
51244 +DEFINE_RWLOCK(gr_inode_lock);
51245 +
51246 +struct gr_arg *gr_usermode;
51247 +
51248 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51249 +
51250 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51251 +extern void gr_clear_learn_entries(void);
51252 +
51253 +#ifdef CONFIG_GRKERNSEC_RESLOG
51254 +extern void gr_log_resource(const struct task_struct *task,
51255 + const int res, const unsigned long wanted, const int gt);
51256 +#endif
51257 +
51258 +unsigned char *gr_system_salt;
51259 +unsigned char *gr_system_sum;
51260 +
51261 +static struct sprole_pw **acl_special_roles = NULL;
51262 +static __u16 num_sprole_pws = 0;
51263 +
51264 +static struct acl_role_label *kernel_role = NULL;
51265 +
51266 +static unsigned int gr_auth_attempts = 0;
51267 +static unsigned long gr_auth_expires = 0UL;
51268 +
51269 +#ifdef CONFIG_NET
51270 +extern struct vfsmount *sock_mnt;
51271 +#endif
51272 +
51273 +extern struct vfsmount *pipe_mnt;
51274 +extern struct vfsmount *shm_mnt;
51275 +#ifdef CONFIG_HUGETLBFS
51276 +extern struct vfsmount *hugetlbfs_vfsmount;
51277 +#endif
51278 +
51279 +static struct acl_object_label *fakefs_obj_rw;
51280 +static struct acl_object_label *fakefs_obj_rwx;
51281 +
51282 +extern int gr_init_uidset(void);
51283 +extern void gr_free_uidset(void);
51284 +extern void gr_remove_uid(uid_t uid);
51285 +extern int gr_find_uid(uid_t uid);
51286 +
51287 +DECLARE_BRLOCK(vfsmount_lock);
51288 +
51289 +__inline__ int
51290 +gr_acl_is_enabled(void)
51291 +{
51292 + return (gr_status & GR_READY);
51293 +}
51294 +
51295 +#ifdef CONFIG_BTRFS_FS
51296 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51297 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51298 +#endif
51299 +
51300 +static inline dev_t __get_dev(const struct dentry *dentry)
51301 +{
51302 +#ifdef CONFIG_BTRFS_FS
51303 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51304 + return get_btrfs_dev_from_inode(dentry->d_inode);
51305 + else
51306 +#endif
51307 + return dentry->d_inode->i_sb->s_dev;
51308 +}
51309 +
51310 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51311 +{
51312 + return __get_dev(dentry);
51313 +}
51314 +
51315 +static char gr_task_roletype_to_char(struct task_struct *task)
51316 +{
51317 + switch (task->role->roletype &
51318 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51319 + GR_ROLE_SPECIAL)) {
51320 + case GR_ROLE_DEFAULT:
51321 + return 'D';
51322 + case GR_ROLE_USER:
51323 + return 'U';
51324 + case GR_ROLE_GROUP:
51325 + return 'G';
51326 + case GR_ROLE_SPECIAL:
51327 + return 'S';
51328 + }
51329 +
51330 + return 'X';
51331 +}
51332 +
51333 +char gr_roletype_to_char(void)
51334 +{
51335 + return gr_task_roletype_to_char(current);
51336 +}
51337 +
51338 +__inline__ int
51339 +gr_acl_tpe_check(void)
51340 +{
51341 + if (unlikely(!(gr_status & GR_READY)))
51342 + return 0;
51343 + if (current->role->roletype & GR_ROLE_TPE)
51344 + return 1;
51345 + else
51346 + return 0;
51347 +}
51348 +
51349 +int
51350 +gr_handle_rawio(const struct inode *inode)
51351 +{
51352 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51353 + if (inode && S_ISBLK(inode->i_mode) &&
51354 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51355 + !capable(CAP_SYS_RAWIO))
51356 + return 1;
51357 +#endif
51358 + return 0;
51359 +}
51360 +
51361 +static int
51362 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51363 +{
51364 + if (likely(lena != lenb))
51365 + return 0;
51366 +
51367 + return !memcmp(a, b, lena);
51368 +}
51369 +
51370 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51371 +{
51372 + *buflen -= namelen;
51373 + if (*buflen < 0)
51374 + return -ENAMETOOLONG;
51375 + *buffer -= namelen;
51376 + memcpy(*buffer, str, namelen);
51377 + return 0;
51378 +}
51379 +
51380 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51381 +{
51382 + return prepend(buffer, buflen, name->name, name->len);
51383 +}
51384 +
51385 +static int prepend_path(const struct path *path, struct path *root,
51386 + char **buffer, int *buflen)
51387 +{
51388 + struct dentry *dentry = path->dentry;
51389 + struct vfsmount *vfsmnt = path->mnt;
51390 + bool slash = false;
51391 + int error = 0;
51392 +
51393 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51394 + struct dentry * parent;
51395 +
51396 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51397 + /* Global root? */
51398 + if (vfsmnt->mnt_parent == vfsmnt) {
51399 + goto out;
51400 + }
51401 + dentry = vfsmnt->mnt_mountpoint;
51402 + vfsmnt = vfsmnt->mnt_parent;
51403 + continue;
51404 + }
51405 + parent = dentry->d_parent;
51406 + prefetch(parent);
51407 + spin_lock(&dentry->d_lock);
51408 + error = prepend_name(buffer, buflen, &dentry->d_name);
51409 + spin_unlock(&dentry->d_lock);
51410 + if (!error)
51411 + error = prepend(buffer, buflen, "/", 1);
51412 + if (error)
51413 + break;
51414 +
51415 + slash = true;
51416 + dentry = parent;
51417 + }
51418 +
51419 +out:
51420 + if (!error && !slash)
51421 + error = prepend(buffer, buflen, "/", 1);
51422 +
51423 + return error;
51424 +}
51425 +
51426 +/* this must be called with vfsmount_lock and rename_lock held */
51427 +
51428 +static char *__our_d_path(const struct path *path, struct path *root,
51429 + char *buf, int buflen)
51430 +{
51431 + char *res = buf + buflen;
51432 + int error;
51433 +
51434 + prepend(&res, &buflen, "\0", 1);
51435 + error = prepend_path(path, root, &res, &buflen);
51436 + if (error)
51437 + return ERR_PTR(error);
51438 +
51439 + return res;
51440 +}
51441 +
51442 +static char *
51443 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51444 +{
51445 + char *retval;
51446 +
51447 + retval = __our_d_path(path, root, buf, buflen);
51448 + if (unlikely(IS_ERR(retval)))
51449 + retval = strcpy(buf, "<path too long>");
51450 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51451 + retval[1] = '\0';
51452 +
51453 + return retval;
51454 +}
51455 +
51456 +static char *
51457 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51458 + char *buf, int buflen)
51459 +{
51460 + struct path path;
51461 + char *res;
51462 +
51463 + path.dentry = (struct dentry *)dentry;
51464 + path.mnt = (struct vfsmount *)vfsmnt;
51465 +
51466 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51467 + by the RBAC system */
51468 + res = gen_full_path(&path, &real_root, buf, buflen);
51469 +
51470 + return res;
51471 +}
51472 +
51473 +static char *
51474 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51475 + char *buf, int buflen)
51476 +{
51477 + char *res;
51478 + struct path path;
51479 + struct path root;
51480 + struct task_struct *reaper = &init_task;
51481 +
51482 + path.dentry = (struct dentry *)dentry;
51483 + path.mnt = (struct vfsmount *)vfsmnt;
51484 +
51485 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51486 + get_fs_root(reaper->fs, &root);
51487 +
51488 + write_seqlock(&rename_lock);
51489 + br_read_lock(vfsmount_lock);
51490 + res = gen_full_path(&path, &root, buf, buflen);
51491 + br_read_unlock(vfsmount_lock);
51492 + write_sequnlock(&rename_lock);
51493 +
51494 + path_put(&root);
51495 + return res;
51496 +}
51497 +
51498 +static char *
51499 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51500 +{
51501 + char *ret;
51502 + write_seqlock(&rename_lock);
51503 + br_read_lock(vfsmount_lock);
51504 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51505 + PAGE_SIZE);
51506 + br_read_unlock(vfsmount_lock);
51507 + write_sequnlock(&rename_lock);
51508 + return ret;
51509 +}
51510 +
51511 +static char *
51512 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51513 +{
51514 + char *ret;
51515 + char *buf;
51516 + int buflen;
51517 +
51518 + write_seqlock(&rename_lock);
51519 + br_read_lock(vfsmount_lock);
51520 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51521 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51522 + buflen = (int)(ret - buf);
51523 + if (buflen >= 5)
51524 + prepend(&ret, &buflen, "/proc", 5);
51525 + else
51526 + ret = strcpy(buf, "<path too long>");
51527 + br_read_unlock(vfsmount_lock);
51528 + write_sequnlock(&rename_lock);
51529 + return ret;
51530 +}
51531 +
51532 +char *
51533 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51534 +{
51535 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51536 + PAGE_SIZE);
51537 +}
51538 +
51539 +char *
51540 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51541 +{
51542 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51543 + PAGE_SIZE);
51544 +}
51545 +
51546 +char *
51547 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51548 +{
51549 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51550 + PAGE_SIZE);
51551 +}
51552 +
51553 +char *
51554 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51555 +{
51556 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51557 + PAGE_SIZE);
51558 +}
51559 +
51560 +char *
51561 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51562 +{
51563 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51564 + PAGE_SIZE);
51565 +}
51566 +
51567 +__inline__ __u32
51568 +to_gr_audit(const __u32 reqmode)
51569 +{
51570 + /* masks off auditable permission flags, then shifts them to create
51571 + auditing flags, and adds the special case of append auditing if
51572 + we're requesting write */
51573 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51574 +}
51575 +
51576 +struct acl_subject_label *
51577 +lookup_subject_map(const struct acl_subject_label *userp)
51578 +{
51579 + unsigned int index = shash(userp, subj_map_set.s_size);
51580 + struct subject_map *match;
51581 +
51582 + match = subj_map_set.s_hash[index];
51583 +
51584 + while (match && match->user != userp)
51585 + match = match->next;
51586 +
51587 + if (match != NULL)
51588 + return match->kernel;
51589 + else
51590 + return NULL;
51591 +}
51592 +
51593 +static void
51594 +insert_subj_map_entry(struct subject_map *subjmap)
51595 +{
51596 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51597 + struct subject_map **curr;
51598 +
51599 + subjmap->prev = NULL;
51600 +
51601 + curr = &subj_map_set.s_hash[index];
51602 + if (*curr != NULL)
51603 + (*curr)->prev = subjmap;
51604 +
51605 + subjmap->next = *curr;
51606 + *curr = subjmap;
51607 +
51608 + return;
51609 +}
51610 +
51611 +static struct acl_role_label *
51612 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51613 + const gid_t gid)
51614 +{
51615 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51616 + struct acl_role_label *match;
51617 + struct role_allowed_ip *ipp;
51618 + unsigned int x;
51619 + u32 curr_ip = task->signal->curr_ip;
51620 +
51621 + task->signal->saved_ip = curr_ip;
51622 +
51623 + match = acl_role_set.r_hash[index];
51624 +
51625 + while (match) {
51626 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51627 + for (x = 0; x < match->domain_child_num; x++) {
51628 + if (match->domain_children[x] == uid)
51629 + goto found;
51630 + }
51631 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51632 + break;
51633 + match = match->next;
51634 + }
51635 +found:
51636 + if (match == NULL) {
51637 + try_group:
51638 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51639 + match = acl_role_set.r_hash[index];
51640 +
51641 + while (match) {
51642 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51643 + for (x = 0; x < match->domain_child_num; x++) {
51644 + if (match->domain_children[x] == gid)
51645 + goto found2;
51646 + }
51647 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51648 + break;
51649 + match = match->next;
51650 + }
51651 +found2:
51652 + if (match == NULL)
51653 + match = default_role;
51654 + if (match->allowed_ips == NULL)
51655 + return match;
51656 + else {
51657 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51658 + if (likely
51659 + ((ntohl(curr_ip) & ipp->netmask) ==
51660 + (ntohl(ipp->addr) & ipp->netmask)))
51661 + return match;
51662 + }
51663 + match = default_role;
51664 + }
51665 + } else if (match->allowed_ips == NULL) {
51666 + return match;
51667 + } else {
51668 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51669 + if (likely
51670 + ((ntohl(curr_ip) & ipp->netmask) ==
51671 + (ntohl(ipp->addr) & ipp->netmask)))
51672 + return match;
51673 + }
51674 + goto try_group;
51675 + }
51676 +
51677 + return match;
51678 +}
51679 +
51680 +struct acl_subject_label *
51681 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51682 + const struct acl_role_label *role)
51683 +{
51684 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51685 + struct acl_subject_label *match;
51686 +
51687 + match = role->subj_hash[index];
51688 +
51689 + while (match && (match->inode != ino || match->device != dev ||
51690 + (match->mode & GR_DELETED))) {
51691 + match = match->next;
51692 + }
51693 +
51694 + if (match && !(match->mode & GR_DELETED))
51695 + return match;
51696 + else
51697 + return NULL;
51698 +}
51699 +
51700 +struct acl_subject_label *
51701 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51702 + const struct acl_role_label *role)
51703 +{
51704 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51705 + struct acl_subject_label *match;
51706 +
51707 + match = role->subj_hash[index];
51708 +
51709 + while (match && (match->inode != ino || match->device != dev ||
51710 + !(match->mode & GR_DELETED))) {
51711 + match = match->next;
51712 + }
51713 +
51714 + if (match && (match->mode & GR_DELETED))
51715 + return match;
51716 + else
51717 + return NULL;
51718 +}
51719 +
51720 +static struct acl_object_label *
51721 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51722 + const struct acl_subject_label *subj)
51723 +{
51724 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51725 + struct acl_object_label *match;
51726 +
51727 + match = subj->obj_hash[index];
51728 +
51729 + while (match && (match->inode != ino || match->device != dev ||
51730 + (match->mode & GR_DELETED))) {
51731 + match = match->next;
51732 + }
51733 +
51734 + if (match && !(match->mode & GR_DELETED))
51735 + return match;
51736 + else
51737 + return NULL;
51738 +}
51739 +
51740 +static struct acl_object_label *
51741 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51742 + const struct acl_subject_label *subj)
51743 +{
51744 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51745 + struct acl_object_label *match;
51746 +
51747 + match = subj->obj_hash[index];
51748 +
51749 + while (match && (match->inode != ino || match->device != dev ||
51750 + !(match->mode & GR_DELETED))) {
51751 + match = match->next;
51752 + }
51753 +
51754 + if (match && (match->mode & GR_DELETED))
51755 + return match;
51756 +
51757 + match = subj->obj_hash[index];
51758 +
51759 + while (match && (match->inode != ino || match->device != dev ||
51760 + (match->mode & GR_DELETED))) {
51761 + match = match->next;
51762 + }
51763 +
51764 + if (match && !(match->mode & GR_DELETED))
51765 + return match;
51766 + else
51767 + return NULL;
51768 +}
51769 +
51770 +static struct name_entry *
51771 +lookup_name_entry(const char *name)
51772 +{
51773 + unsigned int len = strlen(name);
51774 + unsigned int key = full_name_hash(name, len);
51775 + unsigned int index = key % name_set.n_size;
51776 + struct name_entry *match;
51777 +
51778 + match = name_set.n_hash[index];
51779 +
51780 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51781 + match = match->next;
51782 +
51783 + return match;
51784 +}
51785 +
51786 +static struct name_entry *
51787 +lookup_name_entry_create(const char *name)
51788 +{
51789 + unsigned int len = strlen(name);
51790 + unsigned int key = full_name_hash(name, len);
51791 + unsigned int index = key % name_set.n_size;
51792 + struct name_entry *match;
51793 +
51794 + match = name_set.n_hash[index];
51795 +
51796 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51797 + !match->deleted))
51798 + match = match->next;
51799 +
51800 + if (match && match->deleted)
51801 + return match;
51802 +
51803 + match = name_set.n_hash[index];
51804 +
51805 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51806 + match->deleted))
51807 + match = match->next;
51808 +
51809 + if (match && !match->deleted)
51810 + return match;
51811 + else
51812 + return NULL;
51813 +}
51814 +
51815 +static struct inodev_entry *
51816 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51817 +{
51818 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51819 + struct inodev_entry *match;
51820 +
51821 + match = inodev_set.i_hash[index];
51822 +
51823 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51824 + match = match->next;
51825 +
51826 + return match;
51827 +}
51828 +
51829 +static void
51830 +insert_inodev_entry(struct inodev_entry *entry)
51831 +{
51832 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51833 + inodev_set.i_size);
51834 + struct inodev_entry **curr;
51835 +
51836 + entry->prev = NULL;
51837 +
51838 + curr = &inodev_set.i_hash[index];
51839 + if (*curr != NULL)
51840 + (*curr)->prev = entry;
51841 +
51842 + entry->next = *curr;
51843 + *curr = entry;
51844 +
51845 + return;
51846 +}
51847 +
51848 +static void
51849 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51850 +{
51851 + unsigned int index =
51852 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51853 + struct acl_role_label **curr;
51854 + struct acl_role_label *tmp;
51855 +
51856 + curr = &acl_role_set.r_hash[index];
51857 +
51858 + /* if role was already inserted due to domains and already has
51859 + a role in the same bucket as it attached, then we need to
51860 + combine these two buckets
51861 + */
51862 + if (role->next) {
51863 + tmp = role->next;
51864 + while (tmp->next)
51865 + tmp = tmp->next;
51866 + tmp->next = *curr;
51867 + } else
51868 + role->next = *curr;
51869 + *curr = role;
51870 +
51871 + return;
51872 +}
51873 +
51874 +static void
51875 +insert_acl_role_label(struct acl_role_label *role)
51876 +{
51877 + int i;
51878 +
51879 + if (role_list == NULL) {
51880 + role_list = role;
51881 + role->prev = NULL;
51882 + } else {
51883 + role->prev = role_list;
51884 + role_list = role;
51885 + }
51886 +
51887 + /* used for hash chains */
51888 + role->next = NULL;
51889 +
51890 + if (role->roletype & GR_ROLE_DOMAIN) {
51891 + for (i = 0; i < role->domain_child_num; i++)
51892 + __insert_acl_role_label(role, role->domain_children[i]);
51893 + } else
51894 + __insert_acl_role_label(role, role->uidgid);
51895 +}
51896 +
51897 +static int
51898 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51899 +{
51900 + struct name_entry **curr, *nentry;
51901 + struct inodev_entry *ientry;
51902 + unsigned int len = strlen(name);
51903 + unsigned int key = full_name_hash(name, len);
51904 + unsigned int index = key % name_set.n_size;
51905 +
51906 + curr = &name_set.n_hash[index];
51907 +
51908 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51909 + curr = &((*curr)->next);
51910 +
51911 + if (*curr != NULL)
51912 + return 1;
51913 +
51914 + nentry = acl_alloc(sizeof (struct name_entry));
51915 + if (nentry == NULL)
51916 + return 0;
51917 + ientry = acl_alloc(sizeof (struct inodev_entry));
51918 + if (ientry == NULL)
51919 + return 0;
51920 + ientry->nentry = nentry;
51921 +
51922 + nentry->key = key;
51923 + nentry->name = name;
51924 + nentry->inode = inode;
51925 + nentry->device = device;
51926 + nentry->len = len;
51927 + nentry->deleted = deleted;
51928 +
51929 + nentry->prev = NULL;
51930 + curr = &name_set.n_hash[index];
51931 + if (*curr != NULL)
51932 + (*curr)->prev = nentry;
51933 + nentry->next = *curr;
51934 + *curr = nentry;
51935 +
51936 + /* insert us into the table searchable by inode/dev */
51937 + insert_inodev_entry(ientry);
51938 +
51939 + return 1;
51940 +}
51941 +
51942 +static void
51943 +insert_acl_obj_label(struct acl_object_label *obj,
51944 + struct acl_subject_label *subj)
51945 +{
51946 + unsigned int index =
51947 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51948 + struct acl_object_label **curr;
51949 +
51950 +
51951 + obj->prev = NULL;
51952 +
51953 + curr = &subj->obj_hash[index];
51954 + if (*curr != NULL)
51955 + (*curr)->prev = obj;
51956 +
51957 + obj->next = *curr;
51958 + *curr = obj;
51959 +
51960 + return;
51961 +}
51962 +
51963 +static void
51964 +insert_acl_subj_label(struct acl_subject_label *obj,
51965 + struct acl_role_label *role)
51966 +{
51967 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51968 + struct acl_subject_label **curr;
51969 +
51970 + obj->prev = NULL;
51971 +
51972 + curr = &role->subj_hash[index];
51973 + if (*curr != NULL)
51974 + (*curr)->prev = obj;
51975 +
51976 + obj->next = *curr;
51977 + *curr = obj;
51978 +
51979 + return;
51980 +}
51981 +
51982 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51983 +
51984 +static void *
51985 +create_table(__u32 * len, int elementsize)
51986 +{
51987 + unsigned int table_sizes[] = {
51988 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51989 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51990 + 4194301, 8388593, 16777213, 33554393, 67108859
51991 + };
51992 + void *newtable = NULL;
51993 + unsigned int pwr = 0;
51994 +
51995 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51996 + table_sizes[pwr] <= *len)
51997 + pwr++;
51998 +
51999 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52000 + return newtable;
52001 +
52002 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52003 + newtable =
52004 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52005 + else
52006 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52007 +
52008 + *len = table_sizes[pwr];
52009 +
52010 + return newtable;
52011 +}
52012 +
52013 +static int
52014 +init_variables(const struct gr_arg *arg)
52015 +{
52016 + struct task_struct *reaper = &init_task;
52017 + unsigned int stacksize;
52018 +
52019 + subj_map_set.s_size = arg->role_db.num_subjects;
52020 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52021 + name_set.n_size = arg->role_db.num_objects;
52022 + inodev_set.i_size = arg->role_db.num_objects;
52023 +
52024 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52025 + !name_set.n_size || !inodev_set.i_size)
52026 + return 1;
52027 +
52028 + if (!gr_init_uidset())
52029 + return 1;
52030 +
52031 + /* set up the stack that holds allocation info */
52032 +
52033 + stacksize = arg->role_db.num_pointers + 5;
52034 +
52035 + if (!acl_alloc_stack_init(stacksize))
52036 + return 1;
52037 +
52038 + /* grab reference for the real root dentry and vfsmount */
52039 + get_fs_root(reaper->fs, &real_root);
52040 +
52041 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52042 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52043 +#endif
52044 +
52045 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52046 + if (fakefs_obj_rw == NULL)
52047 + return 1;
52048 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52049 +
52050 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52051 + if (fakefs_obj_rwx == NULL)
52052 + return 1;
52053 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52054 +
52055 + subj_map_set.s_hash =
52056 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52057 + acl_role_set.r_hash =
52058 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52059 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52060 + inodev_set.i_hash =
52061 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52062 +
52063 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52064 + !name_set.n_hash || !inodev_set.i_hash)
52065 + return 1;
52066 +
52067 + memset(subj_map_set.s_hash, 0,
52068 + sizeof(struct subject_map *) * subj_map_set.s_size);
52069 + memset(acl_role_set.r_hash, 0,
52070 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52071 + memset(name_set.n_hash, 0,
52072 + sizeof (struct name_entry *) * name_set.n_size);
52073 + memset(inodev_set.i_hash, 0,
52074 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52075 +
52076 + return 0;
52077 +}
52078 +
52079 +/* free information not needed after startup
52080 + currently contains user->kernel pointer mappings for subjects
52081 +*/
52082 +
52083 +static void
52084 +free_init_variables(void)
52085 +{
52086 + __u32 i;
52087 +
52088 + if (subj_map_set.s_hash) {
52089 + for (i = 0; i < subj_map_set.s_size; i++) {
52090 + if (subj_map_set.s_hash[i]) {
52091 + kfree(subj_map_set.s_hash[i]);
52092 + subj_map_set.s_hash[i] = NULL;
52093 + }
52094 + }
52095 +
52096 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52097 + PAGE_SIZE)
52098 + kfree(subj_map_set.s_hash);
52099 + else
52100 + vfree(subj_map_set.s_hash);
52101 + }
52102 +
52103 + return;
52104 +}
52105 +
52106 +static void
52107 +free_variables(void)
52108 +{
52109 + struct acl_subject_label *s;
52110 + struct acl_role_label *r;
52111 + struct task_struct *task, *task2;
52112 + unsigned int x;
52113 +
52114 + gr_clear_learn_entries();
52115 +
52116 + read_lock(&tasklist_lock);
52117 + do_each_thread(task2, task) {
52118 + task->acl_sp_role = 0;
52119 + task->acl_role_id = 0;
52120 + task->acl = NULL;
52121 + task->role = NULL;
52122 + } while_each_thread(task2, task);
52123 + read_unlock(&tasklist_lock);
52124 +
52125 + /* release the reference to the real root dentry and vfsmount */
52126 + path_put(&real_root);
52127 +
52128 + /* free all object hash tables */
52129 +
52130 + FOR_EACH_ROLE_START(r)
52131 + if (r->subj_hash == NULL)
52132 + goto next_role;
52133 + FOR_EACH_SUBJECT_START(r, s, x)
52134 + if (s->obj_hash == NULL)
52135 + break;
52136 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52137 + kfree(s->obj_hash);
52138 + else
52139 + vfree(s->obj_hash);
52140 + FOR_EACH_SUBJECT_END(s, x)
52141 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52142 + if (s->obj_hash == NULL)
52143 + break;
52144 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52145 + kfree(s->obj_hash);
52146 + else
52147 + vfree(s->obj_hash);
52148 + FOR_EACH_NESTED_SUBJECT_END(s)
52149 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52150 + kfree(r->subj_hash);
52151 + else
52152 + vfree(r->subj_hash);
52153 + r->subj_hash = NULL;
52154 +next_role:
52155 + FOR_EACH_ROLE_END(r)
52156 +
52157 + acl_free_all();
52158 +
52159 + if (acl_role_set.r_hash) {
52160 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52161 + PAGE_SIZE)
52162 + kfree(acl_role_set.r_hash);
52163 + else
52164 + vfree(acl_role_set.r_hash);
52165 + }
52166 + if (name_set.n_hash) {
52167 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52168 + PAGE_SIZE)
52169 + kfree(name_set.n_hash);
52170 + else
52171 + vfree(name_set.n_hash);
52172 + }
52173 +
52174 + if (inodev_set.i_hash) {
52175 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52176 + PAGE_SIZE)
52177 + kfree(inodev_set.i_hash);
52178 + else
52179 + vfree(inodev_set.i_hash);
52180 + }
52181 +
52182 + gr_free_uidset();
52183 +
52184 + memset(&name_set, 0, sizeof (struct name_db));
52185 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52186 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52187 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52188 +
52189 + default_role = NULL;
52190 + role_list = NULL;
52191 +
52192 + return;
52193 +}
52194 +
52195 +static __u32
52196 +count_user_objs(struct acl_object_label *userp)
52197 +{
52198 + struct acl_object_label o_tmp;
52199 + __u32 num = 0;
52200 +
52201 + while (userp) {
52202 + if (copy_from_user(&o_tmp, userp,
52203 + sizeof (struct acl_object_label)))
52204 + break;
52205 +
52206 + userp = o_tmp.prev;
52207 + num++;
52208 + }
52209 +
52210 + return num;
52211 +}
52212 +
52213 +static struct acl_subject_label *
52214 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52215 +
52216 +static int
52217 +copy_user_glob(struct acl_object_label *obj)
52218 +{
52219 + struct acl_object_label *g_tmp, **guser;
52220 + unsigned int len;
52221 + char *tmp;
52222 +
52223 + if (obj->globbed == NULL)
52224 + return 0;
52225 +
52226 + guser = &obj->globbed;
52227 + while (*guser) {
52228 + g_tmp = (struct acl_object_label *)
52229 + acl_alloc(sizeof (struct acl_object_label));
52230 + if (g_tmp == NULL)
52231 + return -ENOMEM;
52232 +
52233 + if (copy_from_user(g_tmp, *guser,
52234 + sizeof (struct acl_object_label)))
52235 + return -EFAULT;
52236 +
52237 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52238 +
52239 + if (!len || len >= PATH_MAX)
52240 + return -EINVAL;
52241 +
52242 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52243 + return -ENOMEM;
52244 +
52245 + if (copy_from_user(tmp, g_tmp->filename, len))
52246 + return -EFAULT;
52247 + tmp[len-1] = '\0';
52248 + g_tmp->filename = tmp;
52249 +
52250 + *guser = g_tmp;
52251 + guser = &(g_tmp->next);
52252 + }
52253 +
52254 + return 0;
52255 +}
52256 +
52257 +static int
52258 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52259 + struct acl_role_label *role)
52260 +{
52261 + struct acl_object_label *o_tmp;
52262 + unsigned int len;
52263 + int ret;
52264 + char *tmp;
52265 +
52266 + while (userp) {
52267 + if ((o_tmp = (struct acl_object_label *)
52268 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52269 + return -ENOMEM;
52270 +
52271 + if (copy_from_user(o_tmp, userp,
52272 + sizeof (struct acl_object_label)))
52273 + return -EFAULT;
52274 +
52275 + userp = o_tmp->prev;
52276 +
52277 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52278 +
52279 + if (!len || len >= PATH_MAX)
52280 + return -EINVAL;
52281 +
52282 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52283 + return -ENOMEM;
52284 +
52285 + if (copy_from_user(tmp, o_tmp->filename, len))
52286 + return -EFAULT;
52287 + tmp[len-1] = '\0';
52288 + o_tmp->filename = tmp;
52289 +
52290 + insert_acl_obj_label(o_tmp, subj);
52291 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52292 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52293 + return -ENOMEM;
52294 +
52295 + ret = copy_user_glob(o_tmp);
52296 + if (ret)
52297 + return ret;
52298 +
52299 + if (o_tmp->nested) {
52300 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52301 + if (IS_ERR(o_tmp->nested))
52302 + return PTR_ERR(o_tmp->nested);
52303 +
52304 + /* insert into nested subject list */
52305 + o_tmp->nested->next = role->hash->first;
52306 + role->hash->first = o_tmp->nested;
52307 + }
52308 + }
52309 +
52310 + return 0;
52311 +}
52312 +
52313 +static __u32
52314 +count_user_subjs(struct acl_subject_label *userp)
52315 +{
52316 + struct acl_subject_label s_tmp;
52317 + __u32 num = 0;
52318 +
52319 + while (userp) {
52320 + if (copy_from_user(&s_tmp, userp,
52321 + sizeof (struct acl_subject_label)))
52322 + break;
52323 +
52324 + userp = s_tmp.prev;
52325 + /* do not count nested subjects against this count, since
52326 + they are not included in the hash table, but are
52327 + attached to objects. We have already counted
52328 + the subjects in userspace for the allocation
52329 + stack
52330 + */
52331 + if (!(s_tmp.mode & GR_NESTED))
52332 + num++;
52333 + }
52334 +
52335 + return num;
52336 +}
52337 +
52338 +static int
52339 +copy_user_allowedips(struct acl_role_label *rolep)
52340 +{
52341 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52342 +
52343 + ruserip = rolep->allowed_ips;
52344 +
52345 + while (ruserip) {
52346 + rlast = rtmp;
52347 +
52348 + if ((rtmp = (struct role_allowed_ip *)
52349 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52350 + return -ENOMEM;
52351 +
52352 + if (copy_from_user(rtmp, ruserip,
52353 + sizeof (struct role_allowed_ip)))
52354 + return -EFAULT;
52355 +
52356 + ruserip = rtmp->prev;
52357 +
52358 + if (!rlast) {
52359 + rtmp->prev = NULL;
52360 + rolep->allowed_ips = rtmp;
52361 + } else {
52362 + rlast->next = rtmp;
52363 + rtmp->prev = rlast;
52364 + }
52365 +
52366 + if (!ruserip)
52367 + rtmp->next = NULL;
52368 + }
52369 +
52370 + return 0;
52371 +}
52372 +
52373 +static int
52374 +copy_user_transitions(struct acl_role_label *rolep)
52375 +{
52376 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52377 +
52378 + unsigned int len;
52379 + char *tmp;
52380 +
52381 + rusertp = rolep->transitions;
52382 +
52383 + while (rusertp) {
52384 + rlast = rtmp;
52385 +
52386 + if ((rtmp = (struct role_transition *)
52387 + acl_alloc(sizeof (struct role_transition))) == NULL)
52388 + return -ENOMEM;
52389 +
52390 + if (copy_from_user(rtmp, rusertp,
52391 + sizeof (struct role_transition)))
52392 + return -EFAULT;
52393 +
52394 + rusertp = rtmp->prev;
52395 +
52396 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52397 +
52398 + if (!len || len >= GR_SPROLE_LEN)
52399 + return -EINVAL;
52400 +
52401 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52402 + return -ENOMEM;
52403 +
52404 + if (copy_from_user(tmp, rtmp->rolename, len))
52405 + return -EFAULT;
52406 + tmp[len-1] = '\0';
52407 + rtmp->rolename = tmp;
52408 +
52409 + if (!rlast) {
52410 + rtmp->prev = NULL;
52411 + rolep->transitions = rtmp;
52412 + } else {
52413 + rlast->next = rtmp;
52414 + rtmp->prev = rlast;
52415 + }
52416 +
52417 + if (!rusertp)
52418 + rtmp->next = NULL;
52419 + }
52420 +
52421 + return 0;
52422 +}
52423 +
52424 +static struct acl_subject_label *
52425 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52426 +{
52427 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52428 + unsigned int len;
52429 + char *tmp;
52430 + __u32 num_objs;
52431 + struct acl_ip_label **i_tmp, *i_utmp2;
52432 + struct gr_hash_struct ghash;
52433 + struct subject_map *subjmap;
52434 + unsigned int i_num;
52435 + int err;
52436 +
52437 + s_tmp = lookup_subject_map(userp);
52438 +
52439 + /* we've already copied this subject into the kernel, just return
52440 + the reference to it, and don't copy it over again
52441 + */
52442 + if (s_tmp)
52443 + return(s_tmp);
52444 +
52445 + if ((s_tmp = (struct acl_subject_label *)
52446 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52447 + return ERR_PTR(-ENOMEM);
52448 +
52449 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52450 + if (subjmap == NULL)
52451 + return ERR_PTR(-ENOMEM);
52452 +
52453 + subjmap->user = userp;
52454 + subjmap->kernel = s_tmp;
52455 + insert_subj_map_entry(subjmap);
52456 +
52457 + if (copy_from_user(s_tmp, userp,
52458 + sizeof (struct acl_subject_label)))
52459 + return ERR_PTR(-EFAULT);
52460 +
52461 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52462 +
52463 + if (!len || len >= PATH_MAX)
52464 + return ERR_PTR(-EINVAL);
52465 +
52466 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52467 + return ERR_PTR(-ENOMEM);
52468 +
52469 + if (copy_from_user(tmp, s_tmp->filename, len))
52470 + return ERR_PTR(-EFAULT);
52471 + tmp[len-1] = '\0';
52472 + s_tmp->filename = tmp;
52473 +
52474 + if (!strcmp(s_tmp->filename, "/"))
52475 + role->root_label = s_tmp;
52476 +
52477 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52478 + return ERR_PTR(-EFAULT);
52479 +
52480 + /* copy user and group transition tables */
52481 +
52482 + if (s_tmp->user_trans_num) {
52483 + uid_t *uidlist;
52484 +
52485 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52486 + if (uidlist == NULL)
52487 + return ERR_PTR(-ENOMEM);
52488 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52489 + return ERR_PTR(-EFAULT);
52490 +
52491 + s_tmp->user_transitions = uidlist;
52492 + }
52493 +
52494 + if (s_tmp->group_trans_num) {
52495 + gid_t *gidlist;
52496 +
52497 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52498 + if (gidlist == NULL)
52499 + return ERR_PTR(-ENOMEM);
52500 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52501 + return ERR_PTR(-EFAULT);
52502 +
52503 + s_tmp->group_transitions = gidlist;
52504 + }
52505 +
52506 + /* set up object hash table */
52507 + num_objs = count_user_objs(ghash.first);
52508 +
52509 + s_tmp->obj_hash_size = num_objs;
52510 + s_tmp->obj_hash =
52511 + (struct acl_object_label **)
52512 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52513 +
52514 + if (!s_tmp->obj_hash)
52515 + return ERR_PTR(-ENOMEM);
52516 +
52517 + memset(s_tmp->obj_hash, 0,
52518 + s_tmp->obj_hash_size *
52519 + sizeof (struct acl_object_label *));
52520 +
52521 + /* add in objects */
52522 + err = copy_user_objs(ghash.first, s_tmp, role);
52523 +
52524 + if (err)
52525 + return ERR_PTR(err);
52526 +
52527 + /* set pointer for parent subject */
52528 + if (s_tmp->parent_subject) {
52529 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52530 +
52531 + if (IS_ERR(s_tmp2))
52532 + return s_tmp2;
52533 +
52534 + s_tmp->parent_subject = s_tmp2;
52535 + }
52536 +
52537 + /* add in ip acls */
52538 +
52539 + if (!s_tmp->ip_num) {
52540 + s_tmp->ips = NULL;
52541 + goto insert;
52542 + }
52543 +
52544 + i_tmp =
52545 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52546 + sizeof (struct acl_ip_label *));
52547 +
52548 + if (!i_tmp)
52549 + return ERR_PTR(-ENOMEM);
52550 +
52551 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52552 + *(i_tmp + i_num) =
52553 + (struct acl_ip_label *)
52554 + acl_alloc(sizeof (struct acl_ip_label));
52555 + if (!*(i_tmp + i_num))
52556 + return ERR_PTR(-ENOMEM);
52557 +
52558 + if (copy_from_user
52559 + (&i_utmp2, s_tmp->ips + i_num,
52560 + sizeof (struct acl_ip_label *)))
52561 + return ERR_PTR(-EFAULT);
52562 +
52563 + if (copy_from_user
52564 + (*(i_tmp + i_num), i_utmp2,
52565 + sizeof (struct acl_ip_label)))
52566 + return ERR_PTR(-EFAULT);
52567 +
52568 + if ((*(i_tmp + i_num))->iface == NULL)
52569 + continue;
52570 +
52571 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52572 + if (!len || len >= IFNAMSIZ)
52573 + return ERR_PTR(-EINVAL);
52574 + tmp = acl_alloc(len);
52575 + if (tmp == NULL)
52576 + return ERR_PTR(-ENOMEM);
52577 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52578 + return ERR_PTR(-EFAULT);
52579 + (*(i_tmp + i_num))->iface = tmp;
52580 + }
52581 +
52582 + s_tmp->ips = i_tmp;
52583 +
52584 +insert:
52585 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52586 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52587 + return ERR_PTR(-ENOMEM);
52588 +
52589 + return s_tmp;
52590 +}
52591 +
52592 +static int
52593 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52594 +{
52595 + struct acl_subject_label s_pre;
52596 + struct acl_subject_label * ret;
52597 + int err;
52598 +
52599 + while (userp) {
52600 + if (copy_from_user(&s_pre, userp,
52601 + sizeof (struct acl_subject_label)))
52602 + return -EFAULT;
52603 +
52604 + /* do not add nested subjects here, add
52605 + while parsing objects
52606 + */
52607 +
52608 + if (s_pre.mode & GR_NESTED) {
52609 + userp = s_pre.prev;
52610 + continue;
52611 + }
52612 +
52613 + ret = do_copy_user_subj(userp, role);
52614 +
52615 + err = PTR_ERR(ret);
52616 + if (IS_ERR(ret))
52617 + return err;
52618 +
52619 + insert_acl_subj_label(ret, role);
52620 +
52621 + userp = s_pre.prev;
52622 + }
52623 +
52624 + return 0;
52625 +}
52626 +
52627 +static int
52628 +copy_user_acl(struct gr_arg *arg)
52629 +{
52630 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52631 + struct sprole_pw *sptmp;
52632 + struct gr_hash_struct *ghash;
52633 + uid_t *domainlist;
52634 + unsigned int r_num;
52635 + unsigned int len;
52636 + char *tmp;
52637 + int err = 0;
52638 + __u16 i;
52639 + __u32 num_subjs;
52640 +
52641 + /* we need a default and kernel role */
52642 + if (arg->role_db.num_roles < 2)
52643 + return -EINVAL;
52644 +
52645 + /* copy special role authentication info from userspace */
52646 +
52647 + num_sprole_pws = arg->num_sprole_pws;
52648 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52649 +
52650 + if (!acl_special_roles) {
52651 + err = -ENOMEM;
52652 + goto cleanup;
52653 + }
52654 +
52655 + for (i = 0; i < num_sprole_pws; i++) {
52656 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52657 + if (!sptmp) {
52658 + err = -ENOMEM;
52659 + goto cleanup;
52660 + }
52661 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52662 + sizeof (struct sprole_pw))) {
52663 + err = -EFAULT;
52664 + goto cleanup;
52665 + }
52666 +
52667 + len =
52668 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52669 +
52670 + if (!len || len >= GR_SPROLE_LEN) {
52671 + err = -EINVAL;
52672 + goto cleanup;
52673 + }
52674 +
52675 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
52676 + err = -ENOMEM;
52677 + goto cleanup;
52678 + }
52679 +
52680 + if (copy_from_user(tmp, sptmp->rolename, len)) {
52681 + err = -EFAULT;
52682 + goto cleanup;
52683 + }
52684 + tmp[len-1] = '\0';
52685 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52686 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52687 +#endif
52688 + sptmp->rolename = tmp;
52689 + acl_special_roles[i] = sptmp;
52690 + }
52691 +
52692 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52693 +
52694 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52695 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52696 +
52697 + if (!r_tmp) {
52698 + err = -ENOMEM;
52699 + goto cleanup;
52700 + }
52701 +
52702 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52703 + sizeof (struct acl_role_label *))) {
52704 + err = -EFAULT;
52705 + goto cleanup;
52706 + }
52707 +
52708 + if (copy_from_user(r_tmp, r_utmp2,
52709 + sizeof (struct acl_role_label))) {
52710 + err = -EFAULT;
52711 + goto cleanup;
52712 + }
52713 +
52714 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52715 +
52716 + if (!len || len >= PATH_MAX) {
52717 + err = -EINVAL;
52718 + goto cleanup;
52719 + }
52720 +
52721 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
52722 + err = -ENOMEM;
52723 + goto cleanup;
52724 + }
52725 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
52726 + err = -EFAULT;
52727 + goto cleanup;
52728 + }
52729 + tmp[len-1] = '\0';
52730 + r_tmp->rolename = tmp;
52731 +
52732 + if (!strcmp(r_tmp->rolename, "default")
52733 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52734 + default_role = r_tmp;
52735 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52736 + kernel_role = r_tmp;
52737 + }
52738 +
52739 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
52740 + err = -ENOMEM;
52741 + goto cleanup;
52742 + }
52743 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
52744 + err = -EFAULT;
52745 + goto cleanup;
52746 + }
52747 +
52748 + r_tmp->hash = ghash;
52749 +
52750 + num_subjs = count_user_subjs(r_tmp->hash->first);
52751 +
52752 + r_tmp->subj_hash_size = num_subjs;
52753 + r_tmp->subj_hash =
52754 + (struct acl_subject_label **)
52755 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52756 +
52757 + if (!r_tmp->subj_hash) {
52758 + err = -ENOMEM;
52759 + goto cleanup;
52760 + }
52761 +
52762 + err = copy_user_allowedips(r_tmp);
52763 + if (err)
52764 + goto cleanup;
52765 +
52766 + /* copy domain info */
52767 + if (r_tmp->domain_children != NULL) {
52768 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52769 + if (domainlist == NULL) {
52770 + err = -ENOMEM;
52771 + goto cleanup;
52772 + }
52773 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
52774 + err = -EFAULT;
52775 + goto cleanup;
52776 + }
52777 + r_tmp->domain_children = domainlist;
52778 + }
52779 +
52780 + err = copy_user_transitions(r_tmp);
52781 + if (err)
52782 + goto cleanup;
52783 +
52784 + memset(r_tmp->subj_hash, 0,
52785 + r_tmp->subj_hash_size *
52786 + sizeof (struct acl_subject_label *));
52787 +
52788 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52789 +
52790 + if (err)
52791 + goto cleanup;
52792 +
52793 + /* set nested subject list to null */
52794 + r_tmp->hash->first = NULL;
52795 +
52796 + insert_acl_role_label(r_tmp);
52797 + }
52798 +
52799 + goto return_err;
52800 + cleanup:
52801 + free_variables();
52802 + return_err:
52803 + return err;
52804 +
52805 +}
52806 +
52807 +static int
52808 +gracl_init(struct gr_arg *args)
52809 +{
52810 + int error = 0;
52811 +
52812 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52813 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52814 +
52815 + if (init_variables(args)) {
52816 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52817 + error = -ENOMEM;
52818 + free_variables();
52819 + goto out;
52820 + }
52821 +
52822 + error = copy_user_acl(args);
52823 + free_init_variables();
52824 + if (error) {
52825 + free_variables();
52826 + goto out;
52827 + }
52828 +
52829 + if ((error = gr_set_acls(0))) {
52830 + free_variables();
52831 + goto out;
52832 + }
52833 +
52834 + pax_open_kernel();
52835 + gr_status |= GR_READY;
52836 + pax_close_kernel();
52837 +
52838 + out:
52839 + return error;
52840 +}
52841 +
52842 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52843 +
52844 +static int
52845 +glob_match(const char *p, const char *n)
52846 +{
52847 + char c;
52848 +
52849 + while ((c = *p++) != '\0') {
52850 + switch (c) {
52851 + case '?':
52852 + if (*n == '\0')
52853 + return 1;
52854 + else if (*n == '/')
52855 + return 1;
52856 + break;
52857 + case '\\':
52858 + if (*n != c)
52859 + return 1;
52860 + break;
52861 + case '*':
52862 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52863 + if (*n == '/')
52864 + return 1;
52865 + else if (c == '?') {
52866 + if (*n == '\0')
52867 + return 1;
52868 + else
52869 + ++n;
52870 + }
52871 + }
52872 + if (c == '\0') {
52873 + return 0;
52874 + } else {
52875 + const char *endp;
52876 +
52877 + if ((endp = strchr(n, '/')) == NULL)
52878 + endp = n + strlen(n);
52879 +
52880 + if (c == '[') {
52881 + for (--p; n < endp; ++n)
52882 + if (!glob_match(p, n))
52883 + return 0;
52884 + } else if (c == '/') {
52885 + while (*n != '\0' && *n != '/')
52886 + ++n;
52887 + if (*n == '/' && !glob_match(p, n + 1))
52888 + return 0;
52889 + } else {
52890 + for (--p; n < endp; ++n)
52891 + if (*n == c && !glob_match(p, n))
52892 + return 0;
52893 + }
52894 +
52895 + return 1;
52896 + }
52897 + case '[':
52898 + {
52899 + int not;
52900 + char cold;
52901 +
52902 + if (*n == '\0' || *n == '/')
52903 + return 1;
52904 +
52905 + not = (*p == '!' || *p == '^');
52906 + if (not)
52907 + ++p;
52908 +
52909 + c = *p++;
52910 + for (;;) {
52911 + unsigned char fn = (unsigned char)*n;
52912 +
52913 + if (c == '\0')
52914 + return 1;
52915 + else {
52916 + if (c == fn)
52917 + goto matched;
52918 + cold = c;
52919 + c = *p++;
52920 +
52921 + if (c == '-' && *p != ']') {
52922 + unsigned char cend = *p++;
52923 +
52924 + if (cend == '\0')
52925 + return 1;
52926 +
52927 + if (cold <= fn && fn <= cend)
52928 + goto matched;
52929 +
52930 + c = *p++;
52931 + }
52932 + }
52933 +
52934 + if (c == ']')
52935 + break;
52936 + }
52937 + if (!not)
52938 + return 1;
52939 + break;
52940 + matched:
52941 + while (c != ']') {
52942 + if (c == '\0')
52943 + return 1;
52944 +
52945 + c = *p++;
52946 + }
52947 + if (not)
52948 + return 1;
52949 + }
52950 + break;
52951 + default:
52952 + if (c != *n)
52953 + return 1;
52954 + }
52955 +
52956 + ++n;
52957 + }
52958 +
52959 + if (*n == '\0')
52960 + return 0;
52961 +
52962 + if (*n == '/')
52963 + return 0;
52964 +
52965 + return 1;
52966 +}
52967 +
52968 +static struct acl_object_label *
52969 +chk_glob_label(struct acl_object_label *globbed,
52970 + struct dentry *dentry, struct vfsmount *mnt, char **path)
52971 +{
52972 + struct acl_object_label *tmp;
52973 +
52974 + if (*path == NULL)
52975 + *path = gr_to_filename_nolock(dentry, mnt);
52976 +
52977 + tmp = globbed;
52978 +
52979 + while (tmp) {
52980 + if (!glob_match(tmp->filename, *path))
52981 + return tmp;
52982 + tmp = tmp->next;
52983 + }
52984 +
52985 + return NULL;
52986 +}
52987 +
52988 +static struct acl_object_label *
52989 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52990 + const ino_t curr_ino, const dev_t curr_dev,
52991 + const struct acl_subject_label *subj, char **path, const int checkglob)
52992 +{
52993 + struct acl_subject_label *tmpsubj;
52994 + struct acl_object_label *retval;
52995 + struct acl_object_label *retval2;
52996 +
52997 + tmpsubj = (struct acl_subject_label *) subj;
52998 + read_lock(&gr_inode_lock);
52999 + do {
53000 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53001 + if (retval) {
53002 + if (checkglob && retval->globbed) {
53003 + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
53004 + (struct vfsmount *)orig_mnt, path);
53005 + if (retval2)
53006 + retval = retval2;
53007 + }
53008 + break;
53009 + }
53010 + } while ((tmpsubj = tmpsubj->parent_subject));
53011 + read_unlock(&gr_inode_lock);
53012 +
53013 + return retval;
53014 +}
53015 +
53016 +static __inline__ struct acl_object_label *
53017 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53018 + struct dentry *curr_dentry,
53019 + const struct acl_subject_label *subj, char **path, const int checkglob)
53020 +{
53021 + int newglob = checkglob;
53022 + ino_t inode;
53023 + dev_t device;
53024 +
53025 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53026 + as we don't want a / * rule to match instead of the / object
53027 + don't do this for create lookups that call this function though, since they're looking up
53028 + on the parent and thus need globbing checks on all paths
53029 + */
53030 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53031 + newglob = GR_NO_GLOB;
53032 +
53033 + spin_lock(&curr_dentry->d_lock);
53034 + inode = curr_dentry->d_inode->i_ino;
53035 + device = __get_dev(curr_dentry);
53036 + spin_unlock(&curr_dentry->d_lock);
53037 +
53038 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53039 +}
53040 +
53041 +static struct acl_object_label *
53042 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53043 + const struct acl_subject_label *subj, char *path, const int checkglob)
53044 +{
53045 + struct dentry *dentry = (struct dentry *) l_dentry;
53046 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53047 + struct acl_object_label *retval;
53048 + struct dentry *parent;
53049 +
53050 + write_seqlock(&rename_lock);
53051 + br_read_lock(vfsmount_lock);
53052 +
53053 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53054 +#ifdef CONFIG_NET
53055 + mnt == sock_mnt ||
53056 +#endif
53057 +#ifdef CONFIG_HUGETLBFS
53058 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53059 +#endif
53060 + /* ignore Eric Biederman */
53061 + IS_PRIVATE(l_dentry->d_inode))) {
53062 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53063 + goto out;
53064 + }
53065 +
53066 + for (;;) {
53067 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53068 + break;
53069 +
53070 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53071 + if (mnt->mnt_parent == mnt)
53072 + break;
53073 +
53074 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53075 + if (retval != NULL)
53076 + goto out;
53077 +
53078 + dentry = mnt->mnt_mountpoint;
53079 + mnt = mnt->mnt_parent;
53080 + continue;
53081 + }
53082 +
53083 + parent = dentry->d_parent;
53084 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53085 + if (retval != NULL)
53086 + goto out;
53087 +
53088 + dentry = parent;
53089 + }
53090 +
53091 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53092 +
53093 + /* real_root is pinned so we don't have to hold a reference */
53094 + if (retval == NULL)
53095 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53096 +out:
53097 + br_read_unlock(vfsmount_lock);
53098 + write_sequnlock(&rename_lock);
53099 +
53100 + BUG_ON(retval == NULL);
53101 +
53102 + return retval;
53103 +}
53104 +
53105 +static __inline__ struct acl_object_label *
53106 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53107 + const struct acl_subject_label *subj)
53108 +{
53109 + char *path = NULL;
53110 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53111 +}
53112 +
53113 +static __inline__ struct acl_object_label *
53114 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53115 + const struct acl_subject_label *subj)
53116 +{
53117 + char *path = NULL;
53118 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53119 +}
53120 +
53121 +static __inline__ struct acl_object_label *
53122 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53123 + const struct acl_subject_label *subj, char *path)
53124 +{
53125 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53126 +}
53127 +
53128 +static struct acl_subject_label *
53129 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53130 + const struct acl_role_label *role)
53131 +{
53132 + struct dentry *dentry = (struct dentry *) l_dentry;
53133 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53134 + struct acl_subject_label *retval;
53135 + struct dentry *parent;
53136 +
53137 + write_seqlock(&rename_lock);
53138 + br_read_lock(vfsmount_lock);
53139 +
53140 + for (;;) {
53141 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53142 + break;
53143 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53144 + if (mnt->mnt_parent == mnt)
53145 + break;
53146 +
53147 + spin_lock(&dentry->d_lock);
53148 + read_lock(&gr_inode_lock);
53149 + retval =
53150 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53151 + __get_dev(dentry), role);
53152 + read_unlock(&gr_inode_lock);
53153 + spin_unlock(&dentry->d_lock);
53154 + if (retval != NULL)
53155 + goto out;
53156 +
53157 + dentry = mnt->mnt_mountpoint;
53158 + mnt = mnt->mnt_parent;
53159 + continue;
53160 + }
53161 +
53162 + spin_lock(&dentry->d_lock);
53163 + read_lock(&gr_inode_lock);
53164 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53165 + __get_dev(dentry), role);
53166 + read_unlock(&gr_inode_lock);
53167 + parent = dentry->d_parent;
53168 + spin_unlock(&dentry->d_lock);
53169 +
53170 + if (retval != NULL)
53171 + goto out;
53172 +
53173 + dentry = parent;
53174 + }
53175 +
53176 + spin_lock(&dentry->d_lock);
53177 + read_lock(&gr_inode_lock);
53178 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53179 + __get_dev(dentry), role);
53180 + read_unlock(&gr_inode_lock);
53181 + spin_unlock(&dentry->d_lock);
53182 +
53183 + if (unlikely(retval == NULL)) {
53184 + /* real_root is pinned, we don't need to hold a reference */
53185 + read_lock(&gr_inode_lock);
53186 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53187 + __get_dev(real_root.dentry), role);
53188 + read_unlock(&gr_inode_lock);
53189 + }
53190 +out:
53191 + br_read_unlock(vfsmount_lock);
53192 + write_sequnlock(&rename_lock);
53193 +
53194 + BUG_ON(retval == NULL);
53195 +
53196 + return retval;
53197 +}
53198 +
53199 +static void
53200 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53201 +{
53202 + struct task_struct *task = current;
53203 + const struct cred *cred = current_cred();
53204 +
53205 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53206 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53207 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53208 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53209 +
53210 + return;
53211 +}
53212 +
53213 +static void
53214 +gr_log_learn_sysctl(const char *path, const __u32 mode)
53215 +{
53216 + struct task_struct *task = current;
53217 + const struct cred *cred = current_cred();
53218 +
53219 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53220 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53221 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53222 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
53223 +
53224 + return;
53225 +}
53226 +
53227 +static void
53228 +gr_log_learn_id_change(const char type, const unsigned int real,
53229 + const unsigned int effective, const unsigned int fs)
53230 +{
53231 + struct task_struct *task = current;
53232 + const struct cred *cred = current_cred();
53233 +
53234 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53235 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53236 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53237 + type, real, effective, fs, &task->signal->saved_ip);
53238 +
53239 + return;
53240 +}
53241 +
53242 +__u32
53243 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53244 + const struct vfsmount * mnt)
53245 +{
53246 + __u32 retval = mode;
53247 + struct acl_subject_label *curracl;
53248 + struct acl_object_label *currobj;
53249 +
53250 + if (unlikely(!(gr_status & GR_READY)))
53251 + return (mode & ~GR_AUDITS);
53252 +
53253 + curracl = current->acl;
53254 +
53255 + currobj = chk_obj_label(dentry, mnt, curracl);
53256 + retval = currobj->mode & mode;
53257 +
53258 + /* if we're opening a specified transfer file for writing
53259 + (e.g. /dev/initctl), then transfer our role to init
53260 + */
53261 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53262 + current->role->roletype & GR_ROLE_PERSIST)) {
53263 + struct task_struct *task = init_pid_ns.child_reaper;
53264 +
53265 + if (task->role != current->role) {
53266 + task->acl_sp_role = 0;
53267 + task->acl_role_id = current->acl_role_id;
53268 + task->role = current->role;
53269 + rcu_read_lock();
53270 + read_lock(&grsec_exec_file_lock);
53271 + gr_apply_subject_to_task(task);
53272 + read_unlock(&grsec_exec_file_lock);
53273 + rcu_read_unlock();
53274 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53275 + }
53276 + }
53277 +
53278 + if (unlikely
53279 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53280 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53281 + __u32 new_mode = mode;
53282 +
53283 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53284 +
53285 + retval = new_mode;
53286 +
53287 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53288 + new_mode |= GR_INHERIT;
53289 +
53290 + if (!(mode & GR_NOLEARN))
53291 + gr_log_learn(dentry, mnt, new_mode);
53292 + }
53293 +
53294 + return retval;
53295 +}
53296 +
53297 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53298 + const struct dentry *parent,
53299 + const struct vfsmount *mnt)
53300 +{
53301 + struct name_entry *match;
53302 + struct acl_object_label *matchpo;
53303 + struct acl_subject_label *curracl;
53304 + char *path;
53305 +
53306 + if (unlikely(!(gr_status & GR_READY)))
53307 + return NULL;
53308 +
53309 + preempt_disable();
53310 + path = gr_to_filename_rbac(new_dentry, mnt);
53311 + match = lookup_name_entry_create(path);
53312 +
53313 + curracl = current->acl;
53314 +
53315 + if (match) {
53316 + read_lock(&gr_inode_lock);
53317 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53318 + read_unlock(&gr_inode_lock);
53319 +
53320 + if (matchpo) {
53321 + preempt_enable();
53322 + return matchpo;
53323 + }
53324 + }
53325 +
53326 + // lookup parent
53327 +
53328 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53329 +
53330 + preempt_enable();
53331 + return matchpo;
53332 +}
53333 +
53334 +__u32
53335 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53336 + const struct vfsmount * mnt, const __u32 mode)
53337 +{
53338 + struct acl_object_label *matchpo;
53339 + __u32 retval;
53340 +
53341 + if (unlikely(!(gr_status & GR_READY)))
53342 + return (mode & ~GR_AUDITS);
53343 +
53344 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53345 +
53346 + retval = matchpo->mode & mode;
53347 +
53348 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53349 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53350 + __u32 new_mode = mode;
53351 +
53352 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53353 +
53354 + gr_log_learn(new_dentry, mnt, new_mode);
53355 + return new_mode;
53356 + }
53357 +
53358 + return retval;
53359 +}
53360 +
53361 +__u32
53362 +gr_check_link(const struct dentry * new_dentry,
53363 + const struct dentry * parent_dentry,
53364 + const struct vfsmount * parent_mnt,
53365 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53366 +{
53367 + struct acl_object_label *obj;
53368 + __u32 oldmode, newmode;
53369 + __u32 needmode;
53370 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53371 + GR_DELETE | GR_INHERIT;
53372 +
53373 + if (unlikely(!(gr_status & GR_READY)))
53374 + return (GR_CREATE | GR_LINK);
53375 +
53376 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53377 + oldmode = obj->mode;
53378 +
53379 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53380 + newmode = obj->mode;
53381 +
53382 + needmode = newmode & checkmodes;
53383 +
53384 + // old name for hardlink must have at least the permissions of the new name
53385 + if ((oldmode & needmode) != needmode)
53386 + goto bad;
53387 +
53388 + // if old name had restrictions/auditing, make sure the new name does as well
53389 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53390 +
53391 + // don't allow hardlinking of suid/sgid files without permission
53392 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53393 + needmode |= GR_SETID;
53394 +
53395 + if ((newmode & needmode) != needmode)
53396 + goto bad;
53397 +
53398 + // enforce minimum permissions
53399 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53400 + return newmode;
53401 +bad:
53402 + needmode = oldmode;
53403 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53404 + needmode |= GR_SETID;
53405 +
53406 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53407 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53408 + return (GR_CREATE | GR_LINK);
53409 + } else if (newmode & GR_SUPPRESS)
53410 + return GR_SUPPRESS;
53411 + else
53412 + return 0;
53413 +}
53414 +
53415 +int
53416 +gr_check_hidden_task(const struct task_struct *task)
53417 +{
53418 + if (unlikely(!(gr_status & GR_READY)))
53419 + return 0;
53420 +
53421 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53422 + return 1;
53423 +
53424 + return 0;
53425 +}
53426 +
53427 +int
53428 +gr_check_protected_task(const struct task_struct *task)
53429 +{
53430 + if (unlikely(!(gr_status & GR_READY) || !task))
53431 + return 0;
53432 +
53433 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53434 + task->acl != current->acl)
53435 + return 1;
53436 +
53437 + return 0;
53438 +}
53439 +
53440 +int
53441 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53442 +{
53443 + struct task_struct *p;
53444 + int ret = 0;
53445 +
53446 + if (unlikely(!(gr_status & GR_READY) || !pid))
53447 + return ret;
53448 +
53449 + read_lock(&tasklist_lock);
53450 + do_each_pid_task(pid, type, p) {
53451 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53452 + p->acl != current->acl) {
53453 + ret = 1;
53454 + goto out;
53455 + }
53456 + } while_each_pid_task(pid, type, p);
53457 +out:
53458 + read_unlock(&tasklist_lock);
53459 +
53460 + return ret;
53461 +}
53462 +
53463 +void
53464 +gr_copy_label(struct task_struct *tsk)
53465 +{
53466 + tsk->signal->used_accept = 0;
53467 + tsk->acl_sp_role = 0;
53468 + tsk->acl_role_id = current->acl_role_id;
53469 + tsk->acl = current->acl;
53470 + tsk->role = current->role;
53471 + tsk->signal->curr_ip = current->signal->curr_ip;
53472 + tsk->signal->saved_ip = current->signal->saved_ip;
53473 + if (current->exec_file)
53474 + get_file(current->exec_file);
53475 + tsk->exec_file = current->exec_file;
53476 + tsk->is_writable = current->is_writable;
53477 + if (unlikely(current->signal->used_accept)) {
53478 + current->signal->curr_ip = 0;
53479 + current->signal->saved_ip = 0;
53480 + }
53481 +
53482 + return;
53483 +}
53484 +
53485 +static void
53486 +gr_set_proc_res(struct task_struct *task)
53487 +{
53488 + struct acl_subject_label *proc;
53489 + unsigned short i;
53490 +
53491 + proc = task->acl;
53492 +
53493 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53494 + return;
53495 +
53496 + for (i = 0; i < RLIM_NLIMITS; i++) {
53497 + if (!(proc->resmask & (1 << i)))
53498 + continue;
53499 +
53500 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53501 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53502 + }
53503 +
53504 + return;
53505 +}
53506 +
53507 +extern int __gr_process_user_ban(struct user_struct *user);
53508 +
53509 +int
53510 +gr_check_user_change(int real, int effective, int fs)
53511 +{
53512 + unsigned int i;
53513 + __u16 num;
53514 + uid_t *uidlist;
53515 + int curuid;
53516 + int realok = 0;
53517 + int effectiveok = 0;
53518 + int fsok = 0;
53519 +
53520 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53521 + struct user_struct *user;
53522 +
53523 + if (real == -1)
53524 + goto skipit;
53525 +
53526 + user = find_user(real);
53527 + if (user == NULL)
53528 + goto skipit;
53529 +
53530 + if (__gr_process_user_ban(user)) {
53531 + /* for find_user */
53532 + free_uid(user);
53533 + return 1;
53534 + }
53535 +
53536 + /* for find_user */
53537 + free_uid(user);
53538 +
53539 +skipit:
53540 +#endif
53541 +
53542 + if (unlikely(!(gr_status & GR_READY)))
53543 + return 0;
53544 +
53545 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53546 + gr_log_learn_id_change('u', real, effective, fs);
53547 +
53548 + num = current->acl->user_trans_num;
53549 + uidlist = current->acl->user_transitions;
53550 +
53551 + if (uidlist == NULL)
53552 + return 0;
53553 +
53554 + if (real == -1)
53555 + realok = 1;
53556 + if (effective == -1)
53557 + effectiveok = 1;
53558 + if (fs == -1)
53559 + fsok = 1;
53560 +
53561 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53562 + for (i = 0; i < num; i++) {
53563 + curuid = (int)uidlist[i];
53564 + if (real == curuid)
53565 + realok = 1;
53566 + if (effective == curuid)
53567 + effectiveok = 1;
53568 + if (fs == curuid)
53569 + fsok = 1;
53570 + }
53571 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53572 + for (i = 0; i < num; i++) {
53573 + curuid = (int)uidlist[i];
53574 + if (real == curuid)
53575 + break;
53576 + if (effective == curuid)
53577 + break;
53578 + if (fs == curuid)
53579 + break;
53580 + }
53581 + /* not in deny list */
53582 + if (i == num) {
53583 + realok = 1;
53584 + effectiveok = 1;
53585 + fsok = 1;
53586 + }
53587 + }
53588 +
53589 + if (realok && effectiveok && fsok)
53590 + return 0;
53591 + else {
53592 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53593 + return 1;
53594 + }
53595 +}
53596 +
53597 +int
53598 +gr_check_group_change(int real, int effective, int fs)
53599 +{
53600 + unsigned int i;
53601 + __u16 num;
53602 + gid_t *gidlist;
53603 + int curgid;
53604 + int realok = 0;
53605 + int effectiveok = 0;
53606 + int fsok = 0;
53607 +
53608 + if (unlikely(!(gr_status & GR_READY)))
53609 + return 0;
53610 +
53611 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53612 + gr_log_learn_id_change('g', real, effective, fs);
53613 +
53614 + num = current->acl->group_trans_num;
53615 + gidlist = current->acl->group_transitions;
53616 +
53617 + if (gidlist == NULL)
53618 + return 0;
53619 +
53620 + if (real == -1)
53621 + realok = 1;
53622 + if (effective == -1)
53623 + effectiveok = 1;
53624 + if (fs == -1)
53625 + fsok = 1;
53626 +
53627 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53628 + for (i = 0; i < num; i++) {
53629 + curgid = (int)gidlist[i];
53630 + if (real == curgid)
53631 + realok = 1;
53632 + if (effective == curgid)
53633 + effectiveok = 1;
53634 + if (fs == curgid)
53635 + fsok = 1;
53636 + }
53637 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53638 + for (i = 0; i < num; i++) {
53639 + curgid = (int)gidlist[i];
53640 + if (real == curgid)
53641 + break;
53642 + if (effective == curgid)
53643 + break;
53644 + if (fs == curgid)
53645 + break;
53646 + }
53647 + /* not in deny list */
53648 + if (i == num) {
53649 + realok = 1;
53650 + effectiveok = 1;
53651 + fsok = 1;
53652 + }
53653 + }
53654 +
53655 + if (realok && effectiveok && fsok)
53656 + return 0;
53657 + else {
53658 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53659 + return 1;
53660 + }
53661 +}
53662 +
53663 +void
53664 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53665 +{
53666 + struct acl_role_label *role = task->role;
53667 + struct acl_subject_label *subj = NULL;
53668 + struct acl_object_label *obj;
53669 + struct file *filp;
53670 +
53671 + if (unlikely(!(gr_status & GR_READY)))
53672 + return;
53673 +
53674 + filp = task->exec_file;
53675 +
53676 + /* kernel process, we'll give them the kernel role */
53677 + if (unlikely(!filp)) {
53678 + task->role = kernel_role;
53679 + task->acl = kernel_role->root_label;
53680 + return;
53681 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53682 + role = lookup_acl_role_label(task, uid, gid);
53683 +
53684 + /* perform subject lookup in possibly new role
53685 + we can use this result below in the case where role == task->role
53686 + */
53687 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53688 +
53689 + /* if we changed uid/gid, but result in the same role
53690 + and are using inheritance, don't lose the inherited subject
53691 + if current subject is other than what normal lookup
53692 + would result in, we arrived via inheritance, don't
53693 + lose subject
53694 + */
53695 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53696 + (subj == task->acl)))
53697 + task->acl = subj;
53698 +
53699 + task->role = role;
53700 +
53701 + task->is_writable = 0;
53702 +
53703 + /* ignore additional mmap checks for processes that are writable
53704 + by the default ACL */
53705 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53706 + if (unlikely(obj->mode & GR_WRITE))
53707 + task->is_writable = 1;
53708 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53709 + if (unlikely(obj->mode & GR_WRITE))
53710 + task->is_writable = 1;
53711 +
53712 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53713 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53714 +#endif
53715 +
53716 + gr_set_proc_res(task);
53717 +
53718 + return;
53719 +}
53720 +
53721 +int
53722 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53723 + const int unsafe_share)
53724 +{
53725 + struct task_struct *task = current;
53726 + struct acl_subject_label *newacl;
53727 + struct acl_object_label *obj;
53728 + __u32 retmode;
53729 +
53730 + if (unlikely(!(gr_status & GR_READY)))
53731 + return 0;
53732 +
53733 + newacl = chk_subj_label(dentry, mnt, task->role);
53734 +
53735 + task_lock(task);
53736 + if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
53737 + !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53738 + !(task->role->roletype & GR_ROLE_GOD) &&
53739 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53740 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
53741 + task_unlock(task);
53742 + if (unsafe_share)
53743 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53744 + else
53745 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53746 + return -EACCES;
53747 + }
53748 + task_unlock(task);
53749 +
53750 + obj = chk_obj_label(dentry, mnt, task->acl);
53751 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53752 +
53753 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53754 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53755 + if (obj->nested)
53756 + task->acl = obj->nested;
53757 + else
53758 + task->acl = newacl;
53759 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53760 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53761 +
53762 + task->is_writable = 0;
53763 +
53764 + /* ignore additional mmap checks for processes that are writable
53765 + by the default ACL */
53766 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53767 + if (unlikely(obj->mode & GR_WRITE))
53768 + task->is_writable = 1;
53769 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53770 + if (unlikely(obj->mode & GR_WRITE))
53771 + task->is_writable = 1;
53772 +
53773 + gr_set_proc_res(task);
53774 +
53775 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53776 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53777 +#endif
53778 + return 0;
53779 +}
53780 +
53781 +/* always called with valid inodev ptr */
53782 +static void
53783 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53784 +{
53785 + struct acl_object_label *matchpo;
53786 + struct acl_subject_label *matchps;
53787 + struct acl_subject_label *subj;
53788 + struct acl_role_label *role;
53789 + unsigned int x;
53790 +
53791 + FOR_EACH_ROLE_START(role)
53792 + FOR_EACH_SUBJECT_START(role, subj, x)
53793 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53794 + matchpo->mode |= GR_DELETED;
53795 + FOR_EACH_SUBJECT_END(subj,x)
53796 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53797 + if (subj->inode == ino && subj->device == dev)
53798 + subj->mode |= GR_DELETED;
53799 + FOR_EACH_NESTED_SUBJECT_END(subj)
53800 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53801 + matchps->mode |= GR_DELETED;
53802 + FOR_EACH_ROLE_END(role)
53803 +
53804 + inodev->nentry->deleted = 1;
53805 +
53806 + return;
53807 +}
53808 +
53809 +void
53810 +gr_handle_delete(const ino_t ino, const dev_t dev)
53811 +{
53812 + struct inodev_entry *inodev;
53813 +
53814 + if (unlikely(!(gr_status & GR_READY)))
53815 + return;
53816 +
53817 + write_lock(&gr_inode_lock);
53818 + inodev = lookup_inodev_entry(ino, dev);
53819 + if (inodev != NULL)
53820 + do_handle_delete(inodev, ino, dev);
53821 + write_unlock(&gr_inode_lock);
53822 +
53823 + return;
53824 +}
53825 +
53826 +static void
53827 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53828 + const ino_t newinode, const dev_t newdevice,
53829 + struct acl_subject_label *subj)
53830 +{
53831 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53832 + struct acl_object_label *match;
53833 +
53834 + match = subj->obj_hash[index];
53835 +
53836 + while (match && (match->inode != oldinode ||
53837 + match->device != olddevice ||
53838 + !(match->mode & GR_DELETED)))
53839 + match = match->next;
53840 +
53841 + if (match && (match->inode == oldinode)
53842 + && (match->device == olddevice)
53843 + && (match->mode & GR_DELETED)) {
53844 + if (match->prev == NULL) {
53845 + subj->obj_hash[index] = match->next;
53846 + if (match->next != NULL)
53847 + match->next->prev = NULL;
53848 + } else {
53849 + match->prev->next = match->next;
53850 + if (match->next != NULL)
53851 + match->next->prev = match->prev;
53852 + }
53853 + match->prev = NULL;
53854 + match->next = NULL;
53855 + match->inode = newinode;
53856 + match->device = newdevice;
53857 + match->mode &= ~GR_DELETED;
53858 +
53859 + insert_acl_obj_label(match, subj);
53860 + }
53861 +
53862 + return;
53863 +}
53864 +
53865 +static void
53866 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53867 + const ino_t newinode, const dev_t newdevice,
53868 + struct acl_role_label *role)
53869 +{
53870 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53871 + struct acl_subject_label *match;
53872 +
53873 + match = role->subj_hash[index];
53874 +
53875 + while (match && (match->inode != oldinode ||
53876 + match->device != olddevice ||
53877 + !(match->mode & GR_DELETED)))
53878 + match = match->next;
53879 +
53880 + if (match && (match->inode == oldinode)
53881 + && (match->device == olddevice)
53882 + && (match->mode & GR_DELETED)) {
53883 + if (match->prev == NULL) {
53884 + role->subj_hash[index] = match->next;
53885 + if (match->next != NULL)
53886 + match->next->prev = NULL;
53887 + } else {
53888 + match->prev->next = match->next;
53889 + if (match->next != NULL)
53890 + match->next->prev = match->prev;
53891 + }
53892 + match->prev = NULL;
53893 + match->next = NULL;
53894 + match->inode = newinode;
53895 + match->device = newdevice;
53896 + match->mode &= ~GR_DELETED;
53897 +
53898 + insert_acl_subj_label(match, role);
53899 + }
53900 +
53901 + return;
53902 +}
53903 +
53904 +static void
53905 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53906 + const ino_t newinode, const dev_t newdevice)
53907 +{
53908 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53909 + struct inodev_entry *match;
53910 +
53911 + match = inodev_set.i_hash[index];
53912 +
53913 + while (match && (match->nentry->inode != oldinode ||
53914 + match->nentry->device != olddevice || !match->nentry->deleted))
53915 + match = match->next;
53916 +
53917 + if (match && (match->nentry->inode == oldinode)
53918 + && (match->nentry->device == olddevice) &&
53919 + match->nentry->deleted) {
53920 + if (match->prev == NULL) {
53921 + inodev_set.i_hash[index] = match->next;
53922 + if (match->next != NULL)
53923 + match->next->prev = NULL;
53924 + } else {
53925 + match->prev->next = match->next;
53926 + if (match->next != NULL)
53927 + match->next->prev = match->prev;
53928 + }
53929 + match->prev = NULL;
53930 + match->next = NULL;
53931 + match->nentry->inode = newinode;
53932 + match->nentry->device = newdevice;
53933 + match->nentry->deleted = 0;
53934 +
53935 + insert_inodev_entry(match);
53936 + }
53937 +
53938 + return;
53939 +}
53940 +
53941 +static void
53942 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53943 +{
53944 + struct acl_subject_label *subj;
53945 + struct acl_role_label *role;
53946 + unsigned int x;
53947 +
53948 + FOR_EACH_ROLE_START(role)
53949 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53950 +
53951 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53952 + if ((subj->inode == ino) && (subj->device == dev)) {
53953 + subj->inode = ino;
53954 + subj->device = dev;
53955 + }
53956 + FOR_EACH_NESTED_SUBJECT_END(subj)
53957 + FOR_EACH_SUBJECT_START(role, subj, x)
53958 + update_acl_obj_label(matchn->inode, matchn->device,
53959 + ino, dev, subj);
53960 + FOR_EACH_SUBJECT_END(subj,x)
53961 + FOR_EACH_ROLE_END(role)
53962 +
53963 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53964 +
53965 + return;
53966 +}
53967 +
53968 +static void
53969 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53970 + const struct vfsmount *mnt)
53971 +{
53972 + ino_t ino = dentry->d_inode->i_ino;
53973 + dev_t dev = __get_dev(dentry);
53974 +
53975 + __do_handle_create(matchn, ino, dev);
53976 +
53977 + return;
53978 +}
53979 +
53980 +void
53981 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53982 +{
53983 + struct name_entry *matchn;
53984 +
53985 + if (unlikely(!(gr_status & GR_READY)))
53986 + return;
53987 +
53988 + preempt_disable();
53989 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53990 +
53991 + if (unlikely((unsigned long)matchn)) {
53992 + write_lock(&gr_inode_lock);
53993 + do_handle_create(matchn, dentry, mnt);
53994 + write_unlock(&gr_inode_lock);
53995 + }
53996 + preempt_enable();
53997 +
53998 + return;
53999 +}
54000 +
54001 +void
54002 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54003 +{
54004 + struct name_entry *matchn;
54005 +
54006 + if (unlikely(!(gr_status & GR_READY)))
54007 + return;
54008 +
54009 + preempt_disable();
54010 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54011 +
54012 + if (unlikely((unsigned long)matchn)) {
54013 + write_lock(&gr_inode_lock);
54014 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54015 + write_unlock(&gr_inode_lock);
54016 + }
54017 + preempt_enable();
54018 +
54019 + return;
54020 +}
54021 +
54022 +void
54023 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54024 + struct dentry *old_dentry,
54025 + struct dentry *new_dentry,
54026 + struct vfsmount *mnt, const __u8 replace)
54027 +{
54028 + struct name_entry *matchn;
54029 + struct inodev_entry *inodev;
54030 + struct inode *inode = new_dentry->d_inode;
54031 + ino_t old_ino = old_dentry->d_inode->i_ino;
54032 + dev_t old_dev = __get_dev(old_dentry);
54033 +
54034 + /* vfs_rename swaps the name and parent link for old_dentry and
54035 + new_dentry
54036 + at this point, old_dentry has the new name, parent link, and inode
54037 + for the renamed file
54038 + if a file is being replaced by a rename, new_dentry has the inode
54039 + and name for the replaced file
54040 + */
54041 +
54042 + if (unlikely(!(gr_status & GR_READY)))
54043 + return;
54044 +
54045 + preempt_disable();
54046 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54047 +
54048 + /* we wouldn't have to check d_inode if it weren't for
54049 + NFS silly-renaming
54050 + */
54051 +
54052 + write_lock(&gr_inode_lock);
54053 + if (unlikely(replace && inode)) {
54054 + ino_t new_ino = inode->i_ino;
54055 + dev_t new_dev = __get_dev(new_dentry);
54056 +
54057 + inodev = lookup_inodev_entry(new_ino, new_dev);
54058 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54059 + do_handle_delete(inodev, new_ino, new_dev);
54060 + }
54061 +
54062 + inodev = lookup_inodev_entry(old_ino, old_dev);
54063 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54064 + do_handle_delete(inodev, old_ino, old_dev);
54065 +
54066 + if (unlikely((unsigned long)matchn))
54067 + do_handle_create(matchn, old_dentry, mnt);
54068 +
54069 + write_unlock(&gr_inode_lock);
54070 + preempt_enable();
54071 +
54072 + return;
54073 +}
54074 +
54075 +static int
54076 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54077 + unsigned char **sum)
54078 +{
54079 + struct acl_role_label *r;
54080 + struct role_allowed_ip *ipp;
54081 + struct role_transition *trans;
54082 + unsigned int i;
54083 + int found = 0;
54084 + u32 curr_ip = current->signal->curr_ip;
54085 +
54086 + current->signal->saved_ip = curr_ip;
54087 +
54088 + /* check transition table */
54089 +
54090 + for (trans = current->role->transitions; trans; trans = trans->next) {
54091 + if (!strcmp(rolename, trans->rolename)) {
54092 + found = 1;
54093 + break;
54094 + }
54095 + }
54096 +
54097 + if (!found)
54098 + return 0;
54099 +
54100 + /* handle special roles that do not require authentication
54101 + and check ip */
54102 +
54103 + FOR_EACH_ROLE_START(r)
54104 + if (!strcmp(rolename, r->rolename) &&
54105 + (r->roletype & GR_ROLE_SPECIAL)) {
54106 + found = 0;
54107 + if (r->allowed_ips != NULL) {
54108 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54109 + if ((ntohl(curr_ip) & ipp->netmask) ==
54110 + (ntohl(ipp->addr) & ipp->netmask))
54111 + found = 1;
54112 + }
54113 + } else
54114 + found = 2;
54115 + if (!found)
54116 + return 0;
54117 +
54118 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54119 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54120 + *salt = NULL;
54121 + *sum = NULL;
54122 + return 1;
54123 + }
54124 + }
54125 + FOR_EACH_ROLE_END(r)
54126 +
54127 + for (i = 0; i < num_sprole_pws; i++) {
54128 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54129 + *salt = acl_special_roles[i]->salt;
54130 + *sum = acl_special_roles[i]->sum;
54131 + return 1;
54132 + }
54133 + }
54134 +
54135 + return 0;
54136 +}
54137 +
54138 +static void
54139 +assign_special_role(char *rolename)
54140 +{
54141 + struct acl_object_label *obj;
54142 + struct acl_role_label *r;
54143 + struct acl_role_label *assigned = NULL;
54144 + struct task_struct *tsk;
54145 + struct file *filp;
54146 +
54147 + FOR_EACH_ROLE_START(r)
54148 + if (!strcmp(rolename, r->rolename) &&
54149 + (r->roletype & GR_ROLE_SPECIAL)) {
54150 + assigned = r;
54151 + break;
54152 + }
54153 + FOR_EACH_ROLE_END(r)
54154 +
54155 + if (!assigned)
54156 + return;
54157 +
54158 + read_lock(&tasklist_lock);
54159 + read_lock(&grsec_exec_file_lock);
54160 +
54161 + tsk = current->real_parent;
54162 + if (tsk == NULL)
54163 + goto out_unlock;
54164 +
54165 + filp = tsk->exec_file;
54166 + if (filp == NULL)
54167 + goto out_unlock;
54168 +
54169 + tsk->is_writable = 0;
54170 +
54171 + tsk->acl_sp_role = 1;
54172 + tsk->acl_role_id = ++acl_sp_role_value;
54173 + tsk->role = assigned;
54174 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54175 +
54176 + /* ignore additional mmap checks for processes that are writable
54177 + by the default ACL */
54178 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54179 + if (unlikely(obj->mode & GR_WRITE))
54180 + tsk->is_writable = 1;
54181 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54182 + if (unlikely(obj->mode & GR_WRITE))
54183 + tsk->is_writable = 1;
54184 +
54185 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54186 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54187 +#endif
54188 +
54189 +out_unlock:
54190 + read_unlock(&grsec_exec_file_lock);
54191 + read_unlock(&tasklist_lock);
54192 + return;
54193 +}
54194 +
54195 +int gr_check_secure_terminal(struct task_struct *task)
54196 +{
54197 + struct task_struct *p, *p2, *p3;
54198 + struct files_struct *files;
54199 + struct fdtable *fdt;
54200 + struct file *our_file = NULL, *file;
54201 + int i;
54202 +
54203 + if (task->signal->tty == NULL)
54204 + return 1;
54205 +
54206 + files = get_files_struct(task);
54207 + if (files != NULL) {
54208 + rcu_read_lock();
54209 + fdt = files_fdtable(files);
54210 + for (i=0; i < fdt->max_fds; i++) {
54211 + file = fcheck_files(files, i);
54212 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54213 + get_file(file);
54214 + our_file = file;
54215 + }
54216 + }
54217 + rcu_read_unlock();
54218 + put_files_struct(files);
54219 + }
54220 +
54221 + if (our_file == NULL)
54222 + return 1;
54223 +
54224 + read_lock(&tasklist_lock);
54225 + do_each_thread(p2, p) {
54226 + files = get_files_struct(p);
54227 + if (files == NULL ||
54228 + (p->signal && p->signal->tty == task->signal->tty)) {
54229 + if (files != NULL)
54230 + put_files_struct(files);
54231 + continue;
54232 + }
54233 + rcu_read_lock();
54234 + fdt = files_fdtable(files);
54235 + for (i=0; i < fdt->max_fds; i++) {
54236 + file = fcheck_files(files, i);
54237 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54238 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54239 + p3 = task;
54240 + while (p3->pid > 0) {
54241 + if (p3 == p)
54242 + break;
54243 + p3 = p3->real_parent;
54244 + }
54245 + if (p3 == p)
54246 + break;
54247 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54248 + gr_handle_alertkill(p);
54249 + rcu_read_unlock();
54250 + put_files_struct(files);
54251 + read_unlock(&tasklist_lock);
54252 + fput(our_file);
54253 + return 0;
54254 + }
54255 + }
54256 + rcu_read_unlock();
54257 + put_files_struct(files);
54258 + } while_each_thread(p2, p);
54259 + read_unlock(&tasklist_lock);
54260 +
54261 + fput(our_file);
54262 + return 1;
54263 +}
54264 +
54265 +ssize_t
54266 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54267 +{
54268 + struct gr_arg_wrapper uwrap;
54269 + unsigned char *sprole_salt = NULL;
54270 + unsigned char *sprole_sum = NULL;
54271 + int error = sizeof (struct gr_arg_wrapper);
54272 + int error2 = 0;
54273 +
54274 + mutex_lock(&gr_dev_mutex);
54275 +
54276 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54277 + error = -EPERM;
54278 + goto out;
54279 + }
54280 +
54281 + if (count != sizeof (struct gr_arg_wrapper)) {
54282 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54283 + error = -EINVAL;
54284 + goto out;
54285 + }
54286 +
54287 +
54288 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54289 + gr_auth_expires = 0;
54290 + gr_auth_attempts = 0;
54291 + }
54292 +
54293 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54294 + error = -EFAULT;
54295 + goto out;
54296 + }
54297 +
54298 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54299 + error = -EINVAL;
54300 + goto out;
54301 + }
54302 +
54303 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54304 + error = -EFAULT;
54305 + goto out;
54306 + }
54307 +
54308 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54309 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54310 + time_after(gr_auth_expires, get_seconds())) {
54311 + error = -EBUSY;
54312 + goto out;
54313 + }
54314 +
54315 + /* if non-root trying to do anything other than use a special role,
54316 + do not attempt authentication, do not count towards authentication
54317 + locking
54318 + */
54319 +
54320 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54321 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54322 + current_uid()) {
54323 + error = -EPERM;
54324 + goto out;
54325 + }
54326 +
54327 + /* ensure pw and special role name are null terminated */
54328 +
54329 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54330 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54331 +
54332 + /* Okay.
54333 + * We have our enough of the argument structure..(we have yet
54334 + * to copy_from_user the tables themselves) . Copy the tables
54335 + * only if we need them, i.e. for loading operations. */
54336 +
54337 + switch (gr_usermode->mode) {
54338 + case GR_STATUS:
54339 + if (gr_status & GR_READY) {
54340 + error = 1;
54341 + if (!gr_check_secure_terminal(current))
54342 + error = 3;
54343 + } else
54344 + error = 2;
54345 + goto out;
54346 + case GR_SHUTDOWN:
54347 + if ((gr_status & GR_READY)
54348 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54349 + pax_open_kernel();
54350 + gr_status &= ~GR_READY;
54351 + pax_close_kernel();
54352 +
54353 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54354 + free_variables();
54355 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54356 + memset(gr_system_salt, 0, GR_SALT_LEN);
54357 + memset(gr_system_sum, 0, GR_SHA_LEN);
54358 + } else if (gr_status & GR_READY) {
54359 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54360 + error = -EPERM;
54361 + } else {
54362 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54363 + error = -EAGAIN;
54364 + }
54365 + break;
54366 + case GR_ENABLE:
54367 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54368 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54369 + else {
54370 + if (gr_status & GR_READY)
54371 + error = -EAGAIN;
54372 + else
54373 + error = error2;
54374 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54375 + }
54376 + break;
54377 + case GR_RELOAD:
54378 + if (!(gr_status & GR_READY)) {
54379 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54380 + error = -EAGAIN;
54381 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54382 + preempt_disable();
54383 +
54384 + pax_open_kernel();
54385 + gr_status &= ~GR_READY;
54386 + pax_close_kernel();
54387 +
54388 + free_variables();
54389 + if (!(error2 = gracl_init(gr_usermode))) {
54390 + preempt_enable();
54391 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54392 + } else {
54393 + preempt_enable();
54394 + error = error2;
54395 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54396 + }
54397 + } else {
54398 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54399 + error = -EPERM;
54400 + }
54401 + break;
54402 + case GR_SEGVMOD:
54403 + if (unlikely(!(gr_status & GR_READY))) {
54404 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54405 + error = -EAGAIN;
54406 + break;
54407 + }
54408 +
54409 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54410 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54411 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54412 + struct acl_subject_label *segvacl;
54413 + segvacl =
54414 + lookup_acl_subj_label(gr_usermode->segv_inode,
54415 + gr_usermode->segv_device,
54416 + current->role);
54417 + if (segvacl) {
54418 + segvacl->crashes = 0;
54419 + segvacl->expires = 0;
54420 + }
54421 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54422 + gr_remove_uid(gr_usermode->segv_uid);
54423 + }
54424 + } else {
54425 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54426 + error = -EPERM;
54427 + }
54428 + break;
54429 + case GR_SPROLE:
54430 + case GR_SPROLEPAM:
54431 + if (unlikely(!(gr_status & GR_READY))) {
54432 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54433 + error = -EAGAIN;
54434 + break;
54435 + }
54436 +
54437 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54438 + current->role->expires = 0;
54439 + current->role->auth_attempts = 0;
54440 + }
54441 +
54442 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54443 + time_after(current->role->expires, get_seconds())) {
54444 + error = -EBUSY;
54445 + goto out;
54446 + }
54447 +
54448 + if (lookup_special_role_auth
54449 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54450 + && ((!sprole_salt && !sprole_sum)
54451 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54452 + char *p = "";
54453 + assign_special_role(gr_usermode->sp_role);
54454 + read_lock(&tasklist_lock);
54455 + if (current->real_parent)
54456 + p = current->real_parent->role->rolename;
54457 + read_unlock(&tasklist_lock);
54458 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54459 + p, acl_sp_role_value);
54460 + } else {
54461 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54462 + error = -EPERM;
54463 + if(!(current->role->auth_attempts++))
54464 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54465 +
54466 + goto out;
54467 + }
54468 + break;
54469 + case GR_UNSPROLE:
54470 + if (unlikely(!(gr_status & GR_READY))) {
54471 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54472 + error = -EAGAIN;
54473 + break;
54474 + }
54475 +
54476 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54477 + char *p = "";
54478 + int i = 0;
54479 +
54480 + read_lock(&tasklist_lock);
54481 + if (current->real_parent) {
54482 + p = current->real_parent->role->rolename;
54483 + i = current->real_parent->acl_role_id;
54484 + }
54485 + read_unlock(&tasklist_lock);
54486 +
54487 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54488 + gr_set_acls(1);
54489 + } else {
54490 + error = -EPERM;
54491 + goto out;
54492 + }
54493 + break;
54494 + default:
54495 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54496 + error = -EINVAL;
54497 + break;
54498 + }
54499 +
54500 + if (error != -EPERM)
54501 + goto out;
54502 +
54503 + if(!(gr_auth_attempts++))
54504 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54505 +
54506 + out:
54507 + mutex_unlock(&gr_dev_mutex);
54508 + return error;
54509 +}
54510 +
54511 +/* must be called with
54512 + rcu_read_lock();
54513 + read_lock(&tasklist_lock);
54514 + read_lock(&grsec_exec_file_lock);
54515 +*/
54516 +int gr_apply_subject_to_task(struct task_struct *task)
54517 +{
54518 + struct acl_object_label *obj;
54519 + char *tmpname;
54520 + struct acl_subject_label *tmpsubj;
54521 + struct file *filp;
54522 + struct name_entry *nmatch;
54523 +
54524 + filp = task->exec_file;
54525 + if (filp == NULL)
54526 + return 0;
54527 +
54528 + /* the following is to apply the correct subject
54529 + on binaries running when the RBAC system
54530 + is enabled, when the binaries have been
54531 + replaced or deleted since their execution
54532 + -----
54533 + when the RBAC system starts, the inode/dev
54534 + from exec_file will be one the RBAC system
54535 + is unaware of. It only knows the inode/dev
54536 + of the present file on disk, or the absence
54537 + of it.
54538 + */
54539 + preempt_disable();
54540 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54541 +
54542 + nmatch = lookup_name_entry(tmpname);
54543 + preempt_enable();
54544 + tmpsubj = NULL;
54545 + if (nmatch) {
54546 + if (nmatch->deleted)
54547 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54548 + else
54549 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54550 + if (tmpsubj != NULL)
54551 + task->acl = tmpsubj;
54552 + }
54553 + if (tmpsubj == NULL)
54554 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54555 + task->role);
54556 + if (task->acl) {
54557 + task->is_writable = 0;
54558 + /* ignore additional mmap checks for processes that are writable
54559 + by the default ACL */
54560 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54561 + if (unlikely(obj->mode & GR_WRITE))
54562 + task->is_writable = 1;
54563 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54564 + if (unlikely(obj->mode & GR_WRITE))
54565 + task->is_writable = 1;
54566 +
54567 + gr_set_proc_res(task);
54568 +
54569 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54570 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54571 +#endif
54572 + } else {
54573 + return 1;
54574 + }
54575 +
54576 + return 0;
54577 +}
54578 +
54579 +int
54580 +gr_set_acls(const int type)
54581 +{
54582 + struct task_struct *task, *task2;
54583 + struct acl_role_label *role = current->role;
54584 + __u16 acl_role_id = current->acl_role_id;
54585 + const struct cred *cred;
54586 + int ret;
54587 +
54588 + rcu_read_lock();
54589 + read_lock(&tasklist_lock);
54590 + read_lock(&grsec_exec_file_lock);
54591 + do_each_thread(task2, task) {
54592 + /* check to see if we're called from the exit handler,
54593 + if so, only replace ACLs that have inherited the admin
54594 + ACL */
54595 +
54596 + if (type && (task->role != role ||
54597 + task->acl_role_id != acl_role_id))
54598 + continue;
54599 +
54600 + task->acl_role_id = 0;
54601 + task->acl_sp_role = 0;
54602 +
54603 + if (task->exec_file) {
54604 + cred = __task_cred(task);
54605 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54606 + ret = gr_apply_subject_to_task(task);
54607 + if (ret) {
54608 + read_unlock(&grsec_exec_file_lock);
54609 + read_unlock(&tasklist_lock);
54610 + rcu_read_unlock();
54611 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54612 + return ret;
54613 + }
54614 + } else {
54615 + // it's a kernel process
54616 + task->role = kernel_role;
54617 + task->acl = kernel_role->root_label;
54618 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54619 + task->acl->mode &= ~GR_PROCFIND;
54620 +#endif
54621 + }
54622 + } while_each_thread(task2, task);
54623 + read_unlock(&grsec_exec_file_lock);
54624 + read_unlock(&tasklist_lock);
54625 + rcu_read_unlock();
54626 +
54627 + return 0;
54628 +}
54629 +
54630 +void
54631 +gr_learn_resource(const struct task_struct *task,
54632 + const int res, const unsigned long wanted, const int gt)
54633 +{
54634 + struct acl_subject_label *acl;
54635 + const struct cred *cred;
54636 +
54637 + if (unlikely((gr_status & GR_READY) &&
54638 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54639 + goto skip_reslog;
54640 +
54641 +#ifdef CONFIG_GRKERNSEC_RESLOG
54642 + gr_log_resource(task, res, wanted, gt);
54643 +#endif
54644 + skip_reslog:
54645 +
54646 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54647 + return;
54648 +
54649 + acl = task->acl;
54650 +
54651 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54652 + !(acl->resmask & (1 << (unsigned short) res))))
54653 + return;
54654 +
54655 + if (wanted >= acl->res[res].rlim_cur) {
54656 + unsigned long res_add;
54657 +
54658 + res_add = wanted;
54659 + switch (res) {
54660 + case RLIMIT_CPU:
54661 + res_add += GR_RLIM_CPU_BUMP;
54662 + break;
54663 + case RLIMIT_FSIZE:
54664 + res_add += GR_RLIM_FSIZE_BUMP;
54665 + break;
54666 + case RLIMIT_DATA:
54667 + res_add += GR_RLIM_DATA_BUMP;
54668 + break;
54669 + case RLIMIT_STACK:
54670 + res_add += GR_RLIM_STACK_BUMP;
54671 + break;
54672 + case RLIMIT_CORE:
54673 + res_add += GR_RLIM_CORE_BUMP;
54674 + break;
54675 + case RLIMIT_RSS:
54676 + res_add += GR_RLIM_RSS_BUMP;
54677 + break;
54678 + case RLIMIT_NPROC:
54679 + res_add += GR_RLIM_NPROC_BUMP;
54680 + break;
54681 + case RLIMIT_NOFILE:
54682 + res_add += GR_RLIM_NOFILE_BUMP;
54683 + break;
54684 + case RLIMIT_MEMLOCK:
54685 + res_add += GR_RLIM_MEMLOCK_BUMP;
54686 + break;
54687 + case RLIMIT_AS:
54688 + res_add += GR_RLIM_AS_BUMP;
54689 + break;
54690 + case RLIMIT_LOCKS:
54691 + res_add += GR_RLIM_LOCKS_BUMP;
54692 + break;
54693 + case RLIMIT_SIGPENDING:
54694 + res_add += GR_RLIM_SIGPENDING_BUMP;
54695 + break;
54696 + case RLIMIT_MSGQUEUE:
54697 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54698 + break;
54699 + case RLIMIT_NICE:
54700 + res_add += GR_RLIM_NICE_BUMP;
54701 + break;
54702 + case RLIMIT_RTPRIO:
54703 + res_add += GR_RLIM_RTPRIO_BUMP;
54704 + break;
54705 + case RLIMIT_RTTIME:
54706 + res_add += GR_RLIM_RTTIME_BUMP;
54707 + break;
54708 + }
54709 +
54710 + acl->res[res].rlim_cur = res_add;
54711 +
54712 + if (wanted > acl->res[res].rlim_max)
54713 + acl->res[res].rlim_max = res_add;
54714 +
54715 + /* only log the subject filename, since resource logging is supported for
54716 + single-subject learning only */
54717 + rcu_read_lock();
54718 + cred = __task_cred(task);
54719 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54720 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54721 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54722 + "", (unsigned long) res, &task->signal->saved_ip);
54723 + rcu_read_unlock();
54724 + }
54725 +
54726 + return;
54727 +}
54728 +
54729 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54730 +void
54731 +pax_set_initial_flags(struct linux_binprm *bprm)
54732 +{
54733 + struct task_struct *task = current;
54734 + struct acl_subject_label *proc;
54735 + unsigned long flags;
54736 +
54737 + if (unlikely(!(gr_status & GR_READY)))
54738 + return;
54739 +
54740 + flags = pax_get_flags(task);
54741 +
54742 + proc = task->acl;
54743 +
54744 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54745 + flags &= ~MF_PAX_PAGEEXEC;
54746 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54747 + flags &= ~MF_PAX_SEGMEXEC;
54748 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54749 + flags &= ~MF_PAX_RANDMMAP;
54750 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54751 + flags &= ~MF_PAX_EMUTRAMP;
54752 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54753 + flags &= ~MF_PAX_MPROTECT;
54754 +
54755 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54756 + flags |= MF_PAX_PAGEEXEC;
54757 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54758 + flags |= MF_PAX_SEGMEXEC;
54759 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54760 + flags |= MF_PAX_RANDMMAP;
54761 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54762 + flags |= MF_PAX_EMUTRAMP;
54763 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54764 + flags |= MF_PAX_MPROTECT;
54765 +
54766 + pax_set_flags(task, flags);
54767 +
54768 + return;
54769 +}
54770 +#endif
54771 +
54772 +#ifdef CONFIG_SYSCTL
54773 +/* Eric Biederman likes breaking userland ABI and every inode-based security
54774 + system to save 35kb of memory */
54775 +
54776 +/* we modify the passed in filename, but adjust it back before returning */
54777 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54778 +{
54779 + struct name_entry *nmatch;
54780 + char *p, *lastp = NULL;
54781 + struct acl_object_label *obj = NULL, *tmp;
54782 + struct acl_subject_label *tmpsubj;
54783 + char c = '\0';
54784 +
54785 + read_lock(&gr_inode_lock);
54786 +
54787 + p = name + len - 1;
54788 + do {
54789 + nmatch = lookup_name_entry(name);
54790 + if (lastp != NULL)
54791 + *lastp = c;
54792 +
54793 + if (nmatch == NULL)
54794 + goto next_component;
54795 + tmpsubj = current->acl;
54796 + do {
54797 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54798 + if (obj != NULL) {
54799 + tmp = obj->globbed;
54800 + while (tmp) {
54801 + if (!glob_match(tmp->filename, name)) {
54802 + obj = tmp;
54803 + goto found_obj;
54804 + }
54805 + tmp = tmp->next;
54806 + }
54807 + goto found_obj;
54808 + }
54809 + } while ((tmpsubj = tmpsubj->parent_subject));
54810 +next_component:
54811 + /* end case */
54812 + if (p == name)
54813 + break;
54814 +
54815 + while (*p != '/')
54816 + p--;
54817 + if (p == name)
54818 + lastp = p + 1;
54819 + else {
54820 + lastp = p;
54821 + p--;
54822 + }
54823 + c = *lastp;
54824 + *lastp = '\0';
54825 + } while (1);
54826 +found_obj:
54827 + read_unlock(&gr_inode_lock);
54828 + /* obj returned will always be non-null */
54829 + return obj;
54830 +}
54831 +
54832 +/* returns 0 when allowing, non-zero on error
54833 + op of 0 is used for readdir, so we don't log the names of hidden files
54834 +*/
54835 +__u32
54836 +gr_handle_sysctl(const struct ctl_table *table, const int op)
54837 +{
54838 + struct ctl_table *tmp;
54839 + const char *proc_sys = "/proc/sys";
54840 + char *path;
54841 + struct acl_object_label *obj;
54842 + unsigned short len = 0, pos = 0, depth = 0, i;
54843 + __u32 err = 0;
54844 + __u32 mode = 0;
54845 +
54846 + if (unlikely(!(gr_status & GR_READY)))
54847 + return 0;
54848 +
54849 + /* for now, ignore operations on non-sysctl entries if it's not a
54850 + readdir*/
54851 + if (table->child != NULL && op != 0)
54852 + return 0;
54853 +
54854 + mode |= GR_FIND;
54855 + /* it's only a read if it's an entry, read on dirs is for readdir */
54856 + if (op & MAY_READ)
54857 + mode |= GR_READ;
54858 + if (op & MAY_WRITE)
54859 + mode |= GR_WRITE;
54860 +
54861 + preempt_disable();
54862 +
54863 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54864 +
54865 + /* it's only a read/write if it's an actual entry, not a dir
54866 + (which are opened for readdir)
54867 + */
54868 +
54869 + /* convert the requested sysctl entry into a pathname */
54870 +
54871 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54872 + len += strlen(tmp->procname);
54873 + len++;
54874 + depth++;
54875 + }
54876 +
54877 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54878 + /* deny */
54879 + goto out;
54880 + }
54881 +
54882 + memset(path, 0, PAGE_SIZE);
54883 +
54884 + memcpy(path, proc_sys, strlen(proc_sys));
54885 +
54886 + pos += strlen(proc_sys);
54887 +
54888 + for (; depth > 0; depth--) {
54889 + path[pos] = '/';
54890 + pos++;
54891 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54892 + if (depth == i) {
54893 + memcpy(path + pos, tmp->procname,
54894 + strlen(tmp->procname));
54895 + pos += strlen(tmp->procname);
54896 + }
54897 + i++;
54898 + }
54899 + }
54900 +
54901 + obj = gr_lookup_by_name(path, pos);
54902 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54903 +
54904 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54905 + ((err & mode) != mode))) {
54906 + __u32 new_mode = mode;
54907 +
54908 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54909 +
54910 + err = 0;
54911 + gr_log_learn_sysctl(path, new_mode);
54912 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54913 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54914 + err = -ENOENT;
54915 + } else if (!(err & GR_FIND)) {
54916 + err = -ENOENT;
54917 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54918 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54919 + path, (mode & GR_READ) ? " reading" : "",
54920 + (mode & GR_WRITE) ? " writing" : "");
54921 + err = -EACCES;
54922 + } else if ((err & mode) != mode) {
54923 + err = -EACCES;
54924 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54925 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54926 + path, (mode & GR_READ) ? " reading" : "",
54927 + (mode & GR_WRITE) ? " writing" : "");
54928 + err = 0;
54929 + } else
54930 + err = 0;
54931 +
54932 + out:
54933 + preempt_enable();
54934 +
54935 + return err;
54936 +}
54937 +#endif
54938 +
54939 +int
54940 +gr_handle_proc_ptrace(struct task_struct *task)
54941 +{
54942 + struct file *filp;
54943 + struct task_struct *tmp = task;
54944 + struct task_struct *curtemp = current;
54945 + __u32 retmode;
54946 +
54947 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54948 + if (unlikely(!(gr_status & GR_READY)))
54949 + return 0;
54950 +#endif
54951 +
54952 + read_lock(&tasklist_lock);
54953 + read_lock(&grsec_exec_file_lock);
54954 + filp = task->exec_file;
54955 +
54956 + while (tmp->pid > 0) {
54957 + if (tmp == curtemp)
54958 + break;
54959 + tmp = tmp->real_parent;
54960 + }
54961 +
54962 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54963 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54964 + read_unlock(&grsec_exec_file_lock);
54965 + read_unlock(&tasklist_lock);
54966 + return 1;
54967 + }
54968 +
54969 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54970 + if (!(gr_status & GR_READY)) {
54971 + read_unlock(&grsec_exec_file_lock);
54972 + read_unlock(&tasklist_lock);
54973 + return 0;
54974 + }
54975 +#endif
54976 +
54977 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54978 + read_unlock(&grsec_exec_file_lock);
54979 + read_unlock(&tasklist_lock);
54980 +
54981 + if (retmode & GR_NOPTRACE)
54982 + return 1;
54983 +
54984 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54985 + && (current->acl != task->acl || (current->acl != current->role->root_label
54986 + && current->pid != task->pid)))
54987 + return 1;
54988 +
54989 + return 0;
54990 +}
54991 +
54992 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54993 +{
54994 + if (unlikely(!(gr_status & GR_READY)))
54995 + return;
54996 +
54997 + if (!(current->role->roletype & GR_ROLE_GOD))
54998 + return;
54999 +
55000 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55001 + p->role->rolename, gr_task_roletype_to_char(p),
55002 + p->acl->filename);
55003 +}
55004 +
55005 +int
55006 +gr_handle_ptrace(struct task_struct *task, const long request)
55007 +{
55008 + struct task_struct *tmp = task;
55009 + struct task_struct *curtemp = current;
55010 + __u32 retmode;
55011 +
55012 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55013 + if (unlikely(!(gr_status & GR_READY)))
55014 + return 0;
55015 +#endif
55016 +
55017 + read_lock(&tasklist_lock);
55018 + while (tmp->pid > 0) {
55019 + if (tmp == curtemp)
55020 + break;
55021 + tmp = tmp->real_parent;
55022 + }
55023 +
55024 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55025 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55026 + read_unlock(&tasklist_lock);
55027 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55028 + return 1;
55029 + }
55030 + read_unlock(&tasklist_lock);
55031 +
55032 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55033 + if (!(gr_status & GR_READY))
55034 + return 0;
55035 +#endif
55036 +
55037 + read_lock(&grsec_exec_file_lock);
55038 + if (unlikely(!task->exec_file)) {
55039 + read_unlock(&grsec_exec_file_lock);
55040 + return 0;
55041 + }
55042 +
55043 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55044 + read_unlock(&grsec_exec_file_lock);
55045 +
55046 + if (retmode & GR_NOPTRACE) {
55047 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55048 + return 1;
55049 + }
55050 +
55051 + if (retmode & GR_PTRACERD) {
55052 + switch (request) {
55053 + case PTRACE_SEIZE:
55054 + case PTRACE_POKETEXT:
55055 + case PTRACE_POKEDATA:
55056 + case PTRACE_POKEUSR:
55057 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55058 + case PTRACE_SETREGS:
55059 + case PTRACE_SETFPREGS:
55060 +#endif
55061 +#ifdef CONFIG_X86
55062 + case PTRACE_SETFPXREGS:
55063 +#endif
55064 +#ifdef CONFIG_ALTIVEC
55065 + case PTRACE_SETVRREGS:
55066 +#endif
55067 + return 1;
55068 + default:
55069 + return 0;
55070 + }
55071 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55072 + !(current->role->roletype & GR_ROLE_GOD) &&
55073 + (current->acl != task->acl)) {
55074 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55075 + return 1;
55076 + }
55077 +
55078 + return 0;
55079 +}
55080 +
55081 +static int is_writable_mmap(const struct file *filp)
55082 +{
55083 + struct task_struct *task = current;
55084 + struct acl_object_label *obj, *obj2;
55085 +
55086 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55087 + !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))) {
55088 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55089 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55090 + task->role->root_label);
55091 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55092 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55093 + return 1;
55094 + }
55095 + }
55096 + return 0;
55097 +}
55098 +
55099 +int
55100 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55101 +{
55102 + __u32 mode;
55103 +
55104 + if (unlikely(!file || !(prot & PROT_EXEC)))
55105 + return 1;
55106 +
55107 + if (is_writable_mmap(file))
55108 + return 0;
55109 +
55110 + mode =
55111 + gr_search_file(file->f_path.dentry,
55112 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55113 + file->f_path.mnt);
55114 +
55115 + if (!gr_tpe_allow(file))
55116 + return 0;
55117 +
55118 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55119 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55120 + return 0;
55121 + } else if (unlikely(!(mode & GR_EXEC))) {
55122 + return 0;
55123 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55124 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55125 + return 1;
55126 + }
55127 +
55128 + return 1;
55129 +}
55130 +
55131 +int
55132 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55133 +{
55134 + __u32 mode;
55135 +
55136 + if (unlikely(!file || !(prot & PROT_EXEC)))
55137 + return 1;
55138 +
55139 + if (is_writable_mmap(file))
55140 + return 0;
55141 +
55142 + mode =
55143 + gr_search_file(file->f_path.dentry,
55144 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55145 + file->f_path.mnt);
55146 +
55147 + if (!gr_tpe_allow(file))
55148 + return 0;
55149 +
55150 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55151 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55152 + return 0;
55153 + } else if (unlikely(!(mode & GR_EXEC))) {
55154 + return 0;
55155 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55156 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55157 + return 1;
55158 + }
55159 +
55160 + return 1;
55161 +}
55162 +
55163 +void
55164 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55165 +{
55166 + unsigned long runtime;
55167 + unsigned long cputime;
55168 + unsigned int wday, cday;
55169 + __u8 whr, chr;
55170 + __u8 wmin, cmin;
55171 + __u8 wsec, csec;
55172 + struct timespec timeval;
55173 +
55174 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55175 + !(task->acl->mode & GR_PROCACCT)))
55176 + return;
55177 +
55178 + do_posix_clock_monotonic_gettime(&timeval);
55179 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55180 + wday = runtime / (3600 * 24);
55181 + runtime -= wday * (3600 * 24);
55182 + whr = runtime / 3600;
55183 + runtime -= whr * 3600;
55184 + wmin = runtime / 60;
55185 + runtime -= wmin * 60;
55186 + wsec = runtime;
55187 +
55188 + cputime = (task->utime + task->stime) / HZ;
55189 + cday = cputime / (3600 * 24);
55190 + cputime -= cday * (3600 * 24);
55191 + chr = cputime / 3600;
55192 + cputime -= chr * 3600;
55193 + cmin = cputime / 60;
55194 + cputime -= cmin * 60;
55195 + csec = cputime;
55196 +
55197 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55198 +
55199 + return;
55200 +}
55201 +
55202 +void gr_set_kernel_label(struct task_struct *task)
55203 +{
55204 + if (gr_status & GR_READY) {
55205 + task->role = kernel_role;
55206 + task->acl = kernel_role->root_label;
55207 + }
55208 + return;
55209 +}
55210 +
55211 +#ifdef CONFIG_TASKSTATS
55212 +int gr_is_taskstats_denied(int pid)
55213 +{
55214 + struct task_struct *task;
55215 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55216 + const struct cred *cred;
55217 +#endif
55218 + int ret = 0;
55219 +
55220 + /* restrict taskstats viewing to un-chrooted root users
55221 + who have the 'view' subject flag if the RBAC system is enabled
55222 + */
55223 +
55224 + rcu_read_lock();
55225 + read_lock(&tasklist_lock);
55226 + task = find_task_by_vpid(pid);
55227 + if (task) {
55228 +#ifdef CONFIG_GRKERNSEC_CHROOT
55229 + if (proc_is_chrooted(task))
55230 + ret = -EACCES;
55231 +#endif
55232 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55233 + cred = __task_cred(task);
55234 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55235 + if (cred->uid != 0)
55236 + ret = -EACCES;
55237 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55238 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55239 + ret = -EACCES;
55240 +#endif
55241 +#endif
55242 + if (gr_status & GR_READY) {
55243 + if (!(task->acl->mode & GR_VIEW))
55244 + ret = -EACCES;
55245 + }
55246 + } else
55247 + ret = -ENOENT;
55248 +
55249 + read_unlock(&tasklist_lock);
55250 + rcu_read_unlock();
55251 +
55252 + return ret;
55253 +}
55254 +#endif
55255 +
55256 +/* AUXV entries are filled via a descendant of search_binary_handler
55257 + after we've already applied the subject for the target
55258 +*/
55259 +int gr_acl_enable_at_secure(void)
55260 +{
55261 + if (unlikely(!(gr_status & GR_READY)))
55262 + return 0;
55263 +
55264 + if (current->acl->mode & GR_ATSECURE)
55265 + return 1;
55266 +
55267 + return 0;
55268 +}
55269 +
55270 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55271 +{
55272 + struct task_struct *task = current;
55273 + struct dentry *dentry = file->f_path.dentry;
55274 + struct vfsmount *mnt = file->f_path.mnt;
55275 + struct acl_object_label *obj, *tmp;
55276 + struct acl_subject_label *subj;
55277 + unsigned int bufsize;
55278 + int is_not_root;
55279 + char *path;
55280 + dev_t dev = __get_dev(dentry);
55281 +
55282 + if (unlikely(!(gr_status & GR_READY)))
55283 + return 1;
55284 +
55285 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55286 + return 1;
55287 +
55288 + /* ignore Eric Biederman */
55289 + if (IS_PRIVATE(dentry->d_inode))
55290 + return 1;
55291 +
55292 + subj = task->acl;
55293 + do {
55294 + obj = lookup_acl_obj_label(ino, dev, subj);
55295 + if (obj != NULL)
55296 + return (obj->mode & GR_FIND) ? 1 : 0;
55297 + } while ((subj = subj->parent_subject));
55298 +
55299 + /* this is purely an optimization since we're looking for an object
55300 + for the directory we're doing a readdir on
55301 + if it's possible for any globbed object to match the entry we're
55302 + filling into the directory, then the object we find here will be
55303 + an anchor point with attached globbed objects
55304 + */
55305 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55306 + if (obj->globbed == NULL)
55307 + return (obj->mode & GR_FIND) ? 1 : 0;
55308 +
55309 + is_not_root = ((obj->filename[0] == '/') &&
55310 + (obj->filename[1] == '\0')) ? 0 : 1;
55311 + bufsize = PAGE_SIZE - namelen - is_not_root;
55312 +
55313 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55314 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55315 + return 1;
55316 +
55317 + preempt_disable();
55318 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55319 + bufsize);
55320 +
55321 + bufsize = strlen(path);
55322 +
55323 + /* if base is "/", don't append an additional slash */
55324 + if (is_not_root)
55325 + *(path + bufsize) = '/';
55326 + memcpy(path + bufsize + is_not_root, name, namelen);
55327 + *(path + bufsize + namelen + is_not_root) = '\0';
55328 +
55329 + tmp = obj->globbed;
55330 + while (tmp) {
55331 + if (!glob_match(tmp->filename, path)) {
55332 + preempt_enable();
55333 + return (tmp->mode & GR_FIND) ? 1 : 0;
55334 + }
55335 + tmp = tmp->next;
55336 + }
55337 + preempt_enable();
55338 + return (obj->mode & GR_FIND) ? 1 : 0;
55339 +}
55340 +
55341 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55342 +EXPORT_SYMBOL(gr_acl_is_enabled);
55343 +#endif
55344 +EXPORT_SYMBOL(gr_learn_resource);
55345 +EXPORT_SYMBOL(gr_set_kernel_label);
55346 +#ifdef CONFIG_SECURITY
55347 +EXPORT_SYMBOL(gr_check_user_change);
55348 +EXPORT_SYMBOL(gr_check_group_change);
55349 +#endif
55350 +
55351 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55352 new file mode 100644
55353 index 0000000..34fefda
55354 --- /dev/null
55355 +++ b/grsecurity/gracl_alloc.c
55356 @@ -0,0 +1,105 @@
55357 +#include <linux/kernel.h>
55358 +#include <linux/mm.h>
55359 +#include <linux/slab.h>
55360 +#include <linux/vmalloc.h>
55361 +#include <linux/gracl.h>
55362 +#include <linux/grsecurity.h>
55363 +
55364 +static unsigned long alloc_stack_next = 1;
55365 +static unsigned long alloc_stack_size = 1;
55366 +static void **alloc_stack;
55367 +
55368 +static __inline__ int
55369 +alloc_pop(void)
55370 +{
55371 + if (alloc_stack_next == 1)
55372 + return 0;
55373 +
55374 + kfree(alloc_stack[alloc_stack_next - 2]);
55375 +
55376 + alloc_stack_next--;
55377 +
55378 + return 1;
55379 +}
55380 +
55381 +static __inline__ int
55382 +alloc_push(void *buf)
55383 +{
55384 + if (alloc_stack_next >= alloc_stack_size)
55385 + return 1;
55386 +
55387 + alloc_stack[alloc_stack_next - 1] = buf;
55388 +
55389 + alloc_stack_next++;
55390 +
55391 + return 0;
55392 +}
55393 +
55394 +void *
55395 +acl_alloc(unsigned long len)
55396 +{
55397 + void *ret = NULL;
55398 +
55399 + if (!len || len > PAGE_SIZE)
55400 + goto out;
55401 +
55402 + ret = kmalloc(len, GFP_KERNEL);
55403 +
55404 + if (ret) {
55405 + if (alloc_push(ret)) {
55406 + kfree(ret);
55407 + ret = NULL;
55408 + }
55409 + }
55410 +
55411 +out:
55412 + return ret;
55413 +}
55414 +
55415 +void *
55416 +acl_alloc_num(unsigned long num, unsigned long len)
55417 +{
55418 + if (!len || (num > (PAGE_SIZE / len)))
55419 + return NULL;
55420 +
55421 + return acl_alloc(num * len);
55422 +}
55423 +
55424 +void
55425 +acl_free_all(void)
55426 +{
55427 + if (gr_acl_is_enabled() || !alloc_stack)
55428 + return;
55429 +
55430 + while (alloc_pop()) ;
55431 +
55432 + if (alloc_stack) {
55433 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55434 + kfree(alloc_stack);
55435 + else
55436 + vfree(alloc_stack);
55437 + }
55438 +
55439 + alloc_stack = NULL;
55440 + alloc_stack_size = 1;
55441 + alloc_stack_next = 1;
55442 +
55443 + return;
55444 +}
55445 +
55446 +int
55447 +acl_alloc_stack_init(unsigned long size)
55448 +{
55449 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55450 + alloc_stack =
55451 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55452 + else
55453 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55454 +
55455 + alloc_stack_size = size;
55456 +
55457 + if (!alloc_stack)
55458 + return 0;
55459 + else
55460 + return 1;
55461 +}
55462 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55463 new file mode 100644
55464 index 0000000..955ddfb
55465 --- /dev/null
55466 +++ b/grsecurity/gracl_cap.c
55467 @@ -0,0 +1,101 @@
55468 +#include <linux/kernel.h>
55469 +#include <linux/module.h>
55470 +#include <linux/sched.h>
55471 +#include <linux/gracl.h>
55472 +#include <linux/grsecurity.h>
55473 +#include <linux/grinternal.h>
55474 +
55475 +extern const char *captab_log[];
55476 +extern int captab_log_entries;
55477 +
55478 +int
55479 +gr_acl_is_capable(const int cap)
55480 +{
55481 + struct task_struct *task = current;
55482 + const struct cred *cred = current_cred();
55483 + struct acl_subject_label *curracl;
55484 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55485 + kernel_cap_t cap_audit = __cap_empty_set;
55486 +
55487 + if (!gr_acl_is_enabled())
55488 + return 1;
55489 +
55490 + curracl = task->acl;
55491 +
55492 + cap_drop = curracl->cap_lower;
55493 + cap_mask = curracl->cap_mask;
55494 + cap_audit = curracl->cap_invert_audit;
55495 +
55496 + while ((curracl = curracl->parent_subject)) {
55497 + /* if the cap isn't specified in the current computed mask but is specified in the
55498 + current level subject, and is lowered in the current level subject, then add
55499 + it to the set of dropped capabilities
55500 + otherwise, add the current level subject's mask to the current computed mask
55501 + */
55502 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55503 + cap_raise(cap_mask, cap);
55504 + if (cap_raised(curracl->cap_lower, cap))
55505 + cap_raise(cap_drop, cap);
55506 + if (cap_raised(curracl->cap_invert_audit, cap))
55507 + cap_raise(cap_audit, cap);
55508 + }
55509 + }
55510 +
55511 + if (!cap_raised(cap_drop, cap)) {
55512 + if (cap_raised(cap_audit, cap))
55513 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55514 + return 1;
55515 + }
55516 +
55517 + curracl = task->acl;
55518 +
55519 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55520 + && cap_raised(cred->cap_effective, cap)) {
55521 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55522 + task->role->roletype, cred->uid,
55523 + cred->gid, task->exec_file ?
55524 + gr_to_filename(task->exec_file->f_path.dentry,
55525 + task->exec_file->f_path.mnt) : curracl->filename,
55526 + curracl->filename, 0UL,
55527 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55528 + return 1;
55529 + }
55530 +
55531 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55532 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55533 + return 0;
55534 +}
55535 +
55536 +int
55537 +gr_acl_is_capable_nolog(const int cap)
55538 +{
55539 + struct acl_subject_label *curracl;
55540 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55541 +
55542 + if (!gr_acl_is_enabled())
55543 + return 1;
55544 +
55545 + curracl = current->acl;
55546 +
55547 + cap_drop = curracl->cap_lower;
55548 + cap_mask = curracl->cap_mask;
55549 +
55550 + while ((curracl = curracl->parent_subject)) {
55551 + /* if the cap isn't specified in the current computed mask but is specified in the
55552 + current level subject, and is lowered in the current level subject, then add
55553 + it to the set of dropped capabilities
55554 + otherwise, add the current level subject's mask to the current computed mask
55555 + */
55556 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55557 + cap_raise(cap_mask, cap);
55558 + if (cap_raised(curracl->cap_lower, cap))
55559 + cap_raise(cap_drop, cap);
55560 + }
55561 + }
55562 +
55563 + if (!cap_raised(cap_drop, cap))
55564 + return 1;
55565 +
55566 + return 0;
55567 +}
55568 +
55569 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55570 new file mode 100644
55571 index 0000000..4eda5c3
55572 --- /dev/null
55573 +++ b/grsecurity/gracl_fs.c
55574 @@ -0,0 +1,433 @@
55575 +#include <linux/kernel.h>
55576 +#include <linux/sched.h>
55577 +#include <linux/types.h>
55578 +#include <linux/fs.h>
55579 +#include <linux/file.h>
55580 +#include <linux/stat.h>
55581 +#include <linux/grsecurity.h>
55582 +#include <linux/grinternal.h>
55583 +#include <linux/gracl.h>
55584 +
55585 +__u32
55586 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55587 + const struct vfsmount * mnt)
55588 +{
55589 + __u32 mode;
55590 +
55591 + if (unlikely(!dentry->d_inode))
55592 + return GR_FIND;
55593 +
55594 + mode =
55595 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55596 +
55597 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55598 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55599 + return mode;
55600 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55601 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55602 + return 0;
55603 + } else if (unlikely(!(mode & GR_FIND)))
55604 + return 0;
55605 +
55606 + return GR_FIND;
55607 +}
55608 +
55609 +__u32
55610 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55611 + int acc_mode)
55612 +{
55613 + __u32 reqmode = GR_FIND;
55614 + __u32 mode;
55615 +
55616 + if (unlikely(!dentry->d_inode))
55617 + return reqmode;
55618 +
55619 + if (acc_mode & MAY_APPEND)
55620 + reqmode |= GR_APPEND;
55621 + else if (acc_mode & MAY_WRITE)
55622 + reqmode |= GR_WRITE;
55623 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55624 + reqmode |= GR_READ;
55625 +
55626 + mode =
55627 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55628 + mnt);
55629 +
55630 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55631 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55632 + reqmode & GR_READ ? " reading" : "",
55633 + reqmode & GR_WRITE ? " writing" : reqmode &
55634 + GR_APPEND ? " appending" : "");
55635 + return reqmode;
55636 + } else
55637 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55638 + {
55639 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55640 + reqmode & GR_READ ? " reading" : "",
55641 + reqmode & GR_WRITE ? " writing" : reqmode &
55642 + GR_APPEND ? " appending" : "");
55643 + return 0;
55644 + } else if (unlikely((mode & reqmode) != reqmode))
55645 + return 0;
55646 +
55647 + return reqmode;
55648 +}
55649 +
55650 +__u32
55651 +gr_acl_handle_creat(const struct dentry * dentry,
55652 + const struct dentry * p_dentry,
55653 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55654 + const int imode)
55655 +{
55656 + __u32 reqmode = GR_WRITE | GR_CREATE;
55657 + __u32 mode;
55658 +
55659 + if (acc_mode & MAY_APPEND)
55660 + reqmode |= GR_APPEND;
55661 + // if a directory was required or the directory already exists, then
55662 + // don't count this open as a read
55663 + if ((acc_mode & MAY_READ) &&
55664 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55665 + reqmode |= GR_READ;
55666 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55667 + reqmode |= GR_SETID;
55668 +
55669 + mode =
55670 + gr_check_create(dentry, p_dentry, p_mnt,
55671 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55672 +
55673 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55674 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55675 + reqmode & GR_READ ? " reading" : "",
55676 + reqmode & GR_WRITE ? " writing" : reqmode &
55677 + GR_APPEND ? " appending" : "");
55678 + return reqmode;
55679 + } else
55680 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55681 + {
55682 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55683 + reqmode & GR_READ ? " reading" : "",
55684 + reqmode & GR_WRITE ? " writing" : reqmode &
55685 + GR_APPEND ? " appending" : "");
55686 + return 0;
55687 + } else if (unlikely((mode & reqmode) != reqmode))
55688 + return 0;
55689 +
55690 + return reqmode;
55691 +}
55692 +
55693 +__u32
55694 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55695 + const int fmode)
55696 +{
55697 + __u32 mode, reqmode = GR_FIND;
55698 +
55699 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55700 + reqmode |= GR_EXEC;
55701 + if (fmode & S_IWOTH)
55702 + reqmode |= GR_WRITE;
55703 + if (fmode & S_IROTH)
55704 + reqmode |= GR_READ;
55705 +
55706 + mode =
55707 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55708 + mnt);
55709 +
55710 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55711 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55712 + reqmode & GR_READ ? " reading" : "",
55713 + reqmode & GR_WRITE ? " writing" : "",
55714 + reqmode & GR_EXEC ? " executing" : "");
55715 + return reqmode;
55716 + } else
55717 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55718 + {
55719 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55720 + reqmode & GR_READ ? " reading" : "",
55721 + reqmode & GR_WRITE ? " writing" : "",
55722 + reqmode & GR_EXEC ? " executing" : "");
55723 + return 0;
55724 + } else if (unlikely((mode & reqmode) != reqmode))
55725 + return 0;
55726 +
55727 + return reqmode;
55728 +}
55729 +
55730 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55731 +{
55732 + __u32 mode;
55733 +
55734 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55735 +
55736 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55737 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55738 + return mode;
55739 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55740 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55741 + return 0;
55742 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55743 + return 0;
55744 +
55745 + return (reqmode);
55746 +}
55747 +
55748 +__u32
55749 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55750 +{
55751 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55752 +}
55753 +
55754 +__u32
55755 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55756 +{
55757 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55758 +}
55759 +
55760 +__u32
55761 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55762 +{
55763 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55764 +}
55765 +
55766 +__u32
55767 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55768 +{
55769 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55770 +}
55771 +
55772 +__u32
55773 +gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
55774 + mode_t mode)
55775 +{
55776 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55777 + return 1;
55778 +
55779 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55780 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55781 + GR_FCHMOD_ACL_MSG);
55782 + } else {
55783 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
55784 + }
55785 +}
55786 +
55787 +__u32
55788 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55789 + mode_t mode)
55790 +{
55791 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55792 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55793 + GR_CHMOD_ACL_MSG);
55794 + } else {
55795 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55796 + }
55797 +}
55798 +
55799 +__u32
55800 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55801 +{
55802 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55803 +}
55804 +
55805 +__u32
55806 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55807 +{
55808 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55809 +}
55810 +
55811 +__u32
55812 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55813 +{
55814 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55815 +}
55816 +
55817 +__u32
55818 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55819 +{
55820 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55821 + GR_UNIXCONNECT_ACL_MSG);
55822 +}
55823 +
55824 +/* hardlinks require at minimum create and link permission,
55825 + any additional privilege required is based on the
55826 + privilege of the file being linked to
55827 +*/
55828 +__u32
55829 +gr_acl_handle_link(const struct dentry * new_dentry,
55830 + const struct dentry * parent_dentry,
55831 + const struct vfsmount * parent_mnt,
55832 + const struct dentry * old_dentry,
55833 + const struct vfsmount * old_mnt, const char *to)
55834 +{
55835 + __u32 mode;
55836 + __u32 needmode = GR_CREATE | GR_LINK;
55837 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55838 +
55839 + mode =
55840 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55841 + old_mnt);
55842 +
55843 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55844 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55845 + return mode;
55846 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55847 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55848 + return 0;
55849 + } else if (unlikely((mode & needmode) != needmode))
55850 + return 0;
55851 +
55852 + return 1;
55853 +}
55854 +
55855 +__u32
55856 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55857 + const struct dentry * parent_dentry,
55858 + const struct vfsmount * parent_mnt, const char *from)
55859 +{
55860 + __u32 needmode = GR_WRITE | GR_CREATE;
55861 + __u32 mode;
55862 +
55863 + mode =
55864 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55865 + GR_CREATE | GR_AUDIT_CREATE |
55866 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55867 +
55868 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55869 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55870 + return mode;
55871 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55872 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55873 + return 0;
55874 + } else if (unlikely((mode & needmode) != needmode))
55875 + return 0;
55876 +
55877 + return (GR_WRITE | GR_CREATE);
55878 +}
55879 +
55880 +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)
55881 +{
55882 + __u32 mode;
55883 +
55884 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55885 +
55886 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55887 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55888 + return mode;
55889 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55890 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55891 + return 0;
55892 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55893 + return 0;
55894 +
55895 + return (reqmode);
55896 +}
55897 +
55898 +__u32
55899 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55900 + const struct dentry * parent_dentry,
55901 + const struct vfsmount * parent_mnt,
55902 + const int mode)
55903 +{
55904 + __u32 reqmode = GR_WRITE | GR_CREATE;
55905 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55906 + reqmode |= GR_SETID;
55907 +
55908 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55909 + reqmode, GR_MKNOD_ACL_MSG);
55910 +}
55911 +
55912 +__u32
55913 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55914 + const struct dentry *parent_dentry,
55915 + const struct vfsmount *parent_mnt)
55916 +{
55917 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55918 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55919 +}
55920 +
55921 +#define RENAME_CHECK_SUCCESS(old, new) \
55922 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55923 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55924 +
55925 +int
55926 +gr_acl_handle_rename(struct dentry *new_dentry,
55927 + struct dentry *parent_dentry,
55928 + const struct vfsmount *parent_mnt,
55929 + struct dentry *old_dentry,
55930 + struct inode *old_parent_inode,
55931 + struct vfsmount *old_mnt, const char *newname)
55932 +{
55933 + __u32 comp1, comp2;
55934 + int error = 0;
55935 +
55936 + if (unlikely(!gr_acl_is_enabled()))
55937 + return 0;
55938 +
55939 + if (!new_dentry->d_inode) {
55940 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55941 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55942 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55943 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55944 + GR_DELETE | GR_AUDIT_DELETE |
55945 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55946 + GR_SUPPRESS, old_mnt);
55947 + } else {
55948 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55949 + GR_CREATE | GR_DELETE |
55950 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55951 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55952 + GR_SUPPRESS, parent_mnt);
55953 + comp2 =
55954 + gr_search_file(old_dentry,
55955 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55956 + GR_DELETE | GR_AUDIT_DELETE |
55957 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55958 + }
55959 +
55960 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55961 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55962 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55963 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55964 + && !(comp2 & GR_SUPPRESS)) {
55965 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55966 + error = -EACCES;
55967 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55968 + error = -EACCES;
55969 +
55970 + return error;
55971 +}
55972 +
55973 +void
55974 +gr_acl_handle_exit(void)
55975 +{
55976 + u16 id;
55977 + char *rolename;
55978 + struct file *exec_file;
55979 +
55980 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55981 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55982 + id = current->acl_role_id;
55983 + rolename = current->role->rolename;
55984 + gr_set_acls(1);
55985 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55986 + }
55987 +
55988 + write_lock(&grsec_exec_file_lock);
55989 + exec_file = current->exec_file;
55990 + current->exec_file = NULL;
55991 + write_unlock(&grsec_exec_file_lock);
55992 +
55993 + if (exec_file)
55994 + fput(exec_file);
55995 +}
55996 +
55997 +int
55998 +gr_acl_handle_procpidmem(const struct task_struct *task)
55999 +{
56000 + if (unlikely(!gr_acl_is_enabled()))
56001 + return 0;
56002 +
56003 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56004 + return -EACCES;
56005 +
56006 + return 0;
56007 +}
56008 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56009 new file mode 100644
56010 index 0000000..17050ca
56011 --- /dev/null
56012 +++ b/grsecurity/gracl_ip.c
56013 @@ -0,0 +1,381 @@
56014 +#include <linux/kernel.h>
56015 +#include <asm/uaccess.h>
56016 +#include <asm/errno.h>
56017 +#include <net/sock.h>
56018 +#include <linux/file.h>
56019 +#include <linux/fs.h>
56020 +#include <linux/net.h>
56021 +#include <linux/in.h>
56022 +#include <linux/skbuff.h>
56023 +#include <linux/ip.h>
56024 +#include <linux/udp.h>
56025 +#include <linux/types.h>
56026 +#include <linux/sched.h>
56027 +#include <linux/netdevice.h>
56028 +#include <linux/inetdevice.h>
56029 +#include <linux/gracl.h>
56030 +#include <linux/grsecurity.h>
56031 +#include <linux/grinternal.h>
56032 +
56033 +#define GR_BIND 0x01
56034 +#define GR_CONNECT 0x02
56035 +#define GR_INVERT 0x04
56036 +#define GR_BINDOVERRIDE 0x08
56037 +#define GR_CONNECTOVERRIDE 0x10
56038 +#define GR_SOCK_FAMILY 0x20
56039 +
56040 +static const char * gr_protocols[IPPROTO_MAX] = {
56041 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56042 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56043 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56044 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56045 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56046 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56047 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56048 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56049 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56050 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56051 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56052 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56053 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56054 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56055 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56056 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56057 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56058 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56059 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56060 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56061 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56062 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56063 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56064 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56065 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56066 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56067 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56068 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56069 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56070 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56071 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56072 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56073 + };
56074 +
56075 +static const char * gr_socktypes[SOCK_MAX] = {
56076 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56077 + "unknown:7", "unknown:8", "unknown:9", "packet"
56078 + };
56079 +
56080 +static const char * gr_sockfamilies[AF_MAX+1] = {
56081 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56082 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56083 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56084 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56085 + };
56086 +
56087 +const char *
56088 +gr_proto_to_name(unsigned char proto)
56089 +{
56090 + return gr_protocols[proto];
56091 +}
56092 +
56093 +const char *
56094 +gr_socktype_to_name(unsigned char type)
56095 +{
56096 + return gr_socktypes[type];
56097 +}
56098 +
56099 +const char *
56100 +gr_sockfamily_to_name(unsigned char family)
56101 +{
56102 + return gr_sockfamilies[family];
56103 +}
56104 +
56105 +int
56106 +gr_search_socket(const int domain, const int type, const int protocol)
56107 +{
56108 + struct acl_subject_label *curr;
56109 + const struct cred *cred = current_cred();
56110 +
56111 + if (unlikely(!gr_acl_is_enabled()))
56112 + goto exit;
56113 +
56114 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56115 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56116 + goto exit; // let the kernel handle it
56117 +
56118 + curr = current->acl;
56119 +
56120 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56121 + /* the family is allowed, if this is PF_INET allow it only if
56122 + the extra sock type/protocol checks pass */
56123 + if (domain == PF_INET)
56124 + goto inet_check;
56125 + goto exit;
56126 + } else {
56127 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56128 + __u32 fakeip = 0;
56129 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56130 + current->role->roletype, cred->uid,
56131 + cred->gid, current->exec_file ?
56132 + gr_to_filename(current->exec_file->f_path.dentry,
56133 + current->exec_file->f_path.mnt) :
56134 + curr->filename, curr->filename,
56135 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56136 + &current->signal->saved_ip);
56137 + goto exit;
56138 + }
56139 + goto exit_fail;
56140 + }
56141 +
56142 +inet_check:
56143 + /* the rest of this checking is for IPv4 only */
56144 + if (!curr->ips)
56145 + goto exit;
56146 +
56147 + if ((curr->ip_type & (1 << type)) &&
56148 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56149 + goto exit;
56150 +
56151 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56152 + /* we don't place acls on raw sockets , and sometimes
56153 + dgram/ip sockets are opened for ioctl and not
56154 + bind/connect, so we'll fake a bind learn log */
56155 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56156 + __u32 fakeip = 0;
56157 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56158 + current->role->roletype, cred->uid,
56159 + cred->gid, current->exec_file ?
56160 + gr_to_filename(current->exec_file->f_path.dentry,
56161 + current->exec_file->f_path.mnt) :
56162 + curr->filename, curr->filename,
56163 + &fakeip, 0, type,
56164 + protocol, GR_CONNECT, &current->signal->saved_ip);
56165 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56166 + __u32 fakeip = 0;
56167 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56168 + current->role->roletype, cred->uid,
56169 + cred->gid, current->exec_file ?
56170 + gr_to_filename(current->exec_file->f_path.dentry,
56171 + current->exec_file->f_path.mnt) :
56172 + curr->filename, curr->filename,
56173 + &fakeip, 0, type,
56174 + protocol, GR_BIND, &current->signal->saved_ip);
56175 + }
56176 + /* we'll log when they use connect or bind */
56177 + goto exit;
56178 + }
56179 +
56180 +exit_fail:
56181 + if (domain == PF_INET)
56182 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56183 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56184 + else
56185 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56186 + gr_socktype_to_name(type), protocol);
56187 +
56188 + return 0;
56189 +exit:
56190 + return 1;
56191 +}
56192 +
56193 +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)
56194 +{
56195 + if ((ip->mode & mode) &&
56196 + (ip_port >= ip->low) &&
56197 + (ip_port <= ip->high) &&
56198 + ((ntohl(ip_addr) & our_netmask) ==
56199 + (ntohl(our_addr) & our_netmask))
56200 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56201 + && (ip->type & (1 << type))) {
56202 + if (ip->mode & GR_INVERT)
56203 + return 2; // specifically denied
56204 + else
56205 + return 1; // allowed
56206 + }
56207 +
56208 + return 0; // not specifically allowed, may continue parsing
56209 +}
56210 +
56211 +static int
56212 +gr_search_connectbind(const int full_mode, struct sock *sk,
56213 + struct sockaddr_in *addr, const int type)
56214 +{
56215 + char iface[IFNAMSIZ] = {0};
56216 + struct acl_subject_label *curr;
56217 + struct acl_ip_label *ip;
56218 + struct inet_sock *isk;
56219 + struct net_device *dev;
56220 + struct in_device *idev;
56221 + unsigned long i;
56222 + int ret;
56223 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56224 + __u32 ip_addr = 0;
56225 + __u32 our_addr;
56226 + __u32 our_netmask;
56227 + char *p;
56228 + __u16 ip_port = 0;
56229 + const struct cred *cred = current_cred();
56230 +
56231 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56232 + return 0;
56233 +
56234 + curr = current->acl;
56235 + isk = inet_sk(sk);
56236 +
56237 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56238 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56239 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56240 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56241 + struct sockaddr_in saddr;
56242 + int err;
56243 +
56244 + saddr.sin_family = AF_INET;
56245 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56246 + saddr.sin_port = isk->inet_sport;
56247 +
56248 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56249 + if (err)
56250 + return err;
56251 +
56252 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56253 + if (err)
56254 + return err;
56255 + }
56256 +
56257 + if (!curr->ips)
56258 + return 0;
56259 +
56260 + ip_addr = addr->sin_addr.s_addr;
56261 + ip_port = ntohs(addr->sin_port);
56262 +
56263 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56264 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56265 + current->role->roletype, cred->uid,
56266 + cred->gid, current->exec_file ?
56267 + gr_to_filename(current->exec_file->f_path.dentry,
56268 + current->exec_file->f_path.mnt) :
56269 + curr->filename, curr->filename,
56270 + &ip_addr, ip_port, type,
56271 + sk->sk_protocol, mode, &current->signal->saved_ip);
56272 + return 0;
56273 + }
56274 +
56275 + for (i = 0; i < curr->ip_num; i++) {
56276 + ip = *(curr->ips + i);
56277 + if (ip->iface != NULL) {
56278 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56279 + p = strchr(iface, ':');
56280 + if (p != NULL)
56281 + *p = '\0';
56282 + dev = dev_get_by_name(sock_net(sk), iface);
56283 + if (dev == NULL)
56284 + continue;
56285 + idev = in_dev_get(dev);
56286 + if (idev == NULL) {
56287 + dev_put(dev);
56288 + continue;
56289 + }
56290 + rcu_read_lock();
56291 + for_ifa(idev) {
56292 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56293 + our_addr = ifa->ifa_address;
56294 + our_netmask = 0xffffffff;
56295 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56296 + if (ret == 1) {
56297 + rcu_read_unlock();
56298 + in_dev_put(idev);
56299 + dev_put(dev);
56300 + return 0;
56301 + } else if (ret == 2) {
56302 + rcu_read_unlock();
56303 + in_dev_put(idev);
56304 + dev_put(dev);
56305 + goto denied;
56306 + }
56307 + }
56308 + } endfor_ifa(idev);
56309 + rcu_read_unlock();
56310 + in_dev_put(idev);
56311 + dev_put(dev);
56312 + } else {
56313 + our_addr = ip->addr;
56314 + our_netmask = ip->netmask;
56315 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56316 + if (ret == 1)
56317 + return 0;
56318 + else if (ret == 2)
56319 + goto denied;
56320 + }
56321 + }
56322 +
56323 +denied:
56324 + if (mode == GR_BIND)
56325 + 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));
56326 + else if (mode == GR_CONNECT)
56327 + 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));
56328 +
56329 + return -EACCES;
56330 +}
56331 +
56332 +int
56333 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56334 +{
56335 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56336 +}
56337 +
56338 +int
56339 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56340 +{
56341 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56342 +}
56343 +
56344 +int gr_search_listen(struct socket *sock)
56345 +{
56346 + struct sock *sk = sock->sk;
56347 + struct sockaddr_in addr;
56348 +
56349 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56350 + addr.sin_port = inet_sk(sk)->inet_sport;
56351 +
56352 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56353 +}
56354 +
56355 +int gr_search_accept(struct socket *sock)
56356 +{
56357 + struct sock *sk = sock->sk;
56358 + struct sockaddr_in addr;
56359 +
56360 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56361 + addr.sin_port = inet_sk(sk)->inet_sport;
56362 +
56363 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56364 +}
56365 +
56366 +int
56367 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56368 +{
56369 + if (addr)
56370 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56371 + else {
56372 + struct sockaddr_in sin;
56373 + const struct inet_sock *inet = inet_sk(sk);
56374 +
56375 + sin.sin_addr.s_addr = inet->inet_daddr;
56376 + sin.sin_port = inet->inet_dport;
56377 +
56378 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56379 + }
56380 +}
56381 +
56382 +int
56383 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56384 +{
56385 + struct sockaddr_in sin;
56386 +
56387 + if (unlikely(skb->len < sizeof (struct udphdr)))
56388 + return 0; // skip this packet
56389 +
56390 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56391 + sin.sin_port = udp_hdr(skb)->source;
56392 +
56393 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56394 +}
56395 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56396 new file mode 100644
56397 index 0000000..25f54ef
56398 --- /dev/null
56399 +++ b/grsecurity/gracl_learn.c
56400 @@ -0,0 +1,207 @@
56401 +#include <linux/kernel.h>
56402 +#include <linux/mm.h>
56403 +#include <linux/sched.h>
56404 +#include <linux/poll.h>
56405 +#include <linux/string.h>
56406 +#include <linux/file.h>
56407 +#include <linux/types.h>
56408 +#include <linux/vmalloc.h>
56409 +#include <linux/grinternal.h>
56410 +
56411 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56412 + size_t count, loff_t *ppos);
56413 +extern int gr_acl_is_enabled(void);
56414 +
56415 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56416 +static int gr_learn_attached;
56417 +
56418 +/* use a 512k buffer */
56419 +#define LEARN_BUFFER_SIZE (512 * 1024)
56420 +
56421 +static DEFINE_SPINLOCK(gr_learn_lock);
56422 +static DEFINE_MUTEX(gr_learn_user_mutex);
56423 +
56424 +/* we need to maintain two buffers, so that the kernel context of grlearn
56425 + uses a semaphore around the userspace copying, and the other kernel contexts
56426 + use a spinlock when copying into the buffer, since they cannot sleep
56427 +*/
56428 +static char *learn_buffer;
56429 +static char *learn_buffer_user;
56430 +static int learn_buffer_len;
56431 +static int learn_buffer_user_len;
56432 +
56433 +static ssize_t
56434 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56435 +{
56436 + DECLARE_WAITQUEUE(wait, current);
56437 + ssize_t retval = 0;
56438 +
56439 + add_wait_queue(&learn_wait, &wait);
56440 + set_current_state(TASK_INTERRUPTIBLE);
56441 + do {
56442 + mutex_lock(&gr_learn_user_mutex);
56443 + spin_lock(&gr_learn_lock);
56444 + if (learn_buffer_len)
56445 + break;
56446 + spin_unlock(&gr_learn_lock);
56447 + mutex_unlock(&gr_learn_user_mutex);
56448 + if (file->f_flags & O_NONBLOCK) {
56449 + retval = -EAGAIN;
56450 + goto out;
56451 + }
56452 + if (signal_pending(current)) {
56453 + retval = -ERESTARTSYS;
56454 + goto out;
56455 + }
56456 +
56457 + schedule();
56458 + } while (1);
56459 +
56460 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56461 + learn_buffer_user_len = learn_buffer_len;
56462 + retval = learn_buffer_len;
56463 + learn_buffer_len = 0;
56464 +
56465 + spin_unlock(&gr_learn_lock);
56466 +
56467 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56468 + retval = -EFAULT;
56469 +
56470 + mutex_unlock(&gr_learn_user_mutex);
56471 +out:
56472 + set_current_state(TASK_RUNNING);
56473 + remove_wait_queue(&learn_wait, &wait);
56474 + return retval;
56475 +}
56476 +
56477 +static unsigned int
56478 +poll_learn(struct file * file, poll_table * wait)
56479 +{
56480 + poll_wait(file, &learn_wait, wait);
56481 +
56482 + if (learn_buffer_len)
56483 + return (POLLIN | POLLRDNORM);
56484 +
56485 + return 0;
56486 +}
56487 +
56488 +void
56489 +gr_clear_learn_entries(void)
56490 +{
56491 + char *tmp;
56492 +
56493 + mutex_lock(&gr_learn_user_mutex);
56494 + spin_lock(&gr_learn_lock);
56495 + tmp = learn_buffer;
56496 + learn_buffer = NULL;
56497 + spin_unlock(&gr_learn_lock);
56498 + if (tmp)
56499 + vfree(tmp);
56500 + if (learn_buffer_user != NULL) {
56501 + vfree(learn_buffer_user);
56502 + learn_buffer_user = NULL;
56503 + }
56504 + learn_buffer_len = 0;
56505 + mutex_unlock(&gr_learn_user_mutex);
56506 +
56507 + return;
56508 +}
56509 +
56510 +void
56511 +gr_add_learn_entry(const char *fmt, ...)
56512 +{
56513 + va_list args;
56514 + unsigned int len;
56515 +
56516 + if (!gr_learn_attached)
56517 + return;
56518 +
56519 + spin_lock(&gr_learn_lock);
56520 +
56521 + /* leave a gap at the end so we know when it's "full" but don't have to
56522 + compute the exact length of the string we're trying to append
56523 + */
56524 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56525 + spin_unlock(&gr_learn_lock);
56526 + wake_up_interruptible(&learn_wait);
56527 + return;
56528 + }
56529 + if (learn_buffer == NULL) {
56530 + spin_unlock(&gr_learn_lock);
56531 + return;
56532 + }
56533 +
56534 + va_start(args, fmt);
56535 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56536 + va_end(args);
56537 +
56538 + learn_buffer_len += len + 1;
56539 +
56540 + spin_unlock(&gr_learn_lock);
56541 + wake_up_interruptible(&learn_wait);
56542 +
56543 + return;
56544 +}
56545 +
56546 +static int
56547 +open_learn(struct inode *inode, struct file *file)
56548 +{
56549 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56550 + return -EBUSY;
56551 + if (file->f_mode & FMODE_READ) {
56552 + int retval = 0;
56553 + mutex_lock(&gr_learn_user_mutex);
56554 + if (learn_buffer == NULL)
56555 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56556 + if (learn_buffer_user == NULL)
56557 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56558 + if (learn_buffer == NULL) {
56559 + retval = -ENOMEM;
56560 + goto out_error;
56561 + }
56562 + if (learn_buffer_user == NULL) {
56563 + retval = -ENOMEM;
56564 + goto out_error;
56565 + }
56566 + learn_buffer_len = 0;
56567 + learn_buffer_user_len = 0;
56568 + gr_learn_attached = 1;
56569 +out_error:
56570 + mutex_unlock(&gr_learn_user_mutex);
56571 + return retval;
56572 + }
56573 + return 0;
56574 +}
56575 +
56576 +static int
56577 +close_learn(struct inode *inode, struct file *file)
56578 +{
56579 + if (file->f_mode & FMODE_READ) {
56580 + char *tmp = NULL;
56581 + mutex_lock(&gr_learn_user_mutex);
56582 + spin_lock(&gr_learn_lock);
56583 + tmp = learn_buffer;
56584 + learn_buffer = NULL;
56585 + spin_unlock(&gr_learn_lock);
56586 + if (tmp)
56587 + vfree(tmp);
56588 + if (learn_buffer_user != NULL) {
56589 + vfree(learn_buffer_user);
56590 + learn_buffer_user = NULL;
56591 + }
56592 + learn_buffer_len = 0;
56593 + learn_buffer_user_len = 0;
56594 + gr_learn_attached = 0;
56595 + mutex_unlock(&gr_learn_user_mutex);
56596 + }
56597 +
56598 + return 0;
56599 +}
56600 +
56601 +const struct file_operations grsec_fops = {
56602 + .read = read_learn,
56603 + .write = write_grsec_handler,
56604 + .open = open_learn,
56605 + .release = close_learn,
56606 + .poll = poll_learn,
56607 +};
56608 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56609 new file mode 100644
56610 index 0000000..39645c9
56611 --- /dev/null
56612 +++ b/grsecurity/gracl_res.c
56613 @@ -0,0 +1,68 @@
56614 +#include <linux/kernel.h>
56615 +#include <linux/sched.h>
56616 +#include <linux/gracl.h>
56617 +#include <linux/grinternal.h>
56618 +
56619 +static const char *restab_log[] = {
56620 + [RLIMIT_CPU] = "RLIMIT_CPU",
56621 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56622 + [RLIMIT_DATA] = "RLIMIT_DATA",
56623 + [RLIMIT_STACK] = "RLIMIT_STACK",
56624 + [RLIMIT_CORE] = "RLIMIT_CORE",
56625 + [RLIMIT_RSS] = "RLIMIT_RSS",
56626 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56627 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56628 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56629 + [RLIMIT_AS] = "RLIMIT_AS",
56630 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56631 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56632 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56633 + [RLIMIT_NICE] = "RLIMIT_NICE",
56634 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56635 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56636 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56637 +};
56638 +
56639 +void
56640 +gr_log_resource(const struct task_struct *task,
56641 + const int res, const unsigned long wanted, const int gt)
56642 +{
56643 + const struct cred *cred;
56644 + unsigned long rlim;
56645 +
56646 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56647 + return;
56648 +
56649 + // not yet supported resource
56650 + if (unlikely(!restab_log[res]))
56651 + return;
56652 +
56653 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56654 + rlim = task_rlimit_max(task, res);
56655 + else
56656 + rlim = task_rlimit(task, res);
56657 +
56658 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56659 + return;
56660 +
56661 + rcu_read_lock();
56662 + cred = __task_cred(task);
56663 +
56664 + if (res == RLIMIT_NPROC &&
56665 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56666 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56667 + goto out_rcu_unlock;
56668 + else if (res == RLIMIT_MEMLOCK &&
56669 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56670 + goto out_rcu_unlock;
56671 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56672 + goto out_rcu_unlock;
56673 + rcu_read_unlock();
56674 +
56675 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56676 +
56677 + return;
56678 +out_rcu_unlock:
56679 + rcu_read_unlock();
56680 + return;
56681 +}
56682 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56683 new file mode 100644
56684 index 0000000..5556be3
56685 --- /dev/null
56686 +++ b/grsecurity/gracl_segv.c
56687 @@ -0,0 +1,299 @@
56688 +#include <linux/kernel.h>
56689 +#include <linux/mm.h>
56690 +#include <asm/uaccess.h>
56691 +#include <asm/errno.h>
56692 +#include <asm/mman.h>
56693 +#include <net/sock.h>
56694 +#include <linux/file.h>
56695 +#include <linux/fs.h>
56696 +#include <linux/net.h>
56697 +#include <linux/in.h>
56698 +#include <linux/slab.h>
56699 +#include <linux/types.h>
56700 +#include <linux/sched.h>
56701 +#include <linux/timer.h>
56702 +#include <linux/gracl.h>
56703 +#include <linux/grsecurity.h>
56704 +#include <linux/grinternal.h>
56705 +
56706 +static struct crash_uid *uid_set;
56707 +static unsigned short uid_used;
56708 +static DEFINE_SPINLOCK(gr_uid_lock);
56709 +extern rwlock_t gr_inode_lock;
56710 +extern struct acl_subject_label *
56711 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56712 + struct acl_role_label *role);
56713 +
56714 +#ifdef CONFIG_BTRFS_FS
56715 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56716 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56717 +#endif
56718 +
56719 +static inline dev_t __get_dev(const struct dentry *dentry)
56720 +{
56721 +#ifdef CONFIG_BTRFS_FS
56722 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56723 + return get_btrfs_dev_from_inode(dentry->d_inode);
56724 + else
56725 +#endif
56726 + return dentry->d_inode->i_sb->s_dev;
56727 +}
56728 +
56729 +int
56730 +gr_init_uidset(void)
56731 +{
56732 + uid_set =
56733 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56734 + uid_used = 0;
56735 +
56736 + return uid_set ? 1 : 0;
56737 +}
56738 +
56739 +void
56740 +gr_free_uidset(void)
56741 +{
56742 + if (uid_set)
56743 + kfree(uid_set);
56744 +
56745 + return;
56746 +}
56747 +
56748 +int
56749 +gr_find_uid(const uid_t uid)
56750 +{
56751 + struct crash_uid *tmp = uid_set;
56752 + uid_t buid;
56753 + int low = 0, high = uid_used - 1, mid;
56754 +
56755 + while (high >= low) {
56756 + mid = (low + high) >> 1;
56757 + buid = tmp[mid].uid;
56758 + if (buid == uid)
56759 + return mid;
56760 + if (buid > uid)
56761 + high = mid - 1;
56762 + if (buid < uid)
56763 + low = mid + 1;
56764 + }
56765 +
56766 + return -1;
56767 +}
56768 +
56769 +static __inline__ void
56770 +gr_insertsort(void)
56771 +{
56772 + unsigned short i, j;
56773 + struct crash_uid index;
56774 +
56775 + for (i = 1; i < uid_used; i++) {
56776 + index = uid_set[i];
56777 + j = i;
56778 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56779 + uid_set[j] = uid_set[j - 1];
56780 + j--;
56781 + }
56782 + uid_set[j] = index;
56783 + }
56784 +
56785 + return;
56786 +}
56787 +
56788 +static __inline__ void
56789 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56790 +{
56791 + int loc;
56792 +
56793 + if (uid_used == GR_UIDTABLE_MAX)
56794 + return;
56795 +
56796 + loc = gr_find_uid(uid);
56797 +
56798 + if (loc >= 0) {
56799 + uid_set[loc].expires = expires;
56800 + return;
56801 + }
56802 +
56803 + uid_set[uid_used].uid = uid;
56804 + uid_set[uid_used].expires = expires;
56805 + uid_used++;
56806 +
56807 + gr_insertsort();
56808 +
56809 + return;
56810 +}
56811 +
56812 +void
56813 +gr_remove_uid(const unsigned short loc)
56814 +{
56815 + unsigned short i;
56816 +
56817 + for (i = loc + 1; i < uid_used; i++)
56818 + uid_set[i - 1] = uid_set[i];
56819 +
56820 + uid_used--;
56821 +
56822 + return;
56823 +}
56824 +
56825 +int
56826 +gr_check_crash_uid(const uid_t uid)
56827 +{
56828 + int loc;
56829 + int ret = 0;
56830 +
56831 + if (unlikely(!gr_acl_is_enabled()))
56832 + return 0;
56833 +
56834 + spin_lock(&gr_uid_lock);
56835 + loc = gr_find_uid(uid);
56836 +
56837 + if (loc < 0)
56838 + goto out_unlock;
56839 +
56840 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56841 + gr_remove_uid(loc);
56842 + else
56843 + ret = 1;
56844 +
56845 +out_unlock:
56846 + spin_unlock(&gr_uid_lock);
56847 + return ret;
56848 +}
56849 +
56850 +static __inline__ int
56851 +proc_is_setxid(const struct cred *cred)
56852 +{
56853 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
56854 + cred->uid != cred->fsuid)
56855 + return 1;
56856 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56857 + cred->gid != cred->fsgid)
56858 + return 1;
56859 +
56860 + return 0;
56861 +}
56862 +
56863 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56864 +
56865 +void
56866 +gr_handle_crash(struct task_struct *task, const int sig)
56867 +{
56868 + struct acl_subject_label *curr;
56869 + struct task_struct *tsk, *tsk2;
56870 + const struct cred *cred;
56871 + const struct cred *cred2;
56872 +
56873 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56874 + return;
56875 +
56876 + if (unlikely(!gr_acl_is_enabled()))
56877 + return;
56878 +
56879 + curr = task->acl;
56880 +
56881 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56882 + return;
56883 +
56884 + if (time_before_eq(curr->expires, get_seconds())) {
56885 + curr->expires = 0;
56886 + curr->crashes = 0;
56887 + }
56888 +
56889 + curr->crashes++;
56890 +
56891 + if (!curr->expires)
56892 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56893 +
56894 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56895 + time_after(curr->expires, get_seconds())) {
56896 + rcu_read_lock();
56897 + cred = __task_cred(task);
56898 + if (cred->uid && proc_is_setxid(cred)) {
56899 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56900 + spin_lock(&gr_uid_lock);
56901 + gr_insert_uid(cred->uid, curr->expires);
56902 + spin_unlock(&gr_uid_lock);
56903 + curr->expires = 0;
56904 + curr->crashes = 0;
56905 + read_lock(&tasklist_lock);
56906 + do_each_thread(tsk2, tsk) {
56907 + cred2 = __task_cred(tsk);
56908 + if (tsk != task && cred2->uid == cred->uid)
56909 + gr_fake_force_sig(SIGKILL, tsk);
56910 + } while_each_thread(tsk2, tsk);
56911 + read_unlock(&tasklist_lock);
56912 + } else {
56913 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56914 + read_lock(&tasklist_lock);
56915 + read_lock(&grsec_exec_file_lock);
56916 + do_each_thread(tsk2, tsk) {
56917 + if (likely(tsk != task)) {
56918 + // if this thread has the same subject as the one that triggered
56919 + // RES_CRASH and it's the same binary, kill it
56920 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56921 + gr_fake_force_sig(SIGKILL, tsk);
56922 + }
56923 + } while_each_thread(tsk2, tsk);
56924 + read_unlock(&grsec_exec_file_lock);
56925 + read_unlock(&tasklist_lock);
56926 + }
56927 + rcu_read_unlock();
56928 + }
56929 +
56930 + return;
56931 +}
56932 +
56933 +int
56934 +gr_check_crash_exec(const struct file *filp)
56935 +{
56936 + struct acl_subject_label *curr;
56937 +
56938 + if (unlikely(!gr_acl_is_enabled()))
56939 + return 0;
56940 +
56941 + read_lock(&gr_inode_lock);
56942 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56943 + __get_dev(filp->f_path.dentry),
56944 + current->role);
56945 + read_unlock(&gr_inode_lock);
56946 +
56947 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56948 + (!curr->crashes && !curr->expires))
56949 + return 0;
56950 +
56951 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56952 + time_after(curr->expires, get_seconds()))
56953 + return 1;
56954 + else if (time_before_eq(curr->expires, get_seconds())) {
56955 + curr->crashes = 0;
56956 + curr->expires = 0;
56957 + }
56958 +
56959 + return 0;
56960 +}
56961 +
56962 +void
56963 +gr_handle_alertkill(struct task_struct *task)
56964 +{
56965 + struct acl_subject_label *curracl;
56966 + __u32 curr_ip;
56967 + struct task_struct *p, *p2;
56968 +
56969 + if (unlikely(!gr_acl_is_enabled()))
56970 + return;
56971 +
56972 + curracl = task->acl;
56973 + curr_ip = task->signal->curr_ip;
56974 +
56975 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56976 + read_lock(&tasklist_lock);
56977 + do_each_thread(p2, p) {
56978 + if (p->signal->curr_ip == curr_ip)
56979 + gr_fake_force_sig(SIGKILL, p);
56980 + } while_each_thread(p2, p);
56981 + read_unlock(&tasklist_lock);
56982 + } else if (curracl->mode & GR_KILLPROC)
56983 + gr_fake_force_sig(SIGKILL, task);
56984 +
56985 + return;
56986 +}
56987 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56988 new file mode 100644
56989 index 0000000..9d83a69
56990 --- /dev/null
56991 +++ b/grsecurity/gracl_shm.c
56992 @@ -0,0 +1,40 @@
56993 +#include <linux/kernel.h>
56994 +#include <linux/mm.h>
56995 +#include <linux/sched.h>
56996 +#include <linux/file.h>
56997 +#include <linux/ipc.h>
56998 +#include <linux/gracl.h>
56999 +#include <linux/grsecurity.h>
57000 +#include <linux/grinternal.h>
57001 +
57002 +int
57003 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57004 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57005 +{
57006 + struct task_struct *task;
57007 +
57008 + if (!gr_acl_is_enabled())
57009 + return 1;
57010 +
57011 + rcu_read_lock();
57012 + read_lock(&tasklist_lock);
57013 +
57014 + task = find_task_by_vpid(shm_cprid);
57015 +
57016 + if (unlikely(!task))
57017 + task = find_task_by_vpid(shm_lapid);
57018 +
57019 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57020 + (task->pid == shm_lapid)) &&
57021 + (task->acl->mode & GR_PROTSHM) &&
57022 + (task->acl != current->acl))) {
57023 + read_unlock(&tasklist_lock);
57024 + rcu_read_unlock();
57025 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57026 + return 0;
57027 + }
57028 + read_unlock(&tasklist_lock);
57029 + rcu_read_unlock();
57030 +
57031 + return 1;
57032 +}
57033 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57034 new file mode 100644
57035 index 0000000..bc0be01
57036 --- /dev/null
57037 +++ b/grsecurity/grsec_chdir.c
57038 @@ -0,0 +1,19 @@
57039 +#include <linux/kernel.h>
57040 +#include <linux/sched.h>
57041 +#include <linux/fs.h>
57042 +#include <linux/file.h>
57043 +#include <linux/grsecurity.h>
57044 +#include <linux/grinternal.h>
57045 +
57046 +void
57047 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57048 +{
57049 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57050 + if ((grsec_enable_chdir && grsec_enable_group &&
57051 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57052 + !grsec_enable_group)) {
57053 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57054 + }
57055 +#endif
57056 + return;
57057 +}
57058 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57059 new file mode 100644
57060 index 0000000..a2dc675
57061 --- /dev/null
57062 +++ b/grsecurity/grsec_chroot.c
57063 @@ -0,0 +1,351 @@
57064 +#include <linux/kernel.h>
57065 +#include <linux/module.h>
57066 +#include <linux/sched.h>
57067 +#include <linux/file.h>
57068 +#include <linux/fs.h>
57069 +#include <linux/mount.h>
57070 +#include <linux/types.h>
57071 +#include <linux/pid_namespace.h>
57072 +#include <linux/grsecurity.h>
57073 +#include <linux/grinternal.h>
57074 +
57075 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57076 +{
57077 +#ifdef CONFIG_GRKERNSEC
57078 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57079 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
57080 + task->gr_is_chrooted = 1;
57081 + else
57082 + task->gr_is_chrooted = 0;
57083 +
57084 + task->gr_chroot_dentry = path->dentry;
57085 +#endif
57086 + return;
57087 +}
57088 +
57089 +void gr_clear_chroot_entries(struct task_struct *task)
57090 +{
57091 +#ifdef CONFIG_GRKERNSEC
57092 + task->gr_is_chrooted = 0;
57093 + task->gr_chroot_dentry = NULL;
57094 +#endif
57095 + return;
57096 +}
57097 +
57098 +int
57099 +gr_handle_chroot_unix(const pid_t pid)
57100 +{
57101 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57102 + struct task_struct *p;
57103 +
57104 + if (unlikely(!grsec_enable_chroot_unix))
57105 + return 1;
57106 +
57107 + if (likely(!proc_is_chrooted(current)))
57108 + return 1;
57109 +
57110 + rcu_read_lock();
57111 + read_lock(&tasklist_lock);
57112 + p = find_task_by_vpid_unrestricted(pid);
57113 + if (unlikely(p && !have_same_root(current, p))) {
57114 + read_unlock(&tasklist_lock);
57115 + rcu_read_unlock();
57116 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57117 + return 0;
57118 + }
57119 + read_unlock(&tasklist_lock);
57120 + rcu_read_unlock();
57121 +#endif
57122 + return 1;
57123 +}
57124 +
57125 +int
57126 +gr_handle_chroot_nice(void)
57127 +{
57128 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57129 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57130 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57131 + return -EPERM;
57132 + }
57133 +#endif
57134 + return 0;
57135 +}
57136 +
57137 +int
57138 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57139 +{
57140 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57141 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57142 + && proc_is_chrooted(current)) {
57143 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57144 + return -EACCES;
57145 + }
57146 +#endif
57147 + return 0;
57148 +}
57149 +
57150 +int
57151 +gr_handle_chroot_rawio(const struct inode *inode)
57152 +{
57153 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57154 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57155 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57156 + return 1;
57157 +#endif
57158 + return 0;
57159 +}
57160 +
57161 +int
57162 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57163 +{
57164 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57165 + struct task_struct *p;
57166 + int ret = 0;
57167 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57168 + return ret;
57169 +
57170 + read_lock(&tasklist_lock);
57171 + do_each_pid_task(pid, type, p) {
57172 + if (!have_same_root(current, p)) {
57173 + ret = 1;
57174 + goto out;
57175 + }
57176 + } while_each_pid_task(pid, type, p);
57177 +out:
57178 + read_unlock(&tasklist_lock);
57179 + return ret;
57180 +#endif
57181 + return 0;
57182 +}
57183 +
57184 +int
57185 +gr_pid_is_chrooted(struct task_struct *p)
57186 +{
57187 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57188 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57189 + return 0;
57190 +
57191 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57192 + !have_same_root(current, p)) {
57193 + return 1;
57194 + }
57195 +#endif
57196 + return 0;
57197 +}
57198 +
57199 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57200 +
57201 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57202 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57203 +{
57204 + struct path path, currentroot;
57205 + int ret = 0;
57206 +
57207 + path.dentry = (struct dentry *)u_dentry;
57208 + path.mnt = (struct vfsmount *)u_mnt;
57209 + get_fs_root(current->fs, &currentroot);
57210 + if (path_is_under(&path, &currentroot))
57211 + ret = 1;
57212 + path_put(&currentroot);
57213 +
57214 + return ret;
57215 +}
57216 +#endif
57217 +
57218 +int
57219 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57220 +{
57221 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57222 + if (!grsec_enable_chroot_fchdir)
57223 + return 1;
57224 +
57225 + if (!proc_is_chrooted(current))
57226 + return 1;
57227 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57228 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57229 + return 0;
57230 + }
57231 +#endif
57232 + return 1;
57233 +}
57234 +
57235 +int
57236 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57237 + const time_t shm_createtime)
57238 +{
57239 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57240 + struct task_struct *p;
57241 + time_t starttime;
57242 +
57243 + if (unlikely(!grsec_enable_chroot_shmat))
57244 + return 1;
57245 +
57246 + if (likely(!proc_is_chrooted(current)))
57247 + return 1;
57248 +
57249 + rcu_read_lock();
57250 + read_lock(&tasklist_lock);
57251 +
57252 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57253 + starttime = p->start_time.tv_sec;
57254 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57255 + if (have_same_root(current, p)) {
57256 + goto allow;
57257 + } else {
57258 + read_unlock(&tasklist_lock);
57259 + rcu_read_unlock();
57260 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57261 + return 0;
57262 + }
57263 + }
57264 + /* creator exited, pid reuse, fall through to next check */
57265 + }
57266 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57267 + if (unlikely(!have_same_root(current, p))) {
57268 + read_unlock(&tasklist_lock);
57269 + rcu_read_unlock();
57270 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57271 + return 0;
57272 + }
57273 + }
57274 +
57275 +allow:
57276 + read_unlock(&tasklist_lock);
57277 + rcu_read_unlock();
57278 +#endif
57279 + return 1;
57280 +}
57281 +
57282 +void
57283 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57284 +{
57285 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57286 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57287 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57288 +#endif
57289 + return;
57290 +}
57291 +
57292 +int
57293 +gr_handle_chroot_mknod(const struct dentry *dentry,
57294 + const struct vfsmount *mnt, const int mode)
57295 +{
57296 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57297 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57298 + proc_is_chrooted(current)) {
57299 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57300 + return -EPERM;
57301 + }
57302 +#endif
57303 + return 0;
57304 +}
57305 +
57306 +int
57307 +gr_handle_chroot_mount(const struct dentry *dentry,
57308 + const struct vfsmount *mnt, const char *dev_name)
57309 +{
57310 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57311 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57312 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57313 + return -EPERM;
57314 + }
57315 +#endif
57316 + return 0;
57317 +}
57318 +
57319 +int
57320 +gr_handle_chroot_pivot(void)
57321 +{
57322 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57323 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57324 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57325 + return -EPERM;
57326 + }
57327 +#endif
57328 + return 0;
57329 +}
57330 +
57331 +int
57332 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57333 +{
57334 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57335 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57336 + !gr_is_outside_chroot(dentry, mnt)) {
57337 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57338 + return -EPERM;
57339 + }
57340 +#endif
57341 + return 0;
57342 +}
57343 +
57344 +extern const char *captab_log[];
57345 +extern int captab_log_entries;
57346 +
57347 +int
57348 +gr_chroot_is_capable(const int cap)
57349 +{
57350 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57351 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
57352 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57353 + if (cap_raised(chroot_caps, cap)) {
57354 + const struct cred *creds = current_cred();
57355 + if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
57356 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
57357 + }
57358 + return 0;
57359 + }
57360 + }
57361 +#endif
57362 + return 1;
57363 +}
57364 +
57365 +int
57366 +gr_chroot_is_capable_nolog(const int cap)
57367 +{
57368 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57369 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
57370 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57371 + if (cap_raised(chroot_caps, cap)) {
57372 + return 0;
57373 + }
57374 + }
57375 +#endif
57376 + return 1;
57377 +}
57378 +
57379 +int
57380 +gr_handle_chroot_sysctl(const int op)
57381 +{
57382 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57383 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57384 + proc_is_chrooted(current))
57385 + return -EACCES;
57386 +#endif
57387 + return 0;
57388 +}
57389 +
57390 +void
57391 +gr_handle_chroot_chdir(struct path *path)
57392 +{
57393 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57394 + if (grsec_enable_chroot_chdir)
57395 + set_fs_pwd(current->fs, path);
57396 +#endif
57397 + return;
57398 +}
57399 +
57400 +int
57401 +gr_handle_chroot_chmod(const struct dentry *dentry,
57402 + const struct vfsmount *mnt, const int mode)
57403 +{
57404 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57405 + /* allow chmod +s on directories, but not files */
57406 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57407 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57408 + proc_is_chrooted(current)) {
57409 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57410 + return -EPERM;
57411 + }
57412 +#endif
57413 + return 0;
57414 +}
57415 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57416 new file mode 100644
57417 index 0000000..d81a586
57418 --- /dev/null
57419 +++ b/grsecurity/grsec_disabled.c
57420 @@ -0,0 +1,439 @@
57421 +#include <linux/kernel.h>
57422 +#include <linux/module.h>
57423 +#include <linux/sched.h>
57424 +#include <linux/file.h>
57425 +#include <linux/fs.h>
57426 +#include <linux/kdev_t.h>
57427 +#include <linux/net.h>
57428 +#include <linux/in.h>
57429 +#include <linux/ip.h>
57430 +#include <linux/skbuff.h>
57431 +#include <linux/sysctl.h>
57432 +
57433 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57434 +void
57435 +pax_set_initial_flags(struct linux_binprm *bprm)
57436 +{
57437 + return;
57438 +}
57439 +#endif
57440 +
57441 +#ifdef CONFIG_SYSCTL
57442 +__u32
57443 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57444 +{
57445 + return 0;
57446 +}
57447 +#endif
57448 +
57449 +#ifdef CONFIG_TASKSTATS
57450 +int gr_is_taskstats_denied(int pid)
57451 +{
57452 + return 0;
57453 +}
57454 +#endif
57455 +
57456 +int
57457 +gr_acl_is_enabled(void)
57458 +{
57459 + return 0;
57460 +}
57461 +
57462 +void
57463 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57464 +{
57465 + return;
57466 +}
57467 +
57468 +int
57469 +gr_handle_rawio(const struct inode *inode)
57470 +{
57471 + return 0;
57472 +}
57473 +
57474 +void
57475 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57476 +{
57477 + return;
57478 +}
57479 +
57480 +int
57481 +gr_handle_ptrace(struct task_struct *task, const long request)
57482 +{
57483 + return 0;
57484 +}
57485 +
57486 +int
57487 +gr_handle_proc_ptrace(struct task_struct *task)
57488 +{
57489 + return 0;
57490 +}
57491 +
57492 +void
57493 +gr_learn_resource(const struct task_struct *task,
57494 + const int res, const unsigned long wanted, const int gt)
57495 +{
57496 + return;
57497 +}
57498 +
57499 +int
57500 +gr_set_acls(const int type)
57501 +{
57502 + return 0;
57503 +}
57504 +
57505 +int
57506 +gr_check_hidden_task(const struct task_struct *tsk)
57507 +{
57508 + return 0;
57509 +}
57510 +
57511 +int
57512 +gr_check_protected_task(const struct task_struct *task)
57513 +{
57514 + return 0;
57515 +}
57516 +
57517 +int
57518 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57519 +{
57520 + return 0;
57521 +}
57522 +
57523 +void
57524 +gr_copy_label(struct task_struct *tsk)
57525 +{
57526 + return;
57527 +}
57528 +
57529 +void
57530 +gr_set_pax_flags(struct task_struct *task)
57531 +{
57532 + return;
57533 +}
57534 +
57535 +int
57536 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57537 + const int unsafe_share)
57538 +{
57539 + return 0;
57540 +}
57541 +
57542 +void
57543 +gr_handle_delete(const ino_t ino, const dev_t dev)
57544 +{
57545 + return;
57546 +}
57547 +
57548 +void
57549 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57550 +{
57551 + return;
57552 +}
57553 +
57554 +void
57555 +gr_handle_crash(struct task_struct *task, const int sig)
57556 +{
57557 + return;
57558 +}
57559 +
57560 +int
57561 +gr_check_crash_exec(const struct file *filp)
57562 +{
57563 + return 0;
57564 +}
57565 +
57566 +int
57567 +gr_check_crash_uid(const uid_t uid)
57568 +{
57569 + return 0;
57570 +}
57571 +
57572 +void
57573 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57574 + struct dentry *old_dentry,
57575 + struct dentry *new_dentry,
57576 + struct vfsmount *mnt, const __u8 replace)
57577 +{
57578 + return;
57579 +}
57580 +
57581 +int
57582 +gr_search_socket(const int family, const int type, const int protocol)
57583 +{
57584 + return 1;
57585 +}
57586 +
57587 +int
57588 +gr_search_connectbind(const int mode, const struct socket *sock,
57589 + const struct sockaddr_in *addr)
57590 +{
57591 + return 0;
57592 +}
57593 +
57594 +void
57595 +gr_handle_alertkill(struct task_struct *task)
57596 +{
57597 + return;
57598 +}
57599 +
57600 +__u32
57601 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57602 +{
57603 + return 1;
57604 +}
57605 +
57606 +__u32
57607 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57608 + const struct vfsmount * mnt)
57609 +{
57610 + return 1;
57611 +}
57612 +
57613 +__u32
57614 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57615 + int acc_mode)
57616 +{
57617 + return 1;
57618 +}
57619 +
57620 +__u32
57621 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57622 +{
57623 + return 1;
57624 +}
57625 +
57626 +__u32
57627 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57628 +{
57629 + return 1;
57630 +}
57631 +
57632 +int
57633 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57634 + unsigned int *vm_flags)
57635 +{
57636 + return 1;
57637 +}
57638 +
57639 +__u32
57640 +gr_acl_handle_truncate(const struct dentry * dentry,
57641 + const struct vfsmount * mnt)
57642 +{
57643 + return 1;
57644 +}
57645 +
57646 +__u32
57647 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57648 +{
57649 + return 1;
57650 +}
57651 +
57652 +__u32
57653 +gr_acl_handle_access(const struct dentry * dentry,
57654 + const struct vfsmount * mnt, const int fmode)
57655 +{
57656 + return 1;
57657 +}
57658 +
57659 +__u32
57660 +gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
57661 + mode_t mode)
57662 +{
57663 + return 1;
57664 +}
57665 +
57666 +__u32
57667 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57668 + mode_t mode)
57669 +{
57670 + return 1;
57671 +}
57672 +
57673 +__u32
57674 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57675 +{
57676 + return 1;
57677 +}
57678 +
57679 +__u32
57680 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57681 +{
57682 + return 1;
57683 +}
57684 +
57685 +void
57686 +grsecurity_init(void)
57687 +{
57688 + return;
57689 +}
57690 +
57691 +__u32
57692 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57693 + const struct dentry * parent_dentry,
57694 + const struct vfsmount * parent_mnt,
57695 + const int mode)
57696 +{
57697 + return 1;
57698 +}
57699 +
57700 +__u32
57701 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57702 + const struct dentry * parent_dentry,
57703 + const struct vfsmount * parent_mnt)
57704 +{
57705 + return 1;
57706 +}
57707 +
57708 +__u32
57709 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57710 + const struct dentry * parent_dentry,
57711 + const struct vfsmount * parent_mnt, const char *from)
57712 +{
57713 + return 1;
57714 +}
57715 +
57716 +__u32
57717 +gr_acl_handle_link(const struct dentry * new_dentry,
57718 + const struct dentry * parent_dentry,
57719 + const struct vfsmount * parent_mnt,
57720 + const struct dentry * old_dentry,
57721 + const struct vfsmount * old_mnt, const char *to)
57722 +{
57723 + return 1;
57724 +}
57725 +
57726 +int
57727 +gr_acl_handle_rename(const struct dentry *new_dentry,
57728 + const struct dentry *parent_dentry,
57729 + const struct vfsmount *parent_mnt,
57730 + const struct dentry *old_dentry,
57731 + const struct inode *old_parent_inode,
57732 + const struct vfsmount *old_mnt, const char *newname)
57733 +{
57734 + return 0;
57735 +}
57736 +
57737 +int
57738 +gr_acl_handle_filldir(const struct file *file, const char *name,
57739 + const int namelen, const ino_t ino)
57740 +{
57741 + return 1;
57742 +}
57743 +
57744 +int
57745 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57746 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57747 +{
57748 + return 1;
57749 +}
57750 +
57751 +int
57752 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57753 +{
57754 + return 0;
57755 +}
57756 +
57757 +int
57758 +gr_search_accept(const struct socket *sock)
57759 +{
57760 + return 0;
57761 +}
57762 +
57763 +int
57764 +gr_search_listen(const struct socket *sock)
57765 +{
57766 + return 0;
57767 +}
57768 +
57769 +int
57770 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57771 +{
57772 + return 0;
57773 +}
57774 +
57775 +__u32
57776 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57777 +{
57778 + return 1;
57779 +}
57780 +
57781 +__u32
57782 +gr_acl_handle_creat(const struct dentry * dentry,
57783 + const struct dentry * p_dentry,
57784 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57785 + const int imode)
57786 +{
57787 + return 1;
57788 +}
57789 +
57790 +void
57791 +gr_acl_handle_exit(void)
57792 +{
57793 + return;
57794 +}
57795 +
57796 +int
57797 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57798 +{
57799 + return 1;
57800 +}
57801 +
57802 +void
57803 +gr_set_role_label(const uid_t uid, const gid_t gid)
57804 +{
57805 + return;
57806 +}
57807 +
57808 +int
57809 +gr_acl_handle_procpidmem(const struct task_struct *task)
57810 +{
57811 + return 0;
57812 +}
57813 +
57814 +int
57815 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57816 +{
57817 + return 0;
57818 +}
57819 +
57820 +int
57821 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57822 +{
57823 + return 0;
57824 +}
57825 +
57826 +void
57827 +gr_set_kernel_label(struct task_struct *task)
57828 +{
57829 + return;
57830 +}
57831 +
57832 +int
57833 +gr_check_user_change(int real, int effective, int fs)
57834 +{
57835 + return 0;
57836 +}
57837 +
57838 +int
57839 +gr_check_group_change(int real, int effective, int fs)
57840 +{
57841 + return 0;
57842 +}
57843 +
57844 +int gr_acl_enable_at_secure(void)
57845 +{
57846 + return 0;
57847 +}
57848 +
57849 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57850 +{
57851 + return dentry->d_inode->i_sb->s_dev;
57852 +}
57853 +
57854 +EXPORT_SYMBOL(gr_learn_resource);
57855 +EXPORT_SYMBOL(gr_set_kernel_label);
57856 +#ifdef CONFIG_SECURITY
57857 +EXPORT_SYMBOL(gr_check_user_change);
57858 +EXPORT_SYMBOL(gr_check_group_change);
57859 +#endif
57860 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57861 new file mode 100644
57862 index 0000000..2b05ada
57863 --- /dev/null
57864 +++ b/grsecurity/grsec_exec.c
57865 @@ -0,0 +1,146 @@
57866 +#include <linux/kernel.h>
57867 +#include <linux/sched.h>
57868 +#include <linux/file.h>
57869 +#include <linux/binfmts.h>
57870 +#include <linux/fs.h>
57871 +#include <linux/types.h>
57872 +#include <linux/grdefs.h>
57873 +#include <linux/grsecurity.h>
57874 +#include <linux/grinternal.h>
57875 +#include <linux/capability.h>
57876 +#include <linux/module.h>
57877 +
57878 +#include <asm/uaccess.h>
57879 +
57880 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57881 +static char gr_exec_arg_buf[132];
57882 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57883 +#endif
57884 +
57885 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57886 +
57887 +void
57888 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57889 +{
57890 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57891 + char *grarg = gr_exec_arg_buf;
57892 + unsigned int i, x, execlen = 0;
57893 + char c;
57894 +
57895 + if (!((grsec_enable_execlog && grsec_enable_group &&
57896 + in_group_p(grsec_audit_gid))
57897 + || (grsec_enable_execlog && !grsec_enable_group)))
57898 + return;
57899 +
57900 + mutex_lock(&gr_exec_arg_mutex);
57901 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57902 +
57903 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57904 + const char __user *p;
57905 + unsigned int len;
57906 +
57907 + p = get_user_arg_ptr(argv, i);
57908 + if (IS_ERR(p))
57909 + goto log;
57910 +
57911 + len = strnlen_user(p, 128 - execlen);
57912 + if (len > 128 - execlen)
57913 + len = 128 - execlen;
57914 + else if (len > 0)
57915 + len--;
57916 + if (copy_from_user(grarg + execlen, p, len))
57917 + goto log;
57918 +
57919 + /* rewrite unprintable characters */
57920 + for (x = 0; x < len; x++) {
57921 + c = *(grarg + execlen + x);
57922 + if (c < 32 || c > 126)
57923 + *(grarg + execlen + x) = ' ';
57924 + }
57925 +
57926 + execlen += len;
57927 + *(grarg + execlen) = ' ';
57928 + *(grarg + execlen + 1) = '\0';
57929 + execlen++;
57930 + }
57931 +
57932 + log:
57933 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57934 + bprm->file->f_path.mnt, grarg);
57935 + mutex_unlock(&gr_exec_arg_mutex);
57936 +#endif
57937 + return;
57938 +}
57939 +
57940 +#ifdef CONFIG_GRKERNSEC
57941 +extern int gr_acl_is_capable(const int cap);
57942 +extern int gr_acl_is_capable_nolog(const int cap);
57943 +extern int gr_chroot_is_capable(const int cap);
57944 +extern int gr_chroot_is_capable_nolog(const int cap);
57945 +#endif
57946 +
57947 +const char *captab_log[] = {
57948 + "CAP_CHOWN",
57949 + "CAP_DAC_OVERRIDE",
57950 + "CAP_DAC_READ_SEARCH",
57951 + "CAP_FOWNER",
57952 + "CAP_FSETID",
57953 + "CAP_KILL",
57954 + "CAP_SETGID",
57955 + "CAP_SETUID",
57956 + "CAP_SETPCAP",
57957 + "CAP_LINUX_IMMUTABLE",
57958 + "CAP_NET_BIND_SERVICE",
57959 + "CAP_NET_BROADCAST",
57960 + "CAP_NET_ADMIN",
57961 + "CAP_NET_RAW",
57962 + "CAP_IPC_LOCK",
57963 + "CAP_IPC_OWNER",
57964 + "CAP_SYS_MODULE",
57965 + "CAP_SYS_RAWIO",
57966 + "CAP_SYS_CHROOT",
57967 + "CAP_SYS_PTRACE",
57968 + "CAP_SYS_PACCT",
57969 + "CAP_SYS_ADMIN",
57970 + "CAP_SYS_BOOT",
57971 + "CAP_SYS_NICE",
57972 + "CAP_SYS_RESOURCE",
57973 + "CAP_SYS_TIME",
57974 + "CAP_SYS_TTY_CONFIG",
57975 + "CAP_MKNOD",
57976 + "CAP_LEASE",
57977 + "CAP_AUDIT_WRITE",
57978 + "CAP_AUDIT_CONTROL",
57979 + "CAP_SETFCAP",
57980 + "CAP_MAC_OVERRIDE",
57981 + "CAP_MAC_ADMIN",
57982 + "CAP_SYSLOG",
57983 + "CAP_WAKE_ALARM"
57984 +};
57985 +
57986 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57987 +
57988 +int gr_is_capable(const int cap)
57989 +{
57990 +#ifdef CONFIG_GRKERNSEC
57991 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57992 + return 1;
57993 + return 0;
57994 +#else
57995 + return 1;
57996 +#endif
57997 +}
57998 +
57999 +int gr_is_capable_nolog(const int cap)
58000 +{
58001 +#ifdef CONFIG_GRKERNSEC
58002 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58003 + return 1;
58004 + return 0;
58005 +#else
58006 + return 1;
58007 +#endif
58008 +}
58009 +
58010 +EXPORT_SYMBOL(gr_is_capable);
58011 +EXPORT_SYMBOL(gr_is_capable_nolog);
58012 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58013 new file mode 100644
58014 index 0000000..d3ee748
58015 --- /dev/null
58016 +++ b/grsecurity/grsec_fifo.c
58017 @@ -0,0 +1,24 @@
58018 +#include <linux/kernel.h>
58019 +#include <linux/sched.h>
58020 +#include <linux/fs.h>
58021 +#include <linux/file.h>
58022 +#include <linux/grinternal.h>
58023 +
58024 +int
58025 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58026 + const struct dentry *dir, const int flag, const int acc_mode)
58027 +{
58028 +#ifdef CONFIG_GRKERNSEC_FIFO
58029 + const struct cred *cred = current_cred();
58030 +
58031 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58032 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58033 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58034 + (cred->fsuid != dentry->d_inode->i_uid)) {
58035 + if (!inode_permission(dentry->d_inode, acc_mode))
58036 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58037 + return -EACCES;
58038 + }
58039 +#endif
58040 + return 0;
58041 +}
58042 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58043 new file mode 100644
58044 index 0000000..8ca18bf
58045 --- /dev/null
58046 +++ b/grsecurity/grsec_fork.c
58047 @@ -0,0 +1,23 @@
58048 +#include <linux/kernel.h>
58049 +#include <linux/sched.h>
58050 +#include <linux/grsecurity.h>
58051 +#include <linux/grinternal.h>
58052 +#include <linux/errno.h>
58053 +
58054 +void
58055 +gr_log_forkfail(const int retval)
58056 +{
58057 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58058 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58059 + switch (retval) {
58060 + case -EAGAIN:
58061 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58062 + break;
58063 + case -ENOMEM:
58064 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58065 + break;
58066 + }
58067 + }
58068 +#endif
58069 + return;
58070 +}
58071 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58072 new file mode 100644
58073 index 0000000..cb8e5a1
58074 --- /dev/null
58075 +++ b/grsecurity/grsec_init.c
58076 @@ -0,0 +1,273 @@
58077 +#include <linux/kernel.h>
58078 +#include <linux/sched.h>
58079 +#include <linux/mm.h>
58080 +#include <linux/gracl.h>
58081 +#include <linux/slab.h>
58082 +#include <linux/vmalloc.h>
58083 +#include <linux/percpu.h>
58084 +#include <linux/module.h>
58085 +
58086 +int grsec_enable_setxid;
58087 +int grsec_enable_brute;
58088 +int grsec_enable_link;
58089 +int grsec_enable_dmesg;
58090 +int grsec_enable_harden_ptrace;
58091 +int grsec_enable_fifo;
58092 +int grsec_enable_execlog;
58093 +int grsec_enable_signal;
58094 +int grsec_enable_forkfail;
58095 +int grsec_enable_audit_ptrace;
58096 +int grsec_enable_time;
58097 +int grsec_enable_audit_textrel;
58098 +int grsec_enable_group;
58099 +int grsec_audit_gid;
58100 +int grsec_enable_chdir;
58101 +int grsec_enable_mount;
58102 +int grsec_enable_rofs;
58103 +int grsec_enable_chroot_findtask;
58104 +int grsec_enable_chroot_mount;
58105 +int grsec_enable_chroot_shmat;
58106 +int grsec_enable_chroot_fchdir;
58107 +int grsec_enable_chroot_double;
58108 +int grsec_enable_chroot_pivot;
58109 +int grsec_enable_chroot_chdir;
58110 +int grsec_enable_chroot_chmod;
58111 +int grsec_enable_chroot_mknod;
58112 +int grsec_enable_chroot_nice;
58113 +int grsec_enable_chroot_execlog;
58114 +int grsec_enable_chroot_caps;
58115 +int grsec_enable_chroot_sysctl;
58116 +int grsec_enable_chroot_unix;
58117 +int grsec_enable_tpe;
58118 +int grsec_tpe_gid;
58119 +int grsec_enable_blackhole;
58120 +#ifdef CONFIG_IPV6_MODULE
58121 +EXPORT_SYMBOL(grsec_enable_blackhole);
58122 +#endif
58123 +int grsec_lastack_retries;
58124 +int grsec_enable_tpe_all;
58125 +int grsec_enable_tpe_invert;
58126 +int grsec_enable_socket_all;
58127 +int grsec_socket_all_gid;
58128 +int grsec_enable_socket_client;
58129 +int grsec_socket_client_gid;
58130 +int grsec_enable_socket_server;
58131 +int grsec_socket_server_gid;
58132 +int grsec_resource_logging;
58133 +int grsec_disable_privio;
58134 +int grsec_enable_log_rwxmaps;
58135 +int grsec_lock;
58136 +
58137 +DEFINE_SPINLOCK(grsec_alert_lock);
58138 +unsigned long grsec_alert_wtime = 0;
58139 +unsigned long grsec_alert_fyet = 0;
58140 +
58141 +DEFINE_SPINLOCK(grsec_audit_lock);
58142 +
58143 +DEFINE_RWLOCK(grsec_exec_file_lock);
58144 +
58145 +char *gr_shared_page[4];
58146 +
58147 +char *gr_alert_log_fmt;
58148 +char *gr_audit_log_fmt;
58149 +char *gr_alert_log_buf;
58150 +char *gr_audit_log_buf;
58151 +
58152 +extern struct gr_arg *gr_usermode;
58153 +extern unsigned char *gr_system_salt;
58154 +extern unsigned char *gr_system_sum;
58155 +
58156 +void __init
58157 +grsecurity_init(void)
58158 +{
58159 + int j;
58160 + /* create the per-cpu shared pages */
58161 +
58162 +#ifdef CONFIG_X86
58163 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58164 +#endif
58165 +
58166 + for (j = 0; j < 4; j++) {
58167 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58168 + if (gr_shared_page[j] == NULL) {
58169 + panic("Unable to allocate grsecurity shared page");
58170 + return;
58171 + }
58172 + }
58173 +
58174 + /* allocate log buffers */
58175 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58176 + if (!gr_alert_log_fmt) {
58177 + panic("Unable to allocate grsecurity alert log format buffer");
58178 + return;
58179 + }
58180 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58181 + if (!gr_audit_log_fmt) {
58182 + panic("Unable to allocate grsecurity audit log format buffer");
58183 + return;
58184 + }
58185 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58186 + if (!gr_alert_log_buf) {
58187 + panic("Unable to allocate grsecurity alert log buffer");
58188 + return;
58189 + }
58190 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58191 + if (!gr_audit_log_buf) {
58192 + panic("Unable to allocate grsecurity audit log buffer");
58193 + return;
58194 + }
58195 +
58196 + /* allocate memory for authentication structure */
58197 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58198 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58199 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58200 +
58201 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58202 + panic("Unable to allocate grsecurity authentication structure");
58203 + return;
58204 + }
58205 +
58206 +
58207 +#ifdef CONFIG_GRKERNSEC_IO
58208 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58209 + grsec_disable_privio = 1;
58210 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58211 + grsec_disable_privio = 1;
58212 +#else
58213 + grsec_disable_privio = 0;
58214 +#endif
58215 +#endif
58216 +
58217 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58218 + /* for backward compatibility, tpe_invert always defaults to on if
58219 + enabled in the kernel
58220 + */
58221 + grsec_enable_tpe_invert = 1;
58222 +#endif
58223 +
58224 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58225 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58226 + grsec_lock = 1;
58227 +#endif
58228 +
58229 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58230 + grsec_enable_audit_textrel = 1;
58231 +#endif
58232 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58233 + grsec_enable_log_rwxmaps = 1;
58234 +#endif
58235 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58236 + grsec_enable_group = 1;
58237 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58238 +#endif
58239 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58240 + grsec_enable_chdir = 1;
58241 +#endif
58242 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58243 + grsec_enable_harden_ptrace = 1;
58244 +#endif
58245 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58246 + grsec_enable_mount = 1;
58247 +#endif
58248 +#ifdef CONFIG_GRKERNSEC_LINK
58249 + grsec_enable_link = 1;
58250 +#endif
58251 +#ifdef CONFIG_GRKERNSEC_BRUTE
58252 + grsec_enable_brute = 1;
58253 +#endif
58254 +#ifdef CONFIG_GRKERNSEC_DMESG
58255 + grsec_enable_dmesg = 1;
58256 +#endif
58257 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58258 + grsec_enable_blackhole = 1;
58259 + grsec_lastack_retries = 4;
58260 +#endif
58261 +#ifdef CONFIG_GRKERNSEC_FIFO
58262 + grsec_enable_fifo = 1;
58263 +#endif
58264 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58265 + grsec_enable_execlog = 1;
58266 +#endif
58267 +#ifdef CONFIG_GRKERNSEC_SETXID
58268 + grsec_enable_setxid = 1;
58269 +#endif
58270 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58271 + grsec_enable_signal = 1;
58272 +#endif
58273 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58274 + grsec_enable_forkfail = 1;
58275 +#endif
58276 +#ifdef CONFIG_GRKERNSEC_TIME
58277 + grsec_enable_time = 1;
58278 +#endif
58279 +#ifdef CONFIG_GRKERNSEC_RESLOG
58280 + grsec_resource_logging = 1;
58281 +#endif
58282 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58283 + grsec_enable_chroot_findtask = 1;
58284 +#endif
58285 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58286 + grsec_enable_chroot_unix = 1;
58287 +#endif
58288 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58289 + grsec_enable_chroot_mount = 1;
58290 +#endif
58291 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58292 + grsec_enable_chroot_fchdir = 1;
58293 +#endif
58294 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58295 + grsec_enable_chroot_shmat = 1;
58296 +#endif
58297 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58298 + grsec_enable_audit_ptrace = 1;
58299 +#endif
58300 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58301 + grsec_enable_chroot_double = 1;
58302 +#endif
58303 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58304 + grsec_enable_chroot_pivot = 1;
58305 +#endif
58306 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58307 + grsec_enable_chroot_chdir = 1;
58308 +#endif
58309 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58310 + grsec_enable_chroot_chmod = 1;
58311 +#endif
58312 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58313 + grsec_enable_chroot_mknod = 1;
58314 +#endif
58315 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58316 + grsec_enable_chroot_nice = 1;
58317 +#endif
58318 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58319 + grsec_enable_chroot_execlog = 1;
58320 +#endif
58321 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58322 + grsec_enable_chroot_caps = 1;
58323 +#endif
58324 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58325 + grsec_enable_chroot_sysctl = 1;
58326 +#endif
58327 +#ifdef CONFIG_GRKERNSEC_TPE
58328 + grsec_enable_tpe = 1;
58329 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58330 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58331 + grsec_enable_tpe_all = 1;
58332 +#endif
58333 +#endif
58334 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58335 + grsec_enable_socket_all = 1;
58336 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58337 +#endif
58338 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58339 + grsec_enable_socket_client = 1;
58340 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58341 +#endif
58342 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58343 + grsec_enable_socket_server = 1;
58344 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58345 +#endif
58346 +#endif
58347 +
58348 + return;
58349 +}
58350 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58351 new file mode 100644
58352 index 0000000..3efe141
58353 --- /dev/null
58354 +++ b/grsecurity/grsec_link.c
58355 @@ -0,0 +1,43 @@
58356 +#include <linux/kernel.h>
58357 +#include <linux/sched.h>
58358 +#include <linux/fs.h>
58359 +#include <linux/file.h>
58360 +#include <linux/grinternal.h>
58361 +
58362 +int
58363 +gr_handle_follow_link(const struct inode *parent,
58364 + const struct inode *inode,
58365 + const struct dentry *dentry, const struct vfsmount *mnt)
58366 +{
58367 +#ifdef CONFIG_GRKERNSEC_LINK
58368 + const struct cred *cred = current_cred();
58369 +
58370 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58371 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
58372 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
58373 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58374 + return -EACCES;
58375 + }
58376 +#endif
58377 + return 0;
58378 +}
58379 +
58380 +int
58381 +gr_handle_hardlink(const struct dentry *dentry,
58382 + const struct vfsmount *mnt,
58383 + struct inode *inode, const int mode, const char *to)
58384 +{
58385 +#ifdef CONFIG_GRKERNSEC_LINK
58386 + const struct cred *cred = current_cred();
58387 +
58388 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
58389 + (!S_ISREG(mode) || (mode & S_ISUID) ||
58390 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58391 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58392 + !capable(CAP_FOWNER) && cred->uid) {
58393 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58394 + return -EPERM;
58395 + }
58396 +#endif
58397 + return 0;
58398 +}
58399 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58400 new file mode 100644
58401 index 0000000..a45d2e9
58402 --- /dev/null
58403 +++ b/grsecurity/grsec_log.c
58404 @@ -0,0 +1,322 @@
58405 +#include <linux/kernel.h>
58406 +#include <linux/sched.h>
58407 +#include <linux/file.h>
58408 +#include <linux/tty.h>
58409 +#include <linux/fs.h>
58410 +#include <linux/grinternal.h>
58411 +
58412 +#ifdef CONFIG_TREE_PREEMPT_RCU
58413 +#define DISABLE_PREEMPT() preempt_disable()
58414 +#define ENABLE_PREEMPT() preempt_enable()
58415 +#else
58416 +#define DISABLE_PREEMPT()
58417 +#define ENABLE_PREEMPT()
58418 +#endif
58419 +
58420 +#define BEGIN_LOCKS(x) \
58421 + DISABLE_PREEMPT(); \
58422 + rcu_read_lock(); \
58423 + read_lock(&tasklist_lock); \
58424 + read_lock(&grsec_exec_file_lock); \
58425 + if (x != GR_DO_AUDIT) \
58426 + spin_lock(&grsec_alert_lock); \
58427 + else \
58428 + spin_lock(&grsec_audit_lock)
58429 +
58430 +#define END_LOCKS(x) \
58431 + if (x != GR_DO_AUDIT) \
58432 + spin_unlock(&grsec_alert_lock); \
58433 + else \
58434 + spin_unlock(&grsec_audit_lock); \
58435 + read_unlock(&grsec_exec_file_lock); \
58436 + read_unlock(&tasklist_lock); \
58437 + rcu_read_unlock(); \
58438 + ENABLE_PREEMPT(); \
58439 + if (x == GR_DONT_AUDIT) \
58440 + gr_handle_alertkill(current)
58441 +
58442 +enum {
58443 + FLOODING,
58444 + NO_FLOODING
58445 +};
58446 +
58447 +extern char *gr_alert_log_fmt;
58448 +extern char *gr_audit_log_fmt;
58449 +extern char *gr_alert_log_buf;
58450 +extern char *gr_audit_log_buf;
58451 +
58452 +static int gr_log_start(int audit)
58453 +{
58454 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58455 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58456 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58457 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58458 + unsigned long curr_secs = get_seconds();
58459 +
58460 + if (audit == GR_DO_AUDIT)
58461 + goto set_fmt;
58462 +
58463 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58464 + grsec_alert_wtime = curr_secs;
58465 + grsec_alert_fyet = 0;
58466 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58467 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58468 + grsec_alert_fyet++;
58469 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58470 + grsec_alert_wtime = curr_secs;
58471 + grsec_alert_fyet++;
58472 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58473 + return FLOODING;
58474 + }
58475 + else return FLOODING;
58476 +
58477 +set_fmt:
58478 +#endif
58479 + memset(buf, 0, PAGE_SIZE);
58480 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58481 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58482 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58483 + } else if (current->signal->curr_ip) {
58484 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58485 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58486 + } else if (gr_acl_is_enabled()) {
58487 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58488 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58489 + } else {
58490 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58491 + strcpy(buf, fmt);
58492 + }
58493 +
58494 + return NO_FLOODING;
58495 +}
58496 +
58497 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58498 + __attribute__ ((format (printf, 2, 0)));
58499 +
58500 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58501 +{
58502 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58503 + unsigned int len = strlen(buf);
58504 +
58505 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58506 +
58507 + return;
58508 +}
58509 +
58510 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58511 + __attribute__ ((format (printf, 2, 3)));
58512 +
58513 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58514 +{
58515 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58516 + unsigned int len = strlen(buf);
58517 + va_list ap;
58518 +
58519 + va_start(ap, msg);
58520 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58521 + va_end(ap);
58522 +
58523 + return;
58524 +}
58525 +
58526 +static void gr_log_end(int audit, int append_default)
58527 +{
58528 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58529 +
58530 + if (append_default) {
58531 + unsigned int len = strlen(buf);
58532 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58533 + }
58534 +
58535 + printk("%s\n", buf);
58536 +
58537 + return;
58538 +}
58539 +
58540 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58541 +{
58542 + int logtype;
58543 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58544 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58545 + void *voidptr = NULL;
58546 + int num1 = 0, num2 = 0;
58547 + unsigned long ulong1 = 0, ulong2 = 0;
58548 + struct dentry *dentry = NULL;
58549 + struct vfsmount *mnt = NULL;
58550 + struct file *file = NULL;
58551 + struct task_struct *task = NULL;
58552 + const struct cred *cred, *pcred;
58553 + va_list ap;
58554 +
58555 + BEGIN_LOCKS(audit);
58556 + logtype = gr_log_start(audit);
58557 + if (logtype == FLOODING) {
58558 + END_LOCKS(audit);
58559 + return;
58560 + }
58561 + va_start(ap, argtypes);
58562 + switch (argtypes) {
58563 + case GR_TTYSNIFF:
58564 + task = va_arg(ap, struct task_struct *);
58565 + 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);
58566 + break;
58567 + case GR_SYSCTL_HIDDEN:
58568 + str1 = va_arg(ap, char *);
58569 + gr_log_middle_varargs(audit, msg, result, str1);
58570 + break;
58571 + case GR_RBAC:
58572 + dentry = va_arg(ap, struct dentry *);
58573 + mnt = va_arg(ap, struct vfsmount *);
58574 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58575 + break;
58576 + case GR_RBAC_STR:
58577 + dentry = va_arg(ap, struct dentry *);
58578 + mnt = va_arg(ap, struct vfsmount *);
58579 + str1 = va_arg(ap, char *);
58580 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58581 + break;
58582 + case GR_STR_RBAC:
58583 + str1 = va_arg(ap, char *);
58584 + dentry = va_arg(ap, struct dentry *);
58585 + mnt = va_arg(ap, struct vfsmount *);
58586 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58587 + break;
58588 + case GR_RBAC_MODE2:
58589 + dentry = va_arg(ap, struct dentry *);
58590 + mnt = va_arg(ap, struct vfsmount *);
58591 + str1 = va_arg(ap, char *);
58592 + str2 = va_arg(ap, char *);
58593 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58594 + break;
58595 + case GR_RBAC_MODE3:
58596 + dentry = va_arg(ap, struct dentry *);
58597 + mnt = va_arg(ap, struct vfsmount *);
58598 + str1 = va_arg(ap, char *);
58599 + str2 = va_arg(ap, char *);
58600 + str3 = va_arg(ap, char *);
58601 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58602 + break;
58603 + case GR_FILENAME:
58604 + dentry = va_arg(ap, struct dentry *);
58605 + mnt = va_arg(ap, struct vfsmount *);
58606 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58607 + break;
58608 + case GR_STR_FILENAME:
58609 + str1 = va_arg(ap, char *);
58610 + dentry = va_arg(ap, struct dentry *);
58611 + mnt = va_arg(ap, struct vfsmount *);
58612 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58613 + break;
58614 + case GR_FILENAME_STR:
58615 + dentry = va_arg(ap, struct dentry *);
58616 + mnt = va_arg(ap, struct vfsmount *);
58617 + str1 = va_arg(ap, char *);
58618 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58619 + break;
58620 + case GR_FILENAME_TWO_INT:
58621 + dentry = va_arg(ap, struct dentry *);
58622 + mnt = va_arg(ap, struct vfsmount *);
58623 + num1 = va_arg(ap, int);
58624 + num2 = va_arg(ap, int);
58625 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58626 + break;
58627 + case GR_FILENAME_TWO_INT_STR:
58628 + dentry = va_arg(ap, struct dentry *);
58629 + mnt = va_arg(ap, struct vfsmount *);
58630 + num1 = va_arg(ap, int);
58631 + num2 = va_arg(ap, int);
58632 + str1 = va_arg(ap, char *);
58633 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58634 + break;
58635 + case GR_TEXTREL:
58636 + file = va_arg(ap, struct file *);
58637 + ulong1 = va_arg(ap, unsigned long);
58638 + ulong2 = va_arg(ap, unsigned long);
58639 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58640 + break;
58641 + case GR_PTRACE:
58642 + task = va_arg(ap, struct task_struct *);
58643 + 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);
58644 + break;
58645 + case GR_RESOURCE:
58646 + task = va_arg(ap, struct task_struct *);
58647 + cred = __task_cred(task);
58648 + pcred = __task_cred(task->real_parent);
58649 + ulong1 = va_arg(ap, unsigned long);
58650 + str1 = va_arg(ap, char *);
58651 + ulong2 = va_arg(ap, unsigned long);
58652 + 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);
58653 + break;
58654 + case GR_CAP:
58655 + task = va_arg(ap, struct task_struct *);
58656 + cred = __task_cred(task);
58657 + pcred = __task_cred(task->real_parent);
58658 + str1 = va_arg(ap, char *);
58659 + 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);
58660 + break;
58661 + case GR_SIG:
58662 + str1 = va_arg(ap, char *);
58663 + voidptr = va_arg(ap, void *);
58664 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58665 + break;
58666 + case GR_SIG2:
58667 + task = va_arg(ap, struct task_struct *);
58668 + cred = __task_cred(task);
58669 + pcred = __task_cred(task->real_parent);
58670 + num1 = va_arg(ap, int);
58671 + 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);
58672 + break;
58673 + case GR_CRASH1:
58674 + task = va_arg(ap, struct task_struct *);
58675 + cred = __task_cred(task);
58676 + pcred = __task_cred(task->real_parent);
58677 + ulong1 = va_arg(ap, unsigned long);
58678 + 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);
58679 + break;
58680 + case GR_CRASH2:
58681 + task = va_arg(ap, struct task_struct *);
58682 + cred = __task_cred(task);
58683 + pcred = __task_cred(task->real_parent);
58684 + ulong1 = va_arg(ap, unsigned long);
58685 + 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);
58686 + break;
58687 + case GR_RWXMAP:
58688 + file = va_arg(ap, struct file *);
58689 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58690 + break;
58691 + case GR_PSACCT:
58692 + {
58693 + unsigned int wday, cday;
58694 + __u8 whr, chr;
58695 + __u8 wmin, cmin;
58696 + __u8 wsec, csec;
58697 + char cur_tty[64] = { 0 };
58698 + char parent_tty[64] = { 0 };
58699 +
58700 + task = va_arg(ap, struct task_struct *);
58701 + wday = va_arg(ap, unsigned int);
58702 + cday = va_arg(ap, unsigned int);
58703 + whr = va_arg(ap, int);
58704 + chr = va_arg(ap, int);
58705 + wmin = va_arg(ap, int);
58706 + cmin = va_arg(ap, int);
58707 + wsec = va_arg(ap, int);
58708 + csec = va_arg(ap, int);
58709 + ulong1 = va_arg(ap, unsigned long);
58710 + cred = __task_cred(task);
58711 + pcred = __task_cred(task->real_parent);
58712 +
58713 + 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);
58714 + }
58715 + break;
58716 + default:
58717 + gr_log_middle(audit, msg, ap);
58718 + }
58719 + va_end(ap);
58720 + // these don't need DEFAULTSECARGS printed on the end
58721 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58722 + gr_log_end(audit, 0);
58723 + else
58724 + gr_log_end(audit, 1);
58725 + END_LOCKS(audit);
58726 +}
58727 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58728 new file mode 100644
58729 index 0000000..6c0416b
58730 --- /dev/null
58731 +++ b/grsecurity/grsec_mem.c
58732 @@ -0,0 +1,33 @@
58733 +#include <linux/kernel.h>
58734 +#include <linux/sched.h>
58735 +#include <linux/mm.h>
58736 +#include <linux/mman.h>
58737 +#include <linux/grinternal.h>
58738 +
58739 +void
58740 +gr_handle_ioperm(void)
58741 +{
58742 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58743 + return;
58744 +}
58745 +
58746 +void
58747 +gr_handle_iopl(void)
58748 +{
58749 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58750 + return;
58751 +}
58752 +
58753 +void
58754 +gr_handle_mem_readwrite(u64 from, u64 to)
58755 +{
58756 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58757 + return;
58758 +}
58759 +
58760 +void
58761 +gr_handle_vm86(void)
58762 +{
58763 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58764 + return;
58765 +}
58766 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58767 new file mode 100644
58768 index 0000000..2131422
58769 --- /dev/null
58770 +++ b/grsecurity/grsec_mount.c
58771 @@ -0,0 +1,62 @@
58772 +#include <linux/kernel.h>
58773 +#include <linux/sched.h>
58774 +#include <linux/mount.h>
58775 +#include <linux/grsecurity.h>
58776 +#include <linux/grinternal.h>
58777 +
58778 +void
58779 +gr_log_remount(const char *devname, const int retval)
58780 +{
58781 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58782 + if (grsec_enable_mount && (retval >= 0))
58783 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58784 +#endif
58785 + return;
58786 +}
58787 +
58788 +void
58789 +gr_log_unmount(const char *devname, const int retval)
58790 +{
58791 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58792 + if (grsec_enable_mount && (retval >= 0))
58793 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58794 +#endif
58795 + return;
58796 +}
58797 +
58798 +void
58799 +gr_log_mount(const char *from, const char *to, const int retval)
58800 +{
58801 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58802 + if (grsec_enable_mount && (retval >= 0))
58803 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58804 +#endif
58805 + return;
58806 +}
58807 +
58808 +int
58809 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58810 +{
58811 +#ifdef CONFIG_GRKERNSEC_ROFS
58812 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58813 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58814 + return -EPERM;
58815 + } else
58816 + return 0;
58817 +#endif
58818 + return 0;
58819 +}
58820 +
58821 +int
58822 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58823 +{
58824 +#ifdef CONFIG_GRKERNSEC_ROFS
58825 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58826 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58827 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58828 + return -EPERM;
58829 + } else
58830 + return 0;
58831 +#endif
58832 + return 0;
58833 +}
58834 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58835 new file mode 100644
58836 index 0000000..a3b12a0
58837 --- /dev/null
58838 +++ b/grsecurity/grsec_pax.c
58839 @@ -0,0 +1,36 @@
58840 +#include <linux/kernel.h>
58841 +#include <linux/sched.h>
58842 +#include <linux/mm.h>
58843 +#include <linux/file.h>
58844 +#include <linux/grinternal.h>
58845 +#include <linux/grsecurity.h>
58846 +
58847 +void
58848 +gr_log_textrel(struct vm_area_struct * vma)
58849 +{
58850 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58851 + if (grsec_enable_audit_textrel)
58852 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58853 +#endif
58854 + return;
58855 +}
58856 +
58857 +void
58858 +gr_log_rwxmmap(struct file *file)
58859 +{
58860 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58861 + if (grsec_enable_log_rwxmaps)
58862 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58863 +#endif
58864 + return;
58865 +}
58866 +
58867 +void
58868 +gr_log_rwxmprotect(struct file *file)
58869 +{
58870 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58871 + if (grsec_enable_log_rwxmaps)
58872 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58873 +#endif
58874 + return;
58875 +}
58876 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58877 new file mode 100644
58878 index 0000000..472c1d6
58879 --- /dev/null
58880 +++ b/grsecurity/grsec_ptrace.c
58881 @@ -0,0 +1,14 @@
58882 +#include <linux/kernel.h>
58883 +#include <linux/sched.h>
58884 +#include <linux/grinternal.h>
58885 +#include <linux/grsecurity.h>
58886 +
58887 +void
58888 +gr_audit_ptrace(struct task_struct *task)
58889 +{
58890 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58891 + if (grsec_enable_audit_ptrace)
58892 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58893 +#endif
58894 + return;
58895 +}
58896 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58897 new file mode 100644
58898 index 0000000..7a5b2de
58899 --- /dev/null
58900 +++ b/grsecurity/grsec_sig.c
58901 @@ -0,0 +1,207 @@
58902 +#include <linux/kernel.h>
58903 +#include <linux/sched.h>
58904 +#include <linux/delay.h>
58905 +#include <linux/grsecurity.h>
58906 +#include <linux/grinternal.h>
58907 +#include <linux/hardirq.h>
58908 +
58909 +char *signames[] = {
58910 + [SIGSEGV] = "Segmentation fault",
58911 + [SIGILL] = "Illegal instruction",
58912 + [SIGABRT] = "Abort",
58913 + [SIGBUS] = "Invalid alignment/Bus error"
58914 +};
58915 +
58916 +void
58917 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58918 +{
58919 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58920 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58921 + (sig == SIGABRT) || (sig == SIGBUS))) {
58922 + if (t->pid == current->pid) {
58923 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58924 + } else {
58925 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58926 + }
58927 + }
58928 +#endif
58929 + return;
58930 +}
58931 +
58932 +int
58933 +gr_handle_signal(const struct task_struct *p, const int sig)
58934 +{
58935 +#ifdef CONFIG_GRKERNSEC
58936 + /* ignore the 0 signal for protected task checks */
58937 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58938 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58939 + return -EPERM;
58940 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58941 + return -EPERM;
58942 + }
58943 +#endif
58944 + return 0;
58945 +}
58946 +
58947 +#ifdef CONFIG_GRKERNSEC
58948 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58949 +
58950 +int gr_fake_force_sig(int sig, struct task_struct *t)
58951 +{
58952 + unsigned long int flags;
58953 + int ret, blocked, ignored;
58954 + struct k_sigaction *action;
58955 +
58956 + spin_lock_irqsave(&t->sighand->siglock, flags);
58957 + action = &t->sighand->action[sig-1];
58958 + ignored = action->sa.sa_handler == SIG_IGN;
58959 + blocked = sigismember(&t->blocked, sig);
58960 + if (blocked || ignored) {
58961 + action->sa.sa_handler = SIG_DFL;
58962 + if (blocked) {
58963 + sigdelset(&t->blocked, sig);
58964 + recalc_sigpending_and_wake(t);
58965 + }
58966 + }
58967 + if (action->sa.sa_handler == SIG_DFL)
58968 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58969 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58970 +
58971 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58972 +
58973 + return ret;
58974 +}
58975 +#endif
58976 +
58977 +#ifdef CONFIG_GRKERNSEC_BRUTE
58978 +#define GR_USER_BAN_TIME (15 * 60)
58979 +
58980 +static int __get_dumpable(unsigned long mm_flags)
58981 +{
58982 + int ret;
58983 +
58984 + ret = mm_flags & MMF_DUMPABLE_MASK;
58985 + return (ret >= 2) ? 2 : ret;
58986 +}
58987 +#endif
58988 +
58989 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58990 +{
58991 +#ifdef CONFIG_GRKERNSEC_BRUTE
58992 + uid_t uid = 0;
58993 +
58994 + if (!grsec_enable_brute)
58995 + return;
58996 +
58997 + rcu_read_lock();
58998 + read_lock(&tasklist_lock);
58999 + read_lock(&grsec_exec_file_lock);
59000 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59001 + p->real_parent->brute = 1;
59002 + else {
59003 + const struct cred *cred = __task_cred(p), *cred2;
59004 + struct task_struct *tsk, *tsk2;
59005 +
59006 + if (!__get_dumpable(mm_flags) && cred->uid) {
59007 + struct user_struct *user;
59008 +
59009 + uid = cred->uid;
59010 +
59011 + /* this is put upon execution past expiration */
59012 + user = find_user(uid);
59013 + if (user == NULL)
59014 + goto unlock;
59015 + user->banned = 1;
59016 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59017 + if (user->ban_expires == ~0UL)
59018 + user->ban_expires--;
59019 +
59020 + do_each_thread(tsk2, tsk) {
59021 + cred2 = __task_cred(tsk);
59022 + if (tsk != p && cred2->uid == uid)
59023 + gr_fake_force_sig(SIGKILL, tsk);
59024 + } while_each_thread(tsk2, tsk);
59025 + }
59026 + }
59027 +unlock:
59028 + read_unlock(&grsec_exec_file_lock);
59029 + read_unlock(&tasklist_lock);
59030 + rcu_read_unlock();
59031 +
59032 + if (uid)
59033 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
59034 +
59035 +#endif
59036 + return;
59037 +}
59038 +
59039 +void gr_handle_brute_check(void)
59040 +{
59041 +#ifdef CONFIG_GRKERNSEC_BRUTE
59042 + if (current->brute)
59043 + msleep(30 * 1000);
59044 +#endif
59045 + return;
59046 +}
59047 +
59048 +void gr_handle_kernel_exploit(void)
59049 +{
59050 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59051 + const struct cred *cred;
59052 + struct task_struct *tsk, *tsk2;
59053 + struct user_struct *user;
59054 + uid_t uid;
59055 +
59056 + if (in_irq() || in_serving_softirq() || in_nmi())
59057 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59058 +
59059 + uid = current_uid();
59060 +
59061 + if (uid == 0)
59062 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59063 + else {
59064 + /* kill all the processes of this user, hold a reference
59065 + to their creds struct, and prevent them from creating
59066 + another process until system reset
59067 + */
59068 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
59069 + /* we intentionally leak this ref */
59070 + user = get_uid(current->cred->user);
59071 + if (user) {
59072 + user->banned = 1;
59073 + user->ban_expires = ~0UL;
59074 + }
59075 +
59076 + read_lock(&tasklist_lock);
59077 + do_each_thread(tsk2, tsk) {
59078 + cred = __task_cred(tsk);
59079 + if (cred->uid == uid)
59080 + gr_fake_force_sig(SIGKILL, tsk);
59081 + } while_each_thread(tsk2, tsk);
59082 + read_unlock(&tasklist_lock);
59083 + }
59084 +#endif
59085 +}
59086 +
59087 +int __gr_process_user_ban(struct user_struct *user)
59088 +{
59089 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59090 + if (unlikely(user->banned)) {
59091 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59092 + user->banned = 0;
59093 + user->ban_expires = 0;
59094 + free_uid(user);
59095 + } else
59096 + return -EPERM;
59097 + }
59098 +#endif
59099 + return 0;
59100 +}
59101 +
59102 +int gr_process_user_ban(void)
59103 +{
59104 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59105 + return __gr_process_user_ban(current->cred->user);
59106 +#endif
59107 + return 0;
59108 +}
59109 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59110 new file mode 100644
59111 index 0000000..4030d57
59112 --- /dev/null
59113 +++ b/grsecurity/grsec_sock.c
59114 @@ -0,0 +1,244 @@
59115 +#include <linux/kernel.h>
59116 +#include <linux/module.h>
59117 +#include <linux/sched.h>
59118 +#include <linux/file.h>
59119 +#include <linux/net.h>
59120 +#include <linux/in.h>
59121 +#include <linux/ip.h>
59122 +#include <net/sock.h>
59123 +#include <net/inet_sock.h>
59124 +#include <linux/grsecurity.h>
59125 +#include <linux/grinternal.h>
59126 +#include <linux/gracl.h>
59127 +
59128 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59129 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59130 +
59131 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59132 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59133 +
59134 +#ifdef CONFIG_UNIX_MODULE
59135 +EXPORT_SYMBOL(gr_acl_handle_unix);
59136 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59137 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59138 +EXPORT_SYMBOL(gr_handle_create);
59139 +#endif
59140 +
59141 +#ifdef CONFIG_GRKERNSEC
59142 +#define gr_conn_table_size 32749
59143 +struct conn_table_entry {
59144 + struct conn_table_entry *next;
59145 + struct signal_struct *sig;
59146 +};
59147 +
59148 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59149 +DEFINE_SPINLOCK(gr_conn_table_lock);
59150 +
59151 +extern const char * gr_socktype_to_name(unsigned char type);
59152 +extern const char * gr_proto_to_name(unsigned char proto);
59153 +extern const char * gr_sockfamily_to_name(unsigned char family);
59154 +
59155 +static __inline__ int
59156 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59157 +{
59158 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59159 +}
59160 +
59161 +static __inline__ int
59162 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59163 + __u16 sport, __u16 dport)
59164 +{
59165 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59166 + sig->gr_sport == sport && sig->gr_dport == dport))
59167 + return 1;
59168 + else
59169 + return 0;
59170 +}
59171 +
59172 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59173 +{
59174 + struct conn_table_entry **match;
59175 + unsigned int index;
59176 +
59177 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59178 + sig->gr_sport, sig->gr_dport,
59179 + gr_conn_table_size);
59180 +
59181 + newent->sig = sig;
59182 +
59183 + match = &gr_conn_table[index];
59184 + newent->next = *match;
59185 + *match = newent;
59186 +
59187 + return;
59188 +}
59189 +
59190 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59191 +{
59192 + struct conn_table_entry *match, *last = NULL;
59193 + unsigned int index;
59194 +
59195 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59196 + sig->gr_sport, sig->gr_dport,
59197 + gr_conn_table_size);
59198 +
59199 + match = gr_conn_table[index];
59200 + while (match && !conn_match(match->sig,
59201 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59202 + sig->gr_dport)) {
59203 + last = match;
59204 + match = match->next;
59205 + }
59206 +
59207 + if (match) {
59208 + if (last)
59209 + last->next = match->next;
59210 + else
59211 + gr_conn_table[index] = NULL;
59212 + kfree(match);
59213 + }
59214 +
59215 + return;
59216 +}
59217 +
59218 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59219 + __u16 sport, __u16 dport)
59220 +{
59221 + struct conn_table_entry *match;
59222 + unsigned int index;
59223 +
59224 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59225 +
59226 + match = gr_conn_table[index];
59227 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59228 + match = match->next;
59229 +
59230 + if (match)
59231 + return match->sig;
59232 + else
59233 + return NULL;
59234 +}
59235 +
59236 +#endif
59237 +
59238 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59239 +{
59240 +#ifdef CONFIG_GRKERNSEC
59241 + struct signal_struct *sig = task->signal;
59242 + struct conn_table_entry *newent;
59243 +
59244 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59245 + if (newent == NULL)
59246 + return;
59247 + /* no bh lock needed since we are called with bh disabled */
59248 + spin_lock(&gr_conn_table_lock);
59249 + gr_del_task_from_ip_table_nolock(sig);
59250 + sig->gr_saddr = inet->inet_rcv_saddr;
59251 + sig->gr_daddr = inet->inet_daddr;
59252 + sig->gr_sport = inet->inet_sport;
59253 + sig->gr_dport = inet->inet_dport;
59254 + gr_add_to_task_ip_table_nolock(sig, newent);
59255 + spin_unlock(&gr_conn_table_lock);
59256 +#endif
59257 + return;
59258 +}
59259 +
59260 +void gr_del_task_from_ip_table(struct task_struct *task)
59261 +{
59262 +#ifdef CONFIG_GRKERNSEC
59263 + spin_lock_bh(&gr_conn_table_lock);
59264 + gr_del_task_from_ip_table_nolock(task->signal);
59265 + spin_unlock_bh(&gr_conn_table_lock);
59266 +#endif
59267 + return;
59268 +}
59269 +
59270 +void
59271 +gr_attach_curr_ip(const struct sock *sk)
59272 +{
59273 +#ifdef CONFIG_GRKERNSEC
59274 + struct signal_struct *p, *set;
59275 + const struct inet_sock *inet = inet_sk(sk);
59276 +
59277 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59278 + return;
59279 +
59280 + set = current->signal;
59281 +
59282 + spin_lock_bh(&gr_conn_table_lock);
59283 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59284 + inet->inet_dport, inet->inet_sport);
59285 + if (unlikely(p != NULL)) {
59286 + set->curr_ip = p->curr_ip;
59287 + set->used_accept = 1;
59288 + gr_del_task_from_ip_table_nolock(p);
59289 + spin_unlock_bh(&gr_conn_table_lock);
59290 + return;
59291 + }
59292 + spin_unlock_bh(&gr_conn_table_lock);
59293 +
59294 + set->curr_ip = inet->inet_daddr;
59295 + set->used_accept = 1;
59296 +#endif
59297 + return;
59298 +}
59299 +
59300 +int
59301 +gr_handle_sock_all(const int family, const int type, const int protocol)
59302 +{
59303 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59304 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59305 + (family != AF_UNIX)) {
59306 + if (family == AF_INET)
59307 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59308 + else
59309 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59310 + return -EACCES;
59311 + }
59312 +#endif
59313 + return 0;
59314 +}
59315 +
59316 +int
59317 +gr_handle_sock_server(const struct sockaddr *sck)
59318 +{
59319 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59320 + if (grsec_enable_socket_server &&
59321 + in_group_p(grsec_socket_server_gid) &&
59322 + sck && (sck->sa_family != AF_UNIX) &&
59323 + (sck->sa_family != AF_LOCAL)) {
59324 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59325 + return -EACCES;
59326 + }
59327 +#endif
59328 + return 0;
59329 +}
59330 +
59331 +int
59332 +gr_handle_sock_server_other(const struct sock *sck)
59333 +{
59334 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59335 + if (grsec_enable_socket_server &&
59336 + in_group_p(grsec_socket_server_gid) &&
59337 + sck && (sck->sk_family != AF_UNIX) &&
59338 + (sck->sk_family != AF_LOCAL)) {
59339 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59340 + return -EACCES;
59341 + }
59342 +#endif
59343 + return 0;
59344 +}
59345 +
59346 +int
59347 +gr_handle_sock_client(const struct sockaddr *sck)
59348 +{
59349 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59350 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59351 + sck && (sck->sa_family != AF_UNIX) &&
59352 + (sck->sa_family != AF_LOCAL)) {
59353 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59354 + return -EACCES;
59355 + }
59356 +#endif
59357 + return 0;
59358 +}
59359 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59360 new file mode 100644
59361 index 0000000..bceef2f
59362 --- /dev/null
59363 +++ b/grsecurity/grsec_sysctl.c
59364 @@ -0,0 +1,442 @@
59365 +#include <linux/kernel.h>
59366 +#include <linux/sched.h>
59367 +#include <linux/sysctl.h>
59368 +#include <linux/grsecurity.h>
59369 +#include <linux/grinternal.h>
59370 +
59371 +int
59372 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59373 +{
59374 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59375 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59376 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59377 + return -EACCES;
59378 + }
59379 +#endif
59380 + return 0;
59381 +}
59382 +
59383 +#ifdef CONFIG_GRKERNSEC_ROFS
59384 +static int __maybe_unused one = 1;
59385 +#endif
59386 +
59387 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59388 +struct ctl_table grsecurity_table[] = {
59389 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59390 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59391 +#ifdef CONFIG_GRKERNSEC_IO
59392 + {
59393 + .procname = "disable_priv_io",
59394 + .data = &grsec_disable_privio,
59395 + .maxlen = sizeof(int),
59396 + .mode = 0600,
59397 + .proc_handler = &proc_dointvec,
59398 + },
59399 +#endif
59400 +#endif
59401 +#ifdef CONFIG_GRKERNSEC_LINK
59402 + {
59403 + .procname = "linking_restrictions",
59404 + .data = &grsec_enable_link,
59405 + .maxlen = sizeof(int),
59406 + .mode = 0600,
59407 + .proc_handler = &proc_dointvec,
59408 + },
59409 +#endif
59410 +#ifdef CONFIG_GRKERNSEC_BRUTE
59411 + {
59412 + .procname = "deter_bruteforce",
59413 + .data = &grsec_enable_brute,
59414 + .maxlen = sizeof(int),
59415 + .mode = 0600,
59416 + .proc_handler = &proc_dointvec,
59417 + },
59418 +#endif
59419 +#ifdef CONFIG_GRKERNSEC_FIFO
59420 + {
59421 + .procname = "fifo_restrictions",
59422 + .data = &grsec_enable_fifo,
59423 + .maxlen = sizeof(int),
59424 + .mode = 0600,
59425 + .proc_handler = &proc_dointvec,
59426 + },
59427 +#endif
59428 +#ifdef CONFIG_GRKERNSEC_SETXID
59429 + {
59430 + .procname = "consistent_setxid",
59431 + .data = &grsec_enable_setxid,
59432 + .maxlen = sizeof(int),
59433 + .mode = 0600,
59434 + .proc_handler = &proc_dointvec,
59435 + },
59436 +#endif
59437 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59438 + {
59439 + .procname = "ip_blackhole",
59440 + .data = &grsec_enable_blackhole,
59441 + .maxlen = sizeof(int),
59442 + .mode = 0600,
59443 + .proc_handler = &proc_dointvec,
59444 + },
59445 + {
59446 + .procname = "lastack_retries",
59447 + .data = &grsec_lastack_retries,
59448 + .maxlen = sizeof(int),
59449 + .mode = 0600,
59450 + .proc_handler = &proc_dointvec,
59451 + },
59452 +#endif
59453 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59454 + {
59455 + .procname = "exec_logging",
59456 + .data = &grsec_enable_execlog,
59457 + .maxlen = sizeof(int),
59458 + .mode = 0600,
59459 + .proc_handler = &proc_dointvec,
59460 + },
59461 +#endif
59462 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59463 + {
59464 + .procname = "rwxmap_logging",
59465 + .data = &grsec_enable_log_rwxmaps,
59466 + .maxlen = sizeof(int),
59467 + .mode = 0600,
59468 + .proc_handler = &proc_dointvec,
59469 + },
59470 +#endif
59471 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59472 + {
59473 + .procname = "signal_logging",
59474 + .data = &grsec_enable_signal,
59475 + .maxlen = sizeof(int),
59476 + .mode = 0600,
59477 + .proc_handler = &proc_dointvec,
59478 + },
59479 +#endif
59480 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59481 + {
59482 + .procname = "forkfail_logging",
59483 + .data = &grsec_enable_forkfail,
59484 + .maxlen = sizeof(int),
59485 + .mode = 0600,
59486 + .proc_handler = &proc_dointvec,
59487 + },
59488 +#endif
59489 +#ifdef CONFIG_GRKERNSEC_TIME
59490 + {
59491 + .procname = "timechange_logging",
59492 + .data = &grsec_enable_time,
59493 + .maxlen = sizeof(int),
59494 + .mode = 0600,
59495 + .proc_handler = &proc_dointvec,
59496 + },
59497 +#endif
59498 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59499 + {
59500 + .procname = "chroot_deny_shmat",
59501 + .data = &grsec_enable_chroot_shmat,
59502 + .maxlen = sizeof(int),
59503 + .mode = 0600,
59504 + .proc_handler = &proc_dointvec,
59505 + },
59506 +#endif
59507 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59508 + {
59509 + .procname = "chroot_deny_unix",
59510 + .data = &grsec_enable_chroot_unix,
59511 + .maxlen = sizeof(int),
59512 + .mode = 0600,
59513 + .proc_handler = &proc_dointvec,
59514 + },
59515 +#endif
59516 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59517 + {
59518 + .procname = "chroot_deny_mount",
59519 + .data = &grsec_enable_chroot_mount,
59520 + .maxlen = sizeof(int),
59521 + .mode = 0600,
59522 + .proc_handler = &proc_dointvec,
59523 + },
59524 +#endif
59525 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59526 + {
59527 + .procname = "chroot_deny_fchdir",
59528 + .data = &grsec_enable_chroot_fchdir,
59529 + .maxlen = sizeof(int),
59530 + .mode = 0600,
59531 + .proc_handler = &proc_dointvec,
59532 + },
59533 +#endif
59534 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59535 + {
59536 + .procname = "chroot_deny_chroot",
59537 + .data = &grsec_enable_chroot_double,
59538 + .maxlen = sizeof(int),
59539 + .mode = 0600,
59540 + .proc_handler = &proc_dointvec,
59541 + },
59542 +#endif
59543 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59544 + {
59545 + .procname = "chroot_deny_pivot",
59546 + .data = &grsec_enable_chroot_pivot,
59547 + .maxlen = sizeof(int),
59548 + .mode = 0600,
59549 + .proc_handler = &proc_dointvec,
59550 + },
59551 +#endif
59552 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59553 + {
59554 + .procname = "chroot_enforce_chdir",
59555 + .data = &grsec_enable_chroot_chdir,
59556 + .maxlen = sizeof(int),
59557 + .mode = 0600,
59558 + .proc_handler = &proc_dointvec,
59559 + },
59560 +#endif
59561 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59562 + {
59563 + .procname = "chroot_deny_chmod",
59564 + .data = &grsec_enable_chroot_chmod,
59565 + .maxlen = sizeof(int),
59566 + .mode = 0600,
59567 + .proc_handler = &proc_dointvec,
59568 + },
59569 +#endif
59570 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59571 + {
59572 + .procname = "chroot_deny_mknod",
59573 + .data = &grsec_enable_chroot_mknod,
59574 + .maxlen = sizeof(int),
59575 + .mode = 0600,
59576 + .proc_handler = &proc_dointvec,
59577 + },
59578 +#endif
59579 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59580 + {
59581 + .procname = "chroot_restrict_nice",
59582 + .data = &grsec_enable_chroot_nice,
59583 + .maxlen = sizeof(int),
59584 + .mode = 0600,
59585 + .proc_handler = &proc_dointvec,
59586 + },
59587 +#endif
59588 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59589 + {
59590 + .procname = "chroot_execlog",
59591 + .data = &grsec_enable_chroot_execlog,
59592 + .maxlen = sizeof(int),
59593 + .mode = 0600,
59594 + .proc_handler = &proc_dointvec,
59595 + },
59596 +#endif
59597 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59598 + {
59599 + .procname = "chroot_caps",
59600 + .data = &grsec_enable_chroot_caps,
59601 + .maxlen = sizeof(int),
59602 + .mode = 0600,
59603 + .proc_handler = &proc_dointvec,
59604 + },
59605 +#endif
59606 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59607 + {
59608 + .procname = "chroot_deny_sysctl",
59609 + .data = &grsec_enable_chroot_sysctl,
59610 + .maxlen = sizeof(int),
59611 + .mode = 0600,
59612 + .proc_handler = &proc_dointvec,
59613 + },
59614 +#endif
59615 +#ifdef CONFIG_GRKERNSEC_TPE
59616 + {
59617 + .procname = "tpe",
59618 + .data = &grsec_enable_tpe,
59619 + .maxlen = sizeof(int),
59620 + .mode = 0600,
59621 + .proc_handler = &proc_dointvec,
59622 + },
59623 + {
59624 + .procname = "tpe_gid",
59625 + .data = &grsec_tpe_gid,
59626 + .maxlen = sizeof(int),
59627 + .mode = 0600,
59628 + .proc_handler = &proc_dointvec,
59629 + },
59630 +#endif
59631 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59632 + {
59633 + .procname = "tpe_invert",
59634 + .data = &grsec_enable_tpe_invert,
59635 + .maxlen = sizeof(int),
59636 + .mode = 0600,
59637 + .proc_handler = &proc_dointvec,
59638 + },
59639 +#endif
59640 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59641 + {
59642 + .procname = "tpe_restrict_all",
59643 + .data = &grsec_enable_tpe_all,
59644 + .maxlen = sizeof(int),
59645 + .mode = 0600,
59646 + .proc_handler = &proc_dointvec,
59647 + },
59648 +#endif
59649 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59650 + {
59651 + .procname = "socket_all",
59652 + .data = &grsec_enable_socket_all,
59653 + .maxlen = sizeof(int),
59654 + .mode = 0600,
59655 + .proc_handler = &proc_dointvec,
59656 + },
59657 + {
59658 + .procname = "socket_all_gid",
59659 + .data = &grsec_socket_all_gid,
59660 + .maxlen = sizeof(int),
59661 + .mode = 0600,
59662 + .proc_handler = &proc_dointvec,
59663 + },
59664 +#endif
59665 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59666 + {
59667 + .procname = "socket_client",
59668 + .data = &grsec_enable_socket_client,
59669 + .maxlen = sizeof(int),
59670 + .mode = 0600,
59671 + .proc_handler = &proc_dointvec,
59672 + },
59673 + {
59674 + .procname = "socket_client_gid",
59675 + .data = &grsec_socket_client_gid,
59676 + .maxlen = sizeof(int),
59677 + .mode = 0600,
59678 + .proc_handler = &proc_dointvec,
59679 + },
59680 +#endif
59681 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59682 + {
59683 + .procname = "socket_server",
59684 + .data = &grsec_enable_socket_server,
59685 + .maxlen = sizeof(int),
59686 + .mode = 0600,
59687 + .proc_handler = &proc_dointvec,
59688 + },
59689 + {
59690 + .procname = "socket_server_gid",
59691 + .data = &grsec_socket_server_gid,
59692 + .maxlen = sizeof(int),
59693 + .mode = 0600,
59694 + .proc_handler = &proc_dointvec,
59695 + },
59696 +#endif
59697 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59698 + {
59699 + .procname = "audit_group",
59700 + .data = &grsec_enable_group,
59701 + .maxlen = sizeof(int),
59702 + .mode = 0600,
59703 + .proc_handler = &proc_dointvec,
59704 + },
59705 + {
59706 + .procname = "audit_gid",
59707 + .data = &grsec_audit_gid,
59708 + .maxlen = sizeof(int),
59709 + .mode = 0600,
59710 + .proc_handler = &proc_dointvec,
59711 + },
59712 +#endif
59713 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59714 + {
59715 + .procname = "audit_chdir",
59716 + .data = &grsec_enable_chdir,
59717 + .maxlen = sizeof(int),
59718 + .mode = 0600,
59719 + .proc_handler = &proc_dointvec,
59720 + },
59721 +#endif
59722 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59723 + {
59724 + .procname = "audit_mount",
59725 + .data = &grsec_enable_mount,
59726 + .maxlen = sizeof(int),
59727 + .mode = 0600,
59728 + .proc_handler = &proc_dointvec,
59729 + },
59730 +#endif
59731 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59732 + {
59733 + .procname = "audit_textrel",
59734 + .data = &grsec_enable_audit_textrel,
59735 + .maxlen = sizeof(int),
59736 + .mode = 0600,
59737 + .proc_handler = &proc_dointvec,
59738 + },
59739 +#endif
59740 +#ifdef CONFIG_GRKERNSEC_DMESG
59741 + {
59742 + .procname = "dmesg",
59743 + .data = &grsec_enable_dmesg,
59744 + .maxlen = sizeof(int),
59745 + .mode = 0600,
59746 + .proc_handler = &proc_dointvec,
59747 + },
59748 +#endif
59749 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59750 + {
59751 + .procname = "chroot_findtask",
59752 + .data = &grsec_enable_chroot_findtask,
59753 + .maxlen = sizeof(int),
59754 + .mode = 0600,
59755 + .proc_handler = &proc_dointvec,
59756 + },
59757 +#endif
59758 +#ifdef CONFIG_GRKERNSEC_RESLOG
59759 + {
59760 + .procname = "resource_logging",
59761 + .data = &grsec_resource_logging,
59762 + .maxlen = sizeof(int),
59763 + .mode = 0600,
59764 + .proc_handler = &proc_dointvec,
59765 + },
59766 +#endif
59767 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59768 + {
59769 + .procname = "audit_ptrace",
59770 + .data = &grsec_enable_audit_ptrace,
59771 + .maxlen = sizeof(int),
59772 + .mode = 0600,
59773 + .proc_handler = &proc_dointvec,
59774 + },
59775 +#endif
59776 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59777 + {
59778 + .procname = "harden_ptrace",
59779 + .data = &grsec_enable_harden_ptrace,
59780 + .maxlen = sizeof(int),
59781 + .mode = 0600,
59782 + .proc_handler = &proc_dointvec,
59783 + },
59784 +#endif
59785 + {
59786 + .procname = "grsec_lock",
59787 + .data = &grsec_lock,
59788 + .maxlen = sizeof(int),
59789 + .mode = 0600,
59790 + .proc_handler = &proc_dointvec,
59791 + },
59792 +#endif
59793 +#ifdef CONFIG_GRKERNSEC_ROFS
59794 + {
59795 + .procname = "romount_protect",
59796 + .data = &grsec_enable_rofs,
59797 + .maxlen = sizeof(int),
59798 + .mode = 0600,
59799 + .proc_handler = &proc_dointvec_minmax,
59800 + .extra1 = &one,
59801 + .extra2 = &one,
59802 + },
59803 +#endif
59804 + { }
59805 +};
59806 +#endif
59807 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59808 new file mode 100644
59809 index 0000000..0dc13c3
59810 --- /dev/null
59811 +++ b/grsecurity/grsec_time.c
59812 @@ -0,0 +1,16 @@
59813 +#include <linux/kernel.h>
59814 +#include <linux/sched.h>
59815 +#include <linux/grinternal.h>
59816 +#include <linux/module.h>
59817 +
59818 +void
59819 +gr_log_timechange(void)
59820 +{
59821 +#ifdef CONFIG_GRKERNSEC_TIME
59822 + if (grsec_enable_time)
59823 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59824 +#endif
59825 + return;
59826 +}
59827 +
59828 +EXPORT_SYMBOL(gr_log_timechange);
59829 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59830 new file mode 100644
59831 index 0000000..4a78774
59832 --- /dev/null
59833 +++ b/grsecurity/grsec_tpe.c
59834 @@ -0,0 +1,39 @@
59835 +#include <linux/kernel.h>
59836 +#include <linux/sched.h>
59837 +#include <linux/file.h>
59838 +#include <linux/fs.h>
59839 +#include <linux/grinternal.h>
59840 +
59841 +extern int gr_acl_tpe_check(void);
59842 +
59843 +int
59844 +gr_tpe_allow(const struct file *file)
59845 +{
59846 +#ifdef CONFIG_GRKERNSEC
59847 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59848 + const struct cred *cred = current_cred();
59849 +
59850 + if (cred->uid && ((grsec_enable_tpe &&
59851 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59852 + ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
59853 + (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
59854 +#else
59855 + in_group_p(grsec_tpe_gid)
59856 +#endif
59857 + ) || gr_acl_tpe_check()) &&
59858 + (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
59859 + (inode->i_mode & S_IWOTH))))) {
59860 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59861 + return 0;
59862 + }
59863 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59864 + if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
59865 + ((inode->i_uid && (inode->i_uid != cred->uid)) ||
59866 + (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
59867 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59868 + return 0;
59869 + }
59870 +#endif
59871 +#endif
59872 + return 1;
59873 +}
59874 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59875 new file mode 100644
59876 index 0000000..9f7b1ac
59877 --- /dev/null
59878 +++ b/grsecurity/grsum.c
59879 @@ -0,0 +1,61 @@
59880 +#include <linux/err.h>
59881 +#include <linux/kernel.h>
59882 +#include <linux/sched.h>
59883 +#include <linux/mm.h>
59884 +#include <linux/scatterlist.h>
59885 +#include <linux/crypto.h>
59886 +#include <linux/gracl.h>
59887 +
59888 +
59889 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59890 +#error "crypto and sha256 must be built into the kernel"
59891 +#endif
59892 +
59893 +int
59894 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59895 +{
59896 + char *p;
59897 + struct crypto_hash *tfm;
59898 + struct hash_desc desc;
59899 + struct scatterlist sg;
59900 + unsigned char temp_sum[GR_SHA_LEN];
59901 + volatile int retval = 0;
59902 + volatile int dummy = 0;
59903 + unsigned int i;
59904 +
59905 + sg_init_table(&sg, 1);
59906 +
59907 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59908 + if (IS_ERR(tfm)) {
59909 + /* should never happen, since sha256 should be built in */
59910 + return 1;
59911 + }
59912 +
59913 + desc.tfm = tfm;
59914 + desc.flags = 0;
59915 +
59916 + crypto_hash_init(&desc);
59917 +
59918 + p = salt;
59919 + sg_set_buf(&sg, p, GR_SALT_LEN);
59920 + crypto_hash_update(&desc, &sg, sg.length);
59921 +
59922 + p = entry->pw;
59923 + sg_set_buf(&sg, p, strlen(p));
59924 +
59925 + crypto_hash_update(&desc, &sg, sg.length);
59926 +
59927 + crypto_hash_final(&desc, temp_sum);
59928 +
59929 + memset(entry->pw, 0, GR_PW_LEN);
59930 +
59931 + for (i = 0; i < GR_SHA_LEN; i++)
59932 + if (sum[i] != temp_sum[i])
59933 + retval = 1;
59934 + else
59935 + dummy = 1; // waste a cycle
59936 +
59937 + crypto_free_hash(tfm);
59938 +
59939 + return retval;
59940 +}
59941 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59942 index 6cd5b64..f620d2d 100644
59943 --- a/include/acpi/acpi_bus.h
59944 +++ b/include/acpi/acpi_bus.h
59945 @@ -107,7 +107,7 @@ struct acpi_device_ops {
59946 acpi_op_bind bind;
59947 acpi_op_unbind unbind;
59948 acpi_op_notify notify;
59949 -};
59950 +} __no_const;
59951
59952 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59953
59954 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59955 index b7babf0..71e4e74 100644
59956 --- a/include/asm-generic/atomic-long.h
59957 +++ b/include/asm-generic/atomic-long.h
59958 @@ -22,6 +22,12 @@
59959
59960 typedef atomic64_t atomic_long_t;
59961
59962 +#ifdef CONFIG_PAX_REFCOUNT
59963 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59964 +#else
59965 +typedef atomic64_t atomic_long_unchecked_t;
59966 +#endif
59967 +
59968 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59969
59970 static inline long atomic_long_read(atomic_long_t *l)
59971 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59972 return (long)atomic64_read(v);
59973 }
59974
59975 +#ifdef CONFIG_PAX_REFCOUNT
59976 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59977 +{
59978 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59979 +
59980 + return (long)atomic64_read_unchecked(v);
59981 +}
59982 +#endif
59983 +
59984 static inline void atomic_long_set(atomic_long_t *l, long i)
59985 {
59986 atomic64_t *v = (atomic64_t *)l;
59987 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59988 atomic64_set(v, i);
59989 }
59990
59991 +#ifdef CONFIG_PAX_REFCOUNT
59992 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59993 +{
59994 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59995 +
59996 + atomic64_set_unchecked(v, i);
59997 +}
59998 +#endif
59999 +
60000 static inline void atomic_long_inc(atomic_long_t *l)
60001 {
60002 atomic64_t *v = (atomic64_t *)l;
60003 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60004 atomic64_inc(v);
60005 }
60006
60007 +#ifdef CONFIG_PAX_REFCOUNT
60008 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60009 +{
60010 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60011 +
60012 + atomic64_inc_unchecked(v);
60013 +}
60014 +#endif
60015 +
60016 static inline void atomic_long_dec(atomic_long_t *l)
60017 {
60018 atomic64_t *v = (atomic64_t *)l;
60019 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60020 atomic64_dec(v);
60021 }
60022
60023 +#ifdef CONFIG_PAX_REFCOUNT
60024 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60025 +{
60026 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60027 +
60028 + atomic64_dec_unchecked(v);
60029 +}
60030 +#endif
60031 +
60032 static inline void atomic_long_add(long i, atomic_long_t *l)
60033 {
60034 atomic64_t *v = (atomic64_t *)l;
60035 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60036 atomic64_add(i, v);
60037 }
60038
60039 +#ifdef CONFIG_PAX_REFCOUNT
60040 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60041 +{
60042 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60043 +
60044 + atomic64_add_unchecked(i, v);
60045 +}
60046 +#endif
60047 +
60048 static inline void atomic_long_sub(long i, atomic_long_t *l)
60049 {
60050 atomic64_t *v = (atomic64_t *)l;
60051 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60052 atomic64_sub(i, v);
60053 }
60054
60055 +#ifdef CONFIG_PAX_REFCOUNT
60056 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60057 +{
60058 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60059 +
60060 + atomic64_sub_unchecked(i, v);
60061 +}
60062 +#endif
60063 +
60064 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60065 {
60066 atomic64_t *v = (atomic64_t *)l;
60067 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60068 return (long)atomic64_inc_return(v);
60069 }
60070
60071 +#ifdef CONFIG_PAX_REFCOUNT
60072 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60073 +{
60074 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60075 +
60076 + return (long)atomic64_inc_return_unchecked(v);
60077 +}
60078 +#endif
60079 +
60080 static inline long atomic_long_dec_return(atomic_long_t *l)
60081 {
60082 atomic64_t *v = (atomic64_t *)l;
60083 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60084
60085 typedef atomic_t atomic_long_t;
60086
60087 +#ifdef CONFIG_PAX_REFCOUNT
60088 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60089 +#else
60090 +typedef atomic_t atomic_long_unchecked_t;
60091 +#endif
60092 +
60093 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60094 static inline long atomic_long_read(atomic_long_t *l)
60095 {
60096 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60097 return (long)atomic_read(v);
60098 }
60099
60100 +#ifdef CONFIG_PAX_REFCOUNT
60101 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60102 +{
60103 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60104 +
60105 + return (long)atomic_read_unchecked(v);
60106 +}
60107 +#endif
60108 +
60109 static inline void atomic_long_set(atomic_long_t *l, long i)
60110 {
60111 atomic_t *v = (atomic_t *)l;
60112 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60113 atomic_set(v, i);
60114 }
60115
60116 +#ifdef CONFIG_PAX_REFCOUNT
60117 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60118 +{
60119 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60120 +
60121 + atomic_set_unchecked(v, i);
60122 +}
60123 +#endif
60124 +
60125 static inline void atomic_long_inc(atomic_long_t *l)
60126 {
60127 atomic_t *v = (atomic_t *)l;
60128 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60129 atomic_inc(v);
60130 }
60131
60132 +#ifdef CONFIG_PAX_REFCOUNT
60133 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60134 +{
60135 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60136 +
60137 + atomic_inc_unchecked(v);
60138 +}
60139 +#endif
60140 +
60141 static inline void atomic_long_dec(atomic_long_t *l)
60142 {
60143 atomic_t *v = (atomic_t *)l;
60144 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60145 atomic_dec(v);
60146 }
60147
60148 +#ifdef CONFIG_PAX_REFCOUNT
60149 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60150 +{
60151 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60152 +
60153 + atomic_dec_unchecked(v);
60154 +}
60155 +#endif
60156 +
60157 static inline void atomic_long_add(long i, atomic_long_t *l)
60158 {
60159 atomic_t *v = (atomic_t *)l;
60160 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60161 atomic_add(i, v);
60162 }
60163
60164 +#ifdef CONFIG_PAX_REFCOUNT
60165 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60166 +{
60167 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60168 +
60169 + atomic_add_unchecked(i, v);
60170 +}
60171 +#endif
60172 +
60173 static inline void atomic_long_sub(long i, atomic_long_t *l)
60174 {
60175 atomic_t *v = (atomic_t *)l;
60176 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60177 atomic_sub(i, v);
60178 }
60179
60180 +#ifdef CONFIG_PAX_REFCOUNT
60181 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60182 +{
60183 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60184 +
60185 + atomic_sub_unchecked(i, v);
60186 +}
60187 +#endif
60188 +
60189 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60190 {
60191 atomic_t *v = (atomic_t *)l;
60192 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60193 return (long)atomic_inc_return(v);
60194 }
60195
60196 +#ifdef CONFIG_PAX_REFCOUNT
60197 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60198 +{
60199 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60200 +
60201 + return (long)atomic_inc_return_unchecked(v);
60202 +}
60203 +#endif
60204 +
60205 static inline long atomic_long_dec_return(atomic_long_t *l)
60206 {
60207 atomic_t *v = (atomic_t *)l;
60208 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60209
60210 #endif /* BITS_PER_LONG == 64 */
60211
60212 +#ifdef CONFIG_PAX_REFCOUNT
60213 +static inline void pax_refcount_needs_these_functions(void)
60214 +{
60215 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60216 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60217 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60218 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60219 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60220 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60221 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60222 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60223 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60224 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60225 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60226 +
60227 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60228 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60229 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60230 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60231 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60232 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60233 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60234 +}
60235 +#else
60236 +#define atomic_read_unchecked(v) atomic_read(v)
60237 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60238 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60239 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60240 +#define atomic_inc_unchecked(v) atomic_inc(v)
60241 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60242 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60243 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60244 +#define atomic_dec_unchecked(v) atomic_dec(v)
60245 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60246 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60247 +
60248 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60249 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60250 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60251 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60252 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60253 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60254 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60255 +#endif
60256 +
60257 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60258 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60259 index b18ce4f..2ee2843 100644
60260 --- a/include/asm-generic/atomic64.h
60261 +++ b/include/asm-generic/atomic64.h
60262 @@ -16,6 +16,8 @@ typedef struct {
60263 long long counter;
60264 } atomic64_t;
60265
60266 +typedef atomic64_t atomic64_unchecked_t;
60267 +
60268 #define ATOMIC64_INIT(i) { (i) }
60269
60270 extern long long atomic64_read(const atomic64_t *v);
60271 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60272 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60273 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60274
60275 +#define atomic64_read_unchecked(v) atomic64_read(v)
60276 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60277 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60278 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60279 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60280 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60281 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60282 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60283 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60284 +
60285 #endif /* _ASM_GENERIC_ATOMIC64_H */
60286 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60287 index 1bfcfe5..e04c5c9 100644
60288 --- a/include/asm-generic/cache.h
60289 +++ b/include/asm-generic/cache.h
60290 @@ -6,7 +6,7 @@
60291 * cache lines need to provide their own cache.h.
60292 */
60293
60294 -#define L1_CACHE_SHIFT 5
60295 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60296 +#define L1_CACHE_SHIFT 5UL
60297 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60298
60299 #endif /* __ASM_GENERIC_CACHE_H */
60300 diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
60301 index 1ca3efc..e3dc852 100644
60302 --- a/include/asm-generic/int-l64.h
60303 +++ b/include/asm-generic/int-l64.h
60304 @@ -46,6 +46,8 @@ typedef unsigned int u32;
60305 typedef signed long s64;
60306 typedef unsigned long u64;
60307
60308 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
60309 +
60310 #define S8_C(x) x
60311 #define U8_C(x) x ## U
60312 #define S16_C(x) x
60313 diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
60314 index f394147..b6152b9 100644
60315 --- a/include/asm-generic/int-ll64.h
60316 +++ b/include/asm-generic/int-ll64.h
60317 @@ -51,6 +51,8 @@ typedef unsigned int u32;
60318 typedef signed long long s64;
60319 typedef unsigned long long u64;
60320
60321 +typedef unsigned long long intoverflow_t;
60322 +
60323 #define S8_C(x) x
60324 #define U8_C(x) x ## U
60325 #define S16_C(x) x
60326 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60327 index 0232ccb..13d9165 100644
60328 --- a/include/asm-generic/kmap_types.h
60329 +++ b/include/asm-generic/kmap_types.h
60330 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60331 KMAP_D(17) KM_NMI,
60332 KMAP_D(18) KM_NMI_PTE,
60333 KMAP_D(19) KM_KDB,
60334 +KMAP_D(20) KM_CLEARPAGE,
60335 /*
60336 * Remember to update debug_kmap_atomic() when adding new kmap types!
60337 */
60338 -KMAP_D(20) KM_TYPE_NR
60339 +KMAP_D(21) KM_TYPE_NR
60340 };
60341
60342 #undef KMAP_D
60343 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60344 index 725612b..9cc513a 100644
60345 --- a/include/asm-generic/pgtable-nopmd.h
60346 +++ b/include/asm-generic/pgtable-nopmd.h
60347 @@ -1,14 +1,19 @@
60348 #ifndef _PGTABLE_NOPMD_H
60349 #define _PGTABLE_NOPMD_H
60350
60351 -#ifndef __ASSEMBLY__
60352 -
60353 #include <asm-generic/pgtable-nopud.h>
60354
60355 -struct mm_struct;
60356 -
60357 #define __PAGETABLE_PMD_FOLDED
60358
60359 +#define PMD_SHIFT PUD_SHIFT
60360 +#define PTRS_PER_PMD 1
60361 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60362 +#define PMD_MASK (~(PMD_SIZE-1))
60363 +
60364 +#ifndef __ASSEMBLY__
60365 +
60366 +struct mm_struct;
60367 +
60368 /*
60369 * Having the pmd type consist of a pud gets the size right, and allows
60370 * us to conceptually access the pud entry that this pmd is folded into
60371 @@ -16,11 +21,6 @@ struct mm_struct;
60372 */
60373 typedef struct { pud_t pud; } pmd_t;
60374
60375 -#define PMD_SHIFT PUD_SHIFT
60376 -#define PTRS_PER_PMD 1
60377 -#define PMD_SIZE (1UL << PMD_SHIFT)
60378 -#define PMD_MASK (~(PMD_SIZE-1))
60379 -
60380 /*
60381 * The "pud_xxx()" functions here are trivial for a folded two-level
60382 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60383 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60384 index 810431d..ccc3638 100644
60385 --- a/include/asm-generic/pgtable-nopud.h
60386 +++ b/include/asm-generic/pgtable-nopud.h
60387 @@ -1,10 +1,15 @@
60388 #ifndef _PGTABLE_NOPUD_H
60389 #define _PGTABLE_NOPUD_H
60390
60391 -#ifndef __ASSEMBLY__
60392 -
60393 #define __PAGETABLE_PUD_FOLDED
60394
60395 +#define PUD_SHIFT PGDIR_SHIFT
60396 +#define PTRS_PER_PUD 1
60397 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60398 +#define PUD_MASK (~(PUD_SIZE-1))
60399 +
60400 +#ifndef __ASSEMBLY__
60401 +
60402 /*
60403 * Having the pud type consist of a pgd gets the size right, and allows
60404 * us to conceptually access the pgd entry that this pud is folded into
60405 @@ -12,11 +17,6 @@
60406 */
60407 typedef struct { pgd_t pgd; } pud_t;
60408
60409 -#define PUD_SHIFT PGDIR_SHIFT
60410 -#define PTRS_PER_PUD 1
60411 -#define PUD_SIZE (1UL << PUD_SHIFT)
60412 -#define PUD_MASK (~(PUD_SIZE-1))
60413 -
60414 /*
60415 * The "pgd_xxx()" functions here are trivial for a folded two-level
60416 * setup: the pud is never bad, and a pud always exists (as it's folded
60417 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60418 index 76bff2b..c7a14e2 100644
60419 --- a/include/asm-generic/pgtable.h
60420 +++ b/include/asm-generic/pgtable.h
60421 @@ -443,6 +443,14 @@ static inline int pmd_write(pmd_t pmd)
60422 #endif /* __HAVE_ARCH_PMD_WRITE */
60423 #endif
60424
60425 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60426 +static inline unsigned long pax_open_kernel(void) { return 0; }
60427 +#endif
60428 +
60429 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60430 +static inline unsigned long pax_close_kernel(void) { return 0; }
60431 +#endif
60432 +
60433 #endif /* !__ASSEMBLY__ */
60434
60435 #endif /* _ASM_GENERIC_PGTABLE_H */
60436 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60437 index db22d13..1f2e3e1 100644
60438 --- a/include/asm-generic/vmlinux.lds.h
60439 +++ b/include/asm-generic/vmlinux.lds.h
60440 @@ -217,6 +217,7 @@
60441 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60442 VMLINUX_SYMBOL(__start_rodata) = .; \
60443 *(.rodata) *(.rodata.*) \
60444 + *(.data..read_only) \
60445 *(__vermagic) /* Kernel version magic */ \
60446 . = ALIGN(8); \
60447 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60448 @@ -723,17 +724,18 @@
60449 * section in the linker script will go there too. @phdr should have
60450 * a leading colon.
60451 *
60452 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60453 + * Note that this macros defines per_cpu_load as an absolute symbol.
60454 * If there is no need to put the percpu section at a predetermined
60455 * address, use PERCPU_SECTION.
60456 */
60457 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60458 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60459 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60460 + per_cpu_load = .; \
60461 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60462 - LOAD_OFFSET) { \
60463 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60464 PERCPU_INPUT(cacheline) \
60465 } phdr \
60466 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60467 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60468
60469 /**
60470 * PERCPU_SECTION - define output section for percpu area, simple version
60471 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60472 index 9b7c2bb..76b7d1e 100644
60473 --- a/include/drm/drmP.h
60474 +++ b/include/drm/drmP.h
60475 @@ -73,6 +73,7 @@
60476 #include <linux/workqueue.h>
60477 #include <linux/poll.h>
60478 #include <asm/pgalloc.h>
60479 +#include <asm/local.h>
60480 #include "drm.h"
60481
60482 #include <linux/idr.h>
60483 @@ -1035,7 +1036,7 @@ struct drm_device {
60484
60485 /** \name Usage Counters */
60486 /*@{ */
60487 - int open_count; /**< Outstanding files open */
60488 + local_t open_count; /**< Outstanding files open */
60489 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60490 atomic_t vma_count; /**< Outstanding vma areas open */
60491 int buf_use; /**< Buffers in use -- cannot alloc */
60492 @@ -1046,7 +1047,7 @@ struct drm_device {
60493 /*@{ */
60494 unsigned long counters;
60495 enum drm_stat_type types[15];
60496 - atomic_t counts[15];
60497 + atomic_unchecked_t counts[15];
60498 /*@} */
60499
60500 struct list_head filelist;
60501 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60502 index 73b0712..0b7ef2f 100644
60503 --- a/include/drm/drm_crtc_helper.h
60504 +++ b/include/drm/drm_crtc_helper.h
60505 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
60506
60507 /* disable crtc when not in use - more explicit than dpms off */
60508 void (*disable)(struct drm_crtc *crtc);
60509 -};
60510 +} __no_const;
60511
60512 struct drm_encoder_helper_funcs {
60513 void (*dpms)(struct drm_encoder *encoder, int mode);
60514 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
60515 struct drm_connector *connector);
60516 /* disable encoder when not in use - more explicit than dpms off */
60517 void (*disable)(struct drm_encoder *encoder);
60518 -};
60519 +} __no_const;
60520
60521 struct drm_connector_helper_funcs {
60522 int (*get_modes)(struct drm_connector *connector);
60523 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60524 index 26c1f78..6722682 100644
60525 --- a/include/drm/ttm/ttm_memory.h
60526 +++ b/include/drm/ttm/ttm_memory.h
60527 @@ -47,7 +47,7 @@
60528
60529 struct ttm_mem_shrink {
60530 int (*do_shrink) (struct ttm_mem_shrink *);
60531 -};
60532 +} __no_const;
60533
60534 /**
60535 * struct ttm_mem_global - Global memory accounting structure.
60536 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60537 index e86dfca..40cc55f 100644
60538 --- a/include/linux/a.out.h
60539 +++ b/include/linux/a.out.h
60540 @@ -39,6 +39,14 @@ enum machine_type {
60541 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60542 };
60543
60544 +/* Constants for the N_FLAGS field */
60545 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60546 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60547 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60548 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60549 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60550 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60551 +
60552 #if !defined (N_MAGIC)
60553 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60554 #endif
60555 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60556 index 49a83ca..df96b54 100644
60557 --- a/include/linux/atmdev.h
60558 +++ b/include/linux/atmdev.h
60559 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60560 #endif
60561
60562 struct k_atm_aal_stats {
60563 -#define __HANDLE_ITEM(i) atomic_t i
60564 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60565 __AAL_STAT_ITEMS
60566 #undef __HANDLE_ITEM
60567 };
60568 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60569 index fd88a39..f4d0bad 100644
60570 --- a/include/linux/binfmts.h
60571 +++ b/include/linux/binfmts.h
60572 @@ -88,6 +88,7 @@ struct linux_binfmt {
60573 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60574 int (*load_shlib)(struct file *);
60575 int (*core_dump)(struct coredump_params *cprm);
60576 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60577 unsigned long min_coredump; /* minimal dump size */
60578 };
60579
60580 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60581 index 5e30b45..5b41b49 100644
60582 --- a/include/linux/blkdev.h
60583 +++ b/include/linux/blkdev.h
60584 @@ -675,6 +675,9 @@ extern int blk_insert_cloned_request(struct request_queue *q,
60585 struct request *rq);
60586 extern void blk_delay_queue(struct request_queue *, unsigned long);
60587 extern void blk_recount_segments(struct request_queue *, struct bio *);
60588 +extern int scsi_verify_blk_ioctl(struct block_device *, unsigned int);
60589 +extern int scsi_cmd_blk_ioctl(struct block_device *, fmode_t,
60590 + unsigned int, void __user *);
60591 extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
60592 unsigned int, void __user *);
60593 extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,
60594 @@ -1318,7 +1321,7 @@ struct block_device_operations {
60595 /* this callback is with swap_lock and sometimes page table lock held */
60596 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60597 struct module *owner;
60598 -};
60599 +} __do_const;
60600
60601 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60602 unsigned long);
60603 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60604 index 8e9e4bc..88bd457 100644
60605 --- a/include/linux/blktrace_api.h
60606 +++ b/include/linux/blktrace_api.h
60607 @@ -162,7 +162,7 @@ struct blk_trace {
60608 struct dentry *dir;
60609 struct dentry *dropped_file;
60610 struct dentry *msg_file;
60611 - atomic_t dropped;
60612 + atomic_unchecked_t dropped;
60613 };
60614
60615 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60616 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60617 index 83195fb..0b0f77d 100644
60618 --- a/include/linux/byteorder/little_endian.h
60619 +++ b/include/linux/byteorder/little_endian.h
60620 @@ -42,51 +42,51 @@
60621
60622 static inline __le64 __cpu_to_le64p(const __u64 *p)
60623 {
60624 - return (__force __le64)*p;
60625 + return (__force const __le64)*p;
60626 }
60627 static inline __u64 __le64_to_cpup(const __le64 *p)
60628 {
60629 - return (__force __u64)*p;
60630 + return (__force const __u64)*p;
60631 }
60632 static inline __le32 __cpu_to_le32p(const __u32 *p)
60633 {
60634 - return (__force __le32)*p;
60635 + return (__force const __le32)*p;
60636 }
60637 static inline __u32 __le32_to_cpup(const __le32 *p)
60638 {
60639 - return (__force __u32)*p;
60640 + return (__force const __u32)*p;
60641 }
60642 static inline __le16 __cpu_to_le16p(const __u16 *p)
60643 {
60644 - return (__force __le16)*p;
60645 + return (__force const __le16)*p;
60646 }
60647 static inline __u16 __le16_to_cpup(const __le16 *p)
60648 {
60649 - return (__force __u16)*p;
60650 + return (__force const __u16)*p;
60651 }
60652 static inline __be64 __cpu_to_be64p(const __u64 *p)
60653 {
60654 - return (__force __be64)__swab64p(p);
60655 + return (__force const __be64)__swab64p(p);
60656 }
60657 static inline __u64 __be64_to_cpup(const __be64 *p)
60658 {
60659 - return __swab64p((__u64 *)p);
60660 + return __swab64p((const __u64 *)p);
60661 }
60662 static inline __be32 __cpu_to_be32p(const __u32 *p)
60663 {
60664 - return (__force __be32)__swab32p(p);
60665 + return (__force const __be32)__swab32p(p);
60666 }
60667 static inline __u32 __be32_to_cpup(const __be32 *p)
60668 {
60669 - return __swab32p((__u32 *)p);
60670 + return __swab32p((const __u32 *)p);
60671 }
60672 static inline __be16 __cpu_to_be16p(const __u16 *p)
60673 {
60674 - return (__force __be16)__swab16p(p);
60675 + return (__force const __be16)__swab16p(p);
60676 }
60677 static inline __u16 __be16_to_cpup(const __be16 *p)
60678 {
60679 - return __swab16p((__u16 *)p);
60680 + return __swab16p((const __u16 *)p);
60681 }
60682 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60683 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60684 diff --git a/include/linux/cache.h b/include/linux/cache.h
60685 index 4c57065..4307975 100644
60686 --- a/include/linux/cache.h
60687 +++ b/include/linux/cache.h
60688 @@ -16,6 +16,10 @@
60689 #define __read_mostly
60690 #endif
60691
60692 +#ifndef __read_only
60693 +#define __read_only __read_mostly
60694 +#endif
60695 +
60696 #ifndef ____cacheline_aligned
60697 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60698 #endif
60699 diff --git a/include/linux/capability.h b/include/linux/capability.h
60700 index c421123..e343179 100644
60701 --- a/include/linux/capability.h
60702 +++ b/include/linux/capability.h
60703 @@ -547,6 +547,9 @@ extern bool capable(int cap);
60704 extern bool ns_capable(struct user_namespace *ns, int cap);
60705 extern bool task_ns_capable(struct task_struct *t, int cap);
60706 extern bool nsown_capable(int cap);
60707 +extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
60708 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60709 +extern bool capable_nolog(int cap);
60710
60711 /* audit system wants to get cap info from files as well */
60712 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60713 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60714 index 04ffb2e..6799180 100644
60715 --- a/include/linux/cleancache.h
60716 +++ b/include/linux/cleancache.h
60717 @@ -31,7 +31,7 @@ struct cleancache_ops {
60718 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
60719 void (*flush_inode)(int, struct cleancache_filekey);
60720 void (*flush_fs)(int);
60721 -};
60722 +} __no_const;
60723
60724 extern struct cleancache_ops
60725 cleancache_register_ops(struct cleancache_ops *ops);
60726 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60727 index dfadc96..c0e70c1 100644
60728 --- a/include/linux/compiler-gcc4.h
60729 +++ b/include/linux/compiler-gcc4.h
60730 @@ -31,6 +31,12 @@
60731
60732
60733 #if __GNUC_MINOR__ >= 5
60734 +
60735 +#ifdef CONSTIFY_PLUGIN
60736 +#define __no_const __attribute__((no_const))
60737 +#define __do_const __attribute__((do_const))
60738 +#endif
60739 +
60740 /*
60741 * Mark a position in code as unreachable. This can be used to
60742 * suppress control flow warnings after asm blocks that transfer
60743 @@ -46,6 +52,11 @@
60744 #define __noclone __attribute__((__noclone__))
60745
60746 #endif
60747 +
60748 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60749 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60750 +#define __bos0(ptr) __bos((ptr), 0)
60751 +#define __bos1(ptr) __bos((ptr), 1)
60752 #endif
60753
60754 #if __GNUC_MINOR__ > 0
60755 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60756 index 320d6c9..8573a1c 100644
60757 --- a/include/linux/compiler.h
60758 +++ b/include/linux/compiler.h
60759 @@ -5,31 +5,62 @@
60760
60761 #ifdef __CHECKER__
60762 # define __user __attribute__((noderef, address_space(1)))
60763 +# define __force_user __force __user
60764 # define __kernel __attribute__((address_space(0)))
60765 +# define __force_kernel __force __kernel
60766 # define __safe __attribute__((safe))
60767 # define __force __attribute__((force))
60768 # define __nocast __attribute__((nocast))
60769 # define __iomem __attribute__((noderef, address_space(2)))
60770 +# define __force_iomem __force __iomem
60771 # define __acquires(x) __attribute__((context(x,0,1)))
60772 # define __releases(x) __attribute__((context(x,1,0)))
60773 # define __acquire(x) __context__(x,1)
60774 # define __release(x) __context__(x,-1)
60775 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60776 # define __percpu __attribute__((noderef, address_space(3)))
60777 +# define __force_percpu __force __percpu
60778 #ifdef CONFIG_SPARSE_RCU_POINTER
60779 # define __rcu __attribute__((noderef, address_space(4)))
60780 +# define __force_rcu __force __rcu
60781 #else
60782 # define __rcu
60783 +# define __force_rcu
60784 #endif
60785 extern void __chk_user_ptr(const volatile void __user *);
60786 extern void __chk_io_ptr(const volatile void __iomem *);
60787 +#elif defined(CHECKER_PLUGIN)
60788 +//# define __user
60789 +//# define __force_user
60790 +//# define __kernel
60791 +//# define __force_kernel
60792 +# define __safe
60793 +# define __force
60794 +# define __nocast
60795 +# define __iomem
60796 +# define __force_iomem
60797 +# define __chk_user_ptr(x) (void)0
60798 +# define __chk_io_ptr(x) (void)0
60799 +# define __builtin_warning(x, y...) (1)
60800 +# define __acquires(x)
60801 +# define __releases(x)
60802 +# define __acquire(x) (void)0
60803 +# define __release(x) (void)0
60804 +# define __cond_lock(x,c) (c)
60805 +# define __percpu
60806 +# define __force_percpu
60807 +# define __rcu
60808 +# define __force_rcu
60809 #else
60810 # define __user
60811 +# define __force_user
60812 # define __kernel
60813 +# define __force_kernel
60814 # define __safe
60815 # define __force
60816 # define __nocast
60817 # define __iomem
60818 +# define __force_iomem
60819 # define __chk_user_ptr(x) (void)0
60820 # define __chk_io_ptr(x) (void)0
60821 # define __builtin_warning(x, y...) (1)
60822 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60823 # define __release(x) (void)0
60824 # define __cond_lock(x,c) (c)
60825 # define __percpu
60826 +# define __force_percpu
60827 # define __rcu
60828 +# define __force_rcu
60829 #endif
60830
60831 #ifdef __KERNEL__
60832 @@ -264,6 +297,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60833 # define __attribute_const__ /* unimplemented */
60834 #endif
60835
60836 +#ifndef __no_const
60837 +# define __no_const
60838 +#endif
60839 +
60840 +#ifndef __do_const
60841 +# define __do_const
60842 +#endif
60843 +
60844 /*
60845 * Tell gcc if a function is cold. The compiler will assume any path
60846 * directly leading to the call is unlikely.
60847 @@ -273,6 +314,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60848 #define __cold
60849 #endif
60850
60851 +#ifndef __alloc_size
60852 +#define __alloc_size(...)
60853 +#endif
60854 +
60855 +#ifndef __bos
60856 +#define __bos(ptr, arg)
60857 +#endif
60858 +
60859 +#ifndef __bos0
60860 +#define __bos0(ptr)
60861 +#endif
60862 +
60863 +#ifndef __bos1
60864 +#define __bos1(ptr)
60865 +#endif
60866 +
60867 /* Simple shorthand for a section definition */
60868 #ifndef __section
60869 # define __section(S) __attribute__ ((__section__(#S)))
60870 @@ -306,6 +363,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60871 * use is to mediate communication between process-level code and irq/NMI
60872 * handlers, all running on the same CPU.
60873 */
60874 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60875 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60876 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60877
60878 #endif /* __LINUX_COMPILER_H */
60879 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
60880 index e9eaec5..bfeb9bb 100644
60881 --- a/include/linux/cpuset.h
60882 +++ b/include/linux/cpuset.h
60883 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
60884 * nodemask.
60885 */
60886 smp_mb();
60887 - --ACCESS_ONCE(current->mems_allowed_change_disable);
60888 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
60889 }
60890
60891 static inline void set_mems_allowed(nodemask_t nodemask)
60892 diff --git a/include/linux/cred.h b/include/linux/cred.h
60893 index 4030896..a5c9f09 100644
60894 --- a/include/linux/cred.h
60895 +++ b/include/linux/cred.h
60896 @@ -196,6 +196,11 @@ do { \
60897 __validate_process_creds(current, __FILE__, __LINE__); \
60898 } while(0)
60899
60900 +#define validate_task_creds(task) \
60901 +do { \
60902 + __validate_process_creds((task), __FILE__, __LINE__); \
60903 +} while(0)
60904 +
60905 extern void validate_creds_for_do_exit(struct task_struct *);
60906 #else
60907 static inline void validate_creds(const struct cred *cred)
60908 @@ -207,6 +212,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60909 static inline void validate_process_creds(void)
60910 {
60911 }
60912 +static inline void validate_task_creds(struct task_struct *task)
60913 +{
60914 +}
60915 #endif
60916
60917 /**
60918 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60919 index e5e468e..f079672 100644
60920 --- a/include/linux/crypto.h
60921 +++ b/include/linux/crypto.h
60922 @@ -361,7 +361,7 @@ struct cipher_tfm {
60923 const u8 *key, unsigned int keylen);
60924 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60925 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60926 -};
60927 +} __no_const;
60928
60929 struct hash_tfm {
60930 int (*init)(struct hash_desc *desc);
60931 @@ -382,13 +382,13 @@ struct compress_tfm {
60932 int (*cot_decompress)(struct crypto_tfm *tfm,
60933 const u8 *src, unsigned int slen,
60934 u8 *dst, unsigned int *dlen);
60935 -};
60936 +} __no_const;
60937
60938 struct rng_tfm {
60939 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60940 unsigned int dlen);
60941 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60942 -};
60943 +} __no_const;
60944
60945 #define crt_ablkcipher crt_u.ablkcipher
60946 #define crt_aead crt_u.aead
60947 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60948 index 7925bf0..d5143d2 100644
60949 --- a/include/linux/decompress/mm.h
60950 +++ b/include/linux/decompress/mm.h
60951 @@ -77,7 +77,7 @@ static void free(void *where)
60952 * warnings when not needed (indeed large_malloc / large_free are not
60953 * needed by inflate */
60954
60955 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60956 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60957 #define free(a) kfree(a)
60958
60959 #define large_malloc(a) vmalloc(a)
60960 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60961 index 347fdc3..cd01657 100644
60962 --- a/include/linux/dma-mapping.h
60963 +++ b/include/linux/dma-mapping.h
60964 @@ -42,7 +42,7 @@ struct dma_map_ops {
60965 int (*dma_supported)(struct device *dev, u64 mask);
60966 int (*set_dma_mask)(struct device *dev, u64 mask);
60967 int is_phys;
60968 -};
60969 +} __do_const;
60970
60971 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60972
60973 diff --git a/include/linux/efi.h b/include/linux/efi.h
60974 index 2362a0b..cfaf8fcc 100644
60975 --- a/include/linux/efi.h
60976 +++ b/include/linux/efi.h
60977 @@ -446,7 +446,7 @@ struct efivar_operations {
60978 efi_get_variable_t *get_variable;
60979 efi_get_next_variable_t *get_next_variable;
60980 efi_set_variable_t *set_variable;
60981 -};
60982 +} __no_const;
60983
60984 struct efivars {
60985 /*
60986 diff --git a/include/linux/elf.h b/include/linux/elf.h
60987 index 110821c..cb14c08 100644
60988 --- a/include/linux/elf.h
60989 +++ b/include/linux/elf.h
60990 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
60991 #define PT_GNU_EH_FRAME 0x6474e550
60992
60993 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60994 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60995 +
60996 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60997 +
60998 +/* Constants for the e_flags field */
60999 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61000 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61001 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61002 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61003 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61004 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61005
61006 /*
61007 * Extended Numbering
61008 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
61009 #define DT_DEBUG 21
61010 #define DT_TEXTREL 22
61011 #define DT_JMPREL 23
61012 +#define DT_FLAGS 30
61013 + #define DF_TEXTREL 0x00000004
61014 #define DT_ENCODING 32
61015 #define OLD_DT_LOOS 0x60000000
61016 #define DT_LOOS 0x6000000d
61017 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
61018 #define PF_W 0x2
61019 #define PF_X 0x1
61020
61021 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61022 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61023 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61024 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61025 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61026 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61027 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61028 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61029 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61030 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61031 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61032 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61033 +
61034 typedef struct elf32_phdr{
61035 Elf32_Word p_type;
61036 Elf32_Off p_offset;
61037 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
61038 #define EI_OSABI 7
61039 #define EI_PAD 8
61040
61041 +#define EI_PAX 14
61042 +
61043 #define ELFMAG0 0x7f /* EI_MAG */
61044 #define ELFMAG1 'E'
61045 #define ELFMAG2 'L'
61046 @@ -422,6 +450,7 @@ extern Elf32_Dyn _DYNAMIC [];
61047 #define elf_note elf32_note
61048 #define elf_addr_t Elf32_Off
61049 #define Elf_Half Elf32_Half
61050 +#define elf_dyn Elf32_Dyn
61051
61052 #else
61053
61054 @@ -432,6 +461,7 @@ extern Elf64_Dyn _DYNAMIC [];
61055 #define elf_note elf64_note
61056 #define elf_addr_t Elf64_Off
61057 #define Elf_Half Elf64_Half
61058 +#define elf_dyn Elf64_Dyn
61059
61060 #endif
61061
61062 diff --git a/include/linux/filter.h b/include/linux/filter.h
61063 index 741956f..f02f482 100644
61064 --- a/include/linux/filter.h
61065 +++ b/include/linux/filter.h
61066 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
61067
61068 struct sk_buff;
61069 struct sock;
61070 +struct bpf_jit_work;
61071
61072 struct sk_filter
61073 {
61074 @@ -141,6 +142,9 @@ struct sk_filter
61075 unsigned int len; /* Number of filter blocks */
61076 unsigned int (*bpf_func)(const struct sk_buff *skb,
61077 const struct sock_filter *filter);
61078 +#ifdef CONFIG_BPF_JIT
61079 + struct bpf_jit_work *work;
61080 +#endif
61081 struct rcu_head rcu;
61082 struct sock_filter insns[0];
61083 };
61084 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61085 index 84ccf8e..2e9b14c 100644
61086 --- a/include/linux/firewire.h
61087 +++ b/include/linux/firewire.h
61088 @@ -428,7 +428,7 @@ struct fw_iso_context {
61089 union {
61090 fw_iso_callback_t sc;
61091 fw_iso_mc_callback_t mc;
61092 - } callback;
61093 + } __no_const callback;
61094 void *callback_data;
61095 };
61096
61097 diff --git a/include/linux/fs.h b/include/linux/fs.h
61098 index cf7bc25..0d2babf 100644
61099 --- a/include/linux/fs.h
61100 +++ b/include/linux/fs.h
61101 @@ -1588,7 +1588,8 @@ struct file_operations {
61102 int (*setlease)(struct file *, long, struct file_lock **);
61103 long (*fallocate)(struct file *file, int mode, loff_t offset,
61104 loff_t len);
61105 -};
61106 +} __do_const;
61107 +typedef struct file_operations __no_const file_operations_no_const;
61108
61109 struct inode_operations {
61110 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
61111 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61112 index 003dc0f..3c4ea97 100644
61113 --- a/include/linux/fs_struct.h
61114 +++ b/include/linux/fs_struct.h
61115 @@ -6,7 +6,7 @@
61116 #include <linux/seqlock.h>
61117
61118 struct fs_struct {
61119 - int users;
61120 + atomic_t users;
61121 spinlock_t lock;
61122 seqcount_t seq;
61123 int umask;
61124 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61125 index af095b5..cf1220c 100644
61126 --- a/include/linux/fscache-cache.h
61127 +++ b/include/linux/fscache-cache.h
61128 @@ -102,7 +102,7 @@ struct fscache_operation {
61129 fscache_operation_release_t release;
61130 };
61131
61132 -extern atomic_t fscache_op_debug_id;
61133 +extern atomic_unchecked_t fscache_op_debug_id;
61134 extern void fscache_op_work_func(struct work_struct *work);
61135
61136 extern void fscache_enqueue_operation(struct fscache_operation *);
61137 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61138 {
61139 INIT_WORK(&op->work, fscache_op_work_func);
61140 atomic_set(&op->usage, 1);
61141 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61142 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61143 op->processor = processor;
61144 op->release = release;
61145 INIT_LIST_HEAD(&op->pend_link);
61146 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61147 index 2a53f10..0187fdf 100644
61148 --- a/include/linux/fsnotify.h
61149 +++ b/include/linux/fsnotify.h
61150 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61151 */
61152 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61153 {
61154 - return kstrdup(name, GFP_KERNEL);
61155 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61156 }
61157
61158 /*
61159 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61160 index 91d0e0a3..035666b 100644
61161 --- a/include/linux/fsnotify_backend.h
61162 +++ b/include/linux/fsnotify_backend.h
61163 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61164 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61165 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61166 };
61167 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61168
61169 /*
61170 * A group is a "thing" that wants to receive notification about filesystem
61171 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61172 index 96efa67..1261547 100644
61173 --- a/include/linux/ftrace_event.h
61174 +++ b/include/linux/ftrace_event.h
61175 @@ -97,7 +97,7 @@ struct trace_event_functions {
61176 trace_print_func raw;
61177 trace_print_func hex;
61178 trace_print_func binary;
61179 -};
61180 +} __no_const;
61181
61182 struct trace_event {
61183 struct hlist_node node;
61184 @@ -252,7 +252,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61185 extern int trace_add_event_call(struct ftrace_event_call *call);
61186 extern void trace_remove_event_call(struct ftrace_event_call *call);
61187
61188 -#define is_signed_type(type) (((type)(-1)) < 0)
61189 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61190
61191 int trace_set_clr_event(const char *system, const char *event, int set);
61192
61193 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61194 index 02fa469..a15f279 100644
61195 --- a/include/linux/genhd.h
61196 +++ b/include/linux/genhd.h
61197 @@ -184,7 +184,7 @@ struct gendisk {
61198 struct kobject *slave_dir;
61199
61200 struct timer_rand_state *random;
61201 - atomic_t sync_io; /* RAID */
61202 + atomic_unchecked_t sync_io; /* RAID */
61203 struct disk_events *ev;
61204 #ifdef CONFIG_BLK_DEV_INTEGRITY
61205 struct blk_integrity *integrity;
61206 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61207 new file mode 100644
61208 index 0000000..0dc3943
61209 --- /dev/null
61210 +++ b/include/linux/gracl.h
61211 @@ -0,0 +1,317 @@
61212 +#ifndef GR_ACL_H
61213 +#define GR_ACL_H
61214 +
61215 +#include <linux/grdefs.h>
61216 +#include <linux/resource.h>
61217 +#include <linux/capability.h>
61218 +#include <linux/dcache.h>
61219 +#include <asm/resource.h>
61220 +
61221 +/* Major status information */
61222 +
61223 +#define GR_VERSION "grsecurity 2.2.2"
61224 +#define GRSECURITY_VERSION 0x2202
61225 +
61226 +enum {
61227 + GR_SHUTDOWN = 0,
61228 + GR_ENABLE = 1,
61229 + GR_SPROLE = 2,
61230 + GR_RELOAD = 3,
61231 + GR_SEGVMOD = 4,
61232 + GR_STATUS = 5,
61233 + GR_UNSPROLE = 6,
61234 + GR_PASSSET = 7,
61235 + GR_SPROLEPAM = 8,
61236 +};
61237 +
61238 +/* Password setup definitions
61239 + * kernel/grhash.c */
61240 +enum {
61241 + GR_PW_LEN = 128,
61242 + GR_SALT_LEN = 16,
61243 + GR_SHA_LEN = 32,
61244 +};
61245 +
61246 +enum {
61247 + GR_SPROLE_LEN = 64,
61248 +};
61249 +
61250 +enum {
61251 + GR_NO_GLOB = 0,
61252 + GR_REG_GLOB,
61253 + GR_CREATE_GLOB
61254 +};
61255 +
61256 +#define GR_NLIMITS 32
61257 +
61258 +/* Begin Data Structures */
61259 +
61260 +struct sprole_pw {
61261 + unsigned char *rolename;
61262 + unsigned char salt[GR_SALT_LEN];
61263 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61264 +};
61265 +
61266 +struct name_entry {
61267 + __u32 key;
61268 + ino_t inode;
61269 + dev_t device;
61270 + char *name;
61271 + __u16 len;
61272 + __u8 deleted;
61273 + struct name_entry *prev;
61274 + struct name_entry *next;
61275 +};
61276 +
61277 +struct inodev_entry {
61278 + struct name_entry *nentry;
61279 + struct inodev_entry *prev;
61280 + struct inodev_entry *next;
61281 +};
61282 +
61283 +struct acl_role_db {
61284 + struct acl_role_label **r_hash;
61285 + __u32 r_size;
61286 +};
61287 +
61288 +struct inodev_db {
61289 + struct inodev_entry **i_hash;
61290 + __u32 i_size;
61291 +};
61292 +
61293 +struct name_db {
61294 + struct name_entry **n_hash;
61295 + __u32 n_size;
61296 +};
61297 +
61298 +struct crash_uid {
61299 + uid_t uid;
61300 + unsigned long expires;
61301 +};
61302 +
61303 +struct gr_hash_struct {
61304 + void **table;
61305 + void **nametable;
61306 + void *first;
61307 + __u32 table_size;
61308 + __u32 used_size;
61309 + int type;
61310 +};
61311 +
61312 +/* Userspace Grsecurity ACL data structures */
61313 +
61314 +struct acl_subject_label {
61315 + char *filename;
61316 + ino_t inode;
61317 + dev_t device;
61318 + __u32 mode;
61319 + kernel_cap_t cap_mask;
61320 + kernel_cap_t cap_lower;
61321 + kernel_cap_t cap_invert_audit;
61322 +
61323 + struct rlimit res[GR_NLIMITS];
61324 + __u32 resmask;
61325 +
61326 + __u8 user_trans_type;
61327 + __u8 group_trans_type;
61328 + uid_t *user_transitions;
61329 + gid_t *group_transitions;
61330 + __u16 user_trans_num;
61331 + __u16 group_trans_num;
61332 +
61333 + __u32 sock_families[2];
61334 + __u32 ip_proto[8];
61335 + __u32 ip_type;
61336 + struct acl_ip_label **ips;
61337 + __u32 ip_num;
61338 + __u32 inaddr_any_override;
61339 +
61340 + __u32 crashes;
61341 + unsigned long expires;
61342 +
61343 + struct acl_subject_label *parent_subject;
61344 + struct gr_hash_struct *hash;
61345 + struct acl_subject_label *prev;
61346 + struct acl_subject_label *next;
61347 +
61348 + struct acl_object_label **obj_hash;
61349 + __u32 obj_hash_size;
61350 + __u16 pax_flags;
61351 +};
61352 +
61353 +struct role_allowed_ip {
61354 + __u32 addr;
61355 + __u32 netmask;
61356 +
61357 + struct role_allowed_ip *prev;
61358 + struct role_allowed_ip *next;
61359 +};
61360 +
61361 +struct role_transition {
61362 + char *rolename;
61363 +
61364 + struct role_transition *prev;
61365 + struct role_transition *next;
61366 +};
61367 +
61368 +struct acl_role_label {
61369 + char *rolename;
61370 + uid_t uidgid;
61371 + __u16 roletype;
61372 +
61373 + __u16 auth_attempts;
61374 + unsigned long expires;
61375 +
61376 + struct acl_subject_label *root_label;
61377 + struct gr_hash_struct *hash;
61378 +
61379 + struct acl_role_label *prev;
61380 + struct acl_role_label *next;
61381 +
61382 + struct role_transition *transitions;
61383 + struct role_allowed_ip *allowed_ips;
61384 + uid_t *domain_children;
61385 + __u16 domain_child_num;
61386 +
61387 + struct acl_subject_label **subj_hash;
61388 + __u32 subj_hash_size;
61389 +};
61390 +
61391 +struct user_acl_role_db {
61392 + struct acl_role_label **r_table;
61393 + __u32 num_pointers; /* Number of allocations to track */
61394 + __u32 num_roles; /* Number of roles */
61395 + __u32 num_domain_children; /* Number of domain children */
61396 + __u32 num_subjects; /* Number of subjects */
61397 + __u32 num_objects; /* Number of objects */
61398 +};
61399 +
61400 +struct acl_object_label {
61401 + char *filename;
61402 + ino_t inode;
61403 + dev_t device;
61404 + __u32 mode;
61405 +
61406 + struct acl_subject_label *nested;
61407 + struct acl_object_label *globbed;
61408 +
61409 + /* next two structures not used */
61410 +
61411 + struct acl_object_label *prev;
61412 + struct acl_object_label *next;
61413 +};
61414 +
61415 +struct acl_ip_label {
61416 + char *iface;
61417 + __u32 addr;
61418 + __u32 netmask;
61419 + __u16 low, high;
61420 + __u8 mode;
61421 + __u32 type;
61422 + __u32 proto[8];
61423 +
61424 + /* next two structures not used */
61425 +
61426 + struct acl_ip_label *prev;
61427 + struct acl_ip_label *next;
61428 +};
61429 +
61430 +struct gr_arg {
61431 + struct user_acl_role_db role_db;
61432 + unsigned char pw[GR_PW_LEN];
61433 + unsigned char salt[GR_SALT_LEN];
61434 + unsigned char sum[GR_SHA_LEN];
61435 + unsigned char sp_role[GR_SPROLE_LEN];
61436 + struct sprole_pw *sprole_pws;
61437 + dev_t segv_device;
61438 + ino_t segv_inode;
61439 + uid_t segv_uid;
61440 + __u16 num_sprole_pws;
61441 + __u16 mode;
61442 +};
61443 +
61444 +struct gr_arg_wrapper {
61445 + struct gr_arg *arg;
61446 + __u32 version;
61447 + __u32 size;
61448 +};
61449 +
61450 +struct subject_map {
61451 + struct acl_subject_label *user;
61452 + struct acl_subject_label *kernel;
61453 + struct subject_map *prev;
61454 + struct subject_map *next;
61455 +};
61456 +
61457 +struct acl_subj_map_db {
61458 + struct subject_map **s_hash;
61459 + __u32 s_size;
61460 +};
61461 +
61462 +/* End Data Structures Section */
61463 +
61464 +/* Hash functions generated by empirical testing by Brad Spengler
61465 + Makes good use of the low bits of the inode. Generally 0-1 times
61466 + in loop for successful match. 0-3 for unsuccessful match.
61467 + Shift/add algorithm with modulus of table size and an XOR*/
61468 +
61469 +static __inline__ unsigned int
61470 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61471 +{
61472 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61473 +}
61474 +
61475 + static __inline__ unsigned int
61476 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61477 +{
61478 + return ((const unsigned long)userp % sz);
61479 +}
61480 +
61481 +static __inline__ unsigned int
61482 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61483 +{
61484 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61485 +}
61486 +
61487 +static __inline__ unsigned int
61488 +nhash(const char *name, const __u16 len, const unsigned int sz)
61489 +{
61490 + return full_name_hash((const unsigned char *)name, len) % sz;
61491 +}
61492 +
61493 +#define FOR_EACH_ROLE_START(role) \
61494 + role = role_list; \
61495 + while (role) {
61496 +
61497 +#define FOR_EACH_ROLE_END(role) \
61498 + role = role->prev; \
61499 + }
61500 +
61501 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61502 + subj = NULL; \
61503 + iter = 0; \
61504 + while (iter < role->subj_hash_size) { \
61505 + if (subj == NULL) \
61506 + subj = role->subj_hash[iter]; \
61507 + if (subj == NULL) { \
61508 + iter++; \
61509 + continue; \
61510 + }
61511 +
61512 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61513 + subj = subj->next; \
61514 + if (subj == NULL) \
61515 + iter++; \
61516 + }
61517 +
61518 +
61519 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61520 + subj = role->hash->first; \
61521 + while (subj != NULL) {
61522 +
61523 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61524 + subj = subj->next; \
61525 + }
61526 +
61527 +#endif
61528 +
61529 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61530 new file mode 100644
61531 index 0000000..323ecf2
61532 --- /dev/null
61533 +++ b/include/linux/gralloc.h
61534 @@ -0,0 +1,9 @@
61535 +#ifndef __GRALLOC_H
61536 +#define __GRALLOC_H
61537 +
61538 +void acl_free_all(void);
61539 +int acl_alloc_stack_init(unsigned long size);
61540 +void *acl_alloc(unsigned long len);
61541 +void *acl_alloc_num(unsigned long num, unsigned long len);
61542 +
61543 +#endif
61544 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61545 new file mode 100644
61546 index 0000000..b30e9bc
61547 --- /dev/null
61548 +++ b/include/linux/grdefs.h
61549 @@ -0,0 +1,140 @@
61550 +#ifndef GRDEFS_H
61551 +#define GRDEFS_H
61552 +
61553 +/* Begin grsecurity status declarations */
61554 +
61555 +enum {
61556 + GR_READY = 0x01,
61557 + GR_STATUS_INIT = 0x00 // disabled state
61558 +};
61559 +
61560 +/* Begin ACL declarations */
61561 +
61562 +/* Role flags */
61563 +
61564 +enum {
61565 + GR_ROLE_USER = 0x0001,
61566 + GR_ROLE_GROUP = 0x0002,
61567 + GR_ROLE_DEFAULT = 0x0004,
61568 + GR_ROLE_SPECIAL = 0x0008,
61569 + GR_ROLE_AUTH = 0x0010,
61570 + GR_ROLE_NOPW = 0x0020,
61571 + GR_ROLE_GOD = 0x0040,
61572 + GR_ROLE_LEARN = 0x0080,
61573 + GR_ROLE_TPE = 0x0100,
61574 + GR_ROLE_DOMAIN = 0x0200,
61575 + GR_ROLE_PAM = 0x0400,
61576 + GR_ROLE_PERSIST = 0x0800
61577 +};
61578 +
61579 +/* ACL Subject and Object mode flags */
61580 +enum {
61581 + GR_DELETED = 0x80000000
61582 +};
61583 +
61584 +/* ACL Object-only mode flags */
61585 +enum {
61586 + GR_READ = 0x00000001,
61587 + GR_APPEND = 0x00000002,
61588 + GR_WRITE = 0x00000004,
61589 + GR_EXEC = 0x00000008,
61590 + GR_FIND = 0x00000010,
61591 + GR_INHERIT = 0x00000020,
61592 + GR_SETID = 0x00000040,
61593 + GR_CREATE = 0x00000080,
61594 + GR_DELETE = 0x00000100,
61595 + GR_LINK = 0x00000200,
61596 + GR_AUDIT_READ = 0x00000400,
61597 + GR_AUDIT_APPEND = 0x00000800,
61598 + GR_AUDIT_WRITE = 0x00001000,
61599 + GR_AUDIT_EXEC = 0x00002000,
61600 + GR_AUDIT_FIND = 0x00004000,
61601 + GR_AUDIT_INHERIT= 0x00008000,
61602 + GR_AUDIT_SETID = 0x00010000,
61603 + GR_AUDIT_CREATE = 0x00020000,
61604 + GR_AUDIT_DELETE = 0x00040000,
61605 + GR_AUDIT_LINK = 0x00080000,
61606 + GR_PTRACERD = 0x00100000,
61607 + GR_NOPTRACE = 0x00200000,
61608 + GR_SUPPRESS = 0x00400000,
61609 + GR_NOLEARN = 0x00800000,
61610 + GR_INIT_TRANSFER= 0x01000000
61611 +};
61612 +
61613 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61614 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61615 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61616 +
61617 +/* ACL subject-only mode flags */
61618 +enum {
61619 + GR_KILL = 0x00000001,
61620 + GR_VIEW = 0x00000002,
61621 + GR_PROTECTED = 0x00000004,
61622 + GR_LEARN = 0x00000008,
61623 + GR_OVERRIDE = 0x00000010,
61624 + /* just a placeholder, this mode is only used in userspace */
61625 + GR_DUMMY = 0x00000020,
61626 + GR_PROTSHM = 0x00000040,
61627 + GR_KILLPROC = 0x00000080,
61628 + GR_KILLIPPROC = 0x00000100,
61629 + /* just a placeholder, this mode is only used in userspace */
61630 + GR_NOTROJAN = 0x00000200,
61631 + GR_PROTPROCFD = 0x00000400,
61632 + GR_PROCACCT = 0x00000800,
61633 + GR_RELAXPTRACE = 0x00001000,
61634 + GR_NESTED = 0x00002000,
61635 + GR_INHERITLEARN = 0x00004000,
61636 + GR_PROCFIND = 0x00008000,
61637 + GR_POVERRIDE = 0x00010000,
61638 + GR_KERNELAUTH = 0x00020000,
61639 + GR_ATSECURE = 0x00040000,
61640 + GR_SHMEXEC = 0x00080000
61641 +};
61642 +
61643 +enum {
61644 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61645 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61646 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61647 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61648 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61649 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61650 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61651 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61652 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61653 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61654 +};
61655 +
61656 +enum {
61657 + GR_ID_USER = 0x01,
61658 + GR_ID_GROUP = 0x02,
61659 +};
61660 +
61661 +enum {
61662 + GR_ID_ALLOW = 0x01,
61663 + GR_ID_DENY = 0x02,
61664 +};
61665 +
61666 +#define GR_CRASH_RES 31
61667 +#define GR_UIDTABLE_MAX 500
61668 +
61669 +/* begin resource learning section */
61670 +enum {
61671 + GR_RLIM_CPU_BUMP = 60,
61672 + GR_RLIM_FSIZE_BUMP = 50000,
61673 + GR_RLIM_DATA_BUMP = 10000,
61674 + GR_RLIM_STACK_BUMP = 1000,
61675 + GR_RLIM_CORE_BUMP = 10000,
61676 + GR_RLIM_RSS_BUMP = 500000,
61677 + GR_RLIM_NPROC_BUMP = 1,
61678 + GR_RLIM_NOFILE_BUMP = 5,
61679 + GR_RLIM_MEMLOCK_BUMP = 50000,
61680 + GR_RLIM_AS_BUMP = 500000,
61681 + GR_RLIM_LOCKS_BUMP = 2,
61682 + GR_RLIM_SIGPENDING_BUMP = 5,
61683 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61684 + GR_RLIM_NICE_BUMP = 1,
61685 + GR_RLIM_RTPRIO_BUMP = 1,
61686 + GR_RLIM_RTTIME_BUMP = 1000000
61687 +};
61688 +
61689 +#endif
61690 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61691 new file mode 100644
61692 index 0000000..60cda84
61693 --- /dev/null
61694 +++ b/include/linux/grinternal.h
61695 @@ -0,0 +1,220 @@
61696 +#ifndef __GRINTERNAL_H
61697 +#define __GRINTERNAL_H
61698 +
61699 +#ifdef CONFIG_GRKERNSEC
61700 +
61701 +#include <linux/fs.h>
61702 +#include <linux/mnt_namespace.h>
61703 +#include <linux/nsproxy.h>
61704 +#include <linux/gracl.h>
61705 +#include <linux/grdefs.h>
61706 +#include <linux/grmsg.h>
61707 +
61708 +void gr_add_learn_entry(const char *fmt, ...)
61709 + __attribute__ ((format (printf, 1, 2)));
61710 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61711 + const struct vfsmount *mnt);
61712 +__u32 gr_check_create(const struct dentry *new_dentry,
61713 + const struct dentry *parent,
61714 + const struct vfsmount *mnt, const __u32 mode);
61715 +int gr_check_protected_task(const struct task_struct *task);
61716 +__u32 to_gr_audit(const __u32 reqmode);
61717 +int gr_set_acls(const int type);
61718 +int gr_apply_subject_to_task(struct task_struct *task);
61719 +int gr_acl_is_enabled(void);
61720 +char gr_roletype_to_char(void);
61721 +
61722 +void gr_handle_alertkill(struct task_struct *task);
61723 +char *gr_to_filename(const struct dentry *dentry,
61724 + const struct vfsmount *mnt);
61725 +char *gr_to_filename1(const struct dentry *dentry,
61726 + const struct vfsmount *mnt);
61727 +char *gr_to_filename2(const struct dentry *dentry,
61728 + const struct vfsmount *mnt);
61729 +char *gr_to_filename3(const struct dentry *dentry,
61730 + const struct vfsmount *mnt);
61731 +
61732 +extern int grsec_enable_harden_ptrace;
61733 +extern int grsec_enable_link;
61734 +extern int grsec_enable_fifo;
61735 +extern int grsec_enable_execve;
61736 +extern int grsec_enable_shm;
61737 +extern int grsec_enable_execlog;
61738 +extern int grsec_enable_signal;
61739 +extern int grsec_enable_audit_ptrace;
61740 +extern int grsec_enable_forkfail;
61741 +extern int grsec_enable_time;
61742 +extern int grsec_enable_rofs;
61743 +extern int grsec_enable_chroot_shmat;
61744 +extern int grsec_enable_chroot_mount;
61745 +extern int grsec_enable_chroot_double;
61746 +extern int grsec_enable_chroot_pivot;
61747 +extern int grsec_enable_chroot_chdir;
61748 +extern int grsec_enable_chroot_chmod;
61749 +extern int grsec_enable_chroot_mknod;
61750 +extern int grsec_enable_chroot_fchdir;
61751 +extern int grsec_enable_chroot_nice;
61752 +extern int grsec_enable_chroot_execlog;
61753 +extern int grsec_enable_chroot_caps;
61754 +extern int grsec_enable_chroot_sysctl;
61755 +extern int grsec_enable_chroot_unix;
61756 +extern int grsec_enable_tpe;
61757 +extern int grsec_tpe_gid;
61758 +extern int grsec_enable_tpe_all;
61759 +extern int grsec_enable_tpe_invert;
61760 +extern int grsec_enable_socket_all;
61761 +extern int grsec_socket_all_gid;
61762 +extern int grsec_enable_socket_client;
61763 +extern int grsec_socket_client_gid;
61764 +extern int grsec_enable_socket_server;
61765 +extern int grsec_socket_server_gid;
61766 +extern int grsec_audit_gid;
61767 +extern int grsec_enable_group;
61768 +extern int grsec_enable_audit_textrel;
61769 +extern int grsec_enable_log_rwxmaps;
61770 +extern int grsec_enable_mount;
61771 +extern int grsec_enable_chdir;
61772 +extern int grsec_resource_logging;
61773 +extern int grsec_enable_blackhole;
61774 +extern int grsec_lastack_retries;
61775 +extern int grsec_enable_brute;
61776 +extern int grsec_lock;
61777 +
61778 +extern spinlock_t grsec_alert_lock;
61779 +extern unsigned long grsec_alert_wtime;
61780 +extern unsigned long grsec_alert_fyet;
61781 +
61782 +extern spinlock_t grsec_audit_lock;
61783 +
61784 +extern rwlock_t grsec_exec_file_lock;
61785 +
61786 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61787 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61788 + (tsk)->exec_file->f_vfsmnt) : "/")
61789 +
61790 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61791 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61792 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61793 +
61794 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61795 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61796 + (tsk)->exec_file->f_vfsmnt) : "/")
61797 +
61798 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61799 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61800 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61801 +
61802 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61803 +
61804 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61805 +
61806 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61807 + (task)->pid, (cred)->uid, \
61808 + (cred)->euid, (cred)->gid, (cred)->egid, \
61809 + gr_parent_task_fullpath(task), \
61810 + (task)->real_parent->comm, (task)->real_parent->pid, \
61811 + (pcred)->uid, (pcred)->euid, \
61812 + (pcred)->gid, (pcred)->egid
61813 +
61814 +#define GR_CHROOT_CAPS {{ \
61815 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61816 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61817 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61818 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61819 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61820 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61821 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61822 +
61823 +#define security_learn(normal_msg,args...) \
61824 +({ \
61825 + read_lock(&grsec_exec_file_lock); \
61826 + gr_add_learn_entry(normal_msg "\n", ## args); \
61827 + read_unlock(&grsec_exec_file_lock); \
61828 +})
61829 +
61830 +enum {
61831 + GR_DO_AUDIT,
61832 + GR_DONT_AUDIT,
61833 + /* used for non-audit messages that we shouldn't kill the task on */
61834 + GR_DONT_AUDIT_GOOD
61835 +};
61836 +
61837 +enum {
61838 + GR_TTYSNIFF,
61839 + GR_RBAC,
61840 + GR_RBAC_STR,
61841 + GR_STR_RBAC,
61842 + GR_RBAC_MODE2,
61843 + GR_RBAC_MODE3,
61844 + GR_FILENAME,
61845 + GR_SYSCTL_HIDDEN,
61846 + GR_NOARGS,
61847 + GR_ONE_INT,
61848 + GR_ONE_INT_TWO_STR,
61849 + GR_ONE_STR,
61850 + GR_STR_INT,
61851 + GR_TWO_STR_INT,
61852 + GR_TWO_INT,
61853 + GR_TWO_U64,
61854 + GR_THREE_INT,
61855 + GR_FIVE_INT_TWO_STR,
61856 + GR_TWO_STR,
61857 + GR_THREE_STR,
61858 + GR_FOUR_STR,
61859 + GR_STR_FILENAME,
61860 + GR_FILENAME_STR,
61861 + GR_FILENAME_TWO_INT,
61862 + GR_FILENAME_TWO_INT_STR,
61863 + GR_TEXTREL,
61864 + GR_PTRACE,
61865 + GR_RESOURCE,
61866 + GR_CAP,
61867 + GR_SIG,
61868 + GR_SIG2,
61869 + GR_CRASH1,
61870 + GR_CRASH2,
61871 + GR_PSACCT,
61872 + GR_RWXMAP
61873 +};
61874 +
61875 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61876 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61877 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61878 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61879 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61880 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61881 +#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)
61882 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61883 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61884 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61885 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61886 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61887 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61888 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61889 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61890 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61891 +#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)
61892 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61893 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61894 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61895 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61896 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61897 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61898 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61899 +#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)
61900 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61901 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61902 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61903 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61904 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61905 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61906 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61907 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61908 +#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)
61909 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61910 +
61911 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61912 +
61913 +#endif
61914 +
61915 +#endif
61916 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61917 new file mode 100644
61918 index 0000000..9d5fd4a
61919 --- /dev/null
61920 +++ b/include/linux/grmsg.h
61921 @@ -0,0 +1,108 @@
61922 +#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"
61923 +#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"
61924 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61925 +#define GR_STOPMOD_MSG "denied modification of module state by "
61926 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61927 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61928 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61929 +#define GR_IOPL_MSG "denied use of iopl() by "
61930 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61931 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61932 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61933 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61934 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61935 +#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"
61936 +#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"
61937 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61938 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61939 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61940 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61941 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61942 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61943 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61944 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61945 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61946 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61947 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61948 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61949 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61950 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61951 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61952 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61953 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61954 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61955 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61956 +#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
61957 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61958 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61959 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61960 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61961 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61962 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61963 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61964 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61965 +#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
61966 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61967 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61968 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61969 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61970 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61971 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61972 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61973 +#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"
61974 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
61975 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61976 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61977 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61978 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61979 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61980 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61981 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61982 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61983 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61984 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61985 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61986 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61987 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61988 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61989 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61990 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61991 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61992 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61993 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61994 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61995 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61996 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61997 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61998 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61999 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62000 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62001 +#define GR_TIME_MSG "time set by "
62002 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62003 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62004 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62005 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62006 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62007 +#define GR_BIND_MSG "denied bind() by "
62008 +#define GR_CONNECT_MSG "denied connect() by "
62009 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62010 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62011 +#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"
62012 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62013 +#define GR_CAP_ACL_MSG "use of %s denied for "
62014 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62015 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62016 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62017 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62018 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62019 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62020 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62021 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62022 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62023 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62024 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62025 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62026 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62027 +#define GR_VM86_MSG "denied use of vm86 by "
62028 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62029 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62030 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62031 new file mode 100644
62032 index 0000000..4620f36
62033 --- /dev/null
62034 +++ b/include/linux/grsecurity.h
62035 @@ -0,0 +1,231 @@
62036 +#ifndef GR_SECURITY_H
62037 +#define GR_SECURITY_H
62038 +#include <linux/fs.h>
62039 +#include <linux/fs_struct.h>
62040 +#include <linux/binfmts.h>
62041 +#include <linux/gracl.h>
62042 +
62043 +/* notify of brain-dead configs */
62044 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62045 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62046 +#endif
62047 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62048 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62049 +#endif
62050 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
62051 +#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
62052 +#endif
62053 +#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
62054 +#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
62055 +#endif
62056 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62057 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62058 +#endif
62059 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62060 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62061 +#endif
62062 +
62063 +#include <linux/compat.h>
62064 +
62065 +struct user_arg_ptr {
62066 +#ifdef CONFIG_COMPAT
62067 + bool is_compat;
62068 +#endif
62069 + union {
62070 + const char __user *const __user *native;
62071 +#ifdef CONFIG_COMPAT
62072 + compat_uptr_t __user *compat;
62073 +#endif
62074 + } ptr;
62075 +};
62076 +
62077 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62078 +void gr_handle_brute_check(void);
62079 +void gr_handle_kernel_exploit(void);
62080 +int gr_process_user_ban(void);
62081 +
62082 +char gr_roletype_to_char(void);
62083 +
62084 +int gr_acl_enable_at_secure(void);
62085 +
62086 +int gr_check_user_change(int real, int effective, int fs);
62087 +int gr_check_group_change(int real, int effective, int fs);
62088 +
62089 +void gr_del_task_from_ip_table(struct task_struct *p);
62090 +
62091 +int gr_pid_is_chrooted(struct task_struct *p);
62092 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62093 +int gr_handle_chroot_nice(void);
62094 +int gr_handle_chroot_sysctl(const int op);
62095 +int gr_handle_chroot_setpriority(struct task_struct *p,
62096 + const int niceval);
62097 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62098 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62099 + const struct vfsmount *mnt);
62100 +void gr_handle_chroot_chdir(struct path *path);
62101 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62102 + const struct vfsmount *mnt, const int mode);
62103 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62104 + const struct vfsmount *mnt, const int mode);
62105 +int gr_handle_chroot_mount(const struct dentry *dentry,
62106 + const struct vfsmount *mnt,
62107 + const char *dev_name);
62108 +int gr_handle_chroot_pivot(void);
62109 +int gr_handle_chroot_unix(const pid_t pid);
62110 +
62111 +int gr_handle_rawio(const struct inode *inode);
62112 +
62113 +void gr_handle_ioperm(void);
62114 +void gr_handle_iopl(void);
62115 +
62116 +int gr_tpe_allow(const struct file *file);
62117 +
62118 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62119 +void gr_clear_chroot_entries(struct task_struct *task);
62120 +
62121 +void gr_log_forkfail(const int retval);
62122 +void gr_log_timechange(void);
62123 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62124 +void gr_log_chdir(const struct dentry *dentry,
62125 + const struct vfsmount *mnt);
62126 +void gr_log_chroot_exec(const struct dentry *dentry,
62127 + const struct vfsmount *mnt);
62128 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62129 +void gr_log_remount(const char *devname, const int retval);
62130 +void gr_log_unmount(const char *devname, const int retval);
62131 +void gr_log_mount(const char *from, const char *to, const int retval);
62132 +void gr_log_textrel(struct vm_area_struct *vma);
62133 +void gr_log_rwxmmap(struct file *file);
62134 +void gr_log_rwxmprotect(struct file *file);
62135 +
62136 +int gr_handle_follow_link(const struct inode *parent,
62137 + const struct inode *inode,
62138 + const struct dentry *dentry,
62139 + const struct vfsmount *mnt);
62140 +int gr_handle_fifo(const struct dentry *dentry,
62141 + const struct vfsmount *mnt,
62142 + const struct dentry *dir, const int flag,
62143 + const int acc_mode);
62144 +int gr_handle_hardlink(const struct dentry *dentry,
62145 + const struct vfsmount *mnt,
62146 + struct inode *inode,
62147 + const int mode, const char *to);
62148 +
62149 +int gr_is_capable(const int cap);
62150 +int gr_is_capable_nolog(const int cap);
62151 +void gr_learn_resource(const struct task_struct *task, const int limit,
62152 + const unsigned long wanted, const int gt);
62153 +void gr_copy_label(struct task_struct *tsk);
62154 +void gr_handle_crash(struct task_struct *task, const int sig);
62155 +int gr_handle_signal(const struct task_struct *p, const int sig);
62156 +int gr_check_crash_uid(const uid_t uid);
62157 +int gr_check_protected_task(const struct task_struct *task);
62158 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62159 +int gr_acl_handle_mmap(const struct file *file,
62160 + const unsigned long prot);
62161 +int gr_acl_handle_mprotect(const struct file *file,
62162 + const unsigned long prot);
62163 +int gr_check_hidden_task(const struct task_struct *tsk);
62164 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62165 + const struct vfsmount *mnt);
62166 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62167 + const struct vfsmount *mnt);
62168 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62169 + const struct vfsmount *mnt, const int fmode);
62170 +__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
62171 + const struct vfsmount *mnt, mode_t mode);
62172 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62173 + const struct vfsmount *mnt, mode_t mode);
62174 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62175 + const struct vfsmount *mnt);
62176 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62177 + const struct vfsmount *mnt);
62178 +int gr_handle_ptrace(struct task_struct *task, const long request);
62179 +int gr_handle_proc_ptrace(struct task_struct *task);
62180 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62181 + const struct vfsmount *mnt);
62182 +int gr_check_crash_exec(const struct file *filp);
62183 +int gr_acl_is_enabled(void);
62184 +void gr_set_kernel_label(struct task_struct *task);
62185 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62186 + const gid_t gid);
62187 +int gr_set_proc_label(const struct dentry *dentry,
62188 + const struct vfsmount *mnt,
62189 + const int unsafe_share);
62190 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62191 + const struct vfsmount *mnt);
62192 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62193 + const struct vfsmount *mnt, int acc_mode);
62194 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62195 + const struct dentry *p_dentry,
62196 + const struct vfsmount *p_mnt,
62197 + int open_flags, int acc_mode, const int imode);
62198 +void gr_handle_create(const struct dentry *dentry,
62199 + const struct vfsmount *mnt);
62200 +void gr_handle_proc_create(const struct dentry *dentry,
62201 + const struct inode *inode);
62202 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62203 + const struct dentry *parent_dentry,
62204 + const struct vfsmount *parent_mnt,
62205 + const int mode);
62206 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62207 + const struct dentry *parent_dentry,
62208 + const struct vfsmount *parent_mnt);
62209 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62210 + const struct vfsmount *mnt);
62211 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62212 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62213 + const struct vfsmount *mnt);
62214 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62215 + const struct dentry *parent_dentry,
62216 + const struct vfsmount *parent_mnt,
62217 + const char *from);
62218 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62219 + const struct dentry *parent_dentry,
62220 + const struct vfsmount *parent_mnt,
62221 + const struct dentry *old_dentry,
62222 + const struct vfsmount *old_mnt, const char *to);
62223 +int gr_acl_handle_rename(struct dentry *new_dentry,
62224 + struct dentry *parent_dentry,
62225 + const struct vfsmount *parent_mnt,
62226 + struct dentry *old_dentry,
62227 + struct inode *old_parent_inode,
62228 + struct vfsmount *old_mnt, const char *newname);
62229 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62230 + struct dentry *old_dentry,
62231 + struct dentry *new_dentry,
62232 + struct vfsmount *mnt, const __u8 replace);
62233 +__u32 gr_check_link(const struct dentry *new_dentry,
62234 + const struct dentry *parent_dentry,
62235 + const struct vfsmount *parent_mnt,
62236 + const struct dentry *old_dentry,
62237 + const struct vfsmount *old_mnt);
62238 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62239 + const unsigned int namelen, const ino_t ino);
62240 +
62241 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62242 + const struct vfsmount *mnt);
62243 +void gr_acl_handle_exit(void);
62244 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62245 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62246 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62247 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62248 +void gr_audit_ptrace(struct task_struct *task);
62249 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62250 +
62251 +#ifdef CONFIG_GRKERNSEC
62252 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62253 +void gr_handle_vm86(void);
62254 +void gr_handle_mem_readwrite(u64 from, u64 to);
62255 +
62256 +extern int grsec_enable_dmesg;
62257 +extern int grsec_disable_privio;
62258 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62259 +extern int grsec_enable_chroot_findtask;
62260 +#endif
62261 +#ifdef CONFIG_GRKERNSEC_SETXID
62262 +extern int grsec_enable_setxid;
62263 +#endif
62264 +#endif
62265 +
62266 +#endif
62267 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62268 new file mode 100644
62269 index 0000000..e7ffaaf
62270 --- /dev/null
62271 +++ b/include/linux/grsock.h
62272 @@ -0,0 +1,19 @@
62273 +#ifndef __GRSOCK_H
62274 +#define __GRSOCK_H
62275 +
62276 +extern void gr_attach_curr_ip(const struct sock *sk);
62277 +extern int gr_handle_sock_all(const int family, const int type,
62278 + const int protocol);
62279 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62280 +extern int gr_handle_sock_server_other(const struct sock *sck);
62281 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62282 +extern int gr_search_connect(struct socket * sock,
62283 + struct sockaddr_in * addr);
62284 +extern int gr_search_bind(struct socket * sock,
62285 + struct sockaddr_in * addr);
62286 +extern int gr_search_listen(struct socket * sock);
62287 +extern int gr_search_accept(struct socket * sock);
62288 +extern int gr_search_socket(const int domain, const int type,
62289 + const int protocol);
62290 +
62291 +#endif
62292 diff --git a/include/linux/hid.h b/include/linux/hid.h
62293 index 9cf8e7a..5ec94d0 100644
62294 --- a/include/linux/hid.h
62295 +++ b/include/linux/hid.h
62296 @@ -676,7 +676,7 @@ struct hid_ll_driver {
62297 unsigned int code, int value);
62298
62299 int (*parse)(struct hid_device *hdev);
62300 -};
62301 +} __no_const;
62302
62303 #define PM_HINT_FULLON 1<<5
62304 #define PM_HINT_NORMAL 1<<1
62305 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62306 index 3a93f73..b19d0b3 100644
62307 --- a/include/linux/highmem.h
62308 +++ b/include/linux/highmem.h
62309 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
62310 kunmap_atomic(kaddr, KM_USER0);
62311 }
62312
62313 +static inline void sanitize_highpage(struct page *page)
62314 +{
62315 + void *kaddr;
62316 + unsigned long flags;
62317 +
62318 + local_irq_save(flags);
62319 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
62320 + clear_page(kaddr);
62321 + kunmap_atomic(kaddr, KM_CLEARPAGE);
62322 + local_irq_restore(flags);
62323 +}
62324 +
62325 static inline void zero_user_segments(struct page *page,
62326 unsigned start1, unsigned end1,
62327 unsigned start2, unsigned end2)
62328 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62329 index a6c652e..1f5878f 100644
62330 --- a/include/linux/i2c.h
62331 +++ b/include/linux/i2c.h
62332 @@ -346,6 +346,7 @@ struct i2c_algorithm {
62333 /* To determine what the adapter supports */
62334 u32 (*functionality) (struct i2c_adapter *);
62335 };
62336 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62337
62338 /*
62339 * i2c_adapter is the structure used to identify a physical i2c bus along
62340 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62341 index a6deef4..c56a7f2 100644
62342 --- a/include/linux/i2o.h
62343 +++ b/include/linux/i2o.h
62344 @@ -564,7 +564,7 @@ struct i2o_controller {
62345 struct i2o_device *exec; /* Executive */
62346 #if BITS_PER_LONG == 64
62347 spinlock_t context_list_lock; /* lock for context_list */
62348 - atomic_t context_list_counter; /* needed for unique contexts */
62349 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62350 struct list_head context_list; /* list of context id's
62351 and pointers */
62352 #endif
62353 diff --git a/include/linux/init.h b/include/linux/init.h
62354 index 9146f39..885354d 100644
62355 --- a/include/linux/init.h
62356 +++ b/include/linux/init.h
62357 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cmdline);
62358
62359 /* Each module must use one module_init(). */
62360 #define module_init(initfn) \
62361 - static inline initcall_t __inittest(void) \
62362 + static inline __used initcall_t __inittest(void) \
62363 { return initfn; } \
62364 int init_module(void) __attribute__((alias(#initfn)));
62365
62366 /* This is only required if you want to be unloadable. */
62367 #define module_exit(exitfn) \
62368 - static inline exitcall_t __exittest(void) \
62369 + static inline __used exitcall_t __exittest(void) \
62370 { return exitfn; } \
62371 void cleanup_module(void) __attribute__((alias(#exitfn)));
62372
62373 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62374 index d14e058..4162929 100644
62375 --- a/include/linux/init_task.h
62376 +++ b/include/linux/init_task.h
62377 @@ -126,6 +126,12 @@ extern struct cred init_cred;
62378 # define INIT_PERF_EVENTS(tsk)
62379 #endif
62380
62381 +#ifdef CONFIG_X86
62382 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62383 +#else
62384 +#define INIT_TASK_THREAD_INFO
62385 +#endif
62386 +
62387 /*
62388 * INIT_TASK is used to set up the first task table, touch at
62389 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62390 @@ -164,6 +170,7 @@ extern struct cred init_cred;
62391 RCU_INIT_POINTER(.cred, &init_cred), \
62392 .comm = "swapper", \
62393 .thread = INIT_THREAD, \
62394 + INIT_TASK_THREAD_INFO \
62395 .fs = &init_fs, \
62396 .files = &init_files, \
62397 .signal = &init_signals, \
62398 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62399 index 9310c69..6ebb244 100644
62400 --- a/include/linux/intel-iommu.h
62401 +++ b/include/linux/intel-iommu.h
62402 @@ -296,7 +296,7 @@ struct iommu_flush {
62403 u8 fm, u64 type);
62404 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62405 unsigned int size_order, u64 type);
62406 -};
62407 +} __no_const;
62408
62409 enum {
62410 SR_DMAR_FECTL_REG,
62411 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62412 index f51a81b..adfcb44 100644
62413 --- a/include/linux/interrupt.h
62414 +++ b/include/linux/interrupt.h
62415 @@ -425,7 +425,7 @@ enum
62416 /* map softirq index to softirq name. update 'softirq_to_name' in
62417 * kernel/softirq.c when adding a new softirq.
62418 */
62419 -extern char *softirq_to_name[NR_SOFTIRQS];
62420 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62421
62422 /* softirq mask and active fields moved to irq_cpustat_t in
62423 * asm/hardirq.h to get better cache usage. KAO
62424 @@ -433,12 +433,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62425
62426 struct softirq_action
62427 {
62428 - void (*action)(struct softirq_action *);
62429 + void (*action)(void);
62430 };
62431
62432 asmlinkage void do_softirq(void);
62433 asmlinkage void __do_softirq(void);
62434 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62435 +extern void open_softirq(int nr, void (*action)(void));
62436 extern void softirq_init(void);
62437 static inline void __raise_softirq_irqoff(unsigned int nr)
62438 {
62439 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62440 index 0df513b..fe901a2 100644
62441 --- a/include/linux/kallsyms.h
62442 +++ b/include/linux/kallsyms.h
62443 @@ -15,7 +15,8 @@
62444
62445 struct module;
62446
62447 -#ifdef CONFIG_KALLSYMS
62448 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62449 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62450 /* Lookup the address for a symbol. Returns 0 if not found. */
62451 unsigned long kallsyms_lookup_name(const char *name);
62452
62453 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62454 /* Stupid that this does nothing, but I didn't create this mess. */
62455 #define __print_symbol(fmt, addr)
62456 #endif /*CONFIG_KALLSYMS*/
62457 +#else /* when included by kallsyms.c, vsnprintf.c, or
62458 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62459 +extern void __print_symbol(const char *fmt, unsigned long address);
62460 +extern int sprint_backtrace(char *buffer, unsigned long address);
62461 +extern int sprint_symbol(char *buffer, unsigned long address);
62462 +const char *kallsyms_lookup(unsigned long addr,
62463 + unsigned long *symbolsize,
62464 + unsigned long *offset,
62465 + char **modname, char *namebuf);
62466 +#endif
62467
62468 /* This macro allows us to keep printk typechecking */
62469 static void __check_printsym_format(const char *fmt, ...)
62470 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62471 index fa39183..40160be 100644
62472 --- a/include/linux/kgdb.h
62473 +++ b/include/linux/kgdb.h
62474 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62475 extern int kgdb_io_module_registered;
62476
62477 extern atomic_t kgdb_setting_breakpoint;
62478 -extern atomic_t kgdb_cpu_doing_single_step;
62479 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62480
62481 extern struct task_struct *kgdb_usethread;
62482 extern struct task_struct *kgdb_contthread;
62483 @@ -251,7 +251,7 @@ struct kgdb_arch {
62484 void (*disable_hw_break)(struct pt_regs *regs);
62485 void (*remove_all_hw_break)(void);
62486 void (*correct_hw_break)(void);
62487 -};
62488 +} __do_const;
62489
62490 /**
62491 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62492 @@ -276,7 +276,7 @@ struct kgdb_io {
62493 void (*pre_exception) (void);
62494 void (*post_exception) (void);
62495 int is_console;
62496 -};
62497 +} __do_const;
62498
62499 extern struct kgdb_arch arch_kgdb_ops;
62500
62501 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62502 index 0da38cf..d23f05f 100644
62503 --- a/include/linux/kmod.h
62504 +++ b/include/linux/kmod.h
62505 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62506 * usually useless though. */
62507 extern int __request_module(bool wait, const char *name, ...) \
62508 __attribute__((format(printf, 2, 3)));
62509 +extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
62510 + __attribute__((format(printf, 3, 4)));
62511 #define request_module(mod...) __request_module(true, mod)
62512 #define request_module_nowait(mod...) __request_module(false, mod)
62513 #define try_then_request_module(x, mod...) \
62514 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62515 index eabb21a..3f030f4 100644
62516 --- a/include/linux/kvm_host.h
62517 +++ b/include/linux/kvm_host.h
62518 @@ -308,7 +308,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62519 void vcpu_load(struct kvm_vcpu *vcpu);
62520 void vcpu_put(struct kvm_vcpu *vcpu);
62521
62522 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62523 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62524 struct module *module);
62525 void kvm_exit(void);
62526
62527 @@ -454,7 +454,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62528 struct kvm_guest_debug *dbg);
62529 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62530
62531 -int kvm_arch_init(void *opaque);
62532 +int kvm_arch_init(const void *opaque);
62533 void kvm_arch_exit(void);
62534
62535 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62536 diff --git a/include/linux/libata.h b/include/linux/libata.h
62537 index efd6f98..5f5fd37 100644
62538 --- a/include/linux/libata.h
62539 +++ b/include/linux/libata.h
62540 @@ -909,7 +909,7 @@ struct ata_port_operations {
62541 * fields must be pointers.
62542 */
62543 const struct ata_port_operations *inherits;
62544 -};
62545 +} __do_const;
62546
62547 struct ata_port_info {
62548 unsigned long flags;
62549 diff --git a/include/linux/mca.h b/include/linux/mca.h
62550 index 3797270..7765ede 100644
62551 --- a/include/linux/mca.h
62552 +++ b/include/linux/mca.h
62553 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
62554 int region);
62555 void * (*mca_transform_memory)(struct mca_device *,
62556 void *memory);
62557 -};
62558 +} __no_const;
62559
62560 struct mca_bus {
62561 u64 default_dma_mask;
62562 diff --git a/include/linux/memory.h b/include/linux/memory.h
62563 index 935699b..11042cc 100644
62564 --- a/include/linux/memory.h
62565 +++ b/include/linux/memory.h
62566 @@ -144,7 +144,7 @@ struct memory_accessor {
62567 size_t count);
62568 ssize_t (*write)(struct memory_accessor *, const char *buf,
62569 off_t offset, size_t count);
62570 -};
62571 +} __no_const;
62572
62573 /*
62574 * Kernel text modification mutex, used for code patching. Users of this lock
62575 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62576 index 896b5e4..1159ad0 100644
62577 --- a/include/linux/mfd/abx500.h
62578 +++ b/include/linux/mfd/abx500.h
62579 @@ -234,6 +234,7 @@ struct abx500_ops {
62580 int (*event_registers_startup_state_get) (struct device *, u8 *);
62581 int (*startup_irq_enabled) (struct device *, unsigned int);
62582 };
62583 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62584
62585 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62586 void abx500_remove_ops(struct device *dev);
62587 diff --git a/include/linux/mm.h b/include/linux/mm.h
62588 index fedc5f0..7cedb6d 100644
62589 --- a/include/linux/mm.h
62590 +++ b/include/linux/mm.h
62591 @@ -114,7 +114,14 @@ extern unsigned int kobjsize(const void *objp);
62592
62593 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62594 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62595 +
62596 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62597 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62598 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62599 +#else
62600 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62601 +#endif
62602 +
62603 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62604 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62605
62606 @@ -1011,34 +1018,6 @@ int set_page_dirty(struct page *page);
62607 int set_page_dirty_lock(struct page *page);
62608 int clear_page_dirty_for_io(struct page *page);
62609
62610 -/* Is the vma a continuation of the stack vma above it? */
62611 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62612 -{
62613 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62614 -}
62615 -
62616 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62617 - unsigned long addr)
62618 -{
62619 - return (vma->vm_flags & VM_GROWSDOWN) &&
62620 - (vma->vm_start == addr) &&
62621 - !vma_growsdown(vma->vm_prev, addr);
62622 -}
62623 -
62624 -/* Is the vma a continuation of the stack vma below it? */
62625 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62626 -{
62627 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62628 -}
62629 -
62630 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62631 - unsigned long addr)
62632 -{
62633 - return (vma->vm_flags & VM_GROWSUP) &&
62634 - (vma->vm_end == addr) &&
62635 - !vma_growsup(vma->vm_next, addr);
62636 -}
62637 -
62638 extern unsigned long move_page_tables(struct vm_area_struct *vma,
62639 unsigned long old_addr, struct vm_area_struct *new_vma,
62640 unsigned long new_addr, unsigned long len);
62641 @@ -1133,6 +1112,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
62642 }
62643 #endif
62644
62645 +#ifdef CONFIG_MMU
62646 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62647 +#else
62648 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62649 +{
62650 + return __pgprot(0);
62651 +}
62652 +#endif
62653 +
62654 int vma_wants_writenotify(struct vm_area_struct *vma);
62655
62656 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62657 @@ -1417,6 +1405,7 @@ out:
62658 }
62659
62660 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62661 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62662
62663 extern unsigned long do_brk(unsigned long, unsigned long);
62664
62665 @@ -1474,6 +1463,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62666 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62667 struct vm_area_struct **pprev);
62668
62669 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62670 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62671 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62672 +
62673 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62674 NULL if none. Assume start_addr < end_addr. */
62675 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62676 @@ -1490,15 +1483,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
62677 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
62678 }
62679
62680 -#ifdef CONFIG_MMU
62681 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62682 -#else
62683 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62684 -{
62685 - return __pgprot(0);
62686 -}
62687 -#endif
62688 -
62689 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62690 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62691 unsigned long pfn, unsigned long size, pgprot_t);
62692 @@ -1612,7 +1596,7 @@ extern int unpoison_memory(unsigned long pfn);
62693 extern int sysctl_memory_failure_early_kill;
62694 extern int sysctl_memory_failure_recovery;
62695 extern void shake_page(struct page *p, int access);
62696 -extern atomic_long_t mce_bad_pages;
62697 +extern atomic_long_unchecked_t mce_bad_pages;
62698 extern int soft_offline_page(struct page *page, int flags);
62699
62700 extern void dump_page(struct page *page);
62701 @@ -1626,5 +1610,11 @@ extern void copy_user_huge_page(struct page *dst, struct page *src,
62702 unsigned int pages_per_huge_page);
62703 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
62704
62705 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62706 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62707 +#else
62708 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62709 +#endif
62710 +
62711 #endif /* __KERNEL__ */
62712 #endif /* _LINUX_MM_H */
62713 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62714 index 10a2f62..d655142 100644
62715 --- a/include/linux/mm_types.h
62716 +++ b/include/linux/mm_types.h
62717 @@ -230,6 +230,8 @@ struct vm_area_struct {
62718 #ifdef CONFIG_NUMA
62719 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62720 #endif
62721 +
62722 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62723 };
62724
62725 struct core_thread {
62726 @@ -362,6 +364,24 @@ struct mm_struct {
62727 #ifdef CONFIG_CPUMASK_OFFSTACK
62728 struct cpumask cpumask_allocation;
62729 #endif
62730 +
62731 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62732 + unsigned long pax_flags;
62733 +#endif
62734 +
62735 +#ifdef CONFIG_PAX_DLRESOLVE
62736 + unsigned long call_dl_resolve;
62737 +#endif
62738 +
62739 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62740 + unsigned long call_syscall;
62741 +#endif
62742 +
62743 +#ifdef CONFIG_PAX_ASLR
62744 + unsigned long delta_mmap; /* randomized offset */
62745 + unsigned long delta_stack; /* randomized offset */
62746 +#endif
62747 +
62748 };
62749
62750 static inline void mm_init_cpumask(struct mm_struct *mm)
62751 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62752 index 1d1b1e1..2a13c78 100644
62753 --- a/include/linux/mmu_notifier.h
62754 +++ b/include/linux/mmu_notifier.h
62755 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62756 */
62757 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62758 ({ \
62759 - pte_t __pte; \
62760 + pte_t ___pte; \
62761 struct vm_area_struct *___vma = __vma; \
62762 unsigned long ___address = __address; \
62763 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62764 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62765 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62766 - __pte; \
62767 + ___pte; \
62768 })
62769
62770 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62771 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62772 index be1ac8d..26868ce 100644
62773 --- a/include/linux/mmzone.h
62774 +++ b/include/linux/mmzone.h
62775 @@ -356,7 +356,7 @@ struct zone {
62776 unsigned long flags; /* zone flags, see below */
62777
62778 /* Zone statistics */
62779 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62780 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62781
62782 /*
62783 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62784 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62785 index ae28e93..1ac2233 100644
62786 --- a/include/linux/mod_devicetable.h
62787 +++ b/include/linux/mod_devicetable.h
62788 @@ -12,7 +12,7 @@
62789 typedef unsigned long kernel_ulong_t;
62790 #endif
62791
62792 -#define PCI_ANY_ID (~0)
62793 +#define PCI_ANY_ID ((__u16)~0)
62794
62795 struct pci_device_id {
62796 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62797 @@ -131,7 +131,7 @@ struct usb_device_id {
62798 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62799 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62800
62801 -#define HID_ANY_ID (~0)
62802 +#define HID_ANY_ID (~0U)
62803
62804 struct hid_device_id {
62805 __u16 bus;
62806 diff --git a/include/linux/module.h b/include/linux/module.h
62807 index 1c30087..fc2a442 100644
62808 --- a/include/linux/module.h
62809 +++ b/include/linux/module.h
62810 @@ -16,6 +16,7 @@
62811 #include <linux/kobject.h>
62812 #include <linux/moduleparam.h>
62813 #include <linux/tracepoint.h>
62814 +#include <linux/fs.h>
62815
62816 #include <linux/percpu.h>
62817 #include <asm/module.h>
62818 @@ -327,19 +328,16 @@ struct module
62819 int (*init)(void);
62820
62821 /* If this is non-NULL, vfree after init() returns */
62822 - void *module_init;
62823 + void *module_init_rx, *module_init_rw;
62824
62825 /* Here is the actual code + data, vfree'd on unload. */
62826 - void *module_core;
62827 + void *module_core_rx, *module_core_rw;
62828
62829 /* Here are the sizes of the init and core sections */
62830 - unsigned int init_size, core_size;
62831 + unsigned int init_size_rw, core_size_rw;
62832
62833 /* The size of the executable code in each section. */
62834 - unsigned int init_text_size, core_text_size;
62835 -
62836 - /* Size of RO sections of the module (text+rodata) */
62837 - unsigned int init_ro_size, core_ro_size;
62838 + unsigned int init_size_rx, core_size_rx;
62839
62840 /* Arch-specific module values */
62841 struct mod_arch_specific arch;
62842 @@ -395,6 +393,10 @@ struct module
62843 #ifdef CONFIG_EVENT_TRACING
62844 struct ftrace_event_call **trace_events;
62845 unsigned int num_trace_events;
62846 + struct file_operations trace_id;
62847 + struct file_operations trace_enable;
62848 + struct file_operations trace_format;
62849 + struct file_operations trace_filter;
62850 #endif
62851 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62852 unsigned int num_ftrace_callsites;
62853 @@ -445,16 +447,46 @@ bool is_module_address(unsigned long addr);
62854 bool is_module_percpu_address(unsigned long addr);
62855 bool is_module_text_address(unsigned long addr);
62856
62857 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62858 +{
62859 +
62860 +#ifdef CONFIG_PAX_KERNEXEC
62861 + if (ktla_ktva(addr) >= (unsigned long)start &&
62862 + ktla_ktva(addr) < (unsigned long)start + size)
62863 + return 1;
62864 +#endif
62865 +
62866 + return ((void *)addr >= start && (void *)addr < start + size);
62867 +}
62868 +
62869 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62870 +{
62871 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62872 +}
62873 +
62874 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62875 +{
62876 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62877 +}
62878 +
62879 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62880 +{
62881 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62882 +}
62883 +
62884 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62885 +{
62886 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62887 +}
62888 +
62889 static inline int within_module_core(unsigned long addr, struct module *mod)
62890 {
62891 - return (unsigned long)mod->module_core <= addr &&
62892 - addr < (unsigned long)mod->module_core + mod->core_size;
62893 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62894 }
62895
62896 static inline int within_module_init(unsigned long addr, struct module *mod)
62897 {
62898 - return (unsigned long)mod->module_init <= addr &&
62899 - addr < (unsigned long)mod->module_init + mod->init_size;
62900 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62901 }
62902
62903 /* Search for module by name: must hold module_mutex. */
62904 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62905 index b2be02e..6a9fdb1 100644
62906 --- a/include/linux/moduleloader.h
62907 +++ b/include/linux/moduleloader.h
62908 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62909 sections. Returns NULL on failure. */
62910 void *module_alloc(unsigned long size);
62911
62912 +#ifdef CONFIG_PAX_KERNEXEC
62913 +void *module_alloc_exec(unsigned long size);
62914 +#else
62915 +#define module_alloc_exec(x) module_alloc(x)
62916 +#endif
62917 +
62918 /* Free memory returned from module_alloc. */
62919 void module_free(struct module *mod, void *module_region);
62920
62921 +#ifdef CONFIG_PAX_KERNEXEC
62922 +void module_free_exec(struct module *mod, void *module_region);
62923 +#else
62924 +#define module_free_exec(x, y) module_free((x), (y))
62925 +#endif
62926 +
62927 /* Apply the given relocation to the (simplified) ELF. Return -error
62928 or 0. */
62929 int apply_relocate(Elf_Shdr *sechdrs,
62930 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62931 index ddaae98..3c70938 100644
62932 --- a/include/linux/moduleparam.h
62933 +++ b/include/linux/moduleparam.h
62934 @@ -255,7 +255,7 @@ static inline void __kernel_param_unlock(void)
62935 * @len is usually just sizeof(string).
62936 */
62937 #define module_param_string(name, string, len, perm) \
62938 - static const struct kparam_string __param_string_##name \
62939 + static const struct kparam_string __param_string_##name __used \
62940 = { len, string }; \
62941 __module_param_call(MODULE_PARAM_PREFIX, name, \
62942 &param_ops_string, \
62943 @@ -370,7 +370,7 @@ extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
62944 * module_param_named() for why this might be necessary.
62945 */
62946 #define module_param_array_named(name, array, type, nump, perm) \
62947 - static const struct kparam_array __param_arr_##name \
62948 + static const struct kparam_array __param_arr_##name __used \
62949 = { .max = ARRAY_SIZE(array), .num = nump, \
62950 .ops = &param_ops_##type, \
62951 .elemsize = sizeof(array[0]), .elem = array }; \
62952 diff --git a/include/linux/namei.h b/include/linux/namei.h
62953 index ffc0213..2c1f2cb 100644
62954 --- a/include/linux/namei.h
62955 +++ b/include/linux/namei.h
62956 @@ -24,7 +24,7 @@ struct nameidata {
62957 unsigned seq;
62958 int last_type;
62959 unsigned depth;
62960 - char *saved_names[MAX_NESTED_LINKS + 1];
62961 + const char *saved_names[MAX_NESTED_LINKS + 1];
62962
62963 /* Intent data */
62964 union {
62965 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62966 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62967 extern void unlock_rename(struct dentry *, struct dentry *);
62968
62969 -static inline void nd_set_link(struct nameidata *nd, char *path)
62970 +static inline void nd_set_link(struct nameidata *nd, const char *path)
62971 {
62972 nd->saved_names[nd->depth] = path;
62973 }
62974
62975 -static inline char *nd_get_link(struct nameidata *nd)
62976 +static inline const char *nd_get_link(const struct nameidata *nd)
62977 {
62978 return nd->saved_names[nd->depth];
62979 }
62980 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62981 index ddee79b..67af106 100644
62982 --- a/include/linux/netdevice.h
62983 +++ b/include/linux/netdevice.h
62984 @@ -944,6 +944,7 @@ struct net_device_ops {
62985 int (*ndo_set_features)(struct net_device *dev,
62986 u32 features);
62987 };
62988 +typedef struct net_device_ops __no_const net_device_ops_no_const;
62989
62990 /*
62991 * The DEVICE structure.
62992 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62993 new file mode 100644
62994 index 0000000..33f4af8
62995 --- /dev/null
62996 +++ b/include/linux/netfilter/xt_gradm.h
62997 @@ -0,0 +1,9 @@
62998 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
62999 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63000 +
63001 +struct xt_gradm_mtinfo {
63002 + __u16 flags;
63003 + __u16 invflags;
63004 +};
63005 +
63006 +#endif
63007 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63008 index c65a18a..0c05f3a 100644
63009 --- a/include/linux/of_pdt.h
63010 +++ b/include/linux/of_pdt.h
63011 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63012
63013 /* return 0 on success; fill in 'len' with number of bytes in path */
63014 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63015 -};
63016 +} __no_const;
63017
63018 extern void *prom_early_alloc(unsigned long size);
63019
63020 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63021 index 49c8727..34d2ae1 100644
63022 --- a/include/linux/oprofile.h
63023 +++ b/include/linux/oprofile.h
63024 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63025 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63026 char const * name, ulong * val);
63027
63028 -/** Create a file for read-only access to an atomic_t. */
63029 +/** Create a file for read-only access to an atomic_unchecked_t. */
63030 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63031 - char const * name, atomic_t * val);
63032 + char const * name, atomic_unchecked_t * val);
63033
63034 /** create a directory */
63035 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63036 diff --git a/include/linux/padata.h b/include/linux/padata.h
63037 index 4633b2f..988bc08 100644
63038 --- a/include/linux/padata.h
63039 +++ b/include/linux/padata.h
63040 @@ -129,7 +129,7 @@ struct parallel_data {
63041 struct padata_instance *pinst;
63042 struct padata_parallel_queue __percpu *pqueue;
63043 struct padata_serial_queue __percpu *squeue;
63044 - atomic_t seq_nr;
63045 + atomic_unchecked_t seq_nr;
63046 atomic_t reorder_objects;
63047 atomic_t refcnt;
63048 unsigned int max_seq_nr;
63049 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63050 index c816075..cd28c4d 100644
63051 --- a/include/linux/perf_event.h
63052 +++ b/include/linux/perf_event.h
63053 @@ -745,8 +745,8 @@ struct perf_event {
63054
63055 enum perf_event_active_state state;
63056 unsigned int attach_state;
63057 - local64_t count;
63058 - atomic64_t child_count;
63059 + local64_t count; /* PaX: fix it one day */
63060 + atomic64_unchecked_t child_count;
63061
63062 /*
63063 * These are the total time in nanoseconds that the event
63064 @@ -797,8 +797,8 @@ struct perf_event {
63065 * These accumulate total time (in nanoseconds) that children
63066 * events have been enabled and running, respectively.
63067 */
63068 - atomic64_t child_total_time_enabled;
63069 - atomic64_t child_total_time_running;
63070 + atomic64_unchecked_t child_total_time_enabled;
63071 + atomic64_unchecked_t child_total_time_running;
63072
63073 /*
63074 * Protect attach/detach and child_list:
63075 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63076 index 77257c9..51d473a 100644
63077 --- a/include/linux/pipe_fs_i.h
63078 +++ b/include/linux/pipe_fs_i.h
63079 @@ -46,9 +46,9 @@ struct pipe_buffer {
63080 struct pipe_inode_info {
63081 wait_queue_head_t wait;
63082 unsigned int nrbufs, curbuf, buffers;
63083 - unsigned int readers;
63084 - unsigned int writers;
63085 - unsigned int waiting_writers;
63086 + atomic_t readers;
63087 + atomic_t writers;
63088 + atomic_t waiting_writers;
63089 unsigned int r_counter;
63090 unsigned int w_counter;
63091 struct page *tmp_page;
63092 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63093 index daac05d..c6802ce 100644
63094 --- a/include/linux/pm_runtime.h
63095 +++ b/include/linux/pm_runtime.h
63096 @@ -99,7 +99,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63097
63098 static inline void pm_runtime_mark_last_busy(struct device *dev)
63099 {
63100 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63101 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63102 }
63103
63104 #else /* !CONFIG_PM_RUNTIME */
63105 diff --git a/include/linux/poison.h b/include/linux/poison.h
63106 index 79159de..f1233a9 100644
63107 --- a/include/linux/poison.h
63108 +++ b/include/linux/poison.h
63109 @@ -19,8 +19,8 @@
63110 * under normal circumstances, used to verify that nobody uses
63111 * non-initialized list entries.
63112 */
63113 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63114 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63115 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63116 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63117
63118 /********** include/linux/timer.h **********/
63119 /*
63120 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63121 index 58969b2..ead129b 100644
63122 --- a/include/linux/preempt.h
63123 +++ b/include/linux/preempt.h
63124 @@ -123,7 +123,7 @@ struct preempt_ops {
63125 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63126 void (*sched_out)(struct preempt_notifier *notifier,
63127 struct task_struct *next);
63128 -};
63129 +} __no_const;
63130
63131 /**
63132 * preempt_notifier - key for installing preemption notifiers
63133 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63134 index 643b96c..ef55a9c 100644
63135 --- a/include/linux/proc_fs.h
63136 +++ b/include/linux/proc_fs.h
63137 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
63138 return proc_create_data(name, mode, parent, proc_fops, NULL);
63139 }
63140
63141 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
63142 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63143 +{
63144 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63145 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63146 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63147 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63148 +#else
63149 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63150 +#endif
63151 +}
63152 +
63153 +
63154 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63155 mode_t mode, struct proc_dir_entry *base,
63156 read_proc_t *read_proc, void * data)
63157 @@ -258,7 +271,7 @@ union proc_op {
63158 int (*proc_show)(struct seq_file *m,
63159 struct pid_namespace *ns, struct pid *pid,
63160 struct task_struct *task);
63161 -};
63162 +} __no_const;
63163
63164 struct ctl_table_header;
63165 struct ctl_table;
63166 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
63167 index 800f113..af90cc8 100644
63168 --- a/include/linux/ptrace.h
63169 +++ b/include/linux/ptrace.h
63170 @@ -129,10 +129,10 @@ extern void __ptrace_unlink(struct task_struct *child);
63171 extern void exit_ptrace(struct task_struct *tracer);
63172 #define PTRACE_MODE_READ 1
63173 #define PTRACE_MODE_ATTACH 2
63174 -/* Returns 0 on success, -errno on denial. */
63175 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
63176 /* Returns true on success, false on denial. */
63177 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
63178 +/* Returns true on success, false on denial. */
63179 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
63180
63181 static inline int ptrace_reparented(struct task_struct *child)
63182 {
63183 diff --git a/include/linux/random.h b/include/linux/random.h
63184 index d13059f..2eaafaa 100644
63185 --- a/include/linux/random.h
63186 +++ b/include/linux/random.h
63187 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
63188
63189 u32 prandom32(struct rnd_state *);
63190
63191 +static inline unsigned long pax_get_random_long(void)
63192 +{
63193 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63194 +}
63195 +
63196 /*
63197 * Handle minimum values for seeds
63198 */
63199 static inline u32 __seed(u32 x, u32 m)
63200 {
63201 - return (x < m) ? x + m : x;
63202 + return (x <= m) ? x + m + 1 : x;
63203 }
63204
63205 /**
63206 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63207 index e0879a7..a12f962 100644
63208 --- a/include/linux/reboot.h
63209 +++ b/include/linux/reboot.h
63210 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63211 * Architecture-specific implementations of sys_reboot commands.
63212 */
63213
63214 -extern void machine_restart(char *cmd);
63215 -extern void machine_halt(void);
63216 -extern void machine_power_off(void);
63217 +extern void machine_restart(char *cmd) __noreturn;
63218 +extern void machine_halt(void) __noreturn;
63219 +extern void machine_power_off(void) __noreturn;
63220
63221 extern void machine_shutdown(void);
63222 struct pt_regs;
63223 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63224 */
63225
63226 extern void kernel_restart_prepare(char *cmd);
63227 -extern void kernel_restart(char *cmd);
63228 -extern void kernel_halt(void);
63229 -extern void kernel_power_off(void);
63230 +extern void kernel_restart(char *cmd) __noreturn;
63231 +extern void kernel_halt(void) __noreturn;
63232 +extern void kernel_power_off(void) __noreturn;
63233
63234 extern int C_A_D; /* for sysctl */
63235 void ctrl_alt_del(void);
63236 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63237 * Emergency restart, callable from an interrupt handler.
63238 */
63239
63240 -extern void emergency_restart(void);
63241 +extern void emergency_restart(void) __noreturn;
63242 #include <asm/emergency-restart.h>
63243
63244 #endif
63245 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
63246 index 96d465f..b084e05 100644
63247 --- a/include/linux/reiserfs_fs.h
63248 +++ b/include/linux/reiserfs_fs.h
63249 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63250 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63251
63252 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63253 -#define get_generation(s) atomic_read (&fs_generation(s))
63254 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63255 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63256 #define __fs_changed(gen,s) (gen != get_generation (s))
63257 #define fs_changed(gen,s) \
63258 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
63259 index 52c83b6..18ed7eb 100644
63260 --- a/include/linux/reiserfs_fs_sb.h
63261 +++ b/include/linux/reiserfs_fs_sb.h
63262 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
63263 /* Comment? -Hans */
63264 wait_queue_head_t s_wait;
63265 /* To be obsoleted soon by per buffer seals.. -Hans */
63266 - atomic_t s_generation_counter; // increased by one every time the
63267 + atomic_unchecked_t s_generation_counter; // increased by one every time the
63268 // tree gets re-balanced
63269 unsigned long s_properties; /* File system properties. Currently holds
63270 on-disk FS format */
63271 diff --git a/include/linux/relay.h b/include/linux/relay.h
63272 index 14a86bc..17d0700 100644
63273 --- a/include/linux/relay.h
63274 +++ b/include/linux/relay.h
63275 @@ -159,7 +159,7 @@ struct rchan_callbacks
63276 * The callback should return 0 if successful, negative if not.
63277 */
63278 int (*remove_buf_file)(struct dentry *dentry);
63279 -};
63280 +} __no_const;
63281
63282 /*
63283 * CONFIG_RELAY kernel API, kernel/relay.c
63284 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63285 index c6c6084..5bf1212 100644
63286 --- a/include/linux/rfkill.h
63287 +++ b/include/linux/rfkill.h
63288 @@ -147,6 +147,7 @@ struct rfkill_ops {
63289 void (*query)(struct rfkill *rfkill, void *data);
63290 int (*set_block)(void *data, bool blocked);
63291 };
63292 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63293
63294 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63295 /**
63296 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63297 index 2148b12..519b820 100644
63298 --- a/include/linux/rmap.h
63299 +++ b/include/linux/rmap.h
63300 @@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63301 void anon_vma_init(void); /* create anon_vma_cachep */
63302 int anon_vma_prepare(struct vm_area_struct *);
63303 void unlink_anon_vmas(struct vm_area_struct *);
63304 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63305 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63306 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63307 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63308 void __anon_vma_link(struct vm_area_struct *);
63309
63310 static inline void anon_vma_merge(struct vm_area_struct *vma,
63311 diff --git a/include/linux/sched.h b/include/linux/sched.h
63312 index 41d0237..5a64056 100644
63313 --- a/include/linux/sched.h
63314 +++ b/include/linux/sched.h
63315 @@ -100,6 +100,7 @@ struct bio_list;
63316 struct fs_struct;
63317 struct perf_event_context;
63318 struct blk_plug;
63319 +struct linux_binprm;
63320
63321 /*
63322 * List of flags we want to share for kernel threads,
63323 @@ -380,10 +381,13 @@ struct user_namespace;
63324 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63325
63326 extern int sysctl_max_map_count;
63327 +extern unsigned long sysctl_heap_stack_gap;
63328
63329 #include <linux/aio.h>
63330
63331 #ifdef CONFIG_MMU
63332 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63333 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63334 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63335 extern unsigned long
63336 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63337 @@ -629,6 +633,17 @@ struct signal_struct {
63338 #ifdef CONFIG_TASKSTATS
63339 struct taskstats *stats;
63340 #endif
63341 +
63342 +#ifdef CONFIG_GRKERNSEC
63343 + u32 curr_ip;
63344 + u32 saved_ip;
63345 + u32 gr_saddr;
63346 + u32 gr_daddr;
63347 + u16 gr_sport;
63348 + u16 gr_dport;
63349 + u8 used_accept:1;
63350 +#endif
63351 +
63352 #ifdef CONFIG_AUDIT
63353 unsigned audit_tty;
63354 struct tty_audit_buf *tty_audit_buf;
63355 @@ -710,6 +725,11 @@ struct user_struct {
63356 struct key *session_keyring; /* UID's default session keyring */
63357 #endif
63358
63359 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63360 + unsigned int banned;
63361 + unsigned long ban_expires;
63362 +#endif
63363 +
63364 /* Hash table maintenance information */
63365 struct hlist_node uidhash_node;
63366 uid_t uid;
63367 @@ -1340,8 +1360,8 @@ struct task_struct {
63368 struct list_head thread_group;
63369
63370 struct completion *vfork_done; /* for vfork() */
63371 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63372 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63373 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63374 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63375
63376 cputime_t utime, stime, utimescaled, stimescaled;
63377 cputime_t gtime;
63378 @@ -1357,13 +1377,6 @@ struct task_struct {
63379 struct task_cputime cputime_expires;
63380 struct list_head cpu_timers[3];
63381
63382 -/* process credentials */
63383 - const struct cred __rcu *real_cred; /* objective and real subjective task
63384 - * credentials (COW) */
63385 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63386 - * credentials (COW) */
63387 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63388 -
63389 char comm[TASK_COMM_LEN]; /* executable name excluding path
63390 - access with [gs]et_task_comm (which lock
63391 it with task_lock())
63392 @@ -1380,8 +1393,16 @@ struct task_struct {
63393 #endif
63394 /* CPU-specific state of this task */
63395 struct thread_struct thread;
63396 +/* thread_info moved to task_struct */
63397 +#ifdef CONFIG_X86
63398 + struct thread_info tinfo;
63399 +#endif
63400 /* filesystem information */
63401 struct fs_struct *fs;
63402 +
63403 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63404 + * credentials (COW) */
63405 +
63406 /* open file information */
63407 struct files_struct *files;
63408 /* namespaces */
63409 @@ -1428,6 +1449,11 @@ struct task_struct {
63410 struct rt_mutex_waiter *pi_blocked_on;
63411 #endif
63412
63413 +/* process credentials */
63414 + const struct cred __rcu *real_cred; /* objective and real subjective task
63415 + * credentials (COW) */
63416 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63417 +
63418 #ifdef CONFIG_DEBUG_MUTEXES
63419 /* mutex deadlock detection */
63420 struct mutex_waiter *blocked_on;
63421 @@ -1537,6 +1563,21 @@ struct task_struct {
63422 unsigned long default_timer_slack_ns;
63423
63424 struct list_head *scm_work_list;
63425 +
63426 +#ifdef CONFIG_GRKERNSEC
63427 + /* grsecurity */
63428 + struct dentry *gr_chroot_dentry;
63429 + struct acl_subject_label *acl;
63430 + struct acl_role_label *role;
63431 + struct file *exec_file;
63432 + u16 acl_role_id;
63433 + /* is this the task that authenticated to the special role */
63434 + u8 acl_sp_role;
63435 + u8 is_writable;
63436 + u8 brute;
63437 + u8 gr_is_chrooted;
63438 +#endif
63439 +
63440 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63441 /* Index of current stored address in ret_stack */
63442 int curr_ret_stack;
63443 @@ -1571,6 +1612,57 @@ struct task_struct {
63444 #endif
63445 };
63446
63447 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63448 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63449 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63450 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63451 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63452 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63453 +
63454 +#ifdef CONFIG_PAX_SOFTMODE
63455 +extern int pax_softmode;
63456 +#endif
63457 +
63458 +extern int pax_check_flags(unsigned long *);
63459 +
63460 +/* if tsk != current then task_lock must be held on it */
63461 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63462 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63463 +{
63464 + if (likely(tsk->mm))
63465 + return tsk->mm->pax_flags;
63466 + else
63467 + return 0UL;
63468 +}
63469 +
63470 +/* if tsk != current then task_lock must be held on it */
63471 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63472 +{
63473 + if (likely(tsk->mm)) {
63474 + tsk->mm->pax_flags = flags;
63475 + return 0;
63476 + }
63477 + return -EINVAL;
63478 +}
63479 +#endif
63480 +
63481 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63482 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63483 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63484 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63485 +#endif
63486 +
63487 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63488 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63489 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63490 +extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
63491 +
63492 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
63493 +extern void pax_track_stack(void);
63494 +#else
63495 +static inline void pax_track_stack(void) {}
63496 +#endif
63497 +
63498 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63499 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63500
63501 @@ -2074,7 +2166,9 @@ void yield(void);
63502 extern struct exec_domain default_exec_domain;
63503
63504 union thread_union {
63505 +#ifndef CONFIG_X86
63506 struct thread_info thread_info;
63507 +#endif
63508 unsigned long stack[THREAD_SIZE/sizeof(long)];
63509 };
63510
63511 @@ -2107,6 +2201,7 @@ extern struct pid_namespace init_pid_ns;
63512 */
63513
63514 extern struct task_struct *find_task_by_vpid(pid_t nr);
63515 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63516 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63517 struct pid_namespace *ns);
63518
63519 @@ -2243,7 +2338,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63520 extern void exit_itimers(struct signal_struct *);
63521 extern void flush_itimer_signals(void);
63522
63523 -extern NORET_TYPE void do_group_exit(int);
63524 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
63525
63526 extern void daemonize(const char *, ...);
63527 extern int allow_signal(int);
63528 @@ -2408,13 +2503,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63529
63530 #endif
63531
63532 -static inline int object_is_on_stack(void *obj)
63533 +static inline int object_starts_on_stack(void *obj)
63534 {
63535 - void *stack = task_stack_page(current);
63536 + const void *stack = task_stack_page(current);
63537
63538 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63539 }
63540
63541 +#ifdef CONFIG_PAX_USERCOPY
63542 +extern int object_is_on_stack(const void *obj, unsigned long len);
63543 +#endif
63544 +
63545 extern void thread_info_cache_init(void);
63546
63547 #ifdef CONFIG_DEBUG_STACK_USAGE
63548 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63549 index 899fbb4..1cb4138 100644
63550 --- a/include/linux/screen_info.h
63551 +++ b/include/linux/screen_info.h
63552 @@ -43,7 +43,8 @@ struct screen_info {
63553 __u16 pages; /* 0x32 */
63554 __u16 vesa_attributes; /* 0x34 */
63555 __u32 capabilities; /* 0x36 */
63556 - __u8 _reserved[6]; /* 0x3a */
63557 + __u16 vesapm_size; /* 0x3a */
63558 + __u8 _reserved[4]; /* 0x3c */
63559 } __attribute__((packed));
63560
63561 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63562 diff --git a/include/linux/security.h b/include/linux/security.h
63563 index ebd2a53..2d949ae 100644
63564 --- a/include/linux/security.h
63565 +++ b/include/linux/security.h
63566 @@ -36,6 +36,7 @@
63567 #include <linux/key.h>
63568 #include <linux/xfrm.h>
63569 #include <linux/slab.h>
63570 +#include <linux/grsecurity.h>
63571 #include <net/flow.h>
63572
63573 /* Maximum number of letters for an LSM name string */
63574 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63575 index be720cd..a0e1b94 100644
63576 --- a/include/linux/seq_file.h
63577 +++ b/include/linux/seq_file.h
63578 @@ -33,6 +33,7 @@ struct seq_operations {
63579 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63580 int (*show) (struct seq_file *m, void *v);
63581 };
63582 +typedef struct seq_operations __no_const seq_operations_no_const;
63583
63584 #define SEQ_SKIP 1
63585
63586 diff --git a/include/linux/shm.h b/include/linux/shm.h
63587 index 92808b8..c28cac4 100644
63588 --- a/include/linux/shm.h
63589 +++ b/include/linux/shm.h
63590 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63591
63592 /* The task created the shm object. NULL if the task is dead. */
63593 struct task_struct *shm_creator;
63594 +#ifdef CONFIG_GRKERNSEC
63595 + time_t shm_createtime;
63596 + pid_t shm_lapid;
63597 +#endif
63598 };
63599
63600 /* shm_mode upper byte flags */
63601 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63602 index 0f96646..cfb757a 100644
63603 --- a/include/linux/skbuff.h
63604 +++ b/include/linux/skbuff.h
63605 @@ -610,7 +610,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63606 */
63607 static inline int skb_queue_empty(const struct sk_buff_head *list)
63608 {
63609 - return list->next == (struct sk_buff *)list;
63610 + return list->next == (const struct sk_buff *)list;
63611 }
63612
63613 /**
63614 @@ -623,7 +623,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63615 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63616 const struct sk_buff *skb)
63617 {
63618 - return skb->next == (struct sk_buff *)list;
63619 + return skb->next == (const struct sk_buff *)list;
63620 }
63621
63622 /**
63623 @@ -636,7 +636,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63624 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63625 const struct sk_buff *skb)
63626 {
63627 - return skb->prev == (struct sk_buff *)list;
63628 + return skb->prev == (const struct sk_buff *)list;
63629 }
63630
63631 /**
63632 @@ -1458,7 +1458,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63633 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63634 */
63635 #ifndef NET_SKB_PAD
63636 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63637 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63638 #endif
63639
63640 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63641 diff --git a/include/linux/slab.h b/include/linux/slab.h
63642 index 573c809..e84c132 100644
63643 --- a/include/linux/slab.h
63644 +++ b/include/linux/slab.h
63645 @@ -11,12 +11,20 @@
63646
63647 #include <linux/gfp.h>
63648 #include <linux/types.h>
63649 +#include <linux/err.h>
63650
63651 /*
63652 * Flags to pass to kmem_cache_create().
63653 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63654 */
63655 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63656 +
63657 +#ifdef CONFIG_PAX_USERCOPY
63658 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63659 +#else
63660 +#define SLAB_USERCOPY 0x00000000UL
63661 +#endif
63662 +
63663 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63664 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63665 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63666 @@ -87,10 +95,13 @@
63667 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63668 * Both make kfree a no-op.
63669 */
63670 -#define ZERO_SIZE_PTR ((void *)16)
63671 +#define ZERO_SIZE_PTR \
63672 +({ \
63673 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63674 + (void *)(-MAX_ERRNO-1L); \
63675 +})
63676
63677 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63678 - (unsigned long)ZERO_SIZE_PTR)
63679 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63680
63681 /*
63682 * struct kmem_cache related prototypes
63683 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63684 void kfree(const void *);
63685 void kzfree(const void *);
63686 size_t ksize(const void *);
63687 +void check_object_size(const void *ptr, unsigned long n, bool to);
63688
63689 /*
63690 * Allocator specific definitions. These are mainly used to establish optimized
63691 @@ -353,4 +365,59 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
63692
63693 void __init kmem_cache_init_late(void);
63694
63695 +#define kmalloc(x, y) \
63696 +({ \
63697 + void *___retval; \
63698 + intoverflow_t ___x = (intoverflow_t)x; \
63699 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
63700 + ___retval = NULL; \
63701 + else \
63702 + ___retval = kmalloc((size_t)___x, (y)); \
63703 + ___retval; \
63704 +})
63705 +
63706 +#define kmalloc_node(x, y, z) \
63707 +({ \
63708 + void *___retval; \
63709 + intoverflow_t ___x = (intoverflow_t)x; \
63710 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
63711 + ___retval = NULL; \
63712 + else \
63713 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
63714 + ___retval; \
63715 +})
63716 +
63717 +#define kzalloc(x, y) \
63718 +({ \
63719 + void *___retval; \
63720 + intoverflow_t ___x = (intoverflow_t)x; \
63721 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
63722 + ___retval = NULL; \
63723 + else \
63724 + ___retval = kzalloc((size_t)___x, (y)); \
63725 + ___retval; \
63726 +})
63727 +
63728 +#define __krealloc(x, y, z) \
63729 +({ \
63730 + void *___retval; \
63731 + intoverflow_t ___y = (intoverflow_t)y; \
63732 + if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
63733 + ___retval = NULL; \
63734 + else \
63735 + ___retval = __krealloc((x), (size_t)___y, (z)); \
63736 + ___retval; \
63737 +})
63738 +
63739 +#define krealloc(x, y, z) \
63740 +({ \
63741 + void *___retval; \
63742 + intoverflow_t ___y = (intoverflow_t)y; \
63743 + if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
63744 + ___retval = NULL; \
63745 + else \
63746 + ___retval = krealloc((x), (size_t)___y, (z)); \
63747 + ___retval; \
63748 +})
63749 +
63750 #endif /* _LINUX_SLAB_H */
63751 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63752 index d00e0ba..1b3bf7b 100644
63753 --- a/include/linux/slab_def.h
63754 +++ b/include/linux/slab_def.h
63755 @@ -68,10 +68,10 @@ struct kmem_cache {
63756 unsigned long node_allocs;
63757 unsigned long node_frees;
63758 unsigned long node_overflow;
63759 - atomic_t allochit;
63760 - atomic_t allocmiss;
63761 - atomic_t freehit;
63762 - atomic_t freemiss;
63763 + atomic_unchecked_t allochit;
63764 + atomic_unchecked_t allocmiss;
63765 + atomic_unchecked_t freehit;
63766 + atomic_unchecked_t freemiss;
63767
63768 /*
63769 * If debugging is enabled, then the allocator can add additional
63770 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63771 index f58d641..c56bf9c 100644
63772 --- a/include/linux/slub_def.h
63773 +++ b/include/linux/slub_def.h
63774 @@ -85,7 +85,7 @@ struct kmem_cache {
63775 struct kmem_cache_order_objects max;
63776 struct kmem_cache_order_objects min;
63777 gfp_t allocflags; /* gfp flags to use on each alloc */
63778 - int refcount; /* Refcount for slab cache destroy */
63779 + atomic_t refcount; /* Refcount for slab cache destroy */
63780 void (*ctor)(void *);
63781 int inuse; /* Offset to metadata */
63782 int align; /* Alignment */
63783 @@ -211,7 +211,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63784 }
63785
63786 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63787 -void *__kmalloc(size_t size, gfp_t flags);
63788 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
63789
63790 static __always_inline void *
63791 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63792 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63793 index de8832d..0147b46 100644
63794 --- a/include/linux/sonet.h
63795 +++ b/include/linux/sonet.h
63796 @@ -61,7 +61,7 @@ struct sonet_stats {
63797 #include <linux/atomic.h>
63798
63799 struct k_sonet_stats {
63800 -#define __HANDLE_ITEM(i) atomic_t i
63801 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63802 __SONET_ITEMS
63803 #undef __HANDLE_ITEM
63804 };
63805 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63806 index db7bcaf..1aca77e 100644
63807 --- a/include/linux/sunrpc/clnt.h
63808 +++ b/include/linux/sunrpc/clnt.h
63809 @@ -169,9 +169,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63810 {
63811 switch (sap->sa_family) {
63812 case AF_INET:
63813 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
63814 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63815 case AF_INET6:
63816 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63817 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63818 }
63819 return 0;
63820 }
63821 @@ -204,7 +204,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63822 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63823 const struct sockaddr *src)
63824 {
63825 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63826 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63827 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63828
63829 dsin->sin_family = ssin->sin_family;
63830 @@ -301,7 +301,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63831 if (sa->sa_family != AF_INET6)
63832 return 0;
63833
63834 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63835 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63836 }
63837
63838 #endif /* __KERNEL__ */
63839 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63840 index e775689..9e206d9 100644
63841 --- a/include/linux/sunrpc/sched.h
63842 +++ b/include/linux/sunrpc/sched.h
63843 @@ -105,6 +105,7 @@ struct rpc_call_ops {
63844 void (*rpc_call_done)(struct rpc_task *, void *);
63845 void (*rpc_release)(void *);
63846 };
63847 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63848
63849 struct rpc_task_setup {
63850 struct rpc_task *task;
63851 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63852 index c14fe86..393245e 100644
63853 --- a/include/linux/sunrpc/svc_rdma.h
63854 +++ b/include/linux/sunrpc/svc_rdma.h
63855 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63856 extern unsigned int svcrdma_max_requests;
63857 extern unsigned int svcrdma_max_req_size;
63858
63859 -extern atomic_t rdma_stat_recv;
63860 -extern atomic_t rdma_stat_read;
63861 -extern atomic_t rdma_stat_write;
63862 -extern atomic_t rdma_stat_sq_starve;
63863 -extern atomic_t rdma_stat_rq_starve;
63864 -extern atomic_t rdma_stat_rq_poll;
63865 -extern atomic_t rdma_stat_rq_prod;
63866 -extern atomic_t rdma_stat_sq_poll;
63867 -extern atomic_t rdma_stat_sq_prod;
63868 +extern atomic_unchecked_t rdma_stat_recv;
63869 +extern atomic_unchecked_t rdma_stat_read;
63870 +extern atomic_unchecked_t rdma_stat_write;
63871 +extern atomic_unchecked_t rdma_stat_sq_starve;
63872 +extern atomic_unchecked_t rdma_stat_rq_starve;
63873 +extern atomic_unchecked_t rdma_stat_rq_poll;
63874 +extern atomic_unchecked_t rdma_stat_rq_prod;
63875 +extern atomic_unchecked_t rdma_stat_sq_poll;
63876 +extern atomic_unchecked_t rdma_stat_sq_prod;
63877
63878 #define RPCRDMA_VERSION 1
63879
63880 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63881 index 11684d9..0d245eb 100644
63882 --- a/include/linux/sysctl.h
63883 +++ b/include/linux/sysctl.h
63884 @@ -155,7 +155,11 @@ enum
63885 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63886 };
63887
63888 -
63889 +#ifdef CONFIG_PAX_SOFTMODE
63890 +enum {
63891 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63892 +};
63893 +#endif
63894
63895 /* CTL_VM names: */
63896 enum
63897 @@ -967,6 +971,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63898
63899 extern int proc_dostring(struct ctl_table *, int,
63900 void __user *, size_t *, loff_t *);
63901 +extern int proc_dostring_modpriv(struct ctl_table *, int,
63902 + void __user *, size_t *, loff_t *);
63903 extern int proc_dointvec(struct ctl_table *, int,
63904 void __user *, size_t *, loff_t *);
63905 extern int proc_dointvec_minmax(struct ctl_table *, int,
63906 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63907 index ff7dc08..893e1bd 100644
63908 --- a/include/linux/tty_ldisc.h
63909 +++ b/include/linux/tty_ldisc.h
63910 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63911
63912 struct module *owner;
63913
63914 - int refcount;
63915 + atomic_t refcount;
63916 };
63917
63918 struct tty_ldisc {
63919 diff --git a/include/linux/types.h b/include/linux/types.h
63920 index 176da8c..e45e473 100644
63921 --- a/include/linux/types.h
63922 +++ b/include/linux/types.h
63923 @@ -213,10 +213,26 @@ typedef struct {
63924 int counter;
63925 } atomic_t;
63926
63927 +#ifdef CONFIG_PAX_REFCOUNT
63928 +typedef struct {
63929 + int counter;
63930 +} atomic_unchecked_t;
63931 +#else
63932 +typedef atomic_t atomic_unchecked_t;
63933 +#endif
63934 +
63935 #ifdef CONFIG_64BIT
63936 typedef struct {
63937 long counter;
63938 } atomic64_t;
63939 +
63940 +#ifdef CONFIG_PAX_REFCOUNT
63941 +typedef struct {
63942 + long counter;
63943 +} atomic64_unchecked_t;
63944 +#else
63945 +typedef atomic64_t atomic64_unchecked_t;
63946 +#endif
63947 #endif
63948
63949 struct list_head {
63950 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63951 index 5ca0951..ab496a5 100644
63952 --- a/include/linux/uaccess.h
63953 +++ b/include/linux/uaccess.h
63954 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63955 long ret; \
63956 mm_segment_t old_fs = get_fs(); \
63957 \
63958 - set_fs(KERNEL_DS); \
63959 pagefault_disable(); \
63960 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63961 - pagefault_enable(); \
63962 + set_fs(KERNEL_DS); \
63963 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63964 set_fs(old_fs); \
63965 + pagefault_enable(); \
63966 ret; \
63967 })
63968
63969 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63970 index 99c1b4d..bb94261 100644
63971 --- a/include/linux/unaligned/access_ok.h
63972 +++ b/include/linux/unaligned/access_ok.h
63973 @@ -6,32 +6,32 @@
63974
63975 static inline u16 get_unaligned_le16(const void *p)
63976 {
63977 - return le16_to_cpup((__le16 *)p);
63978 + return le16_to_cpup((const __le16 *)p);
63979 }
63980
63981 static inline u32 get_unaligned_le32(const void *p)
63982 {
63983 - return le32_to_cpup((__le32 *)p);
63984 + return le32_to_cpup((const __le32 *)p);
63985 }
63986
63987 static inline u64 get_unaligned_le64(const void *p)
63988 {
63989 - return le64_to_cpup((__le64 *)p);
63990 + return le64_to_cpup((const __le64 *)p);
63991 }
63992
63993 static inline u16 get_unaligned_be16(const void *p)
63994 {
63995 - return be16_to_cpup((__be16 *)p);
63996 + return be16_to_cpup((const __be16 *)p);
63997 }
63998
63999 static inline u32 get_unaligned_be32(const void *p)
64000 {
64001 - return be32_to_cpup((__be32 *)p);
64002 + return be32_to_cpup((const __be32 *)p);
64003 }
64004
64005 static inline u64 get_unaligned_be64(const void *p)
64006 {
64007 - return be64_to_cpup((__be64 *)p);
64008 + return be64_to_cpup((const __be64 *)p);
64009 }
64010
64011 static inline void put_unaligned_le16(u16 val, void *p)
64012 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64013 index cf97b5b..40ebc87 100644
64014 --- a/include/linux/vermagic.h
64015 +++ b/include/linux/vermagic.h
64016 @@ -26,9 +26,35 @@
64017 #define MODULE_ARCH_VERMAGIC ""
64018 #endif
64019
64020 +#ifdef CONFIG_PAX_REFCOUNT
64021 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64022 +#else
64023 +#define MODULE_PAX_REFCOUNT ""
64024 +#endif
64025 +
64026 +#ifdef CONSTIFY_PLUGIN
64027 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64028 +#else
64029 +#define MODULE_CONSTIFY_PLUGIN ""
64030 +#endif
64031 +
64032 +#ifdef STACKLEAK_PLUGIN
64033 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64034 +#else
64035 +#define MODULE_STACKLEAK_PLUGIN ""
64036 +#endif
64037 +
64038 +#ifdef CONFIG_GRKERNSEC
64039 +#define MODULE_GRSEC "GRSEC "
64040 +#else
64041 +#define MODULE_GRSEC ""
64042 +#endif
64043 +
64044 #define VERMAGIC_STRING \
64045 UTS_RELEASE " " \
64046 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64047 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64048 - MODULE_ARCH_VERMAGIC
64049 + MODULE_ARCH_VERMAGIC \
64050 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64051 + MODULE_GRSEC
64052
64053 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64054 index 687fb11..b342358 100644
64055 --- a/include/linux/vmalloc.h
64056 +++ b/include/linux/vmalloc.h
64057 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64058 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64059 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64060 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64061 +
64062 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64063 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64064 +#endif
64065 +
64066 /* bits [20..32] reserved for arch specific ioremap internals */
64067
64068 /*
64069 @@ -156,4 +161,103 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
64070 # endif
64071 #endif
64072
64073 +#define vmalloc(x) \
64074 +({ \
64075 + void *___retval; \
64076 + intoverflow_t ___x = (intoverflow_t)x; \
64077 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
64078 + ___retval = NULL; \
64079 + else \
64080 + ___retval = vmalloc((unsigned long)___x); \
64081 + ___retval; \
64082 +})
64083 +
64084 +#define vzalloc(x) \
64085 +({ \
64086 + void *___retval; \
64087 + intoverflow_t ___x = (intoverflow_t)x; \
64088 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
64089 + ___retval = NULL; \
64090 + else \
64091 + ___retval = vzalloc((unsigned long)___x); \
64092 + ___retval; \
64093 +})
64094 +
64095 +#define __vmalloc(x, y, z) \
64096 +({ \
64097 + void *___retval; \
64098 + intoverflow_t ___x = (intoverflow_t)x; \
64099 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
64100 + ___retval = NULL; \
64101 + else \
64102 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
64103 + ___retval; \
64104 +})
64105 +
64106 +#define vmalloc_user(x) \
64107 +({ \
64108 + void *___retval; \
64109 + intoverflow_t ___x = (intoverflow_t)x; \
64110 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
64111 + ___retval = NULL; \
64112 + else \
64113 + ___retval = vmalloc_user((unsigned long)___x); \
64114 + ___retval; \
64115 +})
64116 +
64117 +#define vmalloc_exec(x) \
64118 +({ \
64119 + void *___retval; \
64120 + intoverflow_t ___x = (intoverflow_t)x; \
64121 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
64122 + ___retval = NULL; \
64123 + else \
64124 + ___retval = vmalloc_exec((unsigned long)___x); \
64125 + ___retval; \
64126 +})
64127 +
64128 +#define vmalloc_node(x, y) \
64129 +({ \
64130 + void *___retval; \
64131 + intoverflow_t ___x = (intoverflow_t)x; \
64132 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
64133 + ___retval = NULL; \
64134 + else \
64135 + ___retval = vmalloc_node((unsigned long)___x, (y));\
64136 + ___retval; \
64137 +})
64138 +
64139 +#define vzalloc_node(x, y) \
64140 +({ \
64141 + void *___retval; \
64142 + intoverflow_t ___x = (intoverflow_t)x; \
64143 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
64144 + ___retval = NULL; \
64145 + else \
64146 + ___retval = vzalloc_node((unsigned long)___x, (y));\
64147 + ___retval; \
64148 +})
64149 +
64150 +#define vmalloc_32(x) \
64151 +({ \
64152 + void *___retval; \
64153 + intoverflow_t ___x = (intoverflow_t)x; \
64154 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
64155 + ___retval = NULL; \
64156 + else \
64157 + ___retval = vmalloc_32((unsigned long)___x); \
64158 + ___retval; \
64159 +})
64160 +
64161 +#define vmalloc_32_user(x) \
64162 +({ \
64163 +void *___retval; \
64164 + intoverflow_t ___x = (intoverflow_t)x; \
64165 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
64166 + ___retval = NULL; \
64167 + else \
64168 + ___retval = vmalloc_32_user((unsigned long)___x);\
64169 + ___retval; \
64170 +})
64171 +
64172 #endif /* _LINUX_VMALLOC_H */
64173 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64174 index 65efb92..137adbb 100644
64175 --- a/include/linux/vmstat.h
64176 +++ b/include/linux/vmstat.h
64177 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64178 /*
64179 * Zone based page accounting with per cpu differentials.
64180 */
64181 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64182 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64183
64184 static inline void zone_page_state_add(long x, struct zone *zone,
64185 enum zone_stat_item item)
64186 {
64187 - atomic_long_add(x, &zone->vm_stat[item]);
64188 - atomic_long_add(x, &vm_stat[item]);
64189 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64190 + atomic_long_add_unchecked(x, &vm_stat[item]);
64191 }
64192
64193 static inline unsigned long global_page_state(enum zone_stat_item item)
64194 {
64195 - long x = atomic_long_read(&vm_stat[item]);
64196 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64197 #ifdef CONFIG_SMP
64198 if (x < 0)
64199 x = 0;
64200 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64201 static inline unsigned long zone_page_state(struct zone *zone,
64202 enum zone_stat_item item)
64203 {
64204 - long x = atomic_long_read(&zone->vm_stat[item]);
64205 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64206 #ifdef CONFIG_SMP
64207 if (x < 0)
64208 x = 0;
64209 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64210 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64211 enum zone_stat_item item)
64212 {
64213 - long x = atomic_long_read(&zone->vm_stat[item]);
64214 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64215
64216 #ifdef CONFIG_SMP
64217 int cpu;
64218 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64219
64220 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64221 {
64222 - atomic_long_inc(&zone->vm_stat[item]);
64223 - atomic_long_inc(&vm_stat[item]);
64224 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64225 + atomic_long_inc_unchecked(&vm_stat[item]);
64226 }
64227
64228 static inline void __inc_zone_page_state(struct page *page,
64229 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64230
64231 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64232 {
64233 - atomic_long_dec(&zone->vm_stat[item]);
64234 - atomic_long_dec(&vm_stat[item]);
64235 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64236 + atomic_long_dec_unchecked(&vm_stat[item]);
64237 }
64238
64239 static inline void __dec_zone_page_state(struct page *page,
64240 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64241 index aed54c5..3e07f7a 100644
64242 --- a/include/linux/xattr.h
64243 +++ b/include/linux/xattr.h
64244 @@ -49,6 +49,11 @@
64245 #define XATTR_CAPS_SUFFIX "capability"
64246 #define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
64247
64248 +/* User namespace */
64249 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64250 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64251 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64252 +
64253 #ifdef __KERNEL__
64254
64255 #include <linux/types.h>
64256 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64257 index 4aeff96..b378cdc 100644
64258 --- a/include/media/saa7146_vv.h
64259 +++ b/include/media/saa7146_vv.h
64260 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
64261 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64262
64263 /* the extension can override this */
64264 - struct v4l2_ioctl_ops ops;
64265 + v4l2_ioctl_ops_no_const ops;
64266 /* pointer to the saa7146 core ops */
64267 const struct v4l2_ioctl_ops *core_ops;
64268
64269 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64270 index c7c40f1..4f01585 100644
64271 --- a/include/media/v4l2-dev.h
64272 +++ b/include/media/v4l2-dev.h
64273 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
64274
64275
64276 struct v4l2_file_operations {
64277 - struct module *owner;
64278 + struct module * const owner;
64279 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
64280 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
64281 unsigned int (*poll) (struct file *, struct poll_table_struct *);
64282 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
64283 int (*open) (struct file *);
64284 int (*release) (struct file *);
64285 };
64286 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64287
64288 /*
64289 * Newer version of video_device, handled by videodev2.c
64290 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64291 index dd9f1e7..8c4dd86 100644
64292 --- a/include/media/v4l2-ioctl.h
64293 +++ b/include/media/v4l2-ioctl.h
64294 @@ -272,7 +272,7 @@ struct v4l2_ioctl_ops {
64295 long (*vidioc_default) (struct file *file, void *fh,
64296 bool valid_prio, int cmd, void *arg);
64297 };
64298 -
64299 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64300
64301 /* v4l debugging and diagnostics */
64302
64303 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64304 index c5dedd8..a93b07b 100644
64305 --- a/include/net/caif/caif_hsi.h
64306 +++ b/include/net/caif/caif_hsi.h
64307 @@ -94,7 +94,7 @@ struct cfhsi_drv {
64308 void (*rx_done_cb) (struct cfhsi_drv *drv);
64309 void (*wake_up_cb) (struct cfhsi_drv *drv);
64310 void (*wake_down_cb) (struct cfhsi_drv *drv);
64311 -};
64312 +} __no_const;
64313
64314 /* Structure implemented by HSI device. */
64315 struct cfhsi_dev {
64316 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64317 index 9e5425b..8136ffc 100644
64318 --- a/include/net/caif/cfctrl.h
64319 +++ b/include/net/caif/cfctrl.h
64320 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64321 void (*radioset_rsp)(void);
64322 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64323 struct cflayer *client_layer);
64324 -};
64325 +} __no_const;
64326
64327 /* Link Setup Parameters for CAIF-Links. */
64328 struct cfctrl_link_param {
64329 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64330 struct cfctrl {
64331 struct cfsrvl serv;
64332 struct cfctrl_rsp res;
64333 - atomic_t req_seq_no;
64334 - atomic_t rsp_seq_no;
64335 + atomic_unchecked_t req_seq_no;
64336 + atomic_unchecked_t rsp_seq_no;
64337 struct list_head list;
64338 /* Protects from simultaneous access to first_req list */
64339 spinlock_t info_list_lock;
64340 diff --git a/include/net/flow.h b/include/net/flow.h
64341 index 57f15a7..0de26c6 100644
64342 --- a/include/net/flow.h
64343 +++ b/include/net/flow.h
64344 @@ -208,6 +208,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64345
64346 extern void flow_cache_flush(void);
64347 extern void flow_cache_flush_deferred(void);
64348 -extern atomic_t flow_cache_genid;
64349 +extern atomic_unchecked_t flow_cache_genid;
64350
64351 #endif
64352 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64353 index e9ff3fc..9d3e5c7 100644
64354 --- a/include/net/inetpeer.h
64355 +++ b/include/net/inetpeer.h
64356 @@ -48,8 +48,8 @@ struct inet_peer {
64357 */
64358 union {
64359 struct {
64360 - atomic_t rid; /* Frag reception counter */
64361 - atomic_t ip_id_count; /* IP ID for the next packet */
64362 + atomic_unchecked_t rid; /* Frag reception counter */
64363 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64364 __u32 tcp_ts;
64365 __u32 tcp_ts_stamp;
64366 };
64367 @@ -113,11 +113,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64368 more++;
64369 inet_peer_refcheck(p);
64370 do {
64371 - old = atomic_read(&p->ip_id_count);
64372 + old = atomic_read_unchecked(&p->ip_id_count);
64373 new = old + more;
64374 if (!new)
64375 new = 1;
64376 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64377 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64378 return new;
64379 }
64380
64381 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64382 index 10422ef..662570f 100644
64383 --- a/include/net/ip_fib.h
64384 +++ b/include/net/ip_fib.h
64385 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64386
64387 #define FIB_RES_SADDR(net, res) \
64388 ((FIB_RES_NH(res).nh_saddr_genid == \
64389 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64390 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64391 FIB_RES_NH(res).nh_saddr : \
64392 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64393 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64394 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64395 index 8fa4430..05dd772 100644
64396 --- a/include/net/ip_vs.h
64397 +++ b/include/net/ip_vs.h
64398 @@ -509,7 +509,7 @@ struct ip_vs_conn {
64399 struct ip_vs_conn *control; /* Master control connection */
64400 atomic_t n_control; /* Number of controlled ones */
64401 struct ip_vs_dest *dest; /* real server */
64402 - atomic_t in_pkts; /* incoming packet counter */
64403 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64404
64405 /* packet transmitter for different forwarding methods. If it
64406 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64407 @@ -647,7 +647,7 @@ struct ip_vs_dest {
64408 __be16 port; /* port number of the server */
64409 union nf_inet_addr addr; /* IP address of the server */
64410 volatile unsigned flags; /* dest status flags */
64411 - atomic_t conn_flags; /* flags to copy to conn */
64412 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64413 atomic_t weight; /* server weight */
64414
64415 atomic_t refcnt; /* reference counter */
64416 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64417 index 69b610a..fe3962c 100644
64418 --- a/include/net/irda/ircomm_core.h
64419 +++ b/include/net/irda/ircomm_core.h
64420 @@ -51,7 +51,7 @@ typedef struct {
64421 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64422 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64423 struct ircomm_info *);
64424 -} call_t;
64425 +} __no_const call_t;
64426
64427 struct ircomm_cb {
64428 irda_queue_t queue;
64429 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64430 index 59ba38bc..d515662 100644
64431 --- a/include/net/irda/ircomm_tty.h
64432 +++ b/include/net/irda/ircomm_tty.h
64433 @@ -35,6 +35,7 @@
64434 #include <linux/termios.h>
64435 #include <linux/timer.h>
64436 #include <linux/tty.h> /* struct tty_struct */
64437 +#include <asm/local.h>
64438
64439 #include <net/irda/irias_object.h>
64440 #include <net/irda/ircomm_core.h>
64441 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64442 unsigned short close_delay;
64443 unsigned short closing_wait; /* time to wait before closing */
64444
64445 - int open_count;
64446 - int blocked_open; /* # of blocked opens */
64447 + local_t open_count;
64448 + local_t blocked_open; /* # of blocked opens */
64449
64450 /* Protect concurent access to :
64451 * o self->open_count
64452 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64453 index f82a1e8..82d81e8 100644
64454 --- a/include/net/iucv/af_iucv.h
64455 +++ b/include/net/iucv/af_iucv.h
64456 @@ -87,7 +87,7 @@ struct iucv_sock {
64457 struct iucv_sock_list {
64458 struct hlist_head head;
64459 rwlock_t lock;
64460 - atomic_t autobind_name;
64461 + atomic_unchecked_t autobind_name;
64462 };
64463
64464 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64465 diff --git a/include/net/lapb.h b/include/net/lapb.h
64466 index 96cb5dd..25e8d4f 100644
64467 --- a/include/net/lapb.h
64468 +++ b/include/net/lapb.h
64469 @@ -95,7 +95,7 @@ struct lapb_cb {
64470 struct sk_buff_head write_queue;
64471 struct sk_buff_head ack_queue;
64472 unsigned char window;
64473 - struct lapb_register_struct callbacks;
64474 + struct lapb_register_struct *callbacks;
64475
64476 /* FRMR control information */
64477 struct lapb_frame frmr_data;
64478 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64479 index 2720884..3aa5c25 100644
64480 --- a/include/net/neighbour.h
64481 +++ b/include/net/neighbour.h
64482 @@ -122,7 +122,7 @@ struct neigh_ops {
64483 void (*error_report)(struct neighbour *, struct sk_buff *);
64484 int (*output)(struct neighbour *, struct sk_buff *);
64485 int (*connected_output)(struct neighbour *, struct sk_buff *);
64486 -};
64487 +} __do_const;
64488
64489 struct pneigh_entry {
64490 struct pneigh_entry *next;
64491 diff --git a/include/net/netlink.h b/include/net/netlink.h
64492 index 98c1854..d4add7b 100644
64493 --- a/include/net/netlink.h
64494 +++ b/include/net/netlink.h
64495 @@ -562,7 +562,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64496 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64497 {
64498 if (mark)
64499 - skb_trim(skb, (unsigned char *) mark - skb->data);
64500 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64501 }
64502
64503 /**
64504 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64505 index d786b4f..4c3dd41 100644
64506 --- a/include/net/netns/ipv4.h
64507 +++ b/include/net/netns/ipv4.h
64508 @@ -56,8 +56,8 @@ struct netns_ipv4 {
64509
64510 unsigned int sysctl_ping_group_range[2];
64511
64512 - atomic_t rt_genid;
64513 - atomic_t dev_addr_genid;
64514 + atomic_unchecked_t rt_genid;
64515 + atomic_unchecked_t dev_addr_genid;
64516
64517 #ifdef CONFIG_IP_MROUTE
64518 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64519 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64520 index 6a72a58..e6a127d 100644
64521 --- a/include/net/sctp/sctp.h
64522 +++ b/include/net/sctp/sctp.h
64523 @@ -318,9 +318,9 @@ do { \
64524
64525 #else /* SCTP_DEBUG */
64526
64527 -#define SCTP_DEBUG_PRINTK(whatever...)
64528 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64529 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64530 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64531 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64532 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64533 #define SCTP_ENABLE_DEBUG
64534 #define SCTP_DISABLE_DEBUG
64535 #define SCTP_ASSERT(expr, str, func)
64536 diff --git a/include/net/sock.h b/include/net/sock.h
64537 index 8e4062f..77b041e 100644
64538 --- a/include/net/sock.h
64539 +++ b/include/net/sock.h
64540 @@ -278,7 +278,7 @@ struct sock {
64541 #ifdef CONFIG_RPS
64542 __u32 sk_rxhash;
64543 #endif
64544 - atomic_t sk_drops;
64545 + atomic_unchecked_t sk_drops;
64546 int sk_rcvbuf;
64547
64548 struct sk_filter __rcu *sk_filter;
64549 @@ -1391,7 +1391,7 @@ static inline void sk_nocaps_add(struct sock *sk, int flags)
64550 }
64551
64552 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64553 - char __user *from, char *to,
64554 + char __user *from, unsigned char *to,
64555 int copy, int offset)
64556 {
64557 if (skb->ip_summed == CHECKSUM_NONE) {
64558 diff --git a/include/net/tcp.h b/include/net/tcp.h
64559 index acc620a..f4d99c6 100644
64560 --- a/include/net/tcp.h
64561 +++ b/include/net/tcp.h
64562 @@ -1401,8 +1401,8 @@ enum tcp_seq_states {
64563 struct tcp_seq_afinfo {
64564 char *name;
64565 sa_family_t family;
64566 - struct file_operations seq_fops;
64567 - struct seq_operations seq_ops;
64568 + file_operations_no_const seq_fops;
64569 + seq_operations_no_const seq_ops;
64570 };
64571
64572 struct tcp_iter_state {
64573 diff --git a/include/net/udp.h b/include/net/udp.h
64574 index 67ea6fc..e42aee8 100644
64575 --- a/include/net/udp.h
64576 +++ b/include/net/udp.h
64577 @@ -234,8 +234,8 @@ struct udp_seq_afinfo {
64578 char *name;
64579 sa_family_t family;
64580 struct udp_table *udp_table;
64581 - struct file_operations seq_fops;
64582 - struct seq_operations seq_ops;
64583 + file_operations_no_const seq_fops;
64584 + seq_operations_no_const seq_ops;
64585 };
64586
64587 struct udp_iter_state {
64588 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64589 index b203e14..1df3991 100644
64590 --- a/include/net/xfrm.h
64591 +++ b/include/net/xfrm.h
64592 @@ -505,7 +505,7 @@ struct xfrm_policy {
64593 struct timer_list timer;
64594
64595 struct flow_cache_object flo;
64596 - atomic_t genid;
64597 + atomic_unchecked_t genid;
64598 u32 priority;
64599 u32 index;
64600 struct xfrm_mark mark;
64601 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64602 index 2d0191c..a55797d 100644
64603 --- a/include/rdma/iw_cm.h
64604 +++ b/include/rdma/iw_cm.h
64605 @@ -120,7 +120,7 @@ struct iw_cm_verbs {
64606 int backlog);
64607
64608 int (*destroy_listen)(struct iw_cm_id *cm_id);
64609 -};
64610 +} __no_const;
64611
64612 /**
64613 * iw_create_cm_id - Create an IW CM identifier.
64614 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64615 index 7d96829..4ba78d3 100644
64616 --- a/include/scsi/libfc.h
64617 +++ b/include/scsi/libfc.h
64618 @@ -758,6 +758,7 @@ struct libfc_function_template {
64619 */
64620 void (*disc_stop_final) (struct fc_lport *);
64621 };
64622 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64623
64624 /**
64625 * struct fc_disc - Discovery context
64626 @@ -861,7 +862,7 @@ struct fc_lport {
64627 struct fc_vport *vport;
64628
64629 /* Operational Information */
64630 - struct libfc_function_template tt;
64631 + libfc_function_template_no_const tt;
64632 u8 link_up;
64633 u8 qfull;
64634 enum fc_lport_state state;
64635 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64636 index d371c3c..e228a8c 100644
64637 --- a/include/scsi/scsi_device.h
64638 +++ b/include/scsi/scsi_device.h
64639 @@ -161,9 +161,9 @@ struct scsi_device {
64640 unsigned int max_device_blocked; /* what device_blocked counts down from */
64641 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64642
64643 - atomic_t iorequest_cnt;
64644 - atomic_t iodone_cnt;
64645 - atomic_t ioerr_cnt;
64646 + atomic_unchecked_t iorequest_cnt;
64647 + atomic_unchecked_t iodone_cnt;
64648 + atomic_unchecked_t ioerr_cnt;
64649
64650 struct device sdev_gendev,
64651 sdev_dev;
64652 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64653 index 2a65167..91e01f8 100644
64654 --- a/include/scsi/scsi_transport_fc.h
64655 +++ b/include/scsi/scsi_transport_fc.h
64656 @@ -711,7 +711,7 @@ struct fc_function_template {
64657 unsigned long show_host_system_hostname:1;
64658
64659 unsigned long disable_target_scan:1;
64660 -};
64661 +} __do_const;
64662
64663
64664 /**
64665 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64666 index 030b87c..98a6954 100644
64667 --- a/include/sound/ak4xxx-adda.h
64668 +++ b/include/sound/ak4xxx-adda.h
64669 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64670 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64671 unsigned char val);
64672 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64673 -};
64674 +} __no_const;
64675
64676 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64677
64678 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64679 index 8c05e47..2b5df97 100644
64680 --- a/include/sound/hwdep.h
64681 +++ b/include/sound/hwdep.h
64682 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64683 struct snd_hwdep_dsp_status *status);
64684 int (*dsp_load)(struct snd_hwdep *hw,
64685 struct snd_hwdep_dsp_image *image);
64686 -};
64687 +} __no_const;
64688
64689 struct snd_hwdep {
64690 struct snd_card *card;
64691 diff --git a/include/sound/info.h b/include/sound/info.h
64692 index 4e94cf1..76748b1 100644
64693 --- a/include/sound/info.h
64694 +++ b/include/sound/info.h
64695 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
64696 struct snd_info_buffer *buffer);
64697 void (*write)(struct snd_info_entry *entry,
64698 struct snd_info_buffer *buffer);
64699 -};
64700 +} __no_const;
64701
64702 struct snd_info_entry_ops {
64703 int (*open)(struct snd_info_entry *entry,
64704 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64705 index 57e71fa..a2c7534 100644
64706 --- a/include/sound/pcm.h
64707 +++ b/include/sound/pcm.h
64708 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
64709 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64710 int (*ack)(struct snd_pcm_substream *substream);
64711 };
64712 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64713
64714 /*
64715 *
64716 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64717 index af1b49e..a5d55a5 100644
64718 --- a/include/sound/sb16_csp.h
64719 +++ b/include/sound/sb16_csp.h
64720 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64721 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64722 int (*csp_stop) (struct snd_sb_csp * p);
64723 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64724 -};
64725 +} __no_const;
64726
64727 /*
64728 * CSP private data
64729 diff --git a/include/sound/soc.h b/include/sound/soc.h
64730 index aa19f5a..a5b8208 100644
64731 --- a/include/sound/soc.h
64732 +++ b/include/sound/soc.h
64733 @@ -676,7 +676,7 @@ struct snd_soc_platform_driver {
64734 /* platform IO - used for platform DAPM */
64735 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64736 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64737 -};
64738 +} __do_const;
64739
64740 struct snd_soc_platform {
64741 const char *name;
64742 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64743 index 444cd6b..3327cc5 100644
64744 --- a/include/sound/ymfpci.h
64745 +++ b/include/sound/ymfpci.h
64746 @@ -358,7 +358,7 @@ struct snd_ymfpci {
64747 spinlock_t reg_lock;
64748 spinlock_t voice_lock;
64749 wait_queue_head_t interrupt_sleep;
64750 - atomic_t interrupt_sleep_count;
64751 + atomic_unchecked_t interrupt_sleep_count;
64752 struct snd_info_entry *proc_entry;
64753 const struct firmware *dsp_microcode;
64754 const struct firmware *controller_microcode;
64755 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64756 index 2704065..e10f3ef 100644
64757 --- a/include/target/target_core_base.h
64758 +++ b/include/target/target_core_base.h
64759 @@ -356,7 +356,7 @@ struct t10_reservation_ops {
64760 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64761 int (*t10_pr_register)(struct se_cmd *);
64762 int (*t10_pr_clear)(struct se_cmd *);
64763 -};
64764 +} __no_const;
64765
64766 struct t10_reservation {
64767 /* Reservation effects all target ports */
64768 @@ -496,8 +496,8 @@ struct se_cmd {
64769 atomic_t t_task_cdbs_left;
64770 atomic_t t_task_cdbs_ex_left;
64771 atomic_t t_task_cdbs_timeout_left;
64772 - atomic_t t_task_cdbs_sent;
64773 - atomic_t t_transport_aborted;
64774 + atomic_unchecked_t t_task_cdbs_sent;
64775 + atomic_unchecked_t t_transport_aborted;
64776 atomic_t t_transport_active;
64777 atomic_t t_transport_complete;
64778 atomic_t t_transport_queue_active;
64779 @@ -744,7 +744,7 @@ struct se_device {
64780 atomic_t active_cmds;
64781 atomic_t simple_cmds;
64782 atomic_t depth_left;
64783 - atomic_t dev_ordered_id;
64784 + atomic_unchecked_t dev_ordered_id;
64785 atomic_t dev_tur_active;
64786 atomic_t execute_tasks;
64787 atomic_t dev_status_thr_count;
64788 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64789 index 1c09820..7f5ec79 100644
64790 --- a/include/trace/events/irq.h
64791 +++ b/include/trace/events/irq.h
64792 @@ -36,7 +36,7 @@ struct softirq_action;
64793 */
64794 TRACE_EVENT(irq_handler_entry,
64795
64796 - TP_PROTO(int irq, struct irqaction *action),
64797 + TP_PROTO(int irq, const struct irqaction *action),
64798
64799 TP_ARGS(irq, action),
64800
64801 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64802 */
64803 TRACE_EVENT(irq_handler_exit,
64804
64805 - TP_PROTO(int irq, struct irqaction *action, int ret),
64806 + TP_PROTO(int irq, const struct irqaction *action, int ret),
64807
64808 TP_ARGS(irq, action, ret),
64809
64810 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64811 index 69d485a..dd0bee7 100644
64812 --- a/include/video/udlfb.h
64813 +++ b/include/video/udlfb.h
64814 @@ -51,10 +51,10 @@ struct dlfb_data {
64815 int base8;
64816 u32 pseudo_palette[256];
64817 /* blit-only rendering path metrics, exposed through sysfs */
64818 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64819 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64820 - atomic_t bytes_sent; /* to usb, after compression including overhead */
64821 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64822 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64823 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64824 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64825 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64826 };
64827
64828 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64829 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64830 index 0993a22..32ba2fe 100644
64831 --- a/include/video/uvesafb.h
64832 +++ b/include/video/uvesafb.h
64833 @@ -177,6 +177,7 @@ struct uvesafb_par {
64834 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64835 u8 pmi_setpal; /* PMI for palette changes */
64836 u16 *pmi_base; /* protected mode interface location */
64837 + u8 *pmi_code; /* protected mode code location */
64838 void *pmi_start;
64839 void *pmi_pal;
64840 u8 *vbe_state_orig; /*
64841 diff --git a/init/Kconfig b/init/Kconfig
64842 index d627783..693a9f3 100644
64843 --- a/init/Kconfig
64844 +++ b/init/Kconfig
64845 @@ -1202,7 +1202,7 @@ config SLUB_DEBUG
64846
64847 config COMPAT_BRK
64848 bool "Disable heap randomization"
64849 - default y
64850 + default n
64851 help
64852 Randomizing heap placement makes heap exploits harder, but it
64853 also breaks ancient binaries (including anything libc5 based).
64854 diff --git a/init/do_mounts.c b/init/do_mounts.c
64855 index ef6478f..fdb0d8a 100644
64856 --- a/init/do_mounts.c
64857 +++ b/init/do_mounts.c
64858 @@ -287,11 +287,11 @@ static void __init get_fs_names(char *page)
64859
64860 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64861 {
64862 - int err = sys_mount(name, "/root", fs, flags, data);
64863 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64864 if (err)
64865 return err;
64866
64867 - sys_chdir((const char __user __force *)"/root");
64868 + sys_chdir((const char __force_user*)"/root");
64869 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
64870 printk(KERN_INFO
64871 "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
64872 @@ -410,18 +410,18 @@ void __init change_floppy(char *fmt, ...)
64873 va_start(args, fmt);
64874 vsprintf(buf, fmt, args);
64875 va_end(args);
64876 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64877 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64878 if (fd >= 0) {
64879 sys_ioctl(fd, FDEJECT, 0);
64880 sys_close(fd);
64881 }
64882 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64883 - fd = sys_open("/dev/console", O_RDWR, 0);
64884 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64885 if (fd >= 0) {
64886 sys_ioctl(fd, TCGETS, (long)&termios);
64887 termios.c_lflag &= ~ICANON;
64888 sys_ioctl(fd, TCSETSF, (long)&termios);
64889 - sys_read(fd, &c, 1);
64890 + sys_read(fd, (char __user *)&c, 1);
64891 termios.c_lflag |= ICANON;
64892 sys_ioctl(fd, TCSETSF, (long)&termios);
64893 sys_close(fd);
64894 @@ -515,6 +515,6 @@ void __init prepare_namespace(void)
64895 mount_root();
64896 out:
64897 devtmpfs_mount("dev");
64898 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64899 - sys_chroot((const char __user __force *)".");
64900 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64901 + sys_chroot((const char __force_user *)".");
64902 }
64903 diff --git a/init/do_mounts.h b/init/do_mounts.h
64904 index f5b978a..69dbfe8 100644
64905 --- a/init/do_mounts.h
64906 +++ b/init/do_mounts.h
64907 @@ -15,15 +15,15 @@ extern int root_mountflags;
64908
64909 static inline int create_dev(char *name, dev_t dev)
64910 {
64911 - sys_unlink(name);
64912 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64913 + sys_unlink((char __force_user *)name);
64914 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64915 }
64916
64917 #if BITS_PER_LONG == 32
64918 static inline u32 bstat(char *name)
64919 {
64920 struct stat64 stat;
64921 - if (sys_stat64(name, &stat) != 0)
64922 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64923 return 0;
64924 if (!S_ISBLK(stat.st_mode))
64925 return 0;
64926 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64927 static inline u32 bstat(char *name)
64928 {
64929 struct stat stat;
64930 - if (sys_newstat(name, &stat) != 0)
64931 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64932 return 0;
64933 if (!S_ISBLK(stat.st_mode))
64934 return 0;
64935 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64936 index 3098a38..253064e 100644
64937 --- a/init/do_mounts_initrd.c
64938 +++ b/init/do_mounts_initrd.c
64939 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
64940 create_dev("/dev/root.old", Root_RAM0);
64941 /* mount initrd on rootfs' /root */
64942 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64943 - sys_mkdir("/old", 0700);
64944 - root_fd = sys_open("/", 0, 0);
64945 - old_fd = sys_open("/old", 0, 0);
64946 + sys_mkdir((const char __force_user *)"/old", 0700);
64947 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
64948 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64949 /* move initrd over / and chdir/chroot in initrd root */
64950 - sys_chdir("/root");
64951 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64952 - sys_chroot(".");
64953 + sys_chdir((const char __force_user *)"/root");
64954 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64955 + sys_chroot((const char __force_user *)".");
64956
64957 /*
64958 * In case that a resume from disk is carried out by linuxrc or one of
64959 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
64960
64961 /* move initrd to rootfs' /old */
64962 sys_fchdir(old_fd);
64963 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
64964 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64965 /* switch root and cwd back to / of rootfs */
64966 sys_fchdir(root_fd);
64967 - sys_chroot(".");
64968 + sys_chroot((const char __force_user *)".");
64969 sys_close(old_fd);
64970 sys_close(root_fd);
64971
64972 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64973 - sys_chdir("/old");
64974 + sys_chdir((const char __force_user *)"/old");
64975 return;
64976 }
64977
64978 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
64979 mount_root();
64980
64981 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64982 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64983 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64984 if (!error)
64985 printk("okay\n");
64986 else {
64987 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
64988 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64989 if (error == -ENOENT)
64990 printk("/initrd does not exist. Ignored.\n");
64991 else
64992 printk("failed\n");
64993 printk(KERN_NOTICE "Unmounting old root\n");
64994 - sys_umount("/old", MNT_DETACH);
64995 + sys_umount((char __force_user *)"/old", MNT_DETACH);
64996 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64997 if (fd < 0) {
64998 error = fd;
64999 @@ -116,11 +116,11 @@ int __init initrd_load(void)
65000 * mounted in the normal path.
65001 */
65002 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65003 - sys_unlink("/initrd.image");
65004 + sys_unlink((const char __force_user *)"/initrd.image");
65005 handle_initrd();
65006 return 1;
65007 }
65008 }
65009 - sys_unlink("/initrd.image");
65010 + sys_unlink((const char __force_user *)"/initrd.image");
65011 return 0;
65012 }
65013 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65014 index 32c4799..c27ee74 100644
65015 --- a/init/do_mounts_md.c
65016 +++ b/init/do_mounts_md.c
65017 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
65018 partitioned ? "_d" : "", minor,
65019 md_setup_args[ent].device_names);
65020
65021 - fd = sys_open(name, 0, 0);
65022 + fd = sys_open((char __force_user *)name, 0, 0);
65023 if (fd < 0) {
65024 printk(KERN_ERR "md: open failed - cannot start "
65025 "array %s\n", name);
65026 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
65027 * array without it
65028 */
65029 sys_close(fd);
65030 - fd = sys_open(name, 0, 0);
65031 + fd = sys_open((char __force_user *)name, 0, 0);
65032 sys_ioctl(fd, BLKRRPART, 0);
65033 }
65034 sys_close(fd);
65035 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
65036
65037 wait_for_device_probe();
65038
65039 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
65040 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65041 if (fd >= 0) {
65042 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65043 sys_close(fd);
65044 diff --git a/init/initramfs.c b/init/initramfs.c
65045 index 2531811..040d4d4 100644
65046 --- a/init/initramfs.c
65047 +++ b/init/initramfs.c
65048 @@ -74,7 +74,7 @@ static void __init free_hash(void)
65049 }
65050 }
65051
65052 -static long __init do_utime(char __user *filename, time_t mtime)
65053 +static long __init do_utime(__force char __user *filename, time_t mtime)
65054 {
65055 struct timespec t[2];
65056
65057 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
65058 struct dir_entry *de, *tmp;
65059 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65060 list_del(&de->list);
65061 - do_utime(de->name, de->mtime);
65062 + do_utime((char __force_user *)de->name, de->mtime);
65063 kfree(de->name);
65064 kfree(de);
65065 }
65066 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
65067 if (nlink >= 2) {
65068 char *old = find_link(major, minor, ino, mode, collected);
65069 if (old)
65070 - return (sys_link(old, collected) < 0) ? -1 : 1;
65071 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65072 }
65073 return 0;
65074 }
65075 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
65076 {
65077 struct stat st;
65078
65079 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65080 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65081 if (S_ISDIR(st.st_mode))
65082 - sys_rmdir(path);
65083 + sys_rmdir((char __force_user *)path);
65084 else
65085 - sys_unlink(path);
65086 + sys_unlink((char __force_user *)path);
65087 }
65088 }
65089
65090 @@ -305,7 +305,7 @@ static int __init do_name(void)
65091 int openflags = O_WRONLY|O_CREAT;
65092 if (ml != 1)
65093 openflags |= O_TRUNC;
65094 - wfd = sys_open(collected, openflags, mode);
65095 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65096
65097 if (wfd >= 0) {
65098 sys_fchown(wfd, uid, gid);
65099 @@ -317,17 +317,17 @@ static int __init do_name(void)
65100 }
65101 }
65102 } else if (S_ISDIR(mode)) {
65103 - sys_mkdir(collected, mode);
65104 - sys_chown(collected, uid, gid);
65105 - sys_chmod(collected, mode);
65106 + sys_mkdir((char __force_user *)collected, mode);
65107 + sys_chown((char __force_user *)collected, uid, gid);
65108 + sys_chmod((char __force_user *)collected, mode);
65109 dir_add(collected, mtime);
65110 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65111 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65112 if (maybe_link() == 0) {
65113 - sys_mknod(collected, mode, rdev);
65114 - sys_chown(collected, uid, gid);
65115 - sys_chmod(collected, mode);
65116 - do_utime(collected, mtime);
65117 + sys_mknod((char __force_user *)collected, mode, rdev);
65118 + sys_chown((char __force_user *)collected, uid, gid);
65119 + sys_chmod((char __force_user *)collected, mode);
65120 + do_utime((char __force_user *)collected, mtime);
65121 }
65122 }
65123 return 0;
65124 @@ -336,15 +336,15 @@ static int __init do_name(void)
65125 static int __init do_copy(void)
65126 {
65127 if (count >= body_len) {
65128 - sys_write(wfd, victim, body_len);
65129 + sys_write(wfd, (char __force_user *)victim, body_len);
65130 sys_close(wfd);
65131 - do_utime(vcollected, mtime);
65132 + do_utime((char __force_user *)vcollected, mtime);
65133 kfree(vcollected);
65134 eat(body_len);
65135 state = SkipIt;
65136 return 0;
65137 } else {
65138 - sys_write(wfd, victim, count);
65139 + sys_write(wfd, (char __force_user *)victim, count);
65140 body_len -= count;
65141 eat(count);
65142 return 1;
65143 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
65144 {
65145 collected[N_ALIGN(name_len) + body_len] = '\0';
65146 clean_path(collected, 0);
65147 - sys_symlink(collected + N_ALIGN(name_len), collected);
65148 - sys_lchown(collected, uid, gid);
65149 - do_utime(collected, mtime);
65150 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65151 + sys_lchown((char __force_user *)collected, uid, gid);
65152 + do_utime((char __force_user *)collected, mtime);
65153 state = SkipIt;
65154 next_state = Reset;
65155 return 0;
65156 diff --git a/init/main.c b/init/main.c
65157 index 03b408d..5777f59 100644
65158 --- a/init/main.c
65159 +++ b/init/main.c
65160 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
65161 extern void tc_init(void);
65162 #endif
65163
65164 +extern void grsecurity_init(void);
65165 +
65166 /*
65167 * Debug helper: via this flag we know that we are in 'early bootup code'
65168 * where only the boot processor is running with IRQ disabled. This means
65169 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
65170
65171 __setup("reset_devices", set_reset_devices);
65172
65173 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65174 +extern char pax_enter_kernel_user[];
65175 +extern char pax_exit_kernel_user[];
65176 +extern pgdval_t clone_pgd_mask;
65177 +#endif
65178 +
65179 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65180 +static int __init setup_pax_nouderef(char *str)
65181 +{
65182 +#ifdef CONFIG_X86_32
65183 + unsigned int cpu;
65184 + struct desc_struct *gdt;
65185 +
65186 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
65187 + gdt = get_cpu_gdt_table(cpu);
65188 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65189 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65190 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65191 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65192 + }
65193 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65194 +#else
65195 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65196 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65197 + clone_pgd_mask = ~(pgdval_t)0UL;
65198 +#endif
65199 +
65200 + return 0;
65201 +}
65202 +early_param("pax_nouderef", setup_pax_nouderef);
65203 +#endif
65204 +
65205 +#ifdef CONFIG_PAX_SOFTMODE
65206 +int pax_softmode;
65207 +
65208 +static int __init setup_pax_softmode(char *str)
65209 +{
65210 + get_option(&str, &pax_softmode);
65211 + return 1;
65212 +}
65213 +__setup("pax_softmode=", setup_pax_softmode);
65214 +#endif
65215 +
65216 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65217 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65218 static const char *panic_later, *panic_param;
65219 @@ -678,6 +723,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65220 {
65221 int count = preempt_count();
65222 int ret;
65223 + const char *msg1 = "", *msg2 = "";
65224
65225 if (initcall_debug)
65226 ret = do_one_initcall_debug(fn);
65227 @@ -690,15 +736,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65228 sprintf(msgbuf, "error code %d ", ret);
65229
65230 if (preempt_count() != count) {
65231 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65232 + msg1 = " preemption imbalance";
65233 preempt_count() = count;
65234 }
65235 if (irqs_disabled()) {
65236 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65237 + msg2 = " disabled interrupts";
65238 local_irq_enable();
65239 }
65240 - if (msgbuf[0]) {
65241 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65242 + if (msgbuf[0] || *msg1 || *msg2) {
65243 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65244 }
65245
65246 return ret;
65247 @@ -817,7 +863,7 @@ static int __init kernel_init(void * unused)
65248 do_basic_setup();
65249
65250 /* Open the /dev/console on the rootfs, this should never fail */
65251 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65252 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65253 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65254
65255 (void) sys_dup(0);
65256 @@ -830,11 +876,13 @@ static int __init kernel_init(void * unused)
65257 if (!ramdisk_execute_command)
65258 ramdisk_execute_command = "/init";
65259
65260 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65261 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65262 ramdisk_execute_command = NULL;
65263 prepare_namespace();
65264 }
65265
65266 + grsecurity_init();
65267 +
65268 /*
65269 * Ok, we have completed the initial bootup, and
65270 * we're essentially up and running. Get rid of the
65271 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65272 index ed049ea..6442f7f 100644
65273 --- a/ipc/mqueue.c
65274 +++ b/ipc/mqueue.c
65275 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65276 mq_bytes = (mq_msg_tblsz +
65277 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
65278
65279 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65280 spin_lock(&mq_lock);
65281 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65282 u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
65283 diff --git a/ipc/msg.c b/ipc/msg.c
65284 index 7385de2..a8180e0 100644
65285 --- a/ipc/msg.c
65286 +++ b/ipc/msg.c
65287 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65288 return security_msg_queue_associate(msq, msgflg);
65289 }
65290
65291 +static struct ipc_ops msg_ops = {
65292 + .getnew = newque,
65293 + .associate = msg_security,
65294 + .more_checks = NULL
65295 +};
65296 +
65297 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65298 {
65299 struct ipc_namespace *ns;
65300 - struct ipc_ops msg_ops;
65301 struct ipc_params msg_params;
65302
65303 ns = current->nsproxy->ipc_ns;
65304
65305 - msg_ops.getnew = newque;
65306 - msg_ops.associate = msg_security;
65307 - msg_ops.more_checks = NULL;
65308 -
65309 msg_params.key = key;
65310 msg_params.flg = msgflg;
65311
65312 diff --git a/ipc/sem.c b/ipc/sem.c
65313 index c8e00f8..1135c4e 100644
65314 --- a/ipc/sem.c
65315 +++ b/ipc/sem.c
65316 @@ -318,10 +318,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65317 return 0;
65318 }
65319
65320 +static struct ipc_ops sem_ops = {
65321 + .getnew = newary,
65322 + .associate = sem_security,
65323 + .more_checks = sem_more_checks
65324 +};
65325 +
65326 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65327 {
65328 struct ipc_namespace *ns;
65329 - struct ipc_ops sem_ops;
65330 struct ipc_params sem_params;
65331
65332 ns = current->nsproxy->ipc_ns;
65333 @@ -329,10 +334,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65334 if (nsems < 0 || nsems > ns->sc_semmsl)
65335 return -EINVAL;
65336
65337 - sem_ops.getnew = newary;
65338 - sem_ops.associate = sem_security;
65339 - sem_ops.more_checks = sem_more_checks;
65340 -
65341 sem_params.key = key;
65342 sem_params.flg = semflg;
65343 sem_params.u.nsems = nsems;
65344 @@ -848,6 +849,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
65345 int nsems;
65346 struct list_head tasks;
65347
65348 + pax_track_stack();
65349 +
65350 sma = sem_lock_check(ns, semid);
65351 if (IS_ERR(sma))
65352 return PTR_ERR(sma);
65353 @@ -1295,6 +1298,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
65354 struct ipc_namespace *ns;
65355 struct list_head tasks;
65356
65357 + pax_track_stack();
65358 +
65359 ns = current->nsproxy->ipc_ns;
65360
65361 if (nsops < 1 || semid < 0)
65362 diff --git a/ipc/shm.c b/ipc/shm.c
65363 index 02ecf2c..c8f5627 100644
65364 --- a/ipc/shm.c
65365 +++ b/ipc/shm.c
65366 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65367 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65368 #endif
65369
65370 +#ifdef CONFIG_GRKERNSEC
65371 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65372 + const time_t shm_createtime, const uid_t cuid,
65373 + const int shmid);
65374 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65375 + const time_t shm_createtime);
65376 +#endif
65377 +
65378 void shm_init_ns(struct ipc_namespace *ns)
65379 {
65380 ns->shm_ctlmax = SHMMAX;
65381 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65382 shp->shm_lprid = 0;
65383 shp->shm_atim = shp->shm_dtim = 0;
65384 shp->shm_ctim = get_seconds();
65385 +#ifdef CONFIG_GRKERNSEC
65386 + {
65387 + struct timespec timeval;
65388 + do_posix_clock_monotonic_gettime(&timeval);
65389 +
65390 + shp->shm_createtime = timeval.tv_sec;
65391 + }
65392 +#endif
65393 shp->shm_segsz = size;
65394 shp->shm_nattch = 0;
65395 shp->shm_file = file;
65396 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65397 return 0;
65398 }
65399
65400 +static struct ipc_ops shm_ops = {
65401 + .getnew = newseg,
65402 + .associate = shm_security,
65403 + .more_checks = shm_more_checks
65404 +};
65405 +
65406 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65407 {
65408 struct ipc_namespace *ns;
65409 - struct ipc_ops shm_ops;
65410 struct ipc_params shm_params;
65411
65412 ns = current->nsproxy->ipc_ns;
65413
65414 - shm_ops.getnew = newseg;
65415 - shm_ops.associate = shm_security;
65416 - shm_ops.more_checks = shm_more_checks;
65417 -
65418 shm_params.key = key;
65419 shm_params.flg = shmflg;
65420 shm_params.u.size = size;
65421 @@ -870,8 +887,6 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)
65422 case SHM_LOCK:
65423 case SHM_UNLOCK:
65424 {
65425 - struct file *uninitialized_var(shm_file);
65426 -
65427 lru_add_drain_all(); /* drain pagevecs to lru lists */
65428
65429 shp = shm_lock_check(ns, shmid);
65430 @@ -1004,9 +1019,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65431 if (err)
65432 goto out_unlock;
65433
65434 +#ifdef CONFIG_GRKERNSEC
65435 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65436 + shp->shm_perm.cuid, shmid) ||
65437 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65438 + err = -EACCES;
65439 + goto out_unlock;
65440 + }
65441 +#endif
65442 +
65443 path = shp->shm_file->f_path;
65444 path_get(&path);
65445 shp->shm_nattch++;
65446 +#ifdef CONFIG_GRKERNSEC
65447 + shp->shm_lapid = current->pid;
65448 +#endif
65449 size = i_size_read(path.dentry->d_inode);
65450 shm_unlock(shp);
65451
65452 diff --git a/kernel/acct.c b/kernel/acct.c
65453 index fa7eb3d..7faf116 100644
65454 --- a/kernel/acct.c
65455 +++ b/kernel/acct.c
65456 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65457 */
65458 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65459 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65460 - file->f_op->write(file, (char *)&ac,
65461 + file->f_op->write(file, (char __force_user *)&ac,
65462 sizeof(acct_t), &file->f_pos);
65463 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65464 set_fs(fs);
65465 diff --git a/kernel/audit.c b/kernel/audit.c
65466 index 0a1355c..9359745 100644
65467 --- a/kernel/audit.c
65468 +++ b/kernel/audit.c
65469 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65470 3) suppressed due to audit_rate_limit
65471 4) suppressed due to audit_backlog_limit
65472 */
65473 -static atomic_t audit_lost = ATOMIC_INIT(0);
65474 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65475
65476 /* The netlink socket. */
65477 static struct sock *audit_sock;
65478 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65479 unsigned long now;
65480 int print;
65481
65482 - atomic_inc(&audit_lost);
65483 + atomic_inc_unchecked(&audit_lost);
65484
65485 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65486
65487 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65488 printk(KERN_WARNING
65489 "audit: audit_lost=%d audit_rate_limit=%d "
65490 "audit_backlog_limit=%d\n",
65491 - atomic_read(&audit_lost),
65492 + atomic_read_unchecked(&audit_lost),
65493 audit_rate_limit,
65494 audit_backlog_limit);
65495 audit_panic(message);
65496 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65497 status_set.pid = audit_pid;
65498 status_set.rate_limit = audit_rate_limit;
65499 status_set.backlog_limit = audit_backlog_limit;
65500 - status_set.lost = atomic_read(&audit_lost);
65501 + status_set.lost = atomic_read_unchecked(&audit_lost);
65502 status_set.backlog = skb_queue_len(&audit_skb_queue);
65503 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65504 &status_set, sizeof(status_set));
65505 @@ -1260,12 +1260,13 @@ static void audit_log_vformat(struct audit_buffer *ab, const char *fmt,
65506 avail = audit_expand(ab,
65507 max_t(unsigned, AUDIT_BUFSIZ, 1+len-avail));
65508 if (!avail)
65509 - goto out;
65510 + goto out_va_end;
65511 len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args2);
65512 }
65513 - va_end(args2);
65514 if (len > 0)
65515 skb_put(skb, len);
65516 +out_va_end:
65517 + va_end(args2);
65518 out:
65519 return;
65520 }
65521 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65522 index ce4b054..aaa419e 100644
65523 --- a/kernel/auditsc.c
65524 +++ b/kernel/auditsc.c
65525 @@ -1166,8 +1166,8 @@ static void audit_log_execve_info(struct audit_context *context,
65526 struct audit_buffer **ab,
65527 struct audit_aux_data_execve *axi)
65528 {
65529 - int i;
65530 - size_t len, len_sent = 0;
65531 + int i, len;
65532 + size_t len_sent = 0;
65533 const char __user *p;
65534 char *buf;
65535
65536 @@ -2118,7 +2118,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65537 }
65538
65539 /* global counter which is incremented every time something logs in */
65540 -static atomic_t session_id = ATOMIC_INIT(0);
65541 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65542
65543 /**
65544 * audit_set_loginuid - set a task's audit_context loginuid
65545 @@ -2131,7 +2131,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
65546 */
65547 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
65548 {
65549 - unsigned int sessionid = atomic_inc_return(&session_id);
65550 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
65551 struct audit_context *context = task->audit_context;
65552
65553 if (context && context->in_syscall) {
65554 diff --git a/kernel/capability.c b/kernel/capability.c
65555 index 283c529..36ac81e 100644
65556 --- a/kernel/capability.c
65557 +++ b/kernel/capability.c
65558 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65559 * before modification is attempted and the application
65560 * fails.
65561 */
65562 + if (tocopy > ARRAY_SIZE(kdata))
65563 + return -EFAULT;
65564 +
65565 if (copy_to_user(dataptr, kdata, tocopy
65566 * sizeof(struct __user_cap_data_struct))) {
65567 return -EFAULT;
65568 @@ -374,7 +377,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65569 BUG();
65570 }
65571
65572 - if (security_capable(ns, current_cred(), cap) == 0) {
65573 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
65574 current->flags |= PF_SUPERPRIV;
65575 return true;
65576 }
65577 @@ -382,6 +385,27 @@ bool ns_capable(struct user_namespace *ns, int cap)
65578 }
65579 EXPORT_SYMBOL(ns_capable);
65580
65581 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
65582 +{
65583 + if (unlikely(!cap_valid(cap))) {
65584 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65585 + BUG();
65586 + }
65587 +
65588 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
65589 + current->flags |= PF_SUPERPRIV;
65590 + return true;
65591 + }
65592 + return false;
65593 +}
65594 +EXPORT_SYMBOL(ns_capable_nolog);
65595 +
65596 +bool capable_nolog(int cap)
65597 +{
65598 + return ns_capable_nolog(&init_user_ns, cap);
65599 +}
65600 +EXPORT_SYMBOL(capable_nolog);
65601 +
65602 /**
65603 * task_ns_capable - Determine whether current task has a superior
65604 * capability targeted at a specific task's user namespace.
65605 @@ -396,6 +420,12 @@ bool task_ns_capable(struct task_struct *t, int cap)
65606 }
65607 EXPORT_SYMBOL(task_ns_capable);
65608
65609 +bool task_ns_capable_nolog(struct task_struct *t, int cap)
65610 +{
65611 + return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
65612 +}
65613 +EXPORT_SYMBOL(task_ns_capable_nolog);
65614 +
65615 /**
65616 * nsown_capable - Check superior capability to one's own user_ns
65617 * @cap: The capability in question
65618 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
65619 index e4cbdfb..191bec4 100644
65620 --- a/kernel/cgroup.c
65621 +++ b/kernel/cgroup.c
65622 @@ -595,6 +595,8 @@ static struct css_set *find_css_set(
65623 struct hlist_head *hhead;
65624 struct cg_cgroup_link *link;
65625
65626 + pax_track_stack();
65627 +
65628 /* First see if we already have a cgroup group that matches
65629 * the desired set */
65630 read_lock(&css_set_lock);
65631 diff --git a/kernel/compat.c b/kernel/compat.c
65632 index e2435ee..8e82199 100644
65633 --- a/kernel/compat.c
65634 +++ b/kernel/compat.c
65635 @@ -13,6 +13,7 @@
65636
65637 #include <linux/linkage.h>
65638 #include <linux/compat.h>
65639 +#include <linux/module.h>
65640 #include <linux/errno.h>
65641 #include <linux/time.h>
65642 #include <linux/signal.h>
65643 @@ -167,7 +168,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65644 mm_segment_t oldfs;
65645 long ret;
65646
65647 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65648 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65649 oldfs = get_fs();
65650 set_fs(KERNEL_DS);
65651 ret = hrtimer_nanosleep_restart(restart);
65652 @@ -199,7 +200,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65653 oldfs = get_fs();
65654 set_fs(KERNEL_DS);
65655 ret = hrtimer_nanosleep(&tu,
65656 - rmtp ? (struct timespec __user *)&rmt : NULL,
65657 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
65658 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65659 set_fs(oldfs);
65660
65661 @@ -308,7 +309,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65662 mm_segment_t old_fs = get_fs();
65663
65664 set_fs(KERNEL_DS);
65665 - ret = sys_sigpending((old_sigset_t __user *) &s);
65666 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
65667 set_fs(old_fs);
65668 if (ret == 0)
65669 ret = put_user(s, set);
65670 @@ -331,8 +332,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
65671 old_fs = get_fs();
65672 set_fs(KERNEL_DS);
65673 ret = sys_sigprocmask(how,
65674 - set ? (old_sigset_t __user *) &s : NULL,
65675 - oset ? (old_sigset_t __user *) &s : NULL);
65676 + set ? (old_sigset_t __force_user *) &s : NULL,
65677 + oset ? (old_sigset_t __force_user *) &s : NULL);
65678 set_fs(old_fs);
65679 if (ret == 0)
65680 if (oset)
65681 @@ -369,7 +370,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65682 mm_segment_t old_fs = get_fs();
65683
65684 set_fs(KERNEL_DS);
65685 - ret = sys_old_getrlimit(resource, &r);
65686 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65687 set_fs(old_fs);
65688
65689 if (!ret) {
65690 @@ -441,7 +442,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65691 mm_segment_t old_fs = get_fs();
65692
65693 set_fs(KERNEL_DS);
65694 - ret = sys_getrusage(who, (struct rusage __user *) &r);
65695 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65696 set_fs(old_fs);
65697
65698 if (ret)
65699 @@ -468,8 +469,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65700 set_fs (KERNEL_DS);
65701 ret = sys_wait4(pid,
65702 (stat_addr ?
65703 - (unsigned int __user *) &status : NULL),
65704 - options, (struct rusage __user *) &r);
65705 + (unsigned int __force_user *) &status : NULL),
65706 + options, (struct rusage __force_user *) &r);
65707 set_fs (old_fs);
65708
65709 if (ret > 0) {
65710 @@ -494,8 +495,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65711 memset(&info, 0, sizeof(info));
65712
65713 set_fs(KERNEL_DS);
65714 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65715 - uru ? (struct rusage __user *)&ru : NULL);
65716 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65717 + uru ? (struct rusage __force_user *)&ru : NULL);
65718 set_fs(old_fs);
65719
65720 if ((ret < 0) || (info.si_signo == 0))
65721 @@ -625,8 +626,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65722 oldfs = get_fs();
65723 set_fs(KERNEL_DS);
65724 err = sys_timer_settime(timer_id, flags,
65725 - (struct itimerspec __user *) &newts,
65726 - (struct itimerspec __user *) &oldts);
65727 + (struct itimerspec __force_user *) &newts,
65728 + (struct itimerspec __force_user *) &oldts);
65729 set_fs(oldfs);
65730 if (!err && old && put_compat_itimerspec(old, &oldts))
65731 return -EFAULT;
65732 @@ -643,7 +644,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65733 oldfs = get_fs();
65734 set_fs(KERNEL_DS);
65735 err = sys_timer_gettime(timer_id,
65736 - (struct itimerspec __user *) &ts);
65737 + (struct itimerspec __force_user *) &ts);
65738 set_fs(oldfs);
65739 if (!err && put_compat_itimerspec(setting, &ts))
65740 return -EFAULT;
65741 @@ -662,7 +663,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65742 oldfs = get_fs();
65743 set_fs(KERNEL_DS);
65744 err = sys_clock_settime(which_clock,
65745 - (struct timespec __user *) &ts);
65746 + (struct timespec __force_user *) &ts);
65747 set_fs(oldfs);
65748 return err;
65749 }
65750 @@ -677,7 +678,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65751 oldfs = get_fs();
65752 set_fs(KERNEL_DS);
65753 err = sys_clock_gettime(which_clock,
65754 - (struct timespec __user *) &ts);
65755 + (struct timespec __force_user *) &ts);
65756 set_fs(oldfs);
65757 if (!err && put_compat_timespec(&ts, tp))
65758 return -EFAULT;
65759 @@ -697,7 +698,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65760
65761 oldfs = get_fs();
65762 set_fs(KERNEL_DS);
65763 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65764 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65765 set_fs(oldfs);
65766
65767 err = compat_put_timex(utp, &txc);
65768 @@ -717,7 +718,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65769 oldfs = get_fs();
65770 set_fs(KERNEL_DS);
65771 err = sys_clock_getres(which_clock,
65772 - (struct timespec __user *) &ts);
65773 + (struct timespec __force_user *) &ts);
65774 set_fs(oldfs);
65775 if (!err && tp && put_compat_timespec(&ts, tp))
65776 return -EFAULT;
65777 @@ -729,9 +730,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65778 long err;
65779 mm_segment_t oldfs;
65780 struct timespec tu;
65781 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65782 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65783
65784 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65785 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65786 oldfs = get_fs();
65787 set_fs(KERNEL_DS);
65788 err = clock_nanosleep_restart(restart);
65789 @@ -763,8 +764,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65790 oldfs = get_fs();
65791 set_fs(KERNEL_DS);
65792 err = sys_clock_nanosleep(which_clock, flags,
65793 - (struct timespec __user *) &in,
65794 - (struct timespec __user *) &out);
65795 + (struct timespec __force_user *) &in,
65796 + (struct timespec __force_user *) &out);
65797 set_fs(oldfs);
65798
65799 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65800 diff --git a/kernel/configs.c b/kernel/configs.c
65801 index 42e8fa0..9e7406b 100644
65802 --- a/kernel/configs.c
65803 +++ b/kernel/configs.c
65804 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65805 struct proc_dir_entry *entry;
65806
65807 /* create the current config file */
65808 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65809 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65810 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65811 + &ikconfig_file_ops);
65812 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65813 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65814 + &ikconfig_file_ops);
65815 +#endif
65816 +#else
65817 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65818 &ikconfig_file_ops);
65819 +#endif
65820 +
65821 if (!entry)
65822 return -ENOMEM;
65823
65824 diff --git a/kernel/cred.c b/kernel/cred.c
65825 index 8ef31f5..7957d07 100644
65826 --- a/kernel/cred.c
65827 +++ b/kernel/cred.c
65828 @@ -158,6 +158,8 @@ static void put_cred_rcu(struct rcu_head *rcu)
65829 */
65830 void __put_cred(struct cred *cred)
65831 {
65832 + pax_track_stack();
65833 +
65834 kdebug("__put_cred(%p{%d,%d})", cred,
65835 atomic_read(&cred->usage),
65836 read_cred_subscribers(cred));
65837 @@ -182,6 +184,8 @@ void exit_creds(struct task_struct *tsk)
65838 {
65839 struct cred *cred;
65840
65841 + pax_track_stack();
65842 +
65843 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
65844 atomic_read(&tsk->cred->usage),
65845 read_cred_subscribers(tsk->cred));
65846 @@ -220,6 +224,8 @@ const struct cred *get_task_cred(struct task_struct *task)
65847 {
65848 const struct cred *cred;
65849
65850 + pax_track_stack();
65851 +
65852 rcu_read_lock();
65853
65854 do {
65855 @@ -239,6 +245,8 @@ struct cred *cred_alloc_blank(void)
65856 {
65857 struct cred *new;
65858
65859 + pax_track_stack();
65860 +
65861 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
65862 if (!new)
65863 return NULL;
65864 @@ -281,13 +289,15 @@ error:
65865 *
65866 * Call commit_creds() or abort_creds() to clean up.
65867 */
65868 -struct cred *prepare_creds(void)
65869 +
65870 +static struct cred *__prepare_creds(struct task_struct *task)
65871 {
65872 - struct task_struct *task = current;
65873 const struct cred *old;
65874 struct cred *new;
65875
65876 - validate_process_creds();
65877 + pax_track_stack();
65878 +
65879 + validate_task_creds(task);
65880
65881 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
65882 if (!new)
65883 @@ -322,6 +332,11 @@ error:
65884 abort_creds(new);
65885 return NULL;
65886 }
65887 +
65888 +struct cred *prepare_creds(void)
65889 +{
65890 + return __prepare_creds(current);
65891 +}
65892 EXPORT_SYMBOL(prepare_creds);
65893
65894 /*
65895 @@ -333,6 +348,8 @@ struct cred *prepare_exec_creds(void)
65896 struct thread_group_cred *tgcred = NULL;
65897 struct cred *new;
65898
65899 + pax_track_stack();
65900 +
65901 #ifdef CONFIG_KEYS
65902 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
65903 if (!tgcred)
65904 @@ -385,6 +402,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
65905 struct cred *new;
65906 int ret;
65907
65908 + pax_track_stack();
65909 +
65910 if (
65911 #ifdef CONFIG_KEYS
65912 !p->cred->thread_keyring &&
65913 @@ -470,11 +489,12 @@ error_put:
65914 * Always returns 0 thus allowing this function to be tail-called at the end
65915 * of, say, sys_setgid().
65916 */
65917 -int commit_creds(struct cred *new)
65918 +static int __commit_creds(struct task_struct *task, struct cred *new)
65919 {
65920 - struct task_struct *task = current;
65921 const struct cred *old = task->real_cred;
65922
65923 + pax_track_stack();
65924 +
65925 kdebug("commit_creds(%p{%d,%d})", new,
65926 atomic_read(&new->usage),
65927 read_cred_subscribers(new));
65928 @@ -489,6 +509,8 @@ int commit_creds(struct cred *new)
65929
65930 get_cred(new); /* we will require a ref for the subj creds too */
65931
65932 + gr_set_role_label(task, new->uid, new->gid);
65933 +
65934 /* dumpability changes */
65935 if (old->euid != new->euid ||
65936 old->egid != new->egid ||
65937 @@ -538,6 +560,87 @@ int commit_creds(struct cred *new)
65938 put_cred(old);
65939 return 0;
65940 }
65941 +
65942 +#ifdef CONFIG_GRKERNSEC_SETXID
65943 +static int set_task_user(struct user_namespace *user_ns, struct cred *new)
65944 +{
65945 + struct user_struct *new_user;
65946 +
65947 + new_user = alloc_uid(user_ns, new->uid);
65948 + if (!new_user)
65949 + return -EAGAIN;
65950 + free_uid(new->user);
65951 + new->user = new_user;
65952 + return 0;
65953 +}
65954 +#endif
65955 +
65956 +int commit_creds(struct cred *new)
65957 +{
65958 +#ifdef CONFIG_GRKERNSEC_SETXID
65959 + struct task_struct *t;
65960 + struct cred *ncred;
65961 + const struct cred *old;
65962 +
65963 + /* we won't get called with tasklist_lock held for writing
65964 + and interrupts disabled as the cred struct in that case is
65965 + init_cred
65966 + */
65967 + if (grsec_enable_setxid && !current_is_single_threaded() &&
65968 + !current_uid() && new->uid) {
65969 + rcu_read_lock();
65970 + read_lock(&tasklist_lock);
65971 + for (t = next_thread(current); t != current;
65972 + t = next_thread(t)) {
65973 + old = __task_cred(t);
65974 + if (old->uid)
65975 + continue;
65976 + ncred = __prepare_creds(t);
65977 + if (!ncred)
65978 + goto die;
65979 + // uids
65980 + ncred->uid = new->uid;
65981 + ncred->euid = new->euid;
65982 + ncred->suid = new->suid;
65983 + ncred->fsuid = new->fsuid;
65984 + // gids
65985 + ncred->gid = new->gid;
65986 + ncred->egid = new->egid;
65987 + ncred->sgid = new->sgid;
65988 + ncred->fsgid = new->fsgid;
65989 + // groups
65990 + if (set_groups(ncred, new->group_info) < 0) {
65991 + abort_creds(ncred);
65992 + goto die;
65993 + }
65994 + // caps
65995 + ncred->securebits = new->securebits;
65996 + ncred->cap_inheritable = new->cap_inheritable;
65997 + ncred->cap_permitted = new->cap_permitted;
65998 + ncred->cap_effective = new->cap_effective;
65999 + ncred->cap_bset = new->cap_bset;
66000 +
66001 + if (set_task_user(old->user_ns, ncred)) {
66002 + abort_creds(ncred);
66003 + goto die;
66004 + }
66005 +
66006 + __commit_creds(t, ncred);
66007 + }
66008 + read_unlock(&tasklist_lock);
66009 + rcu_read_unlock();
66010 + }
66011 +#endif
66012 + return __commit_creds(current, new);
66013 +#ifdef CONFIG_GRKERNSEC_SETXID
66014 +die:
66015 + read_unlock(&tasklist_lock);
66016 + rcu_read_unlock();
66017 + abort_creds(new);
66018 + do_group_exit(SIGKILL);
66019 +#endif
66020 +}
66021 +
66022 EXPORT_SYMBOL(commit_creds);
66023
66024 /**
66025 @@ -549,6 +652,8 @@ EXPORT_SYMBOL(commit_creds);
66026 */
66027 void abort_creds(struct cred *new)
66028 {
66029 + pax_track_stack();
66030 +
66031 kdebug("abort_creds(%p{%d,%d})", new,
66032 atomic_read(&new->usage),
66033 read_cred_subscribers(new));
66034 @@ -572,6 +677,8 @@ const struct cred *override_creds(const struct cred *new)
66035 {
66036 const struct cred *old = current->cred;
66037
66038 + pax_track_stack();
66039 +
66040 kdebug("override_creds(%p{%d,%d})", new,
66041 atomic_read(&new->usage),
66042 read_cred_subscribers(new));
66043 @@ -601,6 +708,8 @@ void revert_creds(const struct cred *old)
66044 {
66045 const struct cred *override = current->cred;
66046
66047 + pax_track_stack();
66048 +
66049 kdebug("revert_creds(%p{%d,%d})", old,
66050 atomic_read(&old->usage),
66051 read_cred_subscribers(old));
66052 @@ -647,6 +756,8 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
66053 const struct cred *old;
66054 struct cred *new;
66055
66056 + pax_track_stack();
66057 +
66058 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
66059 if (!new)
66060 return NULL;
66061 @@ -701,6 +812,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
66062 */
66063 int set_security_override(struct cred *new, u32 secid)
66064 {
66065 + pax_track_stack();
66066 +
66067 return security_kernel_act_as(new, secid);
66068 }
66069 EXPORT_SYMBOL(set_security_override);
66070 @@ -720,6 +833,8 @@ int set_security_override_from_ctx(struct cred *new, const char *secctx)
66071 u32 secid;
66072 int ret;
66073
66074 + pax_track_stack();
66075 +
66076 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
66077 if (ret < 0)
66078 return ret;
66079 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66080 index 0d7c087..01b8cef 100644
66081 --- a/kernel/debug/debug_core.c
66082 +++ b/kernel/debug/debug_core.c
66083 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66084 */
66085 static atomic_t masters_in_kgdb;
66086 static atomic_t slaves_in_kgdb;
66087 -static atomic_t kgdb_break_tasklet_var;
66088 +static atomic_unchecked_t kgdb_break_tasklet_var;
66089 atomic_t kgdb_setting_breakpoint;
66090
66091 struct task_struct *kgdb_usethread;
66092 @@ -129,7 +129,7 @@ int kgdb_single_step;
66093 static pid_t kgdb_sstep_pid;
66094
66095 /* to keep track of the CPU which is doing the single stepping*/
66096 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66097 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66098
66099 /*
66100 * If you are debugging a problem where roundup (the collection of
66101 @@ -542,7 +542,7 @@ return_normal:
66102 * kernel will only try for the value of sstep_tries before
66103 * giving up and continuing on.
66104 */
66105 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66106 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66107 (kgdb_info[cpu].task &&
66108 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66109 atomic_set(&kgdb_active, -1);
66110 @@ -636,8 +636,8 @@ cpu_master_loop:
66111 }
66112
66113 kgdb_restore:
66114 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66115 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66116 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66117 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66118 if (kgdb_info[sstep_cpu].task)
66119 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66120 else
66121 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(void)
66122 static void kgdb_tasklet_bpt(unsigned long ing)
66123 {
66124 kgdb_breakpoint();
66125 - atomic_set(&kgdb_break_tasklet_var, 0);
66126 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66127 }
66128
66129 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66130
66131 void kgdb_schedule_breakpoint(void)
66132 {
66133 - if (atomic_read(&kgdb_break_tasklet_var) ||
66134 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66135 atomic_read(&kgdb_active) != -1 ||
66136 atomic_read(&kgdb_setting_breakpoint))
66137 return;
66138 - atomic_inc(&kgdb_break_tasklet_var);
66139 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66140 tasklet_schedule(&kgdb_tasklet_breakpoint);
66141 }
66142 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66143 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66144 index 63786e7..0780cac 100644
66145 --- a/kernel/debug/kdb/kdb_main.c
66146 +++ b/kernel/debug/kdb/kdb_main.c
66147 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
66148 list_for_each_entry(mod, kdb_modules, list) {
66149
66150 kdb_printf("%-20s%8u 0x%p ", mod->name,
66151 - mod->core_size, (void *)mod);
66152 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66153 #ifdef CONFIG_MODULE_UNLOAD
66154 kdb_printf("%4d ", module_refcount(mod));
66155 #endif
66156 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
66157 kdb_printf(" (Loading)");
66158 else
66159 kdb_printf(" (Live)");
66160 - kdb_printf(" 0x%p", mod->module_core);
66161 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66162
66163 #ifdef CONFIG_MODULE_UNLOAD
66164 {
66165 diff --git a/kernel/events/core.c b/kernel/events/core.c
66166 index 0f85778..0d43716 100644
66167 --- a/kernel/events/core.c
66168 +++ b/kernel/events/core.c
66169 @@ -172,7 +172,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66170 return 0;
66171 }
66172
66173 -static atomic64_t perf_event_id;
66174 +static atomic64_unchecked_t perf_event_id;
66175
66176 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66177 enum event_type_t event_type);
66178 @@ -2535,7 +2535,7 @@ static void __perf_event_read(void *info)
66179
66180 static inline u64 perf_event_count(struct perf_event *event)
66181 {
66182 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66183 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66184 }
66185
66186 static u64 perf_event_read(struct perf_event *event)
66187 @@ -3060,9 +3060,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66188 mutex_lock(&event->child_mutex);
66189 total += perf_event_read(event);
66190 *enabled += event->total_time_enabled +
66191 - atomic64_read(&event->child_total_time_enabled);
66192 + atomic64_read_unchecked(&event->child_total_time_enabled);
66193 *running += event->total_time_running +
66194 - atomic64_read(&event->child_total_time_running);
66195 + atomic64_read_unchecked(&event->child_total_time_running);
66196
66197 list_for_each_entry(child, &event->child_list, child_list) {
66198 total += perf_event_read(child);
66199 @@ -3448,10 +3448,10 @@ void perf_event_update_userpage(struct perf_event *event)
66200 userpg->offset -= local64_read(&event->hw.prev_count);
66201
66202 userpg->time_enabled = enabled +
66203 - atomic64_read(&event->child_total_time_enabled);
66204 + atomic64_read_unchecked(&event->child_total_time_enabled);
66205
66206 userpg->time_running = running +
66207 - atomic64_read(&event->child_total_time_running);
66208 + atomic64_read_unchecked(&event->child_total_time_running);
66209
66210 barrier();
66211 ++userpg->lock;
66212 @@ -3822,11 +3822,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66213 values[n++] = perf_event_count(event);
66214 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66215 values[n++] = enabled +
66216 - atomic64_read(&event->child_total_time_enabled);
66217 + atomic64_read_unchecked(&event->child_total_time_enabled);
66218 }
66219 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66220 values[n++] = running +
66221 - atomic64_read(&event->child_total_time_running);
66222 + atomic64_read_unchecked(&event->child_total_time_running);
66223 }
66224 if (read_format & PERF_FORMAT_ID)
66225 values[n++] = primary_event_id(event);
66226 @@ -4477,12 +4477,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66227 * need to add enough zero bytes after the string to handle
66228 * the 64bit alignment we do later.
66229 */
66230 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66231 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
66232 if (!buf) {
66233 name = strncpy(tmp, "//enomem", sizeof(tmp));
66234 goto got_name;
66235 }
66236 - name = d_path(&file->f_path, buf, PATH_MAX);
66237 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66238 if (IS_ERR(name)) {
66239 name = strncpy(tmp, "//toolong", sizeof(tmp));
66240 goto got_name;
66241 @@ -5833,7 +5833,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66242 event->parent = parent_event;
66243
66244 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66245 - event->id = atomic64_inc_return(&perf_event_id);
66246 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
66247
66248 event->state = PERF_EVENT_STATE_INACTIVE;
66249
66250 @@ -6355,10 +6355,10 @@ static void sync_child_event(struct perf_event *child_event,
66251 /*
66252 * Add back the child's count to the parent's count:
66253 */
66254 - atomic64_add(child_val, &parent_event->child_count);
66255 - atomic64_add(child_event->total_time_enabled,
66256 + atomic64_add_unchecked(child_val, &parent_event->child_count);
66257 + atomic64_add_unchecked(child_event->total_time_enabled,
66258 &parent_event->child_total_time_enabled);
66259 - atomic64_add(child_event->total_time_running,
66260 + atomic64_add_unchecked(child_event->total_time_running,
66261 &parent_event->child_total_time_running);
66262
66263 /*
66264 diff --git a/kernel/exit.c b/kernel/exit.c
66265 index 9e316ae..b3656d5 100644
66266 --- a/kernel/exit.c
66267 +++ b/kernel/exit.c
66268 @@ -57,6 +57,10 @@
66269 #include <asm/pgtable.h>
66270 #include <asm/mmu_context.h>
66271
66272 +#ifdef CONFIG_GRKERNSEC
66273 +extern rwlock_t grsec_exec_file_lock;
66274 +#endif
66275 +
66276 static void exit_mm(struct task_struct * tsk);
66277
66278 static void __unhash_process(struct task_struct *p, bool group_dead)
66279 @@ -168,6 +172,10 @@ void release_task(struct task_struct * p)
66280 struct task_struct *leader;
66281 int zap_leader;
66282 repeat:
66283 +#ifdef CONFIG_NET
66284 + gr_del_task_from_ip_table(p);
66285 +#endif
66286 +
66287 /* don't need to get the RCU readlock here - the process is dead and
66288 * can't be modifying its own credentials. But shut RCU-lockdep up */
66289 rcu_read_lock();
66290 @@ -380,7 +388,7 @@ int allow_signal(int sig)
66291 * know it'll be handled, so that they don't get converted to
66292 * SIGKILL or just silently dropped.
66293 */
66294 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66295 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66296 recalc_sigpending();
66297 spin_unlock_irq(&current->sighand->siglock);
66298 return 0;
66299 @@ -416,6 +424,17 @@ void daemonize(const char *name, ...)
66300 vsnprintf(current->comm, sizeof(current->comm), name, args);
66301 va_end(args);
66302
66303 +#ifdef CONFIG_GRKERNSEC
66304 + write_lock(&grsec_exec_file_lock);
66305 + if (current->exec_file) {
66306 + fput(current->exec_file);
66307 + current->exec_file = NULL;
66308 + }
66309 + write_unlock(&grsec_exec_file_lock);
66310 +#endif
66311 +
66312 + gr_set_kernel_label(current);
66313 +
66314 /*
66315 * If we were started as result of loading a module, close all of the
66316 * user space pages. We don't need them, and if we didn't close them
66317 @@ -895,6 +914,8 @@ NORET_TYPE void do_exit(long code)
66318 struct task_struct *tsk = current;
66319 int group_dead;
66320
66321 + set_fs(USER_DS);
66322 +
66323 profile_task_exit(tsk);
66324
66325 WARN_ON(blk_needs_flush_plug(tsk));
66326 @@ -911,7 +932,6 @@ NORET_TYPE void do_exit(long code)
66327 * mm_release()->clear_child_tid() from writing to a user-controlled
66328 * kernel address.
66329 */
66330 - set_fs(USER_DS);
66331
66332 ptrace_event(PTRACE_EVENT_EXIT, code);
66333
66334 @@ -973,6 +993,9 @@ NORET_TYPE void do_exit(long code)
66335 tsk->exit_code = code;
66336 taskstats_exit(tsk, group_dead);
66337
66338 + gr_acl_handle_psacct(tsk, code);
66339 + gr_acl_handle_exit();
66340 +
66341 exit_mm(tsk);
66342
66343 if (group_dead)
66344 diff --git a/kernel/fork.c b/kernel/fork.c
66345 index 8e6b6f4..9dccf00 100644
66346 --- a/kernel/fork.c
66347 +++ b/kernel/fork.c
66348 @@ -285,7 +285,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66349 *stackend = STACK_END_MAGIC; /* for overflow detection */
66350
66351 #ifdef CONFIG_CC_STACKPROTECTOR
66352 - tsk->stack_canary = get_random_int();
66353 + tsk->stack_canary = pax_get_random_long();
66354 #endif
66355
66356 /*
66357 @@ -309,13 +309,77 @@ out:
66358 }
66359
66360 #ifdef CONFIG_MMU
66361 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
66362 +{
66363 + struct vm_area_struct *tmp;
66364 + unsigned long charge;
66365 + struct mempolicy *pol;
66366 + struct file *file;
66367 +
66368 + charge = 0;
66369 + if (mpnt->vm_flags & VM_ACCOUNT) {
66370 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66371 + if (security_vm_enough_memory(len))
66372 + goto fail_nomem;
66373 + charge = len;
66374 + }
66375 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66376 + if (!tmp)
66377 + goto fail_nomem;
66378 + *tmp = *mpnt;
66379 + tmp->vm_mm = mm;
66380 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66381 + pol = mpol_dup(vma_policy(mpnt));
66382 + if (IS_ERR(pol))
66383 + goto fail_nomem_policy;
66384 + vma_set_policy(tmp, pol);
66385 + if (anon_vma_fork(tmp, mpnt))
66386 + goto fail_nomem_anon_vma_fork;
66387 + tmp->vm_flags &= ~VM_LOCKED;
66388 + tmp->vm_next = tmp->vm_prev = NULL;
66389 + tmp->vm_mirror = NULL;
66390 + file = tmp->vm_file;
66391 + if (file) {
66392 + struct inode *inode = file->f_path.dentry->d_inode;
66393 + struct address_space *mapping = file->f_mapping;
66394 +
66395 + get_file(file);
66396 + if (tmp->vm_flags & VM_DENYWRITE)
66397 + atomic_dec(&inode->i_writecount);
66398 + mutex_lock(&mapping->i_mmap_mutex);
66399 + if (tmp->vm_flags & VM_SHARED)
66400 + mapping->i_mmap_writable++;
66401 + flush_dcache_mmap_lock(mapping);
66402 + /* insert tmp into the share list, just after mpnt */
66403 + vma_prio_tree_add(tmp, mpnt);
66404 + flush_dcache_mmap_unlock(mapping);
66405 + mutex_unlock(&mapping->i_mmap_mutex);
66406 + }
66407 +
66408 + /*
66409 + * Clear hugetlb-related page reserves for children. This only
66410 + * affects MAP_PRIVATE mappings. Faults generated by the child
66411 + * are not guaranteed to succeed, even if read-only
66412 + */
66413 + if (is_vm_hugetlb_page(tmp))
66414 + reset_vma_resv_huge_pages(tmp);
66415 +
66416 + return tmp;
66417 +
66418 +fail_nomem_anon_vma_fork:
66419 + mpol_put(pol);
66420 +fail_nomem_policy:
66421 + kmem_cache_free(vm_area_cachep, tmp);
66422 +fail_nomem:
66423 + vm_unacct_memory(charge);
66424 + return NULL;
66425 +}
66426 +
66427 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66428 {
66429 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66430 struct rb_node **rb_link, *rb_parent;
66431 int retval;
66432 - unsigned long charge;
66433 - struct mempolicy *pol;
66434
66435 down_write(&oldmm->mmap_sem);
66436 flush_cache_dup_mm(oldmm);
66437 @@ -327,8 +391,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66438 mm->locked_vm = 0;
66439 mm->mmap = NULL;
66440 mm->mmap_cache = NULL;
66441 - mm->free_area_cache = oldmm->mmap_base;
66442 - mm->cached_hole_size = ~0UL;
66443 + mm->free_area_cache = oldmm->free_area_cache;
66444 + mm->cached_hole_size = oldmm->cached_hole_size;
66445 mm->map_count = 0;
66446 cpumask_clear(mm_cpumask(mm));
66447 mm->mm_rb = RB_ROOT;
66448 @@ -344,8 +408,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66449
66450 prev = NULL;
66451 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66452 - struct file *file;
66453 -
66454 if (mpnt->vm_flags & VM_DONTCOPY) {
66455 long pages = vma_pages(mpnt);
66456 mm->total_vm -= pages;
66457 @@ -353,53 +415,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66458 -pages);
66459 continue;
66460 }
66461 - charge = 0;
66462 - if (mpnt->vm_flags & VM_ACCOUNT) {
66463 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66464 - if (security_vm_enough_memory(len))
66465 - goto fail_nomem;
66466 - charge = len;
66467 + tmp = dup_vma(mm, mpnt);
66468 + if (!tmp) {
66469 + retval = -ENOMEM;
66470 + goto out;
66471 }
66472 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66473 - if (!tmp)
66474 - goto fail_nomem;
66475 - *tmp = *mpnt;
66476 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66477 - pol = mpol_dup(vma_policy(mpnt));
66478 - retval = PTR_ERR(pol);
66479 - if (IS_ERR(pol))
66480 - goto fail_nomem_policy;
66481 - vma_set_policy(tmp, pol);
66482 - tmp->vm_mm = mm;
66483 - if (anon_vma_fork(tmp, mpnt))
66484 - goto fail_nomem_anon_vma_fork;
66485 - tmp->vm_flags &= ~VM_LOCKED;
66486 - tmp->vm_next = tmp->vm_prev = NULL;
66487 - file = tmp->vm_file;
66488 - if (file) {
66489 - struct inode *inode = file->f_path.dentry->d_inode;
66490 - struct address_space *mapping = file->f_mapping;
66491 -
66492 - get_file(file);
66493 - if (tmp->vm_flags & VM_DENYWRITE)
66494 - atomic_dec(&inode->i_writecount);
66495 - mutex_lock(&mapping->i_mmap_mutex);
66496 - if (tmp->vm_flags & VM_SHARED)
66497 - mapping->i_mmap_writable++;
66498 - flush_dcache_mmap_lock(mapping);
66499 - /* insert tmp into the share list, just after mpnt */
66500 - vma_prio_tree_add(tmp, mpnt);
66501 - flush_dcache_mmap_unlock(mapping);
66502 - mutex_unlock(&mapping->i_mmap_mutex);
66503 - }
66504 -
66505 - /*
66506 - * Clear hugetlb-related page reserves for children. This only
66507 - * affects MAP_PRIVATE mappings. Faults generated by the child
66508 - * are not guaranteed to succeed, even if read-only
66509 - */
66510 - if (is_vm_hugetlb_page(tmp))
66511 - reset_vma_resv_huge_pages(tmp);
66512
66513 /*
66514 * Link in the new vma and copy the page table entries.
66515 @@ -422,6 +442,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66516 if (retval)
66517 goto out;
66518 }
66519 +
66520 +#ifdef CONFIG_PAX_SEGMEXEC
66521 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66522 + struct vm_area_struct *mpnt_m;
66523 +
66524 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66525 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66526 +
66527 + if (!mpnt->vm_mirror)
66528 + continue;
66529 +
66530 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66531 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66532 + mpnt->vm_mirror = mpnt_m;
66533 + } else {
66534 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66535 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66536 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66537 + mpnt->vm_mirror->vm_mirror = mpnt;
66538 + }
66539 + }
66540 + BUG_ON(mpnt_m);
66541 + }
66542 +#endif
66543 +
66544 /* a new mm has just been created */
66545 arch_dup_mmap(oldmm, mm);
66546 retval = 0;
66547 @@ -430,14 +475,6 @@ out:
66548 flush_tlb_mm(oldmm);
66549 up_write(&oldmm->mmap_sem);
66550 return retval;
66551 -fail_nomem_anon_vma_fork:
66552 - mpol_put(pol);
66553 -fail_nomem_policy:
66554 - kmem_cache_free(vm_area_cachep, tmp);
66555 -fail_nomem:
66556 - retval = -ENOMEM;
66557 - vm_unacct_memory(charge);
66558 - goto out;
66559 }
66560
66561 static inline int mm_alloc_pgd(struct mm_struct *mm)
66562 @@ -837,13 +874,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66563 spin_unlock(&fs->lock);
66564 return -EAGAIN;
66565 }
66566 - fs->users++;
66567 + atomic_inc(&fs->users);
66568 spin_unlock(&fs->lock);
66569 return 0;
66570 }
66571 tsk->fs = copy_fs_struct(fs);
66572 if (!tsk->fs)
66573 return -ENOMEM;
66574 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66575 return 0;
66576 }
66577
66578 @@ -1105,6 +1143,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66579 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66580 #endif
66581 retval = -EAGAIN;
66582 +
66583 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66584 +
66585 if (atomic_read(&p->real_cred->user->processes) >=
66586 task_rlimit(p, RLIMIT_NPROC)) {
66587 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66588 @@ -1264,6 +1305,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66589 if (clone_flags & CLONE_THREAD)
66590 p->tgid = current->tgid;
66591
66592 + gr_copy_label(p);
66593 +
66594 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
66595 /*
66596 * Clear TID on mm_release()?
66597 @@ -1428,6 +1471,8 @@ bad_fork_cleanup_count:
66598 bad_fork_free:
66599 free_task(p);
66600 fork_out:
66601 + gr_log_forkfail(retval);
66602 +
66603 return ERR_PTR(retval);
66604 }
66605
66606 @@ -1528,6 +1573,8 @@ long do_fork(unsigned long clone_flags,
66607 if (clone_flags & CLONE_PARENT_SETTID)
66608 put_user(nr, parent_tidptr);
66609
66610 + gr_handle_brute_check();
66611 +
66612 if (clone_flags & CLONE_VFORK) {
66613 p->vfork_done = &vfork;
66614 init_completion(&vfork);
66615 @@ -1637,7 +1684,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66616 return 0;
66617
66618 /* don't need lock here; in the worst case we'll do useless copy */
66619 - if (fs->users == 1)
66620 + if (atomic_read(&fs->users) == 1)
66621 return 0;
66622
66623 *new_fsp = copy_fs_struct(fs);
66624 @@ -1726,7 +1773,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66625 fs = current->fs;
66626 spin_lock(&fs->lock);
66627 current->fs = new_fs;
66628 - if (--fs->users)
66629 + gr_set_chroot_entries(current, &current->fs->root);
66630 + if (atomic_dec_return(&fs->users))
66631 new_fs = NULL;
66632 else
66633 new_fs = fs;
66634 diff --git a/kernel/futex.c b/kernel/futex.c
66635 index e6160fa..edf9565 100644
66636 --- a/kernel/futex.c
66637 +++ b/kernel/futex.c
66638 @@ -54,6 +54,7 @@
66639 #include <linux/mount.h>
66640 #include <linux/pagemap.h>
66641 #include <linux/syscalls.h>
66642 +#include <linux/ptrace.h>
66643 #include <linux/signal.h>
66644 #include <linux/module.h>
66645 #include <linux/magic.h>
66646 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66647 struct page *page, *page_head;
66648 int err, ro = 0;
66649
66650 +#ifdef CONFIG_PAX_SEGMEXEC
66651 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66652 + return -EFAULT;
66653 +#endif
66654 +
66655 /*
66656 * The futex address must be "naturally" aligned.
66657 */
66658 @@ -1875,6 +1881,8 @@ static int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val,
66659 struct futex_q q = futex_q_init;
66660 int ret;
66661
66662 + pax_track_stack();
66663 +
66664 if (!bitset)
66665 return -EINVAL;
66666 q.bitset = bitset;
66667 @@ -2271,6 +2279,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
66668 struct futex_q q = futex_q_init;
66669 int res, ret;
66670
66671 + pax_track_stack();
66672 +
66673 if (!bitset)
66674 return -EINVAL;
66675
66676 @@ -2459,6 +2469,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
66677 if (!p)
66678 goto err_unlock;
66679 ret = -EPERM;
66680 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66681 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
66682 + goto err_unlock;
66683 +#endif
66684 pcred = __task_cred(p);
66685 /* If victim is in different user_ns, then uids are not
66686 comparable, so we must have CAP_SYS_PTRACE */
66687 @@ -2724,6 +2738,7 @@ static int __init futex_init(void)
66688 {
66689 u32 curval;
66690 int i;
66691 + mm_segment_t oldfs;
66692
66693 /*
66694 * This will fail and we want it. Some arch implementations do
66695 @@ -2735,8 +2750,11 @@ static int __init futex_init(void)
66696 * implementation, the non-functional ones will return
66697 * -ENOSYS.
66698 */
66699 + oldfs = get_fs();
66700 + set_fs(USER_DS);
66701 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66702 futex_cmpxchg_enabled = 1;
66703 + set_fs(oldfs);
66704
66705 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66706 plist_head_init(&futex_queues[i].chain);
66707 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
66708 index 5f9e689..582d46d 100644
66709 --- a/kernel/futex_compat.c
66710 +++ b/kernel/futex_compat.c
66711 @@ -10,6 +10,7 @@
66712 #include <linux/compat.h>
66713 #include <linux/nsproxy.h>
66714 #include <linux/futex.h>
66715 +#include <linux/ptrace.h>
66716
66717 #include <asm/uaccess.h>
66718
66719 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
66720 {
66721 struct compat_robust_list_head __user *head;
66722 unsigned long ret;
66723 - const struct cred *cred = current_cred(), *pcred;
66724 + const struct cred *cred = current_cred();
66725 + const struct cred *pcred;
66726
66727 if (!futex_cmpxchg_enabled)
66728 return -ENOSYS;
66729 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
66730 if (!p)
66731 goto err_unlock;
66732 ret = -EPERM;
66733 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66734 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
66735 + goto err_unlock;
66736 +#endif
66737 pcred = __task_cred(p);
66738 /* If victim is in different user_ns, then uids are not
66739 comparable, so we must have CAP_SYS_PTRACE */
66740 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66741 index 9b22d03..6295b62 100644
66742 --- a/kernel/gcov/base.c
66743 +++ b/kernel/gcov/base.c
66744 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
66745 }
66746
66747 #ifdef CONFIG_MODULES
66748 -static inline int within(void *addr, void *start, unsigned long size)
66749 -{
66750 - return ((addr >= start) && (addr < start + size));
66751 -}
66752 -
66753 /* Update list and generate events when modules are unloaded. */
66754 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66755 void *data)
66756 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66757 prev = NULL;
66758 /* Remove entries located in module from linked list. */
66759 for (info = gcov_info_head; info; info = info->next) {
66760 - if (within(info, mod->module_core, mod->core_size)) {
66761 + if (within_module_core_rw((unsigned long)info, mod)) {
66762 if (prev)
66763 prev->next = info->next;
66764 else
66765 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66766 index 2043c08..ec81a69 100644
66767 --- a/kernel/hrtimer.c
66768 +++ b/kernel/hrtimer.c
66769 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
66770 local_irq_restore(flags);
66771 }
66772
66773 -static void run_hrtimer_softirq(struct softirq_action *h)
66774 +static void run_hrtimer_softirq(void)
66775 {
66776 hrtimer_peek_ahead_timers();
66777 }
66778 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66779 index e6f1f24..6c19597 100644
66780 --- a/kernel/jump_label.c
66781 +++ b/kernel/jump_label.c
66782 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66783
66784 size = (((unsigned long)stop - (unsigned long)start)
66785 / sizeof(struct jump_entry));
66786 + pax_open_kernel();
66787 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66788 + pax_close_kernel();
66789 }
66790
66791 static void jump_label_update(struct jump_label_key *key, int enable);
66792 @@ -298,10 +300,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66793 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66794 struct jump_entry *iter;
66795
66796 + pax_open_kernel();
66797 for (iter = iter_start; iter < iter_stop; iter++) {
66798 if (within_module_init(iter->code, mod))
66799 iter->code = 0;
66800 }
66801 + pax_close_kernel();
66802 }
66803
66804 static int
66805 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66806 index 079f1d3..a407562 100644
66807 --- a/kernel/kallsyms.c
66808 +++ b/kernel/kallsyms.c
66809 @@ -11,6 +11,9 @@
66810 * Changed the compression method from stem compression to "table lookup"
66811 * compression (see scripts/kallsyms.c for a more complete description)
66812 */
66813 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66814 +#define __INCLUDED_BY_HIDESYM 1
66815 +#endif
66816 #include <linux/kallsyms.h>
66817 #include <linux/module.h>
66818 #include <linux/init.h>
66819 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66820
66821 static inline int is_kernel_inittext(unsigned long addr)
66822 {
66823 + if (system_state != SYSTEM_BOOTING)
66824 + return 0;
66825 +
66826 if (addr >= (unsigned long)_sinittext
66827 && addr <= (unsigned long)_einittext)
66828 return 1;
66829 return 0;
66830 }
66831
66832 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66833 +#ifdef CONFIG_MODULES
66834 +static inline int is_module_text(unsigned long addr)
66835 +{
66836 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66837 + return 1;
66838 +
66839 + addr = ktla_ktva(addr);
66840 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66841 +}
66842 +#else
66843 +static inline int is_module_text(unsigned long addr)
66844 +{
66845 + return 0;
66846 +}
66847 +#endif
66848 +#endif
66849 +
66850 static inline int is_kernel_text(unsigned long addr)
66851 {
66852 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66853 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66854
66855 static inline int is_kernel(unsigned long addr)
66856 {
66857 +
66858 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66859 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
66860 + return 1;
66861 +
66862 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66863 +#else
66864 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66865 +#endif
66866 +
66867 return 1;
66868 return in_gate_area_no_mm(addr);
66869 }
66870
66871 static int is_ksym_addr(unsigned long addr)
66872 {
66873 +
66874 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66875 + if (is_module_text(addr))
66876 + return 0;
66877 +#endif
66878 +
66879 if (all_var)
66880 return is_kernel(addr);
66881
66882 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66883
66884 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66885 {
66886 - iter->name[0] = '\0';
66887 iter->nameoff = get_symbol_offset(new_pos);
66888 iter->pos = new_pos;
66889 }
66890 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66891 {
66892 struct kallsym_iter *iter = m->private;
66893
66894 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66895 + if (current_uid())
66896 + return 0;
66897 +#endif
66898 +
66899 /* Some debugging symbols have no name. Ignore them. */
66900 if (!iter->name[0])
66901 return 0;
66902 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66903 struct kallsym_iter *iter;
66904 int ret;
66905
66906 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66907 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66908 if (!iter)
66909 return -ENOMEM;
66910 reset_iter(iter, 0);
66911 diff --git a/kernel/kexec.c b/kernel/kexec.c
66912 index 296fbc8..84cb857 100644
66913 --- a/kernel/kexec.c
66914 +++ b/kernel/kexec.c
66915 @@ -1033,7 +1033,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66916 unsigned long flags)
66917 {
66918 struct compat_kexec_segment in;
66919 - struct kexec_segment out, __user *ksegments;
66920 + struct kexec_segment out;
66921 + struct kexec_segment __user *ksegments;
66922 unsigned long i, result;
66923
66924 /* Don't allow clients that don't understand the native
66925 diff --git a/kernel/kmod.c b/kernel/kmod.c
66926 index a4bea97..7a1ae9a 100644
66927 --- a/kernel/kmod.c
66928 +++ b/kernel/kmod.c
66929 @@ -73,13 +73,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
66930 * If module auto-loading support is disabled then this function
66931 * becomes a no-operation.
66932 */
66933 -int __request_module(bool wait, const char *fmt, ...)
66934 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
66935 {
66936 - va_list args;
66937 char module_name[MODULE_NAME_LEN];
66938 unsigned int max_modprobes;
66939 int ret;
66940 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
66941 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
66942 static char *envp[] = { "HOME=/",
66943 "TERM=linux",
66944 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
66945 @@ -88,9 +87,7 @@ int __request_module(bool wait, const char *fmt, ...)
66946 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
66947 static int kmod_loop_msg;
66948
66949 - va_start(args, fmt);
66950 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
66951 - va_end(args);
66952 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
66953 if (ret >= MODULE_NAME_LEN)
66954 return -ENAMETOOLONG;
66955
66956 @@ -98,6 +95,20 @@ int __request_module(bool wait, const char *fmt, ...)
66957 if (ret)
66958 return ret;
66959
66960 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66961 + if (!current_uid()) {
66962 + /* hack to workaround consolekit/udisks stupidity */
66963 + read_lock(&tasklist_lock);
66964 + if (!strcmp(current->comm, "mount") &&
66965 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
66966 + read_unlock(&tasklist_lock);
66967 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
66968 + return -EPERM;
66969 + }
66970 + read_unlock(&tasklist_lock);
66971 + }
66972 +#endif
66973 +
66974 /* If modprobe needs a service that is in a module, we get a recursive
66975 * loop. Limit the number of running kmod threads to max_threads/2 or
66976 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66977 @@ -133,6 +144,47 @@ int __request_module(bool wait, const char *fmt, ...)
66978 atomic_dec(&kmod_concurrent);
66979 return ret;
66980 }
66981 +
66982 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66983 +{
66984 + va_list args;
66985 + int ret;
66986 +
66987 + va_start(args, fmt);
66988 + ret = ____request_module(wait, module_param, fmt, args);
66989 + va_end(args);
66990 +
66991 + return ret;
66992 +}
66993 +
66994 +int __request_module(bool wait, const char *fmt, ...)
66995 +{
66996 + va_list args;
66997 + int ret;
66998 +
66999 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67000 + if (current_uid()) {
67001 + char module_param[MODULE_NAME_LEN];
67002 +
67003 + memset(module_param, 0, sizeof(module_param));
67004 +
67005 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67006 +
67007 + va_start(args, fmt);
67008 + ret = ____request_module(wait, module_param, fmt, args);
67009 + va_end(args);
67010 +
67011 + return ret;
67012 + }
67013 +#endif
67014 +
67015 + va_start(args, fmt);
67016 + ret = ____request_module(wait, NULL, fmt, args);
67017 + va_end(args);
67018 +
67019 + return ret;
67020 +}
67021 +
67022 EXPORT_SYMBOL(__request_module);
67023 #endif /* CONFIG_MODULES */
67024
67025 @@ -222,7 +274,7 @@ static int wait_for_helper(void *data)
67026 *
67027 * Thus the __user pointer cast is valid here.
67028 */
67029 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67030 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67031
67032 /*
67033 * If ret is 0, either ____call_usermodehelper failed and the
67034 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67035 index b30fd54..11821ec 100644
67036 --- a/kernel/kprobes.c
67037 +++ b/kernel/kprobes.c
67038 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67039 * kernel image and loaded module images reside. This is required
67040 * so x86_64 can correctly handle the %rip-relative fixups.
67041 */
67042 - kip->insns = module_alloc(PAGE_SIZE);
67043 + kip->insns = module_alloc_exec(PAGE_SIZE);
67044 if (!kip->insns) {
67045 kfree(kip);
67046 return NULL;
67047 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67048 */
67049 if (!list_is_singular(&kip->list)) {
67050 list_del(&kip->list);
67051 - module_free(NULL, kip->insns);
67052 + module_free_exec(NULL, kip->insns);
67053 kfree(kip);
67054 }
67055 return 1;
67056 @@ -1949,7 +1949,7 @@ static int __init init_kprobes(void)
67057 {
67058 int i, err = 0;
67059 unsigned long offset = 0, size = 0;
67060 - char *modname, namebuf[128];
67061 + char *modname, namebuf[KSYM_NAME_LEN];
67062 const char *symbol_name;
67063 void *addr;
67064 struct kprobe_blackpoint *kb;
67065 @@ -2075,7 +2075,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67066 const char *sym = NULL;
67067 unsigned int i = *(loff_t *) v;
67068 unsigned long offset = 0;
67069 - char *modname, namebuf[128];
67070 + char *modname, namebuf[KSYM_NAME_LEN];
67071
67072 head = &kprobe_table[i];
67073 preempt_disable();
67074 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67075 index 4479606..4036bea 100644
67076 --- a/kernel/lockdep.c
67077 +++ b/kernel/lockdep.c
67078 @@ -584,6 +584,10 @@ static int static_obj(void *obj)
67079 end = (unsigned long) &_end,
67080 addr = (unsigned long) obj;
67081
67082 +#ifdef CONFIG_PAX_KERNEXEC
67083 + start = ktla_ktva(start);
67084 +#endif
67085 +
67086 /*
67087 * static variable?
67088 */
67089 @@ -719,6 +723,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67090 if (!static_obj(lock->key)) {
67091 debug_locks_off();
67092 printk("INFO: trying to register non-static key.\n");
67093 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67094 printk("the code is fine but needs lockdep annotation.\n");
67095 printk("turning off the locking correctness validator.\n");
67096 dump_stack();
67097 @@ -2954,7 +2959,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67098 if (!class)
67099 return 0;
67100 }
67101 - atomic_inc((atomic_t *)&class->ops);
67102 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67103 if (very_verbose(class)) {
67104 printk("\nacquire class [%p] %s", class->key, class->name);
67105 if (class->name_version > 1)
67106 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67107 index 71edd2f..e0542a5 100644
67108 --- a/kernel/lockdep_proc.c
67109 +++ b/kernel/lockdep_proc.c
67110 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67111
67112 static void print_name(struct seq_file *m, struct lock_class *class)
67113 {
67114 - char str[128];
67115 + char str[KSYM_NAME_LEN];
67116 const char *name = class->name;
67117
67118 if (!name) {
67119 diff --git a/kernel/module.c b/kernel/module.c
67120 index 04379f92..fba2faf 100644
67121 --- a/kernel/module.c
67122 +++ b/kernel/module.c
67123 @@ -58,6 +58,7 @@
67124 #include <linux/jump_label.h>
67125 #include <linux/pfn.h>
67126 #include <linux/bsearch.h>
67127 +#include <linux/grsecurity.h>
67128
67129 #define CREATE_TRACE_POINTS
67130 #include <trace/events/module.h>
67131 @@ -119,7 +120,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67132
67133 /* Bounds of module allocation, for speeding __module_address.
67134 * Protected by module_mutex. */
67135 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67136 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67137 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67138
67139 int register_module_notifier(struct notifier_block * nb)
67140 {
67141 @@ -284,7 +286,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67142 return true;
67143
67144 list_for_each_entry_rcu(mod, &modules, list) {
67145 - struct symsearch arr[] = {
67146 + struct symsearch modarr[] = {
67147 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67148 NOT_GPL_ONLY, false },
67149 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67150 @@ -306,7 +308,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67151 #endif
67152 };
67153
67154 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67155 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67156 return true;
67157 }
67158 return false;
67159 @@ -438,7 +440,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67160 static int percpu_modalloc(struct module *mod,
67161 unsigned long size, unsigned long align)
67162 {
67163 - if (align > PAGE_SIZE) {
67164 + if (align-1 >= PAGE_SIZE) {
67165 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67166 mod->name, align, PAGE_SIZE);
67167 align = PAGE_SIZE;
67168 @@ -1183,7 +1185,7 @@ resolve_symbol_wait(struct module *mod,
67169 */
67170 #ifdef CONFIG_SYSFS
67171
67172 -#ifdef CONFIG_KALLSYMS
67173 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67174 static inline bool sect_empty(const Elf_Shdr *sect)
67175 {
67176 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67177 @@ -1649,21 +1651,21 @@ static void set_section_ro_nx(void *base,
67178
67179 static void unset_module_core_ro_nx(struct module *mod)
67180 {
67181 - set_page_attributes(mod->module_core + mod->core_text_size,
67182 - mod->module_core + mod->core_size,
67183 + set_page_attributes(mod->module_core_rw,
67184 + mod->module_core_rw + mod->core_size_rw,
67185 set_memory_x);
67186 - set_page_attributes(mod->module_core,
67187 - mod->module_core + mod->core_ro_size,
67188 + set_page_attributes(mod->module_core_rx,
67189 + mod->module_core_rx + mod->core_size_rx,
67190 set_memory_rw);
67191 }
67192
67193 static void unset_module_init_ro_nx(struct module *mod)
67194 {
67195 - set_page_attributes(mod->module_init + mod->init_text_size,
67196 - mod->module_init + mod->init_size,
67197 + set_page_attributes(mod->module_init_rw,
67198 + mod->module_init_rw + mod->init_size_rw,
67199 set_memory_x);
67200 - set_page_attributes(mod->module_init,
67201 - mod->module_init + mod->init_ro_size,
67202 + set_page_attributes(mod->module_init_rx,
67203 + mod->module_init_rx + mod->init_size_rx,
67204 set_memory_rw);
67205 }
67206
67207 @@ -1674,14 +1676,14 @@ void set_all_modules_text_rw(void)
67208
67209 mutex_lock(&module_mutex);
67210 list_for_each_entry_rcu(mod, &modules, list) {
67211 - if ((mod->module_core) && (mod->core_text_size)) {
67212 - set_page_attributes(mod->module_core,
67213 - mod->module_core + mod->core_text_size,
67214 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67215 + set_page_attributes(mod->module_core_rx,
67216 + mod->module_core_rx + mod->core_size_rx,
67217 set_memory_rw);
67218 }
67219 - if ((mod->module_init) && (mod->init_text_size)) {
67220 - set_page_attributes(mod->module_init,
67221 - mod->module_init + mod->init_text_size,
67222 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67223 + set_page_attributes(mod->module_init_rx,
67224 + mod->module_init_rx + mod->init_size_rx,
67225 set_memory_rw);
67226 }
67227 }
67228 @@ -1695,14 +1697,14 @@ void set_all_modules_text_ro(void)
67229
67230 mutex_lock(&module_mutex);
67231 list_for_each_entry_rcu(mod, &modules, list) {
67232 - if ((mod->module_core) && (mod->core_text_size)) {
67233 - set_page_attributes(mod->module_core,
67234 - mod->module_core + mod->core_text_size,
67235 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67236 + set_page_attributes(mod->module_core_rx,
67237 + mod->module_core_rx + mod->core_size_rx,
67238 set_memory_ro);
67239 }
67240 - if ((mod->module_init) && (mod->init_text_size)) {
67241 - set_page_attributes(mod->module_init,
67242 - mod->module_init + mod->init_text_size,
67243 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67244 + set_page_attributes(mod->module_init_rx,
67245 + mod->module_init_rx + mod->init_size_rx,
67246 set_memory_ro);
67247 }
67248 }
67249 @@ -1748,16 +1750,19 @@ static void free_module(struct module *mod)
67250
67251 /* This may be NULL, but that's OK */
67252 unset_module_init_ro_nx(mod);
67253 - module_free(mod, mod->module_init);
67254 + module_free(mod, mod->module_init_rw);
67255 + module_free_exec(mod, mod->module_init_rx);
67256 kfree(mod->args);
67257 percpu_modfree(mod);
67258
67259 /* Free lock-classes: */
67260 - lockdep_free_key_range(mod->module_core, mod->core_size);
67261 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67262 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67263
67264 /* Finally, free the core (containing the module structure) */
67265 unset_module_core_ro_nx(mod);
67266 - module_free(mod, mod->module_core);
67267 + module_free_exec(mod, mod->module_core_rx);
67268 + module_free(mod, mod->module_core_rw);
67269
67270 #ifdef CONFIG_MPU
67271 update_protections(current->mm);
67272 @@ -1826,10 +1831,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67273 unsigned int i;
67274 int ret = 0;
67275 const struct kernel_symbol *ksym;
67276 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67277 + int is_fs_load = 0;
67278 + int register_filesystem_found = 0;
67279 + char *p;
67280 +
67281 + p = strstr(mod->args, "grsec_modharden_fs");
67282 + if (p) {
67283 + char *endptr = p + strlen("grsec_modharden_fs");
67284 + /* copy \0 as well */
67285 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67286 + is_fs_load = 1;
67287 + }
67288 +#endif
67289
67290 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67291 const char *name = info->strtab + sym[i].st_name;
67292
67293 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67294 + /* it's a real shame this will never get ripped and copied
67295 + upstream! ;(
67296 + */
67297 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67298 + register_filesystem_found = 1;
67299 +#endif
67300 +
67301 switch (sym[i].st_shndx) {
67302 case SHN_COMMON:
67303 /* We compiled with -fno-common. These are not
67304 @@ -1850,7 +1876,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67305 ksym = resolve_symbol_wait(mod, info, name);
67306 /* Ok if resolved. */
67307 if (ksym && !IS_ERR(ksym)) {
67308 + pax_open_kernel();
67309 sym[i].st_value = ksym->value;
67310 + pax_close_kernel();
67311 break;
67312 }
67313
67314 @@ -1869,11 +1897,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67315 secbase = (unsigned long)mod_percpu(mod);
67316 else
67317 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67318 + pax_open_kernel();
67319 sym[i].st_value += secbase;
67320 + pax_close_kernel();
67321 break;
67322 }
67323 }
67324
67325 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67326 + if (is_fs_load && !register_filesystem_found) {
67327 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67328 + ret = -EPERM;
67329 + }
67330 +#endif
67331 +
67332 return ret;
67333 }
67334
67335 @@ -1977,22 +2014,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67336 || s->sh_entsize != ~0UL
67337 || strstarts(sname, ".init"))
67338 continue;
67339 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67340 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67341 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67342 + else
67343 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67344 DEBUGP("\t%s\n", name);
67345 }
67346 - switch (m) {
67347 - case 0: /* executable */
67348 - mod->core_size = debug_align(mod->core_size);
67349 - mod->core_text_size = mod->core_size;
67350 - break;
67351 - case 1: /* RO: text and ro-data */
67352 - mod->core_size = debug_align(mod->core_size);
67353 - mod->core_ro_size = mod->core_size;
67354 - break;
67355 - case 3: /* whole core */
67356 - mod->core_size = debug_align(mod->core_size);
67357 - break;
67358 - }
67359 }
67360
67361 DEBUGP("Init section allocation order:\n");
67362 @@ -2006,23 +2033,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67363 || s->sh_entsize != ~0UL
67364 || !strstarts(sname, ".init"))
67365 continue;
67366 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67367 - | INIT_OFFSET_MASK);
67368 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67369 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67370 + else
67371 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67372 + s->sh_entsize |= INIT_OFFSET_MASK;
67373 DEBUGP("\t%s\n", sname);
67374 }
67375 - switch (m) {
67376 - case 0: /* executable */
67377 - mod->init_size = debug_align(mod->init_size);
67378 - mod->init_text_size = mod->init_size;
67379 - break;
67380 - case 1: /* RO: text and ro-data */
67381 - mod->init_size = debug_align(mod->init_size);
67382 - mod->init_ro_size = mod->init_size;
67383 - break;
67384 - case 3: /* whole init */
67385 - mod->init_size = debug_align(mod->init_size);
67386 - break;
67387 - }
67388 }
67389 }
67390
67391 @@ -2187,7 +2204,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67392
67393 /* Put symbol section at end of init part of module. */
67394 symsect->sh_flags |= SHF_ALLOC;
67395 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67396 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67397 info->index.sym) | INIT_OFFSET_MASK;
67398 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
67399
67400 @@ -2204,19 +2221,19 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67401 }
67402
67403 /* Append room for core symbols at end of core part. */
67404 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67405 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67406 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67407 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67408
67409 /* Put string table section at end of init part of module. */
67410 strsect->sh_flags |= SHF_ALLOC;
67411 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67412 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67413 info->index.str) | INIT_OFFSET_MASK;
67414 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
67415
67416 /* Append room for core symbols' strings at end of core part. */
67417 - info->stroffs = mod->core_size;
67418 + info->stroffs = mod->core_size_rx;
67419 __set_bit(0, info->strmap);
67420 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
67421 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
67422 }
67423
67424 static void add_kallsyms(struct module *mod, const struct load_info *info)
67425 @@ -2232,11 +2249,13 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67426 /* Make sure we get permanent strtab: don't use info->strtab. */
67427 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67428
67429 + pax_open_kernel();
67430 +
67431 /* Set types up while we still have access to sections. */
67432 for (i = 0; i < mod->num_symtab; i++)
67433 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67434
67435 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67436 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67437 src = mod->symtab;
67438 *dst = *src;
67439 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
67440 @@ -2249,10 +2268,12 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67441 }
67442 mod->core_num_syms = ndst;
67443
67444 - mod->core_strtab = s = mod->module_core + info->stroffs;
67445 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67446 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
67447 if (test_bit(i, info->strmap))
67448 *++s = mod->strtab[i];
67449 +
67450 + pax_close_kernel();
67451 }
67452 #else
67453 static inline void layout_symtab(struct module *mod, struct load_info *info)
67454 @@ -2286,17 +2307,33 @@ void * __weak module_alloc(unsigned long size)
67455 return size == 0 ? NULL : vmalloc_exec(size);
67456 }
67457
67458 -static void *module_alloc_update_bounds(unsigned long size)
67459 +static void *module_alloc_update_bounds_rw(unsigned long size)
67460 {
67461 void *ret = module_alloc(size);
67462
67463 if (ret) {
67464 mutex_lock(&module_mutex);
67465 /* Update module bounds. */
67466 - if ((unsigned long)ret < module_addr_min)
67467 - module_addr_min = (unsigned long)ret;
67468 - if ((unsigned long)ret + size > module_addr_max)
67469 - module_addr_max = (unsigned long)ret + size;
67470 + if ((unsigned long)ret < module_addr_min_rw)
67471 + module_addr_min_rw = (unsigned long)ret;
67472 + if ((unsigned long)ret + size > module_addr_max_rw)
67473 + module_addr_max_rw = (unsigned long)ret + size;
67474 + mutex_unlock(&module_mutex);
67475 + }
67476 + return ret;
67477 +}
67478 +
67479 +static void *module_alloc_update_bounds_rx(unsigned long size)
67480 +{
67481 + void *ret = module_alloc_exec(size);
67482 +
67483 + if (ret) {
67484 + mutex_lock(&module_mutex);
67485 + /* Update module bounds. */
67486 + if ((unsigned long)ret < module_addr_min_rx)
67487 + module_addr_min_rx = (unsigned long)ret;
67488 + if ((unsigned long)ret + size > module_addr_max_rx)
67489 + module_addr_max_rx = (unsigned long)ret + size;
67490 mutex_unlock(&module_mutex);
67491 }
67492 return ret;
67493 @@ -2474,8 +2511,14 @@ static struct module *setup_load_info(struct load_info *info)
67494 static int check_modinfo(struct module *mod, struct load_info *info)
67495 {
67496 const char *modmagic = get_modinfo(info, "vermagic");
67497 + const char *license = get_modinfo(info, "license");
67498 int err;
67499
67500 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67501 + if (!license || !license_is_gpl_compatible(license))
67502 + return -ENOEXEC;
67503 +#endif
67504 +
67505 /* This is allowed: modprobe --force will invalidate it. */
67506 if (!modmagic) {
67507 err = try_to_force_load(mod, "bad vermagic");
67508 @@ -2495,7 +2538,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67509 }
67510
67511 /* Set up license info based on the info section */
67512 - set_license(mod, get_modinfo(info, "license"));
67513 + set_license(mod, license);
67514
67515 return 0;
67516 }
67517 @@ -2589,7 +2632,7 @@ static int move_module(struct module *mod, struct load_info *info)
67518 void *ptr;
67519
67520 /* Do the allocs. */
67521 - ptr = module_alloc_update_bounds(mod->core_size);
67522 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67523 /*
67524 * The pointer to this block is stored in the module structure
67525 * which is inside the block. Just mark it as not being a
67526 @@ -2599,23 +2642,50 @@ static int move_module(struct module *mod, struct load_info *info)
67527 if (!ptr)
67528 return -ENOMEM;
67529
67530 - memset(ptr, 0, mod->core_size);
67531 - mod->module_core = ptr;
67532 + memset(ptr, 0, mod->core_size_rw);
67533 + mod->module_core_rw = ptr;
67534
67535 - ptr = module_alloc_update_bounds(mod->init_size);
67536 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67537 /*
67538 * The pointer to this block is stored in the module structure
67539 * which is inside the block. This block doesn't need to be
67540 * scanned as it contains data and code that will be freed
67541 * after the module is initialized.
67542 */
67543 - kmemleak_ignore(ptr);
67544 - if (!ptr && mod->init_size) {
67545 - module_free(mod, mod->module_core);
67546 + kmemleak_not_leak(ptr);
67547 + if (!ptr && mod->init_size_rw) {
67548 + module_free(mod, mod->module_core_rw);
67549 return -ENOMEM;
67550 }
67551 - memset(ptr, 0, mod->init_size);
67552 - mod->module_init = ptr;
67553 + memset(ptr, 0, mod->init_size_rw);
67554 + mod->module_init_rw = ptr;
67555 +
67556 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67557 + kmemleak_not_leak(ptr);
67558 + if (!ptr) {
67559 + module_free(mod, mod->module_init_rw);
67560 + module_free(mod, mod->module_core_rw);
67561 + return -ENOMEM;
67562 + }
67563 +
67564 + pax_open_kernel();
67565 + memset(ptr, 0, mod->core_size_rx);
67566 + pax_close_kernel();
67567 + mod->module_core_rx = ptr;
67568 +
67569 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67570 + kmemleak_not_leak(ptr);
67571 + if (!ptr && mod->init_size_rx) {
67572 + module_free_exec(mod, mod->module_core_rx);
67573 + module_free(mod, mod->module_init_rw);
67574 + module_free(mod, mod->module_core_rw);
67575 + return -ENOMEM;
67576 + }
67577 +
67578 + pax_open_kernel();
67579 + memset(ptr, 0, mod->init_size_rx);
67580 + pax_close_kernel();
67581 + mod->module_init_rx = ptr;
67582
67583 /* Transfer each section which specifies SHF_ALLOC */
67584 DEBUGP("final section addresses:\n");
67585 @@ -2626,16 +2696,45 @@ static int move_module(struct module *mod, struct load_info *info)
67586 if (!(shdr->sh_flags & SHF_ALLOC))
67587 continue;
67588
67589 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67590 - dest = mod->module_init
67591 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67592 - else
67593 - dest = mod->module_core + shdr->sh_entsize;
67594 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67595 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67596 + dest = mod->module_init_rw
67597 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67598 + else
67599 + dest = mod->module_init_rx
67600 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67601 + } else {
67602 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67603 + dest = mod->module_core_rw + shdr->sh_entsize;
67604 + else
67605 + dest = mod->module_core_rx + shdr->sh_entsize;
67606 + }
67607 +
67608 + if (shdr->sh_type != SHT_NOBITS) {
67609 +
67610 +#ifdef CONFIG_PAX_KERNEXEC
67611 +#ifdef CONFIG_X86_64
67612 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67613 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67614 +#endif
67615 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67616 + pax_open_kernel();
67617 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67618 + pax_close_kernel();
67619 + } else
67620 +#endif
67621
67622 - if (shdr->sh_type != SHT_NOBITS)
67623 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67624 + }
67625 /* Update sh_addr to point to copy in image. */
67626 - shdr->sh_addr = (unsigned long)dest;
67627 +
67628 +#ifdef CONFIG_PAX_KERNEXEC
67629 + if (shdr->sh_flags & SHF_EXECINSTR)
67630 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
67631 + else
67632 +#endif
67633 +
67634 + shdr->sh_addr = (unsigned long)dest;
67635 DEBUGP("\t0x%lx %s\n",
67636 shdr->sh_addr, info->secstrings + shdr->sh_name);
67637 }
67638 @@ -2686,12 +2785,12 @@ static void flush_module_icache(const struct module *mod)
67639 * Do it before processing of module parameters, so the module
67640 * can provide parameter accessor functions of its own.
67641 */
67642 - if (mod->module_init)
67643 - flush_icache_range((unsigned long)mod->module_init,
67644 - (unsigned long)mod->module_init
67645 - + mod->init_size);
67646 - flush_icache_range((unsigned long)mod->module_core,
67647 - (unsigned long)mod->module_core + mod->core_size);
67648 + if (mod->module_init_rx)
67649 + flush_icache_range((unsigned long)mod->module_init_rx,
67650 + (unsigned long)mod->module_init_rx
67651 + + mod->init_size_rx);
67652 + flush_icache_range((unsigned long)mod->module_core_rx,
67653 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
67654
67655 set_fs(old_fs);
67656 }
67657 @@ -2771,8 +2870,10 @@ static void module_deallocate(struct module *mod, struct load_info *info)
67658 {
67659 kfree(info->strmap);
67660 percpu_modfree(mod);
67661 - module_free(mod, mod->module_init);
67662 - module_free(mod, mod->module_core);
67663 + module_free_exec(mod, mod->module_init_rx);
67664 + module_free_exec(mod, mod->module_core_rx);
67665 + module_free(mod, mod->module_init_rw);
67666 + module_free(mod, mod->module_core_rw);
67667 }
67668
67669 int __weak module_finalize(const Elf_Ehdr *hdr,
67670 @@ -2836,9 +2937,38 @@ static struct module *load_module(void __user *umod,
67671 if (err)
67672 goto free_unload;
67673
67674 + /* Now copy in args */
67675 + mod->args = strndup_user(uargs, ~0UL >> 1);
67676 + if (IS_ERR(mod->args)) {
67677 + err = PTR_ERR(mod->args);
67678 + goto free_unload;
67679 + }
67680 +
67681 /* Set up MODINFO_ATTR fields */
67682 setup_modinfo(mod, &info);
67683
67684 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67685 + {
67686 + char *p, *p2;
67687 +
67688 + if (strstr(mod->args, "grsec_modharden_netdev")) {
67689 + 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);
67690 + err = -EPERM;
67691 + goto free_modinfo;
67692 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67693 + p += strlen("grsec_modharden_normal");
67694 + p2 = strstr(p, "_");
67695 + if (p2) {
67696 + *p2 = '\0';
67697 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67698 + *p2 = '_';
67699 + }
67700 + err = -EPERM;
67701 + goto free_modinfo;
67702 + }
67703 + }
67704 +#endif
67705 +
67706 /* Fix up syms, so that st_value is a pointer to location. */
67707 err = simplify_symbols(mod, &info);
67708 if (err < 0)
67709 @@ -2854,13 +2984,6 @@ static struct module *load_module(void __user *umod,
67710
67711 flush_module_icache(mod);
67712
67713 - /* Now copy in args */
67714 - mod->args = strndup_user(uargs, ~0UL >> 1);
67715 - if (IS_ERR(mod->args)) {
67716 - err = PTR_ERR(mod->args);
67717 - goto free_arch_cleanup;
67718 - }
67719 -
67720 /* Mark state as coming so strong_try_module_get() ignores us. */
67721 mod->state = MODULE_STATE_COMING;
67722
67723 @@ -2920,11 +3043,10 @@ static struct module *load_module(void __user *umod,
67724 unlock:
67725 mutex_unlock(&module_mutex);
67726 synchronize_sched();
67727 - kfree(mod->args);
67728 - free_arch_cleanup:
67729 module_arch_cleanup(mod);
67730 free_modinfo:
67731 free_modinfo(mod);
67732 + kfree(mod->args);
67733 free_unload:
67734 module_unload_free(mod);
67735 free_module:
67736 @@ -2965,16 +3087,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67737 MODULE_STATE_COMING, mod);
67738
67739 /* Set RO and NX regions for core */
67740 - set_section_ro_nx(mod->module_core,
67741 - mod->core_text_size,
67742 - mod->core_ro_size,
67743 - mod->core_size);
67744 + set_section_ro_nx(mod->module_core_rx,
67745 + mod->core_size_rx,
67746 + mod->core_size_rx,
67747 + mod->core_size_rx);
67748
67749 /* Set RO and NX regions for init */
67750 - set_section_ro_nx(mod->module_init,
67751 - mod->init_text_size,
67752 - mod->init_ro_size,
67753 - mod->init_size);
67754 + set_section_ro_nx(mod->module_init_rx,
67755 + mod->init_size_rx,
67756 + mod->init_size_rx,
67757 + mod->init_size_rx);
67758
67759 do_mod_ctors(mod);
67760 /* Start the module */
67761 @@ -3020,11 +3142,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67762 mod->strtab = mod->core_strtab;
67763 #endif
67764 unset_module_init_ro_nx(mod);
67765 - module_free(mod, mod->module_init);
67766 - mod->module_init = NULL;
67767 - mod->init_size = 0;
67768 - mod->init_ro_size = 0;
67769 - mod->init_text_size = 0;
67770 + module_free(mod, mod->module_init_rw);
67771 + module_free_exec(mod, mod->module_init_rx);
67772 + mod->module_init_rw = NULL;
67773 + mod->module_init_rx = NULL;
67774 + mod->init_size_rw = 0;
67775 + mod->init_size_rx = 0;
67776 mutex_unlock(&module_mutex);
67777
67778 return 0;
67779 @@ -3055,10 +3178,16 @@ static const char *get_ksymbol(struct module *mod,
67780 unsigned long nextval;
67781
67782 /* At worse, next value is at end of module */
67783 - if (within_module_init(addr, mod))
67784 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
67785 + if (within_module_init_rx(addr, mod))
67786 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67787 + else if (within_module_init_rw(addr, mod))
67788 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67789 + else if (within_module_core_rx(addr, mod))
67790 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67791 + else if (within_module_core_rw(addr, mod))
67792 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67793 else
67794 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
67795 + return NULL;
67796
67797 /* Scan for closest preceding symbol, and next symbol. (ELF
67798 starts real symbols at 1). */
67799 @@ -3304,7 +3433,7 @@ static int m_show(struct seq_file *m, void *p)
67800 char buf[8];
67801
67802 seq_printf(m, "%s %u",
67803 - mod->name, mod->init_size + mod->core_size);
67804 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67805 print_unload_info(m, mod);
67806
67807 /* Informative for users. */
67808 @@ -3313,7 +3442,7 @@ static int m_show(struct seq_file *m, void *p)
67809 mod->state == MODULE_STATE_COMING ? "Loading":
67810 "Live");
67811 /* Used by oprofile and other similar tools. */
67812 - seq_printf(m, " 0x%pK", mod->module_core);
67813 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67814
67815 /* Taints info */
67816 if (mod->taints)
67817 @@ -3349,7 +3478,17 @@ static const struct file_operations proc_modules_operations = {
67818
67819 static int __init proc_modules_init(void)
67820 {
67821 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67822 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67823 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67824 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67825 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67826 +#else
67827 proc_create("modules", 0, NULL, &proc_modules_operations);
67828 +#endif
67829 +#else
67830 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67831 +#endif
67832 return 0;
67833 }
67834 module_init(proc_modules_init);
67835 @@ -3408,12 +3547,12 @@ struct module *__module_address(unsigned long addr)
67836 {
67837 struct module *mod;
67838
67839 - if (addr < module_addr_min || addr > module_addr_max)
67840 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67841 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
67842 return NULL;
67843
67844 list_for_each_entry_rcu(mod, &modules, list)
67845 - if (within_module_core(addr, mod)
67846 - || within_module_init(addr, mod))
67847 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
67848 return mod;
67849 return NULL;
67850 }
67851 @@ -3447,11 +3586,20 @@ bool is_module_text_address(unsigned long addr)
67852 */
67853 struct module *__module_text_address(unsigned long addr)
67854 {
67855 - struct module *mod = __module_address(addr);
67856 + struct module *mod;
67857 +
67858 +#ifdef CONFIG_X86_32
67859 + addr = ktla_ktva(addr);
67860 +#endif
67861 +
67862 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67863 + return NULL;
67864 +
67865 + mod = __module_address(addr);
67866 +
67867 if (mod) {
67868 /* Make sure it's within the text section. */
67869 - if (!within(addr, mod->module_init, mod->init_text_size)
67870 - && !within(addr, mod->module_core, mod->core_text_size))
67871 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67872 mod = NULL;
67873 }
67874 return mod;
67875 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67876 index 73da83a..fe46e99 100644
67877 --- a/kernel/mutex-debug.c
67878 +++ b/kernel/mutex-debug.c
67879 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67880 }
67881
67882 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67883 - struct thread_info *ti)
67884 + struct task_struct *task)
67885 {
67886 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67887
67888 /* Mark the current thread as blocked on the lock: */
67889 - ti->task->blocked_on = waiter;
67890 + task->blocked_on = waiter;
67891 }
67892
67893 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67894 - struct thread_info *ti)
67895 + struct task_struct *task)
67896 {
67897 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
67898 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
67899 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
67900 - ti->task->blocked_on = NULL;
67901 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
67902 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
67903 + task->blocked_on = NULL;
67904
67905 list_del_init(&waiter->list);
67906 waiter->task = NULL;
67907 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
67908 index 0799fd3..d06ae3b 100644
67909 --- a/kernel/mutex-debug.h
67910 +++ b/kernel/mutex-debug.h
67911 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
67912 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
67913 extern void debug_mutex_add_waiter(struct mutex *lock,
67914 struct mutex_waiter *waiter,
67915 - struct thread_info *ti);
67916 + struct task_struct *task);
67917 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67918 - struct thread_info *ti);
67919 + struct task_struct *task);
67920 extern void debug_mutex_unlock(struct mutex *lock);
67921 extern void debug_mutex_init(struct mutex *lock, const char *name,
67922 struct lock_class_key *key);
67923 diff --git a/kernel/mutex.c b/kernel/mutex.c
67924 index d607ed5..58d0a52 100644
67925 --- a/kernel/mutex.c
67926 +++ b/kernel/mutex.c
67927 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67928 spin_lock_mutex(&lock->wait_lock, flags);
67929
67930 debug_mutex_lock_common(lock, &waiter);
67931 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
67932 + debug_mutex_add_waiter(lock, &waiter, task);
67933
67934 /* add waiting tasks to the end of the waitqueue (FIFO): */
67935 list_add_tail(&waiter.list, &lock->wait_list);
67936 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67937 * TASK_UNINTERRUPTIBLE case.)
67938 */
67939 if (unlikely(signal_pending_state(state, task))) {
67940 - mutex_remove_waiter(lock, &waiter,
67941 - task_thread_info(task));
67942 + mutex_remove_waiter(lock, &waiter, task);
67943 mutex_release(&lock->dep_map, 1, ip);
67944 spin_unlock_mutex(&lock->wait_lock, flags);
67945
67946 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67947 done:
67948 lock_acquired(&lock->dep_map, ip);
67949 /* got the lock - rejoice! */
67950 - mutex_remove_waiter(lock, &waiter, current_thread_info());
67951 + mutex_remove_waiter(lock, &waiter, task);
67952 mutex_set_owner(lock);
67953
67954 /* set it to 0 if there are no waiters left: */
67955 diff --git a/kernel/padata.c b/kernel/padata.c
67956 index b91941d..0871d60 100644
67957 --- a/kernel/padata.c
67958 +++ b/kernel/padata.c
67959 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
67960 padata->pd = pd;
67961 padata->cb_cpu = cb_cpu;
67962
67963 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
67964 - atomic_set(&pd->seq_nr, -1);
67965 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
67966 + atomic_set_unchecked(&pd->seq_nr, -1);
67967
67968 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
67969 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
67970
67971 target_cpu = padata_cpu_hash(padata);
67972 queue = per_cpu_ptr(pd->pqueue, target_cpu);
67973 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
67974 padata_init_pqueues(pd);
67975 padata_init_squeues(pd);
67976 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
67977 - atomic_set(&pd->seq_nr, -1);
67978 + atomic_set_unchecked(&pd->seq_nr, -1);
67979 atomic_set(&pd->reorder_objects, 0);
67980 atomic_set(&pd->refcnt, 0);
67981 pd->pinst = pinst;
67982 diff --git a/kernel/panic.c b/kernel/panic.c
67983 index d7bb697..0ff55cc 100644
67984 --- a/kernel/panic.c
67985 +++ b/kernel/panic.c
67986 @@ -78,7 +78,11 @@ NORET_TYPE void panic(const char * fmt, ...)
67987 va_end(args);
67988 printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
67989 #ifdef CONFIG_DEBUG_BUGVERBOSE
67990 - dump_stack();
67991 + /*
67992 + * Avoid nested stack-dumping if a panic occurs during oops processing
67993 + */
67994 + if (!oops_in_progress)
67995 + dump_stack();
67996 #endif
67997
67998 /*
67999 @@ -371,7 +375,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68000 const char *board;
68001
68002 printk(KERN_WARNING "------------[ cut here ]------------\n");
68003 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68004 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68005 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68006 if (board)
68007 printk(KERN_WARNING "Hardware name: %s\n", board);
68008 @@ -426,7 +430,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68009 */
68010 void __stack_chk_fail(void)
68011 {
68012 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68013 + dump_stack();
68014 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68015 __builtin_return_address(0));
68016 }
68017 EXPORT_SYMBOL(__stack_chk_fail);
68018 diff --git a/kernel/pid.c b/kernel/pid.c
68019 index e432057..a2b2ac5 100644
68020 --- a/kernel/pid.c
68021 +++ b/kernel/pid.c
68022 @@ -33,6 +33,7 @@
68023 #include <linux/rculist.h>
68024 #include <linux/bootmem.h>
68025 #include <linux/hash.h>
68026 +#include <linux/security.h>
68027 #include <linux/pid_namespace.h>
68028 #include <linux/init_task.h>
68029 #include <linux/syscalls.h>
68030 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68031
68032 int pid_max = PID_MAX_DEFAULT;
68033
68034 -#define RESERVED_PIDS 300
68035 +#define RESERVED_PIDS 500
68036
68037 int pid_max_min = RESERVED_PIDS + 1;
68038 int pid_max_max = PID_MAX_LIMIT;
68039 @@ -418,8 +419,15 @@ EXPORT_SYMBOL(pid_task);
68040 */
68041 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68042 {
68043 + struct task_struct *task;
68044 +
68045 rcu_lockdep_assert(rcu_read_lock_held());
68046 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68047 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68048 +
68049 + if (gr_pid_is_chrooted(task))
68050 + return NULL;
68051 +
68052 + return task;
68053 }
68054
68055 struct task_struct *find_task_by_vpid(pid_t vnr)
68056 @@ -427,6 +435,12 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68057 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68058 }
68059
68060 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68061 +{
68062 + rcu_lockdep_assert(rcu_read_lock_held());
68063 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68064 +}
68065 +
68066 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68067 {
68068 struct pid *pid;
68069 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68070 index 640ded8..3dafb85 100644
68071 --- a/kernel/posix-cpu-timers.c
68072 +++ b/kernel/posix-cpu-timers.c
68073 @@ -6,6 +6,7 @@
68074 #include <linux/posix-timers.h>
68075 #include <linux/errno.h>
68076 #include <linux/math64.h>
68077 +#include <linux/security.h>
68078 #include <asm/uaccess.h>
68079 #include <linux/kernel_stat.h>
68080 #include <trace/events/timer.h>
68081 @@ -1606,14 +1607,14 @@ struct k_clock clock_posix_cpu = {
68082
68083 static __init int init_posix_cpu_timers(void)
68084 {
68085 - struct k_clock process = {
68086 + static struct k_clock process = {
68087 .clock_getres = process_cpu_clock_getres,
68088 .clock_get = process_cpu_clock_get,
68089 .timer_create = process_cpu_timer_create,
68090 .nsleep = process_cpu_nsleep,
68091 .nsleep_restart = process_cpu_nsleep_restart,
68092 };
68093 - struct k_clock thread = {
68094 + static struct k_clock thread = {
68095 .clock_getres = thread_cpu_clock_getres,
68096 .clock_get = thread_cpu_clock_get,
68097 .timer_create = thread_cpu_timer_create,
68098 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68099 index 4556182..9335419 100644
68100 --- a/kernel/posix-timers.c
68101 +++ b/kernel/posix-timers.c
68102 @@ -43,6 +43,7 @@
68103 #include <linux/idr.h>
68104 #include <linux/posix-clock.h>
68105 #include <linux/posix-timers.h>
68106 +#include <linux/grsecurity.h>
68107 #include <linux/syscalls.h>
68108 #include <linux/wait.h>
68109 #include <linux/workqueue.h>
68110 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68111 * which we beg off on and pass to do_sys_settimeofday().
68112 */
68113
68114 -static struct k_clock posix_clocks[MAX_CLOCKS];
68115 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68116
68117 /*
68118 * These ones are defined below.
68119 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68120 */
68121 static __init int init_posix_timers(void)
68122 {
68123 - struct k_clock clock_realtime = {
68124 + static struct k_clock clock_realtime = {
68125 .clock_getres = hrtimer_get_res,
68126 .clock_get = posix_clock_realtime_get,
68127 .clock_set = posix_clock_realtime_set,
68128 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68129 .timer_get = common_timer_get,
68130 .timer_del = common_timer_del,
68131 };
68132 - struct k_clock clock_monotonic = {
68133 + static struct k_clock clock_monotonic = {
68134 .clock_getres = hrtimer_get_res,
68135 .clock_get = posix_ktime_get_ts,
68136 .nsleep = common_nsleep,
68137 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68138 .timer_get = common_timer_get,
68139 .timer_del = common_timer_del,
68140 };
68141 - struct k_clock clock_monotonic_raw = {
68142 + static struct k_clock clock_monotonic_raw = {
68143 .clock_getres = hrtimer_get_res,
68144 .clock_get = posix_get_monotonic_raw,
68145 };
68146 - struct k_clock clock_realtime_coarse = {
68147 + static struct k_clock clock_realtime_coarse = {
68148 .clock_getres = posix_get_coarse_res,
68149 .clock_get = posix_get_realtime_coarse,
68150 };
68151 - struct k_clock clock_monotonic_coarse = {
68152 + static struct k_clock clock_monotonic_coarse = {
68153 .clock_getres = posix_get_coarse_res,
68154 .clock_get = posix_get_monotonic_coarse,
68155 };
68156 - struct k_clock clock_boottime = {
68157 + static struct k_clock clock_boottime = {
68158 .clock_getres = hrtimer_get_res,
68159 .clock_get = posix_get_boottime,
68160 .nsleep = common_nsleep,
68161 @@ -272,6 +273,8 @@ static __init int init_posix_timers(void)
68162 .timer_del = common_timer_del,
68163 };
68164
68165 + pax_track_stack();
68166 +
68167 posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime);
68168 posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic);
68169 posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
68170 @@ -473,7 +476,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68171 return;
68172 }
68173
68174 - posix_clocks[clock_id] = *new_clock;
68175 + posix_clocks[clock_id] = new_clock;
68176 }
68177 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68178
68179 @@ -519,9 +522,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68180 return (id & CLOCKFD_MASK) == CLOCKFD ?
68181 &clock_posix_dynamic : &clock_posix_cpu;
68182
68183 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68184 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68185 return NULL;
68186 - return &posix_clocks[id];
68187 + return posix_clocks[id];
68188 }
68189
68190 static int common_timer_create(struct k_itimer *new_timer)
68191 @@ -959,6 +962,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68192 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68193 return -EFAULT;
68194
68195 + /* only the CLOCK_REALTIME clock can be set, all other clocks
68196 + have their clock_set fptr set to a nosettime dummy function
68197 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68198 + call common_clock_set, which calls do_sys_settimeofday, which
68199 + we hook
68200 + */
68201 +
68202 return kc->clock_set(which_clock, &new_tp);
68203 }
68204
68205 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68206 index d523593..68197a4 100644
68207 --- a/kernel/power/poweroff.c
68208 +++ b/kernel/power/poweroff.c
68209 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68210 .enable_mask = SYSRQ_ENABLE_BOOT,
68211 };
68212
68213 -static int pm_sysrq_init(void)
68214 +static int __init pm_sysrq_init(void)
68215 {
68216 register_sysrq_key('o', &sysrq_poweroff_op);
68217 return 0;
68218 diff --git a/kernel/power/process.c b/kernel/power/process.c
68219 index 0cf3a27..5481be4 100644
68220 --- a/kernel/power/process.c
68221 +++ b/kernel/power/process.c
68222 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_only)
68223 u64 elapsed_csecs64;
68224 unsigned int elapsed_csecs;
68225 bool wakeup = false;
68226 + bool timedout = false;
68227
68228 do_gettimeofday(&start);
68229
68230 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_only)
68231
68232 while (true) {
68233 todo = 0;
68234 + if (time_after(jiffies, end_time))
68235 + timedout = true;
68236 read_lock(&tasklist_lock);
68237 do_each_thread(g, p) {
68238 if (frozen(p) || !freezable(p))
68239 @@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_only)
68240 * try_to_stop() after schedule() in ptrace/signal
68241 * stop sees TIF_FREEZE.
68242 */
68243 - if (!task_is_stopped_or_traced(p) &&
68244 - !freezer_should_skip(p))
68245 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68246 todo++;
68247 + if (timedout) {
68248 + printk(KERN_ERR "Task refusing to freeze:\n");
68249 + sched_show_task(p);
68250 + }
68251 + }
68252 } while_each_thread(g, p);
68253 read_unlock(&tasklist_lock);
68254
68255 @@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_only)
68256 todo += wq_busy;
68257 }
68258
68259 - if (!todo || time_after(jiffies, end_time))
68260 + if (!todo || timedout)
68261 break;
68262
68263 if (pm_wakeup_pending()) {
68264 diff --git a/kernel/printk.c b/kernel/printk.c
68265 index 28a40d8..2411bec 100644
68266 --- a/kernel/printk.c
68267 +++ b/kernel/printk.c
68268 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
68269 if (from_file && type != SYSLOG_ACTION_OPEN)
68270 return 0;
68271
68272 +#ifdef CONFIG_GRKERNSEC_DMESG
68273 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68274 + return -EPERM;
68275 +#endif
68276 +
68277 if (syslog_action_restricted(type)) {
68278 if (capable(CAP_SYSLOG))
68279 return 0;
68280 diff --git a/kernel/profile.c b/kernel/profile.c
68281 index 961b389..c451353 100644
68282 --- a/kernel/profile.c
68283 +++ b/kernel/profile.c
68284 @@ -39,7 +39,7 @@ struct profile_hit {
68285 /* Oprofile timer tick hook */
68286 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68287
68288 -static atomic_t *prof_buffer;
68289 +static atomic_unchecked_t *prof_buffer;
68290 static unsigned long prof_len, prof_shift;
68291
68292 int prof_on __read_mostly;
68293 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68294 hits[i].pc = 0;
68295 continue;
68296 }
68297 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68298 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68299 hits[i].hits = hits[i].pc = 0;
68300 }
68301 }
68302 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68303 * Add the current hit(s) and flush the write-queue out
68304 * to the global buffer:
68305 */
68306 - atomic_add(nr_hits, &prof_buffer[pc]);
68307 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68308 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68309 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68310 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68311 hits[i].pc = hits[i].hits = 0;
68312 }
68313 out:
68314 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68315 {
68316 unsigned long pc;
68317 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68318 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68319 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68320 }
68321 #endif /* !CONFIG_SMP */
68322
68323 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68324 return -EFAULT;
68325 buf++; p++; count--; read++;
68326 }
68327 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68328 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68329 if (copy_to_user(buf, (void *)pnt, count))
68330 return -EFAULT;
68331 read += count;
68332 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68333 }
68334 #endif
68335 profile_discard_flip_buffers();
68336 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68337 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68338 return count;
68339 }
68340
68341 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68342 index 67d1fdd..1af21e2 100644
68343 --- a/kernel/ptrace.c
68344 +++ b/kernel/ptrace.c
68345 @@ -172,7 +172,8 @@ int ptrace_check_attach(struct task_struct *child, bool ignore_state)
68346 return ret;
68347 }
68348
68349 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
68350 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
68351 + unsigned int log)
68352 {
68353 const struct cred *cred = current_cred(), *tcred;
68354
68355 @@ -198,7 +199,8 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
68356 cred->gid == tcred->sgid &&
68357 cred->gid == tcred->gid))
68358 goto ok;
68359 - if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
68360 + if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
68361 + (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
68362 goto ok;
68363 rcu_read_unlock();
68364 return -EPERM;
68365 @@ -207,7 +209,9 @@ ok:
68366 smp_rmb();
68367 if (task->mm)
68368 dumpable = get_dumpable(task->mm);
68369 - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
68370 + if (!dumpable &&
68371 + ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
68372 + (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
68373 return -EPERM;
68374
68375 return security_ptrace_access_check(task, mode);
68376 @@ -217,7 +221,16 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
68377 {
68378 int err;
68379 task_lock(task);
68380 - err = __ptrace_may_access(task, mode);
68381 + err = __ptrace_may_access(task, mode, 0);
68382 + task_unlock(task);
68383 + return !err;
68384 +}
68385 +
68386 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
68387 +{
68388 + int err;
68389 + task_lock(task);
68390 + err = __ptrace_may_access(task, mode, 1);
68391 task_unlock(task);
68392 return !err;
68393 }
68394 @@ -262,7 +275,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68395 goto out;
68396
68397 task_lock(task);
68398 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
68399 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
68400 task_unlock(task);
68401 if (retval)
68402 goto unlock_creds;
68403 @@ -277,7 +290,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68404 task->ptrace = PT_PTRACED;
68405 if (seize)
68406 task->ptrace |= PT_SEIZED;
68407 - if (task_ns_capable(task, CAP_SYS_PTRACE))
68408 + if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
68409 task->ptrace |= PT_PTRACE_CAP;
68410
68411 __ptrace_link(task, current);
68412 @@ -472,6 +485,8 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68413 {
68414 int copied = 0;
68415
68416 + pax_track_stack();
68417 +
68418 while (len > 0) {
68419 char buf[128];
68420 int this_len, retval;
68421 @@ -483,7 +498,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68422 break;
68423 return -EIO;
68424 }
68425 - if (copy_to_user(dst, buf, retval))
68426 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68427 return -EFAULT;
68428 copied += retval;
68429 src += retval;
68430 @@ -497,6 +512,8 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds
68431 {
68432 int copied = 0;
68433
68434 + pax_track_stack();
68435 +
68436 while (len > 0) {
68437 char buf[128];
68438 int this_len, retval;
68439 @@ -680,10 +697,12 @@ int ptrace_request(struct task_struct *child, long request,
68440 bool seized = child->ptrace & PT_SEIZED;
68441 int ret = -EIO;
68442 siginfo_t siginfo, *si;
68443 - void __user *datavp = (void __user *) data;
68444 + void __user *datavp = (__force void __user *) data;
68445 unsigned long __user *datalp = datavp;
68446 unsigned long flags;
68447
68448 + pax_track_stack();
68449 +
68450 switch (request) {
68451 case PTRACE_PEEKTEXT:
68452 case PTRACE_PEEKDATA:
68453 @@ -882,14 +901,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68454 goto out;
68455 }
68456
68457 + if (gr_handle_ptrace(child, request)) {
68458 + ret = -EPERM;
68459 + goto out_put_task_struct;
68460 + }
68461 +
68462 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68463 ret = ptrace_attach(child, request, data);
68464 /*
68465 * Some architectures need to do book-keeping after
68466 * a ptrace attach.
68467 */
68468 - if (!ret)
68469 + if (!ret) {
68470 arch_ptrace_attach(child);
68471 + gr_audit_ptrace(child);
68472 + }
68473 goto out_put_task_struct;
68474 }
68475
68476 @@ -915,7 +941,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68477 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68478 if (copied != sizeof(tmp))
68479 return -EIO;
68480 - return put_user(tmp, (unsigned long __user *)data);
68481 + return put_user(tmp, (__force unsigned long __user *)data);
68482 }
68483
68484 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68485 @@ -938,6 +964,8 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
68486 siginfo_t siginfo;
68487 int ret;
68488
68489 + pax_track_stack();
68490 +
68491 switch (request) {
68492 case PTRACE_PEEKTEXT:
68493 case PTRACE_PEEKDATA:
68494 @@ -1025,14 +1053,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68495 goto out;
68496 }
68497
68498 + if (gr_handle_ptrace(child, request)) {
68499 + ret = -EPERM;
68500 + goto out_put_task_struct;
68501 + }
68502 +
68503 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68504 ret = ptrace_attach(child, request, data);
68505 /*
68506 * Some architectures need to do book-keeping after
68507 * a ptrace attach.
68508 */
68509 - if (!ret)
68510 + if (!ret) {
68511 arch_ptrace_attach(child);
68512 + gr_audit_ptrace(child);
68513 + }
68514 goto out_put_task_struct;
68515 }
68516
68517 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68518 index 98f51b1..30b950c 100644
68519 --- a/kernel/rcutorture.c
68520 +++ b/kernel/rcutorture.c
68521 @@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68522 { 0 };
68523 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68524 { 0 };
68525 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68526 -static atomic_t n_rcu_torture_alloc;
68527 -static atomic_t n_rcu_torture_alloc_fail;
68528 -static atomic_t n_rcu_torture_free;
68529 -static atomic_t n_rcu_torture_mberror;
68530 -static atomic_t n_rcu_torture_error;
68531 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68532 +static atomic_unchecked_t n_rcu_torture_alloc;
68533 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68534 +static atomic_unchecked_t n_rcu_torture_free;
68535 +static atomic_unchecked_t n_rcu_torture_mberror;
68536 +static atomic_unchecked_t n_rcu_torture_error;
68537 static long n_rcu_torture_boost_ktrerror;
68538 static long n_rcu_torture_boost_rterror;
68539 static long n_rcu_torture_boost_failure;
68540 @@ -223,11 +223,11 @@ rcu_torture_alloc(void)
68541
68542 spin_lock_bh(&rcu_torture_lock);
68543 if (list_empty(&rcu_torture_freelist)) {
68544 - atomic_inc(&n_rcu_torture_alloc_fail);
68545 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68546 spin_unlock_bh(&rcu_torture_lock);
68547 return NULL;
68548 }
68549 - atomic_inc(&n_rcu_torture_alloc);
68550 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68551 p = rcu_torture_freelist.next;
68552 list_del_init(p);
68553 spin_unlock_bh(&rcu_torture_lock);
68554 @@ -240,7 +240,7 @@ rcu_torture_alloc(void)
68555 static void
68556 rcu_torture_free(struct rcu_torture *p)
68557 {
68558 - atomic_inc(&n_rcu_torture_free);
68559 + atomic_inc_unchecked(&n_rcu_torture_free);
68560 spin_lock_bh(&rcu_torture_lock);
68561 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68562 spin_unlock_bh(&rcu_torture_lock);
68563 @@ -360,7 +360,7 @@ rcu_torture_cb(struct rcu_head *p)
68564 i = rp->rtort_pipe_count;
68565 if (i > RCU_TORTURE_PIPE_LEN)
68566 i = RCU_TORTURE_PIPE_LEN;
68567 - atomic_inc(&rcu_torture_wcount[i]);
68568 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68569 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68570 rp->rtort_mbtest = 0;
68571 rcu_torture_free(rp);
68572 @@ -407,7 +407,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68573 i = rp->rtort_pipe_count;
68574 if (i > RCU_TORTURE_PIPE_LEN)
68575 i = RCU_TORTURE_PIPE_LEN;
68576 - atomic_inc(&rcu_torture_wcount[i]);
68577 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68578 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68579 rp->rtort_mbtest = 0;
68580 list_del(&rp->rtort_free);
68581 @@ -882,7 +882,7 @@ rcu_torture_writer(void *arg)
68582 i = old_rp->rtort_pipe_count;
68583 if (i > RCU_TORTURE_PIPE_LEN)
68584 i = RCU_TORTURE_PIPE_LEN;
68585 - atomic_inc(&rcu_torture_wcount[i]);
68586 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68587 old_rp->rtort_pipe_count++;
68588 cur_ops->deferred_free(old_rp);
68589 }
68590 @@ -950,7 +950,7 @@ static void rcu_torture_timer(unsigned long unused)
68591 return;
68592 }
68593 if (p->rtort_mbtest == 0)
68594 - atomic_inc(&n_rcu_torture_mberror);
68595 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68596 spin_lock(&rand_lock);
68597 cur_ops->read_delay(&rand);
68598 n_rcu_torture_timers++;
68599 @@ -1011,7 +1011,7 @@ rcu_torture_reader(void *arg)
68600 continue;
68601 }
68602 if (p->rtort_mbtest == 0)
68603 - atomic_inc(&n_rcu_torture_mberror);
68604 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68605 cur_ops->read_delay(&rand);
68606 preempt_disable();
68607 pipe_count = p->rtort_pipe_count;
68608 @@ -1070,16 +1070,16 @@ rcu_torture_printk(char *page)
68609 rcu_torture_current,
68610 rcu_torture_current_version,
68611 list_empty(&rcu_torture_freelist),
68612 - atomic_read(&n_rcu_torture_alloc),
68613 - atomic_read(&n_rcu_torture_alloc_fail),
68614 - atomic_read(&n_rcu_torture_free),
68615 - atomic_read(&n_rcu_torture_mberror),
68616 + atomic_read_unchecked(&n_rcu_torture_alloc),
68617 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68618 + atomic_read_unchecked(&n_rcu_torture_free),
68619 + atomic_read_unchecked(&n_rcu_torture_mberror),
68620 n_rcu_torture_boost_ktrerror,
68621 n_rcu_torture_boost_rterror,
68622 n_rcu_torture_boost_failure,
68623 n_rcu_torture_boosts,
68624 n_rcu_torture_timers);
68625 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68626 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68627 n_rcu_torture_boost_ktrerror != 0 ||
68628 n_rcu_torture_boost_rterror != 0 ||
68629 n_rcu_torture_boost_failure != 0)
68630 @@ -1087,7 +1087,7 @@ rcu_torture_printk(char *page)
68631 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68632 if (i > 1) {
68633 cnt += sprintf(&page[cnt], "!!! ");
68634 - atomic_inc(&n_rcu_torture_error);
68635 + atomic_inc_unchecked(&n_rcu_torture_error);
68636 WARN_ON_ONCE(1);
68637 }
68638 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68639 @@ -1101,7 +1101,7 @@ rcu_torture_printk(char *page)
68640 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68641 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68642 cnt += sprintf(&page[cnt], " %d",
68643 - atomic_read(&rcu_torture_wcount[i]));
68644 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68645 }
68646 cnt += sprintf(&page[cnt], "\n");
68647 if (cur_ops->stats)
68648 @@ -1410,7 +1410,7 @@ rcu_torture_cleanup(void)
68649
68650 if (cur_ops->cleanup)
68651 cur_ops->cleanup();
68652 - if (atomic_read(&n_rcu_torture_error))
68653 + if (atomic_read_unchecked(&n_rcu_torture_error))
68654 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68655 else
68656 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
68657 @@ -1474,17 +1474,17 @@ rcu_torture_init(void)
68658
68659 rcu_torture_current = NULL;
68660 rcu_torture_current_version = 0;
68661 - atomic_set(&n_rcu_torture_alloc, 0);
68662 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68663 - atomic_set(&n_rcu_torture_free, 0);
68664 - atomic_set(&n_rcu_torture_mberror, 0);
68665 - atomic_set(&n_rcu_torture_error, 0);
68666 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68667 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68668 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68669 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68670 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68671 n_rcu_torture_boost_ktrerror = 0;
68672 n_rcu_torture_boost_rterror = 0;
68673 n_rcu_torture_boost_failure = 0;
68674 n_rcu_torture_boosts = 0;
68675 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68676 - atomic_set(&rcu_torture_wcount[i], 0);
68677 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68678 for_each_possible_cpu(cpu) {
68679 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68680 per_cpu(rcu_torture_count, cpu)[i] = 0;
68681 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68682 index ba06207..85d8ba8 100644
68683 --- a/kernel/rcutree.c
68684 +++ b/kernel/rcutree.c
68685 @@ -356,9 +356,9 @@ void rcu_enter_nohz(void)
68686 }
68687 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68688 smp_mb__before_atomic_inc(); /* See above. */
68689 - atomic_inc(&rdtp->dynticks);
68690 + atomic_inc_unchecked(&rdtp->dynticks);
68691 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68692 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68693 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68694 local_irq_restore(flags);
68695
68696 /* If the interrupt queued a callback, get out of dyntick mode. */
68697 @@ -387,10 +387,10 @@ void rcu_exit_nohz(void)
68698 return;
68699 }
68700 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68701 - atomic_inc(&rdtp->dynticks);
68702 + atomic_inc_unchecked(&rdtp->dynticks);
68703 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68704 smp_mb__after_atomic_inc(); /* See above. */
68705 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68706 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68707 local_irq_restore(flags);
68708 }
68709
68710 @@ -406,14 +406,14 @@ void rcu_nmi_enter(void)
68711 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68712
68713 if (rdtp->dynticks_nmi_nesting == 0 &&
68714 - (atomic_read(&rdtp->dynticks) & 0x1))
68715 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68716 return;
68717 rdtp->dynticks_nmi_nesting++;
68718 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68719 - atomic_inc(&rdtp->dynticks);
68720 + atomic_inc_unchecked(&rdtp->dynticks);
68721 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68722 smp_mb__after_atomic_inc(); /* See above. */
68723 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68724 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68725 }
68726
68727 /**
68728 @@ -432,9 +432,9 @@ void rcu_nmi_exit(void)
68729 return;
68730 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68731 smp_mb__before_atomic_inc(); /* See above. */
68732 - atomic_inc(&rdtp->dynticks);
68733 + atomic_inc_unchecked(&rdtp->dynticks);
68734 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68735 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68736 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68737 }
68738
68739 /**
68740 @@ -469,7 +469,7 @@ void rcu_irq_exit(void)
68741 */
68742 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68743 {
68744 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68745 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68746 return 0;
68747 }
68748
68749 @@ -484,7 +484,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68750 unsigned long curr;
68751 unsigned long snap;
68752
68753 - curr = (unsigned long)atomic_add_return(0, &rdp->dynticks->dynticks);
68754 + curr = (unsigned long)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68755 snap = (unsigned long)rdp->dynticks_snap;
68756
68757 /*
68758 @@ -1470,7 +1470,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68759 /*
68760 * Do softirq processing for the current CPU.
68761 */
68762 -static void rcu_process_callbacks(struct softirq_action *unused)
68763 +static void rcu_process_callbacks(void)
68764 {
68765 __rcu_process_callbacks(&rcu_sched_state,
68766 &__get_cpu_var(rcu_sched_data));
68767 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68768 index 01b2ccd..4f5d80a 100644
68769 --- a/kernel/rcutree.h
68770 +++ b/kernel/rcutree.h
68771 @@ -86,7 +86,7 @@
68772 struct rcu_dynticks {
68773 int dynticks_nesting; /* Track irq/process nesting level. */
68774 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68775 - atomic_t dynticks; /* Even value for dynticks-idle, else odd. */
68776 + atomic_unchecked_t dynticks; /* Even value for dynticks-idle, else odd. */
68777 };
68778
68779 /* RCU's kthread states for tracing. */
68780 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68781 index 8aafbb8..2fca109 100644
68782 --- a/kernel/rcutree_plugin.h
68783 +++ b/kernel/rcutree_plugin.h
68784 @@ -822,7 +822,7 @@ void synchronize_rcu_expedited(void)
68785
68786 /* Clean up and exit. */
68787 smp_mb(); /* ensure expedited GP seen before counter increment. */
68788 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68789 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68790 unlock_mb_ret:
68791 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68792 mb_ret:
68793 @@ -1774,8 +1774,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
68794
68795 #else /* #ifndef CONFIG_SMP */
68796
68797 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68798 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68799 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68800 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68801
68802 static int synchronize_sched_expedited_cpu_stop(void *data)
68803 {
68804 @@ -1830,7 +1830,7 @@ void synchronize_sched_expedited(void)
68805 int firstsnap, s, snap, trycount = 0;
68806
68807 /* Note that atomic_inc_return() implies full memory barrier. */
68808 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68809 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68810 get_online_cpus();
68811
68812 /*
68813 @@ -1851,7 +1851,7 @@ void synchronize_sched_expedited(void)
68814 }
68815
68816 /* Check to see if someone else did our work for us. */
68817 - s = atomic_read(&sync_sched_expedited_done);
68818 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68819 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68820 smp_mb(); /* ensure test happens before caller kfree */
68821 return;
68822 @@ -1866,7 +1866,7 @@ void synchronize_sched_expedited(void)
68823 * grace period works for us.
68824 */
68825 get_online_cpus();
68826 - snap = atomic_read(&sync_sched_expedited_started) - 1;
68827 + snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
68828 smp_mb(); /* ensure read is before try_stop_cpus(). */
68829 }
68830
68831 @@ -1877,12 +1877,12 @@ void synchronize_sched_expedited(void)
68832 * than we did beat us to the punch.
68833 */
68834 do {
68835 - s = atomic_read(&sync_sched_expedited_done);
68836 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68837 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68838 smp_mb(); /* ensure test happens before caller kfree */
68839 break;
68840 }
68841 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68842 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68843
68844 put_online_cpus();
68845 }
68846 @@ -1953,7 +1953,7 @@ int rcu_needs_cpu(int cpu)
68847 for_each_online_cpu(thatcpu) {
68848 if (thatcpu == cpu)
68849 continue;
68850 - snap = atomic_add_return(0, &per_cpu(rcu_dynticks,
68851 + snap = atomic_add_return_unchecked(0, &per_cpu(rcu_dynticks,
68852 thatcpu).dynticks);
68853 smp_mb(); /* Order sampling of snap with end of grace period. */
68854 if ((snap & 0x1) != 0) {
68855 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68856 index 3b0c098..43ba2d8 100644
68857 --- a/kernel/rcutree_trace.c
68858 +++ b/kernel/rcutree_trace.c
68859 @@ -74,7 +74,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68860 rdp->qs_pending);
68861 #ifdef CONFIG_NO_HZ
68862 seq_printf(m, " dt=%d/%d/%d df=%lu",
68863 - atomic_read(&rdp->dynticks->dynticks),
68864 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68865 rdp->dynticks->dynticks_nesting,
68866 rdp->dynticks->dynticks_nmi_nesting,
68867 rdp->dynticks_fqs);
68868 @@ -148,7 +148,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68869 rdp->qs_pending);
68870 #ifdef CONFIG_NO_HZ
68871 seq_printf(m, ",%d,%d,%d,%lu",
68872 - atomic_read(&rdp->dynticks->dynticks),
68873 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68874 rdp->dynticks->dynticks_nesting,
68875 rdp->dynticks->dynticks_nmi_nesting,
68876 rdp->dynticks_fqs);
68877 diff --git a/kernel/relay.c b/kernel/relay.c
68878 index 859ea5a..096e2fe 100644
68879 --- a/kernel/relay.c
68880 +++ b/kernel/relay.c
68881 @@ -1236,6 +1236,8 @@ static ssize_t subbuf_splice_actor(struct file *in,
68882 };
68883 ssize_t ret;
68884
68885 + pax_track_stack();
68886 +
68887 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
68888 return 0;
68889 if (splice_grow_spd(pipe, &spd))
68890 diff --git a/kernel/resource.c b/kernel/resource.c
68891 index c8dc249..f1e2359 100644
68892 --- a/kernel/resource.c
68893 +++ b/kernel/resource.c
68894 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68895
68896 static int __init ioresources_init(void)
68897 {
68898 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68899 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68900 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68901 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68902 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68903 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68904 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68905 +#endif
68906 +#else
68907 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68908 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68909 +#endif
68910 return 0;
68911 }
68912 __initcall(ioresources_init);
68913 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68914 index 5c9ccd3..a35e22b 100644
68915 --- a/kernel/rtmutex-tester.c
68916 +++ b/kernel/rtmutex-tester.c
68917 @@ -20,7 +20,7 @@
68918 #define MAX_RT_TEST_MUTEXES 8
68919
68920 static spinlock_t rttest_lock;
68921 -static atomic_t rttest_event;
68922 +static atomic_unchecked_t rttest_event;
68923
68924 struct test_thread_data {
68925 int opcode;
68926 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68927
68928 case RTTEST_LOCKCONT:
68929 td->mutexes[td->opdata] = 1;
68930 - td->event = atomic_add_return(1, &rttest_event);
68931 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68932 return 0;
68933
68934 case RTTEST_RESET:
68935 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68936 return 0;
68937
68938 case RTTEST_RESETEVENT:
68939 - atomic_set(&rttest_event, 0);
68940 + atomic_set_unchecked(&rttest_event, 0);
68941 return 0;
68942
68943 default:
68944 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68945 return ret;
68946
68947 td->mutexes[id] = 1;
68948 - td->event = atomic_add_return(1, &rttest_event);
68949 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68950 rt_mutex_lock(&mutexes[id]);
68951 - td->event = atomic_add_return(1, &rttest_event);
68952 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68953 td->mutexes[id] = 4;
68954 return 0;
68955
68956 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68957 return ret;
68958
68959 td->mutexes[id] = 1;
68960 - td->event = atomic_add_return(1, &rttest_event);
68961 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68962 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
68963 - td->event = atomic_add_return(1, &rttest_event);
68964 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68965 td->mutexes[id] = ret ? 0 : 4;
68966 return ret ? -EINTR : 0;
68967
68968 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68969 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
68970 return ret;
68971
68972 - td->event = atomic_add_return(1, &rttest_event);
68973 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68974 rt_mutex_unlock(&mutexes[id]);
68975 - td->event = atomic_add_return(1, &rttest_event);
68976 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68977 td->mutexes[id] = 0;
68978 return 0;
68979
68980 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68981 break;
68982
68983 td->mutexes[dat] = 2;
68984 - td->event = atomic_add_return(1, &rttest_event);
68985 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68986 break;
68987
68988 default:
68989 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68990 return;
68991
68992 td->mutexes[dat] = 3;
68993 - td->event = atomic_add_return(1, &rttest_event);
68994 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68995 break;
68996
68997 case RTTEST_LOCKNOWAIT:
68998 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68999 return;
69000
69001 td->mutexes[dat] = 1;
69002 - td->event = atomic_add_return(1, &rttest_event);
69003 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69004 return;
69005
69006 default:
69007 diff --git a/kernel/sched.c b/kernel/sched.c
69008 index b50b0f0..1c6c591 100644
69009 --- a/kernel/sched.c
69010 +++ b/kernel/sched.c
69011 @@ -4264,6 +4264,8 @@ static void __sched __schedule(void)
69012 struct rq *rq;
69013 int cpu;
69014
69015 + pax_track_stack();
69016 +
69017 need_resched:
69018 preempt_disable();
69019 cpu = smp_processor_id();
69020 @@ -4950,6 +4952,8 @@ int can_nice(const struct task_struct *p, const int nice)
69021 /* convert nice value [19,-20] to rlimit style value [1,40] */
69022 int nice_rlim = 20 - nice;
69023
69024 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69025 +
69026 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69027 capable(CAP_SYS_NICE));
69028 }
69029 @@ -4983,7 +4987,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69030 if (nice > 19)
69031 nice = 19;
69032
69033 - if (increment < 0 && !can_nice(current, nice))
69034 + if (increment < 0 && (!can_nice(current, nice) ||
69035 + gr_handle_chroot_nice()))
69036 return -EPERM;
69037
69038 retval = security_task_setnice(current, nice);
69039 @@ -5127,6 +5132,7 @@ recheck:
69040 unsigned long rlim_rtprio =
69041 task_rlimit(p, RLIMIT_RTPRIO);
69042
69043 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69044 /* can't set/change the rt policy */
69045 if (policy != p->policy && !rlim_rtprio)
69046 return -EPERM;
69047 diff --git a/kernel/sched_autogroup.c b/kernel/sched_autogroup.c
69048 index 429242f..d7cca82 100644
69049 --- a/kernel/sched_autogroup.c
69050 +++ b/kernel/sched_autogroup.c
69051 @@ -7,7 +7,7 @@
69052
69053 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69054 static struct autogroup autogroup_default;
69055 -static atomic_t autogroup_seq_nr;
69056 +static atomic_unchecked_t autogroup_seq_nr;
69057
69058 static void __init autogroup_init(struct task_struct *init_task)
69059 {
69060 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69061
69062 kref_init(&ag->kref);
69063 init_rwsem(&ag->lock);
69064 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69065 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69066 ag->tg = tg;
69067 #ifdef CONFIG_RT_GROUP_SCHED
69068 /*
69069 diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
69070 index bc8ee99..b6f6492 100644
69071 --- a/kernel/sched_fair.c
69072 +++ b/kernel/sched_fair.c
69073 @@ -4062,7 +4062,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69074 * run_rebalance_domains is triggered when needed from the scheduler tick.
69075 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69076 */
69077 -static void run_rebalance_domains(struct softirq_action *h)
69078 +static void run_rebalance_domains(void)
69079 {
69080 int this_cpu = smp_processor_id();
69081 struct rq *this_rq = cpu_rq(this_cpu);
69082 diff --git a/kernel/signal.c b/kernel/signal.c
69083 index 195331c..e89634ce 100644
69084 --- a/kernel/signal.c
69085 +++ b/kernel/signal.c
69086 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cachep;
69087
69088 int print_fatal_signals __read_mostly;
69089
69090 -static void __user *sig_handler(struct task_struct *t, int sig)
69091 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69092 {
69093 return t->sighand->action[sig - 1].sa.sa_handler;
69094 }
69095
69096 -static int sig_handler_ignored(void __user *handler, int sig)
69097 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69098 {
69099 /* Is it explicitly or implicitly ignored? */
69100 return handler == SIG_IGN ||
69101 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69102 static int sig_task_ignored(struct task_struct *t, int sig,
69103 int from_ancestor_ns)
69104 {
69105 - void __user *handler;
69106 + __sighandler_t handler;
69107
69108 handler = sig_handler(t, sig);
69109
69110 @@ -364,6 +364,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69111 atomic_inc(&user->sigpending);
69112 rcu_read_unlock();
69113
69114 + if (!override_rlimit)
69115 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69116 +
69117 if (override_rlimit ||
69118 atomic_read(&user->sigpending) <=
69119 task_rlimit(t, RLIMIT_SIGPENDING)) {
69120 @@ -488,7 +491,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69121
69122 int unhandled_signal(struct task_struct *tsk, int sig)
69123 {
69124 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69125 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69126 if (is_global_init(tsk))
69127 return 1;
69128 if (handler != SIG_IGN && handler != SIG_DFL)
69129 @@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69130 }
69131 }
69132
69133 + /* allow glibc communication via tgkill to other threads in our
69134 + thread group */
69135 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69136 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69137 + && gr_handle_signal(t, sig))
69138 + return -EPERM;
69139 +
69140 return security_task_kill(t, info, sig, 0);
69141 }
69142
69143 @@ -1165,7 +1175,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69144 return send_signal(sig, info, p, 1);
69145 }
69146
69147 -static int
69148 +int
69149 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69150 {
69151 return send_signal(sig, info, t, 0);
69152 @@ -1202,6 +1212,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69153 unsigned long int flags;
69154 int ret, blocked, ignored;
69155 struct k_sigaction *action;
69156 + int is_unhandled = 0;
69157
69158 spin_lock_irqsave(&t->sighand->siglock, flags);
69159 action = &t->sighand->action[sig-1];
69160 @@ -1216,9 +1227,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69161 }
69162 if (action->sa.sa_handler == SIG_DFL)
69163 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69164 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69165 + is_unhandled = 1;
69166 ret = specific_send_sig_info(sig, info, t);
69167 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69168
69169 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
69170 + normal operation */
69171 + if (is_unhandled) {
69172 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69173 + gr_handle_crash(t, sig);
69174 + }
69175 +
69176 return ret;
69177 }
69178
69179 @@ -1285,8 +1305,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69180 ret = check_kill_permission(sig, info, p);
69181 rcu_read_unlock();
69182
69183 - if (!ret && sig)
69184 + if (!ret && sig) {
69185 ret = do_send_sig_info(sig, info, p, true);
69186 + if (!ret)
69187 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69188 + }
69189
69190 return ret;
69191 }
69192 @@ -1909,6 +1932,8 @@ static void ptrace_do_notify(int signr, int exit_code, int why)
69193 {
69194 siginfo_t info;
69195
69196 + pax_track_stack();
69197 +
69198 memset(&info, 0, sizeof info);
69199 info.si_signo = signr;
69200 info.si_code = exit_code;
69201 @@ -2746,7 +2771,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69202 int error = -ESRCH;
69203
69204 rcu_read_lock();
69205 - p = find_task_by_vpid(pid);
69206 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69207 + /* allow glibc communication via tgkill to other threads in our
69208 + thread group */
69209 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69210 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
69211 + p = find_task_by_vpid_unrestricted(pid);
69212 + else
69213 +#endif
69214 + p = find_task_by_vpid(pid);
69215 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69216 error = check_kill_permission(sig, info, p);
69217 /*
69218 diff --git a/kernel/smp.c b/kernel/smp.c
69219 index fb67dfa..f819e2e 100644
69220 --- a/kernel/smp.c
69221 +++ b/kernel/smp.c
69222 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69223 }
69224 EXPORT_SYMBOL(smp_call_function);
69225
69226 -void ipi_call_lock(void)
69227 +void ipi_call_lock(void) __acquires(call_function.lock)
69228 {
69229 raw_spin_lock(&call_function.lock);
69230 }
69231
69232 -void ipi_call_unlock(void)
69233 +void ipi_call_unlock(void) __releases(call_function.lock)
69234 {
69235 raw_spin_unlock(&call_function.lock);
69236 }
69237
69238 -void ipi_call_lock_irq(void)
69239 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
69240 {
69241 raw_spin_lock_irq(&call_function.lock);
69242 }
69243
69244 -void ipi_call_unlock_irq(void)
69245 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
69246 {
69247 raw_spin_unlock_irq(&call_function.lock);
69248 }
69249 diff --git a/kernel/softirq.c b/kernel/softirq.c
69250 index fca82c3..1db9690 100644
69251 --- a/kernel/softirq.c
69252 +++ b/kernel/softirq.c
69253 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69254
69255 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69256
69257 -char *softirq_to_name[NR_SOFTIRQS] = {
69258 +const char * const softirq_to_name[NR_SOFTIRQS] = {
69259 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69260 "TASKLET", "SCHED", "HRTIMER", "RCU"
69261 };
69262 @@ -235,7 +235,7 @@ restart:
69263 kstat_incr_softirqs_this_cpu(vec_nr);
69264
69265 trace_softirq_entry(vec_nr);
69266 - h->action(h);
69267 + h->action();
69268 trace_softirq_exit(vec_nr);
69269 if (unlikely(prev_count != preempt_count())) {
69270 printk(KERN_ERR "huh, entered softirq %u %s %p"
69271 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
69272 local_irq_restore(flags);
69273 }
69274
69275 -void open_softirq(int nr, void (*action)(struct softirq_action *))
69276 +void open_softirq(int nr, void (*action)(void))
69277 {
69278 - softirq_vec[nr].action = action;
69279 + pax_open_kernel();
69280 + *(void **)&softirq_vec[nr].action = action;
69281 + pax_close_kernel();
69282 }
69283
69284 /*
69285 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69286
69287 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69288
69289 -static void tasklet_action(struct softirq_action *a)
69290 +static void tasklet_action(void)
69291 {
69292 struct tasklet_struct *list;
69293
69294 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
69295 }
69296 }
69297
69298 -static void tasklet_hi_action(struct softirq_action *a)
69299 +static void tasklet_hi_action(void)
69300 {
69301 struct tasklet_struct *list;
69302
69303 diff --git a/kernel/sys.c b/kernel/sys.c
69304 index 1dbbe69..e96e1dd 100644
69305 --- a/kernel/sys.c
69306 +++ b/kernel/sys.c
69307 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69308 error = -EACCES;
69309 goto out;
69310 }
69311 +
69312 + if (gr_handle_chroot_setpriority(p, niceval)) {
69313 + error = -EACCES;
69314 + goto out;
69315 + }
69316 +
69317 no_nice = security_task_setnice(p, niceval);
69318 if (no_nice) {
69319 error = no_nice;
69320 @@ -571,6 +577,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69321 goto error;
69322 }
69323
69324 + if (gr_check_group_change(new->gid, new->egid, -1))
69325 + goto error;
69326 +
69327 if (rgid != (gid_t) -1 ||
69328 (egid != (gid_t) -1 && egid != old->gid))
69329 new->sgid = new->egid;
69330 @@ -600,6 +609,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69331 old = current_cred();
69332
69333 retval = -EPERM;
69334 +
69335 + if (gr_check_group_change(gid, gid, gid))
69336 + goto error;
69337 +
69338 if (nsown_capable(CAP_SETGID))
69339 new->gid = new->egid = new->sgid = new->fsgid = gid;
69340 else if (gid == old->gid || gid == old->sgid)
69341 @@ -687,6 +700,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69342 goto error;
69343 }
69344
69345 + if (gr_check_user_change(new->uid, new->euid, -1))
69346 + goto error;
69347 +
69348 if (new->uid != old->uid) {
69349 retval = set_user(new);
69350 if (retval < 0)
69351 @@ -731,6 +747,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69352 old = current_cred();
69353
69354 retval = -EPERM;
69355 +
69356 + if (gr_check_crash_uid(uid))
69357 + goto error;
69358 + if (gr_check_user_change(uid, uid, uid))
69359 + goto error;
69360 +
69361 if (nsown_capable(CAP_SETUID)) {
69362 new->suid = new->uid = uid;
69363 if (uid != old->uid) {
69364 @@ -785,6 +807,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69365 goto error;
69366 }
69367
69368 + if (gr_check_user_change(ruid, euid, -1))
69369 + goto error;
69370 +
69371 if (ruid != (uid_t) -1) {
69372 new->uid = ruid;
69373 if (ruid != old->uid) {
69374 @@ -849,6 +874,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69375 goto error;
69376 }
69377
69378 + if (gr_check_group_change(rgid, egid, -1))
69379 + goto error;
69380 +
69381 if (rgid != (gid_t) -1)
69382 new->gid = rgid;
69383 if (egid != (gid_t) -1)
69384 @@ -895,6 +923,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69385 old = current_cred();
69386 old_fsuid = old->fsuid;
69387
69388 + if (gr_check_user_change(-1, -1, uid))
69389 + goto error;
69390 +
69391 if (uid == old->uid || uid == old->euid ||
69392 uid == old->suid || uid == old->fsuid ||
69393 nsown_capable(CAP_SETUID)) {
69394 @@ -905,6 +936,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69395 }
69396 }
69397
69398 +error:
69399 abort_creds(new);
69400 return old_fsuid;
69401
69402 @@ -931,12 +963,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69403 if (gid == old->gid || gid == old->egid ||
69404 gid == old->sgid || gid == old->fsgid ||
69405 nsown_capable(CAP_SETGID)) {
69406 + if (gr_check_group_change(-1, -1, gid))
69407 + goto error;
69408 +
69409 if (gid != old_fsgid) {
69410 new->fsgid = gid;
69411 goto change_okay;
69412 }
69413 }
69414
69415 +error:
69416 abort_creds(new);
69417 return old_fsgid;
69418
69419 @@ -1188,7 +1224,10 @@ static int override_release(char __user *release, int len)
69420 }
69421 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69422 snprintf(buf, len, "2.6.%u%s", v, rest);
69423 - ret = copy_to_user(release, buf, len);
69424 + if (len > sizeof(buf))
69425 + ret = -EFAULT;
69426 + else
69427 + ret = copy_to_user(release, buf, len);
69428 }
69429 return ret;
69430 }
69431 @@ -1242,19 +1281,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69432 return -EFAULT;
69433
69434 down_read(&uts_sem);
69435 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69436 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69437 __OLD_UTS_LEN);
69438 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69439 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69440 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69441 __OLD_UTS_LEN);
69442 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69443 - error |= __copy_to_user(&name->release, &utsname()->release,
69444 + error |= __copy_to_user(name->release, &utsname()->release,
69445 __OLD_UTS_LEN);
69446 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69447 - error |= __copy_to_user(&name->version, &utsname()->version,
69448 + error |= __copy_to_user(name->version, &utsname()->version,
69449 __OLD_UTS_LEN);
69450 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69451 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69452 + error |= __copy_to_user(name->machine, &utsname()->machine,
69453 __OLD_UTS_LEN);
69454 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69455 up_read(&uts_sem);
69456 @@ -1717,7 +1756,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69457 error = get_dumpable(me->mm);
69458 break;
69459 case PR_SET_DUMPABLE:
69460 - if (arg2 < 0 || arg2 > 1) {
69461 + if (arg2 > 1) {
69462 error = -EINVAL;
69463 break;
69464 }
69465 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69466 index 11d65b5..6957b37 100644
69467 --- a/kernel/sysctl.c
69468 +++ b/kernel/sysctl.c
69469 @@ -85,6 +85,13 @@
69470
69471
69472 #if defined(CONFIG_SYSCTL)
69473 +#include <linux/grsecurity.h>
69474 +#include <linux/grinternal.h>
69475 +
69476 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
69477 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
69478 + const int op);
69479 +extern int gr_handle_chroot_sysctl(const int op);
69480
69481 /* External variables not in a header file. */
69482 extern int sysctl_overcommit_memory;
69483 @@ -197,6 +204,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69484 }
69485
69486 #endif
69487 +extern struct ctl_table grsecurity_table[];
69488
69489 static struct ctl_table root_table[];
69490 static struct ctl_table_root sysctl_table_root;
69491 @@ -226,6 +234,20 @@ extern struct ctl_table epoll_table[];
69492 int sysctl_legacy_va_layout;
69493 #endif
69494
69495 +#ifdef CONFIG_PAX_SOFTMODE
69496 +static ctl_table pax_table[] = {
69497 + {
69498 + .procname = "softmode",
69499 + .data = &pax_softmode,
69500 + .maxlen = sizeof(unsigned int),
69501 + .mode = 0600,
69502 + .proc_handler = &proc_dointvec,
69503 + },
69504 +
69505 + { }
69506 +};
69507 +#endif
69508 +
69509 /* The default sysctl tables: */
69510
69511 static struct ctl_table root_table[] = {
69512 @@ -272,6 +294,22 @@ static int max_extfrag_threshold = 1000;
69513 #endif
69514
69515 static struct ctl_table kern_table[] = {
69516 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69517 + {
69518 + .procname = "grsecurity",
69519 + .mode = 0500,
69520 + .child = grsecurity_table,
69521 + },
69522 +#endif
69523 +
69524 +#ifdef CONFIG_PAX_SOFTMODE
69525 + {
69526 + .procname = "pax",
69527 + .mode = 0500,
69528 + .child = pax_table,
69529 + },
69530 +#endif
69531 +
69532 {
69533 .procname = "sched_child_runs_first",
69534 .data = &sysctl_sched_child_runs_first,
69535 @@ -546,7 +584,7 @@ static struct ctl_table kern_table[] = {
69536 .data = &modprobe_path,
69537 .maxlen = KMOD_PATH_LEN,
69538 .mode = 0644,
69539 - .proc_handler = proc_dostring,
69540 + .proc_handler = proc_dostring_modpriv,
69541 },
69542 {
69543 .procname = "modules_disabled",
69544 @@ -713,16 +751,20 @@ static struct ctl_table kern_table[] = {
69545 .extra1 = &zero,
69546 .extra2 = &one,
69547 },
69548 +#endif
69549 {
69550 .procname = "kptr_restrict",
69551 .data = &kptr_restrict,
69552 .maxlen = sizeof(int),
69553 .mode = 0644,
69554 .proc_handler = proc_dmesg_restrict,
69555 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69556 + .extra1 = &two,
69557 +#else
69558 .extra1 = &zero,
69559 +#endif
69560 .extra2 = &two,
69561 },
69562 -#endif
69563 {
69564 .procname = "ngroups_max",
69565 .data = &ngroups_max,
69566 @@ -1205,6 +1247,13 @@ static struct ctl_table vm_table[] = {
69567 .proc_handler = proc_dointvec_minmax,
69568 .extra1 = &zero,
69569 },
69570 + {
69571 + .procname = "heap_stack_gap",
69572 + .data = &sysctl_heap_stack_gap,
69573 + .maxlen = sizeof(sysctl_heap_stack_gap),
69574 + .mode = 0644,
69575 + .proc_handler = proc_doulongvec_minmax,
69576 + },
69577 #else
69578 {
69579 .procname = "nr_trim_pages",
69580 @@ -1709,6 +1758,17 @@ static int test_perm(int mode, int op)
69581 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
69582 {
69583 int mode;
69584 + int error;
69585 +
69586 + if (table->parent != NULL && table->parent->procname != NULL &&
69587 + table->procname != NULL &&
69588 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
69589 + return -EACCES;
69590 + if (gr_handle_chroot_sysctl(op))
69591 + return -EACCES;
69592 + error = gr_handle_sysctl(table, op);
69593 + if (error)
69594 + return error;
69595
69596 if (root->permissions)
69597 mode = root->permissions(root, current->nsproxy, table);
69598 @@ -2113,6 +2173,16 @@ int proc_dostring(struct ctl_table *table, int write,
69599 buffer, lenp, ppos);
69600 }
69601
69602 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69603 + void __user *buffer, size_t *lenp, loff_t *ppos)
69604 +{
69605 + if (write && !capable(CAP_SYS_MODULE))
69606 + return -EPERM;
69607 +
69608 + return _proc_do_string(table->data, table->maxlen, write,
69609 + buffer, lenp, ppos);
69610 +}
69611 +
69612 static size_t proc_skip_spaces(char **buf)
69613 {
69614 size_t ret;
69615 @@ -2218,6 +2288,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69616 len = strlen(tmp);
69617 if (len > *size)
69618 len = *size;
69619 + if (len > sizeof(tmp))
69620 + len = sizeof(tmp);
69621 if (copy_to_user(*buf, tmp, len))
69622 return -EFAULT;
69623 *size -= len;
69624 @@ -2534,8 +2606,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69625 *i = val;
69626 } else {
69627 val = convdiv * (*i) / convmul;
69628 - if (!first)
69629 + if (!first) {
69630 err = proc_put_char(&buffer, &left, '\t');
69631 + if (err)
69632 + break;
69633 + }
69634 err = proc_put_long(&buffer, &left, val, false);
69635 if (err)
69636 break;
69637 @@ -2930,6 +3005,12 @@ int proc_dostring(struct ctl_table *table, int write,
69638 return -ENOSYS;
69639 }
69640
69641 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69642 + void __user *buffer, size_t *lenp, loff_t *ppos)
69643 +{
69644 + return -ENOSYS;
69645 +}
69646 +
69647 int proc_dointvec(struct ctl_table *table, int write,
69648 void __user *buffer, size_t *lenp, loff_t *ppos)
69649 {
69650 @@ -2986,6 +3067,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69651 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69652 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69653 EXPORT_SYMBOL(proc_dostring);
69654 +EXPORT_SYMBOL(proc_dostring_modpriv);
69655 EXPORT_SYMBOL(proc_doulongvec_minmax);
69656 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69657 EXPORT_SYMBOL(register_sysctl_table);
69658 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69659 index 2ce1b30..82bf0a4 100644
69660 --- a/kernel/sysctl_binary.c
69661 +++ b/kernel/sysctl_binary.c
69662 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69663 int i;
69664
69665 set_fs(KERNEL_DS);
69666 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69667 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69668 set_fs(old_fs);
69669 if (result < 0)
69670 goto out_kfree;
69671 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69672 }
69673
69674 set_fs(KERNEL_DS);
69675 - result = vfs_write(file, buffer, str - buffer, &pos);
69676 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69677 set_fs(old_fs);
69678 if (result < 0)
69679 goto out_kfree;
69680 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69681 int i;
69682
69683 set_fs(KERNEL_DS);
69684 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69685 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69686 set_fs(old_fs);
69687 if (result < 0)
69688 goto out_kfree;
69689 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69690 }
69691
69692 set_fs(KERNEL_DS);
69693 - result = vfs_write(file, buffer, str - buffer, &pos);
69694 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69695 set_fs(old_fs);
69696 if (result < 0)
69697 goto out_kfree;
69698 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69699 int i;
69700
69701 set_fs(KERNEL_DS);
69702 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69703 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69704 set_fs(old_fs);
69705 if (result < 0)
69706 goto out;
69707 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69708 __le16 dnaddr;
69709
69710 set_fs(KERNEL_DS);
69711 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69712 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69713 set_fs(old_fs);
69714 if (result < 0)
69715 goto out;
69716 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69717 le16_to_cpu(dnaddr) & 0x3ff);
69718
69719 set_fs(KERNEL_DS);
69720 - result = vfs_write(file, buf, len, &pos);
69721 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69722 set_fs(old_fs);
69723 if (result < 0)
69724 goto out;
69725 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
69726 index 362da65..ab8ef8c 100644
69727 --- a/kernel/sysctl_check.c
69728 +++ b/kernel/sysctl_check.c
69729 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
69730 set_fail(&fail, table, "Directory with extra2");
69731 } else {
69732 if ((table->proc_handler == proc_dostring) ||
69733 + (table->proc_handler == proc_dostring_modpriv) ||
69734 (table->proc_handler == proc_dointvec) ||
69735 (table->proc_handler == proc_dointvec_minmax) ||
69736 (table->proc_handler == proc_dointvec_jiffies) ||
69737 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69738 index e660464..c8b9e67 100644
69739 --- a/kernel/taskstats.c
69740 +++ b/kernel/taskstats.c
69741 @@ -27,9 +27,12 @@
69742 #include <linux/cgroup.h>
69743 #include <linux/fs.h>
69744 #include <linux/file.h>
69745 +#include <linux/grsecurity.h>
69746 #include <net/genetlink.h>
69747 #include <linux/atomic.h>
69748
69749 +extern int gr_is_taskstats_denied(int pid);
69750 +
69751 /*
69752 * Maximum length of a cpumask that can be specified in
69753 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69754 @@ -556,6 +559,9 @@ err:
69755
69756 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69757 {
69758 + if (gr_is_taskstats_denied(current->pid))
69759 + return -EACCES;
69760 +
69761 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69762 return cmd_attr_register_cpumask(info);
69763 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69764 diff --git a/kernel/time.c b/kernel/time.c
69765 index d776062..fa8d186 100644
69766 --- a/kernel/time.c
69767 +++ b/kernel/time.c
69768 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69769 return error;
69770
69771 if (tz) {
69772 + /* we log in do_settimeofday called below, so don't log twice
69773 + */
69774 + if (!tv)
69775 + gr_log_timechange();
69776 +
69777 /* SMP safe, global irq locking makes it work. */
69778 sys_tz = *tz;
69779 update_vsyscall_tz();
69780 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69781 index 8b70c76..923e9f5 100644
69782 --- a/kernel/time/alarmtimer.c
69783 +++ b/kernel/time/alarmtimer.c
69784 @@ -693,7 +693,7 @@ static int __init alarmtimer_init(void)
69785 {
69786 int error = 0;
69787 int i;
69788 - struct k_clock alarm_clock = {
69789 + static struct k_clock alarm_clock = {
69790 .clock_getres = alarm_clock_getres,
69791 .clock_get = alarm_clock_get,
69792 .timer_create = alarm_timer_create,
69793 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69794 index 7a90d02..6d8585a 100644
69795 --- a/kernel/time/tick-broadcast.c
69796 +++ b/kernel/time/tick-broadcast.c
69797 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69798 * then clear the broadcast bit.
69799 */
69800 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69801 - int cpu = smp_processor_id();
69802 + cpu = smp_processor_id();
69803
69804 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69805 tick_broadcast_clear_oneshot(cpu);
69806 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69807 index 6f9798b..f8c4087 100644
69808 --- a/kernel/time/timekeeping.c
69809 +++ b/kernel/time/timekeeping.c
69810 @@ -14,6 +14,7 @@
69811 #include <linux/init.h>
69812 #include <linux/mm.h>
69813 #include <linux/sched.h>
69814 +#include <linux/grsecurity.h>
69815 #include <linux/syscore_ops.h>
69816 #include <linux/clocksource.h>
69817 #include <linux/jiffies.h>
69818 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
69819 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69820 return -EINVAL;
69821
69822 + gr_log_timechange();
69823 +
69824 write_seqlock_irqsave(&xtime_lock, flags);
69825
69826 timekeeping_forward_now();
69827 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69828 index 3258455..f35227d 100644
69829 --- a/kernel/time/timer_list.c
69830 +++ b/kernel/time/timer_list.c
69831 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69832
69833 static void print_name_offset(struct seq_file *m, void *sym)
69834 {
69835 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69836 + SEQ_printf(m, "<%p>", NULL);
69837 +#else
69838 char symname[KSYM_NAME_LEN];
69839
69840 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69841 SEQ_printf(m, "<%pK>", sym);
69842 else
69843 SEQ_printf(m, "%s", symname);
69844 +#endif
69845 }
69846
69847 static void
69848 @@ -112,7 +116,11 @@ next_one:
69849 static void
69850 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69851 {
69852 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69853 + SEQ_printf(m, " .base: %p\n", NULL);
69854 +#else
69855 SEQ_printf(m, " .base: %pK\n", base);
69856 +#endif
69857 SEQ_printf(m, " .index: %d\n",
69858 base->index);
69859 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69860 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69861 {
69862 struct proc_dir_entry *pe;
69863
69864 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69865 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69866 +#else
69867 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69868 +#endif
69869 if (!pe)
69870 return -ENOMEM;
69871 return 0;
69872 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69873 index a5d0a3a..60c7948 100644
69874 --- a/kernel/time/timer_stats.c
69875 +++ b/kernel/time/timer_stats.c
69876 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69877 static unsigned long nr_entries;
69878 static struct entry entries[MAX_ENTRIES];
69879
69880 -static atomic_t overflow_count;
69881 +static atomic_unchecked_t overflow_count;
69882
69883 /*
69884 * The entries are in a hash-table, for fast lookup:
69885 @@ -140,7 +140,7 @@ static void reset_entries(void)
69886 nr_entries = 0;
69887 memset(entries, 0, sizeof(entries));
69888 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
69889 - atomic_set(&overflow_count, 0);
69890 + atomic_set_unchecked(&overflow_count, 0);
69891 }
69892
69893 static struct entry *alloc_entry(void)
69894 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69895 if (likely(entry))
69896 entry->count++;
69897 else
69898 - atomic_inc(&overflow_count);
69899 + atomic_inc_unchecked(&overflow_count);
69900
69901 out_unlock:
69902 raw_spin_unlock_irqrestore(lock, flags);
69903 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69904
69905 static void print_name_offset(struct seq_file *m, unsigned long addr)
69906 {
69907 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69908 + seq_printf(m, "<%p>", NULL);
69909 +#else
69910 char symname[KSYM_NAME_LEN];
69911
69912 if (lookup_symbol_name(addr, symname) < 0)
69913 seq_printf(m, "<%p>", (void *)addr);
69914 else
69915 seq_printf(m, "%s", symname);
69916 +#endif
69917 }
69918
69919 static int tstats_show(struct seq_file *m, void *v)
69920 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69921
69922 seq_puts(m, "Timer Stats Version: v0.2\n");
69923 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69924 - if (atomic_read(&overflow_count))
69925 + if (atomic_read_unchecked(&overflow_count))
69926 seq_printf(m, "Overflow: %d entries\n",
69927 - atomic_read(&overflow_count));
69928 + atomic_read_unchecked(&overflow_count));
69929
69930 for (i = 0; i < nr_entries; i++) {
69931 entry = entries + i;
69932 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
69933 {
69934 struct proc_dir_entry *pe;
69935
69936 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69937 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
69938 +#else
69939 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
69940 +#endif
69941 if (!pe)
69942 return -ENOMEM;
69943 return 0;
69944 diff --git a/kernel/timer.c b/kernel/timer.c
69945 index 8cff361..0fb5cd8 100644
69946 --- a/kernel/timer.c
69947 +++ b/kernel/timer.c
69948 @@ -1304,7 +1304,7 @@ void update_process_times(int user_tick)
69949 /*
69950 * This function runs timers and the timer-tq in bottom half context.
69951 */
69952 -static void run_timer_softirq(struct softirq_action *h)
69953 +static void run_timer_softirq(void)
69954 {
69955 struct tvec_base *base = __this_cpu_read(tvec_bases);
69956
69957 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
69958 index 7c910a5..8b72104 100644
69959 --- a/kernel/trace/blktrace.c
69960 +++ b/kernel/trace/blktrace.c
69961 @@ -323,7 +323,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
69962 struct blk_trace *bt = filp->private_data;
69963 char buf[16];
69964
69965 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
69966 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
69967
69968 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
69969 }
69970 @@ -388,7 +388,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
69971 return 1;
69972
69973 bt = buf->chan->private_data;
69974 - atomic_inc(&bt->dropped);
69975 + atomic_inc_unchecked(&bt->dropped);
69976 return 0;
69977 }
69978
69979 @@ -489,7 +489,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
69980
69981 bt->dir = dir;
69982 bt->dev = dev;
69983 - atomic_set(&bt->dropped, 0);
69984 + atomic_set_unchecked(&bt->dropped, 0);
69985
69986 ret = -EIO;
69987 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
69988 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
69989 index 48d3762..3b61fce 100644
69990 --- a/kernel/trace/ftrace.c
69991 +++ b/kernel/trace/ftrace.c
69992 @@ -1584,12 +1584,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
69993 if (unlikely(ftrace_disabled))
69994 return 0;
69995
69996 + ret = ftrace_arch_code_modify_prepare();
69997 + FTRACE_WARN_ON(ret);
69998 + if (ret)
69999 + return 0;
70000 +
70001 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70002 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70003 if (ret) {
70004 ftrace_bug(ret, ip);
70005 - return 0;
70006 }
70007 - return 1;
70008 + return ret ? 0 : 1;
70009 }
70010
70011 /*
70012 @@ -2606,7 +2611,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70013
70014 int
70015 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70016 - void *data)
70017 + void *data)
70018 {
70019 struct ftrace_func_probe *entry;
70020 struct ftrace_page *pg;
70021 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70022 index 17a2d44..85907e2 100644
70023 --- a/kernel/trace/trace.c
70024 +++ b/kernel/trace/trace.c
70025 @@ -3451,6 +3451,8 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
70026 size_t rem;
70027 unsigned int i;
70028
70029 + pax_track_stack();
70030 +
70031 if (splice_grow_spd(pipe, &spd))
70032 return -ENOMEM;
70033
70034 @@ -3926,6 +3928,8 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
70035 int entries, size, i;
70036 size_t ret;
70037
70038 + pax_track_stack();
70039 +
70040 if (splice_grow_spd(pipe, &spd))
70041 return -ENOMEM;
70042
70043 @@ -4093,10 +4097,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70044 };
70045 #endif
70046
70047 -static struct dentry *d_tracer;
70048 -
70049 struct dentry *tracing_init_dentry(void)
70050 {
70051 + static struct dentry *d_tracer;
70052 static int once;
70053
70054 if (d_tracer)
70055 @@ -4116,10 +4119,9 @@ struct dentry *tracing_init_dentry(void)
70056 return d_tracer;
70057 }
70058
70059 -static struct dentry *d_percpu;
70060 -
70061 struct dentry *tracing_dentry_percpu(void)
70062 {
70063 + static struct dentry *d_percpu;
70064 static int once;
70065 struct dentry *d_tracer;
70066
70067 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70068 index c212a7f..7b02394 100644
70069 --- a/kernel/trace/trace_events.c
70070 +++ b/kernel/trace/trace_events.c
70071 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
70072 struct ftrace_module_file_ops {
70073 struct list_head list;
70074 struct module *mod;
70075 - struct file_operations id;
70076 - struct file_operations enable;
70077 - struct file_operations format;
70078 - struct file_operations filter;
70079 };
70080
70081 static struct ftrace_module_file_ops *
70082 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
70083
70084 file_ops->mod = mod;
70085
70086 - file_ops->id = ftrace_event_id_fops;
70087 - file_ops->id.owner = mod;
70088 -
70089 - file_ops->enable = ftrace_enable_fops;
70090 - file_ops->enable.owner = mod;
70091 -
70092 - file_ops->filter = ftrace_event_filter_fops;
70093 - file_ops->filter.owner = mod;
70094 -
70095 - file_ops->format = ftrace_event_format_fops;
70096 - file_ops->format.owner = mod;
70097 + pax_open_kernel();
70098 + *(void **)&mod->trace_id.owner = mod;
70099 + *(void **)&mod->trace_enable.owner = mod;
70100 + *(void **)&mod->trace_filter.owner = mod;
70101 + *(void **)&mod->trace_format.owner = mod;
70102 + pax_close_kernel();
70103
70104 list_add(&file_ops->list, &ftrace_module_file_list);
70105
70106 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
70107
70108 for_each_event(call, start, end) {
70109 __trace_add_event_call(*call, mod,
70110 - &file_ops->id, &file_ops->enable,
70111 - &file_ops->filter, &file_ops->format);
70112 + &mod->trace_id, &mod->trace_enable,
70113 + &mod->trace_filter, &mod->trace_format);
70114 }
70115 }
70116
70117 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
70118 index 00d527c..7c5b1a3 100644
70119 --- a/kernel/trace/trace_kprobe.c
70120 +++ b/kernel/trace/trace_kprobe.c
70121 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
70122 long ret;
70123 int maxlen = get_rloc_len(*(u32 *)dest);
70124 u8 *dst = get_rloc_data(dest);
70125 - u8 *src = addr;
70126 + const u8 __user *src = (const u8 __force_user *)addr;
70127 mm_segment_t old_fs = get_fs();
70128 if (!maxlen)
70129 return;
70130 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
70131 pagefault_disable();
70132 do
70133 ret = __copy_from_user_inatomic(dst++, src++, 1);
70134 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
70135 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
70136 dst[-1] = '\0';
70137 pagefault_enable();
70138 set_fs(old_fs);
70139 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
70140 ((u8 *)get_rloc_data(dest))[0] = '\0';
70141 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
70142 } else
70143 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
70144 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
70145 get_rloc_offs(*(u32 *)dest));
70146 }
70147 /* Return the length of string -- including null terminal byte */
70148 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
70149 set_fs(KERNEL_DS);
70150 pagefault_disable();
70151 do {
70152 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
70153 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
70154 len++;
70155 } while (c && ret == 0 && len < MAX_STRING_SIZE);
70156 pagefault_enable();
70157 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70158 index fd3c8aa..5f324a6 100644
70159 --- a/kernel/trace/trace_mmiotrace.c
70160 +++ b/kernel/trace/trace_mmiotrace.c
70161 @@ -24,7 +24,7 @@ struct header_iter {
70162 static struct trace_array *mmio_trace_array;
70163 static bool overrun_detected;
70164 static unsigned long prev_overruns;
70165 -static atomic_t dropped_count;
70166 +static atomic_unchecked_t dropped_count;
70167
70168 static void mmio_reset_data(struct trace_array *tr)
70169 {
70170 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70171
70172 static unsigned long count_overruns(struct trace_iterator *iter)
70173 {
70174 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70175 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70176 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70177
70178 if (over > prev_overruns)
70179 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70180 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70181 sizeof(*entry), 0, pc);
70182 if (!event) {
70183 - atomic_inc(&dropped_count);
70184 + atomic_inc_unchecked(&dropped_count);
70185 return;
70186 }
70187 entry = ring_buffer_event_data(event);
70188 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70189 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70190 sizeof(*entry), 0, pc);
70191 if (!event) {
70192 - atomic_inc(&dropped_count);
70193 + atomic_inc_unchecked(&dropped_count);
70194 return;
70195 }
70196 entry = ring_buffer_event_data(event);
70197 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70198 index 5199930..26c73a0 100644
70199 --- a/kernel/trace/trace_output.c
70200 +++ b/kernel/trace/trace_output.c
70201 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
70202
70203 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70204 if (!IS_ERR(p)) {
70205 - p = mangle_path(s->buffer + s->len, p, "\n");
70206 + p = mangle_path(s->buffer + s->len, p, "\n\\");
70207 if (p) {
70208 s->len = p - s->buffer;
70209 return 1;
70210 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70211 index 77575b3..6e623d1 100644
70212 --- a/kernel/trace/trace_stack.c
70213 +++ b/kernel/trace/trace_stack.c
70214 @@ -50,7 +50,7 @@ static inline void check_stack(void)
70215 return;
70216
70217 /* we do not handle interrupt stacks yet */
70218 - if (!object_is_on_stack(&this_size))
70219 + if (!object_starts_on_stack(&this_size))
70220 return;
70221
70222 local_irq_save(flags);
70223 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
70224 index 209b379..7f76423 100644
70225 --- a/kernel/trace/trace_workqueue.c
70226 +++ b/kernel/trace/trace_workqueue.c
70227 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
70228 int cpu;
70229 pid_t pid;
70230 /* Can be inserted from interrupt or user context, need to be atomic */
70231 - atomic_t inserted;
70232 + atomic_unchecked_t inserted;
70233 /*
70234 * Don't need to be atomic, works are serialized in a single workqueue thread
70235 * on a single CPU.
70236 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
70237 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
70238 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
70239 if (node->pid == wq_thread->pid) {
70240 - atomic_inc(&node->inserted);
70241 + atomic_inc_unchecked(&node->inserted);
70242 goto found;
70243 }
70244 }
70245 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
70246 tsk = get_pid_task(pid, PIDTYPE_PID);
70247 if (tsk) {
70248 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
70249 - atomic_read(&cws->inserted), cws->executed,
70250 + atomic_read_unchecked(&cws->inserted), cws->executed,
70251 tsk->comm);
70252 put_task_struct(tsk);
70253 }
70254 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70255 index c0cb9c4..f33aa89 100644
70256 --- a/lib/Kconfig.debug
70257 +++ b/lib/Kconfig.debug
70258 @@ -1091,6 +1091,7 @@ config LATENCYTOP
70259 depends on DEBUG_KERNEL
70260 depends on STACKTRACE_SUPPORT
70261 depends on PROC_FS
70262 + depends on !GRKERNSEC_HIDESYM
70263 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE
70264 select KALLSYMS
70265 select KALLSYMS_ALL
70266 diff --git a/lib/bitmap.c b/lib/bitmap.c
70267 index 2f4412e..a557e27 100644
70268 --- a/lib/bitmap.c
70269 +++ b/lib/bitmap.c
70270 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70271 {
70272 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70273 u32 chunk;
70274 - const char __user *ubuf = buf;
70275 + const char __user *ubuf = (const char __force_user *)buf;
70276
70277 bitmap_zero(maskp, nmaskbits);
70278
70279 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
70280 {
70281 if (!access_ok(VERIFY_READ, ubuf, ulen))
70282 return -EFAULT;
70283 - return __bitmap_parse((const char *)ubuf, ulen, 1, maskp, nmaskbits);
70284 + return __bitmap_parse((const char __force_kernel *)ubuf, ulen, 1, maskp, nmaskbits);
70285 }
70286 EXPORT_SYMBOL(bitmap_parse_user);
70287
70288 @@ -594,7 +594,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70289 {
70290 unsigned a, b;
70291 int c, old_c, totaldigits;
70292 - const char __user *ubuf = buf;
70293 + const char __user *ubuf = (const char __force_user *)buf;
70294 int exp_digit, in_range;
70295
70296 totaldigits = c = 0;
70297 @@ -694,7 +694,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70298 {
70299 if (!access_ok(VERIFY_READ, ubuf, ulen))
70300 return -EFAULT;
70301 - return __bitmap_parselist((const char *)ubuf,
70302 + return __bitmap_parselist((const char __force_kernel *)ubuf,
70303 ulen, 1, maskp, nmaskbits);
70304 }
70305 EXPORT_SYMBOL(bitmap_parselist_user);
70306 diff --git a/lib/bug.c b/lib/bug.c
70307 index 1955209..cbbb2ad 100644
70308 --- a/lib/bug.c
70309 +++ b/lib/bug.c
70310 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70311 return BUG_TRAP_TYPE_NONE;
70312
70313 bug = find_bug(bugaddr);
70314 + if (!bug)
70315 + return BUG_TRAP_TYPE_NONE;
70316
70317 file = NULL;
70318 line = 0;
70319 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70320 index a78b7c6..2c73084 100644
70321 --- a/lib/debugobjects.c
70322 +++ b/lib/debugobjects.c
70323 @@ -284,7 +284,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70324 if (limit > 4)
70325 return;
70326
70327 - is_on_stack = object_is_on_stack(addr);
70328 + is_on_stack = object_starts_on_stack(addr);
70329 if (is_on_stack == onstack)
70330 return;
70331
70332 diff --git a/lib/devres.c b/lib/devres.c
70333 index 7c0e953..f642b5c 100644
70334 --- a/lib/devres.c
70335 +++ b/lib/devres.c
70336 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70337 void devm_iounmap(struct device *dev, void __iomem *addr)
70338 {
70339 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70340 - (void *)addr));
70341 + (void __force *)addr));
70342 iounmap(addr);
70343 }
70344 EXPORT_SYMBOL(devm_iounmap);
70345 @@ -141,7 +141,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70346 {
70347 ioport_unmap(addr);
70348 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70349 - devm_ioport_map_match, (void *)addr));
70350 + devm_ioport_map_match, (void __force *)addr));
70351 }
70352 EXPORT_SYMBOL(devm_ioport_unmap);
70353
70354 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70355 index db07bfd..719b5ab 100644
70356 --- a/lib/dma-debug.c
70357 +++ b/lib/dma-debug.c
70358 @@ -870,7 +870,7 @@ out:
70359
70360 static void check_for_stack(struct device *dev, void *addr)
70361 {
70362 - if (object_is_on_stack(addr))
70363 + if (object_starts_on_stack(addr))
70364 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70365 "stack [addr=%p]\n", addr);
70366 }
70367 diff --git a/lib/extable.c b/lib/extable.c
70368 index 4cac81e..63e9b8f 100644
70369 --- a/lib/extable.c
70370 +++ b/lib/extable.c
70371 @@ -13,6 +13,7 @@
70372 #include <linux/init.h>
70373 #include <linux/sort.h>
70374 #include <asm/uaccess.h>
70375 +#include <asm/pgtable.h>
70376
70377 #ifndef ARCH_HAS_SORT_EXTABLE
70378 /*
70379 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
70380 void sort_extable(struct exception_table_entry *start,
70381 struct exception_table_entry *finish)
70382 {
70383 + pax_open_kernel();
70384 sort(start, finish - start, sizeof(struct exception_table_entry),
70385 cmp_ex, NULL);
70386 + pax_close_kernel();
70387 }
70388
70389 #ifdef CONFIG_MODULES
70390 diff --git a/lib/inflate.c b/lib/inflate.c
70391 index 013a761..c28f3fc 100644
70392 --- a/lib/inflate.c
70393 +++ b/lib/inflate.c
70394 @@ -269,7 +269,7 @@ static void free(void *where)
70395 malloc_ptr = free_mem_ptr;
70396 }
70397 #else
70398 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70399 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70400 #define free(a) kfree(a)
70401 #endif
70402
70403 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70404 index bd2bea9..6b3c95e 100644
70405 --- a/lib/is_single_threaded.c
70406 +++ b/lib/is_single_threaded.c
70407 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70408 struct task_struct *p, *t;
70409 bool ret;
70410
70411 + if (!mm)
70412 + return true;
70413 +
70414 if (atomic_read(&task->signal->live) != 1)
70415 return false;
70416
70417 diff --git a/lib/kref.c b/lib/kref.c
70418 index 3efb882..8492f4c 100644
70419 --- a/lib/kref.c
70420 +++ b/lib/kref.c
70421 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
70422 */
70423 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
70424 {
70425 - WARN_ON(release == NULL);
70426 + BUG_ON(release == NULL);
70427 WARN_ON(release == (void (*)(struct kref *))kfree);
70428
70429 if (atomic_dec_and_test(&kref->refcount)) {
70430 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70431 index a2f9da5..3bcadb6 100644
70432 --- a/lib/radix-tree.c
70433 +++ b/lib/radix-tree.c
70434 @@ -80,7 +80,7 @@ struct radix_tree_preload {
70435 int nr;
70436 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
70437 };
70438 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70439 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70440
70441 static inline void *ptr_to_indirect(void *ptr)
70442 {
70443 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70444 index d7222a9..2172edc 100644
70445 --- a/lib/vsprintf.c
70446 +++ b/lib/vsprintf.c
70447 @@ -16,6 +16,9 @@
70448 * - scnprintf and vscnprintf
70449 */
70450
70451 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70452 +#define __INCLUDED_BY_HIDESYM 1
70453 +#endif
70454 #include <stdarg.h>
70455 #include <linux/module.h>
70456 #include <linux/types.h>
70457 @@ -432,7 +435,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70458 char sym[KSYM_SYMBOL_LEN];
70459 if (ext == 'B')
70460 sprint_backtrace(sym, value);
70461 - else if (ext != 'f' && ext != 's')
70462 + else if (ext != 'f' && ext != 's' && ext != 'a')
70463 sprint_symbol(sym, value);
70464 else
70465 kallsyms_lookup(value, NULL, NULL, NULL, sym);
70466 @@ -796,7 +799,11 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
70467 return string(buf, end, uuid, spec);
70468 }
70469
70470 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70471 +int kptr_restrict __read_mostly = 2;
70472 +#else
70473 int kptr_restrict __read_mostly;
70474 +#endif
70475
70476 /*
70477 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70478 @@ -810,6 +817,8 @@ int kptr_restrict __read_mostly;
70479 * - 'S' For symbolic direct pointers with offset
70480 * - 's' For symbolic direct pointers without offset
70481 * - 'B' For backtraced symbolic direct pointers with offset
70482 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70483 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70484 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70485 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70486 * - 'M' For a 6-byte MAC address, it prints the address in the
70487 @@ -854,12 +863,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70488 {
70489 if (!ptr && *fmt != 'K') {
70490 /*
70491 - * Print (null) with the same width as a pointer so it makes
70492 + * Print (nil) with the same width as a pointer so it makes
70493 * tabular output look nice.
70494 */
70495 if (spec.field_width == -1)
70496 spec.field_width = 2 * sizeof(void *);
70497 - return string(buf, end, "(null)", spec);
70498 + return string(buf, end, "(nil)", spec);
70499 }
70500
70501 switch (*fmt) {
70502 @@ -869,6 +878,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70503 /* Fallthrough */
70504 case 'S':
70505 case 's':
70506 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70507 + break;
70508 +#else
70509 + return symbol_string(buf, end, ptr, spec, *fmt);
70510 +#endif
70511 + case 'A':
70512 + case 'a':
70513 case 'B':
70514 return symbol_string(buf, end, ptr, spec, *fmt);
70515 case 'R':
70516 @@ -1627,11 +1643,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70517 typeof(type) value; \
70518 if (sizeof(type) == 8) { \
70519 args = PTR_ALIGN(args, sizeof(u32)); \
70520 - *(u32 *)&value = *(u32 *)args; \
70521 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70522 + *(u32 *)&value = *(const u32 *)args; \
70523 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70524 } else { \
70525 args = PTR_ALIGN(args, sizeof(type)); \
70526 - value = *(typeof(type) *)args; \
70527 + value = *(const typeof(type) *)args; \
70528 } \
70529 args += sizeof(type); \
70530 value; \
70531 @@ -1694,7 +1710,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70532 case FORMAT_TYPE_STR: {
70533 const char *str_arg = args;
70534 args += strlen(str_arg) + 1;
70535 - str = string(str, end, (char *)str_arg, spec);
70536 + str = string(str, end, str_arg, spec);
70537 break;
70538 }
70539
70540 diff --git a/localversion-grsec b/localversion-grsec
70541 new file mode 100644
70542 index 0000000..7cd6065
70543 --- /dev/null
70544 +++ b/localversion-grsec
70545 @@ -0,0 +1 @@
70546 +-grsec
70547 diff --git a/mm/Kconfig b/mm/Kconfig
70548 index f2f1ca1..0645f06 100644
70549 --- a/mm/Kconfig
70550 +++ b/mm/Kconfig
70551 @@ -238,10 +238,10 @@ config KSM
70552 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70553
70554 config DEFAULT_MMAP_MIN_ADDR
70555 - int "Low address space to protect from user allocation"
70556 + int "Low address space to protect from user allocation"
70557 depends on MMU
70558 - default 4096
70559 - help
70560 + default 65536
70561 + help
70562 This is the portion of low virtual memory which should be protected
70563 from userspace allocation. Keeping a user from writing to low pages
70564 can help reduce the impact of kernel NULL pointer bugs.
70565 diff --git a/mm/filemap.c b/mm/filemap.c
70566 index 0eedbf8..b108990 100644
70567 --- a/mm/filemap.c
70568 +++ b/mm/filemap.c
70569 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70570 struct address_space *mapping = file->f_mapping;
70571
70572 if (!mapping->a_ops->readpage)
70573 - return -ENOEXEC;
70574 + return -ENODEV;
70575 file_accessed(file);
70576 vma->vm_ops = &generic_file_vm_ops;
70577 vma->vm_flags |= VM_CAN_NONLINEAR;
70578 @@ -2173,6 +2173,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70579 *pos = i_size_read(inode);
70580
70581 if (limit != RLIM_INFINITY) {
70582 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70583 if (*pos >= limit) {
70584 send_sig(SIGXFSZ, current, 0);
70585 return -EFBIG;
70586 diff --git a/mm/fremap.c b/mm/fremap.c
70587 index b8e0e2d..076e171 100644
70588 --- a/mm/fremap.c
70589 +++ b/mm/fremap.c
70590 @@ -156,6 +156,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70591 retry:
70592 vma = find_vma(mm, start);
70593
70594 +#ifdef CONFIG_PAX_SEGMEXEC
70595 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70596 + goto out;
70597 +#endif
70598 +
70599 /*
70600 * Make sure the vma is shared, that it supports prefaulting,
70601 * and that the remapped range is valid and fully within
70602 diff --git a/mm/highmem.c b/mm/highmem.c
70603 index 5ef672c..d7660f4 100644
70604 --- a/mm/highmem.c
70605 +++ b/mm/highmem.c
70606 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70607 * So no dangers, even with speculative execution.
70608 */
70609 page = pte_page(pkmap_page_table[i]);
70610 + pax_open_kernel();
70611 pte_clear(&init_mm, (unsigned long)page_address(page),
70612 &pkmap_page_table[i]);
70613 -
70614 + pax_close_kernel();
70615 set_page_address(page, NULL);
70616 need_flush = 1;
70617 }
70618 @@ -186,9 +187,11 @@ start:
70619 }
70620 }
70621 vaddr = PKMAP_ADDR(last_pkmap_nr);
70622 +
70623 + pax_open_kernel();
70624 set_pte_at(&init_mm, vaddr,
70625 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70626 -
70627 + pax_close_kernel();
70628 pkmap_count[last_pkmap_nr] = 1;
70629 set_page_address(page, (void *)vaddr);
70630
70631 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70632 index d819d93..468e18f 100644
70633 --- a/mm/huge_memory.c
70634 +++ b/mm/huge_memory.c
70635 @@ -702,7 +702,7 @@ out:
70636 * run pte_offset_map on the pmd, if an huge pmd could
70637 * materialize from under us from a different thread.
70638 */
70639 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70640 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70641 return VM_FAULT_OOM;
70642 /* if an huge pmd materialized from under us just retry later */
70643 if (unlikely(pmd_trans_huge(*pmd)))
70644 @@ -829,7 +829,7 @@ static int do_huge_pmd_wp_page_fallback(struct mm_struct *mm,
70645
70646 for (i = 0; i < HPAGE_PMD_NR; i++) {
70647 copy_user_highpage(pages[i], page + i,
70648 - haddr + PAGE_SHIFT*i, vma);
70649 + haddr + PAGE_SIZE*i, vma);
70650 __SetPageUptodate(pages[i]);
70651 cond_resched();
70652 }
70653 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70654 index 2316840..b418671 100644
70655 --- a/mm/hugetlb.c
70656 +++ b/mm/hugetlb.c
70657 @@ -2347,6 +2347,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70658 return 1;
70659 }
70660
70661 +#ifdef CONFIG_PAX_SEGMEXEC
70662 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70663 +{
70664 + struct mm_struct *mm = vma->vm_mm;
70665 + struct vm_area_struct *vma_m;
70666 + unsigned long address_m;
70667 + pte_t *ptep_m;
70668 +
70669 + vma_m = pax_find_mirror_vma(vma);
70670 + if (!vma_m)
70671 + return;
70672 +
70673 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70674 + address_m = address + SEGMEXEC_TASK_SIZE;
70675 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70676 + get_page(page_m);
70677 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
70678 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70679 +}
70680 +#endif
70681 +
70682 /*
70683 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70684 */
70685 @@ -2450,6 +2471,11 @@ retry_avoidcopy:
70686 make_huge_pte(vma, new_page, 1));
70687 page_remove_rmap(old_page);
70688 hugepage_add_new_anon_rmap(new_page, vma, address);
70689 +
70690 +#ifdef CONFIG_PAX_SEGMEXEC
70691 + pax_mirror_huge_pte(vma, address, new_page);
70692 +#endif
70693 +
70694 /* Make the old page be freed below */
70695 new_page = old_page;
70696 mmu_notifier_invalidate_range_end(mm,
70697 @@ -2601,6 +2627,10 @@ retry:
70698 && (vma->vm_flags & VM_SHARED)));
70699 set_huge_pte_at(mm, address, ptep, new_pte);
70700
70701 +#ifdef CONFIG_PAX_SEGMEXEC
70702 + pax_mirror_huge_pte(vma, address, page);
70703 +#endif
70704 +
70705 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70706 /* Optimization, do the COW without a second fault */
70707 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70708 @@ -2630,6 +2660,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70709 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70710 struct hstate *h = hstate_vma(vma);
70711
70712 +#ifdef CONFIG_PAX_SEGMEXEC
70713 + struct vm_area_struct *vma_m;
70714 +#endif
70715 +
70716 ptep = huge_pte_offset(mm, address);
70717 if (ptep) {
70718 entry = huge_ptep_get(ptep);
70719 @@ -2641,6 +2675,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70720 VM_FAULT_SET_HINDEX(h - hstates);
70721 }
70722
70723 +#ifdef CONFIG_PAX_SEGMEXEC
70724 + vma_m = pax_find_mirror_vma(vma);
70725 + if (vma_m) {
70726 + unsigned long address_m;
70727 +
70728 + if (vma->vm_start > vma_m->vm_start) {
70729 + address_m = address;
70730 + address -= SEGMEXEC_TASK_SIZE;
70731 + vma = vma_m;
70732 + h = hstate_vma(vma);
70733 + } else
70734 + address_m = address + SEGMEXEC_TASK_SIZE;
70735 +
70736 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70737 + return VM_FAULT_OOM;
70738 + address_m &= HPAGE_MASK;
70739 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70740 + }
70741 +#endif
70742 +
70743 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70744 if (!ptep)
70745 return VM_FAULT_OOM;
70746 diff --git a/mm/internal.h b/mm/internal.h
70747 index 2189af4..f2ca332 100644
70748 --- a/mm/internal.h
70749 +++ b/mm/internal.h
70750 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70751 * in mm/page_alloc.c
70752 */
70753 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70754 +extern void free_compound_page(struct page *page);
70755 extern void prep_compound_page(struct page *page, unsigned long order);
70756 #ifdef CONFIG_MEMORY_FAILURE
70757 extern bool is_free_buddy_page(struct page *page);
70758 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70759 index d6880f5..ed77913 100644
70760 --- a/mm/kmemleak.c
70761 +++ b/mm/kmemleak.c
70762 @@ -357,7 +357,7 @@ static void print_unreferenced(struct seq_file *seq,
70763
70764 for (i = 0; i < object->trace_len; i++) {
70765 void *ptr = (void *)object->trace[i];
70766 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70767 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70768 }
70769 }
70770
70771 diff --git a/mm/maccess.c b/mm/maccess.c
70772 index 4cee182..e00511d 100644
70773 --- a/mm/maccess.c
70774 +++ b/mm/maccess.c
70775 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70776 set_fs(KERNEL_DS);
70777 pagefault_disable();
70778 ret = __copy_from_user_inatomic(dst,
70779 - (__force const void __user *)src, size);
70780 + (const void __force_user *)src, size);
70781 pagefault_enable();
70782 set_fs(old_fs);
70783
70784 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70785
70786 set_fs(KERNEL_DS);
70787 pagefault_disable();
70788 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70789 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70790 pagefault_enable();
70791 set_fs(old_fs);
70792
70793 diff --git a/mm/madvise.c b/mm/madvise.c
70794 index 74bf193..feb6fd3 100644
70795 --- a/mm/madvise.c
70796 +++ b/mm/madvise.c
70797 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70798 pgoff_t pgoff;
70799 unsigned long new_flags = vma->vm_flags;
70800
70801 +#ifdef CONFIG_PAX_SEGMEXEC
70802 + struct vm_area_struct *vma_m;
70803 +#endif
70804 +
70805 switch (behavior) {
70806 case MADV_NORMAL:
70807 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70808 @@ -110,6 +114,13 @@ success:
70809 /*
70810 * vm_flags is protected by the mmap_sem held in write mode.
70811 */
70812 +
70813 +#ifdef CONFIG_PAX_SEGMEXEC
70814 + vma_m = pax_find_mirror_vma(vma);
70815 + if (vma_m)
70816 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70817 +#endif
70818 +
70819 vma->vm_flags = new_flags;
70820
70821 out:
70822 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70823 struct vm_area_struct ** prev,
70824 unsigned long start, unsigned long end)
70825 {
70826 +
70827 +#ifdef CONFIG_PAX_SEGMEXEC
70828 + struct vm_area_struct *vma_m;
70829 +#endif
70830 +
70831 *prev = vma;
70832 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70833 return -EINVAL;
70834 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70835 zap_page_range(vma, start, end - start, &details);
70836 } else
70837 zap_page_range(vma, start, end - start, NULL);
70838 +
70839 +#ifdef CONFIG_PAX_SEGMEXEC
70840 + vma_m = pax_find_mirror_vma(vma);
70841 + if (vma_m) {
70842 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70843 + struct zap_details details = {
70844 + .nonlinear_vma = vma_m,
70845 + .last_index = ULONG_MAX,
70846 + };
70847 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70848 + } else
70849 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70850 + }
70851 +#endif
70852 +
70853 return 0;
70854 }
70855
70856 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70857 if (end < start)
70858 goto out;
70859
70860 +#ifdef CONFIG_PAX_SEGMEXEC
70861 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70862 + if (end > SEGMEXEC_TASK_SIZE)
70863 + goto out;
70864 + } else
70865 +#endif
70866 +
70867 + if (end > TASK_SIZE)
70868 + goto out;
70869 +
70870 error = 0;
70871 if (end == start)
70872 goto out;
70873 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70874 index 2b43ba0..fc09657 100644
70875 --- a/mm/memory-failure.c
70876 +++ b/mm/memory-failure.c
70877 @@ -60,7 +60,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70878
70879 int sysctl_memory_failure_recovery __read_mostly = 1;
70880
70881 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70882 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70883
70884 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70885
70886 @@ -201,7 +201,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
70887 si.si_signo = SIGBUS;
70888 si.si_errno = 0;
70889 si.si_code = BUS_MCEERR_AO;
70890 - si.si_addr = (void *)addr;
70891 + si.si_addr = (void __user *)addr;
70892 #ifdef __ARCH_SI_TRAPNO
70893 si.si_trapno = trapno;
70894 #endif
70895 @@ -1009,7 +1009,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70896 }
70897
70898 nr_pages = 1 << compound_trans_order(hpage);
70899 - atomic_long_add(nr_pages, &mce_bad_pages);
70900 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70901
70902 /*
70903 * We need/can do nothing about count=0 pages.
70904 @@ -1039,7 +1039,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70905 if (!PageHWPoison(hpage)
70906 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70907 || (p != hpage && TestSetPageHWPoison(hpage))) {
70908 - atomic_long_sub(nr_pages, &mce_bad_pages);
70909 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70910 return 0;
70911 }
70912 set_page_hwpoison_huge_page(hpage);
70913 @@ -1097,7 +1097,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70914 }
70915 if (hwpoison_filter(p)) {
70916 if (TestClearPageHWPoison(p))
70917 - atomic_long_sub(nr_pages, &mce_bad_pages);
70918 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70919 unlock_page(hpage);
70920 put_page(hpage);
70921 return 0;
70922 @@ -1314,7 +1314,7 @@ int unpoison_memory(unsigned long pfn)
70923 return 0;
70924 }
70925 if (TestClearPageHWPoison(p))
70926 - atomic_long_sub(nr_pages, &mce_bad_pages);
70927 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70928 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70929 return 0;
70930 }
70931 @@ -1328,7 +1328,7 @@ int unpoison_memory(unsigned long pfn)
70932 */
70933 if (TestClearPageHWPoison(page)) {
70934 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70935 - atomic_long_sub(nr_pages, &mce_bad_pages);
70936 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70937 freeit = 1;
70938 if (PageHuge(page))
70939 clear_page_hwpoison_huge_page(page);
70940 @@ -1441,7 +1441,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70941 }
70942 done:
70943 if (!PageHWPoison(hpage))
70944 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70945 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70946 set_page_hwpoison_huge_page(hpage);
70947 dequeue_hwpoisoned_huge_page(hpage);
70948 /* keep elevated page count for bad page */
70949 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
70950 return ret;
70951
70952 done:
70953 - atomic_long_add(1, &mce_bad_pages);
70954 + atomic_long_add_unchecked(1, &mce_bad_pages);
70955 SetPageHWPoison(page);
70956 /* keep elevated page count for bad page */
70957 return ret;
70958 diff --git a/mm/memory.c b/mm/memory.c
70959 index b2b8731..6080174 100644
70960 --- a/mm/memory.c
70961 +++ b/mm/memory.c
70962 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
70963 return;
70964
70965 pmd = pmd_offset(pud, start);
70966 +
70967 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
70968 pud_clear(pud);
70969 pmd_free_tlb(tlb, pmd, start);
70970 +#endif
70971 +
70972 }
70973
70974 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70975 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70976 if (end - 1 > ceiling - 1)
70977 return;
70978
70979 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
70980 pud = pud_offset(pgd, start);
70981 pgd_clear(pgd);
70982 pud_free_tlb(tlb, pud, start);
70983 +#endif
70984 +
70985 }
70986
70987 /*
70988 @@ -1566,12 +1573,6 @@ no_page_table:
70989 return page;
70990 }
70991
70992 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
70993 -{
70994 - return stack_guard_page_start(vma, addr) ||
70995 - stack_guard_page_end(vma, addr+PAGE_SIZE);
70996 -}
70997 -
70998 /**
70999 * __get_user_pages() - pin user pages in memory
71000 * @tsk: task_struct of target task
71001 @@ -1644,10 +1645,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71002 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71003 i = 0;
71004
71005 - do {
71006 + while (nr_pages) {
71007 struct vm_area_struct *vma;
71008
71009 - vma = find_extend_vma(mm, start);
71010 + vma = find_vma(mm, start);
71011 if (!vma && in_gate_area(mm, start)) {
71012 unsigned long pg = start & PAGE_MASK;
71013 pgd_t *pgd;
71014 @@ -1695,7 +1696,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71015 goto next_page;
71016 }
71017
71018 - if (!vma ||
71019 + if (!vma || start < vma->vm_start ||
71020 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71021 !(vm_flags & vma->vm_flags))
71022 return i ? : -EFAULT;
71023 @@ -1722,11 +1723,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71024 int ret;
71025 unsigned int fault_flags = 0;
71026
71027 - /* For mlock, just skip the stack guard page. */
71028 - if (foll_flags & FOLL_MLOCK) {
71029 - if (stack_guard_page(vma, start))
71030 - goto next_page;
71031 - }
71032 if (foll_flags & FOLL_WRITE)
71033 fault_flags |= FAULT_FLAG_WRITE;
71034 if (nonblocking)
71035 @@ -1800,7 +1796,7 @@ next_page:
71036 start += PAGE_SIZE;
71037 nr_pages--;
71038 } while (nr_pages && start < vma->vm_end);
71039 - } while (nr_pages);
71040 + }
71041 return i;
71042 }
71043 EXPORT_SYMBOL(__get_user_pages);
71044 @@ -2007,6 +2003,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71045 page_add_file_rmap(page);
71046 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71047
71048 +#ifdef CONFIG_PAX_SEGMEXEC
71049 + pax_mirror_file_pte(vma, addr, page, ptl);
71050 +#endif
71051 +
71052 retval = 0;
71053 pte_unmap_unlock(pte, ptl);
71054 return retval;
71055 @@ -2041,10 +2041,22 @@ out:
71056 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71057 struct page *page)
71058 {
71059 +
71060 +#ifdef CONFIG_PAX_SEGMEXEC
71061 + struct vm_area_struct *vma_m;
71062 +#endif
71063 +
71064 if (addr < vma->vm_start || addr >= vma->vm_end)
71065 return -EFAULT;
71066 if (!page_count(page))
71067 return -EINVAL;
71068 +
71069 +#ifdef CONFIG_PAX_SEGMEXEC
71070 + vma_m = pax_find_mirror_vma(vma);
71071 + if (vma_m)
71072 + vma_m->vm_flags |= VM_INSERTPAGE;
71073 +#endif
71074 +
71075 vma->vm_flags |= VM_INSERTPAGE;
71076 return insert_page(vma, addr, page, vma->vm_page_prot);
71077 }
71078 @@ -2130,6 +2142,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71079 unsigned long pfn)
71080 {
71081 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71082 + BUG_ON(vma->vm_mirror);
71083
71084 if (addr < vma->vm_start || addr >= vma->vm_end)
71085 return -EFAULT;
71086 @@ -2445,6 +2458,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71087 copy_user_highpage(dst, src, va, vma);
71088 }
71089
71090 +#ifdef CONFIG_PAX_SEGMEXEC
71091 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71092 +{
71093 + struct mm_struct *mm = vma->vm_mm;
71094 + spinlock_t *ptl;
71095 + pte_t *pte, entry;
71096 +
71097 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71098 + entry = *pte;
71099 + if (!pte_present(entry)) {
71100 + if (!pte_none(entry)) {
71101 + BUG_ON(pte_file(entry));
71102 + free_swap_and_cache(pte_to_swp_entry(entry));
71103 + pte_clear_not_present_full(mm, address, pte, 0);
71104 + }
71105 + } else {
71106 + struct page *page;
71107 +
71108 + flush_cache_page(vma, address, pte_pfn(entry));
71109 + entry = ptep_clear_flush(vma, address, pte);
71110 + BUG_ON(pte_dirty(entry));
71111 + page = vm_normal_page(vma, address, entry);
71112 + if (page) {
71113 + update_hiwater_rss(mm);
71114 + if (PageAnon(page))
71115 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71116 + else
71117 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71118 + page_remove_rmap(page);
71119 + page_cache_release(page);
71120 + }
71121 + }
71122 + pte_unmap_unlock(pte, ptl);
71123 +}
71124 +
71125 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71126 + *
71127 + * the ptl of the lower mapped page is held on entry and is not released on exit
71128 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71129 + */
71130 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71131 +{
71132 + struct mm_struct *mm = vma->vm_mm;
71133 + unsigned long address_m;
71134 + spinlock_t *ptl_m;
71135 + struct vm_area_struct *vma_m;
71136 + pmd_t *pmd_m;
71137 + pte_t *pte_m, entry_m;
71138 +
71139 + BUG_ON(!page_m || !PageAnon(page_m));
71140 +
71141 + vma_m = pax_find_mirror_vma(vma);
71142 + if (!vma_m)
71143 + return;
71144 +
71145 + BUG_ON(!PageLocked(page_m));
71146 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71147 + address_m = address + SEGMEXEC_TASK_SIZE;
71148 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71149 + pte_m = pte_offset_map(pmd_m, address_m);
71150 + ptl_m = pte_lockptr(mm, pmd_m);
71151 + if (ptl != ptl_m) {
71152 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71153 + if (!pte_none(*pte_m))
71154 + goto out;
71155 + }
71156 +
71157 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71158 + page_cache_get(page_m);
71159 + page_add_anon_rmap(page_m, vma_m, address_m);
71160 + inc_mm_counter_fast(mm, MM_ANONPAGES);
71161 + set_pte_at(mm, address_m, pte_m, entry_m);
71162 + update_mmu_cache(vma_m, address_m, entry_m);
71163 +out:
71164 + if (ptl != ptl_m)
71165 + spin_unlock(ptl_m);
71166 + pte_unmap(pte_m);
71167 + unlock_page(page_m);
71168 +}
71169 +
71170 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71171 +{
71172 + struct mm_struct *mm = vma->vm_mm;
71173 + unsigned long address_m;
71174 + spinlock_t *ptl_m;
71175 + struct vm_area_struct *vma_m;
71176 + pmd_t *pmd_m;
71177 + pte_t *pte_m, entry_m;
71178 +
71179 + BUG_ON(!page_m || PageAnon(page_m));
71180 +
71181 + vma_m = pax_find_mirror_vma(vma);
71182 + if (!vma_m)
71183 + return;
71184 +
71185 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71186 + address_m = address + SEGMEXEC_TASK_SIZE;
71187 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71188 + pte_m = pte_offset_map(pmd_m, address_m);
71189 + ptl_m = pte_lockptr(mm, pmd_m);
71190 + if (ptl != ptl_m) {
71191 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71192 + if (!pte_none(*pte_m))
71193 + goto out;
71194 + }
71195 +
71196 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71197 + page_cache_get(page_m);
71198 + page_add_file_rmap(page_m);
71199 + inc_mm_counter_fast(mm, MM_FILEPAGES);
71200 + set_pte_at(mm, address_m, pte_m, entry_m);
71201 + update_mmu_cache(vma_m, address_m, entry_m);
71202 +out:
71203 + if (ptl != ptl_m)
71204 + spin_unlock(ptl_m);
71205 + pte_unmap(pte_m);
71206 +}
71207 +
71208 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71209 +{
71210 + struct mm_struct *mm = vma->vm_mm;
71211 + unsigned long address_m;
71212 + spinlock_t *ptl_m;
71213 + struct vm_area_struct *vma_m;
71214 + pmd_t *pmd_m;
71215 + pte_t *pte_m, entry_m;
71216 +
71217 + vma_m = pax_find_mirror_vma(vma);
71218 + if (!vma_m)
71219 + return;
71220 +
71221 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71222 + address_m = address + SEGMEXEC_TASK_SIZE;
71223 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71224 + pte_m = pte_offset_map(pmd_m, address_m);
71225 + ptl_m = pte_lockptr(mm, pmd_m);
71226 + if (ptl != ptl_m) {
71227 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71228 + if (!pte_none(*pte_m))
71229 + goto out;
71230 + }
71231 +
71232 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71233 + set_pte_at(mm, address_m, pte_m, entry_m);
71234 +out:
71235 + if (ptl != ptl_m)
71236 + spin_unlock(ptl_m);
71237 + pte_unmap(pte_m);
71238 +}
71239 +
71240 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71241 +{
71242 + struct page *page_m;
71243 + pte_t entry;
71244 +
71245 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71246 + goto out;
71247 +
71248 + entry = *pte;
71249 + page_m = vm_normal_page(vma, address, entry);
71250 + if (!page_m)
71251 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71252 + else if (PageAnon(page_m)) {
71253 + if (pax_find_mirror_vma(vma)) {
71254 + pte_unmap_unlock(pte, ptl);
71255 + lock_page(page_m);
71256 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71257 + if (pte_same(entry, *pte))
71258 + pax_mirror_anon_pte(vma, address, page_m, ptl);
71259 + else
71260 + unlock_page(page_m);
71261 + }
71262 + } else
71263 + pax_mirror_file_pte(vma, address, page_m, ptl);
71264 +
71265 +out:
71266 + pte_unmap_unlock(pte, ptl);
71267 +}
71268 +#endif
71269 +
71270 /*
71271 * This routine handles present pages, when users try to write
71272 * to a shared page. It is done by copying the page to a new address
71273 @@ -2656,6 +2849,12 @@ gotten:
71274 */
71275 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71276 if (likely(pte_same(*page_table, orig_pte))) {
71277 +
71278 +#ifdef CONFIG_PAX_SEGMEXEC
71279 + if (pax_find_mirror_vma(vma))
71280 + BUG_ON(!trylock_page(new_page));
71281 +#endif
71282 +
71283 if (old_page) {
71284 if (!PageAnon(old_page)) {
71285 dec_mm_counter_fast(mm, MM_FILEPAGES);
71286 @@ -2707,6 +2906,10 @@ gotten:
71287 page_remove_rmap(old_page);
71288 }
71289
71290 +#ifdef CONFIG_PAX_SEGMEXEC
71291 + pax_mirror_anon_pte(vma, address, new_page, ptl);
71292 +#endif
71293 +
71294 /* Free the old page.. */
71295 new_page = old_page;
71296 ret |= VM_FAULT_WRITE;
71297 @@ -2986,6 +3189,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71298 swap_free(entry);
71299 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71300 try_to_free_swap(page);
71301 +
71302 +#ifdef CONFIG_PAX_SEGMEXEC
71303 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71304 +#endif
71305 +
71306 unlock_page(page);
71307 if (swapcache) {
71308 /*
71309 @@ -3009,6 +3217,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71310
71311 /* No need to invalidate - it was non-present before */
71312 update_mmu_cache(vma, address, page_table);
71313 +
71314 +#ifdef CONFIG_PAX_SEGMEXEC
71315 + pax_mirror_anon_pte(vma, address, page, ptl);
71316 +#endif
71317 +
71318 unlock:
71319 pte_unmap_unlock(page_table, ptl);
71320 out:
71321 @@ -3028,40 +3241,6 @@ out_release:
71322 }
71323
71324 /*
71325 - * This is like a special single-page "expand_{down|up}wards()",
71326 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
71327 - * doesn't hit another vma.
71328 - */
71329 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71330 -{
71331 - address &= PAGE_MASK;
71332 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71333 - struct vm_area_struct *prev = vma->vm_prev;
71334 -
71335 - /*
71336 - * Is there a mapping abutting this one below?
71337 - *
71338 - * That's only ok if it's the same stack mapping
71339 - * that has gotten split..
71340 - */
71341 - if (prev && prev->vm_end == address)
71342 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71343 -
71344 - expand_downwards(vma, address - PAGE_SIZE);
71345 - }
71346 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71347 - struct vm_area_struct *next = vma->vm_next;
71348 -
71349 - /* As VM_GROWSDOWN but s/below/above/ */
71350 - if (next && next->vm_start == address + PAGE_SIZE)
71351 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71352 -
71353 - expand_upwards(vma, address + PAGE_SIZE);
71354 - }
71355 - return 0;
71356 -}
71357 -
71358 -/*
71359 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71360 * but allow concurrent faults), and pte mapped but not yet locked.
71361 * We return with mmap_sem still held, but pte unmapped and unlocked.
71362 @@ -3070,27 +3249,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71363 unsigned long address, pte_t *page_table, pmd_t *pmd,
71364 unsigned int flags)
71365 {
71366 - struct page *page;
71367 + struct page *page = NULL;
71368 spinlock_t *ptl;
71369 pte_t entry;
71370
71371 - pte_unmap(page_table);
71372 -
71373 - /* Check if we need to add a guard page to the stack */
71374 - if (check_stack_guard_page(vma, address) < 0)
71375 - return VM_FAULT_SIGBUS;
71376 -
71377 - /* Use the zero-page for reads */
71378 if (!(flags & FAULT_FLAG_WRITE)) {
71379 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71380 vma->vm_page_prot));
71381 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71382 + ptl = pte_lockptr(mm, pmd);
71383 + spin_lock(ptl);
71384 if (!pte_none(*page_table))
71385 goto unlock;
71386 goto setpte;
71387 }
71388
71389 /* Allocate our own private page. */
71390 + pte_unmap(page_table);
71391 +
71392 if (unlikely(anon_vma_prepare(vma)))
71393 goto oom;
71394 page = alloc_zeroed_user_highpage_movable(vma, address);
71395 @@ -3109,6 +3284,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71396 if (!pte_none(*page_table))
71397 goto release;
71398
71399 +#ifdef CONFIG_PAX_SEGMEXEC
71400 + if (pax_find_mirror_vma(vma))
71401 + BUG_ON(!trylock_page(page));
71402 +#endif
71403 +
71404 inc_mm_counter_fast(mm, MM_ANONPAGES);
71405 page_add_new_anon_rmap(page, vma, address);
71406 setpte:
71407 @@ -3116,6 +3296,12 @@ setpte:
71408
71409 /* No need to invalidate - it was non-present before */
71410 update_mmu_cache(vma, address, page_table);
71411 +
71412 +#ifdef CONFIG_PAX_SEGMEXEC
71413 + if (page)
71414 + pax_mirror_anon_pte(vma, address, page, ptl);
71415 +#endif
71416 +
71417 unlock:
71418 pte_unmap_unlock(page_table, ptl);
71419 return 0;
71420 @@ -3259,6 +3445,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71421 */
71422 /* Only go through if we didn't race with anybody else... */
71423 if (likely(pte_same(*page_table, orig_pte))) {
71424 +
71425 +#ifdef CONFIG_PAX_SEGMEXEC
71426 + if (anon && pax_find_mirror_vma(vma))
71427 + BUG_ON(!trylock_page(page));
71428 +#endif
71429 +
71430 flush_icache_page(vma, page);
71431 entry = mk_pte(page, vma->vm_page_prot);
71432 if (flags & FAULT_FLAG_WRITE)
71433 @@ -3278,6 +3470,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71434
71435 /* no need to invalidate: a not-present page won't be cached */
71436 update_mmu_cache(vma, address, page_table);
71437 +
71438 +#ifdef CONFIG_PAX_SEGMEXEC
71439 + if (anon)
71440 + pax_mirror_anon_pte(vma, address, page, ptl);
71441 + else
71442 + pax_mirror_file_pte(vma, address, page, ptl);
71443 +#endif
71444 +
71445 } else {
71446 if (cow_page)
71447 mem_cgroup_uncharge_page(cow_page);
71448 @@ -3431,6 +3631,12 @@ int handle_pte_fault(struct mm_struct *mm,
71449 if (flags & FAULT_FLAG_WRITE)
71450 flush_tlb_fix_spurious_fault(vma, address);
71451 }
71452 +
71453 +#ifdef CONFIG_PAX_SEGMEXEC
71454 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71455 + return 0;
71456 +#endif
71457 +
71458 unlock:
71459 pte_unmap_unlock(pte, ptl);
71460 return 0;
71461 @@ -3447,6 +3653,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71462 pmd_t *pmd;
71463 pte_t *pte;
71464
71465 +#ifdef CONFIG_PAX_SEGMEXEC
71466 + struct vm_area_struct *vma_m;
71467 +#endif
71468 +
71469 __set_current_state(TASK_RUNNING);
71470
71471 count_vm_event(PGFAULT);
71472 @@ -3458,6 +3668,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71473 if (unlikely(is_vm_hugetlb_page(vma)))
71474 return hugetlb_fault(mm, vma, address, flags);
71475
71476 +#ifdef CONFIG_PAX_SEGMEXEC
71477 + vma_m = pax_find_mirror_vma(vma);
71478 + if (vma_m) {
71479 + unsigned long address_m;
71480 + pgd_t *pgd_m;
71481 + pud_t *pud_m;
71482 + pmd_t *pmd_m;
71483 +
71484 + if (vma->vm_start > vma_m->vm_start) {
71485 + address_m = address;
71486 + address -= SEGMEXEC_TASK_SIZE;
71487 + vma = vma_m;
71488 + } else
71489 + address_m = address + SEGMEXEC_TASK_SIZE;
71490 +
71491 + pgd_m = pgd_offset(mm, address_m);
71492 + pud_m = pud_alloc(mm, pgd_m, address_m);
71493 + if (!pud_m)
71494 + return VM_FAULT_OOM;
71495 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71496 + if (!pmd_m)
71497 + return VM_FAULT_OOM;
71498 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71499 + return VM_FAULT_OOM;
71500 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71501 + }
71502 +#endif
71503 +
71504 pgd = pgd_offset(mm, address);
71505 pud = pud_alloc(mm, pgd, address);
71506 if (!pud)
71507 @@ -3487,7 +3725,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71508 * run pte_offset_map on the pmd, if an huge pmd could
71509 * materialize from under us from a different thread.
71510 */
71511 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71512 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71513 return VM_FAULT_OOM;
71514 /* if an huge pmd materialized from under us just retry later */
71515 if (unlikely(pmd_trans_huge(*pmd)))
71516 @@ -3591,7 +3829,7 @@ static int __init gate_vma_init(void)
71517 gate_vma.vm_start = FIXADDR_USER_START;
71518 gate_vma.vm_end = FIXADDR_USER_END;
71519 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71520 - gate_vma.vm_page_prot = __P101;
71521 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71522 /*
71523 * Make sure the vDSO gets into every core dump.
71524 * Dumping its contents makes post-mortem fully interpretable later
71525 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71526 index 2775fd0..f2b1c49 100644
71527 --- a/mm/mempolicy.c
71528 +++ b/mm/mempolicy.c
71529 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71530 unsigned long vmstart;
71531 unsigned long vmend;
71532
71533 +#ifdef CONFIG_PAX_SEGMEXEC
71534 + struct vm_area_struct *vma_m;
71535 +#endif
71536 +
71537 vma = find_vma_prev(mm, start, &prev);
71538 if (!vma || vma->vm_start > start)
71539 return -EFAULT;
71540 @@ -678,6 +682,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71541 err = policy_vma(vma, new_pol);
71542 if (err)
71543 goto out;
71544 +
71545 +#ifdef CONFIG_PAX_SEGMEXEC
71546 + vma_m = pax_find_mirror_vma(vma);
71547 + if (vma_m) {
71548 + err = policy_vma(vma_m, new_pol);
71549 + if (err)
71550 + goto out;
71551 + }
71552 +#endif
71553 +
71554 }
71555
71556 out:
71557 @@ -1111,6 +1125,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71558
71559 if (end < start)
71560 return -EINVAL;
71561 +
71562 +#ifdef CONFIG_PAX_SEGMEXEC
71563 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71564 + if (end > SEGMEXEC_TASK_SIZE)
71565 + return -EINVAL;
71566 + } else
71567 +#endif
71568 +
71569 + if (end > TASK_SIZE)
71570 + return -EINVAL;
71571 +
71572 if (end == start)
71573 return 0;
71574
71575 @@ -1329,6 +1354,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71576 if (!mm)
71577 goto out;
71578
71579 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71580 + if (mm != current->mm &&
71581 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71582 + err = -EPERM;
71583 + goto out;
71584 + }
71585 +#endif
71586 +
71587 /*
71588 * Check if this process has the right to modify the specified
71589 * process. The right exists if the process has administrative
71590 @@ -1338,8 +1371,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71591 rcu_read_lock();
71592 tcred = __task_cred(task);
71593 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71594 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71595 - !capable(CAP_SYS_NICE)) {
71596 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71597 rcu_read_unlock();
71598 err = -EPERM;
71599 goto out;
71600 diff --git a/mm/migrate.c b/mm/migrate.c
71601 index 14d0a6a..0360908 100644
71602 --- a/mm/migrate.c
71603 +++ b/mm/migrate.c
71604 @@ -866,9 +866,9 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
71605
71606 if (anon_vma)
71607 put_anon_vma(anon_vma);
71608 -out:
71609 unlock_page(hpage);
71610
71611 +out:
71612 if (rc != -EAGAIN) {
71613 list_del(&hpage->lru);
71614 put_page(hpage);
71615 @@ -1124,6 +1124,8 @@ static int do_pages_move(struct mm_struct *mm, struct task_struct *task,
71616 unsigned long chunk_start;
71617 int err;
71618
71619 + pax_track_stack();
71620 +
71621 task_nodes = cpuset_mems_allowed(task);
71622
71623 err = -ENOMEM;
71624 @@ -1308,6 +1310,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71625 if (!mm)
71626 return -EINVAL;
71627
71628 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71629 + if (mm != current->mm &&
71630 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71631 + err = -EPERM;
71632 + goto out;
71633 + }
71634 +#endif
71635 +
71636 /*
71637 * Check if this process has the right to modify the specified
71638 * process. The right exists if the process has administrative
71639 @@ -1317,8 +1327,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71640 rcu_read_lock();
71641 tcred = __task_cred(task);
71642 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71643 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71644 - !capable(CAP_SYS_NICE)) {
71645 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71646 rcu_read_unlock();
71647 err = -EPERM;
71648 goto out;
71649 diff --git a/mm/mlock.c b/mm/mlock.c
71650 index 048260c..57f4a4e 100644
71651 --- a/mm/mlock.c
71652 +++ b/mm/mlock.c
71653 @@ -13,6 +13,7 @@
71654 #include <linux/pagemap.h>
71655 #include <linux/mempolicy.h>
71656 #include <linux/syscalls.h>
71657 +#include <linux/security.h>
71658 #include <linux/sched.h>
71659 #include <linux/module.h>
71660 #include <linux/rmap.h>
71661 @@ -377,6 +378,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71662 return -EINVAL;
71663 if (end == start)
71664 return 0;
71665 + if (end > TASK_SIZE)
71666 + return -EINVAL;
71667 +
71668 vma = find_vma_prev(current->mm, start, &prev);
71669 if (!vma || vma->vm_start > start)
71670 return -ENOMEM;
71671 @@ -387,6 +391,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71672 for (nstart = start ; ; ) {
71673 vm_flags_t newflags;
71674
71675 +#ifdef CONFIG_PAX_SEGMEXEC
71676 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71677 + break;
71678 +#endif
71679 +
71680 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71681
71682 newflags = vma->vm_flags | VM_LOCKED;
71683 @@ -492,6 +501,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71684 lock_limit >>= PAGE_SHIFT;
71685
71686 /* check against resource limits */
71687 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71688 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71689 error = do_mlock(start, len, 1);
71690 up_write(&current->mm->mmap_sem);
71691 @@ -515,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71692 static int do_mlockall(int flags)
71693 {
71694 struct vm_area_struct * vma, * prev = NULL;
71695 - unsigned int def_flags = 0;
71696
71697 if (flags & MCL_FUTURE)
71698 - def_flags = VM_LOCKED;
71699 - current->mm->def_flags = def_flags;
71700 + current->mm->def_flags |= VM_LOCKED;
71701 + else
71702 + current->mm->def_flags &= ~VM_LOCKED;
71703 if (flags == MCL_FUTURE)
71704 goto out;
71705
71706 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71707 vm_flags_t newflags;
71708
71709 +#ifdef CONFIG_PAX_SEGMEXEC
71710 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71711 + break;
71712 +#endif
71713 +
71714 + BUG_ON(vma->vm_end > TASK_SIZE);
71715 newflags = vma->vm_flags | VM_LOCKED;
71716 if (!(flags & MCL_CURRENT))
71717 newflags &= ~VM_LOCKED;
71718 @@ -557,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71719 lock_limit >>= PAGE_SHIFT;
71720
71721 ret = -ENOMEM;
71722 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71723 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71724 capable(CAP_IPC_LOCK))
71725 ret = do_mlockall(flags);
71726 diff --git a/mm/mmap.c b/mm/mmap.c
71727 index a65efd4..17d61ff 100644
71728 --- a/mm/mmap.c
71729 +++ b/mm/mmap.c
71730 @@ -46,6 +46,16 @@
71731 #define arch_rebalance_pgtables(addr, len) (addr)
71732 #endif
71733
71734 +static inline void verify_mm_writelocked(struct mm_struct *mm)
71735 +{
71736 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71737 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71738 + up_read(&mm->mmap_sem);
71739 + BUG();
71740 + }
71741 +#endif
71742 +}
71743 +
71744 static void unmap_region(struct mm_struct *mm,
71745 struct vm_area_struct *vma, struct vm_area_struct *prev,
71746 unsigned long start, unsigned long end);
71747 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
71748 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71749 *
71750 */
71751 -pgprot_t protection_map[16] = {
71752 +pgprot_t protection_map[16] __read_only = {
71753 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71754 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71755 };
71756
71757 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
71758 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71759 {
71760 - return __pgprot(pgprot_val(protection_map[vm_flags &
71761 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71762 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71763 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71764 +
71765 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71766 + if (!(__supported_pte_mask & _PAGE_NX) &&
71767 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71768 + (vm_flags & (VM_READ | VM_WRITE)))
71769 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71770 +#endif
71771 +
71772 + return prot;
71773 }
71774 EXPORT_SYMBOL(vm_get_page_prot);
71775
71776 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71777 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71778 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71779 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71780 /*
71781 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71782 * other variables. It can be updated by several CPUs frequently.
71783 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71784 struct vm_area_struct *next = vma->vm_next;
71785
71786 might_sleep();
71787 + BUG_ON(vma->vm_mirror);
71788 if (vma->vm_ops && vma->vm_ops->close)
71789 vma->vm_ops->close(vma);
71790 if (vma->vm_file) {
71791 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71792 * not page aligned -Ram Gupta
71793 */
71794 rlim = rlimit(RLIMIT_DATA);
71795 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71796 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71797 (mm->end_data - mm->start_data) > rlim)
71798 goto out;
71799 @@ -689,6 +711,12 @@ static int
71800 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71801 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71802 {
71803 +
71804 +#ifdef CONFIG_PAX_SEGMEXEC
71805 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71806 + return 0;
71807 +#endif
71808 +
71809 if (is_mergeable_vma(vma, file, vm_flags) &&
71810 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71811 if (vma->vm_pgoff == vm_pgoff)
71812 @@ -708,6 +736,12 @@ static int
71813 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71814 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71815 {
71816 +
71817 +#ifdef CONFIG_PAX_SEGMEXEC
71818 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71819 + return 0;
71820 +#endif
71821 +
71822 if (is_mergeable_vma(vma, file, vm_flags) &&
71823 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71824 pgoff_t vm_pglen;
71825 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71826 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71827 struct vm_area_struct *prev, unsigned long addr,
71828 unsigned long end, unsigned long vm_flags,
71829 - struct anon_vma *anon_vma, struct file *file,
71830 + struct anon_vma *anon_vma, struct file *file,
71831 pgoff_t pgoff, struct mempolicy *policy)
71832 {
71833 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71834 struct vm_area_struct *area, *next;
71835 int err;
71836
71837 +#ifdef CONFIG_PAX_SEGMEXEC
71838 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71839 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71840 +
71841 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71842 +#endif
71843 +
71844 /*
71845 * We later require that vma->vm_flags == vm_flags,
71846 * so this tests vma->vm_flags & VM_SPECIAL, too.
71847 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71848 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71849 next = next->vm_next;
71850
71851 +#ifdef CONFIG_PAX_SEGMEXEC
71852 + if (prev)
71853 + prev_m = pax_find_mirror_vma(prev);
71854 + if (area)
71855 + area_m = pax_find_mirror_vma(area);
71856 + if (next)
71857 + next_m = pax_find_mirror_vma(next);
71858 +#endif
71859 +
71860 /*
71861 * Can it merge with the predecessor?
71862 */
71863 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71864 /* cases 1, 6 */
71865 err = vma_adjust(prev, prev->vm_start,
71866 next->vm_end, prev->vm_pgoff, NULL);
71867 - } else /* cases 2, 5, 7 */
71868 +
71869 +#ifdef CONFIG_PAX_SEGMEXEC
71870 + if (!err && prev_m)
71871 + err = vma_adjust(prev_m, prev_m->vm_start,
71872 + next_m->vm_end, prev_m->vm_pgoff, NULL);
71873 +#endif
71874 +
71875 + } else { /* cases 2, 5, 7 */
71876 err = vma_adjust(prev, prev->vm_start,
71877 end, prev->vm_pgoff, NULL);
71878 +
71879 +#ifdef CONFIG_PAX_SEGMEXEC
71880 + if (!err && prev_m)
71881 + err = vma_adjust(prev_m, prev_m->vm_start,
71882 + end_m, prev_m->vm_pgoff, NULL);
71883 +#endif
71884 +
71885 + }
71886 if (err)
71887 return NULL;
71888 khugepaged_enter_vma_merge(prev);
71889 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71890 mpol_equal(policy, vma_policy(next)) &&
71891 can_vma_merge_before(next, vm_flags,
71892 anon_vma, file, pgoff+pglen)) {
71893 - if (prev && addr < prev->vm_end) /* case 4 */
71894 + if (prev && addr < prev->vm_end) { /* case 4 */
71895 err = vma_adjust(prev, prev->vm_start,
71896 addr, prev->vm_pgoff, NULL);
71897 - else /* cases 3, 8 */
71898 +
71899 +#ifdef CONFIG_PAX_SEGMEXEC
71900 + if (!err && prev_m)
71901 + err = vma_adjust(prev_m, prev_m->vm_start,
71902 + addr_m, prev_m->vm_pgoff, NULL);
71903 +#endif
71904 +
71905 + } else { /* cases 3, 8 */
71906 err = vma_adjust(area, addr, next->vm_end,
71907 next->vm_pgoff - pglen, NULL);
71908 +
71909 +#ifdef CONFIG_PAX_SEGMEXEC
71910 + if (!err && area_m)
71911 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
71912 + next_m->vm_pgoff - pglen, NULL);
71913 +#endif
71914 +
71915 + }
71916 if (err)
71917 return NULL;
71918 khugepaged_enter_vma_merge(area);
71919 @@ -921,14 +1001,11 @@ none:
71920 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
71921 struct file *file, long pages)
71922 {
71923 - const unsigned long stack_flags
71924 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
71925 -
71926 if (file) {
71927 mm->shared_vm += pages;
71928 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
71929 mm->exec_vm += pages;
71930 - } else if (flags & stack_flags)
71931 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
71932 mm->stack_vm += pages;
71933 if (flags & (VM_RESERVED|VM_IO))
71934 mm->reserved_vm += pages;
71935 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71936 * (the exception is when the underlying filesystem is noexec
71937 * mounted, in which case we dont add PROT_EXEC.)
71938 */
71939 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71940 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71941 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
71942 prot |= PROT_EXEC;
71943
71944 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71945 /* Obtain the address to map to. we verify (or select) it and ensure
71946 * that it represents a valid section of the address space.
71947 */
71948 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
71949 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
71950 if (addr & ~PAGE_MASK)
71951 return addr;
71952
71953 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71954 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
71955 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
71956
71957 +#ifdef CONFIG_PAX_MPROTECT
71958 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71959 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71960 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
71961 + gr_log_rwxmmap(file);
71962 +
71963 +#ifdef CONFIG_PAX_EMUPLT
71964 + vm_flags &= ~VM_EXEC;
71965 +#else
71966 + return -EPERM;
71967 +#endif
71968 +
71969 + }
71970 +
71971 + if (!(vm_flags & VM_EXEC))
71972 + vm_flags &= ~VM_MAYEXEC;
71973 +#else
71974 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71975 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71976 +#endif
71977 + else
71978 + vm_flags &= ~VM_MAYWRITE;
71979 + }
71980 +#endif
71981 +
71982 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71983 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
71984 + vm_flags &= ~VM_PAGEEXEC;
71985 +#endif
71986 +
71987 if (flags & MAP_LOCKED)
71988 if (!can_do_mlock())
71989 return -EPERM;
71990 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71991 locked += mm->locked_vm;
71992 lock_limit = rlimit(RLIMIT_MEMLOCK);
71993 lock_limit >>= PAGE_SHIFT;
71994 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71995 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
71996 return -EAGAIN;
71997 }
71998 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71999 if (error)
72000 return error;
72001
72002 + if (!gr_acl_handle_mmap(file, prot))
72003 + return -EACCES;
72004 +
72005 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72006 }
72007 EXPORT_SYMBOL(do_mmap_pgoff);
72008 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72009 vm_flags_t vm_flags = vma->vm_flags;
72010
72011 /* If it was private or non-writable, the write bit is already clear */
72012 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72013 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72014 return 0;
72015
72016 /* The backer wishes to know when pages are first written to? */
72017 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72018 unsigned long charged = 0;
72019 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72020
72021 +#ifdef CONFIG_PAX_SEGMEXEC
72022 + struct vm_area_struct *vma_m = NULL;
72023 +#endif
72024 +
72025 + /*
72026 + * mm->mmap_sem is required to protect against another thread
72027 + * changing the mappings in case we sleep.
72028 + */
72029 + verify_mm_writelocked(mm);
72030 +
72031 /* Clear old maps */
72032 error = -ENOMEM;
72033 -munmap_back:
72034 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72035 if (vma && vma->vm_start < addr + len) {
72036 if (do_munmap(mm, addr, len))
72037 return -ENOMEM;
72038 - goto munmap_back;
72039 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72040 + BUG_ON(vma && vma->vm_start < addr + len);
72041 }
72042
72043 /* Check against address space limit. */
72044 @@ -1258,6 +1379,16 @@ munmap_back:
72045 goto unacct_error;
72046 }
72047
72048 +#ifdef CONFIG_PAX_SEGMEXEC
72049 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72050 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72051 + if (!vma_m) {
72052 + error = -ENOMEM;
72053 + goto free_vma;
72054 + }
72055 + }
72056 +#endif
72057 +
72058 vma->vm_mm = mm;
72059 vma->vm_start = addr;
72060 vma->vm_end = addr + len;
72061 @@ -1281,6 +1412,19 @@ munmap_back:
72062 error = file->f_op->mmap(file, vma);
72063 if (error)
72064 goto unmap_and_free_vma;
72065 +
72066 +#ifdef CONFIG_PAX_SEGMEXEC
72067 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72068 + added_exe_file_vma(mm);
72069 +#endif
72070 +
72071 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72072 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72073 + vma->vm_flags |= VM_PAGEEXEC;
72074 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72075 + }
72076 +#endif
72077 +
72078 if (vm_flags & VM_EXECUTABLE)
72079 added_exe_file_vma(mm);
72080
72081 @@ -1316,6 +1460,11 @@ munmap_back:
72082 vma_link(mm, vma, prev, rb_link, rb_parent);
72083 file = vma->vm_file;
72084
72085 +#ifdef CONFIG_PAX_SEGMEXEC
72086 + if (vma_m)
72087 + BUG_ON(pax_mirror_vma(vma_m, vma));
72088 +#endif
72089 +
72090 /* Once vma denies write, undo our temporary denial count */
72091 if (correct_wcount)
72092 atomic_inc(&inode->i_writecount);
72093 @@ -1324,6 +1473,7 @@ out:
72094
72095 mm->total_vm += len >> PAGE_SHIFT;
72096 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72097 + track_exec_limit(mm, addr, addr + len, vm_flags);
72098 if (vm_flags & VM_LOCKED) {
72099 if (!mlock_vma_pages_range(vma, addr, addr + len))
72100 mm->locked_vm += (len >> PAGE_SHIFT);
72101 @@ -1341,6 +1491,12 @@ unmap_and_free_vma:
72102 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72103 charged = 0;
72104 free_vma:
72105 +
72106 +#ifdef CONFIG_PAX_SEGMEXEC
72107 + if (vma_m)
72108 + kmem_cache_free(vm_area_cachep, vma_m);
72109 +#endif
72110 +
72111 kmem_cache_free(vm_area_cachep, vma);
72112 unacct_error:
72113 if (charged)
72114 @@ -1348,6 +1504,44 @@ unacct_error:
72115 return error;
72116 }
72117
72118 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72119 +{
72120 + if (!vma) {
72121 +#ifdef CONFIG_STACK_GROWSUP
72122 + if (addr > sysctl_heap_stack_gap)
72123 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72124 + else
72125 + vma = find_vma(current->mm, 0);
72126 + if (vma && (vma->vm_flags & VM_GROWSUP))
72127 + return false;
72128 +#endif
72129 + return true;
72130 + }
72131 +
72132 + if (addr + len > vma->vm_start)
72133 + return false;
72134 +
72135 + if (vma->vm_flags & VM_GROWSDOWN)
72136 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72137 +#ifdef CONFIG_STACK_GROWSUP
72138 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72139 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72140 +#endif
72141 +
72142 + return true;
72143 +}
72144 +
72145 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72146 +{
72147 + if (vma->vm_start < len)
72148 + return -ENOMEM;
72149 + if (!(vma->vm_flags & VM_GROWSDOWN))
72150 + return vma->vm_start - len;
72151 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
72152 + return vma->vm_start - len - sysctl_heap_stack_gap;
72153 + return -ENOMEM;
72154 +}
72155 +
72156 /* Get an address range which is currently unmapped.
72157 * For shmat() with addr=0.
72158 *
72159 @@ -1374,18 +1568,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72160 if (flags & MAP_FIXED)
72161 return addr;
72162
72163 +#ifdef CONFIG_PAX_RANDMMAP
72164 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72165 +#endif
72166 +
72167 if (addr) {
72168 addr = PAGE_ALIGN(addr);
72169 - vma = find_vma(mm, addr);
72170 - if (TASK_SIZE - len >= addr &&
72171 - (!vma || addr + len <= vma->vm_start))
72172 - return addr;
72173 + if (TASK_SIZE - len >= addr) {
72174 + vma = find_vma(mm, addr);
72175 + if (check_heap_stack_gap(vma, addr, len))
72176 + return addr;
72177 + }
72178 }
72179 if (len > mm->cached_hole_size) {
72180 - start_addr = addr = mm->free_area_cache;
72181 + start_addr = addr = mm->free_area_cache;
72182 } else {
72183 - start_addr = addr = TASK_UNMAPPED_BASE;
72184 - mm->cached_hole_size = 0;
72185 + start_addr = addr = mm->mmap_base;
72186 + mm->cached_hole_size = 0;
72187 }
72188
72189 full_search:
72190 @@ -1396,34 +1595,40 @@ full_search:
72191 * Start a new search - just in case we missed
72192 * some holes.
72193 */
72194 - if (start_addr != TASK_UNMAPPED_BASE) {
72195 - addr = TASK_UNMAPPED_BASE;
72196 - start_addr = addr;
72197 + if (start_addr != mm->mmap_base) {
72198 + start_addr = addr = mm->mmap_base;
72199 mm->cached_hole_size = 0;
72200 goto full_search;
72201 }
72202 return -ENOMEM;
72203 }
72204 - if (!vma || addr + len <= vma->vm_start) {
72205 - /*
72206 - * Remember the place where we stopped the search:
72207 - */
72208 - mm->free_area_cache = addr + len;
72209 - return addr;
72210 - }
72211 + if (check_heap_stack_gap(vma, addr, len))
72212 + break;
72213 if (addr + mm->cached_hole_size < vma->vm_start)
72214 mm->cached_hole_size = vma->vm_start - addr;
72215 addr = vma->vm_end;
72216 }
72217 +
72218 + /*
72219 + * Remember the place where we stopped the search:
72220 + */
72221 + mm->free_area_cache = addr + len;
72222 + return addr;
72223 }
72224 #endif
72225
72226 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72227 {
72228 +
72229 +#ifdef CONFIG_PAX_SEGMEXEC
72230 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72231 + return;
72232 +#endif
72233 +
72234 /*
72235 * Is this a new hole at the lowest possible address?
72236 */
72237 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
72238 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
72239 mm->free_area_cache = addr;
72240 mm->cached_hole_size = ~0UL;
72241 }
72242 @@ -1441,7 +1646,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72243 {
72244 struct vm_area_struct *vma;
72245 struct mm_struct *mm = current->mm;
72246 - unsigned long addr = addr0;
72247 + unsigned long base = mm->mmap_base, addr = addr0;
72248
72249 /* requested length too big for entire address space */
72250 if (len > TASK_SIZE)
72251 @@ -1450,13 +1655,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72252 if (flags & MAP_FIXED)
72253 return addr;
72254
72255 +#ifdef CONFIG_PAX_RANDMMAP
72256 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72257 +#endif
72258 +
72259 /* requesting a specific address */
72260 if (addr) {
72261 addr = PAGE_ALIGN(addr);
72262 - vma = find_vma(mm, addr);
72263 - if (TASK_SIZE - len >= addr &&
72264 - (!vma || addr + len <= vma->vm_start))
72265 - return addr;
72266 + if (TASK_SIZE - len >= addr) {
72267 + vma = find_vma(mm, addr);
72268 + if (check_heap_stack_gap(vma, addr, len))
72269 + return addr;
72270 + }
72271 }
72272
72273 /* check if free_area_cache is useful for us */
72274 @@ -1471,7 +1681,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72275 /* make sure it can fit in the remaining address space */
72276 if (addr > len) {
72277 vma = find_vma(mm, addr-len);
72278 - if (!vma || addr <= vma->vm_start)
72279 + if (check_heap_stack_gap(vma, addr - len, len))
72280 /* remember the address as a hint for next time */
72281 return (mm->free_area_cache = addr-len);
72282 }
72283 @@ -1488,7 +1698,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72284 * return with success:
72285 */
72286 vma = find_vma(mm, addr);
72287 - if (!vma || addr+len <= vma->vm_start)
72288 + if (check_heap_stack_gap(vma, addr, len))
72289 /* remember the address as a hint for next time */
72290 return (mm->free_area_cache = addr);
72291
72292 @@ -1497,8 +1707,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72293 mm->cached_hole_size = vma->vm_start - addr;
72294
72295 /* try just below the current vma->vm_start */
72296 - addr = vma->vm_start-len;
72297 - } while (len < vma->vm_start);
72298 + addr = skip_heap_stack_gap(vma, len);
72299 + } while (!IS_ERR_VALUE(addr));
72300
72301 bottomup:
72302 /*
72303 @@ -1507,13 +1717,21 @@ bottomup:
72304 * can happen with large stack limits and large mmap()
72305 * allocations.
72306 */
72307 + mm->mmap_base = TASK_UNMAPPED_BASE;
72308 +
72309 +#ifdef CONFIG_PAX_RANDMMAP
72310 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72311 + mm->mmap_base += mm->delta_mmap;
72312 +#endif
72313 +
72314 + mm->free_area_cache = mm->mmap_base;
72315 mm->cached_hole_size = ~0UL;
72316 - mm->free_area_cache = TASK_UNMAPPED_BASE;
72317 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72318 /*
72319 * Restore the topdown base:
72320 */
72321 - mm->free_area_cache = mm->mmap_base;
72322 + mm->mmap_base = base;
72323 + mm->free_area_cache = base;
72324 mm->cached_hole_size = ~0UL;
72325
72326 return addr;
72327 @@ -1522,6 +1740,12 @@ bottomup:
72328
72329 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72330 {
72331 +
72332 +#ifdef CONFIG_PAX_SEGMEXEC
72333 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72334 + return;
72335 +#endif
72336 +
72337 /*
72338 * Is this a new hole at the highest possible address?
72339 */
72340 @@ -1529,8 +1753,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72341 mm->free_area_cache = addr;
72342
72343 /* dont allow allocations above current base */
72344 - if (mm->free_area_cache > mm->mmap_base)
72345 + if (mm->free_area_cache > mm->mmap_base) {
72346 mm->free_area_cache = mm->mmap_base;
72347 + mm->cached_hole_size = ~0UL;
72348 + }
72349 }
72350
72351 unsigned long
72352 @@ -1638,6 +1864,28 @@ out:
72353 return prev ? prev->vm_next : vma;
72354 }
72355
72356 +#ifdef CONFIG_PAX_SEGMEXEC
72357 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72358 +{
72359 + struct vm_area_struct *vma_m;
72360 +
72361 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72362 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72363 + BUG_ON(vma->vm_mirror);
72364 + return NULL;
72365 + }
72366 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72367 + vma_m = vma->vm_mirror;
72368 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72369 + BUG_ON(vma->vm_file != vma_m->vm_file);
72370 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72371 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72372 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72373 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72374 + return vma_m;
72375 +}
72376 +#endif
72377 +
72378 /*
72379 * Verify that the stack growth is acceptable and
72380 * update accounting. This is shared with both the
72381 @@ -1654,6 +1902,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72382 return -ENOMEM;
72383
72384 /* Stack limit test */
72385 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
72386 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72387 return -ENOMEM;
72388
72389 @@ -1664,6 +1913,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72390 locked = mm->locked_vm + grow;
72391 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72392 limit >>= PAGE_SHIFT;
72393 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72394 if (locked > limit && !capable(CAP_IPC_LOCK))
72395 return -ENOMEM;
72396 }
72397 @@ -1694,37 +1944,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72398 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72399 * vma is the last one with address > vma->vm_end. Have to extend vma.
72400 */
72401 +#ifndef CONFIG_IA64
72402 +static
72403 +#endif
72404 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72405 {
72406 int error;
72407 + bool locknext;
72408
72409 if (!(vma->vm_flags & VM_GROWSUP))
72410 return -EFAULT;
72411
72412 + /* Also guard against wrapping around to address 0. */
72413 + if (address < PAGE_ALIGN(address+1))
72414 + address = PAGE_ALIGN(address+1);
72415 + else
72416 + return -ENOMEM;
72417 +
72418 /*
72419 * We must make sure the anon_vma is allocated
72420 * so that the anon_vma locking is not a noop.
72421 */
72422 if (unlikely(anon_vma_prepare(vma)))
72423 return -ENOMEM;
72424 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72425 + if (locknext && anon_vma_prepare(vma->vm_next))
72426 + return -ENOMEM;
72427 vma_lock_anon_vma(vma);
72428 + if (locknext)
72429 + vma_lock_anon_vma(vma->vm_next);
72430
72431 /*
72432 * vma->vm_start/vm_end cannot change under us because the caller
72433 * is required to hold the mmap_sem in read mode. We need the
72434 - * anon_vma lock to serialize against concurrent expand_stacks.
72435 - * Also guard against wrapping around to address 0.
72436 + * anon_vma locks to serialize against concurrent expand_stacks
72437 + * and expand_upwards.
72438 */
72439 - if (address < PAGE_ALIGN(address+4))
72440 - address = PAGE_ALIGN(address+4);
72441 - else {
72442 - vma_unlock_anon_vma(vma);
72443 - return -ENOMEM;
72444 - }
72445 error = 0;
72446
72447 /* Somebody else might have raced and expanded it already */
72448 - if (address > vma->vm_end) {
72449 + 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)
72450 + error = -ENOMEM;
72451 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72452 unsigned long size, grow;
72453
72454 size = address - vma->vm_start;
72455 @@ -1739,6 +2000,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72456 }
72457 }
72458 }
72459 + if (locknext)
72460 + vma_unlock_anon_vma(vma->vm_next);
72461 vma_unlock_anon_vma(vma);
72462 khugepaged_enter_vma_merge(vma);
72463 return error;
72464 @@ -1752,6 +2015,8 @@ int expand_downwards(struct vm_area_struct *vma,
72465 unsigned long address)
72466 {
72467 int error;
72468 + bool lockprev = false;
72469 + struct vm_area_struct *prev;
72470
72471 /*
72472 * We must make sure the anon_vma is allocated
72473 @@ -1765,6 +2030,15 @@ int expand_downwards(struct vm_area_struct *vma,
72474 if (error)
72475 return error;
72476
72477 + prev = vma->vm_prev;
72478 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72479 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72480 +#endif
72481 + if (lockprev && anon_vma_prepare(prev))
72482 + return -ENOMEM;
72483 + if (lockprev)
72484 + vma_lock_anon_vma(prev);
72485 +
72486 vma_lock_anon_vma(vma);
72487
72488 /*
72489 @@ -1774,9 +2048,17 @@ int expand_downwards(struct vm_area_struct *vma,
72490 */
72491
72492 /* Somebody else might have raced and expanded it already */
72493 - if (address < vma->vm_start) {
72494 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72495 + error = -ENOMEM;
72496 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72497 unsigned long size, grow;
72498
72499 +#ifdef CONFIG_PAX_SEGMEXEC
72500 + struct vm_area_struct *vma_m;
72501 +
72502 + vma_m = pax_find_mirror_vma(vma);
72503 +#endif
72504 +
72505 size = vma->vm_end - address;
72506 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72507
72508 @@ -1786,11 +2068,22 @@ int expand_downwards(struct vm_area_struct *vma,
72509 if (!error) {
72510 vma->vm_start = address;
72511 vma->vm_pgoff -= grow;
72512 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72513 +
72514 +#ifdef CONFIG_PAX_SEGMEXEC
72515 + if (vma_m) {
72516 + vma_m->vm_start -= grow << PAGE_SHIFT;
72517 + vma_m->vm_pgoff -= grow;
72518 + }
72519 +#endif
72520 +
72521 perf_event_mmap(vma);
72522 }
72523 }
72524 }
72525 vma_unlock_anon_vma(vma);
72526 + if (lockprev)
72527 + vma_unlock_anon_vma(prev);
72528 khugepaged_enter_vma_merge(vma);
72529 return error;
72530 }
72531 @@ -1860,6 +2153,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72532 do {
72533 long nrpages = vma_pages(vma);
72534
72535 +#ifdef CONFIG_PAX_SEGMEXEC
72536 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72537 + vma = remove_vma(vma);
72538 + continue;
72539 + }
72540 +#endif
72541 +
72542 mm->total_vm -= nrpages;
72543 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
72544 vma = remove_vma(vma);
72545 @@ -1905,6 +2205,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72546 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72547 vma->vm_prev = NULL;
72548 do {
72549 +
72550 +#ifdef CONFIG_PAX_SEGMEXEC
72551 + if (vma->vm_mirror) {
72552 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72553 + vma->vm_mirror->vm_mirror = NULL;
72554 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72555 + vma->vm_mirror = NULL;
72556 + }
72557 +#endif
72558 +
72559 rb_erase(&vma->vm_rb, &mm->mm_rb);
72560 mm->map_count--;
72561 tail_vma = vma;
72562 @@ -1933,14 +2243,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72563 struct vm_area_struct *new;
72564 int err = -ENOMEM;
72565
72566 +#ifdef CONFIG_PAX_SEGMEXEC
72567 + struct vm_area_struct *vma_m, *new_m = NULL;
72568 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72569 +#endif
72570 +
72571 if (is_vm_hugetlb_page(vma) && (addr &
72572 ~(huge_page_mask(hstate_vma(vma)))))
72573 return -EINVAL;
72574
72575 +#ifdef CONFIG_PAX_SEGMEXEC
72576 + vma_m = pax_find_mirror_vma(vma);
72577 +#endif
72578 +
72579 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72580 if (!new)
72581 goto out_err;
72582
72583 +#ifdef CONFIG_PAX_SEGMEXEC
72584 + if (vma_m) {
72585 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72586 + if (!new_m) {
72587 + kmem_cache_free(vm_area_cachep, new);
72588 + goto out_err;
72589 + }
72590 + }
72591 +#endif
72592 +
72593 /* most fields are the same, copy all, and then fixup */
72594 *new = *vma;
72595
72596 @@ -1953,6 +2282,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72597 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72598 }
72599
72600 +#ifdef CONFIG_PAX_SEGMEXEC
72601 + if (vma_m) {
72602 + *new_m = *vma_m;
72603 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72604 + new_m->vm_mirror = new;
72605 + new->vm_mirror = new_m;
72606 +
72607 + if (new_below)
72608 + new_m->vm_end = addr_m;
72609 + else {
72610 + new_m->vm_start = addr_m;
72611 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72612 + }
72613 + }
72614 +#endif
72615 +
72616 pol = mpol_dup(vma_policy(vma));
72617 if (IS_ERR(pol)) {
72618 err = PTR_ERR(pol);
72619 @@ -1978,6 +2323,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72620 else
72621 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72622
72623 +#ifdef CONFIG_PAX_SEGMEXEC
72624 + if (!err && vma_m) {
72625 + if (anon_vma_clone(new_m, vma_m))
72626 + goto out_free_mpol;
72627 +
72628 + mpol_get(pol);
72629 + vma_set_policy(new_m, pol);
72630 +
72631 + if (new_m->vm_file) {
72632 + get_file(new_m->vm_file);
72633 + if (vma_m->vm_flags & VM_EXECUTABLE)
72634 + added_exe_file_vma(mm);
72635 + }
72636 +
72637 + if (new_m->vm_ops && new_m->vm_ops->open)
72638 + new_m->vm_ops->open(new_m);
72639 +
72640 + if (new_below)
72641 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72642 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72643 + else
72644 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72645 +
72646 + if (err) {
72647 + if (new_m->vm_ops && new_m->vm_ops->close)
72648 + new_m->vm_ops->close(new_m);
72649 + if (new_m->vm_file) {
72650 + if (vma_m->vm_flags & VM_EXECUTABLE)
72651 + removed_exe_file_vma(mm);
72652 + fput(new_m->vm_file);
72653 + }
72654 + mpol_put(pol);
72655 + }
72656 + }
72657 +#endif
72658 +
72659 /* Success. */
72660 if (!err)
72661 return 0;
72662 @@ -1990,10 +2371,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72663 removed_exe_file_vma(mm);
72664 fput(new->vm_file);
72665 }
72666 - unlink_anon_vmas(new);
72667 out_free_mpol:
72668 mpol_put(pol);
72669 out_free_vma:
72670 +
72671 +#ifdef CONFIG_PAX_SEGMEXEC
72672 + if (new_m) {
72673 + unlink_anon_vmas(new_m);
72674 + kmem_cache_free(vm_area_cachep, new_m);
72675 + }
72676 +#endif
72677 +
72678 + unlink_anon_vmas(new);
72679 kmem_cache_free(vm_area_cachep, new);
72680 out_err:
72681 return err;
72682 @@ -2006,6 +2395,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72683 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72684 unsigned long addr, int new_below)
72685 {
72686 +
72687 +#ifdef CONFIG_PAX_SEGMEXEC
72688 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72689 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72690 + if (mm->map_count >= sysctl_max_map_count-1)
72691 + return -ENOMEM;
72692 + } else
72693 +#endif
72694 +
72695 if (mm->map_count >= sysctl_max_map_count)
72696 return -ENOMEM;
72697
72698 @@ -2017,11 +2415,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72699 * work. This now handles partial unmappings.
72700 * Jeremy Fitzhardinge <jeremy@goop.org>
72701 */
72702 +#ifdef CONFIG_PAX_SEGMEXEC
72703 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72704 {
72705 + int ret = __do_munmap(mm, start, len);
72706 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72707 + return ret;
72708 +
72709 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72710 +}
72711 +
72712 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72713 +#else
72714 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72715 +#endif
72716 +{
72717 unsigned long end;
72718 struct vm_area_struct *vma, *prev, *last;
72719
72720 + /*
72721 + * mm->mmap_sem is required to protect against another thread
72722 + * changing the mappings in case we sleep.
72723 + */
72724 + verify_mm_writelocked(mm);
72725 +
72726 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72727 return -EINVAL;
72728
72729 @@ -2096,6 +2513,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72730 /* Fix up all other VM information */
72731 remove_vma_list(mm, vma);
72732
72733 + track_exec_limit(mm, start, end, 0UL);
72734 +
72735 return 0;
72736 }
72737
72738 @@ -2108,22 +2527,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72739
72740 profile_munmap(addr);
72741
72742 +#ifdef CONFIG_PAX_SEGMEXEC
72743 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72744 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
72745 + return -EINVAL;
72746 +#endif
72747 +
72748 down_write(&mm->mmap_sem);
72749 ret = do_munmap(mm, addr, len);
72750 up_write(&mm->mmap_sem);
72751 return ret;
72752 }
72753
72754 -static inline void verify_mm_writelocked(struct mm_struct *mm)
72755 -{
72756 -#ifdef CONFIG_DEBUG_VM
72757 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72758 - WARN_ON(1);
72759 - up_read(&mm->mmap_sem);
72760 - }
72761 -#endif
72762 -}
72763 -
72764 /*
72765 * this is really a simplified "do_mmap". it only handles
72766 * anonymous maps. eventually we may be able to do some
72767 @@ -2137,6 +2552,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72768 struct rb_node ** rb_link, * rb_parent;
72769 pgoff_t pgoff = addr >> PAGE_SHIFT;
72770 int error;
72771 + unsigned long charged;
72772
72773 len = PAGE_ALIGN(len);
72774 if (!len)
72775 @@ -2148,16 +2564,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72776
72777 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72778
72779 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72780 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72781 + flags &= ~VM_EXEC;
72782 +
72783 +#ifdef CONFIG_PAX_MPROTECT
72784 + if (mm->pax_flags & MF_PAX_MPROTECT)
72785 + flags &= ~VM_MAYEXEC;
72786 +#endif
72787 +
72788 + }
72789 +#endif
72790 +
72791 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72792 if (error & ~PAGE_MASK)
72793 return error;
72794
72795 + charged = len >> PAGE_SHIFT;
72796 +
72797 /*
72798 * mlock MCL_FUTURE?
72799 */
72800 if (mm->def_flags & VM_LOCKED) {
72801 unsigned long locked, lock_limit;
72802 - locked = len >> PAGE_SHIFT;
72803 + locked = charged;
72804 locked += mm->locked_vm;
72805 lock_limit = rlimit(RLIMIT_MEMLOCK);
72806 lock_limit >>= PAGE_SHIFT;
72807 @@ -2174,22 +2604,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72808 /*
72809 * Clear old maps. this also does some error checking for us
72810 */
72811 - munmap_back:
72812 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72813 if (vma && vma->vm_start < addr + len) {
72814 if (do_munmap(mm, addr, len))
72815 return -ENOMEM;
72816 - goto munmap_back;
72817 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72818 + BUG_ON(vma && vma->vm_start < addr + len);
72819 }
72820
72821 /* Check against address space limits *after* clearing old maps... */
72822 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72823 + if (!may_expand_vm(mm, charged))
72824 return -ENOMEM;
72825
72826 if (mm->map_count > sysctl_max_map_count)
72827 return -ENOMEM;
72828
72829 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
72830 + if (security_vm_enough_memory(charged))
72831 return -ENOMEM;
72832
72833 /* Can we just expand an old private anonymous mapping? */
72834 @@ -2203,7 +2633,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72835 */
72836 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72837 if (!vma) {
72838 - vm_unacct_memory(len >> PAGE_SHIFT);
72839 + vm_unacct_memory(charged);
72840 return -ENOMEM;
72841 }
72842
72843 @@ -2217,11 +2647,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72844 vma_link(mm, vma, prev, rb_link, rb_parent);
72845 out:
72846 perf_event_mmap(vma);
72847 - mm->total_vm += len >> PAGE_SHIFT;
72848 + mm->total_vm += charged;
72849 if (flags & VM_LOCKED) {
72850 if (!mlock_vma_pages_range(vma, addr, addr + len))
72851 - mm->locked_vm += (len >> PAGE_SHIFT);
72852 + mm->locked_vm += charged;
72853 }
72854 + track_exec_limit(mm, addr, addr + len, flags);
72855 return addr;
72856 }
72857
72858 @@ -2268,8 +2699,10 @@ void exit_mmap(struct mm_struct *mm)
72859 * Walk the list again, actually closing and freeing it,
72860 * with preemption enabled, without holding any MM locks.
72861 */
72862 - while (vma)
72863 + while (vma) {
72864 + vma->vm_mirror = NULL;
72865 vma = remove_vma(vma);
72866 + }
72867
72868 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
72869 }
72870 @@ -2283,6 +2716,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72871 struct vm_area_struct * __vma, * prev;
72872 struct rb_node ** rb_link, * rb_parent;
72873
72874 +#ifdef CONFIG_PAX_SEGMEXEC
72875 + struct vm_area_struct *vma_m = NULL;
72876 +#endif
72877 +
72878 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
72879 + return -EPERM;
72880 +
72881 /*
72882 * The vm_pgoff of a purely anonymous vma should be irrelevant
72883 * until its first write fault, when page's anon_vma and index
72884 @@ -2305,7 +2745,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72885 if ((vma->vm_flags & VM_ACCOUNT) &&
72886 security_vm_enough_memory_mm(mm, vma_pages(vma)))
72887 return -ENOMEM;
72888 +
72889 +#ifdef CONFIG_PAX_SEGMEXEC
72890 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72891 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72892 + if (!vma_m)
72893 + return -ENOMEM;
72894 + }
72895 +#endif
72896 +
72897 vma_link(mm, vma, prev, rb_link, rb_parent);
72898 +
72899 +#ifdef CONFIG_PAX_SEGMEXEC
72900 + if (vma_m)
72901 + BUG_ON(pax_mirror_vma(vma_m, vma));
72902 +#endif
72903 +
72904 return 0;
72905 }
72906
72907 @@ -2323,6 +2778,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72908 struct rb_node **rb_link, *rb_parent;
72909 struct mempolicy *pol;
72910
72911 + BUG_ON(vma->vm_mirror);
72912 +
72913 /*
72914 * If anonymous vma has not yet been faulted, update new pgoff
72915 * to match new location, to increase its chance of merging.
72916 @@ -2373,6 +2830,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72917 return NULL;
72918 }
72919
72920 +#ifdef CONFIG_PAX_SEGMEXEC
72921 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
72922 +{
72923 + struct vm_area_struct *prev_m;
72924 + struct rb_node **rb_link_m, *rb_parent_m;
72925 + struct mempolicy *pol_m;
72926 +
72927 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
72928 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
72929 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
72930 + *vma_m = *vma;
72931 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
72932 + if (anon_vma_clone(vma_m, vma))
72933 + return -ENOMEM;
72934 + pol_m = vma_policy(vma_m);
72935 + mpol_get(pol_m);
72936 + vma_set_policy(vma_m, pol_m);
72937 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
72938 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
72939 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
72940 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
72941 + if (vma_m->vm_file)
72942 + get_file(vma_m->vm_file);
72943 + if (vma_m->vm_ops && vma_m->vm_ops->open)
72944 + vma_m->vm_ops->open(vma_m);
72945 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
72946 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
72947 + vma_m->vm_mirror = vma;
72948 + vma->vm_mirror = vma_m;
72949 + return 0;
72950 +}
72951 +#endif
72952 +
72953 /*
72954 * Return true if the calling process may expand its vm space by the passed
72955 * number of pages
72956 @@ -2383,7 +2873,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
72957 unsigned long lim;
72958
72959 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
72960 -
72961 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
72962 if (cur + npages > lim)
72963 return 0;
72964 return 1;
72965 @@ -2454,6 +2944,22 @@ int install_special_mapping(struct mm_struct *mm,
72966 vma->vm_start = addr;
72967 vma->vm_end = addr + len;
72968
72969 +#ifdef CONFIG_PAX_MPROTECT
72970 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72971 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72972 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
72973 + return -EPERM;
72974 + if (!(vm_flags & VM_EXEC))
72975 + vm_flags &= ~VM_MAYEXEC;
72976 +#else
72977 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72978 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72979 +#endif
72980 + else
72981 + vm_flags &= ~VM_MAYWRITE;
72982 + }
72983 +#endif
72984 +
72985 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
72986 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72987
72988 diff --git a/mm/mprotect.c b/mm/mprotect.c
72989 index 5a688a2..27e031c 100644
72990 --- a/mm/mprotect.c
72991 +++ b/mm/mprotect.c
72992 @@ -23,10 +23,16 @@
72993 #include <linux/mmu_notifier.h>
72994 #include <linux/migrate.h>
72995 #include <linux/perf_event.h>
72996 +
72997 +#ifdef CONFIG_PAX_MPROTECT
72998 +#include <linux/elf.h>
72999 +#endif
73000 +
73001 #include <asm/uaccess.h>
73002 #include <asm/pgtable.h>
73003 #include <asm/cacheflush.h>
73004 #include <asm/tlbflush.h>
73005 +#include <asm/mmu_context.h>
73006
73007 #ifndef pgprot_modify
73008 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73009 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
73010 flush_tlb_range(vma, start, end);
73011 }
73012
73013 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73014 +/* called while holding the mmap semaphor for writing except stack expansion */
73015 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73016 +{
73017 + unsigned long oldlimit, newlimit = 0UL;
73018 +
73019 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73020 + return;
73021 +
73022 + spin_lock(&mm->page_table_lock);
73023 + oldlimit = mm->context.user_cs_limit;
73024 + if ((prot & VM_EXEC) && oldlimit < end)
73025 + /* USER_CS limit moved up */
73026 + newlimit = end;
73027 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73028 + /* USER_CS limit moved down */
73029 + newlimit = start;
73030 +
73031 + if (newlimit) {
73032 + mm->context.user_cs_limit = newlimit;
73033 +
73034 +#ifdef CONFIG_SMP
73035 + wmb();
73036 + cpus_clear(mm->context.cpu_user_cs_mask);
73037 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73038 +#endif
73039 +
73040 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73041 + }
73042 + spin_unlock(&mm->page_table_lock);
73043 + if (newlimit == end) {
73044 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73045 +
73046 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73047 + if (is_vm_hugetlb_page(vma))
73048 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73049 + else
73050 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73051 + }
73052 +}
73053 +#endif
73054 +
73055 int
73056 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73057 unsigned long start, unsigned long end, unsigned long newflags)
73058 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73059 int error;
73060 int dirty_accountable = 0;
73061
73062 +#ifdef CONFIG_PAX_SEGMEXEC
73063 + struct vm_area_struct *vma_m = NULL;
73064 + unsigned long start_m, end_m;
73065 +
73066 + start_m = start + SEGMEXEC_TASK_SIZE;
73067 + end_m = end + SEGMEXEC_TASK_SIZE;
73068 +#endif
73069 +
73070 if (newflags == oldflags) {
73071 *pprev = vma;
73072 return 0;
73073 }
73074
73075 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73076 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73077 +
73078 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73079 + return -ENOMEM;
73080 +
73081 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73082 + return -ENOMEM;
73083 + }
73084 +
73085 /*
73086 * If we make a private mapping writable we increase our commit;
73087 * but (without finer accounting) cannot reduce our commit if we
73088 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73089 }
73090 }
73091
73092 +#ifdef CONFIG_PAX_SEGMEXEC
73093 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73094 + if (start != vma->vm_start) {
73095 + error = split_vma(mm, vma, start, 1);
73096 + if (error)
73097 + goto fail;
73098 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73099 + *pprev = (*pprev)->vm_next;
73100 + }
73101 +
73102 + if (end != vma->vm_end) {
73103 + error = split_vma(mm, vma, end, 0);
73104 + if (error)
73105 + goto fail;
73106 + }
73107 +
73108 + if (pax_find_mirror_vma(vma)) {
73109 + error = __do_munmap(mm, start_m, end_m - start_m);
73110 + if (error)
73111 + goto fail;
73112 + } else {
73113 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73114 + if (!vma_m) {
73115 + error = -ENOMEM;
73116 + goto fail;
73117 + }
73118 + vma->vm_flags = newflags;
73119 + error = pax_mirror_vma(vma_m, vma);
73120 + if (error) {
73121 + vma->vm_flags = oldflags;
73122 + goto fail;
73123 + }
73124 + }
73125 + }
73126 +#endif
73127 +
73128 /*
73129 * First try to merge with previous and/or next vma.
73130 */
73131 @@ -204,9 +306,21 @@ success:
73132 * vm_flags and vm_page_prot are protected by the mmap_sem
73133 * held in write mode.
73134 */
73135 +
73136 +#ifdef CONFIG_PAX_SEGMEXEC
73137 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73138 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73139 +#endif
73140 +
73141 vma->vm_flags = newflags;
73142 +
73143 +#ifdef CONFIG_PAX_MPROTECT
73144 + if (mm->binfmt && mm->binfmt->handle_mprotect)
73145 + mm->binfmt->handle_mprotect(vma, newflags);
73146 +#endif
73147 +
73148 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73149 - vm_get_page_prot(newflags));
73150 + vm_get_page_prot(vma->vm_flags));
73151
73152 if (vma_wants_writenotify(vma)) {
73153 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73154 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73155 end = start + len;
73156 if (end <= start)
73157 return -ENOMEM;
73158 +
73159 +#ifdef CONFIG_PAX_SEGMEXEC
73160 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73161 + if (end > SEGMEXEC_TASK_SIZE)
73162 + return -EINVAL;
73163 + } else
73164 +#endif
73165 +
73166 + if (end > TASK_SIZE)
73167 + return -EINVAL;
73168 +
73169 if (!arch_validate_prot(prot))
73170 return -EINVAL;
73171
73172 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73173 /*
73174 * Does the application expect PROT_READ to imply PROT_EXEC:
73175 */
73176 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73177 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73178 prot |= PROT_EXEC;
73179
73180 vm_flags = calc_vm_prot_bits(prot);
73181 @@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73182 if (start > vma->vm_start)
73183 prev = vma;
73184
73185 +#ifdef CONFIG_PAX_MPROTECT
73186 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73187 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
73188 +#endif
73189 +
73190 for (nstart = start ; ; ) {
73191 unsigned long newflags;
73192
73193 @@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73194
73195 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73196 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73197 + if (prot & (PROT_WRITE | PROT_EXEC))
73198 + gr_log_rwxmprotect(vma->vm_file);
73199 +
73200 + error = -EACCES;
73201 + goto out;
73202 + }
73203 +
73204 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73205 error = -EACCES;
73206 goto out;
73207 }
73208 @@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73209 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73210 if (error)
73211 goto out;
73212 +
73213 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
73214 +
73215 nstart = tmp;
73216
73217 if (nstart < prev->vm_end)
73218 diff --git a/mm/mremap.c b/mm/mremap.c
73219 index 506fa44..ccc0ba9 100644
73220 --- a/mm/mremap.c
73221 +++ b/mm/mremap.c
73222 @@ -113,6 +113,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73223 continue;
73224 pte = ptep_clear_flush(vma, old_addr, old_pte);
73225 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73226 +
73227 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73228 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73229 + pte = pte_exprotect(pte);
73230 +#endif
73231 +
73232 set_pte_at(mm, new_addr, new_pte, pte);
73233 }
73234
73235 @@ -272,6 +278,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73236 if (is_vm_hugetlb_page(vma))
73237 goto Einval;
73238
73239 +#ifdef CONFIG_PAX_SEGMEXEC
73240 + if (pax_find_mirror_vma(vma))
73241 + goto Einval;
73242 +#endif
73243 +
73244 /* We can't remap across vm area boundaries */
73245 if (old_len > vma->vm_end - addr)
73246 goto Efault;
73247 @@ -328,20 +339,25 @@ static unsigned long mremap_to(unsigned long addr,
73248 unsigned long ret = -EINVAL;
73249 unsigned long charged = 0;
73250 unsigned long map_flags;
73251 + unsigned long pax_task_size = TASK_SIZE;
73252
73253 if (new_addr & ~PAGE_MASK)
73254 goto out;
73255
73256 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73257 +#ifdef CONFIG_PAX_SEGMEXEC
73258 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73259 + pax_task_size = SEGMEXEC_TASK_SIZE;
73260 +#endif
73261 +
73262 + pax_task_size -= PAGE_SIZE;
73263 +
73264 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73265 goto out;
73266
73267 /* Check if the location we're moving into overlaps the
73268 * old location at all, and fail if it does.
73269 */
73270 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
73271 - goto out;
73272 -
73273 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
73274 + if (addr + old_len > new_addr && new_addr + new_len > addr)
73275 goto out;
73276
73277 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73278 @@ -413,6 +429,7 @@ unsigned long do_mremap(unsigned long addr,
73279 struct vm_area_struct *vma;
73280 unsigned long ret = -EINVAL;
73281 unsigned long charged = 0;
73282 + unsigned long pax_task_size = TASK_SIZE;
73283
73284 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
73285 goto out;
73286 @@ -431,6 +448,17 @@ unsigned long do_mremap(unsigned long addr,
73287 if (!new_len)
73288 goto out;
73289
73290 +#ifdef CONFIG_PAX_SEGMEXEC
73291 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73292 + pax_task_size = SEGMEXEC_TASK_SIZE;
73293 +#endif
73294 +
73295 + pax_task_size -= PAGE_SIZE;
73296 +
73297 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73298 + old_len > pax_task_size || addr > pax_task_size-old_len)
73299 + goto out;
73300 +
73301 if (flags & MREMAP_FIXED) {
73302 if (flags & MREMAP_MAYMOVE)
73303 ret = mremap_to(addr, old_len, new_addr, new_len);
73304 @@ -480,6 +508,7 @@ unsigned long do_mremap(unsigned long addr,
73305 addr + new_len);
73306 }
73307 ret = addr;
73308 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73309 goto out;
73310 }
73311 }
73312 @@ -506,7 +535,13 @@ unsigned long do_mremap(unsigned long addr,
73313 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73314 if (ret)
73315 goto out;
73316 +
73317 + map_flags = vma->vm_flags;
73318 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73319 + if (!(ret & ~PAGE_MASK)) {
73320 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73321 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73322 + }
73323 }
73324 out:
73325 if (ret & ~PAGE_MASK)
73326 diff --git a/mm/nobootmem.c b/mm/nobootmem.c
73327 index 6e93dc7..c98df0c 100644
73328 --- a/mm/nobootmem.c
73329 +++ b/mm/nobootmem.c
73330 @@ -110,19 +110,30 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
73331 unsigned long __init free_all_memory_core_early(int nodeid)
73332 {
73333 int i;
73334 - u64 start, end;
73335 + u64 start, end, startrange, endrange;
73336 unsigned long count = 0;
73337 - struct range *range = NULL;
73338 + struct range *range = NULL, rangerange = { 0, 0 };
73339 int nr_range;
73340
73341 nr_range = get_free_all_memory_range(&range, nodeid);
73342 + startrange = __pa(range) >> PAGE_SHIFT;
73343 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
73344
73345 for (i = 0; i < nr_range; i++) {
73346 start = range[i].start;
73347 end = range[i].end;
73348 + if (start <= endrange && startrange < end) {
73349 + BUG_ON(rangerange.start | rangerange.end);
73350 + rangerange = range[i];
73351 + continue;
73352 + }
73353 count += end - start;
73354 __free_pages_memory(start, end);
73355 }
73356 + start = rangerange.start;
73357 + end = rangerange.end;
73358 + count += end - start;
73359 + __free_pages_memory(start, end);
73360
73361 return count;
73362 }
73363 diff --git a/mm/nommu.c b/mm/nommu.c
73364 index 4358032..e79b99f 100644
73365 --- a/mm/nommu.c
73366 +++ b/mm/nommu.c
73367 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73368 int sysctl_overcommit_ratio = 50; /* default is 50% */
73369 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73370 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73371 -int heap_stack_gap = 0;
73372
73373 atomic_long_t mmap_pages_allocated;
73374
73375 @@ -825,15 +824,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73376 EXPORT_SYMBOL(find_vma);
73377
73378 /*
73379 - * find a VMA
73380 - * - we don't extend stack VMAs under NOMMU conditions
73381 - */
73382 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73383 -{
73384 - return find_vma(mm, addr);
73385 -}
73386 -
73387 -/*
73388 * expand a stack to a given address
73389 * - not supported under NOMMU conditions
73390 */
73391 @@ -1553,6 +1543,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73392
73393 /* most fields are the same, copy all, and then fixup */
73394 *new = *vma;
73395 + INIT_LIST_HEAD(&new->anon_vma_chain);
73396 *region = *vma->vm_region;
73397 new->vm_region = region;
73398
73399 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73400 index e8fae15..18c0442 100644
73401 --- a/mm/page_alloc.c
73402 +++ b/mm/page_alloc.c
73403 @@ -340,7 +340,7 @@ out:
73404 * This usage means that zero-order pages may not be compound.
73405 */
73406
73407 -static void free_compound_page(struct page *page)
73408 +void free_compound_page(struct page *page)
73409 {
73410 __free_pages_ok(page, compound_order(page));
73411 }
73412 @@ -653,6 +653,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73413 int i;
73414 int bad = 0;
73415
73416 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73417 + unsigned long index = 1UL << order;
73418 +#endif
73419 +
73420 trace_mm_page_free_direct(page, order);
73421 kmemcheck_free_shadow(page, order);
73422
73423 @@ -668,6 +672,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73424 debug_check_no_obj_freed(page_address(page),
73425 PAGE_SIZE << order);
73426 }
73427 +
73428 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73429 + for (; index; --index)
73430 + sanitize_highpage(page + index - 1);
73431 +#endif
73432 +
73433 arch_free_page(page, order);
73434 kernel_map_pages(page, 1 << order, 0);
73435
73436 @@ -783,8 +793,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73437 arch_alloc_page(page, order);
73438 kernel_map_pages(page, 1 << order, 1);
73439
73440 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73441 if (gfp_flags & __GFP_ZERO)
73442 prep_zero_page(page, order, gfp_flags);
73443 +#endif
73444
73445 if (order && (gfp_flags & __GFP_COMP))
73446 prep_compound_page(page, order);
73447 @@ -2539,6 +2551,8 @@ void show_free_areas(unsigned int filter)
73448 int cpu;
73449 struct zone *zone;
73450
73451 + pax_track_stack();
73452 +
73453 for_each_populated_zone(zone) {
73454 if (skip_free_areas_node(filter, zone_to_nid(zone)))
73455 continue;
73456 @@ -3350,7 +3364,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73457 unsigned long pfn;
73458
73459 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73460 +#ifdef CONFIG_X86_32
73461 + /* boot failures in VMware 8 on 32bit vanilla since
73462 + this change */
73463 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73464 +#else
73465 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73466 +#endif
73467 return 1;
73468 }
73469 return 0;
73470 diff --git a/mm/percpu.c b/mm/percpu.c
73471 index 0ae7a09..613118e 100644
73472 --- a/mm/percpu.c
73473 +++ b/mm/percpu.c
73474 @@ -121,7 +121,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73475 static unsigned int pcpu_high_unit_cpu __read_mostly;
73476
73477 /* the address of the first chunk which starts with the kernel static area */
73478 -void *pcpu_base_addr __read_mostly;
73479 +void *pcpu_base_addr __read_only;
73480 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73481
73482 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73483 diff --git a/mm/rmap.c b/mm/rmap.c
73484 index 8005080..198c2cd 100644
73485 --- a/mm/rmap.c
73486 +++ b/mm/rmap.c
73487 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73488 struct anon_vma *anon_vma = vma->anon_vma;
73489 struct anon_vma_chain *avc;
73490
73491 +#ifdef CONFIG_PAX_SEGMEXEC
73492 + struct anon_vma_chain *avc_m = NULL;
73493 +#endif
73494 +
73495 might_sleep();
73496 if (unlikely(!anon_vma)) {
73497 struct mm_struct *mm = vma->vm_mm;
73498 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73499 if (!avc)
73500 goto out_enomem;
73501
73502 +#ifdef CONFIG_PAX_SEGMEXEC
73503 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73504 + if (!avc_m)
73505 + goto out_enomem_free_avc;
73506 +#endif
73507 +
73508 anon_vma = find_mergeable_anon_vma(vma);
73509 allocated = NULL;
73510 if (!anon_vma) {
73511 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73512 /* page_table_lock to protect against threads */
73513 spin_lock(&mm->page_table_lock);
73514 if (likely(!vma->anon_vma)) {
73515 +
73516 +#ifdef CONFIG_PAX_SEGMEXEC
73517 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73518 +
73519 + if (vma_m) {
73520 + BUG_ON(vma_m->anon_vma);
73521 + vma_m->anon_vma = anon_vma;
73522 + avc_m->anon_vma = anon_vma;
73523 + avc_m->vma = vma;
73524 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
73525 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
73526 + avc_m = NULL;
73527 + }
73528 +#endif
73529 +
73530 vma->anon_vma = anon_vma;
73531 avc->anon_vma = anon_vma;
73532 avc->vma = vma;
73533 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73534
73535 if (unlikely(allocated))
73536 put_anon_vma(allocated);
73537 +
73538 +#ifdef CONFIG_PAX_SEGMEXEC
73539 + if (unlikely(avc_m))
73540 + anon_vma_chain_free(avc_m);
73541 +#endif
73542 +
73543 if (unlikely(avc))
73544 anon_vma_chain_free(avc);
73545 }
73546 return 0;
73547
73548 out_enomem_free_avc:
73549 +
73550 +#ifdef CONFIG_PAX_SEGMEXEC
73551 + if (avc_m)
73552 + anon_vma_chain_free(avc_m);
73553 +#endif
73554 +
73555 anon_vma_chain_free(avc);
73556 out_enomem:
73557 return -ENOMEM;
73558 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
73559 * Attach the anon_vmas from src to dst.
73560 * Returns 0 on success, -ENOMEM on failure.
73561 */
73562 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73563 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73564 {
73565 struct anon_vma_chain *avc, *pavc;
73566 struct anon_vma *root = NULL;
73567 @@ -276,7 +313,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73568 * the corresponding VMA in the parent process is attached to.
73569 * Returns 0 on success, non-zero on failure.
73570 */
73571 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73572 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73573 {
73574 struct anon_vma_chain *avc;
73575 struct anon_vma *anon_vma;
73576 diff --git a/mm/shmem.c b/mm/shmem.c
73577 index 32f6763..431c405 100644
73578 --- a/mm/shmem.c
73579 +++ b/mm/shmem.c
73580 @@ -31,7 +31,7 @@
73581 #include <linux/module.h>
73582 #include <linux/swap.h>
73583
73584 -static struct vfsmount *shm_mnt;
73585 +struct vfsmount *shm_mnt;
73586
73587 #ifdef CONFIG_SHMEM
73588 /*
73589 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
73590 #define BOGO_DIRENT_SIZE 20
73591
73592 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73593 -#define SHORT_SYMLINK_LEN 128
73594 +#define SHORT_SYMLINK_LEN 64
73595
73596 struct shmem_xattr {
73597 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73598 @@ -769,6 +769,8 @@ static struct page *shmem_swapin(swp_entry_t swap, gfp_t gfp,
73599 struct mempolicy mpol, *spol;
73600 struct vm_area_struct pvma;
73601
73602 + pax_track_stack();
73603 +
73604 spol = mpol_cond_copy(&mpol,
73605 mpol_shared_policy_lookup(&info->policy, index));
73606
73607 @@ -2149,8 +2151,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73608 int err = -ENOMEM;
73609
73610 /* Round up to L1_CACHE_BYTES to resist false sharing */
73611 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73612 - L1_CACHE_BYTES), GFP_KERNEL);
73613 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73614 if (!sbinfo)
73615 return -ENOMEM;
73616
73617 diff --git a/mm/slab.c b/mm/slab.c
73618 index 893c76d..a742de2 100644
73619 --- a/mm/slab.c
73620 +++ b/mm/slab.c
73621 @@ -151,7 +151,7 @@
73622
73623 /* Legal flag mask for kmem_cache_create(). */
73624 #if DEBUG
73625 -# define CREATE_MASK (SLAB_RED_ZONE | \
73626 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73627 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73628 SLAB_CACHE_DMA | \
73629 SLAB_STORE_USER | \
73630 @@ -159,7 +159,7 @@
73631 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73632 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73633 #else
73634 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73635 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73636 SLAB_CACHE_DMA | \
73637 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73638 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73639 @@ -288,7 +288,7 @@ struct kmem_list3 {
73640 * Need this for bootstrapping a per node allocator.
73641 */
73642 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73643 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73644 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73645 #define CACHE_CACHE 0
73646 #define SIZE_AC MAX_NUMNODES
73647 #define SIZE_L3 (2 * MAX_NUMNODES)
73648 @@ -389,10 +389,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73649 if ((x)->max_freeable < i) \
73650 (x)->max_freeable = i; \
73651 } while (0)
73652 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73653 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73654 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73655 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73656 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73657 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73658 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73659 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73660 #else
73661 #define STATS_INC_ACTIVE(x) do { } while (0)
73662 #define STATS_DEC_ACTIVE(x) do { } while (0)
73663 @@ -538,7 +538,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73664 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73665 */
73666 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73667 - const struct slab *slab, void *obj)
73668 + const struct slab *slab, const void *obj)
73669 {
73670 u32 offset = (obj - slab->s_mem);
73671 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73672 @@ -564,7 +564,7 @@ struct cache_names {
73673 static struct cache_names __initdata cache_names[] = {
73674 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73675 #include <linux/kmalloc_sizes.h>
73676 - {NULL,}
73677 + {NULL}
73678 #undef CACHE
73679 };
73680
73681 @@ -1572,7 +1572,7 @@ void __init kmem_cache_init(void)
73682 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73683 sizes[INDEX_AC].cs_size,
73684 ARCH_KMALLOC_MINALIGN,
73685 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73686 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73687 NULL);
73688
73689 if (INDEX_AC != INDEX_L3) {
73690 @@ -1580,7 +1580,7 @@ void __init kmem_cache_init(void)
73691 kmem_cache_create(names[INDEX_L3].name,
73692 sizes[INDEX_L3].cs_size,
73693 ARCH_KMALLOC_MINALIGN,
73694 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73695 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73696 NULL);
73697 }
73698
73699 @@ -1598,7 +1598,7 @@ void __init kmem_cache_init(void)
73700 sizes->cs_cachep = kmem_cache_create(names->name,
73701 sizes->cs_size,
73702 ARCH_KMALLOC_MINALIGN,
73703 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73704 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73705 NULL);
73706 }
73707 #ifdef CONFIG_ZONE_DMA
73708 @@ -4327,10 +4327,10 @@ static int s_show(struct seq_file *m, void *p)
73709 }
73710 /* cpu stats */
73711 {
73712 - unsigned long allochit = atomic_read(&cachep->allochit);
73713 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73714 - unsigned long freehit = atomic_read(&cachep->freehit);
73715 - unsigned long freemiss = atomic_read(&cachep->freemiss);
73716 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73717 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73718 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73719 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73720
73721 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73722 allochit, allocmiss, freehit, freemiss);
73723 @@ -4587,15 +4587,70 @@ static const struct file_operations proc_slabstats_operations = {
73724
73725 static int __init slab_proc_init(void)
73726 {
73727 - proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
73728 + mode_t gr_mode = S_IRUGO;
73729 +
73730 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73731 + gr_mode = S_IRUSR;
73732 +#endif
73733 +
73734 + proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
73735 #ifdef CONFIG_DEBUG_SLAB_LEAK
73736 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73737 + proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
73738 #endif
73739 return 0;
73740 }
73741 module_init(slab_proc_init);
73742 #endif
73743
73744 +void check_object_size(const void *ptr, unsigned long n, bool to)
73745 +{
73746 +
73747 +#ifdef CONFIG_PAX_USERCOPY
73748 + struct page *page;
73749 + struct kmem_cache *cachep = NULL;
73750 + struct slab *slabp;
73751 + unsigned int objnr;
73752 + unsigned long offset;
73753 + const char *type;
73754 +
73755 + if (!n)
73756 + return;
73757 +
73758 + type = "<null>";
73759 + if (ZERO_OR_NULL_PTR(ptr))
73760 + goto report;
73761 +
73762 + if (!virt_addr_valid(ptr))
73763 + return;
73764 +
73765 + page = virt_to_head_page(ptr);
73766 +
73767 + type = "<process stack>";
73768 + if (!PageSlab(page)) {
73769 + if (object_is_on_stack(ptr, n) == -1)
73770 + goto report;
73771 + return;
73772 + }
73773 +
73774 + cachep = page_get_cache(page);
73775 + type = cachep->name;
73776 + if (!(cachep->flags & SLAB_USERCOPY))
73777 + goto report;
73778 +
73779 + slabp = page_get_slab(page);
73780 + objnr = obj_to_index(cachep, slabp, ptr);
73781 + BUG_ON(objnr >= cachep->num);
73782 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73783 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73784 + return;
73785 +
73786 +report:
73787 + pax_report_usercopy(ptr, n, to, type);
73788 +#endif
73789 +
73790 +}
73791 +EXPORT_SYMBOL(check_object_size);
73792 +
73793 /**
73794 * ksize - get the actual amount of memory allocated for a given object
73795 * @objp: Pointer to the object
73796 diff --git a/mm/slob.c b/mm/slob.c
73797 index bf39181..727f7a3 100644
73798 --- a/mm/slob.c
73799 +++ b/mm/slob.c
73800 @@ -29,7 +29,7 @@
73801 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73802 * alloc_pages() directly, allocating compound pages so the page order
73803 * does not have to be separately tracked, and also stores the exact
73804 - * allocation size in page->private so that it can be used to accurately
73805 + * allocation size in slob_page->size so that it can be used to accurately
73806 * provide ksize(). These objects are detected in kfree() because slob_page()
73807 * is false for them.
73808 *
73809 @@ -58,6 +58,7 @@
73810 */
73811
73812 #include <linux/kernel.h>
73813 +#include <linux/sched.h>
73814 #include <linux/slab.h>
73815 #include <linux/mm.h>
73816 #include <linux/swap.h> /* struct reclaim_state */
73817 @@ -102,7 +103,8 @@ struct slob_page {
73818 unsigned long flags; /* mandatory */
73819 atomic_t _count; /* mandatory */
73820 slobidx_t units; /* free units left in page */
73821 - unsigned long pad[2];
73822 + unsigned long pad[1];
73823 + unsigned long size; /* size when >=PAGE_SIZE */
73824 slob_t *free; /* first free slob_t in page */
73825 struct list_head list; /* linked list of free pages */
73826 };
73827 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73828 */
73829 static inline int is_slob_page(struct slob_page *sp)
73830 {
73831 - return PageSlab((struct page *)sp);
73832 + return PageSlab((struct page *)sp) && !sp->size;
73833 }
73834
73835 static inline void set_slob_page(struct slob_page *sp)
73836 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73837
73838 static inline struct slob_page *slob_page(const void *addr)
73839 {
73840 - return (struct slob_page *)virt_to_page(addr);
73841 + return (struct slob_page *)virt_to_head_page(addr);
73842 }
73843
73844 /*
73845 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73846 /*
73847 * Return the size of a slob block.
73848 */
73849 -static slobidx_t slob_units(slob_t *s)
73850 +static slobidx_t slob_units(const slob_t *s)
73851 {
73852 if (s->units > 0)
73853 return s->units;
73854 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73855 /*
73856 * Return the next free slob block pointer after this one.
73857 */
73858 -static slob_t *slob_next(slob_t *s)
73859 +static slob_t *slob_next(const slob_t *s)
73860 {
73861 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73862 slobidx_t next;
73863 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73864 /*
73865 * Returns true if s is the last free block in its page.
73866 */
73867 -static int slob_last(slob_t *s)
73868 +static int slob_last(const slob_t *s)
73869 {
73870 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73871 }
73872 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73873 if (!page)
73874 return NULL;
73875
73876 + set_slob_page(page);
73877 return page_address(page);
73878 }
73879
73880 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73881 if (!b)
73882 return NULL;
73883 sp = slob_page(b);
73884 - set_slob_page(sp);
73885
73886 spin_lock_irqsave(&slob_lock, flags);
73887 sp->units = SLOB_UNITS(PAGE_SIZE);
73888 sp->free = b;
73889 + sp->size = 0;
73890 INIT_LIST_HEAD(&sp->list);
73891 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
73892 set_slob_page_free(sp, slob_list);
73893 @@ -476,10 +479,9 @@ out:
73894 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
73895 */
73896
73897 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73898 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
73899 {
73900 - unsigned int *m;
73901 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73902 + slob_t *m;
73903 void *ret;
73904
73905 gfp &= gfp_allowed_mask;
73906 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73907
73908 if (!m)
73909 return NULL;
73910 - *m = size;
73911 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
73912 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
73913 + m[0].units = size;
73914 + m[1].units = align;
73915 ret = (void *)m + align;
73916
73917 trace_kmalloc_node(_RET_IP_, ret,
73918 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73919 gfp |= __GFP_COMP;
73920 ret = slob_new_pages(gfp, order, node);
73921 if (ret) {
73922 - struct page *page;
73923 - page = virt_to_page(ret);
73924 - page->private = size;
73925 + struct slob_page *sp;
73926 + sp = slob_page(ret);
73927 + sp->size = size;
73928 }
73929
73930 trace_kmalloc_node(_RET_IP_, ret,
73931 size, PAGE_SIZE << order, gfp, node);
73932 }
73933
73934 - kmemleak_alloc(ret, size, 1, gfp);
73935 + return ret;
73936 +}
73937 +
73938 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73939 +{
73940 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73941 + void *ret = __kmalloc_node_align(size, gfp, node, align);
73942 +
73943 + if (!ZERO_OR_NULL_PTR(ret))
73944 + kmemleak_alloc(ret, size, 1, gfp);
73945 return ret;
73946 }
73947 EXPORT_SYMBOL(__kmalloc_node);
73948 @@ -533,13 +547,92 @@ void kfree(const void *block)
73949 sp = slob_page(block);
73950 if (is_slob_page(sp)) {
73951 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73952 - unsigned int *m = (unsigned int *)(block - align);
73953 - slob_free(m, *m + align);
73954 - } else
73955 + slob_t *m = (slob_t *)(block - align);
73956 + slob_free(m, m[0].units + align);
73957 + } else {
73958 + clear_slob_page(sp);
73959 + free_slob_page(sp);
73960 + sp->size = 0;
73961 put_page(&sp->page);
73962 + }
73963 }
73964 EXPORT_SYMBOL(kfree);
73965
73966 +void check_object_size(const void *ptr, unsigned long n, bool to)
73967 +{
73968 +
73969 +#ifdef CONFIG_PAX_USERCOPY
73970 + struct slob_page *sp;
73971 + const slob_t *free;
73972 + const void *base;
73973 + unsigned long flags;
73974 + const char *type;
73975 +
73976 + if (!n)
73977 + return;
73978 +
73979 + type = "<null>";
73980 + if (ZERO_OR_NULL_PTR(ptr))
73981 + goto report;
73982 +
73983 + if (!virt_addr_valid(ptr))
73984 + return;
73985 +
73986 + type = "<process stack>";
73987 + sp = slob_page(ptr);
73988 + if (!PageSlab((struct page*)sp)) {
73989 + if (object_is_on_stack(ptr, n) == -1)
73990 + goto report;
73991 + return;
73992 + }
73993 +
73994 + type = "<slob>";
73995 + if (sp->size) {
73996 + base = page_address(&sp->page);
73997 + if (base <= ptr && n <= sp->size - (ptr - base))
73998 + return;
73999 + goto report;
74000 + }
74001 +
74002 + /* some tricky double walking to find the chunk */
74003 + spin_lock_irqsave(&slob_lock, flags);
74004 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74005 + free = sp->free;
74006 +
74007 + while (!slob_last(free) && (void *)free <= ptr) {
74008 + base = free + slob_units(free);
74009 + free = slob_next(free);
74010 + }
74011 +
74012 + while (base < (void *)free) {
74013 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74014 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74015 + int offset;
74016 +
74017 + if (ptr < base + align)
74018 + break;
74019 +
74020 + offset = ptr - base - align;
74021 + if (offset >= m) {
74022 + base += size;
74023 + continue;
74024 + }
74025 +
74026 + if (n > m - offset)
74027 + break;
74028 +
74029 + spin_unlock_irqrestore(&slob_lock, flags);
74030 + return;
74031 + }
74032 +
74033 + spin_unlock_irqrestore(&slob_lock, flags);
74034 +report:
74035 + pax_report_usercopy(ptr, n, to, type);
74036 +#endif
74037 +
74038 +}
74039 +EXPORT_SYMBOL(check_object_size);
74040 +
74041 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74042 size_t ksize(const void *block)
74043 {
74044 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
74045 sp = slob_page(block);
74046 if (is_slob_page(sp)) {
74047 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74048 - unsigned int *m = (unsigned int *)(block - align);
74049 - return SLOB_UNITS(*m) * SLOB_UNIT;
74050 + slob_t *m = (slob_t *)(block - align);
74051 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74052 } else
74053 - return sp->page.private;
74054 + return sp->size;
74055 }
74056 EXPORT_SYMBOL(ksize);
74057
74058 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74059 {
74060 struct kmem_cache *c;
74061
74062 +#ifdef CONFIG_PAX_USERCOPY
74063 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74064 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74065 +#else
74066 c = slob_alloc(sizeof(struct kmem_cache),
74067 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74068 +#endif
74069
74070 if (c) {
74071 c->name = name;
74072 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74073
74074 lockdep_trace_alloc(flags);
74075
74076 +#ifdef CONFIG_PAX_USERCOPY
74077 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74078 +#else
74079 if (c->size < PAGE_SIZE) {
74080 b = slob_alloc(c->size, flags, c->align, node);
74081 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74082 SLOB_UNITS(c->size) * SLOB_UNIT,
74083 flags, node);
74084 } else {
74085 + struct slob_page *sp;
74086 +
74087 b = slob_new_pages(flags, get_order(c->size), node);
74088 + sp = slob_page(b);
74089 + sp->size = c->size;
74090 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74091 PAGE_SIZE << get_order(c->size),
74092 flags, node);
74093 }
74094 +#endif
74095
74096 if (c->ctor)
74097 c->ctor(b);
74098 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74099
74100 static void __kmem_cache_free(void *b, int size)
74101 {
74102 - if (size < PAGE_SIZE)
74103 + struct slob_page *sp = slob_page(b);
74104 +
74105 + if (is_slob_page(sp))
74106 slob_free(b, size);
74107 - else
74108 + else {
74109 + clear_slob_page(sp);
74110 + free_slob_page(sp);
74111 + sp->size = 0;
74112 slob_free_pages(b, get_order(size));
74113 + }
74114 }
74115
74116 static void kmem_rcu_free(struct rcu_head *head)
74117 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74118
74119 void kmem_cache_free(struct kmem_cache *c, void *b)
74120 {
74121 + int size = c->size;
74122 +
74123 +#ifdef CONFIG_PAX_USERCOPY
74124 + if (size + c->align < PAGE_SIZE) {
74125 + size += c->align;
74126 + b -= c->align;
74127 + }
74128 +#endif
74129 +
74130 kmemleak_free_recursive(b, c->flags);
74131 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74132 struct slob_rcu *slob_rcu;
74133 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74134 - slob_rcu->size = c->size;
74135 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74136 + slob_rcu->size = size;
74137 call_rcu(&slob_rcu->head, kmem_rcu_free);
74138 } else {
74139 - __kmem_cache_free(b, c->size);
74140 + __kmem_cache_free(b, size);
74141 }
74142
74143 +#ifdef CONFIG_PAX_USERCOPY
74144 + trace_kfree(_RET_IP_, b);
74145 +#else
74146 trace_kmem_cache_free(_RET_IP_, b);
74147 +#endif
74148 +
74149 }
74150 EXPORT_SYMBOL(kmem_cache_free);
74151
74152 diff --git a/mm/slub.c b/mm/slub.c
74153 index f73234d..ce9940d 100644
74154 --- a/mm/slub.c
74155 +++ b/mm/slub.c
74156 @@ -208,7 +208,7 @@ struct track {
74157
74158 enum track_item { TRACK_ALLOC, TRACK_FREE };
74159
74160 -#ifdef CONFIG_SYSFS
74161 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74162 static int sysfs_slab_add(struct kmem_cache *);
74163 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74164 static void sysfs_slab_remove(struct kmem_cache *);
74165 @@ -556,7 +556,7 @@ static void print_track(const char *s, struct track *t)
74166 if (!t->addr)
74167 return;
74168
74169 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74170 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74171 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74172 #ifdef CONFIG_STACKTRACE
74173 {
74174 @@ -2461,6 +2461,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74175
74176 page = virt_to_head_page(x);
74177
74178 + BUG_ON(!PageSlab(page));
74179 +
74180 slab_free(s, page, x, _RET_IP_);
74181
74182 trace_kmem_cache_free(_RET_IP_, x);
74183 @@ -2494,7 +2496,7 @@ static int slub_min_objects;
74184 * Merge control. If this is set then no merging of slab caches will occur.
74185 * (Could be removed. This was introduced to pacify the merge skeptics.)
74186 */
74187 -static int slub_nomerge;
74188 +static int slub_nomerge = 1;
74189
74190 /*
74191 * Calculate the order of allocation given an slab object size.
74192 @@ -2917,7 +2919,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74193 * list to avoid pounding the page allocator excessively.
74194 */
74195 set_min_partial(s, ilog2(s->size));
74196 - s->refcount = 1;
74197 + atomic_set(&s->refcount, 1);
74198 #ifdef CONFIG_NUMA
74199 s->remote_node_defrag_ratio = 1000;
74200 #endif
74201 @@ -3022,8 +3024,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74202 void kmem_cache_destroy(struct kmem_cache *s)
74203 {
74204 down_write(&slub_lock);
74205 - s->refcount--;
74206 - if (!s->refcount) {
74207 + if (atomic_dec_and_test(&s->refcount)) {
74208 list_del(&s->list);
74209 if (kmem_cache_close(s)) {
74210 printk(KERN_ERR "SLUB %s: %s called for cache that "
74211 @@ -3233,6 +3234,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74212 EXPORT_SYMBOL(__kmalloc_node);
74213 #endif
74214
74215 +void check_object_size(const void *ptr, unsigned long n, bool to)
74216 +{
74217 +
74218 +#ifdef CONFIG_PAX_USERCOPY
74219 + struct page *page;
74220 + struct kmem_cache *s = NULL;
74221 + unsigned long offset;
74222 + const char *type;
74223 +
74224 + if (!n)
74225 + return;
74226 +
74227 + type = "<null>";
74228 + if (ZERO_OR_NULL_PTR(ptr))
74229 + goto report;
74230 +
74231 + if (!virt_addr_valid(ptr))
74232 + return;
74233 +
74234 + page = virt_to_head_page(ptr);
74235 +
74236 + type = "<process stack>";
74237 + if (!PageSlab(page)) {
74238 + if (object_is_on_stack(ptr, n) == -1)
74239 + goto report;
74240 + return;
74241 + }
74242 +
74243 + s = page->slab;
74244 + type = s->name;
74245 + if (!(s->flags & SLAB_USERCOPY))
74246 + goto report;
74247 +
74248 + offset = (ptr - page_address(page)) % s->size;
74249 + if (offset <= s->objsize && n <= s->objsize - offset)
74250 + return;
74251 +
74252 +report:
74253 + pax_report_usercopy(ptr, n, to, type);
74254 +#endif
74255 +
74256 +}
74257 +EXPORT_SYMBOL(check_object_size);
74258 +
74259 size_t ksize(const void *object)
74260 {
74261 struct page *page;
74262 @@ -3507,7 +3552,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74263 int node;
74264
74265 list_add(&s->list, &slab_caches);
74266 - s->refcount = -1;
74267 + atomic_set(&s->refcount, -1);
74268
74269 for_each_node_state(node, N_NORMAL_MEMORY) {
74270 struct kmem_cache_node *n = get_node(s, node);
74271 @@ -3624,17 +3669,17 @@ void __init kmem_cache_init(void)
74272
74273 /* Caches that are not of the two-to-the-power-of size */
74274 if (KMALLOC_MIN_SIZE <= 32) {
74275 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74276 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74277 caches++;
74278 }
74279
74280 if (KMALLOC_MIN_SIZE <= 64) {
74281 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74282 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74283 caches++;
74284 }
74285
74286 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74287 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74288 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74289 caches++;
74290 }
74291
74292 @@ -3702,7 +3747,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74293 /*
74294 * We may have set a slab to be unmergeable during bootstrap.
74295 */
74296 - if (s->refcount < 0)
74297 + if (atomic_read(&s->refcount) < 0)
74298 return 1;
74299
74300 return 0;
74301 @@ -3761,7 +3806,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74302 down_write(&slub_lock);
74303 s = find_mergeable(size, align, flags, name, ctor);
74304 if (s) {
74305 - s->refcount++;
74306 + atomic_inc(&s->refcount);
74307 /*
74308 * Adjust the object sizes so that we clear
74309 * the complete object on kzalloc.
74310 @@ -3770,7 +3815,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74311 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74312
74313 if (sysfs_slab_alias(s, name)) {
74314 - s->refcount--;
74315 + atomic_dec(&s->refcount);
74316 goto err;
74317 }
74318 up_write(&slub_lock);
74319 @@ -3898,7 +3943,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74320 }
74321 #endif
74322
74323 -#ifdef CONFIG_SYSFS
74324 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74325 static int count_inuse(struct page *page)
74326 {
74327 return page->inuse;
74328 @@ -4285,12 +4330,12 @@ static void resiliency_test(void)
74329 validate_slab_cache(kmalloc_caches[9]);
74330 }
74331 #else
74332 -#ifdef CONFIG_SYSFS
74333 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74334 static void resiliency_test(void) {};
74335 #endif
74336 #endif
74337
74338 -#ifdef CONFIG_SYSFS
74339 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74340 enum slab_stat_type {
74341 SL_ALL, /* All slabs */
74342 SL_PARTIAL, /* Only partially allocated slabs */
74343 @@ -4500,7 +4545,7 @@ SLAB_ATTR_RO(ctor);
74344
74345 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74346 {
74347 - return sprintf(buf, "%d\n", s->refcount - 1);
74348 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74349 }
74350 SLAB_ATTR_RO(aliases);
74351
74352 @@ -5030,6 +5075,7 @@ static char *create_unique_id(struct kmem_cache *s)
74353 return name;
74354 }
74355
74356 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74357 static int sysfs_slab_add(struct kmem_cache *s)
74358 {
74359 int err;
74360 @@ -5092,6 +5138,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74361 kobject_del(&s->kobj);
74362 kobject_put(&s->kobj);
74363 }
74364 +#endif
74365
74366 /*
74367 * Need to buffer aliases during bootup until sysfs becomes
74368 @@ -5105,6 +5152,7 @@ struct saved_alias {
74369
74370 static struct saved_alias *alias_list;
74371
74372 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74373 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74374 {
74375 struct saved_alias *al;
74376 @@ -5127,6 +5175,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74377 alias_list = al;
74378 return 0;
74379 }
74380 +#endif
74381
74382 static int __init slab_sysfs_init(void)
74383 {
74384 @@ -5262,7 +5311,13 @@ static const struct file_operations proc_slabinfo_operations = {
74385
74386 static int __init slab_proc_init(void)
74387 {
74388 - proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
74389 + mode_t gr_mode = S_IRUGO;
74390 +
74391 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74392 + gr_mode = S_IRUSR;
74393 +#endif
74394 +
74395 + proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
74396 return 0;
74397 }
74398 module_init(slab_proc_init);
74399 diff --git a/mm/swap.c b/mm/swap.c
74400 index 87627f1..8a9eb34 100644
74401 --- a/mm/swap.c
74402 +++ b/mm/swap.c
74403 @@ -31,6 +31,7 @@
74404 #include <linux/backing-dev.h>
74405 #include <linux/memcontrol.h>
74406 #include <linux/gfp.h>
74407 +#include <linux/hugetlb.h>
74408
74409 #include "internal.h"
74410
74411 @@ -71,6 +72,8 @@ static void __put_compound_page(struct page *page)
74412
74413 __page_cache_release(page);
74414 dtor = get_compound_page_dtor(page);
74415 + if (!PageHuge(page))
74416 + BUG_ON(dtor != free_compound_page);
74417 (*dtor)(page);
74418 }
74419
74420 diff --git a/mm/swapfile.c b/mm/swapfile.c
74421 index 17bc224..1677059 100644
74422 --- a/mm/swapfile.c
74423 +++ b/mm/swapfile.c
74424 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(swapon_mutex);
74425
74426 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74427 /* Activity counter to indicate that a swapon or swapoff has occurred */
74428 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74429 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74430
74431 static inline unsigned char swap_count(unsigned char ent)
74432 {
74433 @@ -1671,7 +1671,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74434 }
74435 filp_close(swap_file, NULL);
74436 err = 0;
74437 - atomic_inc(&proc_poll_event);
74438 + atomic_inc_unchecked(&proc_poll_event);
74439 wake_up_interruptible(&proc_poll_wait);
74440
74441 out_dput:
74442 @@ -1687,8 +1687,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74443
74444 poll_wait(file, &proc_poll_wait, wait);
74445
74446 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74447 - seq->poll_event = atomic_read(&proc_poll_event);
74448 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74449 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74450 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74451 }
74452
74453 @@ -1786,7 +1786,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74454 return ret;
74455
74456 seq = file->private_data;
74457 - seq->poll_event = atomic_read(&proc_poll_event);
74458 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74459 return 0;
74460 }
74461
74462 @@ -2124,7 +2124,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74463 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74464
74465 mutex_unlock(&swapon_mutex);
74466 - atomic_inc(&proc_poll_event);
74467 + atomic_inc_unchecked(&proc_poll_event);
74468 wake_up_interruptible(&proc_poll_wait);
74469
74470 if (S_ISREG(inode->i_mode))
74471 diff --git a/mm/util.c b/mm/util.c
74472 index 88ea1bd..0f1dfdb 100644
74473 --- a/mm/util.c
74474 +++ b/mm/util.c
74475 @@ -114,6 +114,7 @@ EXPORT_SYMBOL(memdup_user);
74476 * allocated buffer. Use this if you don't want to free the buffer immediately
74477 * like, for example, with RCU.
74478 */
74479 +#undef __krealloc
74480 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
74481 {
74482 void *ret;
74483 @@ -147,6 +148,7 @@ EXPORT_SYMBOL(__krealloc);
74484 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
74485 * %NULL pointer, the object pointed to is freed.
74486 */
74487 +#undef krealloc
74488 void *krealloc(const void *p, size_t new_size, gfp_t flags)
74489 {
74490 void *ret;
74491 @@ -243,6 +245,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
74492 void arch_pick_mmap_layout(struct mm_struct *mm)
74493 {
74494 mm->mmap_base = TASK_UNMAPPED_BASE;
74495 +
74496 +#ifdef CONFIG_PAX_RANDMMAP
74497 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74498 + mm->mmap_base += mm->delta_mmap;
74499 +#endif
74500 +
74501 mm->get_unmapped_area = arch_get_unmapped_area;
74502 mm->unmap_area = arch_unmap_area;
74503 }
74504 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74505 index 3a65d6f7..39d5e33 100644
74506 --- a/mm/vmalloc.c
74507 +++ b/mm/vmalloc.c
74508 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74509
74510 pte = pte_offset_kernel(pmd, addr);
74511 do {
74512 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74513 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74514 +
74515 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74516 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74517 + BUG_ON(!pte_exec(*pte));
74518 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74519 + continue;
74520 + }
74521 +#endif
74522 +
74523 + {
74524 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74525 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74526 + }
74527 } while (pte++, addr += PAGE_SIZE, addr != end);
74528 }
74529
74530 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74531 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74532 {
74533 pte_t *pte;
74534 + int ret = -ENOMEM;
74535
74536 /*
74537 * nr is a running index into the array which helps higher level
74538 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74539 pte = pte_alloc_kernel(pmd, addr);
74540 if (!pte)
74541 return -ENOMEM;
74542 +
74543 + pax_open_kernel();
74544 do {
74545 struct page *page = pages[*nr];
74546
74547 - if (WARN_ON(!pte_none(*pte)))
74548 - return -EBUSY;
74549 - if (WARN_ON(!page))
74550 - return -ENOMEM;
74551 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74552 + if (pgprot_val(prot) & _PAGE_NX)
74553 +#endif
74554 +
74555 + if (WARN_ON(!pte_none(*pte))) {
74556 + ret = -EBUSY;
74557 + goto out;
74558 + }
74559 + if (WARN_ON(!page)) {
74560 + ret = -ENOMEM;
74561 + goto out;
74562 + }
74563 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74564 (*nr)++;
74565 } while (pte++, addr += PAGE_SIZE, addr != end);
74566 - return 0;
74567 + ret = 0;
74568 +out:
74569 + pax_close_kernel();
74570 + return ret;
74571 }
74572
74573 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74574 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74575 * and fall back on vmalloc() if that fails. Others
74576 * just put it in the vmalloc space.
74577 */
74578 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74579 +#ifdef CONFIG_MODULES
74580 +#ifdef MODULES_VADDR
74581 unsigned long addr = (unsigned long)x;
74582 if (addr >= MODULES_VADDR && addr < MODULES_END)
74583 return 1;
74584 #endif
74585 +
74586 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74587 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74588 + return 1;
74589 +#endif
74590 +
74591 +#endif
74592 +
74593 return is_vmalloc_addr(x);
74594 }
74595
74596 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74597
74598 if (!pgd_none(*pgd)) {
74599 pud_t *pud = pud_offset(pgd, addr);
74600 +#ifdef CONFIG_X86
74601 + if (!pud_large(*pud))
74602 +#endif
74603 if (!pud_none(*pud)) {
74604 pmd_t *pmd = pmd_offset(pud, addr);
74605 +#ifdef CONFIG_X86
74606 + if (!pmd_large(*pmd))
74607 +#endif
74608 if (!pmd_none(*pmd)) {
74609 pte_t *ptep, pte;
74610
74611 @@ -1290,10 +1330,20 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74612 unsigned long align, unsigned long flags, unsigned long start,
74613 unsigned long end, int node, gfp_t gfp_mask, void *caller)
74614 {
74615 - static struct vmap_area *va;
74616 + struct vmap_area *va;
74617 struct vm_struct *area;
74618
74619 BUG_ON(in_interrupt());
74620 +
74621 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74622 + if (flags & VM_KERNEXEC) {
74623 + if (start != VMALLOC_START || end != VMALLOC_END)
74624 + return NULL;
74625 + start = (unsigned long)MODULES_EXEC_VADDR;
74626 + end = (unsigned long)MODULES_EXEC_END;
74627 + }
74628 +#endif
74629 +
74630 if (flags & VM_IOREMAP) {
74631 int bit = fls(size);
74632
74633 @@ -1526,6 +1576,11 @@ void *vmap(struct page **pages, unsigned int count,
74634 if (count > totalram_pages)
74635 return NULL;
74636
74637 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74638 + if (!(pgprot_val(prot) & _PAGE_NX))
74639 + flags |= VM_KERNEXEC;
74640 +#endif
74641 +
74642 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74643 __builtin_return_address(0));
74644 if (!area)
74645 @@ -1627,6 +1682,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74646 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74647 return NULL;
74648
74649 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74650 + if (!(pgprot_val(prot) & _PAGE_NX))
74651 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74652 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74653 + else
74654 +#endif
74655 +
74656 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74657 start, end, node, gfp_mask, caller);
74658
74659 @@ -1674,6 +1736,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
74660 gfp_mask, prot, node, caller);
74661 }
74662
74663 +#undef __vmalloc
74664 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
74665 {
74666 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
74667 @@ -1697,6 +1760,7 @@ static inline void *__vmalloc_node_flags(unsigned long size,
74668 * For tight control over page level allocator and protection flags
74669 * use __vmalloc() instead.
74670 */
74671 +#undef vmalloc
74672 void *vmalloc(unsigned long size)
74673 {
74674 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
74675 @@ -1713,6 +1777,7 @@ EXPORT_SYMBOL(vmalloc);
74676 * For tight control over page level allocator and protection flags
74677 * use __vmalloc() instead.
74678 */
74679 +#undef vzalloc
74680 void *vzalloc(unsigned long size)
74681 {
74682 return __vmalloc_node_flags(size, -1,
74683 @@ -1727,6 +1792,7 @@ EXPORT_SYMBOL(vzalloc);
74684 * The resulting memory area is zeroed so it can be mapped to userspace
74685 * without leaking data.
74686 */
74687 +#undef vmalloc_user
74688 void *vmalloc_user(unsigned long size)
74689 {
74690 struct vm_struct *area;
74691 @@ -1754,6 +1820,7 @@ EXPORT_SYMBOL(vmalloc_user);
74692 * For tight control over page level allocator and protection flags
74693 * use __vmalloc() instead.
74694 */
74695 +#undef vmalloc_node
74696 void *vmalloc_node(unsigned long size, int node)
74697 {
74698 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
74699 @@ -1773,6 +1840,7 @@ EXPORT_SYMBOL(vmalloc_node);
74700 * For tight control over page level allocator and protection flags
74701 * use __vmalloc_node() instead.
74702 */
74703 +#undef vzalloc_node
74704 void *vzalloc_node(unsigned long size, int node)
74705 {
74706 return __vmalloc_node_flags(size, node,
74707 @@ -1795,10 +1863,10 @@ EXPORT_SYMBOL(vzalloc_node);
74708 * For tight control over page level allocator and protection flags
74709 * use __vmalloc() instead.
74710 */
74711 -
74712 +#undef vmalloc_exec
74713 void *vmalloc_exec(unsigned long size)
74714 {
74715 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74716 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74717 -1, __builtin_return_address(0));
74718 }
74719
74720 @@ -1817,6 +1885,7 @@ void *vmalloc_exec(unsigned long size)
74721 * Allocate enough 32bit PA addressable pages to cover @size from the
74722 * page level allocator and map them into contiguous kernel virtual space.
74723 */
74724 +#undef vmalloc_32
74725 void *vmalloc_32(unsigned long size)
74726 {
74727 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
74728 @@ -1831,6 +1900,7 @@ EXPORT_SYMBOL(vmalloc_32);
74729 * The resulting memory area is 32bit addressable and zeroed so it can be
74730 * mapped to userspace without leaking data.
74731 */
74732 +#undef vmalloc_32_user
74733 void *vmalloc_32_user(unsigned long size)
74734 {
74735 struct vm_struct *area;
74736 @@ -2093,6 +2163,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74737 unsigned long uaddr = vma->vm_start;
74738 unsigned long usize = vma->vm_end - vma->vm_start;
74739
74740 + BUG_ON(vma->vm_mirror);
74741 +
74742 if ((PAGE_SIZE-1) & (unsigned long)addr)
74743 return -EINVAL;
74744
74745 diff --git a/mm/vmstat.c b/mm/vmstat.c
74746 index d52b13d..381d1ac 100644
74747 --- a/mm/vmstat.c
74748 +++ b/mm/vmstat.c
74749 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74750 *
74751 * vm_stat contains the global counters
74752 */
74753 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
74754 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
74755 EXPORT_SYMBOL(vm_stat);
74756
74757 #ifdef CONFIG_SMP
74758 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74759 v = p->vm_stat_diff[i];
74760 p->vm_stat_diff[i] = 0;
74761 local_irq_restore(flags);
74762 - atomic_long_add(v, &zone->vm_stat[i]);
74763 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74764 global_diff[i] += v;
74765 #ifdef CONFIG_NUMA
74766 /* 3 seconds idle till flush */
74767 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74768
74769 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74770 if (global_diff[i])
74771 - atomic_long_add(global_diff[i], &vm_stat[i]);
74772 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74773 }
74774
74775 #endif
74776 @@ -1207,10 +1207,20 @@ static int __init setup_vmstat(void)
74777 start_cpu_timer(cpu);
74778 #endif
74779 #ifdef CONFIG_PROC_FS
74780 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74781 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74782 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74783 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74784 + {
74785 + mode_t gr_mode = S_IRUGO;
74786 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74787 + gr_mode = S_IRUSR;
74788 +#endif
74789 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74790 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74791 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74792 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74793 +#else
74794 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74795 +#endif
74796 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74797 + }
74798 #endif
74799 return 0;
74800 }
74801 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74802 index 8970ba1..e3361fe 100644
74803 --- a/net/8021q/vlan.c
74804 +++ b/net/8021q/vlan.c
74805 @@ -588,8 +588,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74806 err = -EPERM;
74807 if (!capable(CAP_NET_ADMIN))
74808 break;
74809 - if ((args.u.name_type >= 0) &&
74810 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74811 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74812 struct vlan_net *vn;
74813
74814 vn = net_generic(net, vlan_net_id);
74815 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74816 index fdfdb57..38d368c 100644
74817 --- a/net/9p/trans_fd.c
74818 +++ b/net/9p/trans_fd.c
74819 @@ -423,7 +423,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74820 oldfs = get_fs();
74821 set_fs(get_ds());
74822 /* The cast to a user pointer is valid due to the set_fs() */
74823 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74824 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74825 set_fs(oldfs);
74826
74827 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74828 diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
74829 index e317583..3c8aeaf 100644
74830 --- a/net/9p/trans_virtio.c
74831 +++ b/net/9p/trans_virtio.c
74832 @@ -327,7 +327,7 @@ req_retry_pinned:
74833 } else {
74834 char *pbuf;
74835 if (req->tc->pubuf)
74836 - pbuf = (__force char *) req->tc->pubuf;
74837 + pbuf = (char __force_kernel *) req->tc->pubuf;
74838 else
74839 pbuf = req->tc->pkbuf;
74840 outp = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM, pbuf,
74841 @@ -357,7 +357,7 @@ req_retry_pinned:
74842 } else {
74843 char *pbuf;
74844 if (req->tc->pubuf)
74845 - pbuf = (__force char *) req->tc->pubuf;
74846 + pbuf = (char __force_kernel *) req->tc->pubuf;
74847 else
74848 pbuf = req->tc->pkbuf;
74849
74850 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74851 index f41f026..fe76ea8 100644
74852 --- a/net/atm/atm_misc.c
74853 +++ b/net/atm/atm_misc.c
74854 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74855 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74856 return 1;
74857 atm_return(vcc, truesize);
74858 - atomic_inc(&vcc->stats->rx_drop);
74859 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74860 return 0;
74861 }
74862 EXPORT_SYMBOL(atm_charge);
74863 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74864 }
74865 }
74866 atm_return(vcc, guess);
74867 - atomic_inc(&vcc->stats->rx_drop);
74868 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74869 return NULL;
74870 }
74871 EXPORT_SYMBOL(atm_alloc_charge);
74872 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74873
74874 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74875 {
74876 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74877 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74878 __SONET_ITEMS
74879 #undef __HANDLE_ITEM
74880 }
74881 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74882
74883 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74884 {
74885 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74886 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74887 __SONET_ITEMS
74888 #undef __HANDLE_ITEM
74889 }
74890 diff --git a/net/atm/lec.h b/net/atm/lec.h
74891 index dfc0719..47c5322 100644
74892 --- a/net/atm/lec.h
74893 +++ b/net/atm/lec.h
74894 @@ -48,7 +48,7 @@ struct lane2_ops {
74895 const u8 *tlvs, u32 sizeoftlvs);
74896 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74897 const u8 *tlvs, u32 sizeoftlvs);
74898 -};
74899 +} __no_const;
74900
74901 /*
74902 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74903 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74904 index 0919a88..a23d54e 100644
74905 --- a/net/atm/mpc.h
74906 +++ b/net/atm/mpc.h
74907 @@ -33,7 +33,7 @@ struct mpoa_client {
74908 struct mpc_parameters parameters; /* parameters for this client */
74909
74910 const struct net_device_ops *old_ops;
74911 - struct net_device_ops new_ops;
74912 + net_device_ops_no_const new_ops;
74913 };
74914
74915
74916 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
74917 index d1b2d9a..7cc2219 100644
74918 --- a/net/atm/mpoa_caches.c
74919 +++ b/net/atm/mpoa_caches.c
74920 @@ -255,6 +255,8 @@ static void check_resolving_entries(struct mpoa_client *client)
74921 struct timeval now;
74922 struct k_message msg;
74923
74924 + pax_track_stack();
74925 +
74926 do_gettimeofday(&now);
74927
74928 read_lock_bh(&client->ingress_lock);
74929 diff --git a/net/atm/proc.c b/net/atm/proc.c
74930 index 0d020de..011c7bb 100644
74931 --- a/net/atm/proc.c
74932 +++ b/net/atm/proc.c
74933 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
74934 const struct k_atm_aal_stats *stats)
74935 {
74936 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
74937 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
74938 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
74939 - atomic_read(&stats->rx_drop));
74940 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
74941 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
74942 + atomic_read_unchecked(&stats->rx_drop));
74943 }
74944
74945 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
74946 diff --git a/net/atm/resources.c b/net/atm/resources.c
74947 index 23f45ce..c748f1a 100644
74948 --- a/net/atm/resources.c
74949 +++ b/net/atm/resources.c
74950 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
74951 static void copy_aal_stats(struct k_atm_aal_stats *from,
74952 struct atm_aal_stats *to)
74953 {
74954 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74955 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74956 __AAL_STAT_ITEMS
74957 #undef __HANDLE_ITEM
74958 }
74959 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
74960 static void subtract_aal_stats(struct k_atm_aal_stats *from,
74961 struct atm_aal_stats *to)
74962 {
74963 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74964 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
74965 __AAL_STAT_ITEMS
74966 #undef __HANDLE_ITEM
74967 }
74968 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
74969 index db7aacf..991e539 100644
74970 --- a/net/batman-adv/hard-interface.c
74971 +++ b/net/batman-adv/hard-interface.c
74972 @@ -347,8 +347,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
74973 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
74974 dev_add_pack(&hard_iface->batman_adv_ptype);
74975
74976 - atomic_set(&hard_iface->seqno, 1);
74977 - atomic_set(&hard_iface->frag_seqno, 1);
74978 + atomic_set_unchecked(&hard_iface->seqno, 1);
74979 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
74980 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
74981 hard_iface->net_dev->name);
74982
74983 diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
74984 index 0f32c81..82d1895 100644
74985 --- a/net/batman-adv/routing.c
74986 +++ b/net/batman-adv/routing.c
74987 @@ -656,7 +656,7 @@ void receive_bat_packet(const struct ethhdr *ethhdr,
74988 return;
74989
74990 /* could be changed by schedule_own_packet() */
74991 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
74992 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
74993
74994 has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0);
74995
74996 diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
74997 index 58d1447..2a66c8c 100644
74998 --- a/net/batman-adv/send.c
74999 +++ b/net/batman-adv/send.c
75000 @@ -326,7 +326,7 @@ void schedule_own_packet(struct hard_iface *hard_iface)
75001
75002 /* change sequence number to network order */
75003 batman_packet->seqno =
75004 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75005 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75006
75007 batman_packet->ttvn = atomic_read(&bat_priv->ttvn);
75008 batman_packet->tt_crc = htons((uint16_t)atomic_read(&bat_priv->tt_crc));
75009 @@ -343,7 +343,7 @@ void schedule_own_packet(struct hard_iface *hard_iface)
75010 else
75011 batman_packet->gw_flags = NO_FLAGS;
75012
75013 - atomic_inc(&hard_iface->seqno);
75014 + atomic_inc_unchecked(&hard_iface->seqno);
75015
75016 slide_own_bcast_window(hard_iface);
75017 send_time = own_send_time(bat_priv);
75018 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75019 index 05dd351..2ecd19b 100644
75020 --- a/net/batman-adv/soft-interface.c
75021 +++ b/net/batman-adv/soft-interface.c
75022 @@ -632,7 +632,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75023
75024 /* set broadcast sequence number */
75025 bcast_packet->seqno =
75026 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75027 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75028
75029 add_bcast_packet_to_list(bat_priv, skb, 1);
75030
75031 @@ -824,7 +824,7 @@ struct net_device *softif_create(const char *name)
75032 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75033
75034 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75035 - atomic_set(&bat_priv->bcast_seqno, 1);
75036 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75037 atomic_set(&bat_priv->ttvn, 0);
75038 atomic_set(&bat_priv->tt_local_changes, 0);
75039 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75040 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75041 index 51a0db7..b8a62be 100644
75042 --- a/net/batman-adv/types.h
75043 +++ b/net/batman-adv/types.h
75044 @@ -38,8 +38,8 @@ struct hard_iface {
75045 int16_t if_num;
75046 char if_status;
75047 struct net_device *net_dev;
75048 - atomic_t seqno;
75049 - atomic_t frag_seqno;
75050 + atomic_unchecked_t seqno;
75051 + atomic_unchecked_t frag_seqno;
75052 unsigned char *packet_buff;
75053 int packet_len;
75054 struct kobject *hardif_obj;
75055 @@ -153,7 +153,7 @@ struct bat_priv {
75056 atomic_t orig_interval; /* uint */
75057 atomic_t hop_penalty; /* uint */
75058 atomic_t log_level; /* uint */
75059 - atomic_t bcast_seqno;
75060 + atomic_unchecked_t bcast_seqno;
75061 atomic_t bcast_queue_left;
75062 atomic_t batman_queue_left;
75063 atomic_t ttvn; /* tranlation table version number */
75064 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75065 index 32b125f..f1447e0 100644
75066 --- a/net/batman-adv/unicast.c
75067 +++ b/net/batman-adv/unicast.c
75068 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75069 frag1->flags = UNI_FRAG_HEAD | large_tail;
75070 frag2->flags = large_tail;
75071
75072 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75073 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75074 frag1->seqno = htons(seqno - 1);
75075 frag2->seqno = htons(seqno);
75076
75077 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
75078 index ea7f031..0615edc 100644
75079 --- a/net/bluetooth/hci_conn.c
75080 +++ b/net/bluetooth/hci_conn.c
75081 @@ -218,7 +218,7 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
75082 cp.handle = cpu_to_le16(conn->handle);
75083 memcpy(cp.ltk, ltk, sizeof(cp.ltk));
75084 cp.ediv = ediv;
75085 - memcpy(cp.rand, rand, sizeof(rand));
75086 + memcpy(cp.rand, rand, sizeof(cp.rand));
75087
75088 hci_send_cmd(hdev, HCI_OP_LE_START_ENC, sizeof(cp), &cp);
75089 }
75090 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
75091 memset(&cp, 0, sizeof(cp));
75092
75093 cp.handle = cpu_to_le16(conn->handle);
75094 - memcpy(cp.ltk, ltk, sizeof(ltk));
75095 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
75096
75097 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
75098 }
75099 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75100 index b3bdb48..7ad90ac 100644
75101 --- a/net/bluetooth/l2cap_core.c
75102 +++ b/net/bluetooth/l2cap_core.c
75103 @@ -2145,7 +2145,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75104 void *ptr = req->data;
75105 int type, olen;
75106 unsigned long val;
75107 - struct l2cap_conf_rfc rfc;
75108 + struct l2cap_conf_rfc rfc = { .mode = L2CAP_MODE_BASIC };
75109
75110 BT_DBG("chan %p, rsp %p, len %d, req %p", chan, rsp, len, data);
75111
75112 @@ -2169,8 +2169,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75113 break;
75114
75115 case L2CAP_CONF_RFC:
75116 - if (olen == sizeof(rfc))
75117 - memcpy(&rfc, (void *)val, olen);
75118 + if (olen != sizeof(rfc))
75119 + break;
75120 +
75121 + memcpy(&rfc, (void *)val, olen);
75122
75123 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75124 rfc.mode != chan->mode)
75125 @@ -2258,12 +2260,24 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
75126
75127 switch (type) {
75128 case L2CAP_CONF_RFC:
75129 - if (olen == sizeof(rfc))
75130 - memcpy(&rfc, (void *)val, olen);
75131 + if (olen != sizeof(rfc))
75132 + break;
75133 +
75134 + memcpy(&rfc, (void *)val, olen);
75135 goto done;
75136 }
75137 }
75138
75139 + /* Use sane default values in case a misbehaving remote device
75140 + * did not send an RFC option.
75141 + */
75142 + rfc.mode = chan->mode;
75143 + rfc.retrans_timeout = cpu_to_le16(L2CAP_DEFAULT_RETRANS_TO);
75144 + rfc.monitor_timeout = cpu_to_le16(L2CAP_DEFAULT_MONITOR_TO);
75145 + rfc.max_pdu_size = cpu_to_le16(chan->imtu);
75146 +
75147 + BT_ERR("Expected RFC option was not found, using defaults");
75148 +
75149 done:
75150 switch (rfc.mode) {
75151 case L2CAP_MODE_ERTM:
75152 diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
75153 index e79ff75..215b57d 100644
75154 --- a/net/bridge/br_multicast.c
75155 +++ b/net/bridge/br_multicast.c
75156 @@ -1485,7 +1485,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
75157 nexthdr = ip6h->nexthdr;
75158 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
75159
75160 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
75161 + if (nexthdr != IPPROTO_ICMPV6)
75162 return 0;
75163
75164 /* Okay, we found ICMPv6 header */
75165 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75166 index 5864cc4..94cab18 100644
75167 --- a/net/bridge/netfilter/ebtables.c
75168 +++ b/net/bridge/netfilter/ebtables.c
75169 @@ -1513,7 +1513,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75170 tmp.valid_hooks = t->table->valid_hooks;
75171 }
75172 mutex_unlock(&ebt_mutex);
75173 - if (copy_to_user(user, &tmp, *len) != 0){
75174 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75175 BUGPRINT("c2u Didn't work\n");
75176 ret = -EFAULT;
75177 break;
75178 @@ -1781,6 +1781,8 @@ static int compat_copy_everything_to_user(struct ebt_table *t,
75179 int ret;
75180 void __user *pos;
75181
75182 + pax_track_stack();
75183 +
75184 memset(&tinfo, 0, sizeof(tinfo));
75185
75186 if (cmd == EBT_SO_GET_ENTRIES) {
75187 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
75188 index a986280..13444a1 100644
75189 --- a/net/caif/caif_socket.c
75190 +++ b/net/caif/caif_socket.c
75191 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
75192 #ifdef CONFIG_DEBUG_FS
75193 struct debug_fs_counter {
75194 atomic_t caif_nr_socks;
75195 - atomic_t caif_sock_create;
75196 - atomic_t num_connect_req;
75197 - atomic_t num_connect_resp;
75198 - atomic_t num_connect_fail_resp;
75199 - atomic_t num_disconnect;
75200 - atomic_t num_remote_shutdown_ind;
75201 - atomic_t num_tx_flow_off_ind;
75202 - atomic_t num_tx_flow_on_ind;
75203 - atomic_t num_rx_flow_off;
75204 - atomic_t num_rx_flow_on;
75205 + atomic_unchecked_t caif_sock_create;
75206 + atomic_unchecked_t num_connect_req;
75207 + atomic_unchecked_t num_connect_resp;
75208 + atomic_unchecked_t num_connect_fail_resp;
75209 + atomic_unchecked_t num_disconnect;
75210 + atomic_unchecked_t num_remote_shutdown_ind;
75211 + atomic_unchecked_t num_tx_flow_off_ind;
75212 + atomic_unchecked_t num_tx_flow_on_ind;
75213 + atomic_unchecked_t num_rx_flow_off;
75214 + atomic_unchecked_t num_rx_flow_on;
75215 };
75216 static struct debug_fs_counter cnt;
75217 #define dbfs_atomic_inc(v) atomic_inc_return(v)
75218 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
75219 #define dbfs_atomic_dec(v) atomic_dec_return(v)
75220 #else
75221 #define dbfs_atomic_inc(v) 0
75222 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75223 atomic_read(&cf_sk->sk.sk_rmem_alloc),
75224 sk_rcvbuf_lowwater(cf_sk));
75225 set_rx_flow_off(cf_sk);
75226 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75227 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75228 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75229 }
75230
75231 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75232 set_rx_flow_off(cf_sk);
75233 if (net_ratelimit())
75234 pr_debug("sending flow OFF due to rmem_schedule\n");
75235 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75236 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75237 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75238 }
75239 skb->dev = NULL;
75240 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
75241 switch (flow) {
75242 case CAIF_CTRLCMD_FLOW_ON_IND:
75243 /* OK from modem to start sending again */
75244 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
75245 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
75246 set_tx_flow_on(cf_sk);
75247 cf_sk->sk.sk_state_change(&cf_sk->sk);
75248 break;
75249
75250 case CAIF_CTRLCMD_FLOW_OFF_IND:
75251 /* Modem asks us to shut up */
75252 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
75253 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
75254 set_tx_flow_off(cf_sk);
75255 cf_sk->sk.sk_state_change(&cf_sk->sk);
75256 break;
75257 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
75258 /* We're now connected */
75259 caif_client_register_refcnt(&cf_sk->layer,
75260 cfsk_hold, cfsk_put);
75261 - dbfs_atomic_inc(&cnt.num_connect_resp);
75262 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
75263 cf_sk->sk.sk_state = CAIF_CONNECTED;
75264 set_tx_flow_on(cf_sk);
75265 cf_sk->sk.sk_state_change(&cf_sk->sk);
75266 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
75267
75268 case CAIF_CTRLCMD_INIT_FAIL_RSP:
75269 /* Connect request failed */
75270 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
75271 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
75272 cf_sk->sk.sk_err = ECONNREFUSED;
75273 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
75274 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75275 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
75276
75277 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
75278 /* Modem has closed this connection, or device is down. */
75279 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
75280 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
75281 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75282 cf_sk->sk.sk_err = ECONNRESET;
75283 set_rx_flow_on(cf_sk);
75284 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
75285 return;
75286
75287 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
75288 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
75289 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
75290 set_rx_flow_on(cf_sk);
75291 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
75292 }
75293 @@ -854,7 +855,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
75294 /*ifindex = id of the interface.*/
75295 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
75296
75297 - dbfs_atomic_inc(&cnt.num_connect_req);
75298 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
75299 cf_sk->layer.receive = caif_sktrecv_cb;
75300
75301 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
75302 @@ -943,7 +944,7 @@ static int caif_release(struct socket *sock)
75303 spin_unlock_bh(&sk->sk_receive_queue.lock);
75304 sock->sk = NULL;
75305
75306 - dbfs_atomic_inc(&cnt.num_disconnect);
75307 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
75308
75309 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
75310 if (cf_sk->debugfs_socket_dir != NULL)
75311 @@ -1122,7 +1123,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
75312 cf_sk->conn_req.protocol = protocol;
75313 /* Increase the number of sockets created. */
75314 dbfs_atomic_inc(&cnt.caif_nr_socks);
75315 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
75316 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
75317 #ifdef CONFIG_DEBUG_FS
75318 if (!IS_ERR(debugfsdir)) {
75319
75320 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75321 index e22671b..6598ea0 100644
75322 --- a/net/caif/cfctrl.c
75323 +++ b/net/caif/cfctrl.c
75324 @@ -9,6 +9,7 @@
75325 #include <linux/stddef.h>
75326 #include <linux/spinlock.h>
75327 #include <linux/slab.h>
75328 +#include <linux/sched.h>
75329 #include <net/caif/caif_layer.h>
75330 #include <net/caif/cfpkt.h>
75331 #include <net/caif/cfctrl.h>
75332 @@ -45,8 +46,8 @@ struct cflayer *cfctrl_create(void)
75333 dev_info.id = 0xff;
75334 memset(this, 0, sizeof(*this));
75335 cfsrvl_init(&this->serv, 0, &dev_info, false);
75336 - atomic_set(&this->req_seq_no, 1);
75337 - atomic_set(&this->rsp_seq_no, 1);
75338 + atomic_set_unchecked(&this->req_seq_no, 1);
75339 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75340 this->serv.layer.receive = cfctrl_recv;
75341 sprintf(this->serv.layer.name, "ctrl");
75342 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75343 @@ -132,8 +133,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75344 struct cfctrl_request_info *req)
75345 {
75346 spin_lock_bh(&ctrl->info_list_lock);
75347 - atomic_inc(&ctrl->req_seq_no);
75348 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75349 + atomic_inc_unchecked(&ctrl->req_seq_no);
75350 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75351 list_add_tail(&req->list, &ctrl->list);
75352 spin_unlock_bh(&ctrl->info_list_lock);
75353 }
75354 @@ -151,7 +152,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75355 if (p != first)
75356 pr_warn("Requests are not received in order\n");
75357
75358 - atomic_set(&ctrl->rsp_seq_no,
75359 + atomic_set_unchecked(&ctrl->rsp_seq_no,
75360 p->sequence_no);
75361 list_del(&p->list);
75362 goto out;
75363 @@ -364,6 +365,7 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
75364 struct cfctrl *cfctrl = container_obj(layer);
75365 struct cfctrl_request_info rsp, *req;
75366
75367 + pax_track_stack();
75368
75369 cfpkt_extr_head(pkt, &cmdrsp, 1);
75370 cmd = cmdrsp & CFCTRL_CMD_MASK;
75371 diff --git a/net/compat.c b/net/compat.c
75372 index c578d93..257fab7 100644
75373 --- a/net/compat.c
75374 +++ b/net/compat.c
75375 @@ -70,9 +70,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75376 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75377 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75378 return -EFAULT;
75379 - kmsg->msg_name = compat_ptr(tmp1);
75380 - kmsg->msg_iov = compat_ptr(tmp2);
75381 - kmsg->msg_control = compat_ptr(tmp3);
75382 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75383 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75384 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75385 return 0;
75386 }
75387
75388 @@ -84,7 +84,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75389
75390 if (kern_msg->msg_namelen) {
75391 if (mode == VERIFY_READ) {
75392 - int err = move_addr_to_kernel(kern_msg->msg_name,
75393 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75394 kern_msg->msg_namelen,
75395 kern_address);
75396 if (err < 0)
75397 @@ -95,7 +95,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75398 kern_msg->msg_name = NULL;
75399
75400 tot_len = iov_from_user_compat_to_kern(kern_iov,
75401 - (struct compat_iovec __user *)kern_msg->msg_iov,
75402 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
75403 kern_msg->msg_iovlen);
75404 if (tot_len >= 0)
75405 kern_msg->msg_iov = kern_iov;
75406 @@ -115,20 +115,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75407
75408 #define CMSG_COMPAT_FIRSTHDR(msg) \
75409 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75410 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75411 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75412 (struct compat_cmsghdr __user *)NULL)
75413
75414 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75415 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75416 (ucmlen) <= (unsigned long) \
75417 ((mhdr)->msg_controllen - \
75418 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75419 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75420
75421 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75422 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75423 {
75424 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75425 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75426 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75427 msg->msg_controllen)
75428 return NULL;
75429 return (struct compat_cmsghdr __user *)ptr;
75430 @@ -220,7 +220,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75431 {
75432 struct compat_timeval ctv;
75433 struct compat_timespec cts[3];
75434 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75435 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75436 struct compat_cmsghdr cmhdr;
75437 int cmlen;
75438
75439 @@ -272,7 +272,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75440
75441 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75442 {
75443 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75444 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75445 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75446 int fdnum = scm->fp->count;
75447 struct file **fp = scm->fp->fp;
75448 @@ -369,7 +369,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75449 return -EFAULT;
75450 old_fs = get_fs();
75451 set_fs(KERNEL_DS);
75452 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75453 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75454 set_fs(old_fs);
75455
75456 return err;
75457 @@ -430,7 +430,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75458 len = sizeof(ktime);
75459 old_fs = get_fs();
75460 set_fs(KERNEL_DS);
75461 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75462 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75463 set_fs(old_fs);
75464
75465 if (!err) {
75466 @@ -565,7 +565,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75467 case MCAST_JOIN_GROUP:
75468 case MCAST_LEAVE_GROUP:
75469 {
75470 - struct compat_group_req __user *gr32 = (void *)optval;
75471 + struct compat_group_req __user *gr32 = (void __user *)optval;
75472 struct group_req __user *kgr =
75473 compat_alloc_user_space(sizeof(struct group_req));
75474 u32 interface;
75475 @@ -586,7 +586,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75476 case MCAST_BLOCK_SOURCE:
75477 case MCAST_UNBLOCK_SOURCE:
75478 {
75479 - struct compat_group_source_req __user *gsr32 = (void *)optval;
75480 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75481 struct group_source_req __user *kgsr = compat_alloc_user_space(
75482 sizeof(struct group_source_req));
75483 u32 interface;
75484 @@ -607,7 +607,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75485 }
75486 case MCAST_MSFILTER:
75487 {
75488 - struct compat_group_filter __user *gf32 = (void *)optval;
75489 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75490 struct group_filter __user *kgf;
75491 u32 interface, fmode, numsrc;
75492
75493 @@ -645,7 +645,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75494 char __user *optval, int __user *optlen,
75495 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75496 {
75497 - struct compat_group_filter __user *gf32 = (void *)optval;
75498 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75499 struct group_filter __user *kgf;
75500 int __user *koptlen;
75501 u32 interface, fmode, numsrc;
75502 diff --git a/net/core/datagram.c b/net/core/datagram.c
75503 index 18ac112..fe95ed9 100644
75504 --- a/net/core/datagram.c
75505 +++ b/net/core/datagram.c
75506 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75507 }
75508
75509 kfree_skb(skb);
75510 - atomic_inc(&sk->sk_drops);
75511 + atomic_inc_unchecked(&sk->sk_drops);
75512 sk_mem_reclaim_partial(sk);
75513
75514 return err;
75515 diff --git a/net/core/dev.c b/net/core/dev.c
75516 index ae5cf2d..2c950a1 100644
75517 --- a/net/core/dev.c
75518 +++ b/net/core/dev.c
75519 @@ -1135,10 +1135,14 @@ void dev_load(struct net *net, const char *name)
75520 if (no_module && capable(CAP_NET_ADMIN))
75521 no_module = request_module("netdev-%s", name);
75522 if (no_module && capable(CAP_SYS_MODULE)) {
75523 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75524 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75525 +#else
75526 if (!request_module("%s", name))
75527 pr_err("Loading kernel module for a network device "
75528 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
75529 "instead\n", name);
75530 +#endif
75531 }
75532 }
75533 EXPORT_SYMBOL(dev_load);
75534 @@ -1977,7 +1981,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75535
75536 struct dev_gso_cb {
75537 void (*destructor)(struct sk_buff *skb);
75538 -};
75539 +} __no_const;
75540
75541 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75542
75543 @@ -2930,7 +2934,7 @@ int netif_rx_ni(struct sk_buff *skb)
75544 }
75545 EXPORT_SYMBOL(netif_rx_ni);
75546
75547 -static void net_tx_action(struct softirq_action *h)
75548 +static void net_tx_action(void)
75549 {
75550 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75551
75552 @@ -3779,7 +3783,7 @@ void netif_napi_del(struct napi_struct *napi)
75553 }
75554 EXPORT_SYMBOL(netif_napi_del);
75555
75556 -static void net_rx_action(struct softirq_action *h)
75557 +static void net_rx_action(void)
75558 {
75559 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75560 unsigned long time_limit = jiffies + 2;
75561 diff --git a/net/core/flow.c b/net/core/flow.c
75562 index d6968e5..1690d9d 100644
75563 --- a/net/core/flow.c
75564 +++ b/net/core/flow.c
75565 @@ -61,7 +61,7 @@ struct flow_cache {
75566 struct timer_list rnd_timer;
75567 };
75568
75569 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75570 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75571 EXPORT_SYMBOL(flow_cache_genid);
75572 static struct flow_cache flow_cache_global;
75573 static struct kmem_cache *flow_cachep __read_mostly;
75574 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75575
75576 static int flow_entry_valid(struct flow_cache_entry *fle)
75577 {
75578 - if (atomic_read(&flow_cache_genid) != fle->genid)
75579 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75580 return 0;
75581 if (fle->object && !fle->object->ops->check(fle->object))
75582 return 0;
75583 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75584 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75585 fcp->hash_count++;
75586 }
75587 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75588 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75589 flo = fle->object;
75590 if (!flo)
75591 goto ret_object;
75592 @@ -280,7 +280,7 @@ nocache:
75593 }
75594 flo = resolver(net, key, family, dir, flo, ctx);
75595 if (fle) {
75596 - fle->genid = atomic_read(&flow_cache_genid);
75597 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75598 if (!IS_ERR(flo))
75599 fle->object = flo;
75600 else
75601 diff --git a/net/core/iovec.c b/net/core/iovec.c
75602 index c40f27e..7f49254 100644
75603 --- a/net/core/iovec.c
75604 +++ b/net/core/iovec.c
75605 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75606 if (m->msg_namelen) {
75607 if (mode == VERIFY_READ) {
75608 void __user *namep;
75609 - namep = (void __user __force *) m->msg_name;
75610 + namep = (void __force_user *) m->msg_name;
75611 err = move_addr_to_kernel(namep, m->msg_namelen,
75612 address);
75613 if (err < 0)
75614 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75615 }
75616
75617 size = m->msg_iovlen * sizeof(struct iovec);
75618 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75619 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75620 return -EFAULT;
75621
75622 m->msg_iov = iov;
75623 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
75624 index 1683e5d..f3621f6 100644
75625 --- a/net/core/net-sysfs.c
75626 +++ b/net/core/net-sysfs.c
75627 @@ -664,11 +664,14 @@ static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
75628 if (count) {
75629 int i;
75630
75631 - if (count > 1<<30) {
75632 - /* Enforce a limit to prevent overflow */
75633 + if (count > INT_MAX)
75634 return -EINVAL;
75635 - }
75636 count = roundup_pow_of_two(count);
75637 + if (count > (ULONG_MAX - sizeof(struct rps_dev_flow_table))
75638 + / sizeof(struct rps_dev_flow)) {
75639 + /* Enforce a limit to prevent overflow */
75640 + return -EINVAL;
75641 + }
75642 table = vmalloc(RPS_DEV_FLOW_TABLE_SIZE(count));
75643 if (!table)
75644 return -ENOMEM;
75645 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75646 index 99d9e95..209bae2 100644
75647 --- a/net/core/rtnetlink.c
75648 +++ b/net/core/rtnetlink.c
75649 @@ -57,7 +57,7 @@ struct rtnl_link {
75650 rtnl_doit_func doit;
75651 rtnl_dumpit_func dumpit;
75652 rtnl_calcit_func calcit;
75653 -};
75654 +} __no_const;
75655
75656 static DEFINE_MUTEX(rtnl_mutex);
75657 static u16 min_ifinfo_dump_size;
75658 diff --git a/net/core/scm.c b/net/core/scm.c
75659 index 811b53f..5d6c343 100644
75660 --- a/net/core/scm.c
75661 +++ b/net/core/scm.c
75662 @@ -218,7 +218,7 @@ EXPORT_SYMBOL(__scm_send);
75663 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75664 {
75665 struct cmsghdr __user *cm
75666 - = (__force struct cmsghdr __user *)msg->msg_control;
75667 + = (struct cmsghdr __force_user *)msg->msg_control;
75668 struct cmsghdr cmhdr;
75669 int cmlen = CMSG_LEN(len);
75670 int err;
75671 @@ -241,7 +241,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75672 err = -EFAULT;
75673 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75674 goto out;
75675 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75676 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75677 goto out;
75678 cmlen = CMSG_SPACE(len);
75679 if (msg->msg_controllen < cmlen)
75680 @@ -257,7 +257,7 @@ EXPORT_SYMBOL(put_cmsg);
75681 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75682 {
75683 struct cmsghdr __user *cm
75684 - = (__force struct cmsghdr __user*)msg->msg_control;
75685 + = (struct cmsghdr __force_user *)msg->msg_control;
75686
75687 int fdmax = 0;
75688 int fdnum = scm->fp->count;
75689 @@ -277,7 +277,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75690 if (fdnum < fdmax)
75691 fdmax = fdnum;
75692
75693 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75694 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75695 i++, cmfptr++)
75696 {
75697 int new_fd;
75698 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
75699 index 387703f..035abcf 100644
75700 --- a/net/core/skbuff.c
75701 +++ b/net/core/skbuff.c
75702 @@ -1650,6 +1650,8 @@ int skb_splice_bits(struct sk_buff *skb, unsigned int offset,
75703 struct sock *sk = skb->sk;
75704 int ret = 0;
75705
75706 + pax_track_stack();
75707 +
75708 if (splice_grow_spd(pipe, &spd))
75709 return -ENOMEM;
75710
75711 diff --git a/net/core/sock.c b/net/core/sock.c
75712 index 11d67b3..df26d4b 100644
75713 --- a/net/core/sock.c
75714 +++ b/net/core/sock.c
75715 @@ -293,7 +293,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75716 */
75717 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
75718 (unsigned)sk->sk_rcvbuf) {
75719 - atomic_inc(&sk->sk_drops);
75720 + atomic_inc_unchecked(&sk->sk_drops);
75721 trace_sock_rcvqueue_full(sk, skb);
75722 return -ENOMEM;
75723 }
75724 @@ -303,7 +303,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75725 return err;
75726
75727 if (!sk_rmem_schedule(sk, skb->truesize)) {
75728 - atomic_inc(&sk->sk_drops);
75729 + atomic_inc_unchecked(&sk->sk_drops);
75730 return -ENOBUFS;
75731 }
75732
75733 @@ -323,7 +323,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75734 skb_dst_force(skb);
75735
75736 spin_lock_irqsave(&list->lock, flags);
75737 - skb->dropcount = atomic_read(&sk->sk_drops);
75738 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75739 __skb_queue_tail(list, skb);
75740 spin_unlock_irqrestore(&list->lock, flags);
75741
75742 @@ -343,7 +343,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75743 skb->dev = NULL;
75744
75745 if (sk_rcvqueues_full(sk, skb)) {
75746 - atomic_inc(&sk->sk_drops);
75747 + atomic_inc_unchecked(&sk->sk_drops);
75748 goto discard_and_relse;
75749 }
75750 if (nested)
75751 @@ -361,7 +361,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75752 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75753 } else if (sk_add_backlog(sk, skb)) {
75754 bh_unlock_sock(sk);
75755 - atomic_inc(&sk->sk_drops);
75756 + atomic_inc_unchecked(&sk->sk_drops);
75757 goto discard_and_relse;
75758 }
75759
75760 @@ -924,7 +924,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75761 if (len > sizeof(peercred))
75762 len = sizeof(peercred);
75763 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75764 - if (copy_to_user(optval, &peercred, len))
75765 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75766 return -EFAULT;
75767 goto lenout;
75768 }
75769 @@ -937,7 +937,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75770 return -ENOTCONN;
75771 if (lv < len)
75772 return -EINVAL;
75773 - if (copy_to_user(optval, address, len))
75774 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75775 return -EFAULT;
75776 goto lenout;
75777 }
75778 @@ -970,7 +970,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75779
75780 if (len > lv)
75781 len = lv;
75782 - if (copy_to_user(optval, &v, len))
75783 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75784 return -EFAULT;
75785 lenout:
75786 if (put_user(len, optlen))
75787 @@ -2029,7 +2029,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75788 */
75789 smp_wmb();
75790 atomic_set(&sk->sk_refcnt, 1);
75791 - atomic_set(&sk->sk_drops, 0);
75792 + atomic_set_unchecked(&sk->sk_drops, 0);
75793 }
75794 EXPORT_SYMBOL(sock_init_data);
75795
75796 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75797 index 02e75d1..9a57a7c 100644
75798 --- a/net/decnet/sysctl_net_decnet.c
75799 +++ b/net/decnet/sysctl_net_decnet.c
75800 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75801
75802 if (len > *lenp) len = *lenp;
75803
75804 - if (copy_to_user(buffer, addr, len))
75805 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75806 return -EFAULT;
75807
75808 *lenp = len;
75809 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75810
75811 if (len > *lenp) len = *lenp;
75812
75813 - if (copy_to_user(buffer, devname, len))
75814 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75815 return -EFAULT;
75816
75817 *lenp = len;
75818 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
75819 index 39a2d29..f39c0fe 100644
75820 --- a/net/econet/Kconfig
75821 +++ b/net/econet/Kconfig
75822 @@ -4,7 +4,7 @@
75823
75824 config ECONET
75825 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75826 - depends on EXPERIMENTAL && INET
75827 + depends on EXPERIMENTAL && INET && BROKEN
75828 ---help---
75829 Econet is a fairly old and slow networking protocol mainly used by
75830 Acorn computers to access file and print servers. It uses native
75831 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75832 index 92fc5f6..b790d91 100644
75833 --- a/net/ipv4/fib_frontend.c
75834 +++ b/net/ipv4/fib_frontend.c
75835 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75836 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75837 fib_sync_up(dev);
75838 #endif
75839 - atomic_inc(&net->ipv4.dev_addr_genid);
75840 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75841 rt_cache_flush(dev_net(dev), -1);
75842 break;
75843 case NETDEV_DOWN:
75844 fib_del_ifaddr(ifa, NULL);
75845 - atomic_inc(&net->ipv4.dev_addr_genid);
75846 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75847 if (ifa->ifa_dev->ifa_list == NULL) {
75848 /* Last address was deleted from this interface.
75849 * Disable IP.
75850 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75851 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75852 fib_sync_up(dev);
75853 #endif
75854 - atomic_inc(&net->ipv4.dev_addr_genid);
75855 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75856 rt_cache_flush(dev_net(dev), -1);
75857 break;
75858 case NETDEV_DOWN:
75859 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75860 index 80106d8..232e898 100644
75861 --- a/net/ipv4/fib_semantics.c
75862 +++ b/net/ipv4/fib_semantics.c
75863 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75864 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75865 nh->nh_gw,
75866 nh->nh_parent->fib_scope);
75867 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75868 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75869
75870 return nh->nh_saddr;
75871 }
75872 diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
75873 index 389a2e6..ac1c1de 100644
75874 --- a/net/ipv4/inet_diag.c
75875 +++ b/net/ipv4/inet_diag.c
75876 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct sock *sk,
75877 r->idiag_retrans = 0;
75878
75879 r->id.idiag_if = sk->sk_bound_dev_if;
75880 +
75881 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75882 + r->id.idiag_cookie[0] = 0;
75883 + r->id.idiag_cookie[1] = 0;
75884 +#else
75885 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
75886 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75887 +#endif
75888
75889 r->id.idiag_sport = inet->inet_sport;
75890 r->id.idiag_dport = inet->inet_dport;
75891 @@ -201,8 +207,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
75892 r->idiag_family = tw->tw_family;
75893 r->idiag_retrans = 0;
75894 r->id.idiag_if = tw->tw_bound_dev_if;
75895 +
75896 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75897 + r->id.idiag_cookie[0] = 0;
75898 + r->id.idiag_cookie[1] = 0;
75899 +#else
75900 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
75901 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
75902 +#endif
75903 +
75904 r->id.idiag_sport = tw->tw_sport;
75905 r->id.idiag_dport = tw->tw_dport;
75906 r->id.idiag_src[0] = tw->tw_rcv_saddr;
75907 @@ -285,12 +298,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
75908 if (sk == NULL)
75909 goto unlock;
75910
75911 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75912 err = -ESTALE;
75913 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
75914 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
75915 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
75916 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
75917 goto out;
75918 +#endif
75919
75920 err = -ENOMEM;
75921 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
75922 @@ -580,8 +595,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
75923 r->idiag_retrans = req->retrans;
75924
75925 r->id.idiag_if = sk->sk_bound_dev_if;
75926 +
75927 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75928 + r->id.idiag_cookie[0] = 0;
75929 + r->id.idiag_cookie[1] = 0;
75930 +#else
75931 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
75932 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
75933 +#endif
75934
75935 tmo = req->expires - jiffies;
75936 if (tmo < 0)
75937 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75938 index 984ec65..97ac518 100644
75939 --- a/net/ipv4/inet_hashtables.c
75940 +++ b/net/ipv4/inet_hashtables.c
75941 @@ -18,12 +18,15 @@
75942 #include <linux/sched.h>
75943 #include <linux/slab.h>
75944 #include <linux/wait.h>
75945 +#include <linux/security.h>
75946
75947 #include <net/inet_connection_sock.h>
75948 #include <net/inet_hashtables.h>
75949 #include <net/secure_seq.h>
75950 #include <net/ip.h>
75951
75952 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75953 +
75954 /*
75955 * Allocate and initialize a new local port bind bucket.
75956 * The bindhash mutex for snum's hash chain must be held here.
75957 @@ -530,6 +533,8 @@ ok:
75958 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75959 spin_unlock(&head->lock);
75960
75961 + gr_update_task_in_ip_table(current, inet_sk(sk));
75962 +
75963 if (tw) {
75964 inet_twsk_deschedule(tw, death_row);
75965 while (twrefcnt) {
75966 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75967 index 86f13c67..0bce60f 100644
75968 --- a/net/ipv4/inetpeer.c
75969 +++ b/net/ipv4/inetpeer.c
75970 @@ -400,6 +400,8 @@ struct inet_peer *inet_getpeer(const struct inetpeer_addr *daddr, int create)
75971 unsigned int sequence;
75972 int invalidated, gccnt = 0;
75973
75974 + pax_track_stack();
75975 +
75976 /* Attempt a lockless lookup first.
75977 * Because of a concurrent writer, we might not find an existing entry.
75978 */
75979 @@ -436,8 +438,8 @@ relookup:
75980 if (p) {
75981 p->daddr = *daddr;
75982 atomic_set(&p->refcnt, 1);
75983 - atomic_set(&p->rid, 0);
75984 - atomic_set(&p->ip_id_count,
75985 + atomic_set_unchecked(&p->rid, 0);
75986 + atomic_set_unchecked(&p->ip_id_count,
75987 (daddr->family == AF_INET) ?
75988 secure_ip_id(daddr->addr.a4) :
75989 secure_ipv6_id(daddr->addr.a6));
75990 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75991 index 0e0ab98..2ed7dd5 100644
75992 --- a/net/ipv4/ip_fragment.c
75993 +++ b/net/ipv4/ip_fragment.c
75994 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75995 return 0;
75996
75997 start = qp->rid;
75998 - end = atomic_inc_return(&peer->rid);
75999 + end = atomic_inc_return_unchecked(&peer->rid);
76000 qp->rid = end;
76001
76002 rc = qp->q.fragments && (end - start) > max;
76003 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76004 index 8905e92..0b179fb 100644
76005 --- a/net/ipv4/ip_sockglue.c
76006 +++ b/net/ipv4/ip_sockglue.c
76007 @@ -1073,6 +1073,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76008 int val;
76009 int len;
76010
76011 + pax_track_stack();
76012 +
76013 if (level != SOL_IP)
76014 return -EOPNOTSUPP;
76015
76016 @@ -1110,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76017 len = min_t(unsigned int, len, opt->optlen);
76018 if (put_user(len, optlen))
76019 return -EFAULT;
76020 - if (copy_to_user(optval, opt->__data, len))
76021 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76022 + copy_to_user(optval, opt->__data, len))
76023 return -EFAULT;
76024 return 0;
76025 }
76026 @@ -1238,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76027 if (sk->sk_type != SOCK_STREAM)
76028 return -ENOPROTOOPT;
76029
76030 - msg.msg_control = optval;
76031 + msg.msg_control = (void __force_kernel *)optval;
76032 msg.msg_controllen = len;
76033 msg.msg_flags = flags;
76034
76035 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76036 index 004bb74..8d4a58c 100644
76037 --- a/net/ipv4/ipconfig.c
76038 +++ b/net/ipv4/ipconfig.c
76039 @@ -317,7 +317,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76040
76041 mm_segment_t oldfs = get_fs();
76042 set_fs(get_ds());
76043 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76044 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76045 set_fs(oldfs);
76046 return res;
76047 }
76048 @@ -328,7 +328,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76049
76050 mm_segment_t oldfs = get_fs();
76051 set_fs(get_ds());
76052 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76053 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76054 set_fs(oldfs);
76055 return res;
76056 }
76057 @@ -339,7 +339,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76058
76059 mm_segment_t oldfs = get_fs();
76060 set_fs(get_ds());
76061 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76062 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76063 set_fs(oldfs);
76064 return res;
76065 }
76066 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
76067 index 076b7c8..9c8d038 100644
76068 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
76069 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
76070 @@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
76071
76072 *len = 0;
76073
76074 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
76075 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
76076 if (*octets == NULL) {
76077 if (net_ratelimit())
76078 pr_notice("OOM in bsalg (%d)\n", __LINE__);
76079 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76080 index 39b403f..8e6a0a8 100644
76081 --- a/net/ipv4/ping.c
76082 +++ b/net/ipv4/ping.c
76083 @@ -837,7 +837,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76084 sk_rmem_alloc_get(sp),
76085 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76086 atomic_read(&sp->sk_refcnt), sp,
76087 - atomic_read(&sp->sk_drops), len);
76088 + atomic_read_unchecked(&sp->sk_drops), len);
76089 }
76090
76091 static int ping_seq_show(struct seq_file *seq, void *v)
76092 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
76093 index 61714bd..c9cee6d 100644
76094 --- a/net/ipv4/raw.c
76095 +++ b/net/ipv4/raw.c
76096 @@ -302,7 +302,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
76097 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76098 {
76099 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76100 - atomic_inc(&sk->sk_drops);
76101 + atomic_inc_unchecked(&sk->sk_drops);
76102 kfree_skb(skb);
76103 return NET_RX_DROP;
76104 }
76105 @@ -737,16 +737,20 @@ static int raw_init(struct sock *sk)
76106
76107 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76108 {
76109 + struct icmp_filter filter;
76110 +
76111 if (optlen > sizeof(struct icmp_filter))
76112 optlen = sizeof(struct icmp_filter);
76113 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76114 + if (copy_from_user(&filter, optval, optlen))
76115 return -EFAULT;
76116 + raw_sk(sk)->filter = filter;
76117 return 0;
76118 }
76119
76120 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76121 {
76122 int len, ret = -EFAULT;
76123 + struct icmp_filter filter;
76124
76125 if (get_user(len, optlen))
76126 goto out;
76127 @@ -756,8 +760,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76128 if (len > sizeof(struct icmp_filter))
76129 len = sizeof(struct icmp_filter);
76130 ret = -EFAULT;
76131 - if (put_user(len, optlen) ||
76132 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76133 + filter = raw_sk(sk)->filter;
76134 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76135 goto out;
76136 ret = 0;
76137 out: return ret;
76138 @@ -985,7 +989,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76139 sk_wmem_alloc_get(sp),
76140 sk_rmem_alloc_get(sp),
76141 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76142 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76143 + atomic_read(&sp->sk_refcnt),
76144 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76145 + NULL,
76146 +#else
76147 + sp,
76148 +#endif
76149 + atomic_read_unchecked(&sp->sk_drops));
76150 }
76151
76152 static int raw_seq_show(struct seq_file *seq, void *v)
76153 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76154 index b563854..e03f8a6 100644
76155 --- a/net/ipv4/route.c
76156 +++ b/net/ipv4/route.c
76157 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76158
76159 static inline int rt_genid(struct net *net)
76160 {
76161 - return atomic_read(&net->ipv4.rt_genid);
76162 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76163 }
76164
76165 #ifdef CONFIG_PROC_FS
76166 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
76167 unsigned char shuffle;
76168
76169 get_random_bytes(&shuffle, sizeof(shuffle));
76170 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76171 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76172 redirect_genid++;
76173 }
76174
76175 @@ -3015,7 +3015,7 @@ static int rt_fill_info(struct net *net,
76176 error = rt->dst.error;
76177 if (peer) {
76178 inet_peer_refcheck(rt->peer);
76179 - id = atomic_read(&peer->ip_id_count) & 0xffff;
76180 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76181 if (peer->tcp_ts_stamp) {
76182 ts = peer->tcp_ts;
76183 tsage = get_seconds() - peer->tcp_ts_stamp;
76184 diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
76185 index 46febca..98b73a4 100644
76186 --- a/net/ipv4/tcp.c
76187 +++ b/net/ipv4/tcp.c
76188 @@ -2122,6 +2122,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
76189 int val;
76190 int err = 0;
76191
76192 + pax_track_stack();
76193 +
76194 /* These are data/string values, all the others are ints */
76195 switch (optname) {
76196 case TCP_CONGESTION: {
76197 @@ -2501,6 +2503,8 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
76198 struct tcp_sock *tp = tcp_sk(sk);
76199 int val, len;
76200
76201 + pax_track_stack();
76202 +
76203 if (get_user(len, optlen))
76204 return -EFAULT;
76205
76206 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76207 index 7963e03..c44f5d0 100644
76208 --- a/net/ipv4/tcp_ipv4.c
76209 +++ b/net/ipv4/tcp_ipv4.c
76210 @@ -87,6 +87,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
76211 int sysctl_tcp_low_latency __read_mostly;
76212 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76213
76214 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76215 +extern int grsec_enable_blackhole;
76216 +#endif
76217
76218 #ifdef CONFIG_TCP_MD5SIG
76219 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
76220 @@ -1622,6 +1625,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76221 return 0;
76222
76223 reset:
76224 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76225 + if (!grsec_enable_blackhole)
76226 +#endif
76227 tcp_v4_send_reset(rsk, skb);
76228 discard:
76229 kfree_skb(skb);
76230 @@ -1684,12 +1690,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76231 TCP_SKB_CB(skb)->sacked = 0;
76232
76233 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76234 - if (!sk)
76235 + if (!sk) {
76236 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76237 + ret = 1;
76238 +#endif
76239 goto no_tcp_socket;
76240 -
76241 + }
76242 process:
76243 - if (sk->sk_state == TCP_TIME_WAIT)
76244 + if (sk->sk_state == TCP_TIME_WAIT) {
76245 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76246 + ret = 2;
76247 +#endif
76248 goto do_time_wait;
76249 + }
76250
76251 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76252 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76253 @@ -1739,6 +1752,10 @@ no_tcp_socket:
76254 bad_packet:
76255 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76256 } else {
76257 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76258 + if (!grsec_enable_blackhole || (ret == 1 &&
76259 + (skb->dev->flags & IFF_LOOPBACK)))
76260 +#endif
76261 tcp_v4_send_reset(NULL, skb);
76262 }
76263
76264 @@ -2403,7 +2420,11 @@ static void get_openreq4(struct sock *sk, struct request_sock *req,
76265 0, /* non standard timer */
76266 0, /* open_requests have no inode */
76267 atomic_read(&sk->sk_refcnt),
76268 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76269 + NULL,
76270 +#else
76271 req,
76272 +#endif
76273 len);
76274 }
76275
76276 @@ -2453,7 +2474,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76277 sock_i_uid(sk),
76278 icsk->icsk_probes_out,
76279 sock_i_ino(sk),
76280 - atomic_read(&sk->sk_refcnt), sk,
76281 + atomic_read(&sk->sk_refcnt),
76282 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76283 + NULL,
76284 +#else
76285 + sk,
76286 +#endif
76287 jiffies_to_clock_t(icsk->icsk_rto),
76288 jiffies_to_clock_t(icsk->icsk_ack.ato),
76289 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76290 @@ -2481,7 +2507,13 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
76291 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76292 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76293 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76294 - atomic_read(&tw->tw_refcnt), tw, len);
76295 + atomic_read(&tw->tw_refcnt),
76296 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76297 + NULL,
76298 +#else
76299 + tw,
76300 +#endif
76301 + len);
76302 }
76303
76304 #define TMPSZ 150
76305 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76306 index 0ce3d06..e182e59 100644
76307 --- a/net/ipv4/tcp_minisocks.c
76308 +++ b/net/ipv4/tcp_minisocks.c
76309 @@ -27,6 +27,10 @@
76310 #include <net/inet_common.h>
76311 #include <net/xfrm.h>
76312
76313 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76314 +extern int grsec_enable_blackhole;
76315 +#endif
76316 +
76317 int sysctl_tcp_syncookies __read_mostly = 1;
76318 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76319
76320 @@ -750,6 +754,10 @@ listen_overflow:
76321
76322 embryonic_reset:
76323 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76324 +
76325 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76326 + if (!grsec_enable_blackhole)
76327 +#endif
76328 if (!(flg & TCP_FLAG_RST))
76329 req->rsk_ops->send_reset(sk, skb);
76330
76331 diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
76332 index 882e0b0..2eba47f 100644
76333 --- a/net/ipv4/tcp_output.c
76334 +++ b/net/ipv4/tcp_output.c
76335 @@ -2421,6 +2421,8 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
76336 int mss;
76337 int s_data_desired = 0;
76338
76339 + pax_track_stack();
76340 +
76341 if (cvp != NULL && cvp->s_data_constant && cvp->s_data_desired)
76342 s_data_desired = cvp->s_data_desired;
76343 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15 + s_data_desired, 1, GFP_ATOMIC);
76344 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76345 index 85ee7eb..53277ab 100644
76346 --- a/net/ipv4/tcp_probe.c
76347 +++ b/net/ipv4/tcp_probe.c
76348 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76349 if (cnt + width >= len)
76350 break;
76351
76352 - if (copy_to_user(buf + cnt, tbuf, width))
76353 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76354 return -EFAULT;
76355 cnt += width;
76356 }
76357 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76358 index ecd44b0..b32fba6 100644
76359 --- a/net/ipv4/tcp_timer.c
76360 +++ b/net/ipv4/tcp_timer.c
76361 @@ -22,6 +22,10 @@
76362 #include <linux/gfp.h>
76363 #include <net/tcp.h>
76364
76365 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76366 +extern int grsec_lastack_retries;
76367 +#endif
76368 +
76369 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76370 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76371 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76372 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock *sk)
76373 }
76374 }
76375
76376 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76377 + if ((sk->sk_state == TCP_LAST_ACK) &&
76378 + (grsec_lastack_retries > 0) &&
76379 + (grsec_lastack_retries < retry_until))
76380 + retry_until = grsec_lastack_retries;
76381 +#endif
76382 +
76383 if (retransmits_timed_out(sk, retry_until,
76384 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76385 /* Has it gone just too far? */
76386 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76387 index 1b5a193..bd354b0 100644
76388 --- a/net/ipv4/udp.c
76389 +++ b/net/ipv4/udp.c
76390 @@ -86,6 +86,7 @@
76391 #include <linux/types.h>
76392 #include <linux/fcntl.h>
76393 #include <linux/module.h>
76394 +#include <linux/security.h>
76395 #include <linux/socket.h>
76396 #include <linux/sockios.h>
76397 #include <linux/igmp.h>
76398 @@ -108,6 +109,10 @@
76399 #include <trace/events/udp.h>
76400 #include "udp_impl.h"
76401
76402 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76403 +extern int grsec_enable_blackhole;
76404 +#endif
76405 +
76406 struct udp_table udp_table __read_mostly;
76407 EXPORT_SYMBOL(udp_table);
76408
76409 @@ -565,6 +570,9 @@ found:
76410 return s;
76411 }
76412
76413 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76414 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76415 +
76416 /*
76417 * This routine is called by the ICMP module when it gets some
76418 * sort of error condition. If err < 0 then the socket should
76419 @@ -856,9 +864,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76420 dport = usin->sin_port;
76421 if (dport == 0)
76422 return -EINVAL;
76423 +
76424 + err = gr_search_udp_sendmsg(sk, usin);
76425 + if (err)
76426 + return err;
76427 } else {
76428 if (sk->sk_state != TCP_ESTABLISHED)
76429 return -EDESTADDRREQ;
76430 +
76431 + err = gr_search_udp_sendmsg(sk, NULL);
76432 + if (err)
76433 + return err;
76434 +
76435 daddr = inet->inet_daddr;
76436 dport = inet->inet_dport;
76437 /* Open fast path for connected socket.
76438 @@ -1099,7 +1116,7 @@ static unsigned int first_packet_length(struct sock *sk)
76439 udp_lib_checksum_complete(skb)) {
76440 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76441 IS_UDPLITE(sk));
76442 - atomic_inc(&sk->sk_drops);
76443 + atomic_inc_unchecked(&sk->sk_drops);
76444 __skb_unlink(skb, rcvq);
76445 __skb_queue_tail(&list_kill, skb);
76446 }
76447 @@ -1185,6 +1202,10 @@ try_again:
76448 if (!skb)
76449 goto out;
76450
76451 + err = gr_search_udp_recvmsg(sk, skb);
76452 + if (err)
76453 + goto out_free;
76454 +
76455 ulen = skb->len - sizeof(struct udphdr);
76456 if (len > ulen)
76457 len = ulen;
76458 @@ -1485,7 +1506,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76459
76460 drop:
76461 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76462 - atomic_inc(&sk->sk_drops);
76463 + atomic_inc_unchecked(&sk->sk_drops);
76464 kfree_skb(skb);
76465 return -1;
76466 }
76467 @@ -1504,7 +1525,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76468 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76469
76470 if (!skb1) {
76471 - atomic_inc(&sk->sk_drops);
76472 + atomic_inc_unchecked(&sk->sk_drops);
76473 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76474 IS_UDPLITE(sk));
76475 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76476 @@ -1673,6 +1694,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76477 goto csum_error;
76478
76479 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76480 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76481 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76482 +#endif
76483 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76484
76485 /*
76486 @@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76487 sk_wmem_alloc_get(sp),
76488 sk_rmem_alloc_get(sp),
76489 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76490 - atomic_read(&sp->sk_refcnt), sp,
76491 - atomic_read(&sp->sk_drops), len);
76492 + atomic_read(&sp->sk_refcnt),
76493 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76494 + NULL,
76495 +#else
76496 + sp,
76497 +#endif
76498 + atomic_read_unchecked(&sp->sk_drops), len);
76499 }
76500
76501 int udp4_seq_show(struct seq_file *seq, void *v)
76502 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76503 index 12368c5..fbf899f 100644
76504 --- a/net/ipv6/addrconf.c
76505 +++ b/net/ipv6/addrconf.c
76506 @@ -2083,7 +2083,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76507 p.iph.ihl = 5;
76508 p.iph.protocol = IPPROTO_IPV6;
76509 p.iph.ttl = 64;
76510 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76511 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76512
76513 if (ops->ndo_do_ioctl) {
76514 mm_segment_t oldfs = get_fs();
76515 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76516 index 8a58e8c..8b5e631 100644
76517 --- a/net/ipv6/inet6_connection_sock.c
76518 +++ b/net/ipv6/inet6_connection_sock.c
76519 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76520 #ifdef CONFIG_XFRM
76521 {
76522 struct rt6_info *rt = (struct rt6_info *)dst;
76523 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76524 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76525 }
76526 #endif
76527 }
76528 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76529 #ifdef CONFIG_XFRM
76530 if (dst) {
76531 struct rt6_info *rt = (struct rt6_info *)dst;
76532 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76533 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76534 __sk_dst_reset(sk);
76535 dst = NULL;
76536 }
76537 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76538 index 2fbda5f..26ed683 100644
76539 --- a/net/ipv6/ipv6_sockglue.c
76540 +++ b/net/ipv6/ipv6_sockglue.c
76541 @@ -129,6 +129,8 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
76542 int val, valbool;
76543 int retv = -ENOPROTOOPT;
76544
76545 + pax_track_stack();
76546 +
76547 if (optval == NULL)
76548 val=0;
76549 else {
76550 @@ -919,6 +921,8 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76551 int len;
76552 int val;
76553
76554 + pax_track_stack();
76555 +
76556 if (ip6_mroute_opt(optname))
76557 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
76558
76559 @@ -960,7 +964,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76560 if (sk->sk_type != SOCK_STREAM)
76561 return -ENOPROTOOPT;
76562
76563 - msg.msg_control = optval;
76564 + msg.msg_control = (void __force_kernel *)optval;
76565 msg.msg_controllen = len;
76566 msg.msg_flags = flags;
76567
76568 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76569 index 343852e..c92bd15 100644
76570 --- a/net/ipv6/raw.c
76571 +++ b/net/ipv6/raw.c
76572 @@ -376,7 +376,7 @@ static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
76573 {
76574 if ((raw6_sk(sk)->checksum || rcu_dereference_raw(sk->sk_filter)) &&
76575 skb_checksum_complete(skb)) {
76576 - atomic_inc(&sk->sk_drops);
76577 + atomic_inc_unchecked(&sk->sk_drops);
76578 kfree_skb(skb);
76579 return NET_RX_DROP;
76580 }
76581 @@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76582 struct raw6_sock *rp = raw6_sk(sk);
76583
76584 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76585 - atomic_inc(&sk->sk_drops);
76586 + atomic_inc_unchecked(&sk->sk_drops);
76587 kfree_skb(skb);
76588 return NET_RX_DROP;
76589 }
76590 @@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76591
76592 if (inet->hdrincl) {
76593 if (skb_checksum_complete(skb)) {
76594 - atomic_inc(&sk->sk_drops);
76595 + atomic_inc_unchecked(&sk->sk_drops);
76596 kfree_skb(skb);
76597 return NET_RX_DROP;
76598 }
76599 @@ -601,7 +601,7 @@ out:
76600 return err;
76601 }
76602
76603 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76604 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76605 struct flowi6 *fl6, struct dst_entry **dstp,
76606 unsigned int flags)
76607 {
76608 @@ -742,6 +742,8 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
76609 u16 proto;
76610 int err;
76611
76612 + pax_track_stack();
76613 +
76614 /* Rough check on arithmetic overflow,
76615 better check is made in ip6_append_data().
76616 */
76617 @@ -909,12 +911,15 @@ do_confirm:
76618 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76619 char __user *optval, int optlen)
76620 {
76621 + struct icmp6_filter filter;
76622 +
76623 switch (optname) {
76624 case ICMPV6_FILTER:
76625 if (optlen > sizeof(struct icmp6_filter))
76626 optlen = sizeof(struct icmp6_filter);
76627 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76628 + if (copy_from_user(&filter, optval, optlen))
76629 return -EFAULT;
76630 + raw6_sk(sk)->filter = filter;
76631 return 0;
76632 default:
76633 return -ENOPROTOOPT;
76634 @@ -927,6 +932,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76635 char __user *optval, int __user *optlen)
76636 {
76637 int len;
76638 + struct icmp6_filter filter;
76639
76640 switch (optname) {
76641 case ICMPV6_FILTER:
76642 @@ -938,7 +944,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76643 len = sizeof(struct icmp6_filter);
76644 if (put_user(len, optlen))
76645 return -EFAULT;
76646 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76647 + filter = raw6_sk(sk)->filter;
76648 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76649 return -EFAULT;
76650 return 0;
76651 default:
76652 @@ -1245,7 +1252,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76653 0, 0L, 0,
76654 sock_i_uid(sp), 0,
76655 sock_i_ino(sp),
76656 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76657 + atomic_read(&sp->sk_refcnt),
76658 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76659 + NULL,
76660 +#else
76661 + sp,
76662 +#endif
76663 + atomic_read_unchecked(&sp->sk_drops));
76664 }
76665
76666 static int raw6_seq_show(struct seq_file *seq, void *v)
76667 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76668 index 7b8fc57..c6185da 100644
76669 --- a/net/ipv6/tcp_ipv6.c
76670 +++ b/net/ipv6/tcp_ipv6.c
76671 @@ -93,6 +93,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76672 }
76673 #endif
76674
76675 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76676 +extern int grsec_enable_blackhole;
76677 +#endif
76678 +
76679 static void tcp_v6_hash(struct sock *sk)
76680 {
76681 if (sk->sk_state != TCP_CLOSE) {
76682 @@ -1647,6 +1651,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76683 return 0;
76684
76685 reset:
76686 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76687 + if (!grsec_enable_blackhole)
76688 +#endif
76689 tcp_v6_send_reset(sk, skb);
76690 discard:
76691 if (opt_skb)
76692 @@ -1726,12 +1733,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76693 TCP_SKB_CB(skb)->sacked = 0;
76694
76695 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76696 - if (!sk)
76697 + if (!sk) {
76698 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76699 + ret = 1;
76700 +#endif
76701 goto no_tcp_socket;
76702 + }
76703
76704 process:
76705 - if (sk->sk_state == TCP_TIME_WAIT)
76706 + if (sk->sk_state == TCP_TIME_WAIT) {
76707 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76708 + ret = 2;
76709 +#endif
76710 goto do_time_wait;
76711 + }
76712
76713 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76714 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76715 @@ -1779,6 +1794,10 @@ no_tcp_socket:
76716 bad_packet:
76717 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76718 } else {
76719 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76720 + if (!grsec_enable_blackhole || (ret == 1 &&
76721 + (skb->dev->flags & IFF_LOOPBACK)))
76722 +#endif
76723 tcp_v6_send_reset(NULL, skb);
76724 }
76725
76726 @@ -2039,7 +2058,13 @@ static void get_openreq6(struct seq_file *seq,
76727 uid,
76728 0, /* non standard timer */
76729 0, /* open_requests have no inode */
76730 - 0, req);
76731 + 0,
76732 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76733 + NULL
76734 +#else
76735 + req
76736 +#endif
76737 + );
76738 }
76739
76740 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76741 @@ -2089,7 +2114,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76742 sock_i_uid(sp),
76743 icsk->icsk_probes_out,
76744 sock_i_ino(sp),
76745 - atomic_read(&sp->sk_refcnt), sp,
76746 + atomic_read(&sp->sk_refcnt),
76747 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76748 + NULL,
76749 +#else
76750 + sp,
76751 +#endif
76752 jiffies_to_clock_t(icsk->icsk_rto),
76753 jiffies_to_clock_t(icsk->icsk_ack.ato),
76754 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76755 @@ -2124,7 +2154,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76756 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76757 tw->tw_substate, 0, 0,
76758 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76759 - atomic_read(&tw->tw_refcnt), tw);
76760 + atomic_read(&tw->tw_refcnt),
76761 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76762 + NULL
76763 +#else
76764 + tw
76765 +#endif
76766 + );
76767 }
76768
76769 static int tcp6_seq_show(struct seq_file *seq, void *v)
76770 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76771 index bb95e8e..ae0ee80 100644
76772 --- a/net/ipv6/udp.c
76773 +++ b/net/ipv6/udp.c
76774 @@ -50,6 +50,10 @@
76775 #include <linux/seq_file.h>
76776 #include "udp_impl.h"
76777
76778 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76779 +extern int grsec_enable_blackhole;
76780 +#endif
76781 +
76782 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76783 {
76784 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76785 @@ -548,7 +552,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
76786
76787 return 0;
76788 drop:
76789 - atomic_inc(&sk->sk_drops);
76790 + atomic_inc_unchecked(&sk->sk_drops);
76791 drop_no_sk_drops_inc:
76792 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76793 kfree_skb(skb);
76794 @@ -624,7 +628,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76795 continue;
76796 }
76797 drop:
76798 - atomic_inc(&sk->sk_drops);
76799 + atomic_inc_unchecked(&sk->sk_drops);
76800 UDP6_INC_STATS_BH(sock_net(sk),
76801 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76802 UDP6_INC_STATS_BH(sock_net(sk),
76803 @@ -779,6 +783,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76804 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76805 proto == IPPROTO_UDPLITE);
76806
76807 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76808 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76809 +#endif
76810 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76811
76812 kfree_skb(skb);
76813 @@ -795,7 +802,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76814 if (!sock_owned_by_user(sk))
76815 udpv6_queue_rcv_skb(sk, skb);
76816 else if (sk_add_backlog(sk, skb)) {
76817 - atomic_inc(&sk->sk_drops);
76818 + atomic_inc_unchecked(&sk->sk_drops);
76819 bh_unlock_sock(sk);
76820 sock_put(sk);
76821 goto discard;
76822 @@ -1406,8 +1413,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76823 0, 0L, 0,
76824 sock_i_uid(sp), 0,
76825 sock_i_ino(sp),
76826 - atomic_read(&sp->sk_refcnt), sp,
76827 - atomic_read(&sp->sk_drops));
76828 + atomic_read(&sp->sk_refcnt),
76829 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76830 + NULL,
76831 +#else
76832 + sp,
76833 +#endif
76834 + atomic_read_unchecked(&sp->sk_drops));
76835 }
76836
76837 int udp6_seq_show(struct seq_file *seq, void *v)
76838 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76839 index b3cc8b3..baa02d0 100644
76840 --- a/net/irda/ircomm/ircomm_tty.c
76841 +++ b/net/irda/ircomm/ircomm_tty.c
76842 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76843 add_wait_queue(&self->open_wait, &wait);
76844
76845 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76846 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76847 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76848
76849 /* As far as I can see, we protect open_count - Jean II */
76850 spin_lock_irqsave(&self->spinlock, flags);
76851 if (!tty_hung_up_p(filp)) {
76852 extra_count = 1;
76853 - self->open_count--;
76854 + local_dec(&self->open_count);
76855 }
76856 spin_unlock_irqrestore(&self->spinlock, flags);
76857 - self->blocked_open++;
76858 + local_inc(&self->blocked_open);
76859
76860 while (1) {
76861 if (tty->termios->c_cflag & CBAUD) {
76862 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76863 }
76864
76865 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76866 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76867 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76868
76869 schedule();
76870 }
76871 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76872 if (extra_count) {
76873 /* ++ is not atomic, so this should be protected - Jean II */
76874 spin_lock_irqsave(&self->spinlock, flags);
76875 - self->open_count++;
76876 + local_inc(&self->open_count);
76877 spin_unlock_irqrestore(&self->spinlock, flags);
76878 }
76879 - self->blocked_open--;
76880 + local_dec(&self->blocked_open);
76881
76882 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76883 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76884 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76885
76886 if (!retval)
76887 self->flags |= ASYNC_NORMAL_ACTIVE;
76888 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76889 }
76890 /* ++ is not atomic, so this should be protected - Jean II */
76891 spin_lock_irqsave(&self->spinlock, flags);
76892 - self->open_count++;
76893 + local_inc(&self->open_count);
76894
76895 tty->driver_data = self;
76896 self->tty = tty;
76897 spin_unlock_irqrestore(&self->spinlock, flags);
76898
76899 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76900 - self->line, self->open_count);
76901 + self->line, local_read(&self->open_count));
76902
76903 /* Not really used by us, but lets do it anyway */
76904 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76905 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76906 return;
76907 }
76908
76909 - if ((tty->count == 1) && (self->open_count != 1)) {
76910 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76911 /*
76912 * Uh, oh. tty->count is 1, which means that the tty
76913 * structure will be freed. state->count should always
76914 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76915 */
76916 IRDA_DEBUG(0, "%s(), bad serial port count; "
76917 "tty->count is 1, state->count is %d\n", __func__ ,
76918 - self->open_count);
76919 - self->open_count = 1;
76920 + local_read(&self->open_count));
76921 + local_set(&self->open_count, 1);
76922 }
76923
76924 - if (--self->open_count < 0) {
76925 + if (local_dec_return(&self->open_count) < 0) {
76926 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76927 - __func__, self->line, self->open_count);
76928 - self->open_count = 0;
76929 + __func__, self->line, local_read(&self->open_count));
76930 + local_set(&self->open_count, 0);
76931 }
76932 - if (self->open_count) {
76933 + if (local_read(&self->open_count)) {
76934 spin_unlock_irqrestore(&self->spinlock, flags);
76935
76936 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76937 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76938 tty->closing = 0;
76939 self->tty = NULL;
76940
76941 - if (self->blocked_open) {
76942 + if (local_read(&self->blocked_open)) {
76943 if (self->close_delay)
76944 schedule_timeout_interruptible(self->close_delay);
76945 wake_up_interruptible(&self->open_wait);
76946 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76947 spin_lock_irqsave(&self->spinlock, flags);
76948 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76949 self->tty = NULL;
76950 - self->open_count = 0;
76951 + local_set(&self->open_count, 0);
76952 spin_unlock_irqrestore(&self->spinlock, flags);
76953
76954 wake_up_interruptible(&self->open_wait);
76955 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76956 seq_putc(m, '\n');
76957
76958 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76959 - seq_printf(m, "Open count: %d\n", self->open_count);
76960 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76961 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76962 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76963
76964 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76965 index e2013e4..edfc1e3 100644
76966 --- a/net/iucv/af_iucv.c
76967 +++ b/net/iucv/af_iucv.c
76968 @@ -648,10 +648,10 @@ static int iucv_sock_autobind(struct sock *sk)
76969
76970 write_lock_bh(&iucv_sk_list.lock);
76971
76972 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76973 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76974 while (__iucv_get_sock_by_name(name)) {
76975 sprintf(name, "%08x",
76976 - atomic_inc_return(&iucv_sk_list.autobind_name));
76977 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76978 }
76979
76980 write_unlock_bh(&iucv_sk_list.lock);
76981 diff --git a/net/key/af_key.c b/net/key/af_key.c
76982 index 1e733e9..c84de2f 100644
76983 --- a/net/key/af_key.c
76984 +++ b/net/key/af_key.c
76985 @@ -2481,6 +2481,8 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
76986 struct xfrm_migrate m[XFRM_MAX_DEPTH];
76987 struct xfrm_kmaddress k;
76988
76989 + pax_track_stack();
76990 +
76991 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
76992 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
76993 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
76994 @@ -3016,10 +3018,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76995 static u32 get_acqseq(void)
76996 {
76997 u32 res;
76998 - static atomic_t acqseq;
76999 + static atomic_unchecked_t acqseq;
77000
77001 do {
77002 - res = atomic_inc_return(&acqseq);
77003 + res = atomic_inc_return_unchecked(&acqseq);
77004 } while (!res);
77005 return res;
77006 }
77007 diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
77008 index 956b7e4..f01d328 100644
77009 --- a/net/lapb/lapb_iface.c
77010 +++ b/net/lapb/lapb_iface.c
77011 @@ -158,7 +158,7 @@ int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks
77012 goto out;
77013
77014 lapb->dev = dev;
77015 - lapb->callbacks = *callbacks;
77016 + lapb->callbacks = callbacks;
77017
77018 __lapb_insert_cb(lapb);
77019
77020 @@ -380,32 +380,32 @@ int lapb_data_received(struct net_device *dev, struct sk_buff *skb)
77021
77022 void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
77023 {
77024 - if (lapb->callbacks.connect_confirmation)
77025 - lapb->callbacks.connect_confirmation(lapb->dev, reason);
77026 + if (lapb->callbacks->connect_confirmation)
77027 + lapb->callbacks->connect_confirmation(lapb->dev, reason);
77028 }
77029
77030 void lapb_connect_indication(struct lapb_cb *lapb, int reason)
77031 {
77032 - if (lapb->callbacks.connect_indication)
77033 - lapb->callbacks.connect_indication(lapb->dev, reason);
77034 + if (lapb->callbacks->connect_indication)
77035 + lapb->callbacks->connect_indication(lapb->dev, reason);
77036 }
77037
77038 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
77039 {
77040 - if (lapb->callbacks.disconnect_confirmation)
77041 - lapb->callbacks.disconnect_confirmation(lapb->dev, reason);
77042 + if (lapb->callbacks->disconnect_confirmation)
77043 + lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
77044 }
77045
77046 void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
77047 {
77048 - if (lapb->callbacks.disconnect_indication)
77049 - lapb->callbacks.disconnect_indication(lapb->dev, reason);
77050 + if (lapb->callbacks->disconnect_indication)
77051 + lapb->callbacks->disconnect_indication(lapb->dev, reason);
77052 }
77053
77054 int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
77055 {
77056 - if (lapb->callbacks.data_indication)
77057 - return lapb->callbacks.data_indication(lapb->dev, skb);
77058 + if (lapb->callbacks->data_indication)
77059 + return lapb->callbacks->data_indication(lapb->dev, skb);
77060
77061 kfree_skb(skb);
77062 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
77063 @@ -415,8 +415,8 @@ int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)
77064 {
77065 int used = 0;
77066
77067 - if (lapb->callbacks.data_transmit) {
77068 - lapb->callbacks.data_transmit(lapb->dev, skb);
77069 + if (lapb->callbacks->data_transmit) {
77070 + lapb->callbacks->data_transmit(lapb->dev, skb);
77071 used = 1;
77072 }
77073
77074 diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
77075 index a01d213..6a1f1ab 100644
77076 --- a/net/mac80211/debugfs_sta.c
77077 +++ b/net/mac80211/debugfs_sta.c
77078 @@ -140,6 +140,8 @@ static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
77079 struct tid_ampdu_rx *tid_rx;
77080 struct tid_ampdu_tx *tid_tx;
77081
77082 + pax_track_stack();
77083 +
77084 rcu_read_lock();
77085
77086 p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
77087 @@ -240,6 +242,8 @@ static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
77088 struct sta_info *sta = file->private_data;
77089 struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
77090
77091 + pax_track_stack();
77092 +
77093 p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
77094 htc->ht_supported ? "" : "not ");
77095 if (htc->ht_supported) {
77096 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77097 index 9fab144..7f0fc14 100644
77098 --- a/net/mac80211/ieee80211_i.h
77099 +++ b/net/mac80211/ieee80211_i.h
77100 @@ -27,6 +27,7 @@
77101 #include <net/ieee80211_radiotap.h>
77102 #include <net/cfg80211.h>
77103 #include <net/mac80211.h>
77104 +#include <asm/local.h>
77105 #include "key.h"
77106 #include "sta_info.h"
77107
77108 @@ -754,7 +755,7 @@ struct ieee80211_local {
77109 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77110 spinlock_t queue_stop_reason_lock;
77111
77112 - int open_count;
77113 + local_t open_count;
77114 int monitors, cooked_mntrs;
77115 /* number of interfaces with corresponding FIF_ flags */
77116 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77117 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77118 index 556e7e6..120dcaf 100644
77119 --- a/net/mac80211/iface.c
77120 +++ b/net/mac80211/iface.c
77121 @@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77122 break;
77123 }
77124
77125 - if (local->open_count == 0) {
77126 + if (local_read(&local->open_count) == 0) {
77127 res = drv_start(local);
77128 if (res)
77129 goto err_del_bss;
77130 @@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77131 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
77132
77133 if (!is_valid_ether_addr(dev->dev_addr)) {
77134 - if (!local->open_count)
77135 + if (!local_read(&local->open_count))
77136 drv_stop(local);
77137 return -EADDRNOTAVAIL;
77138 }
77139 @@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77140 mutex_unlock(&local->mtx);
77141
77142 if (coming_up)
77143 - local->open_count++;
77144 + local_inc(&local->open_count);
77145
77146 if (hw_reconf_flags) {
77147 ieee80211_hw_config(local, hw_reconf_flags);
77148 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77149 err_del_interface:
77150 drv_remove_interface(local, &sdata->vif);
77151 err_stop:
77152 - if (!local->open_count)
77153 + if (!local_read(&local->open_count))
77154 drv_stop(local);
77155 err_del_bss:
77156 sdata->bss = NULL;
77157 @@ -474,7 +474,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77158 }
77159
77160 if (going_down)
77161 - local->open_count--;
77162 + local_dec(&local->open_count);
77163
77164 switch (sdata->vif.type) {
77165 case NL80211_IFTYPE_AP_VLAN:
77166 @@ -533,7 +533,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77167
77168 ieee80211_recalc_ps(local, -1);
77169
77170 - if (local->open_count == 0) {
77171 + if (local_read(&local->open_count) == 0) {
77172 if (local->ops->napi_poll)
77173 napi_disable(&local->napi);
77174 ieee80211_clear_tx_pending(local);
77175 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77176 index 3d90dad..36884d5 100644
77177 --- a/net/mac80211/main.c
77178 +++ b/net/mac80211/main.c
77179 @@ -209,7 +209,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77180 local->hw.conf.power_level = power;
77181 }
77182
77183 - if (changed && local->open_count) {
77184 + if (changed && local_read(&local->open_count)) {
77185 ret = drv_config(local, changed);
77186 /*
77187 * Goal:
77188 diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
77189 index 0f48368..d48e688 100644
77190 --- a/net/mac80211/mlme.c
77191 +++ b/net/mac80211/mlme.c
77192 @@ -1464,6 +1464,8 @@ static bool ieee80211_assoc_success(struct ieee80211_work *wk,
77193 bool have_higher_than_11mbit = false;
77194 u16 ap_ht_cap_flags;
77195
77196 + pax_track_stack();
77197 +
77198 /* AssocResp and ReassocResp have identical structure */
77199
77200 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
77201 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77202 index 6326d34..7225f61 100644
77203 --- a/net/mac80211/pm.c
77204 +++ b/net/mac80211/pm.c
77205 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77206 struct ieee80211_sub_if_data *sdata;
77207 struct sta_info *sta;
77208
77209 - if (!local->open_count)
77210 + if (!local_read(&local->open_count))
77211 goto suspend;
77212
77213 ieee80211_scan_cancel(local);
77214 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77215 cancel_work_sync(&local->dynamic_ps_enable_work);
77216 del_timer_sync(&local->dynamic_ps_timer);
77217
77218 - local->wowlan = wowlan && local->open_count;
77219 + local->wowlan = wowlan && local_read(&local->open_count);
77220 if (local->wowlan) {
77221 int err = drv_suspend(local, wowlan);
77222 if (err < 0) {
77223 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77224 }
77225
77226 /* stop hardware - this must stop RX */
77227 - if (local->open_count)
77228 + if (local_read(&local->open_count))
77229 ieee80211_stop_device(local);
77230
77231 suspend:
77232 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
77233 index 3d5a2cb..b17ad48 100644
77234 --- a/net/mac80211/rate.c
77235 +++ b/net/mac80211/rate.c
77236 @@ -371,7 +371,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
77237
77238 ASSERT_RTNL();
77239
77240 - if (local->open_count)
77241 + if (local_read(&local->open_count))
77242 return -EBUSY;
77243
77244 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77245 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
77246 index 4851e9e..d860e05 100644
77247 --- a/net/mac80211/rc80211_pid_debugfs.c
77248 +++ b/net/mac80211/rc80211_pid_debugfs.c
77249 @@ -192,7 +192,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
77250
77251 spin_unlock_irqrestore(&events->lock, status);
77252
77253 - if (copy_to_user(buf, pb, p))
77254 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77255 return -EFAULT;
77256
77257 return p;
77258 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
77259 index fd031e8..84fbfcf 100644
77260 --- a/net/mac80211/util.c
77261 +++ b/net/mac80211/util.c
77262 @@ -1170,7 +1170,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
77263 drv_set_coverage_class(local, hw->wiphy->coverage_class);
77264
77265 /* everything else happens only if HW was up & running */
77266 - if (!local->open_count)
77267 + if (!local_read(&local->open_count))
77268 goto wake_up;
77269
77270 /*
77271 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
77272 index 32bff6d..d0cf986 100644
77273 --- a/net/netfilter/Kconfig
77274 +++ b/net/netfilter/Kconfig
77275 @@ -781,6 +781,16 @@ config NETFILTER_XT_MATCH_ESP
77276
77277 To compile it as a module, choose M here. If unsure, say N.
77278
77279 +config NETFILTER_XT_MATCH_GRADM
77280 + tristate '"gradm" match support'
77281 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77282 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77283 + ---help---
77284 + The gradm match allows to match on grsecurity RBAC being enabled.
77285 + It is useful when iptables rules are applied early on bootup to
77286 + prevent connections to the machine (except from a trusted host)
77287 + while the RBAC system is disabled.
77288 +
77289 config NETFILTER_XT_MATCH_HASHLIMIT
77290 tristate '"hashlimit" match support'
77291 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77292 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77293 index 1a02853..5d8c22e 100644
77294 --- a/net/netfilter/Makefile
77295 +++ b/net/netfilter/Makefile
77296 @@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
77297 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77298 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77299 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77300 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77301 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77302 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77303 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77304 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77305 index 12571fb..fb73976 100644
77306 --- a/net/netfilter/ipvs/ip_vs_conn.c
77307 +++ b/net/netfilter/ipvs/ip_vs_conn.c
77308 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77309 /* Increase the refcnt counter of the dest */
77310 atomic_inc(&dest->refcnt);
77311
77312 - conn_flags = atomic_read(&dest->conn_flags);
77313 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77314 if (cp->protocol != IPPROTO_UDP)
77315 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77316 /* Bind with the destination and its corresponding transmitter */
77317 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77318 atomic_set(&cp->refcnt, 1);
77319
77320 atomic_set(&cp->n_control, 0);
77321 - atomic_set(&cp->in_pkts, 0);
77322 + atomic_set_unchecked(&cp->in_pkts, 0);
77323
77324 atomic_inc(&ipvs->conn_count);
77325 if (flags & IP_VS_CONN_F_NO_CPORT)
77326 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77327
77328 /* Don't drop the entry if its number of incoming packets is not
77329 located in [0, 8] */
77330 - i = atomic_read(&cp->in_pkts);
77331 + i = atomic_read_unchecked(&cp->in_pkts);
77332 if (i > 8 || i < 0) return 0;
77333
77334 if (!todrop_rate[i]) return 0;
77335 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77336 index 4f77bb1..5d0bc26 100644
77337 --- a/net/netfilter/ipvs/ip_vs_core.c
77338 +++ b/net/netfilter/ipvs/ip_vs_core.c
77339 @@ -563,7 +563,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77340 ret = cp->packet_xmit(skb, cp, pd->pp);
77341 /* do not touch skb anymore */
77342
77343 - atomic_inc(&cp->in_pkts);
77344 + atomic_inc_unchecked(&cp->in_pkts);
77345 ip_vs_conn_put(cp);
77346 return ret;
77347 }
77348 @@ -1612,7 +1612,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77349 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77350 pkts = sysctl_sync_threshold(ipvs);
77351 else
77352 - pkts = atomic_add_return(1, &cp->in_pkts);
77353 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77354
77355 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
77356 cp->protocol == IPPROTO_SCTP) {
77357 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77358 index e3be48b..d658c8c 100644
77359 --- a/net/netfilter/ipvs/ip_vs_ctl.c
77360 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
77361 @@ -782,7 +782,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77362 ip_vs_rs_hash(ipvs, dest);
77363 write_unlock_bh(&ipvs->rs_lock);
77364 }
77365 - atomic_set(&dest->conn_flags, conn_flags);
77366 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77367
77368 /* bind the service */
77369 if (!dest->svc) {
77370 @@ -2027,7 +2027,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77371 " %-7s %-6d %-10d %-10d\n",
77372 &dest->addr.in6,
77373 ntohs(dest->port),
77374 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77375 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77376 atomic_read(&dest->weight),
77377 atomic_read(&dest->activeconns),
77378 atomic_read(&dest->inactconns));
77379 @@ -2038,7 +2038,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77380 "%-7s %-6d %-10d %-10d\n",
77381 ntohl(dest->addr.ip),
77382 ntohs(dest->port),
77383 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77384 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77385 atomic_read(&dest->weight),
77386 atomic_read(&dest->activeconns),
77387 atomic_read(&dest->inactconns));
77388 @@ -2285,6 +2285,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
77389 struct ip_vs_dest_user_kern udest;
77390 struct netns_ipvs *ipvs = net_ipvs(net);
77391
77392 + pax_track_stack();
77393 +
77394 if (!capable(CAP_NET_ADMIN))
77395 return -EPERM;
77396
77397 @@ -2508,7 +2510,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77398
77399 entry.addr = dest->addr.ip;
77400 entry.port = dest->port;
77401 - entry.conn_flags = atomic_read(&dest->conn_flags);
77402 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77403 entry.weight = atomic_read(&dest->weight);
77404 entry.u_threshold = dest->u_threshold;
77405 entry.l_threshold = dest->l_threshold;
77406 @@ -3041,7 +3043,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77407 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
77408
77409 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77410 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77411 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77412 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
77413 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
77414 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
77415 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77416 index 3cdd479..116afa8 100644
77417 --- a/net/netfilter/ipvs/ip_vs_sync.c
77418 +++ b/net/netfilter/ipvs/ip_vs_sync.c
77419 @@ -649,7 +649,7 @@ control:
77420 * i.e only increment in_pkts for Templates.
77421 */
77422 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
77423 - int pkts = atomic_add_return(1, &cp->in_pkts);
77424 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77425
77426 if (pkts % sysctl_sync_period(ipvs) != 1)
77427 return;
77428 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77429
77430 if (opt)
77431 memcpy(&cp->in_seq, opt, sizeof(*opt));
77432 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77433 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77434 cp->state = state;
77435 cp->old_state = cp->state;
77436 /*
77437 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77438 index ee319a4..8a285ee 100644
77439 --- a/net/netfilter/ipvs/ip_vs_xmit.c
77440 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
77441 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77442 else
77443 rc = NF_ACCEPT;
77444 /* do not touch skb anymore */
77445 - atomic_inc(&cp->in_pkts);
77446 + atomic_inc_unchecked(&cp->in_pkts);
77447 goto out;
77448 }
77449
77450 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77451 else
77452 rc = NF_ACCEPT;
77453 /* do not touch skb anymore */
77454 - atomic_inc(&cp->in_pkts);
77455 + atomic_inc_unchecked(&cp->in_pkts);
77456 goto out;
77457 }
77458
77459 diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
77460 index 7dec88a..0996ce3 100644
77461 --- a/net/netfilter/nf_conntrack_netlink.c
77462 +++ b/net/netfilter/nf_conntrack_netlink.c
77463 @@ -135,7 +135,7 @@ nla_put_failure:
77464 static inline int
77465 ctnetlink_dump_timeout(struct sk_buff *skb, const struct nf_conn *ct)
77466 {
77467 - long timeout = (ct->timeout.expires - jiffies) / HZ;
77468 + long timeout = ((long)ct->timeout.expires - (long)jiffies) / HZ;
77469
77470 if (timeout < 0)
77471 timeout = 0;
77472 @@ -1638,7 +1638,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,
77473 const struct nf_conntrack_expect *exp)
77474 {
77475 struct nf_conn *master = exp->master;
77476 - long timeout = (exp->timeout.expires - jiffies) / HZ;
77477 + long timeout = ((long)exp->timeout.expires - (long)jiffies) / HZ;
77478 struct nf_conn_help *help;
77479
77480 if (timeout < 0)
77481 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77482 index 2d8158a..5dca296 100644
77483 --- a/net/netfilter/nfnetlink_log.c
77484 +++ b/net/netfilter/nfnetlink_log.c
77485 @@ -70,7 +70,7 @@ struct nfulnl_instance {
77486 };
77487
77488 static DEFINE_SPINLOCK(instances_lock);
77489 -static atomic_t global_seq;
77490 +static atomic_unchecked_t global_seq;
77491
77492 #define INSTANCE_BUCKETS 16
77493 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77494 @@ -505,7 +505,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77495 /* global sequence number */
77496 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
77497 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
77498 - htonl(atomic_inc_return(&global_seq)));
77499 + htonl(atomic_inc_return_unchecked(&global_seq)));
77500
77501 if (data_len) {
77502 struct nlattr *nla;
77503 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77504 new file mode 100644
77505 index 0000000..6905327
77506 --- /dev/null
77507 +++ b/net/netfilter/xt_gradm.c
77508 @@ -0,0 +1,51 @@
77509 +/*
77510 + * gradm match for netfilter
77511 + * Copyright © Zbigniew Krzystolik, 2010
77512 + *
77513 + * This program is free software; you can redistribute it and/or modify
77514 + * it under the terms of the GNU General Public License; either version
77515 + * 2 or 3 as published by the Free Software Foundation.
77516 + */
77517 +#include <linux/module.h>
77518 +#include <linux/moduleparam.h>
77519 +#include <linux/skbuff.h>
77520 +#include <linux/netfilter/x_tables.h>
77521 +#include <linux/grsecurity.h>
77522 +#include <linux/netfilter/xt_gradm.h>
77523 +
77524 +static bool
77525 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
77526 +{
77527 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77528 + bool retval = false;
77529 + if (gr_acl_is_enabled())
77530 + retval = true;
77531 + return retval ^ info->invflags;
77532 +}
77533 +
77534 +static struct xt_match gradm_mt_reg __read_mostly = {
77535 + .name = "gradm",
77536 + .revision = 0,
77537 + .family = NFPROTO_UNSPEC,
77538 + .match = gradm_mt,
77539 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77540 + .me = THIS_MODULE,
77541 +};
77542 +
77543 +static int __init gradm_mt_init(void)
77544 +{
77545 + return xt_register_match(&gradm_mt_reg);
77546 +}
77547 +
77548 +static void __exit gradm_mt_exit(void)
77549 +{
77550 + xt_unregister_match(&gradm_mt_reg);
77551 +}
77552 +
77553 +module_init(gradm_mt_init);
77554 +module_exit(gradm_mt_exit);
77555 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77556 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77557 +MODULE_LICENSE("GPL");
77558 +MODULE_ALIAS("ipt_gradm");
77559 +MODULE_ALIAS("ip6t_gradm");
77560 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
77561 index 42ecb71..8d687c0 100644
77562 --- a/net/netfilter/xt_statistic.c
77563 +++ b/net/netfilter/xt_statistic.c
77564 @@ -18,7 +18,7 @@
77565 #include <linux/netfilter/x_tables.h>
77566
77567 struct xt_statistic_priv {
77568 - atomic_t count;
77569 + atomic_unchecked_t count;
77570 } ____cacheline_aligned_in_smp;
77571
77572 MODULE_LICENSE("GPL");
77573 @@ -41,9 +41,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
77574 break;
77575 case XT_STATISTIC_MODE_NTH:
77576 do {
77577 - oval = atomic_read(&info->master->count);
77578 + oval = atomic_read_unchecked(&info->master->count);
77579 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77580 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77581 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77582 if (nval == 0)
77583 ret = !ret;
77584 break;
77585 @@ -63,7 +63,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
77586 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77587 if (info->master == NULL)
77588 return -ENOMEM;
77589 - atomic_set(&info->master->count, info->u.nth.count);
77590 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77591
77592 return 0;
77593 }
77594 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
77595 index 0a4db02..604f748 100644
77596 --- a/net/netlink/af_netlink.c
77597 +++ b/net/netlink/af_netlink.c
77598 @@ -742,7 +742,7 @@ static void netlink_overrun(struct sock *sk)
77599 sk->sk_error_report(sk);
77600 }
77601 }
77602 - atomic_inc(&sk->sk_drops);
77603 + atomic_inc_unchecked(&sk->sk_drops);
77604 }
77605
77606 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77607 @@ -2000,7 +2000,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
77608 sk_wmem_alloc_get(s),
77609 nlk->cb,
77610 atomic_read(&s->sk_refcnt),
77611 - atomic_read(&s->sk_drops),
77612 + atomic_read_unchecked(&s->sk_drops),
77613 sock_i_ino(s)
77614 );
77615
77616 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77617 index 732152f..60bb09e 100644
77618 --- a/net/netrom/af_netrom.c
77619 +++ b/net/netrom/af_netrom.c
77620 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77621 struct sock *sk = sock->sk;
77622 struct nr_sock *nr = nr_sk(sk);
77623
77624 + memset(sax, 0, sizeof(*sax));
77625 lock_sock(sk);
77626 if (peer != 0) {
77627 if (sk->sk_state != TCP_ESTABLISHED) {
77628 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77629 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77630 } else {
77631 sax->fsa_ax25.sax25_family = AF_NETROM;
77632 - sax->fsa_ax25.sax25_ndigis = 0;
77633 sax->fsa_ax25.sax25_call = nr->source_addr;
77634 *uaddr_len = sizeof(struct sockaddr_ax25);
77635 }
77636 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77637 index fabb4fa..37aaea0 100644
77638 --- a/net/packet/af_packet.c
77639 +++ b/net/packet/af_packet.c
77640 @@ -954,7 +954,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77641
77642 spin_lock(&sk->sk_receive_queue.lock);
77643 po->stats.tp_packets++;
77644 - skb->dropcount = atomic_read(&sk->sk_drops);
77645 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77646 __skb_queue_tail(&sk->sk_receive_queue, skb);
77647 spin_unlock(&sk->sk_receive_queue.lock);
77648 sk->sk_data_ready(sk, skb->len);
77649 @@ -963,7 +963,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77650 drop_n_acct:
77651 spin_lock(&sk->sk_receive_queue.lock);
77652 po->stats.tp_drops++;
77653 - atomic_inc(&sk->sk_drops);
77654 + atomic_inc_unchecked(&sk->sk_drops);
77655 spin_unlock(&sk->sk_receive_queue.lock);
77656
77657 drop_n_restore:
77658 @@ -1691,8 +1691,12 @@ static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 protoc
77659 {
77660 struct packet_sock *po = pkt_sk(sk);
77661
77662 - if (po->fanout)
77663 + if (po->fanout) {
77664 + if (dev)
77665 + dev_put(dev);
77666 +
77667 return -EINVAL;
77668 + }
77669
77670 lock_sock(sk);
77671
77672 @@ -2479,7 +2483,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77673 case PACKET_HDRLEN:
77674 if (len > sizeof(int))
77675 len = sizeof(int);
77676 - if (copy_from_user(&val, optval, len))
77677 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77678 return -EFAULT;
77679 switch (val) {
77680 case TPACKET_V1:
77681 @@ -2526,7 +2530,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77682
77683 if (put_user(len, optlen))
77684 return -EFAULT;
77685 - if (copy_to_user(optval, data, len))
77686 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77687 return -EFAULT;
77688 return 0;
77689 }
77690 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77691 index c6fffd9..a7ffa0c 100644
77692 --- a/net/phonet/af_phonet.c
77693 +++ b/net/phonet/af_phonet.c
77694 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77695 {
77696 struct phonet_protocol *pp;
77697
77698 - if (protocol >= PHONET_NPROTO)
77699 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77700 return NULL;
77701
77702 rcu_read_lock();
77703 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77704 {
77705 int err = 0;
77706
77707 - if (protocol >= PHONET_NPROTO)
77708 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77709 return -EINVAL;
77710
77711 err = proto_register(pp->prot, 1);
77712 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77713 index f17fd84..edffce8 100644
77714 --- a/net/phonet/pep.c
77715 +++ b/net/phonet/pep.c
77716 @@ -387,7 +387,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77717
77718 case PNS_PEP_CTRL_REQ:
77719 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77720 - atomic_inc(&sk->sk_drops);
77721 + atomic_inc_unchecked(&sk->sk_drops);
77722 break;
77723 }
77724 __skb_pull(skb, 4);
77725 @@ -408,7 +408,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77726 }
77727
77728 if (pn->rx_credits == 0) {
77729 - atomic_inc(&sk->sk_drops);
77730 + atomic_inc_unchecked(&sk->sk_drops);
77731 err = -ENOBUFS;
77732 break;
77733 }
77734 @@ -556,7 +556,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77735 }
77736
77737 if (pn->rx_credits == 0) {
77738 - atomic_inc(&sk->sk_drops);
77739 + atomic_inc_unchecked(&sk->sk_drops);
77740 err = NET_RX_DROP;
77741 break;
77742 }
77743 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77744 index ab07711..9d4ac5d 100644
77745 --- a/net/phonet/socket.c
77746 +++ b/net/phonet/socket.c
77747 @@ -612,8 +612,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77748 pn->resource, sk->sk_state,
77749 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77750 sock_i_uid(sk), sock_i_ino(sk),
77751 - atomic_read(&sk->sk_refcnt), sk,
77752 - atomic_read(&sk->sk_drops), &len);
77753 + atomic_read(&sk->sk_refcnt),
77754 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77755 + NULL,
77756 +#else
77757 + sk,
77758 +#endif
77759 + atomic_read_unchecked(&sk->sk_drops), &len);
77760 }
77761 seq_printf(seq, "%*s\n", 127 - len, "");
77762 return 0;
77763 diff --git a/net/rds/cong.c b/net/rds/cong.c
77764 index 6daaa49..fbf6af5 100644
77765 --- a/net/rds/cong.c
77766 +++ b/net/rds/cong.c
77767 @@ -77,7 +77,7 @@
77768 * finds that the saved generation number is smaller than the global generation
77769 * number, it wakes up the process.
77770 */
77771 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77772 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77773
77774 /*
77775 * Congestion monitoring
77776 @@ -232,7 +232,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
77777 rdsdebug("waking map %p for %pI4\n",
77778 map, &map->m_addr);
77779 rds_stats_inc(s_cong_update_received);
77780 - atomic_inc(&rds_cong_generation);
77781 + atomic_inc_unchecked(&rds_cong_generation);
77782 if (waitqueue_active(&map->m_waitq))
77783 wake_up(&map->m_waitq);
77784 if (waitqueue_active(&rds_poll_waitq))
77785 @@ -258,7 +258,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77786
77787 int rds_cong_updated_since(unsigned long *recent)
77788 {
77789 - unsigned long gen = atomic_read(&rds_cong_generation);
77790 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77791
77792 if (likely(*recent == gen))
77793 return 0;
77794 diff --git a/net/rds/ib.h b/net/rds/ib.h
77795 index edfaaaf..8c89879 100644
77796 --- a/net/rds/ib.h
77797 +++ b/net/rds/ib.h
77798 @@ -128,7 +128,7 @@ struct rds_ib_connection {
77799 /* sending acks */
77800 unsigned long i_ack_flags;
77801 #ifdef KERNEL_HAS_ATOMIC64
77802 - atomic64_t i_ack_next; /* next ACK to send */
77803 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77804 #else
77805 spinlock_t i_ack_lock; /* protect i_ack_next */
77806 u64 i_ack_next; /* next ACK to send */
77807 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
77808 index cd67026..0b9a54a 100644
77809 --- a/net/rds/ib_cm.c
77810 +++ b/net/rds/ib_cm.c
77811 @@ -720,7 +720,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
77812 /* Clear the ACK state */
77813 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77814 #ifdef KERNEL_HAS_ATOMIC64
77815 - atomic64_set(&ic->i_ack_next, 0);
77816 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77817 #else
77818 ic->i_ack_next = 0;
77819 #endif
77820 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
77821 index e29e0ca..fa3a6a3 100644
77822 --- a/net/rds/ib_recv.c
77823 +++ b/net/rds/ib_recv.c
77824 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77825 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77826 int ack_required)
77827 {
77828 - atomic64_set(&ic->i_ack_next, seq);
77829 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77830 if (ack_required) {
77831 smp_mb__before_clear_bit();
77832 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77833 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77834 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77835 smp_mb__after_clear_bit();
77836
77837 - return atomic64_read(&ic->i_ack_next);
77838 + return atomic64_read_unchecked(&ic->i_ack_next);
77839 }
77840 #endif
77841
77842 diff --git a/net/rds/iw.h b/net/rds/iw.h
77843 index 04ce3b1..48119a6 100644
77844 --- a/net/rds/iw.h
77845 +++ b/net/rds/iw.h
77846 @@ -134,7 +134,7 @@ struct rds_iw_connection {
77847 /* sending acks */
77848 unsigned long i_ack_flags;
77849 #ifdef KERNEL_HAS_ATOMIC64
77850 - atomic64_t i_ack_next; /* next ACK to send */
77851 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77852 #else
77853 spinlock_t i_ack_lock; /* protect i_ack_next */
77854 u64 i_ack_next; /* next ACK to send */
77855 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
77856 index 9556d28..f046d0e 100644
77857 --- a/net/rds/iw_cm.c
77858 +++ b/net/rds/iw_cm.c
77859 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
77860 /* Clear the ACK state */
77861 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77862 #ifdef KERNEL_HAS_ATOMIC64
77863 - atomic64_set(&ic->i_ack_next, 0);
77864 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77865 #else
77866 ic->i_ack_next = 0;
77867 #endif
77868 diff --git a/net/rds/iw_rdma.c b/net/rds/iw_rdma.c
77869 index 4e1de17..d121708 100644
77870 --- a/net/rds/iw_rdma.c
77871 +++ b/net/rds/iw_rdma.c
77872 @@ -184,6 +184,8 @@ int rds_iw_update_cm_id(struct rds_iw_device *rds_iwdev, struct rdma_cm_id *cm_i
77873 struct rdma_cm_id *pcm_id;
77874 int rc;
77875
77876 + pax_track_stack();
77877 +
77878 src_addr = (struct sockaddr_in *)&cm_id->route.addr.src_addr;
77879 dst_addr = (struct sockaddr_in *)&cm_id->route.addr.dst_addr;
77880
77881 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
77882 index 5e57347..3916042 100644
77883 --- a/net/rds/iw_recv.c
77884 +++ b/net/rds/iw_recv.c
77885 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77886 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77887 int ack_required)
77888 {
77889 - atomic64_set(&ic->i_ack_next, seq);
77890 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77891 if (ack_required) {
77892 smp_mb__before_clear_bit();
77893 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77894 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77895 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77896 smp_mb__after_clear_bit();
77897
77898 - return atomic64_read(&ic->i_ack_next);
77899 + return atomic64_read_unchecked(&ic->i_ack_next);
77900 }
77901 #endif
77902
77903 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
77904 index 8e0a320..ee8e38f 100644
77905 --- a/net/rds/tcp.c
77906 +++ b/net/rds/tcp.c
77907 @@ -58,7 +58,7 @@ void rds_tcp_nonagle(struct socket *sock)
77908 int val = 1;
77909
77910 set_fs(KERNEL_DS);
77911 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77912 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77913 sizeof(val));
77914 set_fs(oldfs);
77915 }
77916 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
77917 index 1b4fd68..2234175 100644
77918 --- a/net/rds/tcp_send.c
77919 +++ b/net/rds/tcp_send.c
77920 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
77921
77922 oldfs = get_fs();
77923 set_fs(KERNEL_DS);
77924 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77925 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77926 sizeof(val));
77927 set_fs(oldfs);
77928 }
77929 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
77930 index 74c064c..fdec26f 100644
77931 --- a/net/rxrpc/af_rxrpc.c
77932 +++ b/net/rxrpc/af_rxrpc.c
77933 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
77934 __be32 rxrpc_epoch;
77935
77936 /* current debugging ID */
77937 -atomic_t rxrpc_debug_id;
77938 +atomic_unchecked_t rxrpc_debug_id;
77939
77940 /* count of skbs currently in use */
77941 atomic_t rxrpc_n_skbs;
77942 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
77943 index f99cfce..3682692 100644
77944 --- a/net/rxrpc/ar-ack.c
77945 +++ b/net/rxrpc/ar-ack.c
77946 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77947
77948 _enter("{%d,%d,%d,%d},",
77949 call->acks_hard, call->acks_unacked,
77950 - atomic_read(&call->sequence),
77951 + atomic_read_unchecked(&call->sequence),
77952 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77953
77954 stop = 0;
77955 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77956
77957 /* each Tx packet has a new serial number */
77958 sp->hdr.serial =
77959 - htonl(atomic_inc_return(&call->conn->serial));
77960 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77961
77962 hdr = (struct rxrpc_header *) txb->head;
77963 hdr->serial = sp->hdr.serial;
77964 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
77965 */
77966 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77967 {
77968 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77969 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77970 }
77971
77972 /*
77973 @@ -629,7 +629,7 @@ process_further:
77974
77975 latest = ntohl(sp->hdr.serial);
77976 hard = ntohl(ack.firstPacket);
77977 - tx = atomic_read(&call->sequence);
77978 + tx = atomic_read_unchecked(&call->sequence);
77979
77980 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77981 latest,
77982 @@ -842,6 +842,8 @@ void rxrpc_process_call(struct work_struct *work)
77983 u32 abort_code = RX_PROTOCOL_ERROR;
77984 u8 *acks = NULL;
77985
77986 + pax_track_stack();
77987 +
77988 //printk("\n--------------------\n");
77989 _enter("{%d,%s,%lx} [%lu]",
77990 call->debug_id, rxrpc_call_states[call->state], call->events,
77991 @@ -1161,7 +1163,7 @@ void rxrpc_process_call(struct work_struct *work)
77992 goto maybe_reschedule;
77993
77994 send_ACK_with_skew:
77995 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77996 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77997 ntohl(ack.serial));
77998 send_ACK:
77999 mtu = call->conn->trans->peer->if_mtu;
78000 @@ -1173,7 +1175,7 @@ send_ACK:
78001 ackinfo.rxMTU = htonl(5692);
78002 ackinfo.jumbo_max = htonl(4);
78003
78004 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78005 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78006 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78007 ntohl(hdr.serial),
78008 ntohs(ack.maxSkew),
78009 @@ -1191,7 +1193,7 @@ send_ACK:
78010 send_message:
78011 _debug("send message");
78012
78013 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78014 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78015 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78016 send_message_2:
78017
78018 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
78019 index bf656c2..48f9d27 100644
78020 --- a/net/rxrpc/ar-call.c
78021 +++ b/net/rxrpc/ar-call.c
78022 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
78023 spin_lock_init(&call->lock);
78024 rwlock_init(&call->state_lock);
78025 atomic_set(&call->usage, 1);
78026 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78027 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78028 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78029
78030 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78031 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
78032 index 4106ca9..a338d7a 100644
78033 --- a/net/rxrpc/ar-connection.c
78034 +++ b/net/rxrpc/ar-connection.c
78035 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
78036 rwlock_init(&conn->lock);
78037 spin_lock_init(&conn->state_lock);
78038 atomic_set(&conn->usage, 1);
78039 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78040 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78041 conn->avail_calls = RXRPC_MAXCALLS;
78042 conn->size_align = 4;
78043 conn->header_size = sizeof(struct rxrpc_header);
78044 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
78045 index e7ed43a..6afa140 100644
78046 --- a/net/rxrpc/ar-connevent.c
78047 +++ b/net/rxrpc/ar-connevent.c
78048 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
78049
78050 len = iov[0].iov_len + iov[1].iov_len;
78051
78052 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78053 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78054 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78055
78056 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78057 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
78058 index 1a2b0633..e8d1382 100644
78059 --- a/net/rxrpc/ar-input.c
78060 +++ b/net/rxrpc/ar-input.c
78061 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
78062 /* track the latest serial number on this connection for ACK packet
78063 * information */
78064 serial = ntohl(sp->hdr.serial);
78065 - hi_serial = atomic_read(&call->conn->hi_serial);
78066 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78067 while (serial > hi_serial)
78068 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78069 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78070 serial);
78071
78072 /* request ACK generation for any ACK or DATA packet that requests
78073 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
78074 index 8e22bd3..f66d1c0 100644
78075 --- a/net/rxrpc/ar-internal.h
78076 +++ b/net/rxrpc/ar-internal.h
78077 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78078 int error; /* error code for local abort */
78079 int debug_id; /* debug ID for printks */
78080 unsigned call_counter; /* call ID counter */
78081 - atomic_t serial; /* packet serial number counter */
78082 - atomic_t hi_serial; /* highest serial number received */
78083 + atomic_unchecked_t serial; /* packet serial number counter */
78084 + atomic_unchecked_t hi_serial; /* highest serial number received */
78085 u8 avail_calls; /* number of calls available */
78086 u8 size_align; /* data size alignment (for security) */
78087 u8 header_size; /* rxrpc + security header size */
78088 @@ -346,7 +346,7 @@ struct rxrpc_call {
78089 spinlock_t lock;
78090 rwlock_t state_lock; /* lock for state transition */
78091 atomic_t usage;
78092 - atomic_t sequence; /* Tx data packet sequence counter */
78093 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78094 u32 abort_code; /* local/remote abort code */
78095 enum { /* current state of call */
78096 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78097 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
78098 */
78099 extern atomic_t rxrpc_n_skbs;
78100 extern __be32 rxrpc_epoch;
78101 -extern atomic_t rxrpc_debug_id;
78102 +extern atomic_unchecked_t rxrpc_debug_id;
78103 extern struct workqueue_struct *rxrpc_workqueue;
78104
78105 /*
78106 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
78107 index 87f7135..74d3703 100644
78108 --- a/net/rxrpc/ar-local.c
78109 +++ b/net/rxrpc/ar-local.c
78110 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
78111 spin_lock_init(&local->lock);
78112 rwlock_init(&local->services_lock);
78113 atomic_set(&local->usage, 1);
78114 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78115 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78116 memcpy(&local->srx, srx, sizeof(*srx));
78117 }
78118
78119 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
78120 index 5f22e26..e5bd20f 100644
78121 --- a/net/rxrpc/ar-output.c
78122 +++ b/net/rxrpc/ar-output.c
78123 @@ -681,9 +681,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
78124 sp->hdr.cid = call->cid;
78125 sp->hdr.callNumber = call->call_id;
78126 sp->hdr.seq =
78127 - htonl(atomic_inc_return(&call->sequence));
78128 + htonl(atomic_inc_return_unchecked(&call->sequence));
78129 sp->hdr.serial =
78130 - htonl(atomic_inc_return(&conn->serial));
78131 + htonl(atomic_inc_return_unchecked(&conn->serial));
78132 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78133 sp->hdr.userStatus = 0;
78134 sp->hdr.securityIndex = conn->security_ix;
78135 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
78136 index 2754f09..b20e38f 100644
78137 --- a/net/rxrpc/ar-peer.c
78138 +++ b/net/rxrpc/ar-peer.c
78139 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
78140 INIT_LIST_HEAD(&peer->error_targets);
78141 spin_lock_init(&peer->lock);
78142 atomic_set(&peer->usage, 1);
78143 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78144 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78145 memcpy(&peer->srx, srx, sizeof(*srx));
78146
78147 rxrpc_assess_MTU_size(peer);
78148 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
78149 index 38047f7..9f48511 100644
78150 --- a/net/rxrpc/ar-proc.c
78151 +++ b/net/rxrpc/ar-proc.c
78152 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
78153 atomic_read(&conn->usage),
78154 rxrpc_conn_states[conn->state],
78155 key_serial(conn->key),
78156 - atomic_read(&conn->serial),
78157 - atomic_read(&conn->hi_serial));
78158 + atomic_read_unchecked(&conn->serial),
78159 + atomic_read_unchecked(&conn->hi_serial));
78160
78161 return 0;
78162 }
78163 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
78164 index 92df566..87ec1bf 100644
78165 --- a/net/rxrpc/ar-transport.c
78166 +++ b/net/rxrpc/ar-transport.c
78167 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
78168 spin_lock_init(&trans->client_lock);
78169 rwlock_init(&trans->conn_lock);
78170 atomic_set(&trans->usage, 1);
78171 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78172 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78173
78174 if (peer->srx.transport.family == AF_INET) {
78175 switch (peer->srx.transport_type) {
78176 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
78177 index 7635107..5000b71 100644
78178 --- a/net/rxrpc/rxkad.c
78179 +++ b/net/rxrpc/rxkad.c
78180 @@ -211,6 +211,8 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
78181 u16 check;
78182 int nsg;
78183
78184 + pax_track_stack();
78185 +
78186 sp = rxrpc_skb(skb);
78187
78188 _enter("");
78189 @@ -338,6 +340,8 @@ static int rxkad_verify_packet_auth(const struct rxrpc_call *call,
78190 u16 check;
78191 int nsg;
78192
78193 + pax_track_stack();
78194 +
78195 _enter("");
78196
78197 sp = rxrpc_skb(skb);
78198 @@ -610,7 +614,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
78199
78200 len = iov[0].iov_len + iov[1].iov_len;
78201
78202 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78203 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78204 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78205
78206 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78207 @@ -660,7 +664,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
78208
78209 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78210
78211 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78212 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78213 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78214
78215 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78216 diff --git a/net/sctp/auth.c b/net/sctp/auth.c
78217 index 865e68f..bf81204 100644
78218 --- a/net/sctp/auth.c
78219 +++ b/net/sctp/auth.c
78220 @@ -82,7 +82,7 @@ static struct sctp_auth_bytes *sctp_auth_create_key(__u32 key_len, gfp_t gfp)
78221 struct sctp_auth_bytes *key;
78222
78223 /* Verify that we are not going to overflow INT_MAX */
78224 - if ((INT_MAX - key_len) < sizeof(struct sctp_auth_bytes))
78225 + if (key_len > (INT_MAX - sizeof(struct sctp_auth_bytes)))
78226 return NULL;
78227
78228 /* Allocate the shared key */
78229 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
78230 index 05a6ce2..c8bf836 100644
78231 --- a/net/sctp/proc.c
78232 +++ b/net/sctp/proc.c
78233 @@ -318,7 +318,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
78234 seq_printf(seq,
78235 "%8pK %8pK %-3d %-3d %-2d %-4d "
78236 "%4d %8d %8d %7d %5lu %-5d %5d ",
78237 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78238 + assoc, sk,
78239 + sctp_sk(sk)->type, sk->sk_state,
78240 assoc->state, hash,
78241 assoc->assoc_id,
78242 assoc->sndbuf_used,
78243 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
78244 index 4760f4e..e44d3fb 100644
78245 --- a/net/sctp/socket.c
78246 +++ b/net/sctp/socket.c
78247 @@ -4573,7 +4573,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
78248 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
78249 if (space_left < addrlen)
78250 return -ENOMEM;
78251 - if (copy_to_user(to, &temp, addrlen))
78252 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
78253 return -EFAULT;
78254 to += addrlen;
78255 cnt++;
78256 diff --git a/net/socket.c b/net/socket.c
78257 index ffe92ca..8057b85 100644
78258 --- a/net/socket.c
78259 +++ b/net/socket.c
78260 @@ -88,6 +88,7 @@
78261 #include <linux/nsproxy.h>
78262 #include <linux/magic.h>
78263 #include <linux/slab.h>
78264 +#include <linux/in.h>
78265
78266 #include <asm/uaccess.h>
78267 #include <asm/unistd.h>
78268 @@ -105,6 +106,8 @@
78269 #include <linux/sockios.h>
78270 #include <linux/atalk.h>
78271
78272 +#include <linux/grsock.h>
78273 +
78274 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
78275 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
78276 unsigned long nr_segs, loff_t pos);
78277 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
78278 &sockfs_dentry_operations, SOCKFS_MAGIC);
78279 }
78280
78281 -static struct vfsmount *sock_mnt __read_mostly;
78282 +struct vfsmount *sock_mnt __read_mostly;
78283
78284 static struct file_system_type sock_fs_type = {
78285 .name = "sockfs",
78286 @@ -1187,6 +1190,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
78287 return -EAFNOSUPPORT;
78288 if (type < 0 || type >= SOCK_MAX)
78289 return -EINVAL;
78290 + if (protocol < 0)
78291 + return -EINVAL;
78292
78293 /* Compatibility.
78294
78295 @@ -1319,6 +1324,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
78296 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
78297 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78298
78299 + if(!gr_search_socket(family, type, protocol)) {
78300 + retval = -EACCES;
78301 + goto out;
78302 + }
78303 +
78304 + if (gr_handle_sock_all(family, type, protocol)) {
78305 + retval = -EACCES;
78306 + goto out;
78307 + }
78308 +
78309 retval = sock_create(family, type, protocol, &sock);
78310 if (retval < 0)
78311 goto out;
78312 @@ -1431,6 +1446,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78313 if (sock) {
78314 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
78315 if (err >= 0) {
78316 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78317 + err = -EACCES;
78318 + goto error;
78319 + }
78320 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78321 + if (err)
78322 + goto error;
78323 +
78324 err = security_socket_bind(sock,
78325 (struct sockaddr *)&address,
78326 addrlen);
78327 @@ -1439,6 +1462,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78328 (struct sockaddr *)
78329 &address, addrlen);
78330 }
78331 +error:
78332 fput_light(sock->file, fput_needed);
78333 }
78334 return err;
78335 @@ -1462,10 +1486,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
78336 if ((unsigned)backlog > somaxconn)
78337 backlog = somaxconn;
78338
78339 + if (gr_handle_sock_server_other(sock->sk)) {
78340 + err = -EPERM;
78341 + goto error;
78342 + }
78343 +
78344 + err = gr_search_listen(sock);
78345 + if (err)
78346 + goto error;
78347 +
78348 err = security_socket_listen(sock, backlog);
78349 if (!err)
78350 err = sock->ops->listen(sock, backlog);
78351
78352 +error:
78353 fput_light(sock->file, fput_needed);
78354 }
78355 return err;
78356 @@ -1509,6 +1543,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78357 newsock->type = sock->type;
78358 newsock->ops = sock->ops;
78359
78360 + if (gr_handle_sock_server_other(sock->sk)) {
78361 + err = -EPERM;
78362 + sock_release(newsock);
78363 + goto out_put;
78364 + }
78365 +
78366 + err = gr_search_accept(sock);
78367 + if (err) {
78368 + sock_release(newsock);
78369 + goto out_put;
78370 + }
78371 +
78372 /*
78373 * We don't need try_module_get here, as the listening socket (sock)
78374 * has the protocol module (sock->ops->owner) held.
78375 @@ -1547,6 +1593,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78376 fd_install(newfd, newfile);
78377 err = newfd;
78378
78379 + gr_attach_curr_ip(newsock->sk);
78380 +
78381 out_put:
78382 fput_light(sock->file, fput_needed);
78383 out:
78384 @@ -1579,6 +1627,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78385 int, addrlen)
78386 {
78387 struct socket *sock;
78388 + struct sockaddr *sck;
78389 struct sockaddr_storage address;
78390 int err, fput_needed;
78391
78392 @@ -1589,6 +1638,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78393 if (err < 0)
78394 goto out_put;
78395
78396 + sck = (struct sockaddr *)&address;
78397 +
78398 + if (gr_handle_sock_client(sck)) {
78399 + err = -EACCES;
78400 + goto out_put;
78401 + }
78402 +
78403 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78404 + if (err)
78405 + goto out_put;
78406 +
78407 err =
78408 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78409 if (err)
78410 @@ -1890,6 +1950,8 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
78411 unsigned char *ctl_buf = ctl;
78412 int err, ctl_len, iov_size, total_len;
78413
78414 + pax_track_stack();
78415 +
78416 err = -EFAULT;
78417 if (MSG_CMSG_COMPAT & flags) {
78418 if (get_compat_msghdr(msg_sys, msg_compat))
78419 @@ -1950,7 +2012,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
78420 * checking falls down on this.
78421 */
78422 if (copy_from_user(ctl_buf,
78423 - (void __user __force *)msg_sys->msg_control,
78424 + (void __force_user *)msg_sys->msg_control,
78425 ctl_len))
78426 goto out_freectl;
78427 msg_sys->msg_control = ctl_buf;
78428 @@ -2120,7 +2182,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
78429 * kernel msghdr to use the kernel address space)
78430 */
78431
78432 - uaddr = (__force void __user *)msg_sys->msg_name;
78433 + uaddr = (void __force_user *)msg_sys->msg_name;
78434 uaddr_len = COMPAT_NAMELEN(msg);
78435 if (MSG_CMSG_COMPAT & flags) {
78436 err = verify_compat_iovec(msg_sys, iov,
78437 @@ -2748,7 +2810,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78438 }
78439
78440 ifr = compat_alloc_user_space(buf_size);
78441 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
78442 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
78443
78444 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
78445 return -EFAULT;
78446 @@ -2772,12 +2834,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78447 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
78448
78449 if (copy_in_user(rxnfc, compat_rxnfc,
78450 - (void *)(&rxnfc->fs.m_ext + 1) -
78451 - (void *)rxnfc) ||
78452 + (void __user *)(&rxnfc->fs.m_ext + 1) -
78453 + (void __user *)rxnfc) ||
78454 copy_in_user(&rxnfc->fs.ring_cookie,
78455 &compat_rxnfc->fs.ring_cookie,
78456 - (void *)(&rxnfc->fs.location + 1) -
78457 - (void *)&rxnfc->fs.ring_cookie) ||
78458 + (void __user *)(&rxnfc->fs.location + 1) -
78459 + (void __user *)&rxnfc->fs.ring_cookie) ||
78460 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
78461 sizeof(rxnfc->rule_cnt)))
78462 return -EFAULT;
78463 @@ -2789,12 +2851,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78464
78465 if (convert_out) {
78466 if (copy_in_user(compat_rxnfc, rxnfc,
78467 - (const void *)(&rxnfc->fs.m_ext + 1) -
78468 - (const void *)rxnfc) ||
78469 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
78470 + (const void __user *)rxnfc) ||
78471 copy_in_user(&compat_rxnfc->fs.ring_cookie,
78472 &rxnfc->fs.ring_cookie,
78473 - (const void *)(&rxnfc->fs.location + 1) -
78474 - (const void *)&rxnfc->fs.ring_cookie) ||
78475 + (const void __user *)(&rxnfc->fs.location + 1) -
78476 + (const void __user *)&rxnfc->fs.ring_cookie) ||
78477 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
78478 sizeof(rxnfc->rule_cnt)))
78479 return -EFAULT;
78480 @@ -2864,7 +2926,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
78481 old_fs = get_fs();
78482 set_fs(KERNEL_DS);
78483 err = dev_ioctl(net, cmd,
78484 - (struct ifreq __user __force *) &kifr);
78485 + (struct ifreq __force_user *) &kifr);
78486 set_fs(old_fs);
78487
78488 return err;
78489 @@ -2973,7 +3035,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
78490
78491 old_fs = get_fs();
78492 set_fs(KERNEL_DS);
78493 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
78494 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
78495 set_fs(old_fs);
78496
78497 if (cmd == SIOCGIFMAP && !err) {
78498 @@ -3078,7 +3140,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
78499 ret |= __get_user(rtdev, &(ur4->rt_dev));
78500 if (rtdev) {
78501 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
78502 - r4.rt_dev = (char __user __force *)devname;
78503 + r4.rt_dev = (char __force_user *)devname;
78504 devname[15] = 0;
78505 } else
78506 r4.rt_dev = NULL;
78507 @@ -3318,8 +3380,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
78508 int __user *uoptlen;
78509 int err;
78510
78511 - uoptval = (char __user __force *) optval;
78512 - uoptlen = (int __user __force *) optlen;
78513 + uoptval = (char __force_user *) optval;
78514 + uoptlen = (int __force_user *) optlen;
78515
78516 set_fs(KERNEL_DS);
78517 if (level == SOL_SOCKET)
78518 @@ -3339,7 +3401,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
78519 char __user *uoptval;
78520 int err;
78521
78522 - uoptval = (char __user __force *) optval;
78523 + uoptval = (char __force_user *) optval;
78524
78525 set_fs(KERNEL_DS);
78526 if (level == SOL_SOCKET)
78527 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
78528 index d12ffa5..0b5a6e2 100644
78529 --- a/net/sunrpc/sched.c
78530 +++ b/net/sunrpc/sched.c
78531 @@ -238,9 +238,9 @@ static int rpc_wait_bit_killable(void *word)
78532 #ifdef RPC_DEBUG
78533 static void rpc_task_set_debuginfo(struct rpc_task *task)
78534 {
78535 - static atomic_t rpc_pid;
78536 + static atomic_unchecked_t rpc_pid;
78537
78538 - task->tk_pid = atomic_inc_return(&rpc_pid);
78539 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78540 }
78541 #else
78542 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78543 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
78544 index 767d494..fe17e9d 100644
78545 --- a/net/sunrpc/svcsock.c
78546 +++ b/net/sunrpc/svcsock.c
78547 @@ -394,7 +394,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
78548 int buflen, unsigned int base)
78549 {
78550 size_t save_iovlen;
78551 - void __user *save_iovbase;
78552 + void *save_iovbase;
78553 unsigned int i;
78554 int ret;
78555
78556 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
78557 index 09af4fa..77110a9 100644
78558 --- a/net/sunrpc/xprtrdma/svc_rdma.c
78559 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
78560 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
78561 static unsigned int min_max_inline = 4096;
78562 static unsigned int max_max_inline = 65536;
78563
78564 -atomic_t rdma_stat_recv;
78565 -atomic_t rdma_stat_read;
78566 -atomic_t rdma_stat_write;
78567 -atomic_t rdma_stat_sq_starve;
78568 -atomic_t rdma_stat_rq_starve;
78569 -atomic_t rdma_stat_rq_poll;
78570 -atomic_t rdma_stat_rq_prod;
78571 -atomic_t rdma_stat_sq_poll;
78572 -atomic_t rdma_stat_sq_prod;
78573 +atomic_unchecked_t rdma_stat_recv;
78574 +atomic_unchecked_t rdma_stat_read;
78575 +atomic_unchecked_t rdma_stat_write;
78576 +atomic_unchecked_t rdma_stat_sq_starve;
78577 +atomic_unchecked_t rdma_stat_rq_starve;
78578 +atomic_unchecked_t rdma_stat_rq_poll;
78579 +atomic_unchecked_t rdma_stat_rq_prod;
78580 +atomic_unchecked_t rdma_stat_sq_poll;
78581 +atomic_unchecked_t rdma_stat_sq_prod;
78582
78583 /* Temporary NFS request map and context caches */
78584 struct kmem_cache *svc_rdma_map_cachep;
78585 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
78586 len -= *ppos;
78587 if (len > *lenp)
78588 len = *lenp;
78589 - if (len && copy_to_user(buffer, str_buf, len))
78590 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78591 return -EFAULT;
78592 *lenp = len;
78593 *ppos += len;
78594 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
78595 {
78596 .procname = "rdma_stat_read",
78597 .data = &rdma_stat_read,
78598 - .maxlen = sizeof(atomic_t),
78599 + .maxlen = sizeof(atomic_unchecked_t),
78600 .mode = 0644,
78601 .proc_handler = read_reset_stat,
78602 },
78603 {
78604 .procname = "rdma_stat_recv",
78605 .data = &rdma_stat_recv,
78606 - .maxlen = sizeof(atomic_t),
78607 + .maxlen = sizeof(atomic_unchecked_t),
78608 .mode = 0644,
78609 .proc_handler = read_reset_stat,
78610 },
78611 {
78612 .procname = "rdma_stat_write",
78613 .data = &rdma_stat_write,
78614 - .maxlen = sizeof(atomic_t),
78615 + .maxlen = sizeof(atomic_unchecked_t),
78616 .mode = 0644,
78617 .proc_handler = read_reset_stat,
78618 },
78619 {
78620 .procname = "rdma_stat_sq_starve",
78621 .data = &rdma_stat_sq_starve,
78622 - .maxlen = sizeof(atomic_t),
78623 + .maxlen = sizeof(atomic_unchecked_t),
78624 .mode = 0644,
78625 .proc_handler = read_reset_stat,
78626 },
78627 {
78628 .procname = "rdma_stat_rq_starve",
78629 .data = &rdma_stat_rq_starve,
78630 - .maxlen = sizeof(atomic_t),
78631 + .maxlen = sizeof(atomic_unchecked_t),
78632 .mode = 0644,
78633 .proc_handler = read_reset_stat,
78634 },
78635 {
78636 .procname = "rdma_stat_rq_poll",
78637 .data = &rdma_stat_rq_poll,
78638 - .maxlen = sizeof(atomic_t),
78639 + .maxlen = sizeof(atomic_unchecked_t),
78640 .mode = 0644,
78641 .proc_handler = read_reset_stat,
78642 },
78643 {
78644 .procname = "rdma_stat_rq_prod",
78645 .data = &rdma_stat_rq_prod,
78646 - .maxlen = sizeof(atomic_t),
78647 + .maxlen = sizeof(atomic_unchecked_t),
78648 .mode = 0644,
78649 .proc_handler = read_reset_stat,
78650 },
78651 {
78652 .procname = "rdma_stat_sq_poll",
78653 .data = &rdma_stat_sq_poll,
78654 - .maxlen = sizeof(atomic_t),
78655 + .maxlen = sizeof(atomic_unchecked_t),
78656 .mode = 0644,
78657 .proc_handler = read_reset_stat,
78658 },
78659 {
78660 .procname = "rdma_stat_sq_prod",
78661 .data = &rdma_stat_sq_prod,
78662 - .maxlen = sizeof(atomic_t),
78663 + .maxlen = sizeof(atomic_unchecked_t),
78664 .mode = 0644,
78665 .proc_handler = read_reset_stat,
78666 },
78667 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78668 index df67211..c354b13 100644
78669 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78670 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78671 @@ -499,7 +499,7 @@ next_sge:
78672 svc_rdma_put_context(ctxt, 0);
78673 goto out;
78674 }
78675 - atomic_inc(&rdma_stat_read);
78676 + atomic_inc_unchecked(&rdma_stat_read);
78677
78678 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78679 chl_map->ch[ch_no].count -= read_wr.num_sge;
78680 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78681 dto_q);
78682 list_del_init(&ctxt->dto_q);
78683 } else {
78684 - atomic_inc(&rdma_stat_rq_starve);
78685 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78686 clear_bit(XPT_DATA, &xprt->xpt_flags);
78687 ctxt = NULL;
78688 }
78689 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78690 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78691 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78692 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78693 - atomic_inc(&rdma_stat_recv);
78694 + atomic_inc_unchecked(&rdma_stat_recv);
78695
78696 /* Build up the XDR from the receive buffers. */
78697 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78698 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78699 index 249a835..fb2794b 100644
78700 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78701 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78702 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78703 write_wr.wr.rdma.remote_addr = to;
78704
78705 /* Post It */
78706 - atomic_inc(&rdma_stat_write);
78707 + atomic_inc_unchecked(&rdma_stat_write);
78708 if (svc_rdma_send(xprt, &write_wr))
78709 goto err;
78710 return 0;
78711 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78712 index a385430..32254ea 100644
78713 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78714 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78715 @@ -299,7 +299,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78716 return;
78717
78718 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78719 - atomic_inc(&rdma_stat_rq_poll);
78720 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78721
78722 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78723 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78724 @@ -321,7 +321,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78725 }
78726
78727 if (ctxt)
78728 - atomic_inc(&rdma_stat_rq_prod);
78729 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78730
78731 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78732 /*
78733 @@ -393,7 +393,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78734 return;
78735
78736 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78737 - atomic_inc(&rdma_stat_sq_poll);
78738 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78739 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78740 if (wc.status != IB_WC_SUCCESS)
78741 /* Close the transport */
78742 @@ -411,7 +411,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78743 }
78744
78745 if (ctxt)
78746 - atomic_inc(&rdma_stat_sq_prod);
78747 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78748 }
78749
78750 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78751 @@ -1273,7 +1273,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78752 spin_lock_bh(&xprt->sc_lock);
78753 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78754 spin_unlock_bh(&xprt->sc_lock);
78755 - atomic_inc(&rdma_stat_sq_starve);
78756 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78757
78758 /* See if we can opportunistically reap SQ WR to make room */
78759 sq_cq_reap(xprt);
78760 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78761 index ca84212..3aa338f 100644
78762 --- a/net/sysctl_net.c
78763 +++ b/net/sysctl_net.c
78764 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78765 struct ctl_table *table)
78766 {
78767 /* Allow network administrator to have same access as root. */
78768 - if (capable(CAP_NET_ADMIN)) {
78769 + if (capable_nolog(CAP_NET_ADMIN)) {
78770 int mode = (table->mode >> 6) & 7;
78771 return (mode << 6) | (mode << 3) | mode;
78772 }
78773 diff --git a/net/tipc/link.c b/net/tipc/link.c
78774 index f89570c..016cf63 100644
78775 --- a/net/tipc/link.c
78776 +++ b/net/tipc/link.c
78777 @@ -1170,7 +1170,7 @@ static int link_send_sections_long(struct tipc_port *sender,
78778 struct tipc_msg fragm_hdr;
78779 struct sk_buff *buf, *buf_chain, *prev;
78780 u32 fragm_crs, fragm_rest, hsz, sect_rest;
78781 - const unchar *sect_crs;
78782 + const unchar __user *sect_crs;
78783 int curr_sect;
78784 u32 fragm_no;
78785
78786 @@ -1214,7 +1214,7 @@ again:
78787
78788 if (!sect_rest) {
78789 sect_rest = msg_sect[++curr_sect].iov_len;
78790 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78791 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78792 }
78793
78794 if (sect_rest < fragm_rest)
78795 @@ -1233,7 +1233,7 @@ error:
78796 }
78797 } else
78798 skb_copy_to_linear_data_offset(buf, fragm_crs,
78799 - sect_crs, sz);
78800 + (const void __force_kernel *)sect_crs, sz);
78801 sect_crs += sz;
78802 sect_rest -= sz;
78803 fragm_crs += sz;
78804 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
78805 index 83d5096..dcba497 100644
78806 --- a/net/tipc/msg.c
78807 +++ b/net/tipc/msg.c
78808 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
78809 msg_sect[cnt].iov_len);
78810 else
78811 skb_copy_to_linear_data_offset(*buf, pos,
78812 - msg_sect[cnt].iov_base,
78813 + (const void __force_kernel *)msg_sect[cnt].iov_base,
78814 msg_sect[cnt].iov_len);
78815 pos += msg_sect[cnt].iov_len;
78816 }
78817 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
78818 index 6cf7268..7a488ce 100644
78819 --- a/net/tipc/subscr.c
78820 +++ b/net/tipc/subscr.c
78821 @@ -101,7 +101,7 @@ static void subscr_send_event(struct subscription *sub,
78822 {
78823 struct iovec msg_sect;
78824
78825 - msg_sect.iov_base = (void *)&sub->evt;
78826 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78827 msg_sect.iov_len = sizeof(struct tipc_event);
78828
78829 sub->evt.event = htohl(event, sub->swap);
78830 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
78831 index ec68e1c..fdd792f 100644
78832 --- a/net/unix/af_unix.c
78833 +++ b/net/unix/af_unix.c
78834 @@ -767,6 +767,12 @@ static struct sock *unix_find_other(struct net *net,
78835 err = -ECONNREFUSED;
78836 if (!S_ISSOCK(inode->i_mode))
78837 goto put_fail;
78838 +
78839 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78840 + err = -EACCES;
78841 + goto put_fail;
78842 + }
78843 +
78844 u = unix_find_socket_byinode(inode);
78845 if (!u)
78846 goto put_fail;
78847 @@ -787,6 +793,13 @@ static struct sock *unix_find_other(struct net *net,
78848 if (u) {
78849 struct dentry *dentry;
78850 dentry = unix_sk(u)->dentry;
78851 +
78852 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
78853 + err = -EPERM;
78854 + sock_put(u);
78855 + goto fail;
78856 + }
78857 +
78858 if (dentry)
78859 touch_atime(unix_sk(u)->mnt, dentry);
78860 } else
78861 @@ -869,11 +882,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
78862 err = security_path_mknod(&path, dentry, mode, 0);
78863 if (err)
78864 goto out_mknod_drop_write;
78865 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
78866 + err = -EACCES;
78867 + goto out_mknod_drop_write;
78868 + }
78869 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
78870 out_mknod_drop_write:
78871 mnt_drop_write(path.mnt);
78872 if (err)
78873 goto out_mknod_dput;
78874 +
78875 + gr_handle_create(dentry, path.mnt);
78876 +
78877 mutex_unlock(&path.dentry->d_inode->i_mutex);
78878 dput(path.dentry);
78879 path.dentry = dentry;
78880 diff --git a/net/wireless/core.h b/net/wireless/core.h
78881 index 8672e02..48782dd 100644
78882 --- a/net/wireless/core.h
78883 +++ b/net/wireless/core.h
78884 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78885 struct mutex mtx;
78886
78887 /* rfkill support */
78888 - struct rfkill_ops rfkill_ops;
78889 + rfkill_ops_no_const rfkill_ops;
78890 struct rfkill *rfkill;
78891 struct work_struct rfkill_sync;
78892
78893 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
78894 index fdbc23c..212d53e 100644
78895 --- a/net/wireless/wext-core.c
78896 +++ b/net/wireless/wext-core.c
78897 @@ -746,8 +746,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78898 */
78899
78900 /* Support for very large requests */
78901 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78902 - (user_length > descr->max_tokens)) {
78903 + if (user_length > descr->max_tokens) {
78904 /* Allow userspace to GET more than max so
78905 * we can support any size GET requests.
78906 * There is still a limit : -ENOMEM.
78907 @@ -784,22 +783,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78908 }
78909 }
78910
78911 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78912 - /*
78913 - * If this is a GET, but not NOMAX, it means that the extra
78914 - * data is not bounded by userspace, but by max_tokens. Thus
78915 - * set the length to max_tokens. This matches the extra data
78916 - * allocation.
78917 - * The driver should fill it with the number of tokens it
78918 - * provided, and it may check iwp->length rather than having
78919 - * knowledge of max_tokens. If the driver doesn't change the
78920 - * iwp->length, this ioctl just copies back max_token tokens
78921 - * filled with zeroes. Hopefully the driver isn't claiming
78922 - * them to be valid data.
78923 - */
78924 - iwp->length = descr->max_tokens;
78925 - }
78926 -
78927 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78928
78929 iwp->length += essid_compat;
78930 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
78931 index 7e088c0..dd3f206 100644
78932 --- a/net/xfrm/xfrm_policy.c
78933 +++ b/net/xfrm/xfrm_policy.c
78934 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
78935 {
78936 policy->walk.dead = 1;
78937
78938 - atomic_inc(&policy->genid);
78939 + atomic_inc_unchecked(&policy->genid);
78940
78941 if (del_timer(&policy->timer))
78942 xfrm_pol_put(policy);
78943 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
78944 hlist_add_head(&policy->bydst, chain);
78945 xfrm_pol_hold(policy);
78946 net->xfrm.policy_count[dir]++;
78947 - atomic_inc(&flow_cache_genid);
78948 + atomic_inc_unchecked(&flow_cache_genid);
78949 if (delpol)
78950 __xfrm_policy_unlink(delpol, dir);
78951 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78952 @@ -1530,7 +1530,7 @@ free_dst:
78953 goto out;
78954 }
78955
78956 -static int inline
78957 +static inline int
78958 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78959 {
78960 if (!*target) {
78961 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
78962 return 0;
78963 }
78964
78965 -static int inline
78966 +static inline int
78967 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78968 {
78969 #ifdef CONFIG_XFRM_SUB_POLICY
78970 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78971 #endif
78972 }
78973
78974 -static int inline
78975 +static inline int
78976 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78977 {
78978 #ifdef CONFIG_XFRM_SUB_POLICY
78979 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
78980
78981 xdst->num_pols = num_pols;
78982 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78983 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78984 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78985
78986 return xdst;
78987 }
78988 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
78989 if (xdst->xfrm_genid != dst->xfrm->genid)
78990 return 0;
78991 if (xdst->num_pols > 0 &&
78992 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78993 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78994 return 0;
78995
78996 mtu = dst_mtu(dst->child);
78997 @@ -2880,7 +2880,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
78998 sizeof(pol->xfrm_vec[i].saddr));
78999 pol->xfrm_vec[i].encap_family = mp->new_family;
79000 /* flush bundles */
79001 - atomic_inc(&pol->genid);
79002 + atomic_inc_unchecked(&pol->genid);
79003 }
79004 }
79005
79006 diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
79007 index 0256b8a..9341ef6 100644
79008 --- a/net/xfrm/xfrm_user.c
79009 +++ b/net/xfrm/xfrm_user.c
79010 @@ -1394,6 +1394,8 @@ static int copy_to_user_tmpl(struct xfrm_policy *xp, struct sk_buff *skb)
79011 struct xfrm_user_tmpl vec[XFRM_MAX_DEPTH];
79012 int i;
79013
79014 + pax_track_stack();
79015 +
79016 if (xp->xfrm_nr == 0)
79017 return 0;
79018
79019 @@ -2062,6 +2064,8 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
79020 int err;
79021 int n = 0;
79022
79023 + pax_track_stack();
79024 +
79025 if (attrs[XFRMA_MIGRATE] == NULL)
79026 return -EINVAL;
79027
79028 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
79029 index a0fd502..a8e6e83 100644
79030 --- a/scripts/Makefile.build
79031 +++ b/scripts/Makefile.build
79032 @@ -109,7 +109,7 @@ endif
79033 endif
79034
79035 # Do not include host rules unless needed
79036 -ifneq ($(hostprogs-y)$(hostprogs-m),)
79037 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
79038 include scripts/Makefile.host
79039 endif
79040
79041 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
79042 index 686cb0d..9d653bf 100644
79043 --- a/scripts/Makefile.clean
79044 +++ b/scripts/Makefile.clean
79045 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
79046 __clean-files := $(extra-y) $(always) \
79047 $(targets) $(clean-files) \
79048 $(host-progs) \
79049 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
79050 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
79051 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
79052
79053 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
79054
79055 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
79056 index 1ac414f..a1c1451 100644
79057 --- a/scripts/Makefile.host
79058 +++ b/scripts/Makefile.host
79059 @@ -31,6 +31,7 @@
79060 # Note: Shared libraries consisting of C++ files are not supported
79061
79062 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
79063 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
79064
79065 # C code
79066 # Executables compiled from a single .c file
79067 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
79068 # Shared libaries (only .c supported)
79069 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
79070 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
79071 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
79072 # Remove .so files from "xxx-objs"
79073 host-cobjs := $(filter-out %.so,$(host-cobjs))
79074
79075 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
79076 index 291228e..6c55203 100644
79077 --- a/scripts/basic/fixdep.c
79078 +++ b/scripts/basic/fixdep.c
79079 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
79080 /*
79081 * Lookup a value in the configuration string.
79082 */
79083 -static int is_defined_config(const char *name, int len, unsigned int hash)
79084 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
79085 {
79086 struct item *aux;
79087
79088 @@ -211,10 +211,10 @@ static void clear_config(void)
79089 /*
79090 * Record the use of a CONFIG_* word.
79091 */
79092 -static void use_config(const char *m, int slen)
79093 +static void use_config(const char *m, unsigned int slen)
79094 {
79095 unsigned int hash = strhash(m, slen);
79096 - int c, i;
79097 + unsigned int c, i;
79098
79099 if (is_defined_config(m, slen, hash))
79100 return;
79101 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
79102
79103 static void parse_config_file(const char *map, size_t len)
79104 {
79105 - const int *end = (const int *) (map + len);
79106 + const unsigned int *end = (const unsigned int *) (map + len);
79107 /* start at +1, so that p can never be < map */
79108 - const int *m = (const int *) map + 1;
79109 + const unsigned int *m = (const unsigned int *) map + 1;
79110 const char *p, *q;
79111
79112 for (; m < end; m++) {
79113 @@ -405,7 +405,7 @@ static void print_deps(void)
79114 static void traps(void)
79115 {
79116 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
79117 - int *p = (int *)test;
79118 + unsigned int *p = (unsigned int *)test;
79119
79120 if (*p != INT_CONF) {
79121 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
79122 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
79123 new file mode 100644
79124 index 0000000..8729101
79125 --- /dev/null
79126 +++ b/scripts/gcc-plugin.sh
79127 @@ -0,0 +1,2 @@
79128 +#!/bin/sh
79129 +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"
79130 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
79131 index e26e2fb..f84937b 100644
79132 --- a/scripts/mod/file2alias.c
79133 +++ b/scripts/mod/file2alias.c
79134 @@ -72,7 +72,7 @@ static void device_id_check(const char *modname, const char *device_id,
79135 unsigned long size, unsigned long id_size,
79136 void *symval)
79137 {
79138 - int i;
79139 + unsigned int i;
79140
79141 if (size % id_size || size < id_size) {
79142 if (cross_build != 0)
79143 @@ -102,7 +102,7 @@ static void device_id_check(const char *modname, const char *device_id,
79144 /* USB is special because the bcdDevice can be matched against a numeric range */
79145 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
79146 static void do_usb_entry(struct usb_device_id *id,
79147 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
79148 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
79149 unsigned char range_lo, unsigned char range_hi,
79150 unsigned char max, struct module *mod)
79151 {
79152 @@ -203,7 +203,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
79153 {
79154 unsigned int devlo, devhi;
79155 unsigned char chi, clo, max;
79156 - int ndigits;
79157 + unsigned int ndigits;
79158
79159 id->match_flags = TO_NATIVE(id->match_flags);
79160 id->idVendor = TO_NATIVE(id->idVendor);
79161 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
79162 for (i = 0; i < count; i++) {
79163 const char *id = (char *)devs[i].id;
79164 char acpi_id[sizeof(devs[0].id)];
79165 - int j;
79166 + unsigned int j;
79167
79168 buf_printf(&mod->dev_table_buf,
79169 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79170 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79171
79172 for (j = 0; j < PNP_MAX_DEVICES; j++) {
79173 const char *id = (char *)card->devs[j].id;
79174 - int i2, j2;
79175 + unsigned int i2, j2;
79176 int dup = 0;
79177
79178 if (!id[0])
79179 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79180 /* add an individual alias for every device entry */
79181 if (!dup) {
79182 char acpi_id[sizeof(card->devs[0].id)];
79183 - int k;
79184 + unsigned int k;
79185
79186 buf_printf(&mod->dev_table_buf,
79187 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79188 @@ -786,7 +786,7 @@ static void dmi_ascii_filter(char *d, const char *s)
79189 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
79190 char *alias)
79191 {
79192 - int i, j;
79193 + unsigned int i, j;
79194
79195 sprintf(alias, "dmi*");
79196
79197 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
79198 index a509ff8..5822633 100644
79199 --- a/scripts/mod/modpost.c
79200 +++ b/scripts/mod/modpost.c
79201 @@ -919,6 +919,7 @@ enum mismatch {
79202 ANY_INIT_TO_ANY_EXIT,
79203 ANY_EXIT_TO_ANY_INIT,
79204 EXPORT_TO_INIT_EXIT,
79205 + DATA_TO_TEXT
79206 };
79207
79208 struct sectioncheck {
79209 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
79210 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
79211 .mismatch = EXPORT_TO_INIT_EXIT,
79212 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
79213 +},
79214 +/* Do not reference code from writable data */
79215 +{
79216 + .fromsec = { DATA_SECTIONS, NULL },
79217 + .tosec = { TEXT_SECTIONS, NULL },
79218 + .mismatch = DATA_TO_TEXT
79219 }
79220 };
79221
79222 @@ -1149,10 +1156,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
79223 continue;
79224 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
79225 continue;
79226 - if (sym->st_value == addr)
79227 - return sym;
79228 /* Find a symbol nearby - addr are maybe negative */
79229 d = sym->st_value - addr;
79230 + if (d == 0)
79231 + return sym;
79232 if (d < 0)
79233 d = addr - sym->st_value;
79234 if (d < distance) {
79235 @@ -1431,6 +1438,14 @@ static void report_sec_mismatch(const char *modname,
79236 tosym, prl_to, prl_to, tosym);
79237 free(prl_to);
79238 break;
79239 + case DATA_TO_TEXT:
79240 +/*
79241 + fprintf(stderr,
79242 + "The variable %s references\n"
79243 + "the %s %s%s%s\n",
79244 + fromsym, to, sec2annotation(tosec), tosym, to_p);
79245 +*/
79246 + break;
79247 }
79248 fprintf(stderr, "\n");
79249 }
79250 @@ -1656,7 +1671,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
79251 static void check_sec_ref(struct module *mod, const char *modname,
79252 struct elf_info *elf)
79253 {
79254 - int i;
79255 + unsigned int i;
79256 Elf_Shdr *sechdrs = elf->sechdrs;
79257
79258 /* Walk through all sections */
79259 @@ -1754,7 +1769,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
79260 va_end(ap);
79261 }
79262
79263 -void buf_write(struct buffer *buf, const char *s, int len)
79264 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
79265 {
79266 if (buf->size - buf->pos < len) {
79267 buf->size += len + SZ;
79268 @@ -1966,7 +1981,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
79269 if (fstat(fileno(file), &st) < 0)
79270 goto close_write;
79271
79272 - if (st.st_size != b->pos)
79273 + if (st.st_size != (off_t)b->pos)
79274 goto close_write;
79275
79276 tmp = NOFAIL(malloc(b->pos));
79277 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
79278 index 2031119..b5433af 100644
79279 --- a/scripts/mod/modpost.h
79280 +++ b/scripts/mod/modpost.h
79281 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
79282
79283 struct buffer {
79284 char *p;
79285 - int pos;
79286 - int size;
79287 + unsigned int pos;
79288 + unsigned int size;
79289 };
79290
79291 void __attribute__((format(printf, 2, 3)))
79292 buf_printf(struct buffer *buf, const char *fmt, ...);
79293
79294 void
79295 -buf_write(struct buffer *buf, const char *s, int len);
79296 +buf_write(struct buffer *buf, const char *s, unsigned int len);
79297
79298 struct module {
79299 struct module *next;
79300 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
79301 index 9dfcd6d..099068e 100644
79302 --- a/scripts/mod/sumversion.c
79303 +++ b/scripts/mod/sumversion.c
79304 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
79305 goto out;
79306 }
79307
79308 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79309 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79310 warn("writing sum in %s failed: %s\n",
79311 filename, strerror(errno));
79312 goto out;
79313 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
79314 index 5c11312..72742b5 100644
79315 --- a/scripts/pnmtologo.c
79316 +++ b/scripts/pnmtologo.c
79317 @@ -237,14 +237,14 @@ static void write_header(void)
79318 fprintf(out, " * Linux logo %s\n", logoname);
79319 fputs(" */\n\n", out);
79320 fputs("#include <linux/linux_logo.h>\n\n", out);
79321 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79322 + fprintf(out, "static unsigned char %s_data[] = {\n",
79323 logoname);
79324 }
79325
79326 static void write_footer(void)
79327 {
79328 fputs("\n};\n\n", out);
79329 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79330 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79331 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79332 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79333 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79334 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79335 fputs("\n};\n\n", out);
79336
79337 /* write logo clut */
79338 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79339 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79340 logoname);
79341 write_hex_cnt = 0;
79342 for (i = 0; i < logo_clutsize; i++) {
79343 diff --git a/security/Kconfig b/security/Kconfig
79344 index e0f08b5..649220f 100644
79345 --- a/security/Kconfig
79346 +++ b/security/Kconfig
79347 @@ -4,6 +4,626 @@
79348
79349 menu "Security options"
79350
79351 +source grsecurity/Kconfig
79352 +
79353 +menu "PaX"
79354 +
79355 + config ARCH_TRACK_EXEC_LIMIT
79356 + bool
79357 +
79358 + config PAX_KERNEXEC_PLUGIN
79359 + bool
79360 +
79361 + config PAX_PER_CPU_PGD
79362 + bool
79363 +
79364 + config TASK_SIZE_MAX_SHIFT
79365 + int
79366 + depends on X86_64
79367 + default 47 if !PAX_PER_CPU_PGD
79368 + default 42 if PAX_PER_CPU_PGD
79369 +
79370 + config PAX_ENABLE_PAE
79371 + bool
79372 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79373 +
79374 +config PAX
79375 + bool "Enable various PaX features"
79376 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79377 + help
79378 + This allows you to enable various PaX features. PaX adds
79379 + intrusion prevention mechanisms to the kernel that reduce
79380 + the risks posed by exploitable memory corruption bugs.
79381 +
79382 +menu "PaX Control"
79383 + depends on PAX
79384 +
79385 +config PAX_SOFTMODE
79386 + bool 'Support soft mode'
79387 + help
79388 + Enabling this option will allow you to run PaX in soft mode, that
79389 + is, PaX features will not be enforced by default, only on executables
79390 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
79391 + support as they are the only way to mark executables for soft mode use.
79392 +
79393 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79394 + line option on boot. Furthermore you can control various PaX features
79395 + at runtime via the entries in /proc/sys/kernel/pax.
79396 +
79397 +config PAX_EI_PAX
79398 + bool 'Use legacy ELF header marking'
79399 + help
79400 + Enabling this option will allow you to control PaX features on
79401 + a per executable basis via the 'chpax' utility available at
79402 + http://pax.grsecurity.net/. The control flags will be read from
79403 + an otherwise reserved part of the ELF header. This marking has
79404 + numerous drawbacks (no support for soft-mode, toolchain does not
79405 + know about the non-standard use of the ELF header) therefore it
79406 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
79407 + support.
79408 +
79409 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79410 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
79411 + option otherwise they will not get any protection.
79412 +
79413 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
79414 + support as well, they will override the legacy EI_PAX marks.
79415 +
79416 +config PAX_PT_PAX_FLAGS
79417 + bool 'Use ELF program header marking'
79418 + help
79419 + Enabling this option will allow you to control PaX features on
79420 + a per executable basis via the 'paxctl' utility available at
79421 + http://pax.grsecurity.net/. The control flags will be read from
79422 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79423 + has the benefits of supporting both soft mode and being fully
79424 + integrated into the toolchain (the binutils patch is available
79425 + from http://pax.grsecurity.net).
79426 +
79427 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79428 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
79429 + support otherwise they will not get any protection.
79430 +
79431 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79432 + must make sure that the marks are the same if a binary has both marks.
79433 +
79434 + Note that if you enable the legacy EI_PAX marking support as well,
79435 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79436 +
79437 +config PAX_XATTR_PAX_FLAGS
79438 + bool 'Use filesystem extended attributes marking'
79439 + depends on EXPERT
79440 + select CIFS_XATTR if CIFS
79441 + select EXT2_FS_XATTR if EXT2_FS
79442 + select EXT3_FS_XATTR if EXT3_FS
79443 + select EXT4_FS_XATTR if EXT4_FS
79444 + select JFFS2_FS_XATTR if JFFS2_FS
79445 + select REISERFS_FS_XATTR if REISERFS_FS
79446 + select SQUASHFS_XATTR if SQUASHFS
79447 + select TMPFS_XATTR if TMPFS
79448 + select UBIFS_FS_XATTR if UBIFS_FS
79449 + help
79450 + Enabling this option will allow you to control PaX features on
79451 + a per executable basis via the 'setfattr' utility. The control
79452 + flags will be read from the user.pax.flags extended attribute of
79453 + the file. This marking has the benefit of supporting binary-only
79454 + applications that self-check themselves (e.g., skype) and would
79455 + not tolerate chpax/paxctl changes. The main drawback is that
79456 + extended attributes are not supported by some filesystems (e.g.,
79457 + isofs, udf, vfat) so copying files through such filesystems will
79458 + lose the extended attributes and these PaX markings.
79459 +
79460 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79461 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
79462 + support otherwise they will not get any protection.
79463 +
79464 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79465 + must make sure that the marks are the same if a binary has both marks.
79466 +
79467 + Note that if you enable the legacy EI_PAX marking support as well,
79468 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
79469 +
79470 +choice
79471 + prompt 'MAC system integration'
79472 + default PAX_HAVE_ACL_FLAGS
79473 + help
79474 + Mandatory Access Control systems have the option of controlling
79475 + PaX flags on a per executable basis, choose the method supported
79476 + by your particular system.
79477 +
79478 + - "none": if your MAC system does not interact with PaX,
79479 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79480 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79481 +
79482 + NOTE: this option is for developers/integrators only.
79483 +
79484 + config PAX_NO_ACL_FLAGS
79485 + bool 'none'
79486 +
79487 + config PAX_HAVE_ACL_FLAGS
79488 + bool 'direct'
79489 +
79490 + config PAX_HOOK_ACL_FLAGS
79491 + bool 'hook'
79492 +endchoice
79493 +
79494 +endmenu
79495 +
79496 +menu "Non-executable pages"
79497 + depends on PAX
79498 +
79499 +config PAX_NOEXEC
79500 + bool "Enforce non-executable pages"
79501 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
79502 + help
79503 + By design some architectures do not allow for protecting memory
79504 + pages against execution or even if they do, Linux does not make
79505 + use of this feature. In practice this means that if a page is
79506 + readable (such as the stack or heap) it is also executable.
79507 +
79508 + There is a well known exploit technique that makes use of this
79509 + fact and a common programming mistake where an attacker can
79510 + introduce code of his choice somewhere in the attacked program's
79511 + memory (typically the stack or the heap) and then execute it.
79512 +
79513 + If the attacked program was running with different (typically
79514 + higher) privileges than that of the attacker, then he can elevate
79515 + his own privilege level (e.g. get a root shell, write to files for
79516 + which he does not have write access to, etc).
79517 +
79518 + Enabling this option will let you choose from various features
79519 + that prevent the injection and execution of 'foreign' code in
79520 + a program.
79521 +
79522 + This will also break programs that rely on the old behaviour and
79523 + expect that dynamically allocated memory via the malloc() family
79524 + of functions is executable (which it is not). Notable examples
79525 + are the XFree86 4.x server, the java runtime and wine.
79526 +
79527 +config PAX_PAGEEXEC
79528 + bool "Paging based non-executable pages"
79529 + 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)
79530 + select S390_SWITCH_AMODE if S390
79531 + select S390_EXEC_PROTECT if S390
79532 + select ARCH_TRACK_EXEC_LIMIT if X86_32
79533 + help
79534 + This implementation is based on the paging feature of the CPU.
79535 + On i386 without hardware non-executable bit support there is a
79536 + variable but usually low performance impact, however on Intel's
79537 + P4 core based CPUs it is very high so you should not enable this
79538 + for kernels meant to be used on such CPUs.
79539 +
79540 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
79541 + with hardware non-executable bit support there is no performance
79542 + impact, on ppc the impact is negligible.
79543 +
79544 + Note that several architectures require various emulations due to
79545 + badly designed userland ABIs, this will cause a performance impact
79546 + but will disappear as soon as userland is fixed. For example, ppc
79547 + userland MUST have been built with secure-plt by a recent toolchain.
79548 +
79549 +config PAX_SEGMEXEC
79550 + bool "Segmentation based non-executable pages"
79551 + depends on PAX_NOEXEC && X86_32
79552 + help
79553 + This implementation is based on the segmentation feature of the
79554 + CPU and has a very small performance impact, however applications
79555 + will be limited to a 1.5 GB address space instead of the normal
79556 + 3 GB.
79557 +
79558 +config PAX_EMUTRAMP
79559 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
79560 + default y if PARISC
79561 + help
79562 + There are some programs and libraries that for one reason or
79563 + another attempt to execute special small code snippets from
79564 + non-executable memory pages. Most notable examples are the
79565 + signal handler return code generated by the kernel itself and
79566 + the GCC trampolines.
79567 +
79568 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
79569 + such programs will no longer work under your kernel.
79570 +
79571 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
79572 + utilities to enable trampoline emulation for the affected programs
79573 + yet still have the protection provided by the non-executable pages.
79574 +
79575 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
79576 + your system will not even boot.
79577 +
79578 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
79579 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
79580 + for the affected files.
79581 +
79582 + NOTE: enabling this feature *may* open up a loophole in the
79583 + protection provided by non-executable pages that an attacker
79584 + could abuse. Therefore the best solution is to not have any
79585 + files on your system that would require this option. This can
79586 + be achieved by not using libc5 (which relies on the kernel
79587 + signal handler return code) and not using or rewriting programs
79588 + that make use of the nested function implementation of GCC.
79589 + Skilled users can just fix GCC itself so that it implements
79590 + nested function calls in a way that does not interfere with PaX.
79591 +
79592 +config PAX_EMUSIGRT
79593 + bool "Automatically emulate sigreturn trampolines"
79594 + depends on PAX_EMUTRAMP && PARISC
79595 + default y
79596 + help
79597 + Enabling this option will have the kernel automatically detect
79598 + and emulate signal return trampolines executing on the stack
79599 + that would otherwise lead to task termination.
79600 +
79601 + This solution is intended as a temporary one for users with
79602 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
79603 + Modula-3 runtime, etc) or executables linked to such, basically
79604 + everything that does not specify its own SA_RESTORER function in
79605 + normal executable memory like glibc 2.1+ does.
79606 +
79607 + On parisc you MUST enable this option, otherwise your system will
79608 + not even boot.
79609 +
79610 + NOTE: this feature cannot be disabled on a per executable basis
79611 + and since it *does* open up a loophole in the protection provided
79612 + by non-executable pages, the best solution is to not have any
79613 + files on your system that would require this option.
79614 +
79615 +config PAX_MPROTECT
79616 + bool "Restrict mprotect()"
79617 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
79618 + help
79619 + Enabling this option will prevent programs from
79620 + - changing the executable status of memory pages that were
79621 + not originally created as executable,
79622 + - making read-only executable pages writable again,
79623 + - creating executable pages from anonymous memory,
79624 + - making read-only-after-relocations (RELRO) data pages writable again.
79625 +
79626 + You should say Y here to complete the protection provided by
79627 + the enforcement of non-executable pages.
79628 +
79629 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79630 + this feature on a per file basis.
79631 +
79632 +config PAX_MPROTECT_COMPAT
79633 + bool "Use legacy/compat protection demoting (read help)"
79634 + depends on PAX_MPROTECT
79635 + default n
79636 + help
79637 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
79638 + by sending the proper error code to the application. For some broken
79639 + userland, this can cause problems with Python or other applications. The
79640 + current implementation however allows for applications like clamav to
79641 + detect if JIT compilation/execution is allowed and to fall back gracefully
79642 + to an interpreter-based mode if it does not. While we encourage everyone
79643 + to use the current implementation as-is and push upstream to fix broken
79644 + userland (note that the RWX logging option can assist with this), in some
79645 + environments this may not be possible. Having to disable MPROTECT
79646 + completely on certain binaries reduces the security benefit of PaX,
79647 + so this option is provided for those environments to revert to the old
79648 + behavior.
79649 +
79650 +config PAX_ELFRELOCS
79651 + bool "Allow ELF text relocations (read help)"
79652 + depends on PAX_MPROTECT
79653 + default n
79654 + help
79655 + Non-executable pages and mprotect() restrictions are effective
79656 + in preventing the introduction of new executable code into an
79657 + attacked task's address space. There remain only two venues
79658 + for this kind of attack: if the attacker can execute already
79659 + existing code in the attacked task then he can either have it
79660 + create and mmap() a file containing his code or have it mmap()
79661 + an already existing ELF library that does not have position
79662 + independent code in it and use mprotect() on it to make it
79663 + writable and copy his code there. While protecting against
79664 + the former approach is beyond PaX, the latter can be prevented
79665 + by having only PIC ELF libraries on one's system (which do not
79666 + need to relocate their code). If you are sure this is your case,
79667 + as is the case with all modern Linux distributions, then leave
79668 + this option disabled. You should say 'n' here.
79669 +
79670 +config PAX_ETEXECRELOCS
79671 + bool "Allow ELF ET_EXEC text relocations"
79672 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
79673 + select PAX_ELFRELOCS
79674 + default y
79675 + help
79676 + On some architectures there are incorrectly created applications
79677 + that require text relocations and would not work without enabling
79678 + this option. If you are an alpha, ia64 or parisc user, you should
79679 + enable this option and disable it once you have made sure that
79680 + none of your applications need it.
79681 +
79682 +config PAX_EMUPLT
79683 + bool "Automatically emulate ELF PLT"
79684 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79685 + default y
79686 + help
79687 + Enabling this option will have the kernel automatically detect
79688 + and emulate the Procedure Linkage Table entries in ELF files.
79689 + On some architectures such entries are in writable memory, and
79690 + become non-executable leading to task termination. Therefore
79691 + it is mandatory that you enable this option on alpha, parisc,
79692 + sparc and sparc64, otherwise your system would not even boot.
79693 +
79694 + NOTE: this feature *does* open up a loophole in the protection
79695 + provided by the non-executable pages, therefore the proper
79696 + solution is to modify the toolchain to produce a PLT that does
79697 + not need to be writable.
79698 +
79699 +config PAX_DLRESOLVE
79700 + bool 'Emulate old glibc resolver stub'
79701 + depends on PAX_EMUPLT && SPARC
79702 + default n
79703 + help
79704 + This option is needed if userland has an old glibc (before 2.4)
79705 + that puts a 'save' instruction into the runtime generated resolver
79706 + stub that needs special emulation.
79707 +
79708 +config PAX_KERNEXEC
79709 + bool "Enforce non-executable kernel pages"
79710 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79711 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79712 + select PAX_KERNEXEC_PLUGIN if X86_64
79713 + help
79714 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79715 + that is, enabling this option will make it harder to inject
79716 + and execute 'foreign' code in kernel memory itself.
79717 +
79718 + Note that on x86_64 kernels there is a known regression when
79719 + this feature and KVM/VMX are both enabled in the host kernel.
79720 +
79721 +choice
79722 + prompt "Return Address Instrumentation Method"
79723 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
79724 + depends on PAX_KERNEXEC_PLUGIN
79725 + help
79726 + Select the method used to instrument function pointer dereferences.
79727 + Note that binary modules cannot be instrumented by this approach.
79728 +
79729 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
79730 + bool "bts"
79731 + help
79732 + This method is compatible with binary only modules but has
79733 + a higher runtime overhead.
79734 +
79735 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
79736 + bool "or"
79737 + depends on !PARAVIRT
79738 + help
79739 + This method is incompatible with binary only modules but has
79740 + a lower runtime overhead.
79741 +endchoice
79742 +
79743 +config PAX_KERNEXEC_PLUGIN_METHOD
79744 + string
79745 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
79746 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
79747 + default ""
79748 +
79749 +config PAX_KERNEXEC_MODULE_TEXT
79750 + int "Minimum amount of memory reserved for module code"
79751 + default "4"
79752 + depends on PAX_KERNEXEC && X86_32 && MODULES
79753 + help
79754 + Due to implementation details the kernel must reserve a fixed
79755 + amount of memory for module code at compile time that cannot be
79756 + changed at runtime. Here you can specify the minimum amount
79757 + in MB that will be reserved. Due to the same implementation
79758 + details this size will always be rounded up to the next 2/4 MB
79759 + boundary (depends on PAE) so the actually available memory for
79760 + module code will usually be more than this minimum.
79761 +
79762 + The default 4 MB should be enough for most users but if you have
79763 + an excessive number of modules (e.g., most distribution configs
79764 + compile many drivers as modules) or use huge modules such as
79765 + nvidia's kernel driver, you will need to adjust this amount.
79766 + A good rule of thumb is to look at your currently loaded kernel
79767 + modules and add up their sizes.
79768 +
79769 +endmenu
79770 +
79771 +menu "Address Space Layout Randomization"
79772 + depends on PAX
79773 +
79774 +config PAX_ASLR
79775 + bool "Address Space Layout Randomization"
79776 + help
79777 + Many if not most exploit techniques rely on the knowledge of
79778 + certain addresses in the attacked program. The following options
79779 + will allow the kernel to apply a certain amount of randomization
79780 + to specific parts of the program thereby forcing an attacker to
79781 + guess them in most cases. Any failed guess will most likely crash
79782 + the attacked program which allows the kernel to detect such attempts
79783 + and react on them. PaX itself provides no reaction mechanisms,
79784 + instead it is strongly encouraged that you make use of Nergal's
79785 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79786 + (http://www.grsecurity.net/) built-in crash detection features or
79787 + develop one yourself.
79788 +
79789 + By saying Y here you can choose to randomize the following areas:
79790 + - top of the task's kernel stack
79791 + - top of the task's userland stack
79792 + - base address for mmap() requests that do not specify one
79793 + (this includes all libraries)
79794 + - base address of the main executable
79795 +
79796 + It is strongly recommended to say Y here as address space layout
79797 + randomization has negligible impact on performance yet it provides
79798 + a very effective protection.
79799 +
79800 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79801 + this feature on a per file basis.
79802 +
79803 +config PAX_RANDKSTACK
79804 + bool "Randomize kernel stack base"
79805 + depends on X86_TSC && X86
79806 + help
79807 + By saying Y here the kernel will randomize every task's kernel
79808 + stack on every system call. This will not only force an attacker
79809 + to guess it but also prevent him from making use of possible
79810 + leaked information about it.
79811 +
79812 + Since the kernel stack is a rather scarce resource, randomization
79813 + may cause unexpected stack overflows, therefore you should very
79814 + carefully test your system. Note that once enabled in the kernel
79815 + configuration, this feature cannot be disabled on a per file basis.
79816 +
79817 +config PAX_RANDUSTACK
79818 + bool "Randomize user stack base"
79819 + depends on PAX_ASLR
79820 + help
79821 + By saying Y here the kernel will randomize every task's userland
79822 + stack. The randomization is done in two steps where the second
79823 + one may apply a big amount of shift to the top of the stack and
79824 + cause problems for programs that want to use lots of memory (more
79825 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79826 + For this reason the second step can be controlled by 'chpax' or
79827 + 'paxctl' on a per file basis.
79828 +
79829 +config PAX_RANDMMAP
79830 + bool "Randomize mmap() base"
79831 + depends on PAX_ASLR
79832 + help
79833 + By saying Y here the kernel will use a randomized base address for
79834 + mmap() requests that do not specify one themselves. As a result
79835 + all dynamically loaded libraries will appear at random addresses
79836 + and therefore be harder to exploit by a technique where an attacker
79837 + attempts to execute library code for his purposes (e.g. spawn a
79838 + shell from an exploited program that is running at an elevated
79839 + privilege level).
79840 +
79841 + Furthermore, if a program is relinked as a dynamic ELF file, its
79842 + base address will be randomized as well, completing the full
79843 + randomization of the address space layout. Attacking such programs
79844 + becomes a guess game. You can find an example of doing this at
79845 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79846 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79847 +
79848 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79849 + feature on a per file basis.
79850 +
79851 +endmenu
79852 +
79853 +menu "Miscellaneous hardening features"
79854 +
79855 +config PAX_MEMORY_SANITIZE
79856 + bool "Sanitize all freed memory"
79857 + help
79858 + By saying Y here the kernel will erase memory pages as soon as they
79859 + are freed. This in turn reduces the lifetime of data stored in the
79860 + pages, making it less likely that sensitive information such as
79861 + passwords, cryptographic secrets, etc stay in memory for too long.
79862 +
79863 + This is especially useful for programs whose runtime is short, long
79864 + lived processes and the kernel itself benefit from this as long as
79865 + they operate on whole memory pages and ensure timely freeing of pages
79866 + that may hold sensitive information.
79867 +
79868 + The tradeoff is performance impact, on a single CPU system kernel
79869 + compilation sees a 3% slowdown, other systems and workloads may vary
79870 + and you are advised to test this feature on your expected workload
79871 + before deploying it.
79872 +
79873 + Note that this feature does not protect data stored in live pages,
79874 + e.g., process memory swapped to disk may stay there for a long time.
79875 +
79876 +config PAX_MEMORY_STACKLEAK
79877 + bool "Sanitize kernel stack"
79878 + depends on X86
79879 + help
79880 + By saying Y here the kernel will erase the kernel stack before it
79881 + returns from a system call. This in turn reduces the information
79882 + that a kernel stack leak bug can reveal.
79883 +
79884 + Note that such a bug can still leak information that was put on
79885 + the stack by the current system call (the one eventually triggering
79886 + the bug) but traces of earlier system calls on the kernel stack
79887 + cannot leak anymore.
79888 +
79889 + The tradeoff is performance impact: on a single CPU system kernel
79890 + compilation sees a 1% slowdown, other systems and workloads may vary
79891 + and you are advised to test this feature on your expected workload
79892 + before deploying it.
79893 +
79894 + Note: full support for this feature requires gcc with plugin support
79895 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
79896 + versions means that functions with large enough stack frames may
79897 + leave uninitialized memory behind that may be exposed to a later
79898 + syscall leaking the stack.
79899 +
79900 +config PAX_MEMORY_UDEREF
79901 + bool "Prevent invalid userland pointer dereference"
79902 + depends on X86 && !UML_X86 && !XEN
79903 + select PAX_PER_CPU_PGD if X86_64
79904 + help
79905 + By saying Y here the kernel will be prevented from dereferencing
79906 + userland pointers in contexts where the kernel expects only kernel
79907 + pointers. This is both a useful runtime debugging feature and a
79908 + security measure that prevents exploiting a class of kernel bugs.
79909 +
79910 + The tradeoff is that some virtualization solutions may experience
79911 + a huge slowdown and therefore you should not enable this feature
79912 + for kernels meant to run in such environments. Whether a given VM
79913 + solution is affected or not is best determined by simply trying it
79914 + out, the performance impact will be obvious right on boot as this
79915 + mechanism engages from very early on. A good rule of thumb is that
79916 + VMs running on CPUs without hardware virtualization support (i.e.,
79917 + the majority of IA-32 CPUs) will likely experience the slowdown.
79918 +
79919 +config PAX_REFCOUNT
79920 + bool "Prevent various kernel object reference counter overflows"
79921 + depends on GRKERNSEC && (X86 || SPARC64)
79922 + help
79923 + By saying Y here the kernel will detect and prevent overflowing
79924 + various (but not all) kinds of object reference counters. Such
79925 + overflows can normally occur due to bugs only and are often, if
79926 + not always, exploitable.
79927 +
79928 + The tradeoff is that data structures protected by an overflowed
79929 + refcount will never be freed and therefore will leak memory. Note
79930 + that this leak also happens even without this protection but in
79931 + that case the overflow can eventually trigger the freeing of the
79932 + data structure while it is still being used elsewhere, resulting
79933 + in the exploitable situation that this feature prevents.
79934 +
79935 + Since this has a negligible performance impact, you should enable
79936 + this feature.
79937 +
79938 +config PAX_USERCOPY
79939 + bool "Harden heap object copies between kernel and userland"
79940 + depends on X86 || PPC || SPARC || ARM
79941 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79942 + help
79943 + By saying Y here the kernel will enforce the size of heap objects
79944 + when they are copied in either direction between the kernel and
79945 + userland, even if only a part of the heap object is copied.
79946 +
79947 + Specifically, this checking prevents information leaking from the
79948 + kernel heap during kernel to userland copies (if the kernel heap
79949 + object is otherwise fully initialized) and prevents kernel heap
79950 + overflows during userland to kernel copies.
79951 +
79952 + Note that the current implementation provides the strictest bounds
79953 + checks for the SLUB allocator.
79954 +
79955 + Enabling this option also enables per-slab cache protection against
79956 + data in a given cache being copied into/out of via userland
79957 + accessors. Though the whitelist of regions will be reduced over
79958 + time, it notably protects important data structures like task structs.
79959 +
79960 + If frame pointers are enabled on x86, this option will also restrict
79961 + copies into and out of the kernel stack to local variables within a
79962 + single frame.
79963 +
79964 + Since this has a negligible performance impact, you should enable
79965 + this feature.
79966 +
79967 +endmenu
79968 +
79969 +endmenu
79970 +
79971 config KEYS
79972 bool "Enable access key retention support"
79973 help
79974 @@ -167,7 +787,7 @@ config INTEL_TXT
79975 config LSM_MMAP_MIN_ADDR
79976 int "Low address space for LSM to protect from user allocation"
79977 depends on SECURITY && SECURITY_SELINUX
79978 - default 32768 if ARM
79979 + default 32768 if ALPHA || ARM || PARISC || SPARC32
79980 default 65536
79981 help
79982 This is the portion of low virtual memory which should be protected
79983 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
79984 index 3783202..1852837 100644
79985 --- a/security/apparmor/lsm.c
79986 +++ b/security/apparmor/lsm.c
79987 @@ -621,7 +621,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
79988 return error;
79989 }
79990
79991 -static struct security_operations apparmor_ops = {
79992 +static struct security_operations apparmor_ops __read_only = {
79993 .name = "apparmor",
79994
79995 .ptrace_access_check = apparmor_ptrace_access_check,
79996 diff --git a/security/commoncap.c b/security/commoncap.c
79997 index a93b3b7..4410df9 100644
79998 --- a/security/commoncap.c
79999 +++ b/security/commoncap.c
80000 @@ -28,6 +28,7 @@
80001 #include <linux/prctl.h>
80002 #include <linux/securebits.h>
80003 #include <linux/user_namespace.h>
80004 +#include <net/sock.h>
80005
80006 /*
80007 * If a non-root user executes a setuid-root binary in
80008 @@ -58,7 +59,7 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
80009
80010 int cap_netlink_recv(struct sk_buff *skb, int cap)
80011 {
80012 - if (!cap_raised(current_cap(), cap))
80013 + if (!cap_raised(current_cap(), cap) || !gr_is_capable(cap))
80014 return -EPERM;
80015 return 0;
80016 }
80017 @@ -575,6 +576,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
80018 {
80019 const struct cred *cred = current_cred();
80020
80021 + if (gr_acl_enable_at_secure())
80022 + return 1;
80023 +
80024 if (cred->uid != 0) {
80025 if (bprm->cap_effective)
80026 return 1;
80027 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
80028 index 08408bd..67e6e78 100644
80029 --- a/security/integrity/ima/ima.h
80030 +++ b/security/integrity/ima/ima.h
80031 @@ -85,8 +85,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
80032 extern spinlock_t ima_queue_lock;
80033
80034 struct ima_h_table {
80035 - atomic_long_t len; /* number of stored measurements in the list */
80036 - atomic_long_t violations;
80037 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
80038 + atomic_long_unchecked_t violations;
80039 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
80040 };
80041 extern struct ima_h_table ima_htable;
80042 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
80043 index 5335605..abcd9b7 100644
80044 --- a/security/integrity/ima/ima_api.c
80045 +++ b/security/integrity/ima/ima_api.c
80046 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
80047 int result;
80048
80049 /* can overflow, only indicator */
80050 - atomic_long_inc(&ima_htable.violations);
80051 + atomic_long_inc_unchecked(&ima_htable.violations);
80052
80053 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
80054 if (!entry) {
80055 diff --git a/security/integrity/ima/ima_audit.c b/security/integrity/ima/ima_audit.c
80056 index c5c5a72..2ad942f 100644
80057 --- a/security/integrity/ima/ima_audit.c
80058 +++ b/security/integrity/ima/ima_audit.c
80059 @@ -56,9 +56,11 @@ void integrity_audit_msg(int audit_msgno, struct inode *inode,
80060 audit_log_format(ab, " name=");
80061 audit_log_untrustedstring(ab, fname);
80062 }
80063 - if (inode)
80064 - audit_log_format(ab, " dev=%s ino=%lu",
80065 - inode->i_sb->s_id, inode->i_ino);
80066 + if (inode) {
80067 + audit_log_format(ab, " dev=");
80068 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
80069 + audit_log_format(ab, " ino=%lu", inode->i_ino);
80070 + }
80071 audit_log_format(ab, " res=%d", !result ? 0 : 1);
80072 audit_log_end(ab);
80073 }
80074 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
80075 index ef21b96..d53e674 100644
80076 --- a/security/integrity/ima/ima_fs.c
80077 +++ b/security/integrity/ima/ima_fs.c
80078 @@ -28,12 +28,12 @@
80079 static int valid_policy = 1;
80080 #define TMPBUFLEN 12
80081 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
80082 - loff_t *ppos, atomic_long_t *val)
80083 + loff_t *ppos, atomic_long_unchecked_t *val)
80084 {
80085 char tmpbuf[TMPBUFLEN];
80086 ssize_t len;
80087
80088 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
80089 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
80090 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
80091 }
80092
80093 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
80094 index 55a6271..ad829c3 100644
80095 --- a/security/integrity/ima/ima_queue.c
80096 +++ b/security/integrity/ima/ima_queue.c
80097 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
80098 INIT_LIST_HEAD(&qe->later);
80099 list_add_tail_rcu(&qe->later, &ima_measurements);
80100
80101 - atomic_long_inc(&ima_htable.len);
80102 + atomic_long_inc_unchecked(&ima_htable.len);
80103 key = ima_hash_key(entry->digest);
80104 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
80105 return 0;
80106 diff --git a/security/keys/compat.c b/security/keys/compat.c
80107 index 338b510..a235861 100644
80108 --- a/security/keys/compat.c
80109 +++ b/security/keys/compat.c
80110 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
80111 if (ret == 0)
80112 goto no_payload_free;
80113
80114 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80115 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80116
80117 if (iov != iovstack)
80118 kfree(iov);
80119 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
80120 index eca5191..da9c7f0 100644
80121 --- a/security/keys/keyctl.c
80122 +++ b/security/keys/keyctl.c
80123 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
80124 /*
80125 * Copy the iovec data from userspace
80126 */
80127 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80128 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
80129 unsigned ioc)
80130 {
80131 for (; ioc > 0; ioc--) {
80132 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80133 * If successful, 0 will be returned.
80134 */
80135 long keyctl_instantiate_key_common(key_serial_t id,
80136 - const struct iovec *payload_iov,
80137 + const struct iovec __user *payload_iov,
80138 unsigned ioc,
80139 size_t plen,
80140 key_serial_t ringid)
80141 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
80142 [0].iov_len = plen
80143 };
80144
80145 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
80146 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
80147 }
80148
80149 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
80150 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
80151 if (ret == 0)
80152 goto no_payload_free;
80153
80154 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80155 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80156
80157 if (iov != iovstack)
80158 kfree(iov);
80159 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
80160 index 30e242f..ec111ab 100644
80161 --- a/security/keys/keyring.c
80162 +++ b/security/keys/keyring.c
80163 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
80164 ret = -EFAULT;
80165
80166 for (loop = 0; loop < klist->nkeys; loop++) {
80167 + key_serial_t serial;
80168 key = klist->keys[loop];
80169 + serial = key->serial;
80170
80171 tmp = sizeof(key_serial_t);
80172 if (tmp > buflen)
80173 tmp = buflen;
80174
80175 - if (copy_to_user(buffer,
80176 - &key->serial,
80177 - tmp) != 0)
80178 + if (copy_to_user(buffer, &serial, tmp))
80179 goto error;
80180
80181 buflen -= tmp;
80182 diff --git a/security/lsm_audit.c b/security/lsm_audit.c
80183 index 893af8a..ba9237c 100644
80184 --- a/security/lsm_audit.c
80185 +++ b/security/lsm_audit.c
80186 @@ -234,10 +234,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
80187 audit_log_d_path(ab, "path=", &a->u.path);
80188
80189 inode = a->u.path.dentry->d_inode;
80190 - if (inode)
80191 - audit_log_format(ab, " dev=%s ino=%lu",
80192 - inode->i_sb->s_id,
80193 - inode->i_ino);
80194 + if (inode) {
80195 + audit_log_format(ab, " dev=");
80196 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
80197 + audit_log_format(ab, " ino=%lu", inode->i_ino);
80198 + }
80199 break;
80200 }
80201 case LSM_AUDIT_DATA_DENTRY: {
80202 @@ -247,10 +248,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
80203 audit_log_untrustedstring(ab, a->u.dentry->d_name.name);
80204
80205 inode = a->u.dentry->d_inode;
80206 - if (inode)
80207 - audit_log_format(ab, " dev=%s ino=%lu",
80208 - inode->i_sb->s_id,
80209 - inode->i_ino);
80210 + if (inode) {
80211 + audit_log_format(ab, " dev=");
80212 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
80213 + audit_log_format(ab, " ino=%lu", inode->i_ino);
80214 + }
80215 break;
80216 }
80217 case LSM_AUDIT_DATA_INODE: {
80218 @@ -265,8 +267,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
80219 dentry->d_name.name);
80220 dput(dentry);
80221 }
80222 - audit_log_format(ab, " dev=%s ino=%lu", inode->i_sb->s_id,
80223 - inode->i_ino);
80224 + audit_log_format(ab, " dev=");
80225 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
80226 + audit_log_format(ab, " ino=%lu", inode->i_ino);
80227 break;
80228 }
80229 case LSM_AUDIT_DATA_TASK:
80230 diff --git a/security/min_addr.c b/security/min_addr.c
80231 index f728728..6457a0c 100644
80232 --- a/security/min_addr.c
80233 +++ b/security/min_addr.c
80234 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
80235 */
80236 static void update_mmap_min_addr(void)
80237 {
80238 +#ifndef SPARC
80239 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
80240 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
80241 mmap_min_addr = dac_mmap_min_addr;
80242 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
80243 #else
80244 mmap_min_addr = dac_mmap_min_addr;
80245 #endif
80246 +#endif
80247 }
80248
80249 /*
80250 diff --git a/security/security.c b/security/security.c
80251 index d9e1533..91427f2 100644
80252 --- a/security/security.c
80253 +++ b/security/security.c
80254 @@ -25,8 +25,8 @@ static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
80255 /* things that live in capability.c */
80256 extern void __init security_fixup_ops(struct security_operations *ops);
80257
80258 -static struct security_operations *security_ops;
80259 -static struct security_operations default_security_ops = {
80260 +static struct security_operations *security_ops __read_only;
80261 +static struct security_operations default_security_ops __read_only = {
80262 .name = "default",
80263 };
80264
80265 @@ -67,7 +67,9 @@ int __init security_init(void)
80266
80267 void reset_security_ops(void)
80268 {
80269 + pax_open_kernel();
80270 security_ops = &default_security_ops;
80271 + pax_close_kernel();
80272 }
80273
80274 /* Save user chosen LSM */
80275 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
80276 index 266a229..61bd553 100644
80277 --- a/security/selinux/hooks.c
80278 +++ b/security/selinux/hooks.c
80279 @@ -93,7 +93,6 @@
80280 #define NUM_SEL_MNT_OPTS 5
80281
80282 extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm);
80283 -extern struct security_operations *security_ops;
80284
80285 /* SECMARK reference count */
80286 atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
80287 @@ -5455,7 +5454,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
80288
80289 #endif
80290
80291 -static struct security_operations selinux_ops = {
80292 +static struct security_operations selinux_ops __read_only = {
80293 .name = "selinux",
80294
80295 .ptrace_access_check = selinux_ptrace_access_check,
80296 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
80297 index b43813c..74be837 100644
80298 --- a/security/selinux/include/xfrm.h
80299 +++ b/security/selinux/include/xfrm.h
80300 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
80301
80302 static inline void selinux_xfrm_notify_policyload(void)
80303 {
80304 - atomic_inc(&flow_cache_genid);
80305 + atomic_inc_unchecked(&flow_cache_genid);
80306 }
80307 #else
80308 static inline int selinux_xfrm_enabled(void)
80309 diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
80310 index f6917bc..8e8713e 100644
80311 --- a/security/selinux/ss/services.c
80312 +++ b/security/selinux/ss/services.c
80313 @@ -1814,6 +1814,8 @@ int security_load_policy(void *data, size_t len)
80314 int rc = 0;
80315 struct policy_file file = { data, len }, *fp = &file;
80316
80317 + pax_track_stack();
80318 +
80319 if (!ss_initialized) {
80320 avtab_cache_init();
80321 rc = policydb_read(&policydb, fp);
80322 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
80323 index b9c5e14..20ab779 100644
80324 --- a/security/smack/smack_lsm.c
80325 +++ b/security/smack/smack_lsm.c
80326 @@ -3393,7 +3393,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
80327 return 0;
80328 }
80329
80330 -struct security_operations smack_ops = {
80331 +struct security_operations smack_ops __read_only = {
80332 .name = "smack",
80333
80334 .ptrace_access_check = smack_ptrace_access_check,
80335 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
80336 index f776400..f95b158c 100644
80337 --- a/security/tomoyo/tomoyo.c
80338 +++ b/security/tomoyo/tomoyo.c
80339 @@ -446,7 +446,7 @@ static int tomoyo_sb_pivotroot(struct path *old_path, struct path *new_path)
80340 * tomoyo_security_ops is a "struct security_operations" which is used for
80341 * registering TOMOYO.
80342 */
80343 -static struct security_operations tomoyo_security_ops = {
80344 +static struct security_operations tomoyo_security_ops __read_only = {
80345 .name = "tomoyo",
80346 .cred_alloc_blank = tomoyo_cred_alloc_blank,
80347 .cred_prepare = tomoyo_cred_prepare,
80348 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
80349 index 3687a6c..652565e 100644
80350 --- a/sound/aoa/codecs/onyx.c
80351 +++ b/sound/aoa/codecs/onyx.c
80352 @@ -54,7 +54,7 @@ struct onyx {
80353 spdif_locked:1,
80354 analog_locked:1,
80355 original_mute:2;
80356 - int open_count;
80357 + local_t open_count;
80358 struct codec_info *codec_info;
80359
80360 /* mutex serializes concurrent access to the device
80361 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
80362 struct onyx *onyx = cii->codec_data;
80363
80364 mutex_lock(&onyx->mutex);
80365 - onyx->open_count++;
80366 + local_inc(&onyx->open_count);
80367 mutex_unlock(&onyx->mutex);
80368
80369 return 0;
80370 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
80371 struct onyx *onyx = cii->codec_data;
80372
80373 mutex_lock(&onyx->mutex);
80374 - onyx->open_count--;
80375 - if (!onyx->open_count)
80376 + if (local_dec_and_test(&onyx->open_count))
80377 onyx->spdif_locked = onyx->analog_locked = 0;
80378 mutex_unlock(&onyx->mutex);
80379
80380 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
80381 index ffd2025..df062c9 100644
80382 --- a/sound/aoa/codecs/onyx.h
80383 +++ b/sound/aoa/codecs/onyx.h
80384 @@ -11,6 +11,7 @@
80385 #include <linux/i2c.h>
80386 #include <asm/pmac_low_i2c.h>
80387 #include <asm/prom.h>
80388 +#include <asm/local.h>
80389
80390 /* PCM3052 register definitions */
80391
80392 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
80393 index 23c34a0..a2673a5 100644
80394 --- a/sound/core/oss/pcm_oss.c
80395 +++ b/sound/core/oss/pcm_oss.c
80396 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
80397 if (in_kernel) {
80398 mm_segment_t fs;
80399 fs = snd_enter_user();
80400 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80401 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80402 snd_leave_user(fs);
80403 } else {
80404 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80405 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80406 }
80407 if (ret != -EPIPE && ret != -ESTRPIPE)
80408 break;
80409 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
80410 if (in_kernel) {
80411 mm_segment_t fs;
80412 fs = snd_enter_user();
80413 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80414 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80415 snd_leave_user(fs);
80416 } else {
80417 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80418 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80419 }
80420 if (ret == -EPIPE) {
80421 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
80422 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
80423 struct snd_pcm_plugin_channel *channels;
80424 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
80425 if (!in_kernel) {
80426 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
80427 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
80428 return -EFAULT;
80429 buf = runtime->oss.buffer;
80430 }
80431 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
80432 }
80433 } else {
80434 tmp = snd_pcm_oss_write2(substream,
80435 - (const char __force *)buf,
80436 + (const char __force_kernel *)buf,
80437 runtime->oss.period_bytes, 0);
80438 if (tmp <= 0)
80439 goto err;
80440 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
80441 struct snd_pcm_runtime *runtime = substream->runtime;
80442 snd_pcm_sframes_t frames, frames1;
80443 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
80444 - char __user *final_dst = (char __force __user *)buf;
80445 + char __user *final_dst = (char __force_user *)buf;
80446 if (runtime->oss.plugin_first) {
80447 struct snd_pcm_plugin_channel *channels;
80448 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
80449 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
80450 xfer += tmp;
80451 runtime->oss.buffer_used -= tmp;
80452 } else {
80453 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
80454 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
80455 runtime->oss.period_bytes, 0);
80456 if (tmp <= 0)
80457 goto err;
80458 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
80459 size1);
80460 size1 /= runtime->channels; /* frames */
80461 fs = snd_enter_user();
80462 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
80463 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
80464 snd_leave_user(fs);
80465 }
80466 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
80467 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
80468 index 91cdf94..4085161 100644
80469 --- a/sound/core/pcm_compat.c
80470 +++ b/sound/core/pcm_compat.c
80471 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
80472 int err;
80473
80474 fs = snd_enter_user();
80475 - err = snd_pcm_delay(substream, &delay);
80476 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
80477 snd_leave_user(fs);
80478 if (err < 0)
80479 return err;
80480 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
80481 index 1c6be91..c761a59 100644
80482 --- a/sound/core/pcm_native.c
80483 +++ b/sound/core/pcm_native.c
80484 @@ -2770,11 +2770,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
80485 switch (substream->stream) {
80486 case SNDRV_PCM_STREAM_PLAYBACK:
80487 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
80488 - (void __user *)arg);
80489 + (void __force_user *)arg);
80490 break;
80491 case SNDRV_PCM_STREAM_CAPTURE:
80492 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
80493 - (void __user *)arg);
80494 + (void __force_user *)arg);
80495 break;
80496 default:
80497 result = -EINVAL;
80498 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
80499 index 1f99767..14636533 100644
80500 --- a/sound/core/seq/seq_device.c
80501 +++ b/sound/core/seq/seq_device.c
80502 @@ -63,7 +63,7 @@ struct ops_list {
80503 int argsize; /* argument size */
80504
80505 /* operators */
80506 - struct snd_seq_dev_ops ops;
80507 + struct snd_seq_dev_ops *ops;
80508
80509 /* registred devices */
80510 struct list_head dev_list; /* list of devices */
80511 @@ -332,7 +332,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
80512
80513 mutex_lock(&ops->reg_mutex);
80514 /* copy driver operators */
80515 - ops->ops = *entry;
80516 + ops->ops = entry;
80517 ops->driver |= DRIVER_LOADED;
80518 ops->argsize = argsize;
80519
80520 @@ -462,7 +462,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
80521 dev->name, ops->id, ops->argsize, dev->argsize);
80522 return -EINVAL;
80523 }
80524 - if (ops->ops.init_device(dev) >= 0) {
80525 + if (ops->ops->init_device(dev) >= 0) {
80526 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
80527 ops->num_init_devices++;
80528 } else {
80529 @@ -489,7 +489,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
80530 dev->name, ops->id, ops->argsize, dev->argsize);
80531 return -EINVAL;
80532 }
80533 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
80534 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
80535 dev->status = SNDRV_SEQ_DEVICE_FREE;
80536 dev->driver_data = NULL;
80537 ops->num_init_devices--;
80538 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
80539 index 8539ab0..be8a121 100644
80540 --- a/sound/drivers/mts64.c
80541 +++ b/sound/drivers/mts64.c
80542 @@ -28,6 +28,7 @@
80543 #include <sound/initval.h>
80544 #include <sound/rawmidi.h>
80545 #include <sound/control.h>
80546 +#include <asm/local.h>
80547
80548 #define CARD_NAME "Miditerminal 4140"
80549 #define DRIVER_NAME "MTS64"
80550 @@ -66,7 +67,7 @@ struct mts64 {
80551 struct pardevice *pardev;
80552 int pardev_claimed;
80553
80554 - int open_count;
80555 + local_t open_count;
80556 int current_midi_output_port;
80557 int current_midi_input_port;
80558 u8 mode[MTS64_NUM_INPUT_PORTS];
80559 @@ -696,7 +697,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80560 {
80561 struct mts64 *mts = substream->rmidi->private_data;
80562
80563 - if (mts->open_count == 0) {
80564 + if (local_read(&mts->open_count) == 0) {
80565 /* We don't need a spinlock here, because this is just called
80566 if the device has not been opened before.
80567 So there aren't any IRQs from the device */
80568 @@ -704,7 +705,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80569
80570 msleep(50);
80571 }
80572 - ++(mts->open_count);
80573 + local_inc(&mts->open_count);
80574
80575 return 0;
80576 }
80577 @@ -714,8 +715,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80578 struct mts64 *mts = substream->rmidi->private_data;
80579 unsigned long flags;
80580
80581 - --(mts->open_count);
80582 - if (mts->open_count == 0) {
80583 + if (local_dec_return(&mts->open_count) == 0) {
80584 /* We need the spinlock_irqsave here because we can still
80585 have IRQs at this point */
80586 spin_lock_irqsave(&mts->lock, flags);
80587 @@ -724,8 +724,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80588
80589 msleep(500);
80590
80591 - } else if (mts->open_count < 0)
80592 - mts->open_count = 0;
80593 + } else if (local_read(&mts->open_count) < 0)
80594 + local_set(&mts->open_count, 0);
80595
80596 return 0;
80597 }
80598 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
80599 index f07e38d..7aae69a 100644
80600 --- a/sound/drivers/opl4/opl4_lib.c
80601 +++ b/sound/drivers/opl4/opl4_lib.c
80602 @@ -28,7 +28,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
80603 MODULE_DESCRIPTION("OPL4 driver");
80604 MODULE_LICENSE("GPL");
80605
80606 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
80607 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
80608 {
80609 int timeout = 10;
80610 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
80611 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
80612 index f2b0ba2..429efc5 100644
80613 --- a/sound/drivers/portman2x4.c
80614 +++ b/sound/drivers/portman2x4.c
80615 @@ -47,6 +47,7 @@
80616 #include <sound/initval.h>
80617 #include <sound/rawmidi.h>
80618 #include <sound/control.h>
80619 +#include <asm/local.h>
80620
80621 #define CARD_NAME "Portman 2x4"
80622 #define DRIVER_NAME "portman"
80623 @@ -84,7 +85,7 @@ struct portman {
80624 struct pardevice *pardev;
80625 int pardev_claimed;
80626
80627 - int open_count;
80628 + local_t open_count;
80629 int mode[PORTMAN_NUM_INPUT_PORTS];
80630 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
80631 };
80632 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
80633 index 87657dd..a8268d4 100644
80634 --- a/sound/firewire/amdtp.c
80635 +++ b/sound/firewire/amdtp.c
80636 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
80637 ptr = s->pcm_buffer_pointer + data_blocks;
80638 if (ptr >= pcm->runtime->buffer_size)
80639 ptr -= pcm->runtime->buffer_size;
80640 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
80641 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
80642
80643 s->pcm_period_pointer += data_blocks;
80644 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
80645 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
80646 */
80647 void amdtp_out_stream_update(struct amdtp_out_stream *s)
80648 {
80649 - ACCESS_ONCE(s->source_node_id_field) =
80650 + ACCESS_ONCE_RW(s->source_node_id_field) =
80651 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
80652 }
80653 EXPORT_SYMBOL(amdtp_out_stream_update);
80654 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
80655 index 537a9cb..8e8c8e9 100644
80656 --- a/sound/firewire/amdtp.h
80657 +++ b/sound/firewire/amdtp.h
80658 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
80659 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
80660 struct snd_pcm_substream *pcm)
80661 {
80662 - ACCESS_ONCE(s->pcm) = pcm;
80663 + ACCESS_ONCE_RW(s->pcm) = pcm;
80664 }
80665
80666 /**
80667 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
80668 index 4400308..261e9f3 100644
80669 --- a/sound/firewire/isight.c
80670 +++ b/sound/firewire/isight.c
80671 @@ -97,7 +97,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
80672 ptr += count;
80673 if (ptr >= runtime->buffer_size)
80674 ptr -= runtime->buffer_size;
80675 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
80676 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
80677
80678 isight->period_counter += count;
80679 if (isight->period_counter >= runtime->period_size) {
80680 @@ -308,7 +308,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
80681 if (err < 0)
80682 return err;
80683
80684 - ACCESS_ONCE(isight->pcm_active) = true;
80685 + ACCESS_ONCE_RW(isight->pcm_active) = true;
80686
80687 return 0;
80688 }
80689 @@ -341,7 +341,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
80690 {
80691 struct isight *isight = substream->private_data;
80692
80693 - ACCESS_ONCE(isight->pcm_active) = false;
80694 + ACCESS_ONCE_RW(isight->pcm_active) = false;
80695
80696 mutex_lock(&isight->mutex);
80697 isight_stop_streaming(isight);
80698 @@ -434,10 +434,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
80699
80700 switch (cmd) {
80701 case SNDRV_PCM_TRIGGER_START:
80702 - ACCESS_ONCE(isight->pcm_running) = true;
80703 + ACCESS_ONCE_RW(isight->pcm_running) = true;
80704 break;
80705 case SNDRV_PCM_TRIGGER_STOP:
80706 - ACCESS_ONCE(isight->pcm_running) = false;
80707 + ACCESS_ONCE_RW(isight->pcm_running) = false;
80708 break;
80709 default:
80710 return -EINVAL;
80711 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
80712 index fe79a16..4d9714e 100644
80713 --- a/sound/isa/cmi8330.c
80714 +++ b/sound/isa/cmi8330.c
80715 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
80716
80717 struct snd_pcm *pcm;
80718 struct snd_cmi8330_stream {
80719 - struct snd_pcm_ops ops;
80720 + snd_pcm_ops_no_const ops;
80721 snd_pcm_open_callback_t open;
80722 void *private_data; /* sb or wss */
80723 } streams[2];
80724 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
80725 index 733b014..56ce96f 100644
80726 --- a/sound/oss/sb_audio.c
80727 +++ b/sound/oss/sb_audio.c
80728 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
80729 buf16 = (signed short *)(localbuf + localoffs);
80730 while (c)
80731 {
80732 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80733 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80734 if (copy_from_user(lbuf8,
80735 userbuf+useroffs + p,
80736 locallen))
80737 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
80738 index 09d4648..cf234c7 100644
80739 --- a/sound/oss/swarm_cs4297a.c
80740 +++ b/sound/oss/swarm_cs4297a.c
80741 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
80742 {
80743 struct cs4297a_state *s;
80744 u32 pwr, id;
80745 - mm_segment_t fs;
80746 int rval;
80747 #ifndef CONFIG_BCM_CS4297A_CSWARM
80748 u64 cfg;
80749 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
80750 if (!rval) {
80751 char *sb1250_duart_present;
80752
80753 +#if 0
80754 + mm_segment_t fs;
80755 fs = get_fs();
80756 set_fs(KERNEL_DS);
80757 -#if 0
80758 val = SOUND_MASK_LINE;
80759 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
80760 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
80761 val = initvol[i].vol;
80762 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
80763 }
80764 + set_fs(fs);
80765 // cs4297a_write_ac97(s, 0x18, 0x0808);
80766 #else
80767 // cs4297a_write_ac97(s, 0x5e, 0x180);
80768 cs4297a_write_ac97(s, 0x02, 0x0808);
80769 cs4297a_write_ac97(s, 0x18, 0x0808);
80770 #endif
80771 - set_fs(fs);
80772
80773 list_add(&s->list, &cs4297a_devs);
80774
80775 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
80776 index 755f2b0..5c12361 100644
80777 --- a/sound/pci/hda/hda_codec.h
80778 +++ b/sound/pci/hda/hda_codec.h
80779 @@ -611,7 +611,7 @@ struct hda_bus_ops {
80780 /* notify power-up/down from codec to controller */
80781 void (*pm_notify)(struct hda_bus *bus);
80782 #endif
80783 -};
80784 +} __no_const;
80785
80786 /* template to pass to the bus constructor */
80787 struct hda_bus_template {
80788 @@ -713,6 +713,7 @@ struct hda_codec_ops {
80789 #endif
80790 void (*reboot_notify)(struct hda_codec *codec);
80791 };
80792 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
80793
80794 /* record for amp information cache */
80795 struct hda_cache_head {
80796 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
80797 struct snd_pcm_substream *substream);
80798 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
80799 struct snd_pcm_substream *substream);
80800 -};
80801 +} __no_const;
80802
80803 /* PCM information for each substream */
80804 struct hda_pcm_stream {
80805 @@ -801,7 +802,7 @@ struct hda_codec {
80806 const char *modelname; /* model name for preset */
80807
80808 /* set by patch */
80809 - struct hda_codec_ops patch_ops;
80810 + hda_codec_ops_no_const patch_ops;
80811
80812 /* PCM to create, set by patch_ops.build_pcms callback */
80813 unsigned int num_pcms;
80814 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
80815 index 0da778a..bc38b84 100644
80816 --- a/sound/pci/ice1712/ice1712.h
80817 +++ b/sound/pci/ice1712/ice1712.h
80818 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
80819 unsigned int mask_flags; /* total mask bits */
80820 struct snd_akm4xxx_ops {
80821 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
80822 - } ops;
80823 + } __no_const ops;
80824 };
80825
80826 struct snd_ice1712_spdif {
80827 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
80828 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80829 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80830 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80831 - } ops;
80832 + } __no_const ops;
80833 };
80834
80835
80836 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
80837 index f3260e6..4a285d8 100644
80838 --- a/sound/pci/ymfpci/ymfpci_main.c
80839 +++ b/sound/pci/ymfpci/ymfpci_main.c
80840 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
80841 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
80842 break;
80843 }
80844 - if (atomic_read(&chip->interrupt_sleep_count)) {
80845 - atomic_set(&chip->interrupt_sleep_count, 0);
80846 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80847 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80848 wake_up(&chip->interrupt_sleep);
80849 }
80850 __end:
80851 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
80852 continue;
80853 init_waitqueue_entry(&wait, current);
80854 add_wait_queue(&chip->interrupt_sleep, &wait);
80855 - atomic_inc(&chip->interrupt_sleep_count);
80856 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
80857 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
80858 remove_wait_queue(&chip->interrupt_sleep, &wait);
80859 }
80860 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
80861 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
80862 spin_unlock(&chip->reg_lock);
80863
80864 - if (atomic_read(&chip->interrupt_sleep_count)) {
80865 - atomic_set(&chip->interrupt_sleep_count, 0);
80866 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80867 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80868 wake_up(&chip->interrupt_sleep);
80869 }
80870 }
80871 @@ -2363,7 +2363,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
80872 spin_lock_init(&chip->reg_lock);
80873 spin_lock_init(&chip->voice_lock);
80874 init_waitqueue_head(&chip->interrupt_sleep);
80875 - atomic_set(&chip->interrupt_sleep_count, 0);
80876 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80877 chip->card = card;
80878 chip->pci = pci;
80879 chip->irq = -1;
80880 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
80881 index 2879c88..224159e 100644
80882 --- a/sound/soc/soc-pcm.c
80883 +++ b/sound/soc/soc-pcm.c
80884 @@ -568,7 +568,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
80885 }
80886
80887 /* ASoC PCM operations */
80888 -static struct snd_pcm_ops soc_pcm_ops = {
80889 +static snd_pcm_ops_no_const soc_pcm_ops = {
80890 .open = soc_pcm_open,
80891 .close = soc_pcm_close,
80892 .hw_params = soc_pcm_hw_params,
80893 diff --git a/sound/usb/card.h b/sound/usb/card.h
80894 index ae4251d..0961361 100644
80895 --- a/sound/usb/card.h
80896 +++ b/sound/usb/card.h
80897 @@ -44,6 +44,7 @@ struct snd_urb_ops {
80898 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80899 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80900 };
80901 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
80902
80903 struct snd_usb_substream {
80904 struct snd_usb_stream *stream;
80905 @@ -93,7 +94,7 @@ struct snd_usb_substream {
80906 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
80907 spinlock_t lock;
80908
80909 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
80910 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
80911 };
80912
80913 struct snd_usb_stream {
80914 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
80915 new file mode 100644
80916 index 0000000..b044b80
80917 --- /dev/null
80918 +++ b/tools/gcc/Makefile
80919 @@ -0,0 +1,21 @@
80920 +#CC := gcc
80921 +#PLUGIN_SOURCE_FILES := pax_plugin.c
80922 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
80923 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
80924 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W
80925 +
80926 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include
80927 +
80928 +hostlibs-y := constify_plugin.so
80929 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
80930 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
80931 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
80932 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
80933 +
80934 +always := $(hostlibs-y)
80935 +
80936 +constify_plugin-objs := constify_plugin.o
80937 +stackleak_plugin-objs := stackleak_plugin.o
80938 +kallocstat_plugin-objs := kallocstat_plugin.o
80939 +kernexec_plugin-objs := kernexec_plugin.o
80940 +checker_plugin-objs := checker_plugin.o
80941 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
80942 new file mode 100644
80943 index 0000000..d41b5af
80944 --- /dev/null
80945 +++ b/tools/gcc/checker_plugin.c
80946 @@ -0,0 +1,171 @@
80947 +/*
80948 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80949 + * Licensed under the GPL v2
80950 + *
80951 + * Note: the choice of the license means that the compilation process is
80952 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80953 + * but for the kernel it doesn't matter since it doesn't link against
80954 + * any of the gcc libraries
80955 + *
80956 + * gcc plugin to implement various sparse (source code checker) features
80957 + *
80958 + * TODO:
80959 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
80960 + *
80961 + * BUGS:
80962 + * - none known
80963 + */
80964 +#include "gcc-plugin.h"
80965 +#include "config.h"
80966 +#include "system.h"
80967 +#include "coretypes.h"
80968 +#include "tree.h"
80969 +#include "tree-pass.h"
80970 +#include "flags.h"
80971 +#include "intl.h"
80972 +#include "toplev.h"
80973 +#include "plugin.h"
80974 +//#include "expr.h" where are you...
80975 +#include "diagnostic.h"
80976 +#include "plugin-version.h"
80977 +#include "tm.h"
80978 +#include "function.h"
80979 +#include "basic-block.h"
80980 +#include "gimple.h"
80981 +#include "rtl.h"
80982 +#include "emit-rtl.h"
80983 +#include "tree-flow.h"
80984 +#include "target.h"
80985 +
80986 +extern void c_register_addr_space (const char *str, addr_space_t as);
80987 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
80988 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
80989 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
80990 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
80991 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
80992 +
80993 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80994 +extern rtx emit_move_insn(rtx x, rtx y);
80995 +
80996 +int plugin_is_GPL_compatible;
80997 +
80998 +static struct plugin_info checker_plugin_info = {
80999 + .version = "201111150100",
81000 +};
81001 +
81002 +#define ADDR_SPACE_KERNEL 0
81003 +#define ADDR_SPACE_FORCE_KERNEL 1
81004 +#define ADDR_SPACE_USER 2
81005 +#define ADDR_SPACE_FORCE_USER 3
81006 +#define ADDR_SPACE_IOMEM 0
81007 +#define ADDR_SPACE_FORCE_IOMEM 0
81008 +#define ADDR_SPACE_PERCPU 0
81009 +#define ADDR_SPACE_FORCE_PERCPU 0
81010 +#define ADDR_SPACE_RCU 0
81011 +#define ADDR_SPACE_FORCE_RCU 0
81012 +
81013 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
81014 +{
81015 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
81016 +}
81017 +
81018 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
81019 +{
81020 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
81021 +}
81022 +
81023 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
81024 +{
81025 + return default_addr_space_valid_pointer_mode(mode, as);
81026 +}
81027 +
81028 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
81029 +{
81030 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
81031 +}
81032 +
81033 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
81034 +{
81035 + return default_addr_space_legitimize_address(x, oldx, mode, as);
81036 +}
81037 +
81038 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
81039 +{
81040 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
81041 + return true;
81042 +
81043 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
81044 + return true;
81045 +
81046 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
81047 + return true;
81048 +
81049 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
81050 + return true;
81051 +
81052 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
81053 + return true;
81054 +
81055 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
81056 + return true;
81057 +
81058 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
81059 + return true;
81060 +
81061 + return subset == superset;
81062 +}
81063 +
81064 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
81065 +{
81066 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
81067 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
81068 +
81069 + return op;
81070 +}
81071 +
81072 +static void register_checker_address_spaces(void *event_data, void *data)
81073 +{
81074 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
81075 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
81076 + c_register_addr_space("__user", ADDR_SPACE_USER);
81077 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
81078 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
81079 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
81080 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
81081 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
81082 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
81083 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
81084 +
81085 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
81086 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
81087 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
81088 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
81089 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
81090 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
81091 + targetm.addr_space.convert = checker_addr_space_convert;
81092 +}
81093 +
81094 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81095 +{
81096 + const char * const plugin_name = plugin_info->base_name;
81097 + const int argc = plugin_info->argc;
81098 + const struct plugin_argument * const argv = plugin_info->argv;
81099 + int i;
81100 +
81101 + if (!plugin_default_version_check(version, &gcc_version)) {
81102 + error(G_("incompatible gcc/plugin versions"));
81103 + return 1;
81104 + }
81105 +
81106 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
81107 +
81108 + for (i = 0; i < argc; ++i)
81109 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81110 +
81111 + if (TARGET_64BIT == 0)
81112 + return 0;
81113 +
81114 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
81115 +
81116 + return 0;
81117 +}
81118 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
81119 new file mode 100644
81120 index 0000000..704a564
81121 --- /dev/null
81122 +++ b/tools/gcc/constify_plugin.c
81123 @@ -0,0 +1,303 @@
81124 +/*
81125 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
81126 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
81127 + * Licensed under the GPL v2, or (at your option) v3
81128 + *
81129 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
81130 + *
81131 + * Homepage:
81132 + * http://www.grsecurity.net/~ephox/const_plugin/
81133 + *
81134 + * Usage:
81135 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
81136 + * $ gcc -fplugin=constify_plugin.so test.c -O2
81137 + */
81138 +
81139 +#include "gcc-plugin.h"
81140 +#include "config.h"
81141 +#include "system.h"
81142 +#include "coretypes.h"
81143 +#include "tree.h"
81144 +#include "tree-pass.h"
81145 +#include "flags.h"
81146 +#include "intl.h"
81147 +#include "toplev.h"
81148 +#include "plugin.h"
81149 +#include "diagnostic.h"
81150 +#include "plugin-version.h"
81151 +#include "tm.h"
81152 +#include "function.h"
81153 +#include "basic-block.h"
81154 +#include "gimple.h"
81155 +#include "rtl.h"
81156 +#include "emit-rtl.h"
81157 +#include "tree-flow.h"
81158 +
81159 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
81160 +
81161 +int plugin_is_GPL_compatible;
81162 +
81163 +static struct plugin_info const_plugin_info = {
81164 + .version = "201111150100",
81165 + .help = "no-constify\tturn off constification\n",
81166 +};
81167 +
81168 +static void constify_type(tree type);
81169 +static bool walk_struct(tree node);
81170 +
81171 +static tree deconstify_type(tree old_type)
81172 +{
81173 + tree new_type, field;
81174 +
81175 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
81176 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
81177 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
81178 + DECL_FIELD_CONTEXT(field) = new_type;
81179 + TYPE_READONLY(new_type) = 0;
81180 + C_TYPE_FIELDS_READONLY(new_type) = 0;
81181 + return new_type;
81182 +}
81183 +
81184 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81185 +{
81186 + tree type;
81187 +
81188 + *no_add_attrs = true;
81189 + if (TREE_CODE(*node) == FUNCTION_DECL) {
81190 + error("%qE attribute does not apply to functions", name);
81191 + return NULL_TREE;
81192 + }
81193 +
81194 + if (TREE_CODE(*node) == VAR_DECL) {
81195 + error("%qE attribute does not apply to variables", name);
81196 + return NULL_TREE;
81197 + }
81198 +
81199 + if (TYPE_P(*node)) {
81200 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
81201 + *no_add_attrs = false;
81202 + else
81203 + error("%qE attribute applies to struct and union types only", name);
81204 + return NULL_TREE;
81205 + }
81206 +
81207 + type = TREE_TYPE(*node);
81208 +
81209 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
81210 + error("%qE attribute applies to struct and union types only", name);
81211 + return NULL_TREE;
81212 + }
81213 +
81214 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
81215 + error("%qE attribute is already applied to the type", name);
81216 + return NULL_TREE;
81217 + }
81218 +
81219 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
81220 + error("%qE attribute used on type that is not constified", name);
81221 + return NULL_TREE;
81222 + }
81223 +
81224 + if (TREE_CODE(*node) == TYPE_DECL) {
81225 + TREE_TYPE(*node) = deconstify_type(type);
81226 + TREE_READONLY(*node) = 0;
81227 + return NULL_TREE;
81228 + }
81229 +
81230 + return NULL_TREE;
81231 +}
81232 +
81233 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81234 +{
81235 + *no_add_attrs = true;
81236 + if (!TYPE_P(*node)) {
81237 + error("%qE attribute applies to types only", name);
81238 + return NULL_TREE;
81239 + }
81240 +
81241 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
81242 + error("%qE attribute applies to struct and union types only", name);
81243 + return NULL_TREE;
81244 + }
81245 +
81246 + *no_add_attrs = false;
81247 + constify_type(*node);
81248 + return NULL_TREE;
81249 +}
81250 +
81251 +static struct attribute_spec no_const_attr = {
81252 + .name = "no_const",
81253 + .min_length = 0,
81254 + .max_length = 0,
81255 + .decl_required = false,
81256 + .type_required = false,
81257 + .function_type_required = false,
81258 + .handler = handle_no_const_attribute,
81259 +#if BUILDING_GCC_VERSION >= 4007
81260 + .affects_type_identity = true
81261 +#endif
81262 +};
81263 +
81264 +static struct attribute_spec do_const_attr = {
81265 + .name = "do_const",
81266 + .min_length = 0,
81267 + .max_length = 0,
81268 + .decl_required = false,
81269 + .type_required = false,
81270 + .function_type_required = false,
81271 + .handler = handle_do_const_attribute,
81272 +#if BUILDING_GCC_VERSION >= 4007
81273 + .affects_type_identity = true
81274 +#endif
81275 +};
81276 +
81277 +static void register_attributes(void *event_data, void *data)
81278 +{
81279 + register_attribute(&no_const_attr);
81280 + register_attribute(&do_const_attr);
81281 +}
81282 +
81283 +static void constify_type(tree type)
81284 +{
81285 + TYPE_READONLY(type) = 1;
81286 + C_TYPE_FIELDS_READONLY(type) = 1;
81287 +}
81288 +
81289 +static bool is_fptr(tree field)
81290 +{
81291 + tree ptr = TREE_TYPE(field);
81292 +
81293 + if (TREE_CODE(ptr) != POINTER_TYPE)
81294 + return false;
81295 +
81296 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
81297 +}
81298 +
81299 +static bool walk_struct(tree node)
81300 +{
81301 + tree field;
81302 +
81303 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
81304 + return false;
81305 +
81306 + if (TYPE_FIELDS(node) == NULL_TREE)
81307 + return false;
81308 +
81309 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
81310 + tree type = TREE_TYPE(field);
81311 + enum tree_code code = TREE_CODE(type);
81312 + if (code == RECORD_TYPE || code == UNION_TYPE) {
81313 + if (!(walk_struct(type)))
81314 + return false;
81315 + } else if (!is_fptr(field) && !TREE_READONLY(field))
81316 + return false;
81317 + }
81318 + return true;
81319 +}
81320 +
81321 +static void finish_type(void *event_data, void *data)
81322 +{
81323 + tree type = (tree)event_data;
81324 +
81325 + if (type == NULL_TREE)
81326 + return;
81327 +
81328 + if (TYPE_READONLY(type))
81329 + return;
81330 +
81331 + if (walk_struct(type))
81332 + constify_type(type);
81333 +}
81334 +
81335 +static unsigned int check_local_variables(void);
81336 +
81337 +struct gimple_opt_pass pass_local_variable = {
81338 + {
81339 + .type = GIMPLE_PASS,
81340 + .name = "check_local_variables",
81341 + .gate = NULL,
81342 + .execute = check_local_variables,
81343 + .sub = NULL,
81344 + .next = NULL,
81345 + .static_pass_number = 0,
81346 + .tv_id = TV_NONE,
81347 + .properties_required = 0,
81348 + .properties_provided = 0,
81349 + .properties_destroyed = 0,
81350 + .todo_flags_start = 0,
81351 + .todo_flags_finish = 0
81352 + }
81353 +};
81354 +
81355 +static unsigned int check_local_variables(void)
81356 +{
81357 + tree var;
81358 + referenced_var_iterator rvi;
81359 +
81360 +#if BUILDING_GCC_VERSION == 4005
81361 + FOR_EACH_REFERENCED_VAR(var, rvi) {
81362 +#else
81363 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
81364 +#endif
81365 + tree type = TREE_TYPE(var);
81366 +
81367 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
81368 + continue;
81369 +
81370 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81371 + continue;
81372 +
81373 + if (!TYPE_READONLY(type))
81374 + continue;
81375 +
81376 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
81377 +// continue;
81378 +
81379 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
81380 +// continue;
81381 +
81382 + if (walk_struct(type)) {
81383 + error("constified variable %qE cannot be local", var);
81384 + return 1;
81385 + }
81386 + }
81387 + return 0;
81388 +}
81389 +
81390 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81391 +{
81392 + const char * const plugin_name = plugin_info->base_name;
81393 + const int argc = plugin_info->argc;
81394 + const struct plugin_argument * const argv = plugin_info->argv;
81395 + int i;
81396 + bool constify = true;
81397 +
81398 + struct register_pass_info local_variable_pass_info = {
81399 + .pass = &pass_local_variable.pass,
81400 + .reference_pass_name = "*referenced_vars",
81401 + .ref_pass_instance_number = 0,
81402 + .pos_op = PASS_POS_INSERT_AFTER
81403 + };
81404 +
81405 + if (!plugin_default_version_check(version, &gcc_version)) {
81406 + error(G_("incompatible gcc/plugin versions"));
81407 + return 1;
81408 + }
81409 +
81410 + for (i = 0; i < argc; ++i) {
81411 + if (!(strcmp(argv[i].key, "no-constify"))) {
81412 + constify = false;
81413 + continue;
81414 + }
81415 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81416 + }
81417 +
81418 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
81419 + if (constify) {
81420 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
81421 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
81422 + }
81423 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
81424 +
81425 + return 0;
81426 +}
81427 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
81428 new file mode 100644
81429 index 0000000..a5eabce
81430 --- /dev/null
81431 +++ b/tools/gcc/kallocstat_plugin.c
81432 @@ -0,0 +1,167 @@
81433 +/*
81434 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81435 + * Licensed under the GPL v2
81436 + *
81437 + * Note: the choice of the license means that the compilation process is
81438 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81439 + * but for the kernel it doesn't matter since it doesn't link against
81440 + * any of the gcc libraries
81441 + *
81442 + * gcc plugin to find the distribution of k*alloc sizes
81443 + *
81444 + * TODO:
81445 + *
81446 + * BUGS:
81447 + * - none known
81448 + */
81449 +#include "gcc-plugin.h"
81450 +#include "config.h"
81451 +#include "system.h"
81452 +#include "coretypes.h"
81453 +#include "tree.h"
81454 +#include "tree-pass.h"
81455 +#include "flags.h"
81456 +#include "intl.h"
81457 +#include "toplev.h"
81458 +#include "plugin.h"
81459 +//#include "expr.h" where are you...
81460 +#include "diagnostic.h"
81461 +#include "plugin-version.h"
81462 +#include "tm.h"
81463 +#include "function.h"
81464 +#include "basic-block.h"
81465 +#include "gimple.h"
81466 +#include "rtl.h"
81467 +#include "emit-rtl.h"
81468 +
81469 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81470 +
81471 +int plugin_is_GPL_compatible;
81472 +
81473 +static const char * const kalloc_functions[] = {
81474 + "__kmalloc",
81475 + "kmalloc",
81476 + "kmalloc_large",
81477 + "kmalloc_node",
81478 + "kmalloc_order",
81479 + "kmalloc_order_trace",
81480 + "kmalloc_slab",
81481 + "kzalloc",
81482 + "kzalloc_node",
81483 +};
81484 +
81485 +static struct plugin_info kallocstat_plugin_info = {
81486 + .version = "201111150100",
81487 +};
81488 +
81489 +static unsigned int execute_kallocstat(void);
81490 +
81491 +static struct gimple_opt_pass kallocstat_pass = {
81492 + .pass = {
81493 + .type = GIMPLE_PASS,
81494 + .name = "kallocstat",
81495 + .gate = NULL,
81496 + .execute = execute_kallocstat,
81497 + .sub = NULL,
81498 + .next = NULL,
81499 + .static_pass_number = 0,
81500 + .tv_id = TV_NONE,
81501 + .properties_required = 0,
81502 + .properties_provided = 0,
81503 + .properties_destroyed = 0,
81504 + .todo_flags_start = 0,
81505 + .todo_flags_finish = 0
81506 + }
81507 +};
81508 +
81509 +static bool is_kalloc(const char *fnname)
81510 +{
81511 + size_t i;
81512 +
81513 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
81514 + if (!strcmp(fnname, kalloc_functions[i]))
81515 + return true;
81516 + return false;
81517 +}
81518 +
81519 +static unsigned int execute_kallocstat(void)
81520 +{
81521 + basic_block bb;
81522 +
81523 + // 1. loop through BBs and GIMPLE statements
81524 + FOR_EACH_BB(bb) {
81525 + gimple_stmt_iterator gsi;
81526 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81527 + // gimple match:
81528 + tree fndecl, size;
81529 + gimple call_stmt;
81530 + const char *fnname;
81531 +
81532 + // is it a call
81533 + call_stmt = gsi_stmt(gsi);
81534 + if (!is_gimple_call(call_stmt))
81535 + continue;
81536 + fndecl = gimple_call_fndecl(call_stmt);
81537 + if (fndecl == NULL_TREE)
81538 + continue;
81539 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
81540 + continue;
81541 +
81542 + // is it a call to k*alloc
81543 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
81544 + if (!is_kalloc(fnname))
81545 + continue;
81546 +
81547 + // is the size arg the result of a simple const assignment
81548 + size = gimple_call_arg(call_stmt, 0);
81549 + while (true) {
81550 + gimple def_stmt;
81551 + expanded_location xloc;
81552 + size_t size_val;
81553 +
81554 + if (TREE_CODE(size) != SSA_NAME)
81555 + break;
81556 + def_stmt = SSA_NAME_DEF_STMT(size);
81557 + if (!def_stmt || !is_gimple_assign(def_stmt))
81558 + break;
81559 + if (gimple_num_ops(def_stmt) != 2)
81560 + break;
81561 + size = gimple_assign_rhs1(def_stmt);
81562 + if (!TREE_CONSTANT(size))
81563 + continue;
81564 + xloc = expand_location(gimple_location(def_stmt));
81565 + if (!xloc.file)
81566 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
81567 + size_val = TREE_INT_CST_LOW(size);
81568 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
81569 + break;
81570 + }
81571 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81572 +//debug_tree(gimple_call_fn(call_stmt));
81573 +//print_node(stderr, "pax", fndecl, 4);
81574 + }
81575 + }
81576 +
81577 + return 0;
81578 +}
81579 +
81580 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81581 +{
81582 + const char * const plugin_name = plugin_info->base_name;
81583 + struct register_pass_info kallocstat_pass_info = {
81584 + .pass = &kallocstat_pass.pass,
81585 + .reference_pass_name = "ssa",
81586 + .ref_pass_instance_number = 0,
81587 + .pos_op = PASS_POS_INSERT_AFTER
81588 + };
81589 +
81590 + if (!plugin_default_version_check(version, &gcc_version)) {
81591 + error(G_("incompatible gcc/plugin versions"));
81592 + return 1;
81593 + }
81594 +
81595 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
81596 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
81597 +
81598 + return 0;
81599 +}
81600 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
81601 new file mode 100644
81602 index 0000000..51f747e
81603 --- /dev/null
81604 +++ b/tools/gcc/kernexec_plugin.c
81605 @@ -0,0 +1,348 @@
81606 +/*
81607 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81608 + * Licensed under the GPL v2
81609 + *
81610 + * Note: the choice of the license means that the compilation process is
81611 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81612 + * but for the kernel it doesn't matter since it doesn't link against
81613 + * any of the gcc libraries
81614 + *
81615 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
81616 + *
81617 + * TODO:
81618 + *
81619 + * BUGS:
81620 + * - none known
81621 + */
81622 +#include "gcc-plugin.h"
81623 +#include "config.h"
81624 +#include "system.h"
81625 +#include "coretypes.h"
81626 +#include "tree.h"
81627 +#include "tree-pass.h"
81628 +#include "flags.h"
81629 +#include "intl.h"
81630 +#include "toplev.h"
81631 +#include "plugin.h"
81632 +//#include "expr.h" where are you...
81633 +#include "diagnostic.h"
81634 +#include "plugin-version.h"
81635 +#include "tm.h"
81636 +#include "function.h"
81637 +#include "basic-block.h"
81638 +#include "gimple.h"
81639 +#include "rtl.h"
81640 +#include "emit-rtl.h"
81641 +#include "tree-flow.h"
81642 +
81643 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81644 +extern rtx emit_move_insn(rtx x, rtx y);
81645 +
81646 +int plugin_is_GPL_compatible;
81647 +
81648 +static struct plugin_info kernexec_plugin_info = {
81649 + .version = "201111291120",
81650 + .help = "method=[bts|or]\tinstrumentation method\n"
81651 +};
81652 +
81653 +static unsigned int execute_kernexec_fptr(void);
81654 +static unsigned int execute_kernexec_retaddr(void);
81655 +static bool kernexec_cmodel_check(void);
81656 +
81657 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator);
81658 +static void (*kernexec_instrument_retaddr)(rtx);
81659 +
81660 +static struct gimple_opt_pass kernexec_fptr_pass = {
81661 + .pass = {
81662 + .type = GIMPLE_PASS,
81663 + .name = "kernexec_fptr",
81664 + .gate = kernexec_cmodel_check,
81665 + .execute = execute_kernexec_fptr,
81666 + .sub = NULL,
81667 + .next = NULL,
81668 + .static_pass_number = 0,
81669 + .tv_id = TV_NONE,
81670 + .properties_required = 0,
81671 + .properties_provided = 0,
81672 + .properties_destroyed = 0,
81673 + .todo_flags_start = 0,
81674 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81675 + }
81676 +};
81677 +
81678 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81679 + .pass = {
81680 + .type = RTL_PASS,
81681 + .name = "kernexec_retaddr",
81682 + .gate = kernexec_cmodel_check,
81683 + .execute = execute_kernexec_retaddr,
81684 + .sub = NULL,
81685 + .next = NULL,
81686 + .static_pass_number = 0,
81687 + .tv_id = TV_NONE,
81688 + .properties_required = 0,
81689 + .properties_provided = 0,
81690 + .properties_destroyed = 0,
81691 + .todo_flags_start = 0,
81692 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81693 + }
81694 +};
81695 +
81696 +static bool kernexec_cmodel_check(void)
81697 +{
81698 + tree section;
81699 +
81700 + if (ix86_cmodel != CM_KERNEL)
81701 + return false;
81702 +
81703 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
81704 + if (!section || !TREE_VALUE(section))
81705 + return true;
81706 +
81707 + section = TREE_VALUE(TREE_VALUE(section));
81708 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
81709 + return true;
81710 +
81711 + return false;
81712 +}
81713 +
81714 +/*
81715 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
81716 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
81717 + */
81718 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator gsi)
81719 +{
81720 + gimple assign_intptr, assign_new_fptr, call_stmt;
81721 + tree intptr, old_fptr, new_fptr, kernexec_mask;
81722 +
81723 + call_stmt = gsi_stmt(gsi);
81724 + old_fptr = gimple_call_fn(call_stmt);
81725 +
81726 + // create temporary unsigned long variable used for bitops and cast fptr to it
81727 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
81728 + add_referenced_var(intptr);
81729 + mark_sym_for_renaming(intptr);
81730 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
81731 + gsi_insert_before(&gsi, assign_intptr, GSI_SAME_STMT);
81732 + update_stmt(assign_intptr);
81733 +
81734 + // apply logical or to temporary unsigned long and bitmask
81735 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
81736 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
81737 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
81738 + gsi_insert_before(&gsi, assign_intptr, GSI_SAME_STMT);
81739 + update_stmt(assign_intptr);
81740 +
81741 + // cast temporary unsigned long back to a temporary fptr variable
81742 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec");
81743 + add_referenced_var(new_fptr);
81744 + mark_sym_for_renaming(new_fptr);
81745 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
81746 + gsi_insert_before(&gsi, assign_new_fptr, GSI_SAME_STMT);
81747 + update_stmt(assign_new_fptr);
81748 +
81749 + // replace call stmt fn with the new fptr
81750 + gimple_call_set_fn(call_stmt, new_fptr);
81751 + update_stmt(call_stmt);
81752 +}
81753 +
81754 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator gsi)
81755 +{
81756 + gimple asm_or_stmt, call_stmt;
81757 + tree old_fptr, new_fptr, input, output;
81758 + VEC(tree, gc) *inputs = NULL;
81759 + VEC(tree, gc) *outputs = NULL;
81760 +
81761 + call_stmt = gsi_stmt(gsi);
81762 + old_fptr = gimple_call_fn(call_stmt);
81763 +
81764 + // create temporary fptr variable
81765 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
81766 + add_referenced_var(new_fptr);
81767 + mark_sym_for_renaming(new_fptr);
81768 +
81769 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
81770 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
81771 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
81772 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
81773 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
81774 + VEC_safe_push(tree, gc, inputs, input);
81775 + VEC_safe_push(tree, gc, outputs, output);
81776 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
81777 + gimple_asm_set_volatile(asm_or_stmt, true);
81778 + gsi_insert_before(&gsi, asm_or_stmt, GSI_SAME_STMT);
81779 + update_stmt(asm_or_stmt);
81780 +
81781 + // replace call stmt fn with the new fptr
81782 + gimple_call_set_fn(call_stmt, new_fptr);
81783 + update_stmt(call_stmt);
81784 +}
81785 +
81786 +/*
81787 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
81788 + */
81789 +static unsigned int execute_kernexec_fptr(void)
81790 +{
81791 + basic_block bb;
81792 + gimple_stmt_iterator gsi;
81793 +
81794 + // 1. loop through BBs and GIMPLE statements
81795 + FOR_EACH_BB(bb) {
81796 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81797 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
81798 + tree fn;
81799 + gimple call_stmt;
81800 +
81801 + // is it a call ...
81802 + call_stmt = gsi_stmt(gsi);
81803 + if (!is_gimple_call(call_stmt))
81804 + continue;
81805 + fn = gimple_call_fn(call_stmt);
81806 + if (TREE_CODE(fn) == ADDR_EXPR)
81807 + continue;
81808 + if (TREE_CODE(fn) != SSA_NAME)
81809 + gcc_unreachable();
81810 +
81811 + // ... through a function pointer
81812 + fn = SSA_NAME_VAR(fn);
81813 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
81814 + continue;
81815 + fn = TREE_TYPE(fn);
81816 + if (TREE_CODE(fn) != POINTER_TYPE)
81817 + continue;
81818 + fn = TREE_TYPE(fn);
81819 + if (TREE_CODE(fn) != FUNCTION_TYPE)
81820 + continue;
81821 +
81822 + kernexec_instrument_fptr(gsi);
81823 +
81824 +//debug_tree(gimple_call_fn(call_stmt));
81825 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81826 + }
81827 + }
81828 +
81829 + return 0;
81830 +}
81831 +
81832 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
81833 +static void kernexec_instrument_retaddr_bts(rtx insn)
81834 +{
81835 + rtx btsq;
81836 + rtvec argvec, constraintvec, labelvec;
81837 + int line;
81838 +
81839 + // create asm volatile("btsq $63,(%%rsp)":::)
81840 + argvec = rtvec_alloc(0);
81841 + constraintvec = rtvec_alloc(0);
81842 + labelvec = rtvec_alloc(0);
81843 + line = expand_location(RTL_LOCATION(insn)).line;
81844 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81845 + MEM_VOLATILE_P(btsq) = 1;
81846 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
81847 + emit_insn_before(btsq, insn);
81848 +}
81849 +
81850 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
81851 +static void kernexec_instrument_retaddr_or(rtx insn)
81852 +{
81853 + rtx orq;
81854 + rtvec argvec, constraintvec, labelvec;
81855 + int line;
81856 +
81857 + // create asm volatile("orq %%r10,(%%rsp)":::)
81858 + argvec = rtvec_alloc(0);
81859 + constraintvec = rtvec_alloc(0);
81860 + labelvec = rtvec_alloc(0);
81861 + line = expand_location(RTL_LOCATION(insn)).line;
81862 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81863 + MEM_VOLATILE_P(orq) = 1;
81864 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
81865 + emit_insn_before(orq, insn);
81866 +}
81867 +
81868 +/*
81869 + * find all asm level function returns and forcibly set the highest bit of the return address
81870 + */
81871 +static unsigned int execute_kernexec_retaddr(void)
81872 +{
81873 + rtx insn;
81874 +
81875 + // 1. find function returns
81876 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
81877 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
81878 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
81879 + rtx body;
81880 +
81881 + // is it a retn
81882 + if (!JUMP_P(insn))
81883 + continue;
81884 + body = PATTERN(insn);
81885 + if (GET_CODE(body) == PARALLEL)
81886 + body = XVECEXP(body, 0, 0);
81887 + if (GET_CODE(body) != RETURN)
81888 + continue;
81889 + kernexec_instrument_retaddr(insn);
81890 + }
81891 +
81892 +// print_simple_rtl(stderr, get_insns());
81893 +// print_rtl(stderr, get_insns());
81894 +
81895 + return 0;
81896 +}
81897 +
81898 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81899 +{
81900 + const char * const plugin_name = plugin_info->base_name;
81901 + const int argc = plugin_info->argc;
81902 + const struct plugin_argument * const argv = plugin_info->argv;
81903 + int i;
81904 + struct register_pass_info kernexec_fptr_pass_info = {
81905 + .pass = &kernexec_fptr_pass.pass,
81906 + .reference_pass_name = "ssa",
81907 + .ref_pass_instance_number = 0,
81908 + .pos_op = PASS_POS_INSERT_AFTER
81909 + };
81910 + struct register_pass_info kernexec_retaddr_pass_info = {
81911 + .pass = &kernexec_retaddr_pass.pass,
81912 + .reference_pass_name = "pro_and_epilogue",
81913 + .ref_pass_instance_number = 0,
81914 + .pos_op = PASS_POS_INSERT_AFTER
81915 + };
81916 +
81917 + if (!plugin_default_version_check(version, &gcc_version)) {
81918 + error(G_("incompatible gcc/plugin versions"));
81919 + return 1;
81920 + }
81921 +
81922 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
81923 +
81924 + if (TARGET_64BIT == 0)
81925 + return 0;
81926 +
81927 + for (i = 0; i < argc; ++i) {
81928 + if (!strcmp(argv[i].key, "method")) {
81929 + if (!argv[i].value) {
81930 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81931 + continue;
81932 + }
81933 + if (!strcmp(argv[i].value, "bts")) {
81934 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
81935 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
81936 + } else if (!strcmp(argv[i].value, "or")) {
81937 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
81938 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
81939 + fix_register("r10", 1, 1);
81940 + } else
81941 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
81942 + continue;
81943 + }
81944 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81945 + }
81946 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
81947 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
81948 +
81949 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
81950 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
81951 +
81952 + return 0;
81953 +}
81954 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
81955 new file mode 100644
81956 index 0000000..d44f37c
81957 --- /dev/null
81958 +++ b/tools/gcc/stackleak_plugin.c
81959 @@ -0,0 +1,291 @@
81960 +/*
81961 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81962 + * Licensed under the GPL v2
81963 + *
81964 + * Note: the choice of the license means that the compilation process is
81965 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81966 + * but for the kernel it doesn't matter since it doesn't link against
81967 + * any of the gcc libraries
81968 + *
81969 + * gcc plugin to help implement various PaX features
81970 + *
81971 + * - track lowest stack pointer
81972 + *
81973 + * TODO:
81974 + * - initialize all local variables
81975 + *
81976 + * BUGS:
81977 + * - none known
81978 + */
81979 +#include "gcc-plugin.h"
81980 +#include "config.h"
81981 +#include "system.h"
81982 +#include "coretypes.h"
81983 +#include "tree.h"
81984 +#include "tree-pass.h"
81985 +#include "flags.h"
81986 +#include "intl.h"
81987 +#include "toplev.h"
81988 +#include "plugin.h"
81989 +//#include "expr.h" where are you...
81990 +#include "diagnostic.h"
81991 +#include "plugin-version.h"
81992 +#include "tm.h"
81993 +#include "function.h"
81994 +#include "basic-block.h"
81995 +#include "gimple.h"
81996 +#include "rtl.h"
81997 +#include "emit-rtl.h"
81998 +
81999 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82000 +
82001 +int plugin_is_GPL_compatible;
82002 +
82003 +static int track_frame_size = -1;
82004 +static const char track_function[] = "pax_track_stack";
82005 +static const char check_function[] = "pax_check_alloca";
82006 +static bool init_locals;
82007 +
82008 +static struct plugin_info stackleak_plugin_info = {
82009 + .version = "201111150100",
82010 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
82011 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
82012 +};
82013 +
82014 +static bool gate_stackleak_track_stack(void);
82015 +static unsigned int execute_stackleak_tree_instrument(void);
82016 +static unsigned int execute_stackleak_final(void);
82017 +
82018 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
82019 + .pass = {
82020 + .type = GIMPLE_PASS,
82021 + .name = "stackleak_tree_instrument",
82022 + .gate = gate_stackleak_track_stack,
82023 + .execute = execute_stackleak_tree_instrument,
82024 + .sub = NULL,
82025 + .next = NULL,
82026 + .static_pass_number = 0,
82027 + .tv_id = TV_NONE,
82028 + .properties_required = PROP_gimple_leh | PROP_cfg,
82029 + .properties_provided = 0,
82030 + .properties_destroyed = 0,
82031 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
82032 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
82033 + }
82034 +};
82035 +
82036 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
82037 + .pass = {
82038 + .type = RTL_PASS,
82039 + .name = "stackleak_final",
82040 + .gate = gate_stackleak_track_stack,
82041 + .execute = execute_stackleak_final,
82042 + .sub = NULL,
82043 + .next = NULL,
82044 + .static_pass_number = 0,
82045 + .tv_id = TV_NONE,
82046 + .properties_required = 0,
82047 + .properties_provided = 0,
82048 + .properties_destroyed = 0,
82049 + .todo_flags_start = 0,
82050 + .todo_flags_finish = TODO_dump_func
82051 + }
82052 +};
82053 +
82054 +static bool gate_stackleak_track_stack(void)
82055 +{
82056 + return track_frame_size >= 0;
82057 +}
82058 +
82059 +static void stackleak_check_alloca(gimple_stmt_iterator gsi)
82060 +{
82061 + gimple check_alloca;
82062 + tree fndecl, fntype, alloca_size;
82063 +
82064 + // insert call to void pax_check_alloca(unsigned long size)
82065 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
82066 + fndecl = build_fn_decl(check_function, fntype);
82067 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
82068 + alloca_size = gimple_call_arg(gsi_stmt(gsi), 0);
82069 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
82070 + gsi_insert_before(&gsi, check_alloca, GSI_CONTINUE_LINKING);
82071 +}
82072 +
82073 +static void stackleak_add_instrumentation(gimple_stmt_iterator gsi)
82074 +{
82075 + gimple track_stack;
82076 + tree fndecl, fntype;
82077 +
82078 + // insert call to void pax_track_stack(void)
82079 + fntype = build_function_type_list(void_type_node, NULL_TREE);
82080 + fndecl = build_fn_decl(track_function, fntype);
82081 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
82082 + track_stack = gimple_build_call(fndecl, 0);
82083 + gsi_insert_after(&gsi, track_stack, GSI_CONTINUE_LINKING);
82084 +}
82085 +
82086 +#if BUILDING_GCC_VERSION == 4005
82087 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
82088 +{
82089 + tree fndecl;
82090 +
82091 + if (!is_gimple_call(stmt))
82092 + return false;
82093 + fndecl = gimple_call_fndecl(stmt);
82094 + if (!fndecl)
82095 + return false;
82096 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
82097 + return false;
82098 +// print_node(stderr, "pax", fndecl, 4);
82099 + return DECL_FUNCTION_CODE(fndecl) == code;
82100 +}
82101 +#endif
82102 +
82103 +static bool is_alloca(gimple stmt)
82104 +{
82105 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
82106 + return true;
82107 +
82108 +#if BUILDING_GCC_VERSION >= 4007
82109 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
82110 + return true;
82111 +#endif
82112 +
82113 + return false;
82114 +}
82115 +
82116 +static unsigned int execute_stackleak_tree_instrument(void)
82117 +{
82118 + basic_block bb, entry_bb;
82119 + bool prologue_instrumented = false;
82120 +
82121 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
82122 +
82123 + // 1. loop through BBs and GIMPLE statements
82124 + FOR_EACH_BB(bb) {
82125 + gimple_stmt_iterator gsi;
82126 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82127 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
82128 + if (!is_alloca(gsi_stmt(gsi)))
82129 + continue;
82130 +
82131 + // 2. insert stack overflow check before each __builtin_alloca call
82132 + stackleak_check_alloca(gsi);
82133 +
82134 + // 3. insert track call after each __builtin_alloca call
82135 + stackleak_add_instrumentation(gsi);
82136 + if (bb == entry_bb)
82137 + prologue_instrumented = true;
82138 + }
82139 + }
82140 +
82141 + // 4. insert track call at the beginning
82142 + if (!prologue_instrumented) {
82143 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
82144 + if (dom_info_available_p(CDI_DOMINATORS))
82145 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
82146 + stackleak_add_instrumentation(gsi_start_bb(bb));
82147 + }
82148 +
82149 + return 0;
82150 +}
82151 +
82152 +static unsigned int execute_stackleak_final(void)
82153 +{
82154 + rtx insn;
82155 +
82156 + if (cfun->calls_alloca)
82157 + return 0;
82158 +
82159 + // keep calls only if function frame is big enough
82160 + if (get_frame_size() >= track_frame_size)
82161 + return 0;
82162 +
82163 + // 1. find pax_track_stack calls
82164 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
82165 + // 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))
82166 + rtx body;
82167 +
82168 + if (!CALL_P(insn))
82169 + continue;
82170 + body = PATTERN(insn);
82171 + if (GET_CODE(body) != CALL)
82172 + continue;
82173 + body = XEXP(body, 0);
82174 + if (GET_CODE(body) != MEM)
82175 + continue;
82176 + body = XEXP(body, 0);
82177 + if (GET_CODE(body) != SYMBOL_REF)
82178 + continue;
82179 + if (strcmp(XSTR(body, 0), track_function))
82180 + continue;
82181 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
82182 + // 2. delete call
82183 + insn = delete_insn_and_edges(insn);
82184 +#if BUILDING_GCC_VERSION >= 4007
82185 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
82186 + insn = delete_insn_and_edges(insn);
82187 +#endif
82188 + }
82189 +
82190 +// print_simple_rtl(stderr, get_insns());
82191 +// print_rtl(stderr, get_insns());
82192 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
82193 +
82194 + return 0;
82195 +}
82196 +
82197 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82198 +{
82199 + const char * const plugin_name = plugin_info->base_name;
82200 + const int argc = plugin_info->argc;
82201 + const struct plugin_argument * const argv = plugin_info->argv;
82202 + int i;
82203 + struct register_pass_info stackleak_tree_instrument_pass_info = {
82204 + .pass = &stackleak_tree_instrument_pass.pass,
82205 +// .reference_pass_name = "tree_profile",
82206 + .reference_pass_name = "optimized",
82207 + .ref_pass_instance_number = 0,
82208 + .pos_op = PASS_POS_INSERT_AFTER
82209 + };
82210 + struct register_pass_info stackleak_final_pass_info = {
82211 + .pass = &stackleak_final_rtl_opt_pass.pass,
82212 + .reference_pass_name = "final",
82213 + .ref_pass_instance_number = 0,
82214 + .pos_op = PASS_POS_INSERT_BEFORE
82215 + };
82216 +
82217 + if (!plugin_default_version_check(version, &gcc_version)) {
82218 + error(G_("incompatible gcc/plugin versions"));
82219 + return 1;
82220 + }
82221 +
82222 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
82223 +
82224 + for (i = 0; i < argc; ++i) {
82225 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
82226 + if (!argv[i].value) {
82227 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82228 + continue;
82229 + }
82230 + track_frame_size = atoi(argv[i].value);
82231 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
82232 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
82233 + continue;
82234 + }
82235 + if (!strcmp(argv[i].key, "initialize-locals")) {
82236 + if (argv[i].value) {
82237 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
82238 + continue;
82239 + }
82240 + init_locals = true;
82241 + continue;
82242 + }
82243 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82244 + }
82245 +
82246 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
82247 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
82248 +
82249 + return 0;
82250 +}
82251 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
82252 index 6789d78..4afd019 100644
82253 --- a/tools/perf/util/include/asm/alternative-asm.h
82254 +++ b/tools/perf/util/include/asm/alternative-asm.h
82255 @@ -5,4 +5,7 @@
82256
82257 #define altinstruction_entry #
82258
82259 + .macro pax_force_retaddr rip=0, reload=0
82260 + .endm
82261 +
82262 #endif
82263 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
82264 index af0f22f..9a7d479 100644
82265 --- a/usr/gen_init_cpio.c
82266 +++ b/usr/gen_init_cpio.c
82267 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
82268 int retval;
82269 int rc = -1;
82270 int namesize;
82271 - int i;
82272 + unsigned int i;
82273
82274 mode |= S_IFREG;
82275
82276 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
82277 *env_var = *expanded = '\0';
82278 strncat(env_var, start + 2, end - start - 2);
82279 strncat(expanded, new_location, start - new_location);
82280 - strncat(expanded, getenv(env_var), PATH_MAX);
82281 - strncat(expanded, end + 1, PATH_MAX);
82282 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
82283 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
82284 strncpy(new_location, expanded, PATH_MAX);
82285 + new_location[PATH_MAX] = 0;
82286 } else
82287 break;
82288 }
82289 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
82290 index aefdda3..8e8fbb9 100644
82291 --- a/virt/kvm/kvm_main.c
82292 +++ b/virt/kvm/kvm_main.c
82293 @@ -73,7 +73,7 @@ LIST_HEAD(vm_list);
82294
82295 static cpumask_var_t cpus_hardware_enabled;
82296 static int kvm_usage_count = 0;
82297 -static atomic_t hardware_enable_failed;
82298 +static atomic_unchecked_t hardware_enable_failed;
82299
82300 struct kmem_cache *kvm_vcpu_cache;
82301 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
82302 @@ -2266,7 +2266,7 @@ static void hardware_enable_nolock(void *junk)
82303
82304 if (r) {
82305 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
82306 - atomic_inc(&hardware_enable_failed);
82307 + atomic_inc_unchecked(&hardware_enable_failed);
82308 printk(KERN_INFO "kvm: enabling virtualization on "
82309 "CPU%d failed\n", cpu);
82310 }
82311 @@ -2320,10 +2320,10 @@ static int hardware_enable_all(void)
82312
82313 kvm_usage_count++;
82314 if (kvm_usage_count == 1) {
82315 - atomic_set(&hardware_enable_failed, 0);
82316 + atomic_set_unchecked(&hardware_enable_failed, 0);
82317 on_each_cpu(hardware_enable_nolock, NULL, 1);
82318
82319 - if (atomic_read(&hardware_enable_failed)) {
82320 + if (atomic_read_unchecked(&hardware_enable_failed)) {
82321 hardware_disable_all_nolock();
82322 r = -EBUSY;
82323 }
82324 @@ -2588,7 +2588,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
82325 kvm_arch_vcpu_put(vcpu);
82326 }
82327
82328 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
82329 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
82330 struct module *module)
82331 {
82332 int r;
82333 @@ -2651,7 +2651,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
82334 if (!vcpu_align)
82335 vcpu_align = __alignof__(struct kvm_vcpu);
82336 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
82337 - 0, NULL);
82338 + SLAB_USERCOPY, NULL);
82339 if (!kvm_vcpu_cache) {
82340 r = -ENOMEM;
82341 goto out_free_3;
82342 @@ -2661,9 +2661,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
82343 if (r)
82344 goto out_free;
82345
82346 - kvm_chardev_ops.owner = module;
82347 - kvm_vm_fops.owner = module;
82348 - kvm_vcpu_fops.owner = module;
82349 + pax_open_kernel();
82350 + *(void **)&kvm_chardev_ops.owner = module;
82351 + *(void **)&kvm_vm_fops.owner = module;
82352 + *(void **)&kvm_vcpu_fops.owner = module;
82353 + pax_close_kernel();
82354
82355 r = misc_register(&kvm_dev);
82356 if (r) {